Пример #1
0
 private function saveTranslation($nRevChangeId)
 {
     $bPageWasEditedDuringTranslation = $this->getoPage()->getChangeId() > $nRevChangeId ? true : false;
     if ($bPageWasEditedDuringTranslation) {
         //someone has edited the page since user was translating it, let's get the old revision from which we started the translation
         AnwDebug::log("Someone edited the page since we were translating it");
         $oPageRev = new AnwPageByName($this->getoPage()->getName(), $nRevChangeId);
         $oContentBeforeEdit = $oPageRev->getContent();
         $oContentAfterEdit = $this->getoPage()->getContent();
     } else {
         $oPageRev = $this->getoPage();
     }
     $oContent = clone $oPageRev->getContent();
     //preload original lang
     $fOnValue = "preloadOriginalLang_onContentFieldValue";
     AnwUtils::runCallbacksOnTranslatableField($this, $oPageRev->getContent(), $fOnValue);
     //update content from post
     $fOnValue = "saveTranslation_cbkOnValue";
     //$fBeforeContentField
     $fBeforeContentField = "saveTranslation_cbkBeforeField";
     $fAfterContentField = "saveTranslation_cbkAfterField";
     AnwUtils::runCallbacksOnTranslatableField($this, $oContent, $fOnValue, $fBeforeContentField, $fAfterContentField);
     //if needed, apply again the edit which was done since the translation
     if ($bPageWasEditedDuringTranslation) {
         AnwDebug::log("Someone edited the page since we were translating it --> reapplying changes");
         $oContent = AnwAutoSync::propagateContentEdition($oContentBeforeEdit, $oContentAfterEdit, $oContent);
     }
     //save changes to the current page
     $this->debug("Updating current page...");
     $this->getoPage()->saveTranslation($oContent);
     //unlock
     $this->unlockPageForEdition();
     //redirect
     AnwUtils::redirect(AnwUtils::link($this->getPageName()));
 }