public function saveStaticRedirect($record)
{
$error = "";
if (isset($record)) {
if ($record->redirectSrcUrl == "" || $record->redirectDestUrl == "") {
$id = $record->id;
$affectedRows = craft()->db->createCommand()->delete('retour_static_redirects', array('id' => $id));
RetourPlugin::log("Deleted Redirected: " . $id, LogLevel::Info, false);
$error = craft()->cache->flush();
RetourPlugin::log("Cache flushed: " . print_r($error, true), LogLevel::Info, false);
$error = -1;
} else {
if ($record->save()) {
$error = craft()->cache->flush();
RetourPlugin::log("Cache flushed: " . print_r($error, true), LogLevel::Info, false);
craft()->userSession->setNotice(Craft::t('Retour Redirect saved.'));
$error = "";
/* -- To prevent redirect loops, see if any static redirects have our destUrl as their srcUrl */
$redir = $this->getRedirectByRedirectSrcUrl($record->redirectDestUrl, $record->locale);
if ($redir) {
$id = $redir->id;
$affectedRows = craft()->db->createCommand()->delete('retour_static_redirects', array('id' => $id));
}
} else {
$error = $record->getErrors();
RetourPlugin::log(print_r($error, true), LogLevel::Info, false);
craft()->userSession->setError(Craft::t('Couldn’t save Retour Redirect.'));
}
}
}
return $error;
}