Example #1
0
 function changeLang($sLang, $sComment = "", $nTime = null)
 {
     if ($this->isArchive()) {
         throw new AnwUnexpectedException("Can't change the lang of an archive");
     }
     if (!$this->exists()) {
         throw new AnwUnexpectedException("A non existing page can't have it's lang changed");
     }
     if (!Anwi18n::isValidLang($sLang)) {
         throw new AnwBadLangException();
     }
     if (!$nTime) {
         $nTime = time();
     }
     $sOldLang = $this->sLang;
     if ($sLang != $sOldLang && $this->getPageGroup()->hasLang($sLang)) {
         throw new AnwLangExistsForPageGroupException();
     }
     //update some attributes
     $this->touchInfos($nTime);
     $this->sLang = $sLang;
     //get new change ID
     $nChangeType = AnwChange::TYPE_PAGE_CHANGELANG;
     $sChangeInfo = $sOldLang . " -> " . $sLang;
     $oChange = new AnwChange($nChangeType, $this, $nTime, $sComment, $sChangeInfo, "", $sOldLang);
     AnwStorage::transactionStart();
     try {
         //save
         AnwStorage::changeLangPage($this, $oChange);
         //notify change
         $this->notifyChanged();
         AnwStorage::transactionCommit();
     } catch (AnwException $e) {
         AnwStorage::transactionRollback();
         throw $e;
     }
 }