/**
  * Up
  **/
 public function up()
 {
     $rparams = $this->getParams('com_register');
     if (!empty($rparams)) {
         $values = $rparams->toArray();
         $this->db->setQuery("SELECT * FROM `#__extensions` WHERE `type`='component' AND `element`='com_members' LIMIT 1");
         if ($data = $this->db->loadAssoc()) {
             $component = new \JTableExtension($this->db);
             $component->bind($data);
             $mparams = new \Hubzero\Config\Registry($component->params);
             foreach ($values as $key => $value) {
                 $mparams->set($key, $value);
             }
             $component->params = $mparams->toString();
             $component->store();
         }
     }
     // Get the default menu identifier
     //$this->db->setQuery("SELECT menutype FROM `#__menu` WHERE home='1' LIMIT 1;");
     //$menutype = $this->db->loadResult();
     $this->db->setQuery("SELECT extension_id FROM `#__extensions` WHERE `type`='component' AND `element`='com_members'");
     $component = $this->db->loadResult();
     // Check if there's a menu item for com_register
     $this->db->setQuery("SELECT id FROM `#__menu` WHERE `alias`='register' AND `path`='register'");
     //" AND menutype=" . $this->db->quote($menutype));
     if ($id = $this->db->loadResult()) {
         // There is!
         // So, just update its link
         $this->db->setQuery("UPDATE `#__menu` SET `link`='index.php?option=com_members&view=register&layout=create', `component_id`=" . $this->db->quote($component) . " WHERE `id`=" . $this->db->quote($id));
         $this->db->query();
     } else {
         $this->db->setQuery("SELECT menutype FROM `#__menu` WHERE `home`='1' LIMIT 1;");
         $menutype = $this->db->loadResult();
         $this->db->setQuery("SELECT ordering FROM `#__menu` WHERE `menutype`=" . $this->db->quote($menutype) . " ORDER BY ordering DESC LIMIT 1");
         $ordering = intval($this->db->loadResult());
         $ordering++;
         // No menu item for com_register so we need to create one for the new com_members controler
         $query = "INSERT INTO `#__menu` (`id`, `menutype`, `title`, `alias`, `note`, `path`, `link`, `type`, `published`, `parent_id`, `level`, `component_id`, `ordering`, `checked_out`, `checked_out_time`, `browserNav`, `access`, `img`, `template_style_id`, `params`, `lft`, `rgt`, `home`, `language`, `client_id`)\n";
         $query .= "VALUES ('', '{$menutype}', 'Register', 'register', '', 'register', 'index.php?option=com_members&view=register&layout=create', 'component', 1, 1, 1, {$component}, {$ordering}, 0, '0000-00-00 00:00:00', 0, 1, '', 0, '', 0, 0, 0, '*', 0);";
         $this->db->setQuery($query);
         $this->db->query();
         // If we have the nested set class available, use it to rebuild lft/rgt
         if (class_exists('JTableNested') && method_exists('JTableNested', 'rebuild')) {
             // Use the MySQL driver for this
             $config = \JFactory::getConfig();
             $database = \JDatabase::getInstance(array('driver' => 'mysql', 'host' => $config->getValue('host'), 'user' => $config->getValue('user'), 'password' => $config->getValue('password'), 'database' => $config->getValue('db')));
             $table = new \JTableMenu($database);
             $table->rebuild();
             unset($database);
         }
     }
     $this->deleteComponentEntry('register');
 }
Example #2
0
 /**
  * Method to delete a node and, optionally, its child nodes from the table.
  *
  * @param   integer  $pk        The primary key of the node to delete.
  * @param   boolean  $children  True to delete child nodes, false to move them up a level.
  *
  * @return  boolean  True on success.
  *
  * @see     http://docs.joomla.org/JTableNested/delete
  * @since   2.5
  */
 public function delete($pk = null, $children = false)
 {
     return parent::delete($pk, $children);
 }
Example #3
0
 function mosMenu(&$db)
 {
     parent::__construct($db);
 }
Example #4
0
 function ValidateMenus()
 {
     $log = "";
     if (FSFJ3Helper::IsJ3()) {
     } elseif ($this->DBIs16()) {
         // no need at moment, as no added items for a 1.6 install
         $db = JFactory::getDBO();
         $db->setQuery("SELECT * FROM #__menu WHERE link = 'index.php?option=com_fsf' AND menutype = 'main'");
         $component = $db->loadObjectList();
         $componentid = $component[0]->id;
         $componentid16 = $component[0]->component_id;
         if (file_exists(JPATH_COMPONENT . DS . 'fsf.xml')) {
             //echo "<pre>";
             $order = 1;
             $xml = simplexml_load_file(JPATH_COMPONENT . DS . 'fsf.xml');
             foreach ($xml->administration->submenu->menu as $item) {
                 $name = (string) $item;
                 //echo $name."<br>";
                 $arr = $item->attributes();
                 $link = $arr['link'];
                 //echo $link."<br>";
                 $alias = strtolower(str_replace("_", "", $name));
                 $qry = "SELECT * FROM #__menu WHERE link = 'index.php?{$link}' AND menutype = 'main'";
                 //echo $qry."<br>";
                 $db->setQuery($qry);
                 $componentitem = $db->loadObject();
                 if (!$componentitem) {
                     //echo "Missing<br>";
                     // item missing, create it
                     $qry = "INSERT INTO #__menu (menutype, title, alias, path, link, type, parent_id, level, component_id, ordering, img, client_id) VALUES (";
                     $qry .= " 'main', '{$name}', '{$alias}', 'freestylesupportportal/{$alias}', 'index.php?{$link}', 'component', {$componentid}, 2, {$componentid16}, {$order}, 'images/blank.png', 1)";
                     $db->setQuery($qry);
                     $db->Query();
                     $log .= "Adding menu item {$name}<Br>";
                 } else {
                     //print_r($componentitem);
                     $qry = "UPDATE #__menu SET title = '{$name}', ordering = {$order} WHERE id = " . $componentitem->id;
                     //echo $qry."<br>";
                     $db->setQuery($qry);
                     $db->Query();
                 }
                 $order++;
             }
             //echo "</pre>";
             jimport('joomla.database.table.menu');
             require JPATH_SITE . DS . "libraries" . DS . "joomla" . DS . "database" . DS . "table" . DS . "menu.php";
             $table = new JTableMenu($db);
             $table->rebuild();
         }
     } else {
         // find base item
         $db = JFactory::getDBO();
         $db->setQuery("SELECT * FROM #__components WHERE link = 'option=com_fsf' AND parent = 0");
         $component = $db->loadObjectList();
         $componentid = $component[0]->id;
         if (file_exists(JPATH_COMPONENT . DS . 'fsf.xml')) {
             //echo "<pre>";
             $order = 1;
             $xml = simplexml_load_file(JPATH_COMPONENT . DS . 'fsf.xml');
             foreach ($xml->administration->submenu->menu as $item) {
                 $name = (string) $item;
                 //$log .= $name."\n";
                 $arr = $item->attributes();
                 $link = $arr['link'];
                 //$log .= $link."\n";
                 $db->setQuery("SELECT * FROM #__components WHERE admin_menu_link = '{$link}'");
                 $componentitem = $db->loadObject();
                 if (!$componentitem) {
                     // item missing, create it
                     //echo "MISSING<br>";
                     $qry = "INSERT INTO #__components (name, parent, admin_menu_link, admin_menu_alt, `option`, ordering, admin_menu_img, iscore, enabled) VALUES (";
                     $qry .= " '{$name}', {$componentid}, '{$link}', '{$name}', 'com_fsf', {$order}, 'images/blank.png', 0, 1)";
                     $db->setQuery($qry);
                     $db->Query();
                     $log .= "Adding menu item {$name}<Br>";
                 } else {
                     //print_r($componentitem);
                     $qry = "UPDATE #__components SET name = '{$name}', ordering = {$order} WHERE id = " . $componentitem->id;
                     //$log .= $qry."<br>";
                     $db->setQuery($qry);
                     $db->Query();
                 }
                 $order++;
             }
             //echo "</pre>";
             $log .= "Base component id : {$componentid}<br>" . $log;
         }
     }
     if ($log == "") {
         $log = "All admin menu items are ok<br>";
     }
     return $log;
 }
Example #5
0
 /**
  * Create menu structure
  *
  * @return void
  */
 public static function createMenuStructure()
 {
     /* @var $db NenoDatabaseDriverMysqlx */
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $languages = self::getTargetLanguages();
     $defaultLanguage = NenoSettings::get('source_language');
     // Delete all the menus trashed
     $query->delete('#__menu')->where('published = -2');
     $db->setQuery($query);
     $db->execute();
     // Delete all the associations left
     $query->clear()->delete('a USING #__associations AS a')->where(array('context = ' . $db->quote('com_menus.item'), 'NOT EXISTS (SELECT 1 FROM #__menu AS m WHERE a.id = m.id)'));
     $db->setQuery($query);
     $db->execute();
     // Delete associations with just one item
     $query->clear()->select('DISTINCT id')->from('#__associations')->group('`key`')->having('COUNT(*) = 1');
     $db->setQuery($query);
     $ids = $db->loadArray();
     $query->clear()->delete('#__associations')->where(array('context = ' . $db->quote('com_menus.item'), 'id IN (' . implode(', ', $db->quote($ids)) . ')'));
     $db->setQuery($query);
     $db->execute();
     $query->clear()->update('#__modules')->set('language = ' . $db->quote($defaultLanguage))->where(array('published = 1', 'module = ' . $db->quote('mod_menu'), 'client_id = 0', 'language  = ' . $db->quote('*')));
     $db->setQuery($query);
     $db->execute();
     // Set all the menus items from '*' to default language
     $query->clear()->update('#__menu AS m')->set('language = ' . $db->quote($defaultLanguage))->where(array('client_id = 0', 'level <> 0', 'language = ' . $db->quote('*')));
     $db->setQuery($query);
     $db->execute();
     $query->clear()->select(array('m.*'))->from('#__menu_types AS mt')->leftJoin('#__menu AS m ON mt.menutype = m.menutype')->where(array('NOT EXISTS(SELECT 1 FROM #__associations AS a WHERE a.id = m.id AND a.`key` = ' . $db->quote('com_menus.item') . ')', 'client_id = 0', 'level <> 0', 'published <> -2'))->order('level');
     $db->setQuery($query);
     $nonAssociatedMenuItems = $db->loadObjectList();
     $menuAssociations = array();
     $query->clear()->select('DISTINCT m1.menutype AS m1')->from('#__associations a1')->innerJoin('#__menu AS m1 ON a1.id = m1.id')->innerJoin('#__associations AS a2 ON a1.key = a2.key')->innerJoin('#__menu AS m2 ON a2.id = m2.id')->where(array('a1.context = ' . $db->quote('com_menus.item'), 'a2.context = ' . $db->quote('com_menus.item'), 'a1.id <> a2.id', 'm1.client_id = 0', 'm1.level <> 0', 'm1.published <> -2', 'm2.client_id = 0', 'm2.level <> 0', 'm2.published <> -2'));
     $db->setQuery($query);
     $menuTypes = $db->loadArray();
     foreach ($menuTypes as $menuType) {
         $query->clear()->select(array('DISTINCT m2.menutype', 'm2.language'))->from('#__associations a1')->innerJoin('#__menu AS m1 ON a1.id = m1.id')->innerJoin('#__associations AS a2 ON a1.key = a2.key')->innerJoin('#__menu AS m2 ON a2.id = m2.id')->where(array('a1.context = ' . $db->quote('com_menus.item'), 'a2.context = ' . $db->quote('com_menus.item'), 'a1.id <> a2.id', 'm1.client_id = 0', 'm1.level <> 0', 'm1.published <> -2', 'm2.client_id = 0', 'm2.level <> 0', 'm2.published <> -2', 'm1.menutype = ' . $db->quote($menuType)));
         $db->setQuery($query);
         $menuAssociations[$menuType] = $db->loadAssocList('language');
     }
     $menuItemsCreated = array();
     $modulesDuplicated = array();
     foreach ($nonAssociatedMenuItems as $key => $menuItem) {
         if (!isset($menuAssociations[$menuItem->menutype])) {
             $menuAssociations[$menuItem->menutype] = array();
         }
         $associations = array();
         $insert = false;
         $insertQuery = $db->getQuery(true);
         $insertQuery->insert('#__associations')->columns(array('id', $db->quoteName('context'), $db->quoteName('key')));
         foreach ($languages as $language) {
             if ($language->lang_code !== $menuItem->language) {
                 $menuItemsCreated[$language->lang_code] = array();
                 // If there's no menu associated
                 if (empty($menuAssociations[$menuItem->menutype][$language->lang_code])) {
                     if (!isset($menuAssociations[$menuItem->menutype][$language->lang_code])) {
                         $menuAssociations[$menuItem->menutype][$language->lang_code] = array();
                     }
                     $newMenuType = new stdClass();
                     $newMenuType->menutype = $menuItem->menutype;
                     $newMenuType->title = $menuItem->menutype;
                     $newMenuType = self::createMenu($language->lang_code, $newMenuType, $defaultLanguage);
                     // If the menu has been inserted properly, let's save into the data structure
                     if (!empty($newMenuType)) {
                         $menuAssociations[$menuItem->menutype][$language->lang_code]['menutype'] = $newMenuType->menutype;
                         $menuAssociations[$menuItem->menutype][$language->lang_code]['language'] = $language->lang_code;
                     }
                 }
                 $newMenuItem = clone $menuItem;
                 unset($newMenuItem->id);
                 $newMenuItem->menutype = $menuAssociations[$menuItem->menutype][$language->lang_code]['menutype'];
                 $newMenuItem->alias = JFilterOutput::stringURLSafe($newMenuItem->alias . '-' . $language->lang_code);
                 $newMenuItem->language = $language->lang_code;
                 // If the menu item has been inserted properly, let's execute some actions
                 if ($db->insertObject('#__menu', $newMenuItem, 'id')) {
                     $menuItemsCreated[$language->lang_code][] = $newMenuItem->id;
                     // Assign all the modules to this item
                     $query = 'INSERT INTO #__modules_menu (moduleid,menuid) SELECT moduleid,' . $db->quote($newMenuItem->id) . ' FROM  #__modules_menu WHERE menuid = ' . $db->quote($menuItem->id);
                     $db->setQuery($query);
                     $db->execute();
                     $query = $db->getQuery(true);
                     $associations[] = $newMenuItem->id;
                 }
             }
         }
         // Get all the modules assigned to this menu item using a different language from *
         $query->clear()->select('m.*')->from('#__modules AS m')->innerJoin('#__modules_menu AS mm ON m.id = mm.moduleid')->where(array('mm.menuid = ' . (int) $menuItem->id, 'm.language <> ' . $db->quote('*')));
         $db->setQuery($query);
         $modules = $db->loadObjectList();
         if (!empty($modules)) {
             $query->clear()->insert('#__modules_menu')->columns(array('moduleid', 'menuid'));
             foreach ($menuItemsCreated as $language => $newMenuItems) {
                 foreach ($modules as $module) {
                     $previousId = $module->id;
                     if (!isset($modulesDuplicated[$previousId . $language]) && $module->language != $language) {
                         unset($module->id);
                         $module->language = $language;
                         $module->title = $module->title . '(' . $language . ')';
                         if ($db->insertObject('#__modules', $module, 'id')) {
                             $modulesDuplicated[$previousId . $language] = $module->id;
                         }
                     }
                     foreach ($newMenuItems as $newMenuItem) {
                         $query->values($modulesDuplicated[$previousId . $language] . ',' . $newMenuItem->id);
                     }
                 }
             }
             $db->setQuery($query);
             $db->execute();
         }
         $query->clear()->select($db->quoteName('key', 'associationKey'))->from('#__associations')->where(array('id IN (' . implode(',', array_merge($associations, array($menuItem->id))) . ')', 'context = ' . $db->quote('com_menus.item')));
         $db->setQuery($query);
         $associationKey = $db->loadResult();
         if (empty($associationKey)) {
             if (!in_array($menuItem->id, $associations)) {
                 $associations[] = $menuItem->id;
             }
             $associations = array_unique($associations);
             $associationKey = md5(json_encode($associations));
         } else {
             $query->clear()->select('id')->from('#__associations')->where($db->quoteName('key') . ' = ' . $db->quote($associationKey));
             $db->setQuery($query);
             $alreadyInserted = $db->loadArray();
             $associations = array_diff($associations, $alreadyInserted);
         }
         foreach ($associations as $association) {
             $insertQuery->values($association . ',' . $db->quote('com_menus.item') . ',' . $db->quote($associationKey));
             $insert = true;
         }
         if ($insert) {
             $db->setQuery($insertQuery);
             $db->execute();
         }
     }
     // Get all the modules with the language as default
     $query->clear()->select('m.*')->from('#__modules AS m')->where('m.language = ' . $db->quote($defaultLanguage));
     $db->setQuery($query);
     $modules = $db->loadObjectList();
     foreach ($modules as $module) {
         foreach ($languages as $language) {
             if ($language->lang_code != $defaultLanguage) {
                 if (!isset(self::$menuModuleReplicated[$language->lang_code])) {
                     self::$menuModuleReplicated[$language->lang_code] = array();
                 }
                 if (!in_array($module->id, self::$menuModuleReplicated[$language->lang_code])) {
                     self::$menuModuleReplicated[] = $module->id;
                     $previousId = $module->id;
                     $previousTitle = $module->title;
                     $module->id = 0;
                     $module->title = $previousTitle . ' (' . $language->lang_code . ')';
                     $module->language = $language->lang_code;
                     // If the module has been inserted correctly, let's assign it
                     if ($db->insertObject('#__modules', $module, 'id')) {
                         $insert = false;
                         $insertQuery = $db->getQuery(true);
                         $insertQuery->clear()->insert('#__modules_menu')->columns(array('moduleid', 'menuid'));
                         // Check if the previous module is assigned to all
                         $query->clear()->select('1')->from('#__modules_menu')->where(array('moduleid = ' . $previousId, 'menuid = 0'));
                         $db->setQuery($query);
                         $result = $db->loadResult();
                         if ($result == 1) {
                             $insertQuery->values($module->id . ', 0');
                             $insert = true;
                         } else {
                             // Check if the module has assigned selected
                             $query->clear()->select('DISTINCT m2.id')->from('#__modules_menu AS mm')->innerJoin('#__menu AS m1 ON mm.menuid = m1.id')->innerJoin('#__associations AS a1 ON a1.id = m1.id')->innerJoin('#__associations AS a2 ON a1.key = a2.key')->innerJoin('#__menu AS m2 ON a2.id = m2.id')->where(array('a1.context = ' . $db->quote('com_menus.item'), 'a2.context = ' . $db->quote('com_menus.item'), 'a1.id <> a2.id', 'm1.client_id = 0', 'm1.level <> 0', 'm1.published <> -2', 'm2.client_id = 0', 'm2.level <> 0', 'm2.published <> -2', 'mm.moduleid = ' . $previousId, 'm1.language = ' . $db->quote($defaultLanguage), 'm2.language = ' . $db->quote($language->lang_code)));
                             $db->setQuery($query);
                             $menuIds = $db->loadArray();
                             if (!empty($menuIds)) {
                                 $insert = true;
                                 foreach ($menuIds as $menuId) {
                                     $insertQuery->values($module->id . ',' . $menuId);
                                 }
                             }
                         }
                         if ($insert) {
                             $db->setQuery($insertQuery);
                             $db->execute();
                         }
                     }
                 }
             }
         }
     }
     // Fixing levels issue
     foreach ($languages as $language) {
         if ($language->lang_code !== $defaultLanguage) {
             $query->clear()->select('m1.*')->from('#__menu AS m1')->where(array('client_id = 0', 'level <> 0', 'level <> 1', 'EXISTS (SELECT 1 FROM #__menu AS m2 WHERE m2.id = m1.parent_id AND m2.language <> m1.language)'));
             $db->setQuery($query);
             $menuItemsThatNeedsToBeFixed = $db->loadObjectList();
             foreach ($menuItemsThatNeedsToBeFixed as $menuItem) {
                 $query->clear()->select('m2.id')->from('#__menu AS m1')->innerJoin('#__associations AS a1 ON a1.id = m1.id')->innerJoin('#__associations AS a2 ON a1.key = a2.key')->innerJoin('#__menu AS m2 ON a2.id = m2.id')->where(array('a1.context = ' . $db->quote('com_menus.item'), 'a2.context = ' . $db->quote('com_menus.item'), 'a1.id <> a2.id', 'm1.id = ' . $menuItem->parent_id, 'm2.language = ' . $db->quote($menuItem->language)));
                 $db->setQuery($query);
                 $parentId = (int) $db->loadResult();
                 if (!empty($parentId)) {
                     $menuItem->parent_id = $parentId;
                     $db->updateObject('#__menu', $menuItem, 'id');
                 }
             }
         }
     }
     // Once we finish restructuring menus, let's rebuild them
     $menuTable = new JTableMenu($db);
     $menuTable->rebuild();
 }
Example #6
0
 /**
  * Tests JTableNested::delete
  *
  * @return  void
  *
  * @since   11.3
  */
 public function testDelete()
 {
     $table = $this->object;
     $assetsTable = new JTableAsset(self::$dbo);
     $treeAssetsOriginal = $assetsTable->getTree('1');
     $this->assertEquals(159, count($treeAssetsOriginal), 'Line: ' . __LINE__ . ' Assets root tree should have 159 nodes');
     // Delete Sample Data weblinks (18) & children
     $table->load('18');
     $this->assertTrue($table->delete('18', true), 'Line: ' . __LINE__ . ' Should delete 18');
     // Check categories table
     $treeTemp = $table->getTree('1');
     $this->assertEquals(63, count($treeTemp), 'Line: ' . __LINE__ . ' Root tree should have 63 nodes');
     $this->checkLftRgt($treeTemp);
     $this->assertEquals('14', $treeTemp[1]->id, 'Line: ' . __LINE__ . ' id for element 1 should be 14');
     $this->assertEquals('19', $treeTemp[2]->id, 'Line: ' . __LINE__ . ' id for element 2 should be 19');
     $this->assertEquals(0, count($table->getTree('18')), 'Line: ' . __LINE__ . ' Id 18 should have been deleted');
     $this->assertEquals(0, count($table->getTree('31')), 'Line: ' . __LINE__ . ' Id 31 should have been deleted');
     // Check assets table
     $treeAssetsTemp = $assetsTable->getTree('1');
     $this->assertEquals(155, count($treeAssetsTemp), 'Line: ' . __LINE__ . ' After delete, assets root tree should have 155 nodes');
     $this->assertEquals(0, count($assetsTable->getTree('43')), 'Line: ' . __LINE__ . ' Id 43 should have been deleted from assets');
     $this->assertEquals(0, count($assetsTable->getTree('56')), 'Line: ' . __LINE__ . ' Id 56 should have been deleted from assets');
     // Delete Modules (22) and don't delete children
     // Child nodes should be moved up to parent
     $table->load('22');
     $this->assertTrue($table->delete('22', false), 'Line: ' . __LINE__ . ' Delete id 22 should be successful');
     // Check categories table
     $treeTemp = $table->getTree('1');
     $this->assertEquals(62, count($treeTemp), 'Line: ' . __LINE__ . ' Root tree should have 62 nodes');
     $this->checkLftRgt($treeTemp);
     $this->assertEquals('64', $treeTemp[5]->id, 'Line: ' . __LINE__ . ' id for element 5 should be 64');
     $this->assertEquals('4', $treeTemp[5]->level, 'Line: ' . __LINE__ . ' level for element 5 should be 4');
     $this->assertEquals('65', $treeTemp[6]->id, 'Line: ' . __LINE__ . ' id for element 6 should be 65');
     $this->assertEquals('4', $treeTemp[6]->level, 'Line: ' . __LINE__ . ' id for element 6 should be 4');
     $this->assertEquals('66', $treeTemp[7]->id, 'Line: ' . __LINE__ . ' id for element 7 should be 66');
     $this->assertEquals('4', $treeTemp[7]->level, 'Line: ' . __LINE__ . ' id for element 7 should be 4');
     $this->assertEquals('67', $treeTemp[8]->id, 'Line: ' . __LINE__ . ' id for element 8 should be 67');
     $this->assertEquals('4', $treeTemp[8]->level, 'Line: ' . __LINE__ . ' id for element 8 should be 4');
     $this->assertEquals('75', $treeTemp[9]->id, 'Line: ' . __LINE__ . ' id for element 9 should be 75');
     $this->assertEquals('4', $treeTemp[9]->level, 'Line: ' . __LINE__ . ' id for element 9 should be 4');
     $this->assertEquals(0, count($table->getTree('22')), 'Line: ' . __LINE__ . ' id 22 should be deleted');
     // Check assets table
     $treeAssetsTemp = $assetsTable->getTree('1');
     $this->assertEquals(154, count($treeAssetsTemp), 'Line: ' . __LINE__ . ' After delete, assets root tree should have 154 nodes');
     $this->assertEquals(0, count($assetsTable->getTree('47')), 'Line: ' . __LINE__ . ' Id 47 should have been deleted from assets');
     // Try using delete method without the table->load
     // It should fail and return false
     $table->reset();
     $this->assertFalse($table->delete('14'), 'Line: ' . __LINE__ . ' Table delete should fail because table->load() was not run first');
     // Delete Templates (23) without arguments (using just the $table->load)
     $table->load('23');
     $this->assertTrue($table->delete(), 'Line: ' . __LINE__ . ' Should delete id 23 and children');
     // Check categories
     $treeTemp = $table->getTree('1');
     $this->assertEquals(58, count($treeTemp), 'Line: ' . __LINE__ . ' Root tree should have 58 nodes');
     $this->checkLftRgt($treeTemp);
     $this->assertEquals('24', $treeTemp[10]->id, 'Line: ' . __LINE__ . ' id for element 10 should be 24');
     $this->assertEquals(0, count($table->getTree('23')), 'Line: ' . __LINE__ . ' id 23 should be deleted');
     // Check assets
     $treeAssetsTemp = $assetsTable->getTree('1');
     $this->assertEquals(148, count($treeAssetsTemp), 'Line: ' . __LINE__ . ' After delete, assets root tree should have 148 nodes');
     $this->assertEquals(0, count($assetsTable->getTree('48')), 'Line: ' . __LINE__ . ' Id 48 should have been deleted from assets');
     $this->assertEquals(0, count($assetsTable->getTree('98')), 'Line: ' . __LINE__ . ' Id 98 should have been deleted from assets');
     $this->assertEquals(0, count($assetsTable->getTree('147')), 'Line: ' . __LINE__ . ' Id 147 should have been deleted from assets (article)');
     $table->load('21');
     // Components no children
     $this->assertTrue($table->delete('21', false), 'Line: ' . __LINE__ . ' Should delete id 21 but not children');
     // Check categories
     $treeTemp = $table->getTree('1');
     $this->assertEquals(57, count($treeTemp), 'Line: ' . __LINE__ . ' Root tree should have 58 nodes');
     $this->checkLftRgt($treeTemp);
     $this->assertEquals('64', $treeTemp[4]->id, 'Line: ' . __LINE__ . ' id for element 4 should be 64');
     $this->assertEquals(0, count($table->getTree('21')), 'Line: ' . __LINE__ . ' id 21 should be deleted');
     // Check assets
     $treeAssetsTemp = $assetsTable->getTree('1');
     $this->assertEquals(147, count($treeAssetsTemp), 'Line: ' . __LINE__ . ' After delete, assets root tree should have 147 nodes');
     // Test table with no assets
     $menuTable = new JTableMenu(self::$dbo);
     $menuTable->load('2');
     $this->assertTrue($menuTable->delete('2', true), 'Line: ' . __LINE__ . ' Menu id 2 should be deleted');
     $treeMenuTemp = $menuTable->getTree('1');
     $this->checkLftRgt($treeMenuTemp);
     $this->assertEquals(16, count($treeMenuTemp), 'Line: ' . __LINE__ . ' Menu table should have 16 rows');
     $this->assertEquals(147, count($treeAssetsTemp), 'Line: ' . __LINE__ . ' After delete, assets root tree should still have 147 nodes');
     // Check assets
     $treeAssetsTemp = $assetsTable->getTree('1');
     $this->assertEquals(147, count($treeAssetsTemp), 'Line: ' . __LINE__ . ' Assets root tree should have 147 nodes');
     // Check lock
     $lockedTable = $this->getMock('JTableCategory', array('_lock'), array('jos_categories', 'id', self::$dbo));
     $lockedTable->expects($this->any())->method('_lock')->will($this->returnValue(false));
     $this->assertFalse($lockedTable->delete('1'), 'Line: ' . __LINE__ . ' Delete should fail because cannot lock');
 }
Example #7
0
 /**
  * Remove component entries from the appropriate table, depending on the Joomla version
  *
  * @param   string  $name  Component name
  * @return  bool
  **/
 public function deleteComponentEntry($name)
 {
     if ($this->baseDb->tableExists('#__components')) {
         // Delete component entry
         $query = "DELETE FROM `#__components` WHERE `name` = " . $this->baseDb->quote($name);
         $this->baseDb->setQuery($query);
         $this->baseDb->query();
     } else {
         $name = 'com_' . strtolower($name);
         // Delete component entry
         $query = "DELETE FROM `#__extensions` WHERE `name` = " . $this->baseDb->quote($name);
         $this->baseDb->setQuery($query);
         $this->baseDb->query();
         // Remove the component container in the assets table
         $asset = \JTable::getInstance('Asset');
         if ($asset->loadByName($name)) {
             $asset->delete();
         }
         // Check for an admin menu entry...if it's not there, create it
         $query = "DELETE FROM `#__menu` WHERE `menutype` = 'main' AND `title` = " . $this->baseDb->quote($name);
         $this->baseDb->setQuery($query);
         $this->baseDb->query();
         // If we have the nested set class available, use it to rebuild lft/rgt
         if (class_exists('JTableNested') && method_exists('JTableNested', 'rebuild')) {
             // Use the MySQL driver for this
             $database = \JDatabase::getInstance(array('driver' => 'mysql', 'host' => \Config::get('host'), 'user' => \Config::get('user'), 'password' => \Config::get('password'), 'database' => \Config::get('db')));
             $table = new \JTableMenu($database);
             $table->rebuild();
         }
     }
 }
Example #8
0
 static function rent_history($option)
 {
     global $database, $my, $Itemid, $booklibrary_configuration, $mainframe, $mosConfig_list_limit;
     PHP_booklibrary::addTitleAndMetaTags();
     //     $menu = new mosMenu($database);
     //     $menu->load( $Itemid );
     //     $params = new mosParameters( $menu->params );
     if (version_compare(JVERSION, '3.0', 'lt')) {
         $menu = new JTableMenu($database);
         // for 1.6
         $menu->load($Itemid);
         $params = new mosParameters($menu->params);
     } else {
         $menu = new JTableMenu($database);
         $menu->load($Itemid);
         $params = new JRegistry();
         $params->loadString($menu->params);
     }
     $database->setQuery("SELECT id FROM #__menu WHERE link='index.php?option=com_booklibrary'");
     if ($database->loadResult() != $Itemid) {
         $params->def('wrongitemid', '1');
     }
     if ($my->email == null) {
         echo "\n             <script type=\"text/JavaScript\" language = \"JavaScript\">\n                alert('You cannot view My Books that were not authorizated!');\n                window.history.go(-1);\n            </script>";
         exit;
     }
     $limit = $booklibrary_configuration['page']['items'];
     $limitstart = mosGetParam($_REQUEST, 'limitstart', 0);
     $database->setQuery("SELECT count(*) FROM #__booklibrary_lend AS l" . "\nLEFT JOIN #__booklibrary AS a ON a.id = l.   fk_bookid" . "\nWHERE l.fk_userid = '{$my->id}'");
     $total = $database->loadResult();
     echo $database->getErrorMsg();
     $pageNav = new JPagination($total, $limitstart, $limit);
     // for J 1.6
     $query = "SELECT l.*,a.* FROM #__booklibrary_lend AS l" . "\nLEFT JOIN #__booklibrary AS a ON a.id = l.   fk_bookid " . "\nWHERE l.fk_userid = '" . $my->id . "' LIMIT {$pageNav->limitstart},{$pageNav->limit};";
     $database->setQuery($query);
     $books = $database->loadObjectList();
     HTML_booklibrary::showRentHistory($option, $books, $pageNav, $params);
 }
 /**
  * Up
  **/
 public function up()
 {
     $query = "ALTER TABLE `#__menu` ENGINE = MYISAM;";
     $this->db->setQuery($query);
     $this->db->query();
     $first = false;
     if ($this->db->tableHasField('#__menu', 'pollid')) {
         $query = "ALTER TABLE `#__menu` DROP COLUMN `pollid`;";
         $this->db->setQuery($query);
         $this->db->query();
         $first = true;
     }
     if ($this->db->tableHasField('#__menu', 'utaccess')) {
         $query = "ALTER TABLE `#__menu` DROP COLUMN `utaccess`;";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if ($this->db->tableHasField('#__menu', 'menutype')) {
         $query = "ALTER TABLE `#__menu` MODIFY COLUMN `menutype` VARCHAR(24) NOT NULL COMMENT 'The type of menu this item belongs to. FK to #__menu_types.menutype';";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if ($this->db->tableHasField('#__menu', 'name') && !$this->db->tableHasField('#__menu', 'title')) {
         $query = "ALTER TABLE `#__menu` CHANGE COLUMN `name` `title` VARCHAR(255) NOT NULL COMMENT 'The display title of the menu item.';";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if ($this->db->tableHasField('#__menu', 'alias')) {
         $query = "ALTER TABLE `#__menu` MODIFY COLUMN `alias` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NOT NULL COMMENT 'The SEF alias of the menu item.';";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if (!$this->db->tableHasField('#__menu', 'note') && $this->db->tableHasField('#__menu', 'alias')) {
         $query = "ALTER TABLE `#__menu` ADD COLUMN `note` VARCHAR(255) NOT NULL DEFAULT '' AFTER `alias`;";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if ($this->db->tableHasField('#__menu', 'link')) {
         $query = "ALTER TABLE `#__menu` MODIFY COLUMN `link` VARCHAR(1024) NOT NULL COMMENT 'The actually link the menu item refers to.';";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if ($this->db->tableHasField('#__menu', 'type')) {
         $query = "ALTER TABLE `#__menu` MODIFY COLUMN `type` VARCHAR(16) NOT NULL COMMENT 'The type of link: Component, URL, Alias, Separator';";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if ($this->db->tableHasField('#__menu', 'published')) {
         $query = "ALTER TABLE `#__menu` MODIFY COLUMN `published` TINYINT NOT NULL DEFAULT 0 COMMENT 'The published state of the menu link.';";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if ($this->db->tableHasField('#__menu', 'parent') && !$this->db->tableHasField('#__menu', 'parent_id')) {
         $query = "ALTER TABLE `#__menu` CHANGE COLUMN `parent` `parent_id` INT(10) UNSIGNED NOT NULL DEFAULT '1' COMMENT 'The parent menu item in the menu tree.';";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if (!$this->db->tableHasField('#__menu', 'level') && $this->db->tableHasField('#__menu', 'parent_id') && $this->db->tableHasField('#__menu', 'sublevel')) {
         $query = "ALTER TABLE `#__menu` CHANGE COLUMN `sublevel` `level` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'The relative level in the tree.' AFTER `parent_id`;";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if ($this->db->tableHasField('#__menu', 'componentid') && !$this->db->tableHasField('#__menu', 'component_id')) {
         $query = "ALTER TABLE `#__menu` CHANGE COLUMN `componentid` `component_id` INTEGER UNSIGNED NOT NULL DEFAULT 0 COMMENT 'FK to #__components.id';";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if ($this->db->tableHasField('#__menu', 'ordering')) {
         $query = "ALTER TABLE `#__menu` MODIFY COLUMN `ordering` INTEGER NOT NULL DEFAULT 0 COMMENT 'The relative ordering of the menu item in the tree.';";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if ($this->db->tableHasField('#__menu', 'checked_out')) {
         $query = "ALTER TABLE `#__menu` MODIFY COLUMN `checked_out` INTEGER UNSIGNED NOT NULL DEFAULT 0 COMMENT 'FK to #__users.id';";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if ($this->db->tableHasField('#__menu', 'checked_out_time')) {
         $query = "ALTER TABLE `#__menu` MODIFY COLUMN `checked_out_time` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'The time the menu item was checked out.';";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if ($this->db->tableHasField('#__menu', 'browserNav')) {
         $query = "ALTER TABLE `#__menu` MODIFY COLUMN `browserNav` TINYINT NOT NULL DEFAULT 0 COMMENT 'The click behaviour of the link.';";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if ($this->db->tableHasField('#__menu', 'access')) {
         $query = "ALTER TABLE `#__menu` CHANGE COLUMN `access` `access` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'The access level required to view the menu item.';";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if ($this->db->tableHasField('#__menu', 'params')) {
         $query = "ALTER TABLE `#__menu` CHANGE COLUMN `params` `params` TEXT NOT NULL COMMENT 'JSON encoded data for the menu item.';";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if ($this->db->tableHasField('#__menu', 'lft')) {
         $query = "ALTER TABLE `#__menu` MODIFY COLUMN `lft` INTEGER NOT NULL DEFAULT 0 COMMENT 'Nested set lft.';";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if ($this->db->tableHasField('#__menu', 'rgt')) {
         $query = "ALTER TABLE `#__menu` MODIFY COLUMN `rgt` INTEGER NOT NULL DEFAULT 0 COMMENT 'Nested set rgt.';";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if ($this->db->tableHasField('#__menu', 'home')) {
         $query = "ALTER TABLE `#__menu` MODIFY COLUMN `home` TINYINT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Indicates if this menu item is the home or default page.';";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if (!$this->db->tableHasField('#__menu', 'path') && $this->db->tableHasField('#__menu', 'note')) {
         $query = "ALTER TABLE `#__menu` ADD COLUMN `path` VARCHAR(1024) NOT NULL COMMENT 'The computed path of the menu item based on the alias field.' AFTER `note`;";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if (!$this->db->tableHasField('#__menu', 'img') && $this->db->tableHasField('#__menu', 'access')) {
         $query = "ALTER TABLE `#__menu` ADD COLUMN `img` varchar(255) NOT NULL COMMENT 'The image of the menu item.' AFTER `access`;";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if (!$this->db->tableHasField('#__menu', 'template_style_id') && $this->db->tableHasField('#__menu', 'img')) {
         $query = "ALTER TABLE `#__menu` ADD COLUMN `template_style_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `img`;";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if (!$this->db->tableHasField('#__menu', 'language') && $this->db->tableHasField('#__menu', 'home')) {
         $query = "ALTER TABLE `#__menu` ADD COLUMN `language` char(7) NOT NULL DEFAULT '' AFTER `home`;";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if (!$this->db->tableHasField('#__menu', 'client_id') && $this->db->tableHasField('#__menu', 'language')) {
         $query = "ALTER TABLE `#__menu` ADD COLUMN `client_id` TINYINT(4) NOT NULL DEFAULT 0 AFTER `language`;";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if ($this->db->tableHasKey('#__menu', 'componentid')) {
         $query = "ALTER TABLE `#__menu` DROP INDEX `componentid`;";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if ($this->db->tableHasKey('#__menu', 'menutype')) {
         $query = "ALTER TABLE `#__menu` DROP INDEX `menutype`;";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if (!$this->db->tableHasKey('#__menu', 'idx_componentid') && $this->db->tableHasField('#__menu', 'component_id') && $this->db->tableHasField('#__menu', 'menutype') && $this->db->tableHasField('#__menu', 'published') && $this->db->tableHasField('#__menu', 'access')) {
         $query = "ALTER TABLE `#__menu` ADD INDEX `idx_componentid` (`component_id`,`menutype`,`published`,`access`);";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if (!$this->db->tableHasKey('#__menu', 'idx_menutype') && $this->db->tableHasField('#__menu', 'menutype')) {
         $query = "ALTER TABLE `#__menu` ADD INDEX `idx_menutype` (`menutype`);";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if (!$this->db->tableHasKey('#__menu', 'idx_left_right') && $this->db->tableHasField('#__menu', 'lft') && $this->db->tableHasField('#__menu', 'rgt')) {
         $query = "ALTER TABLE `#__menu` ADD INDEX `idx_left_right` (`lft`,`rgt`);";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if (!$this->db->tableHasKey('#__menu', 'idx_alias') && $this->db->tableHasField('#__menu', 'alias')) {
         $query = "ALTER TABLE `#__menu` ADD INDEX `idx_alias` (`alias`);";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if (!$this->db->tableHasKey('#__menu', 'idx_path') && $this->db->tableHasField('#__menu', 'path')) {
         $query = "ALTER TABLE `#__menu` ADD INDEX `idx_path` (`path`(333) ASC);";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if (!$this->db->tableHasKey('#__menu', 'idx_language') && $this->db->tableHasField('#__menu', 'language')) {
         $query = "ALTER TABLE `#__menu` ADD INDEX idx_language(`language`);";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if (!$this->db->tableHasKey('#__menu', 'idx_language') && $this->db->tableHasField('#__menu', 'language')) {
         $query = "ALTER TABLE `#__menu` ADD INDEX idx_language(`language`);";
         $this->db->setQuery($query);
         $this->db->query();
     }
     $query = "ALTER TABLE `#__menu_types` ENGINE = MYISAM;";
     $this->db->setQuery($query);
     $this->db->query();
     if ($this->db->tableHasField('#__menu_types', 'menutype')) {
         $query = "ALTER TABLE `#__menu_types` MODIFY COLUMN `menutype` VARCHAR(24) NOT NULL;";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if ($this->db->tableHasField('#__menu_types', 'title')) {
         $query = "ALTER TABLE `#__menu_types` MODIFY COLUMN `title` VARCHAR(48) NOT NULL;";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if ($this->db->tableHasKey('#__menu_types', 'menutype')) {
         $query = "ALTER TABLE `#__menu_types` DROP INDEX `menutype`;";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if (!$this->db->tableHasKey('#__menu_types', 'idx_menutype') && $this->db->tableHasField('#__menu_types', 'menutype')) {
         $query = "ALTER TABLE `#__menu_types` ADD UNIQUE INDEX `idx_menutype` (`menutype` ASC) ;";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if ($first) {
         // Joomla seems to expect the root item to be 1...blah!
         // So, if id 1 is taken, we need to clear it out
         $query = "SELECT * FROM `#__menu` WHERE `id` = 1;";
         $this->db->setQuery($query);
         $result = $this->db->loadObject();
         if ($result) {
             $result->id = NULL;
             $this->db->insertObject('#__menu', $result);
             $id = $this->db->insertid();
             $query = "UPDATE `#__menu` SET `parent_id` = '{$id}' WHERE `parent_id` = '1';";
             $this->db->setQuery($query);
             $this->db->query();
             $query = "UPDATE `#__modules_menu` SET `menuid` = '{$id}' WHERE `menuid` = '1';";
             $this->db->setQuery($query);
             $this->db->query();
             $query = "DELETE FROM `#__menu` WHERE `id` = '1';";
             $this->db->setQuery($query);
             $this->db->query();
         }
         // Insert new root menu item
         $query = "INSERT INTO `#__menu` (`id`, `menutype`, `title`, `alias`, `note`, `path`, `link`, `type`, `published`, `parent_id`, `level`, `component_id`, `ordering`, `checked_out`, `checked_out_time`, `browserNav`, `access`, `img`, `template_style_id`, `params`, `lft`, `rgt`, `home`, `language`, `client_id`)\n";
         $query .= "VALUES ('1', '', 'Menu_Item_Root', 'root', '', '', '', '', 1, 0, 0, 0, 0, 0, '0000-00-00 00:00:00', 0, 0, '', 0, '', 0, 0, 0, '*', 0);";
         $this->db->setQuery($query);
         $this->db->query();
         // Get the id of the new root menu item
         $query = "SELECT id FROM `#__menu` WHERE alias = 'root';";
         $this->db->setQuery($query);
         $id = $this->db->loadResult();
         // Shift the parent_id's of the existing menus to relate to the new root
         $query = "UPDATE `#__menu` SET `parent_id` = {$id} WHERE `parent_id` = 0 AND `alias` != 'root';";
         $this->db->setQuery($query);
         $this->db->query();
         // Also increment the level 1
         $query = "UPDATE `#__menu` SET `level` = `level` + 1 WHERE `alias` != 'root';";
         $this->db->setQuery($query);
         $this->db->query();
         // Build paths
         $query = "UPDATE `#__menu` SET `path` = `alias` WHERE `alias` != 'root';";
         $this->db->setQuery($query);
         $this->db->query();
         // Get max depth
         $query = "SELECT max(level) AS level FROM `#__menu`;";
         $this->db->setQuery($query);
         $maxlevel = $this->db->loadResult();
         for ($i = 2; $i <= $maxlevel; $i++) {
             $query = "SELECT * FROM `#__menu` WHERE level >= {$i};";
             $this->db->setQuery($query);
             $results = $this->db->loadObjectList();
             if (count($results) > 0) {
                 foreach ($results as $r) {
                     $query = "SELECT `alias` FROM `#__menu` WHERE `id` = {$r->parent_id};";
                     $this->db->setQuery($query);
                     $alias = $this->db->loadResult();
                     $path = $alias . '/' . $r->path;
                     $query = "UPDATE `#__menu` SET `path` = \"{$path}\" WHERE `id` = {$r->id};";
                     $this->db->setQuery($query);
                     $this->db->query();
                 }
             }
         }
         // Add entries for components menu on backend
         $query = "SELECT * FROM `#__components` WHERE `parent` = '0' AND `iscore` = '0' AND `enabled` = '1' AND `admin_menu_link` != '' AND `admin_menu_link` IS NOT NULL;";
         $this->db->setQuery($query);
         $results = $this->db->loadObjectList();
         if (count($results) > 0) {
             foreach ($results as $r) {
                 $alias = substr($r->option, 4);
                 $link = 'index.php?' . $r->admin_menu_link;
                 // Insert item
                 $query = "INSERT INTO `#__menu` (`menutype`, `title`, `alias`, `path`, `link`, `type`, `published`, `parent_id`, `level`, `component_id`, `language`, `client_id`)\n";
                 $query .= "VALUES ('main', '{$r->option}', '{$alias}', '{$alias}', '{$link}', 'component', 1, 1, 1, {$r->id}, '*', 1);";
                 $this->db->setQuery($query);
                 $this->db->query();
             }
         }
         // If we have the nested set class available, use it to rebuild lft/rgt
         if (class_exists('JTableNested') && method_exists('JTableNested', 'rebuild')) {
             // Use the MySQL driver for this
             $config = \JFactory::getConfig();
             $database = \JDatabase::getInstance(array('driver' => 'mysql', 'host' => $config->getValue('host'), 'user' => $config->getValue('user'), 'password' => $config->getValue('password'), 'database' => $config->getValue('db')));
             $table = new \JTableMenu($database);
             $table->rebuild();
         }
         // Update menu params (specifically to fix menu_image)
         $query = "SELECT `id`, `params`, `link` FROM `#__menu`;";
         $this->db->setQuery($query);
         $results = $this->db->loadObjectList();
         if (count($results) > 0) {
             foreach ($results as $r) {
                 $params = trim($r->params);
                 if (empty($params) || $params == '{}') {
                     continue;
                 }
                 $array = array();
                 $ar = explode("\n", $params);
                 foreach ($ar as $a) {
                     $a = trim($a);
                     if (empty($a)) {
                         continue;
                     }
                     $ar2 = explode("=", $a, 2);
                     if ($ar2[0] == 'menu_image' && $ar2[1] == "-1") {
                         $ar2[1] = "0";
                     }
                     $array[$ar2[0]] = isset($ar2[1]) ? $ar2[1] : '';
                 }
                 // Check to see if this menu item points to an article
                 preg_match('/index\\.php\\?option=com_content&view=article&id=([0-9]+)/', $r->link, $matches);
                 // Need to merge in content params (if applicable), as menu item params now take precidence
                 if (isset($matches[1]) && !empty($matches[1])) {
                     $query = "SELECT `attribs` FROM `#__content` WHERE `id` = '{$matches[1]}';";
                     $this->db->setQuery($query);
                     $art_params = json_decode($this->db->loadResult());
                     foreach ($art_params as $k => $v) {
                         if ($v !== null && $v !== '' && array_key_exists($k, $array)) {
                             $array[$k] = $v;
                         }
                     }
                 }
                 $query = "UPDATE `#__menu` SET `params` = " . $this->db->Quote(json_encode($array)) . " WHERE `id` = {$r->id};";
                 $this->db->setQuery($query);
                 $this->db->query();
             }
         }
         // Update component_id -> extension_id
         $query = "SELECT `id`, `link`, `component_id` FROM `#__menu` WHERE `component_id` != '0';";
         $this->db->setQuery($query);
         $results = $this->db->loadObjectList();
         if (count($results) > 0) {
             foreach ($results as $r) {
                 preg_match('/index\\.php\\?option=([a-z0-9_]+)/', $r->link, $matches);
                 if (isset($matches[1]) && !empty($matches[1])) {
                     $query = "SELECT `extension_id` FROM `#__extensions` WHERE `element` = '{$matches[1]}' AND `type` = 'component' ORDER BY `client_id` ASC LIMIT 1;";
                     $this->db->setQuery($query);
                     $id = $this->db->loadResult();
                     $id = !is_null($id) ? $id : '0';
                     $query = "UPDATE `#__menu` SET `component_id` = '{$id}' WHERE `id` = '{$r->id}';";
                     $this->db->setQuery($query);
                     $this->db->query();
                 }
             }
         }
         // Set language for all menu items
         $query = "UPDATE `#__menu` SET `language` = '*';";
         $this->db->setQuery($query);
         $this->db->query();
         // Fix com_user->com_users in menu items
         $query = "SELECT `extension_id` FROM `#__extensions` WHERE `element` = 'com_users';";
         $this->db->setQuery($query);
         $id = $this->db->loadResult();
         $query = "SELECT * FROM `#__menu` WHERE `menutype` = 'default' AND (`alias` = 'login' OR `alias` = 'logout' OR `alias` = 'remind' OR `alias` = 'reset');";
         $this->db->setQuery($query);
         if ($results = $this->db->loadObjectList()) {
             foreach ($results as $r) {
                 $link = preg_replace('/(index\\.php\\?option=com_user)(&view=[a-z]+)/', '${1}s${2}', $r->link);
                 $params = json_decode($r->params);
                 if ($r->alias == 'login') {
                     $params->login_redirect_url = $params->login;
                     unset($params->login);
                 }
                 $query = "UPDATE `#__menu` SET `link` = " . $this->db->quote($link) . ", `component_id` = '{$id}', `params` = " . $this->db->quote(json_encode($params)) . " WHERE `id` = '{$r->id}';";
                 $this->db->setQuery($query);
                 $this->db->query();
             }
         }
         // Fix menu link type menu items to be alias type
         $query = "UPDATE `#__menu` SET `type` = 'alias', `link` = 'index.php?Itemid=', `params` = REPLACE(`params`, 'menu_item', 'aliasoptions') WHERE `type` = 'menulink'";
         $this->db->setQuery($query);
         $this->db->query();
     }
     // Now we can get rid of the components table as well
     if ($this->db->tableExists('#__components')) {
         $query = "DROP TABLE IF EXISTS `#__components`;";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if (!$this->db->tableHasKey('#__menu', 'idx_client_id_parent_id_alias_language') && $this->db->tableHasField('#__menu', 'client_id') && $this->db->tableHasField('#__menu', 'parent_id') && $this->db->tableHasField('#__menu', 'alias') && $this->db->tableHasField('#__menu', 'language')) {
         $query = "ALTER TABLE `#__menu` ADD INDEX `idx_client_id_parent_id_alias_language` (`client_id` ASC, `parent_id` ASC, `alias` ASC, `language` ASC);";
         $this->db->setQuery($query);
         $this->db->query();
     }
 }
Example #10
0
 /**
  * Overloaded store function
  *
  * @param   boolean  $updateNulls  True to update fields even if they are null.
  *
  * @return  mixed  False on failure, positive integer on success.
  *
  * @see     JTable::store
  * @since   11.1
  */
 public function store($updateNulls = false)
 {
     $db = JFactory::getDBO();
     // Verify that the alias is unique
     $table = JTable::getInstance('Menu', 'JTable');
     // re-do alias:
     if (!$this->checkAlias($table)) {
         //stAn, this should never be reached
         if ($this->menutype == $table->menutype) {
             $this->setError(JText::_('JLIB_DATABASE_ERROR_MENU_UNIQUE_ALIAS'));
         } else {
             $this->setError(JText::_('JLIB_DATABASE_ERROR_MENU_UNIQUE_ALIAS_ROOT'));
         }
         return false;
     }
     // Verify that the home page for this language is unique
     if ($this->home == '1') {
         $table = JTable::getInstance('Menu', 'JTable');
         if ($table->load(array('home' => '1', 'language' => $this->language))) {
             if ($table->checked_out && $table->checked_out != $this->checked_out) {
                 $this->setError(JText::_('JLIB_DATABASE_ERROR_MENU_DEFAULT_CHECKIN_USER_MISMATCH'));
                 return false;
             }
             $table->home = 0;
             $table->checked_out = 0;
             $table->checked_out_time = $db->getNullDate();
             $table->store();
         }
         // Verify that the home page for this menu is unique.
         if ($table->load(array('home' => '1', 'menutype' => $this->menutype)) && ($table->id != $this->id || $this->id == 0)) {
             $this->setError(JText::_('JLIB_DATABASE_ERROR_MENU_HOME_NOT_UNIQUE_IN_MENU'));
             return false;
         }
     }
     if (empty($this->parent_id)) {
         var_dump($this);
         die('empty parent_id !');
     }
     if (!parent::store($updateNulls)) {
         return false;
     }
     // Get the new path in case the node was moved
     /*
     $pathNodes = $this->getPath();
     $segments = array();
     foreach ($pathNodes as $node)
     {
     	// Don't include root in path
     	if ($node->alias != 'root')
     	{
     		$segments[] = $node->alias;
     	}
     }
     $newPath = trim(implode('/', $segments), ' /\\');
     */
     $newPath = $this->path;
     // Use new path for partial rebuild of table
     // Rebuild will return positive integer on success, false on failure
     //var_dump("{$this->_tbl_key}");
     //var_dump($this->{$this->_tbl_key}); die();
     //$parent = $this->{$this->_tbl_key};
     $parent = $this->parent_id;
     return $this->rebuild($parent, $this->lft, $this->level, $newPath) > 0;
 }