📄 helper.php
字号:
* and adding core modules from old site to the modules table * * @static * @param JDatabase * @param array errors (by ref) * @return error count * @since 1.5 */ function postMigrate( $db, & $errors, & $args ) { $newPrefix = $args['DBPrefix']; /* * Check to see if migration is from 4.5.1 */ $query = 'SELECT id FROM '.$newPrefix.'users WHERE usertype = "superadministrator"'; $db->setQuery($query); $rows = $db->loadRowList( ); JInstallationHelper::getDBErrors($errors, $db ); /* * if it is, then fill usertype field with correct values from aro_group */ if ( count($rows) > 0 ) { $query = 'UPDATE '.$newPrefix.'users AS u, '.$newPrefix.'core_acl_aro_groups AS g' . ' SET u.usertype = g.value' . ' WHERE u.gid = g.id'; $db->setQuery($query); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); } /* * Construct the menu table based on old table references to core items */ // Component - change all $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `type` = "component" WHERE `type` = "components";'; $db->setQuery( $query ); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); // Component Item Link $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = SUBSTRING(link, 1, LOCATE("&Itemid=", link) -1), `type` = "component" WHERE `type` = "component_item_link";'; $db->setQuery( $query ); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); // get com_contact id $query = 'SELECT `id` FROM `'.$newPrefix.'components` WHERE `option`="com_contact" AND `parent` = 0'; $db->setQuery( $query ); JInstallationHelper::getDBErrors($errors, $db ); $compId = $db->loadResult(); // contact category table $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = INSERT(link, LOCATE("catid=", link), 0, "view=category&"), `type` = "component", `componentid` = '.$compId.' WHERE `type` = "contact_category_table"'; $db->setQuery( $query ); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); // contact item link $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = INSERT(link, LOCATE("task=view", link), 20, "view=contact&id"), `type` = "component", `componentid` = '.$compId.' WHERE `type` = "contact_item_link"'; $db->setQuery( $query ); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); // fix up standalone contact $query = 'UPDATE `'. $newPrefix.'menu_migration` SET `link` = "index.php?option=com_contact&view=category" WHERE `link` = "index.php?option=com_contact"'; $db->setQuery( $query ); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); // get com_content id $query = 'SELECT `id` FROM `'.$newPrefix.'components` WHERE `option`="com_content" AND `parent` = 0'; $db->setQuery( $query ); $compId = $db->loadResult(); JInstallationHelper::getDBErrors($errors, $db ); // front page $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = "index.php?option=com_content&view=frontpage", `type` = "component", `componentid` = '.$compId.' WHERE `link` LIKE "%option=com_frontpage%"'; $db->setQuery( $query ); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); // content archive category or section $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = "index.php?option=com_content&view=archive", `type` = "component", `componentid` = '.$compId.' WHERE (`type` = "content_archive_category" OR `type` = "content_archive_section")'; $db->setQuery( $query ); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); // content blog category $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = INSERT(link, LOCATE("task=blogcat", link), 17, "view=category&layout=blog"), `type` = "component", `componentid` = '.$compId.' WHERE `type` = "content_blog_category"'; $db->setQuery( $query ); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); // content blog section $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = INSERT(link, LOCATE("task=blogsec", link), 16, "view=section&layout=blog"), `type` = "component", `componentid` = '.$compId.' WHERE `type` = "content_blog_section";'; $db->setQuery( $query ); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); // content category $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = INSERT(link, LOCATE("task=", link), LOCATE("&id=", link) - LOCATE("task=", link), "view=category"), `type` = "component", `componentid` = '.$compId.' WHERE `type` = "content_category"'; $db->setQuery( $query ); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); // content item link and typed content $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = INSERT(link, LOCATE("task=", link), 9, "view=article"), `type` = "component", `componentid` = '.$compId.' WHERE (`type` = "content_item_link" OR `type` = "content_typed")'; $db->setQuery( $query ); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); // content section $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = INSERT(link, LOCATE("task=", link), 12, "view=section"), `type` = "component", `componentid` = '.$compId.' WHERE `type` = "content_section"'; $db->setQuery( $query ); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); // get com_newsfeeds id $query = 'SELECT `id` FROM `'.$newPrefix.'components` WHERE `option`="com_newsfeeds" AND `parent` = 0'; $db->setQuery( $query ); $compId = $db->loadResult(); JInstallationHelper::getDBErrors($errors, $db ); // newsfeed categories $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = CONCAT(link, "&view=categories"), `componentid` = '.$compId.' WHERE `type` = "component" AND link LIKE "%option=com_newsfeeds%"'; $db->setQuery( $query ); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); // newsfeed category table $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = INSERT(link, LOCATE("catid=", link), 5, "view=category&catid"), `type` = "component", `componentid` = '.$compId.' WHERE `type` = "newsfeed_category_table"'; $db->setQuery( $query ); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); // newsfeed link $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = INSERT(link, LOCATE("task=", link), 9, "view=newsfeed"), `type` = "component", `componentid` = '.$compId.' WHERE `type` = "newsfeed_link"'; $db->setQuery( $query ); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); // user checkin items $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = INSERT(link, LOCATE("CheckIn", link), 7, "checkin") WHERE `type` = "url" AND link LIKE "%option=com_user&task=CheckIn%"'; $db->setQuery( $query ); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); // user edit details $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = INSERT(link, LOCATE("UserDetails", link), 11, "edit") WHERE `type` = "url" AND link LIKE "%option=com_user&task=UserDetails%"'; $db->setQuery( $query ); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); // get com_weblinks id $query = 'SELECT `id` FROM `'.$newPrefix.'components` WHERE `option`="com_weblinks" AND `parent` = 0'; $db->setQuery( $query ); $compId = $db->loadResult(); JInstallationHelper::getDBErrors($errors, $db ); // weblinks categories $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = CONCAT(link, "&view=categories"), `componentid` = '.$compId.' WHERE `type` = "component" AND link LIKE "%option=com_weblinks%"'; $db->setQuery( $query ); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); // weblinks category table $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = INSERT(link, LOCATE("catid=", link), 5, "view=category&catid"), `type` = "component", `componentid` = '.$compId.' WHERE `type` = "weblink_category_table"'; $db->setQuery( $query ); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); // weblinks submit new item $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = INSERT(link, LOCATE("task=", link), 8, "view=weblink&layout=form") WHERE `type` = "url" AND link LIKE "%option=com_weblinks%"'; $db->setQuery( $query ); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); // get com_wrapper id $query = 'SELECT `id` FROM `'.$newPrefix.'components` WHERE `option`="com_wrapper" AND `parent` = 0'; $db->setQuery( $query ); JInstallationHelper::getDBErrors($errors, $db ); $compId = $db->loadResult(); // wrapper $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = CONCAT(link, "&view=wrapper"), `type` = "component", `componentid` = '.$compId.' WHERE `type` = "wrapper"'; $db->setQuery( $query ); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); // set default to lowest ordering published on mainmenu $query = 'SELECT MIN( `ordering` ) FROM `'.$newPrefix.'menu_migration` WHERE `published` = 1 AND `parent` = 0 AND `menutype` = "mainmenu"'; $db->setQuery( $query ); $minorder = $db->loadResult(); if(!$minorder) $minorder = 0; JInstallationHelper::getDBErrors($errors, $db ); $query = 'SELECT `id` FROM `'.$newPrefix.'menu_migration` WHERE `published` = 1 AND `parent` = 0 AND `menutype` = "mainmenu" AND `ordering` = '.$minorder; $db->setQuery( $query ); $menuitemid = $db->loadResult(); JInstallationHelper::getDBErrors($errors, $db ); if(!$menuitemid) $menuitemid = 1; $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `home` = 1 WHERE `id` = '.$menuitemid; $db->setQuery( $query ); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); // login and log out; component id and link update $query = 'SELECT id FROM `'.$newPrefix.'components` WHERE link like "option=com_user"'; $db->setQuery($query); $componentid = $db->loadResult(); JInstallationHelper::getDBErrors($errors, $db ); $query = 'UPDATE `'.$newPrefix.'menu_migration` SET componentid = '.$componentid .' WHERE link = "index.php?option=com_login"'; $db->setQuery($query); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); $query = 'UPDATE `'.$newPrefix.'menu_migration` SET link = "index.php?option=com_user&view=login" WHERE link = "index.php?option=com_login"'; $db->setQuery($query); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); // Search - Component ID Update $query = 'SELECT id FROM `'.$newPrefix.'components` WHERE link like "option=com_search"'; $db->setQuery($query); $componentid = $db->loadResult(); JInstallationHelper::getDBErrors($errors, $db ); $query = 'UPDATE `'.$newPrefix.'menu_migration` SET componentid = '.$componentid .' WHERE link like "index.php?option=com_search%"'; $db->setQuery($query); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); // tidy up urls with Itemids $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = SUBSTRING(`link`,1,LOCATE("&Itemid",`link`)-1) WHERE `type` = "url" AND `link` LIKE "%&Itemid=%"'; $db->setQuery( $query ); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); $query = 'SELECT DISTINCT `option` FROM '.$newPrefix.'components WHERE `option` != ""'; $db->setQuery( $query ); $lookup = $db->loadResultArray(); JInstallationHelper::getDBErrors($errors, $db ); $lookup[] = 'com_user&'; // prepare to copy across $query = 'SELECT * FROM '.$newPrefix.'menu_migration'; $db->setQuery( $query ); $oldMenuItems = $db->loadObjectList(); JInstallationHelper::getDBErrors($errors, $db ); $query = 'DELETE FROM '.$newPrefix.'menu WHERE 1'; $db->setQuery( $query ); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); $query = 'SELECT * FROM '.$newPrefix.'menu'; $db->setQuery( $query ); $newMenuItems = $db->loadObjectList(); JInstallationHelper::getDBErrors($errors, $db ); // filter out links to 3pd components foreach( $oldMenuItems as $item ) { if ( $item->type == 'url' && !strpos( $item->link, 'com_') ) { $newMenuItems[] = $item; } else if ( $item->type == 'url' && JInstallationHelper::isValidItem( $item->link, $lookup ) ) { $newMenuItems[] = $item; } else if ( $item->type == 'component' ) //&& JInstallationHelper::isValidItem( $item->link, $lookup )) { // unpublish components that don't exist yet if(!JInstallationHelper::isValidItem( $item->link, $lookup )) $item->published = 0; $newMenuItems[] = $item; } } // build the menu table foreach ( $newMenuItems as $item ) { $db->insertObject( $newPrefix.'menu', $item ); JInstallationHelper::getDBErrors($errors, $db ); } // fix possible orphaned sub menu items $query = 'UPDATE `'.$newPrefix.'menu` AS c LEFT OUTER JOIN `'.$newPrefix.'menu` AS p ON c.parent = p.id SET c.parent = 0 WHERE c.parent <> 0 AND p.id IS NULL'; $db->setQuery( $query ); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); /* * Construct the menu_type table base on new menu table types */ $query = 'SELECT DISTINCT `menutype` FROM '.$newPrefix.'menu WHERE 1'; $db->setQuery( $query ); JInstallationHelper::getDBErrors($errors, $db ); $menuTypes = $db->loadResultArray(); $query = 'TRUNCATE TABLE '.$newPrefix.'menu_types'; $db->setQuery($query); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); foreach( $menuTypes as $mType ) { $query = 'INSERT INTO '.$newPrefix.'menu_types ( menutype, title ) VALUES ("'.$mType.'", "'.$mType.'");'; $db->setQuery($query); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); } /* * Add core client modules from old site to modules table as unpublished */ $query = 'SELECT id FROM '.$newPrefix.'modules_migration WHERE client_id = 0 '; $db->setQuery( $query ); $lookup = $db->loadResultArray(); JInstallationHelper::getDBErrors($errors, $db ); $query = 'SELECT MAX(id) FROM '.$newPrefix.'modules '; $db->setQuery( $query ); $nextId = $db->loadResult(); JInstallationHelper::getDBErrors($errors, $db ); jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.file'); foreach( $lookup as $module ) { $qry = 'SELECT * FROM '.$newPrefix.'modules_migration WHERE id = "'.$module.'" AND client_id = 0'; $db->setQuery( $qry ); if ( $row = $db->loadObject() ) { if($row->module == '') { $row->module = 'mod_custom'; } if(JFolder::exists(JPATH_SITE.DS.'modules'.DS.$row->module)) { $nextId++; $oldid = $row->id; $row->id = $nextId; $row->published = 0; if($db->insertObject( $newPrefix.'modules', $row )) { // Grab the old modules menu links and put them in too! $qry = 'SELECT * FROM '. $newPrefix .'modules_migration_menu WHERE moduleid = '. $oldid; $db->setQuery($qry); $entries = $db->loadObjectList(); JInstallationHelper::getDBErrors($errors, $db ); foreach($entries as $entry) { $entry->moduleid = $nextId; $db->insertObject($newPrefix.'modules_menu', $entry); JInstallationHelper::getDBErrors($errors, $db ); } } else JInstallationHelper::getDBErrors($errors, $db ); } // else the module doesn't exist? } else JInstallationHelper::getDBErrors($errors, $db ); } // Put in breadcrumb module as per sample data $query = "INSERT INTO `".$newPrefix ."modules` VALUES (0, 'Breadcrumbs', '', 1, 'breadcrumb', 0, '0000-00-00 00:00:00', 1, 'mod_breadcrumbs', 0, 0, 1, 'moduleclass_sfx=\ncache=0\nshowHome=1\nhomeText=Home\nshowComponent=1\nseparator=\n\n', 1, 0, '');"; $db->setQuery($query); $db->Query(); JInstallationHelper::getDBErrors($errors, $db); /* * Clean up */ $query = 'DROP TABLE IF EXISTS '.$newPrefix.'modules_migration'; $db->setQuery( $query ); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); $query = 'DROP TABLE IF EXISTS '.$newPrefix.'modules_migration_menu'; $db->setQuery( $query ); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); $query = 'DROP TABLE IF EXISTS '.$newPrefix.'menu_migration'; $db->setQuery( $query ); $db->query(); JInstallationHelper::getDBErrors($errors, $db ); return count( $errors ); } function isValidItem ( $link, $lookup ) { foreach( $lookup as $component ) { if ( strpos( $link, $component ) != false ) { return true; } } return false; } function getDBErrors( & $errors, $db ) { if ($db->getErrorNum() > 0) { $errors[] = array('msg' => $db->getErrorMsg(), 'sql' => $db->_sql); } } /** * Inserts ftp variables to mainframe registry * Needed to activate ftp layer for file operations in safe mode * * @param array The post values */ function setFTPCfg( $vars ) { global $mainframe; $arr = array(); $arr['ftp_enable'] = $vars['ftpEnable']; $arr['ftp_user'] = $vars['ftpUser']; $arr['ftp_pass'] = $vars['ftpPassword']; $arr['ftp_root'] = $vars['ftpRoot']; $arr['ftp_host'] = $vars['ftpHost']; $arr['ftp_port'] = $vars['ftpPort']; $mainframe->setCfg( $arr, 'config' ); } function _chmod( $path, $mode ) { global $mainframe; $ret = false; // Initialize variables $ftpFlag = true; $ftpRoot = $mainframe->getCfg('ftp_root'); // Do NOT use ftp if it is not enabled if ($mainframe->getCfg('ftp_enable') != 1) { $ftpFlag = false; } if ($ftpFlag == true) { // Connect the FTP client jimport('joomla.client.ftp'); $ftp = & JFTP::getInstance($mainframe->getCfg('ftp_host'), $mainframe->getCfg('ftp_port')); $ftp->login($mainframe->getCfg('ftp_user'), $mainframe->getCfg('ftp_pass')); //Translate the destination path for the FTP account $path = JPath::clean(str_replace(JPATH_SITE, $ftpRoot, $path), '/'); // do the ftp chmod if (!$ftp->chmod($path, $mode)) { // FTP connector throws an error return false; } $ftp->quit(); $ret = true; } else { $ret = @ chmod($path, $mode); } return $ret; } /** Borrowed from http://au.php.net/manual/en/ini.core.php comments */ function let_to_num($v){ //This function transforms the php.ini notation for numbers (like '2M') to an integer (2*1024*1024 in this case) $l = substr($v, -1); $ret = substr($v, 0, -1); switch(strtoupper($l)){ case 'P': $ret *= 1024; case 'T': $ret *= 1024; case 'G': $ret *= 1024; case 'M': $ret *= 1024; case 'K': $ret *= 1024; break; } return $ret; }}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -