Example #1
0
 /**
  * Renames a page name and updates the path of its children tree.
  *
  * @param integer $pageId Page id.
  * @param string $pageName New page name.
  * @return boolean
  */
 public function renamePage($pageId, $pageName)
 {
     if (!$this->getPageExists($pageId)) {
         // Compatibility mode: handling of content pages with no location
         // in page tree.
         $pageInfo = Page::getModulePageFromId($pageId);
         if ($pageInfo === false) {
             // Page really doesn't exist in content pages table.
             return false;
         }
         // Add the page in the pages tree.
         $this->addPage($pageInfo['module'], $pageInfo['page'], $pageId, 0, $pageName);
     }
     // Checks if the page name is empty.
     if (!strlen($pageName)) {
         $pageName = $pageId;
     }
     // Normalize page name.
     $pageName = self::normalizePageName($pageName);
     // Checks if the page name has been really changed.
     $check_query = $this->dataAccess->execute('SELECT page_path ' . 'FROM innomedia_pages_tree ' . 'WHERE page_id=' . $pageId);
     $old_path = $check_query->getFields('page_path');
     $parentPath = dirname($check_query->getFields('page_path'));
     if ($parentPath == '.') {
         $parentPath = '';
     }
     if (strlen($parentPath)) {
         $parentPath .= '/';
     }
     $prev_name = basename($old_path);
     if ($prev_name == $pageName) {
         return true;
     }
     // The name is new.
     if (!$this->dataAccess->execute('UPDATE innomedia_pages_tree
         SET page_path = ' . $this->dataAccess->formatText($parentPath . $pageName) . '
         WHERE page_id=' . $pageId)) {
         return false;
     }
     return $this->updatePageChildrenTreePaths($pageId);
 }