Example #1
0
 function rename($sName, $bUpdateLinks, $sComment = "", $nTime = null)
 {
     if ($this->isArchive()) {
         throw new AnwUnexpectedException("An archive can't be renamed");
     }
     if (!$this->exists()) {
         throw new AnwUnexpectedException("A non existing page can't be renamed");
     }
     if (!self::isValidPageName($sName)) {
         throw new AnwBadPageNameException();
     }
     if (!$nTime) {
         $nTime = time();
     }
     //update some attributes
     $this->touchInfos($nTime);
     $sOldName = $this->getName();
     $this->sName = $sName;
     //get new change ID
     $nChangeType = AnwChange::TYPE_PAGE_RENAME;
     $sChangeInfo = $sOldName . " -> " . $sName;
     $oChange = new AnwChange($nChangeType, $this, $nTime, $sComment, $sChangeInfo, $sOldName);
     AnwStorage::transactionStart();
     try {
         //save
         AnwStorage::renamePage($this, $oChange, $sOldName);
         //notify change
         $this->notifyChanged();
         if ($bUpdateLinks) {
             //update links to this page
             $aoPageGroups = $this->getPageGroup()->getPageGroupsLinking();
             foreach ($aoPageGroups as $oPageGroup) {
                 //edit the link from the preferred page, then deploy this change to other translations
                 $oPage = $oPageGroup->getPreferedPage();
                 $sNewContent = $oPage->getContent()->toXmlString();
                 // don't generate hreflang attribute in the content now, it will be generated when rendering output
                 $sNewContent = self::updateOutgoingLinkInContent($sOldName, $sName, $sNewContent, false);
                 $oNewContent = $oPage->getPageGroup()->getContentClass()->rebuildContentFromXml($sNewContent);
                 $sChangeInfos = $sOldName . " -> " . $sName;
                 $oPage->saveEditAndDeploy($oNewContent, AnwChange::TYPE_PAGE_UPDATELINKS, "", $sChangeInfos, $nTime);
             }
         }
         AnwStorage::transactionCommit();
     } catch (AnwException $e) {
         AnwStorage::transactionRollback();
         throw $e;
     }
 }