5 * @version $Id: ModuleInstallUtils.class.php,v 1.11 2008/10/26 04:07:23 minahito Exp $
6 * @copyright Copyright 2005-2007 XOOPS Cube Project <http://xoopscube.sourceforge.net/>
7 * @license http://xoopscube.sourceforge.net/license/GPL_V2.txt GNU GENERAL PUBLIC LICENSE Version 2
11 if (!defined('XOOPS_ROOT_PATH')) exit();
13 require_once XOOPS_LEGACY_PATH . "/admin/class/ModuleInstallInformation.class.php";
14 require_once XOOPS_LEGACY_PATH . "/admin/class/ModuleInstaller.class.php";
15 require_once XOOPS_LEGACY_PATH . "/admin/class/ModuleUpdater.class.php";
16 require_once XOOPS_LEGACY_PATH . "/admin/class/ModuleUninstaller.class.php";
18 require_once XOOPS_ROOT_PATH."/class/template.php";
20 define("MODINSTALL_LOGTYPE_REPORT", "report");
21 define("MODINSTALL_LOGTYPE_WARNING", "warning");
22 define("MODINSTALL_LOGTYPE_ERROR", "error");
25 * A temporary log class.
27 class Legacy_ModuleInstallLog
29 var $mFetalErrorFlag = false;
30 var $mMessages = array();
34 $this->mMessages[] = array('type' => MODINSTALL_LOGTYPE_REPORT, 'message' => $msg);
37 function addReport($msg)
42 function addWarning($msg)
44 $this->mMessages[] = array('type' => MODINSTALL_LOGTYPE_WARNING, 'message' => $msg);
47 function addError($msg)
49 $this->mMessages[] = array('type' => MODINSTALL_LOGTYPE_ERROR, 'message' => $msg);
50 $this->mFetalErrorFlag = true;
55 return $this->mFetalErrorFlag;
60 * This class is collection of static utility functions for module installation.
61 * These functions are useful for Legacy modules' system-fixed-installer and
62 * modules' custom-installer. All functions for the custom-installer are added
63 * notes as "FOR THE CUSTOM-ISNTALLER".
65 * For more attentions, see base classes for the custom-installer.
67 * @see Legacy_PhasedUpgrader
69 class Legacy_ModuleInstallUtils
72 * This is factory for the installer. The factory reads xoops_version
73 * without modulehandler, to prevent cache in modulehandler.
75 function &createInstaller($dirname)
77 $installer =& Legacy_ModuleInstallUtils::_createInstaller($dirname, 'installer', 'Legacy_ModuleInstaller');
82 * This is factory for the updater. The factory reads xoops_version
83 * without modulehandler, to prevent cache in modulehandler.
85 function &createUpdater($dirname)
87 $updater =& Legacy_ModuleInstallUtils::_createInstaller($dirname, 'updater', 'Legacy_ModulePhasedUpgrader');
92 * This is factory for the uninstaller. The factory reads xoops_version
93 * without modulehandler, to prevent cache in modulehandler.
95 function &createUninstaller($dirname)
97 $uninstaller =& Legacy_ModuleInstallUtils::_createInstaller($dirname, 'uninstaller', 'Legacy_ModuleUninstaller');
102 * The generic factory for installers. This function is used by other
104 * @param string $dirname
105 * @param string $mode 'installer' 'updater' or 'uninstaller'
106 * @param string $defaultClassName
108 function &_createInstaller($dirname, $mode, $defaultClassName)
112 $filepath = XOOPS_MODULE_PATH . "/${dirname}/xoops_version.php";
113 if (file_exists($filepath)) {
118 if (isset($info['legacy_installer']) && is_array($info['legacy_installer']) && isset($info['legacy_installer'][$mode])) {
119 $updateInfo = $info['legacy_installer'][$mode];
121 $className = $updateInfo['class'];
122 $filePath = isset($updateInfo['filepath']) ? $updateInfo['filepath'] : XOOPS_MODULE_PATH . "/${dirname}/admin/class/${className}.class.php";
123 $namespace = isset($updateInfo['namespace']) ? $updateInfo['namespace'] : ucfirst($dirname);
125 if ($namespace != null) {
126 $className = "${namespace}_${className}";
129 if (!XC_CLASS_EXISTS($className) && file_exists($filePath)) {
130 require_once $filePath;
133 if (XC_CLASS_EXISTS($className)) {
134 $installer =& new $className();
139 $installer =& new $defaultClassName();
145 * Executes SQL file which xoops_version of $module specifies. This
146 * function is usefull for installers, but it's impossible to control
150 * @param XoopsModule $module
151 * @param Legacy_ModuleInstallLog $log
152 * @note FOR THE CUSTOM-INSTALLER
154 function installSQLAutomatically(&$module, &$log)
156 $sqlfileInfo =& $module->getInfo('sqlfile');
157 $dirname = $module->getVar('dirname');
159 if (!isset($sqlfileInfo[XOOPS_DB_TYPE])) {
163 $sqlfile = $sqlfileInfo[XOOPS_DB_TYPE];
164 $sqlfilepath = XOOPS_MODULE_PATH . "/${dirname}/${sqlfile}";
166 if (isset($module->modinfo['cube_style']) && $module->modinfo['cube_style'] == true) {
167 require_once XOOPS_MODULE_PATH . "/legacy/admin/class/Legacy_SQLScanner.class.php";
168 $scanner =& new Legacy_SQLScanner();
169 $scanner->setDB_PREFIX(XOOPS_DB_PREFIX);
170 $scanner->setDirname($module->get('dirname'));
172 if (!$scanner->loadFile($sqlfilepath)) {
173 $log->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_SQL_FILE_NOT_FOUND, $sqlfile));
178 $sqls = $scanner->getSQL();
180 $root =& XCube_Root::getSingleton();
181 $db =& $root->mController->getDB();
184 // TODO The following variable exists for rollback, but it is not implemented.
186 foreach ($sqls as $sql) {
187 if (!$db->query($sql)) {
188 $log->addError($db->error());
193 $log->addReport(_AD_LEGACY_MESSAGE_DATABASE_SETUP_FINISHED);
196 require_once XOOPS_ROOT_PATH.'/class/database/sqlutility.php';
198 $reservedTables = array('avatar', 'avatar_users_link', 'block_module_link', 'xoopscomments', 'config', 'configcategory', 'configoption', 'image', 'imagebody', 'imagecategory', 'groups','groups_users_link','group_permission', 'priv_msgs', 'ranks', 'session', 'smiles', 'users', 'newblocks', 'modules', 'tplfile', 'tplset', 'tplsource');
200 $root =& XCube_Root::getSingleton();
201 $db =& $root->mController->mDB;
203 $sql_query = fread(fopen($sqlfilepath, 'r'), filesize($sqlfilepath));
204 $sql_query = trim($sql_query);
205 SqlUtility::splitMySqlFile($pieces, $sql_query);
206 $created_tables = array();
207 foreach ($pieces as $piece) {
208 // [0] contains the prefixed query
209 // [4] contains unprefixed table name
210 $prefixed_query = SqlUtility::prefixQuery($piece, $db->prefix());
211 if (!$prefixed_query) {
212 $log->addError("${piece} is not a valid SQL!");
216 // check if the table name is reserved
217 if (!in_array($prefixed_query[4], $reservedTables)) {
218 // not reserved, so try to create one
219 if (!$db->query($prefixed_query[0])) {
220 $log->addError($db->error());
224 if (!in_array($prefixed_query[4], $created_tables)) {
225 $log->addReport(' Table ' . $db->prefix($prefixed_query[4]) . ' created.');
226 $created_tables[] = $prefixed_query[4];
229 $log->addReport(' Data inserted to table ' . $db->prefix($prefixed_query[4]));
234 // the table name is reserved, so halt the installation
235 $log->addError($prefixed_query[4] . " is a reserved table!");
243 * Installs all of module templates $module specify. This function is
244 * usefull for installer and updater. In the case of updater, you should
245 * uninstall all of module templates before this function.
247 * This function gets informations about templates from xoops_version.
251 * This function depends the specific spec of Legacy_RenderSystem, but this
252 * static function is needed by the 2nd installer of Legacy System.
255 * @param XoopsModule $module
256 * @param Legacy_ModuleInstallLog $log
257 * @note FOR THE CUSTOM-INSTALLER
258 * @see Legacy_ModuleInstallUtils::uninstallAllOfModuleTemplates()
260 function installAllOfModuleTemplates(&$module, &$log)
262 $templates = $module->getInfo('templates');
263 if ($templates != false) {
264 foreach ($templates as $template) {
265 Legacy_ModuleInstallUtils::installModuleTemplate($module, $template, $log);
271 * Inserts the specified template to DB.
275 * This function depends the specific spec of Legacy_RenderSystem, but this
276 * static function is needed by the 2nd installer of Legacy System.
279 * @param XoopsModule $module
280 * @param string[][] $template
281 * @param Legacy_ModuleInstallLog $log
284 * @note This is not usefull a litte for custom-installers.
285 * @todo We'll need the way to specify the template by identity or others.
287 function installModuleTemplate($module, $template, &$log)
289 $tplHandler =& xoops_gethandler('tplfile');
291 $fileName = trim($template['file']);
293 $tpldata = Legacy_ModuleInstallUtils::readTemplateFile($module->get('dirname'), $fileName);
294 if ($tpldata == false)
298 // Create template file object, then store it.
300 $tplfile =& $tplHandler->create();
301 $tplfile->setVar('tpl_refid', $module->getVar('mid'));
302 $tplfile->setVar('tpl_lastimported', 0);
303 $tplfile->setVar('tpl_lastmodified', time());
305 if (preg_match("/\.css$/i", $fileName)) {
306 $tplfile->setVar('tpl_type', 'css');
309 $tplfile->setVar('tpl_type', 'module');
312 $tplfile->setVar('tpl_source', $tpldata, true);
313 $tplfile->setVar('tpl_module', $module->getVar('dirname'));
314 $tplfile->setVar('tpl_tplset', 'default');
315 $tplfile->setVar('tpl_file', $fileName, true);
317 $description = isset($template['description']) ? $template['description'] : '';
318 $tplfile->setVar('tpl_desc', $description, true);
320 if ($tplHandler->insert($tplfile)) {
321 $log->addReport(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_TEMPLATE_INSTALLED, $fileName));
324 $log->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_COULD_NOT_INSTALL_TEMPLATE, $fileName));
330 * Uninstalls all of module templates $module specify. This function is
331 * usefull for uninstaller and updater. In the case of update, you should
332 * call this function before installAllOfModuleTemplates(). In the case of
333 * uninstall, you must set 'false' to $defaultOnly.
335 * This function gets informations about templates from the database.
339 * This function depends the specific spec of Legacy_RenderSystem, but this
340 * static function is needed by the 2nd installer of Legacy System.
343 * @param XoopsModule $module
344 * @param Legacy_ModuleInstallLog $log
345 * @param bool $defaultOnly Indicates whether this function deletes templates from all of tplsets.
346 * @note FOR THE CUSTOM-INSTALLER
347 * @see Legacy_ModuleInstallUtils::installAllOfModuleTemplates()
349 function _uninstallAllOfModuleTemplates(&$module, $tplset, &$log)
352 // The following processing depends on the structure of Legacy_RenderSystem.
354 $tplHandler =& xoops_gethandler('tplfile');
355 $delTemplates = null;
357 $delTemplates =& $tplHandler->find($tplset, 'module', $module->get('mid'));
359 if (is_array($delTemplates) && count($delTemplates) > 0) {
363 $xoopsTpl =& new XoopsTpl();
364 $xoopsTpl->clear_cache(null, "mod_" . $module->get('dirname'));
366 foreach ($delTemplates as $tpl) {
367 if (!$tplHandler->delete($tpl)) {
368 $log->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_TEMPLATE_UNINSTALLED, $tpl->get('tpl_file')));
374 function uninstallAllOfModuleTemplates(&$module, &$log)
376 Legacy_ModuleInstallUtils::_uninstallAllOfModuleTemplates($module, null, $log);
379 function clearAllOfModuleTemplatesForUpdate(&$module, &$log)
381 Legacy_ModuleInstallUtils::_uninstallAllOfModuleTemplates($module, 'default', $log);
385 * Installs all of blocks $module specify.
387 * This function gets informations about blocks from xoops_version.
390 * @param XoopsModule $module
391 * @param Legacy_ModuleInstallLog $log
392 * @note FOR THE CUSTOM-INSTALLER
393 * @see Legacy_ModuleInstallUtils::uninstallAllOfBlocks()
395 function installAllOfBlocks(&$module, &$log)
397 $definedBlocks = $module->getInfo('blocks');
398 if($definedBlocks == false) {
403 foreach ($definedBlocks as $block) {
405 $updateblocks = array();
407 // Try (1) --- func_num
408 foreach ($definedBlocks as $idx => $block) {
409 if (isset($block['func_num'])) {
410 $updateblocks[$idx] = $block;
412 $successFlag = false;
417 // Try (2) --- index pattern
418 if ($successFlag == false) {
420 $updateblocks = array();
421 foreach ($definedBlocks as $idx => $block) {
423 $block['func_num'] = $idx;
424 $updateblocks[$idx] = $block;
426 $successFlag = false;
432 // Try (3) --- automatic
433 if ($successFlag == false) {
435 $updateblocks = array();
438 foreach ($definedBlocks as $block) {
439 $block['func_num'] = $func_num;
440 $updateblocks[] = $block;
445 foreach ($updateblocks as $block) {
446 $newBlock =& Legacy_ModuleInstallUtils::createBlockByInfo($module, $block, $block['func_num']);
447 Legacy_ModuleInstallUtils::installBlock($module, $newBlock, $block, $log);
452 * Uninstalls all of blocks which $module specifies, and its permissions.
454 * This function gets informations about templates from the database.
457 * @param XoopsModule $module
458 * @param Legacy_ModuleInstallLog $log
461 * @note FOR THE CUSTOM-INSTALLER
462 * @see Legacy_ModuleInstallUtils::installAllOfBlocks()
463 * @see Legacy_ModuleInstallUtils::uninstallBlock()
465 function uninstallAllOfBlocks(&$module, &$log)
467 $handler =& xoops_gethandler('block');
468 $criteria = new Criteria('mid', $module->get('mid'));
470 $blockArr =& $handler->getObjectsDirectly($criteria);
474 foreach (array_keys($blockArr) as $idx) {
475 $successFlag &= Legacy_ModuleInstallUtils::uninstallBlock($blockArr[$idx], $log);
482 * Create XoopsBlock object by array that is defined in xoops_version, return it.
483 * @param $module XoopsModule
484 * @param $block array
487 function &createBlockByInfo(&$module, $block, $func_num)
489 $options = isset($block['options']) ? $block['options'] : null;
490 $edit_func = isset($block['edit_func']) ? $block['edit_func'] : null;
491 $template = isset($block['template']) ? $block['template'] : null;
492 $visible = isset($block['visible']) ? $block['visible'] : (isset($block['visible_any']) ? $block['visible_any']: 0);
493 $blockHandler =& xoops_gethandler('block');
494 $blockObj =& $blockHandler->create();
496 $blockObj->set('mid', $module->getVar('mid'));
497 $blockObj->set('options', $options);
498 $blockObj->set('name', $block['name']);
499 $blockObj->set('title', $block['name']);
500 $blockObj->set('block_type', 'M');
501 $blockObj->set('c_type', 1);
502 $blockObj->set('isactive', 1);
503 $blockObj->set('dirname', $module->getVar('dirname'));
504 $blockObj->set('func_file', $block['file']);
507 // IMPORTANT CONVENTION
510 if (isset($block['class'])) {
511 $show_func = "cl::" . $block['class'];
514 $show_func = $block['show_func'];
517 $blockObj->set('show_func', $show_func);
518 $blockObj->set('edit_func', $edit_func);
519 $blockObj->set('template', $template);
520 $blockObj->set('last_modified', time());
521 $blockObj->set('visible', $visible);
523 $func_num = isset($block['func_num']) ? intval($block['func_num']) : $func_num;
524 $blockObj->set('func_num', $func_num);
530 * This function can receive both new and update.
531 * @param $module XoopsModule
532 * @param $blockObj XoopsBlock
533 * @param $block array
536 function installBlock(&$module, &$blockObj, &$block, &$log)
538 $isNew = $blockObj->isNew();
539 $blockHandler =& xoops_gethandler('block');
541 if (!empty($block['show_all_module'])) {
546 if (!$blockHandler->insert($blockObj, $autolink)) {
547 $log->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_COULD_NOT_INSTALL_BLOCK, $blockObj->getVar('name')));
552 $log->addReport(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_BLOCK_INSTALLED, $blockObj->getVar('name')));
554 $tplHandler =& xoops_gethandler('tplfile');
556 Legacy_ModuleInstallUtils::installBlockTemplate($blockObj, $module, $log);
559 // Process of a permission.
562 if (!empty($block['show_all_module'])) {
563 $link_sql = "INSERT INTO " . $blockHandler->db->prefix('block_module_link') . " (block_id, module_id) VALUES (".$blockObj->getVar('bid').", 0)";
564 if (!$blockHandler->db->query($link_sql)) {
565 $log->addWarning(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_COULD_NOT_SET_LINK, $blockObj->getVar('name')));
568 $gpermHandler =& xoops_gethandler('groupperm');
569 $bperm =& $gpermHandler->create();
570 $bperm->setVar('gperm_itemid', $blockObj->getVar('bid'));
571 $bperm->setVar('gperm_name', 'block_read');
572 $bperm->setVar('gperm_modid', 1);
574 if (!empty($block['visible_any'])) {
575 $memberHandler =& xoops_gethandler('member');
576 $groupObjects =& $memberHandler->getGroups();
577 foreach($groupObjects as $group) {
578 $bperm->setVar('gperm_groupid', $group->getVar('groupid'));
580 if (!$gpermHandler->insert($bperm)) {
581 $log->addWarning(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_COULD_NOT_SET_BLOCK_PERMISSION, $blockObj->getVar('name')));
585 $root =& XCube_Root::getSingleton();
586 $groups = $root->mContext->mXoopsUser->getGroups(true);
587 foreach ($groups as $mygroup) {
588 $bperm->setVar('gperm_groupid', $mygroup);
590 if (!$gpermHandler->insert($bperm)) {
591 $log->addWarning(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_COULD_NOT_SET_BLOCK_PERMISSION, $blockObj->getVar('name')));
602 * Uninstalls a block which $block specifies. In the same time, deletes
603 * permissions for the block.
605 * @param XoopsBlock $block
606 * @param Legacy_ModuleInstallLog $log
607 * @note FOR THE CUSTOM-INSTALLER
609 * @todo error handling & delete the block's template.
611 function uninstallBlock(&$block, &$log)
613 $blockHandler =& xoops_gethandler('block');
614 $blockHandler->delete($block);
615 $log->addReport(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_UNINSTALLATION_BLOCK_SUCCESSFUL, $block->get('name')));
618 // Deletes permissions
620 $gpermHandler =& xoops_gethandler('groupperm');
621 $criteria =& new CriteriaCompo();
622 $criteria->add(new Criteria('gperm_name', 'block_read'));
623 $criteria->add(new Criteria('gperm_itemid', $block->get('bid')));
624 $criteria->add(new Criteria('gperm_modid', 1));
625 $gpermHandler->deleteAll($criteria);
629 * Save the information of block's template specified and the source code of it
633 function installBlockTemplate(&$block, &$module, &$log)
635 if ($block->get('template') == null) {
639 $tplHandler =& xoops_gethandler('tplfile');
641 $criteria =& new CriteriaCompo();
642 $criteria->add(new Criteria('tpl_type', 'block'));
643 $criteria->add(new Criteria('tpl_tplset', 'default'));
644 $criteria->add(new Criteria('tpl_module', $module->get('dirname')));
645 $criteria->add(new Criteria('tpl_file', $block->get('template')));
646 $tplfiles =& $tplHandler->getObjects($criteria);
648 if (count($tplfiles) > 0) {
649 $tplfile =& $tplfiles[0];
652 $tplfile =& $tplHandler->create();
653 $tplfile->set('tpl_refid', $block->get('bid'));
654 $tplfile->set('tpl_tplset', 'default');
655 $tplfile->set('tpl_file', $block->get('template'));
656 $tplfile->set('tpl_module', $module->get('dirname'));
657 $tplfile->set('tpl_type', 'block');
658 // $tplfile->setVar('tpl_desc', $tpl_desc);
659 $tplfile->set('tpl_lastimported', 0);
662 $tplSource = Legacy_ModuleInstallUtils::readTemplateFile($module->get('dirname'), $block->get('template'), true);
663 $tplfile->set('tpl_source', $tplSource);
664 $tplfile->set('tpl_lastmodified', time());
666 if ($tplHandler->insert($tplfile)) {
667 $log->addReport(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_BLOCK_TEMPLATE_INSTALLED, $block->get('template')));
671 $log->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_BLOCK_TEMPLATE_INSTALL, $block->get('name')));
677 * Read template file, return it.
679 * @note This is must, but it depends on ...
681 function readTemplateFile($dirname, $fileName, $isblock = false)
684 // Load template data
687 $filePath = XOOPS_MODULE_PATH . "/" . $dirname . "/templates/blocks/" . $fileName;
690 $filePath = XOOPS_MODULE_PATH . "/" . $dirname . "/templates/" . $fileName;
693 if (!file_exists($filePath)) {
697 $lines = file($filePath);
698 if ($lines == false) {
703 foreach ($lines as $line) {
705 // Unify linefeed to "\r\n"
707 $tpldata .= str_replace("\n", "\r\n", str_replace("\r\n", "\n", $line));
713 function installAllOfConfigs(&$module, &$log)
715 $dirname = $module->get('dirname');
717 $fileReader =& new Legacy_ModinfoX2FileReader($dirname);
718 $preferences =& $fileReader->loadPreferenceInformations();
723 foreach (array_keys($preferences->mPreferences) as $idx) {
724 Legacy_ModuleInstallUtils::installPreferenceByInfo($preferences->mPreferences[$idx], $module, $log);
730 foreach (array_keys($preferences->mComments) as $idx) {
731 Legacy_ModuleInstallUtils::installPreferenceByInfo($preferences->mComments[$idx], $module, $log);
735 function installPreferenceByInfo(&$info, &$module, &$log)
737 $handler =& xoops_gethandler('config');
738 $config =& $handler->createConfig();
739 $config->set('conf_modid', $module->get('mid'));
740 $config->set('conf_catid', 0);
741 $config->set('conf_name', $info->mName);
742 $config->set('conf_title', $info->mTitle);
743 $config->set('conf_desc', $info->mDescription);
744 $config->set('conf_formtype', $info->mFormType);
745 $config->set('conf_valuetype', $info->mValueType);
746 $config->setConfValueForInput($info->mDefault);
747 $config->set('conf_order', $info->mOrder);
749 if (count($info->mOption->mOptions) > 0) {
750 foreach (array_keys($info->mOption->mOptions) as $idx) {
751 $option =& $handler->createConfigOption();
752 $option->set('confop_name', $info->mOption->mOptions[$idx]->mName);
753 $option->set('confop_value', $info->mOption->mOptions[$idx]->mValue);
754 $config->setConfOptions($option);
759 if ($handler->insertConfig($config)) {
760 $log->addReport(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_INSERT_CONFIG, $config->get('conf_name')));
763 $log->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_COULD_NOT_INSERT_CONFIG, $config->get('conf_name')));
768 * Get & build config items from Manifesto by specific module object.
770 function &getConfigInfosFromManifesto(&$module)
772 $configInfos = $module->getInfo('config');
775 // Insert comment config by old style.
777 if ($module->getVar('hascomments') !=0 ) {
778 require_once XOOPS_ROOT_PATH . "/include/comment_constants.php";
780 $configInfos[] = array('name' => 'com_rule',
781 'title' => '_CM_COMRULES',
783 'formtype' => 'select',
784 'valuetype' => 'int',
786 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN)
789 $configInfos[] = array('name' => 'com_anonpost',
790 'title' => '_CM_COMANONPOST',
792 'formtype' => 'yesno',
793 'valuetype' => 'int',
802 * Delete all configs of $module.
804 * @param $module XoopsModule
806 function uninstallAllOfConfigs(&$module, &$log)
808 if ($module->get('hasconfig') == 0) {
812 $configHandler =& xoops_gethandler('config');
813 $configs =& $configHandler->getConfigs(new Criteria('conf_modid', $module->get('mid')));
815 if (count($configs) == 0) {
819 foreach ($configs as $config) {
820 $configHandler->deleteConfig($config);
824 function smartUpdateAllOfBlocks(&$module, &$log)
826 $dirname = $module->get('dirname');
828 $fileReader =& new Legacy_ModinfoX2FileReader($dirname);
829 $latestBlocks =& $fileReader->loadBlockInformations();
831 $dbReader =& new Legacy_ModinfoX2DBReader($dirname);
832 $currentBlocks =& $dbReader->loadBlockInformations();
834 $currentBlocks->update($latestBlocks);
836 foreach (array_keys($currentBlocks->mBlocks) as $idx) {
837 switch ($currentBlocks->mBlocks[$idx]->mStatus) {
838 case LEGACY_INSTALLINFO_STATUS_LOADED:
839 Legacy_ModuleInstallUtils::updateBlockTemplateByInfo($currentBlocks->mBlocks[$idx], $module, $log);
842 case LEGACY_INSTALLINFO_STATUS_UPDATED:
843 Legacy_ModuleInstallUtils::updateBlockByInfo($currentBlocks->mBlocks[$idx], $module, $log);
846 case LEGACY_INSTALLINFO_STATUS_NEW:
847 Legacy_ModuleInstallUtils::installBlockByInfo($currentBlocks->mBlocks[$idx], $module, $log);
850 case LEGACY_INSTALLINFO_STATUS_DELETED:
851 Legacy_ModuleInstallUtils::uninstallBlockByFuncNum($currentBlocks->mBlocks[$idx]->mFuncNum, $module, $log);
857 function smartUpdateAllOfPreferences(&$module, &$log)
859 $dirname = $module->get('dirname');
861 $fileReader =& new Legacy_ModinfoX2FileReader($dirname);
862 $latestPreferences =& $fileReader->loadPreferenceInformations();
864 $dbReader =& new Legacy_ModinfoX2DBReader($dirname);
865 $currentPreferences =& $dbReader->loadPreferenceInformations();
867 $currentPreferences->update($latestPreferences);
872 foreach (array_keys($currentPreferences->mPreferences) as $idx) {
873 switch ($currentPreferences->mPreferences[$idx]->mStatus) {
874 case LEGACY_INSTALLINFO_STATUS_UPDATED:
875 Legacy_ModuleInstallUtils::updatePreferenceByInfo($currentPreferences->mPreferences[$idx], $module, $log);
878 case LEGACY_INSTALLINFO_STATUS_ORDER_UPDATED:
879 Legacy_ModuleInstallUtils::updatePreferenceOrderByInfo($currentPreferences->mPreferences[$idx], $module, $log);
882 case LEGACY_INSTALLINFO_STATUS_NEW:
883 Legacy_ModuleInstallUtils::installPreferenceByInfo($currentPreferences->mPreferences[$idx], $module, $log);
886 case LEGACY_INSTALLINFO_STATUS_DELETED:
887 Legacy_ModuleInstallUtils::uninstallPreferenceByOrder($currentPreferences->mPreferences[$idx]->mOrder, $module, $log);
895 foreach (array_keys($currentPreferences->mComments) as $idx) {
896 switch ($currentPreferences->mComments[$idx]->mStatus) {
897 case LEGACY_INSTALLINFO_STATUS_UPDATED:
898 Legacy_ModuleInstallUtils::updatePreferenceByInfo($currentPreferences->mComments[$idx], $module, $log);
901 case LEGACY_INSTALLINFO_STATUS_ORDER_UPDATED:
902 Legacy_ModuleInstallUtils::updatePreferenceOrderByInfo($currentPreferences->mComments[$idx], $module, $log);
905 case LEGACY_INSTALLINFO_STATUS_NEW:
906 Legacy_ModuleInstallUtils::installPreferenceByInfo($currentPreferences->mComments[$idx], $module, $log);
909 case LEGACY_INSTALLINFO_STATUS_DELETED:
910 Legacy_ModuleInstallUtils::uninstallPreferenceByOrder($currentPreferences->mComments[$idx]->mOrder, $module, $log);
916 function updateBlockTemplateByInfo(&$info, &$module, &$log)
918 $handler =& xoops_getmodulehandler('newblocks', 'legacy');
920 $criteria =& new CriteriaCompo();
921 $criteria->add(new Criteria('dirname', $module->get('dirname')));
922 $criteria->add(new Criteria('func_num', $info->mFuncNum));
924 $blockArr =& $handler->getObjects($criteria);
925 foreach (array_keys($blockArr) as $idx) {
926 Legacy_ModuleInstallUtils::clearBlockTemplateForUpdate($blockArr[$idx], $module, $log);
927 Legacy_ModuleInstallUtils::installBlockTemplate($blockArr[$idx], $module, $log);
931 function updateBlockByInfo(&$info, &$module, &$log)
933 $handler =& xoops_getmodulehandler('newblocks', 'legacy');
935 $criteria =& new CriteriaCompo();
936 $criteria->add(new Criteria('dirname', $module->get('dirname')));
937 $criteria->add(new Criteria('func_num', $info->mFuncNum));
939 $blockArr =& $handler->getObjects($criteria);
940 foreach (array_keys($blockArr) as $idx) {
941 $blockArr[$idx]->set('options', $info->mOptions);
942 $blockArr[$idx]->set('name', $info->mName);
943 $blockArr[$idx]->set('func_file', $info->mFuncFile);
944 $blockArr[$idx]->set('show_func', $info->mShowFunc);
945 $blockArr[$idx]->set('edit_func', $info->mEditFunc);
946 $blockArr[$idx]->set('template', $info->mTemplate);
948 if ($handler->insert($blockArr[$idx])) {
949 $log->addReport(XCube_Utils::formatMessage('Update {0} block successfully.', $blockArr[$idx]->get('name')));
952 $log->addError(XCube_Utils::formatMessage('Could not update {0} block.', $blockArr[$idx]->get('name')));
955 Legacy_ModuleInstallUtils::clearBlockTemplateForUpdate($blockArr[$idx], $module, $log);
956 Legacy_ModuleInstallUtils::installBlockTemplate($blockArr[$idx], $module, $log);
960 function updatePreferenceByInfo(&$info, &$module, &$log)
962 $handler =& xoops_gethandler('config');
964 $criteria =& new CriteriaCompo();
965 $criteria->add(new Criteria('conf_modid', $module->get('mid')));
966 $criteria->add(new Criteria('conf_catid', 0));
967 $criteria->add(new Criteria('conf_name', $info->mName));
969 $configArr =& $handler->getConfigs($criteria);
971 if (!(count($configArr) > 0 && is_object($configArr[0]))) {
972 $log->addError('Execption Error: Could not find config.');
976 $config =& $configArr[0];
978 $config->set('conf_title', $info->mTitle);
979 $config->set('conf_desc', $info->mDescription);
982 // Decide whether it changes values.
984 if ($config->get('conf_formtype') != $info->mFormType && $config->get('conf_valuetype') != $info->mValueType) {
985 $config->set('conf_formtype', $info->mFormType);
986 $config->set('conf_valuetype', $info->mValueType);
987 $config->setConfValueForInput($info->mDefault);
990 $config->set('conf_formtype', $info->mFormType);
991 $config->set('conf_valuetype', $info->mValueType);
994 $config->set('conf_order', $info->mOrder);
996 $optionArr =& $handler->getConfigOptions(new Criteria('conf_id', $config->get('conf_id')));
997 if (is_array($optionArr)) {
998 foreach (array_keys($optionArr) as $idx) {
999 $handler->_oHandler->delete($optionArr[$idx]);
1003 if (count($info->mOption->mOptions) > 0) {
1004 foreach (array_keys($info->mOption->mOptions) as $idx) {
1005 $option =& $handler->createConfigOption();
1006 $option->set('confop_name', $info->mOption->mOptions[$idx]->mName);
1007 $option->set('confop_value', $info->mOption->mOptions[$idx]->mValue);
1008 $option->set('conf_id', $option->get('conf_id'));
1009 $config->setConfOptions($option);
1014 if ($handler->insertConfig($config)) {
1015 $log->addReport(XCube_Utils::formatMessage("Preference '{0}' is updateded.", $config->get('conf_name')));
1018 $log->addError(XCube_Utils::formatMessage("Could not update preference '{0}'.", $config->get('conf_name')));
1022 function updatePreferenceOrderByInfo(&$info, &$module, &$log)
1024 $handler =& xoops_gethandler('config');
1026 $criteria =& new CriteriaCompo();
1027 $criteria->add(new Criteria('conf_modid', $module->get('mid')));
1028 $criteria->add(new Criteria('conf_catid', 0));
1029 $criteria->add(new Criteria('conf_name', $info->mName));
1031 $configArr =& $handler->getConfigs($criteria);
1033 if (!(count($configArr) > 0 && is_object($configArr[0]))) {
1034 $log->addError('Execption Error: Could not find config.');
1038 $config =& $configArr[0];
1040 $config->set('conf_order', $info->mOrder);
1042 if (!$handler->insertConfig($config)) {
1043 $log->addError(XCube_Utils::formatMessage("Could not update the order of preference '{0}'.", $config->get('conf_name')));
1047 function installBlockByInfo(&$info, &$module, &$log)
1049 $handler =& xoops_gethandler('block');
1050 $block =& $handler->create();
1052 $block->set('mid', $module->get('mid'));
1053 $block->set('func_num', $info->mFuncNum);
1054 $block->set('options', $info->mOptions);
1055 $block->set('name', $info->mName);
1056 $block->set('title', $info->mName);
1057 $block->set('dirname', $module->get('dirname'));
1058 $block->set('func_file', $info->mFuncFile);
1059 $block->set('show_func', $info->mShowFunc);
1060 $block->set('edit_func', $info->mEditFunc);
1061 $block->set('template', $info->mTemplate);
1062 $block->set('block_type', 'M');
1063 $block->set('c_type', 1);
1065 if (!$handler->insert($block)) {
1066 $log->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_COULD_NOT_INSTALL_BLOCK, $block->get('name')));
1070 $log->addReport(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_BLOCK_INSTALLED, $block->get('name')));
1072 Legacy_ModuleInstallUtils::installBlockTemplate($block, $module, $log);
1079 * @todo Need a message in the fail case.
1081 function uninstallBlockByFuncNum($func_num, &$module, &$log)
1083 $handler =& xoops_getmodulehandler('newblocks', 'legacy');
1085 $criteria =& new CriteriaCompo();
1086 $criteria->add(new Criteria('dirname', $module->get('dirname')));
1087 $criteria->add(new Criteria('func_num', $func_num));
1089 $blockArr =& $handler->getObjects($criteria);
1090 foreach (array_keys($blockArr) as $idx) {
1091 if ($handler->delete($blockArr[$idx])) {
1092 $log->addReport(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_UNINSTALLATION_BLOCK_SUCCESSFUL, $blockArr[$idx]->get('name')));
1098 Legacy_ModuleInstallUtils::uninstallBlockTemplate($blockArr[$idx], $module, $log);
1104 * Uninstalls the block template data specified by $block of $module.
1105 * @param XoopsBlock $block
1106 * @param XoopsModule $module This object is must the module which has $block.
1107 * @param string $tplset A name of the template set. If this is null, uninstalls
1108 * all templates of any template-sets.
1111 * This method users template handlers of the kernel. But, if they are hooked,
1112 * they may not do something. So, abstraction mechanism is possible enough.
1114 function _uninstallBlockTemplate(&$block, &$module, $tplset, &$log)
1116 $handler =& xoops_gethandler('tplfile');
1117 $criteria =& new CriteriaCompo();
1118 $criteria->add(new Criteria('tpl_refid', $block->get('bid')));
1119 $criteria->add(new Criteria('tpl_file', $block->get('template')));
1120 $criteria->add(new Criteria('tpl_module', $module->get('dirname')));
1121 $criteria->add(new Criteria('tpl_type', 'block'));
1123 if ($tplset != null) {
1125 $criteria->add(new Criteria('tpl_tplset', $tplset));
1128 $handler->deleteAll($criteria);
1131 function uninstallBlockTemplate(&$block, &$module, &$log)
1133 Legacy_ModuleInstallUtils::_uninstallBlockTemplate($block, $module, null, $log);
1138 * Removes a template data from only default group of some render-system.
1140 function clearBlockTemplateForUpdate(&$block, &$module, &$log)
1142 Legacy_ModuleInstallUtils::_uninstallBlockTemplate($block, $module, 'default', $log);
1145 function uninstallPreferenceByOrder($order, &$module, &$log)
1147 $handler =& xoops_gethandler('config');
1149 $criteria =& new CriteriaCompo();
1150 $criteria->add(new Criteria('conf_modid', $module->get('mid')));
1151 $criteria->add(new Criteria('conf_catid', 0));
1152 $criteria->add(new Criteria('conf_order', $order));
1154 $configArr =& $handler->getConfigs($criteria);
1156 foreach (array_keys($configArr) as $idx) {
1157 if ($handler->deleteConfig($configArr[$idx])) {
1158 $log->addReport(XCube_Utils::formatMessage("Delete preference '{0}'.", $configArr[$idx]->get('conf_name')));
1161 $log->addError(XCube_Utils::formatMessage("Could not delete preference '{0}'.", $configArr[$idx]->get('conf_name')));
1167 * Executes SQL query as cube style.
1169 function DBquery($query, &$module, $log)
1171 require_once XOOPS_MODULE_PATH . "/legacy/admin/class/Legacy_SQLScanner.class.php";
1173 $successFlag = true;
1175 $scanner =& new Legacy_SQLScanner();
1176 $scanner->setDB_PREFIX(XOOPS_DB_PREFIX);
1177 $scanner->setDirname($module->get('dirname'));
1178 $scanner->setBuffer($query);
1180 $sqlArr = $scanner->getSQL();
1182 $root =& XCube_Root::getSingleton();
1184 foreach ($sqlArr as $sql) {
1185 if ($root->mController->mDB->query($sql)) {
1186 $log->addReport("Success: ${sql}");
1187 $successFlag &= true;
1190 $log->addError("Failure: ${sql}");
1191 $successFlag = false;
1195 return $successFlag;
1198 function deleteAllOfComments(&$module, &$log)
1200 $handler =& xoops_gethandler('comment');
1201 $criteria =& new Criteria('com_modid', $module->get('mid'));
1202 $handler->deleteAll($criteria);