8 if(!defined('XOOPS_ROOT_PATH'))
13 if(class_exists('Sd2nd_InstallUtils'))
21 class Sd2nd_InstallUtils
24 * installSQLAutomatically
26 * @param XoopsModule &$module
27 * @param Legacy_ModuleInstallLog &$log
31 public static function installSQLAutomatically(/*** XoopsModule ***/ &$module,/*** Legacy_ModuleInstallLog ***/ &$log)
33 $sqlFileInfo =& $module->getInfo('sqlfile');
34 if(!isset($sqlFileInfo[XOOPS_DB_TYPE]))
38 $sqlFile = $sqlFileInfo[XOOPS_DB_TYPE];
40 $dirname = $module->getVar('dirname');
41 $sqlFilePath = sprintf('%s/%s/%s',XOOPS_MODULE_PATH,$dirname,$sqlFile);
42 if(!file_exists($sqlFilePath))
44 $sqlFilePath = sprintf(
47 $module->modinfo['trust_dirname'],
52 require_once XOOPS_MODULE_PATH . '/legacy/admin/class/Legacy_SQLScanner.class.php'; // TODO will be use other class?
53 $scanner =& new Legacy_SQLScanner();
54 $scanner->setDB_PREFIX(XOOPS_DB_PREFIX);
55 $scanner->setDirname($dirname);
56 if(!$scanner->loadFile($sqlFilePath))
59 XCube_Utils::formatString(
60 _MI_SD2ND_INSTALL_ERROR_SQL_FILE_NOT_FOUND,
68 $root =& XCube_Root::getSingleton();
69 $db =& $root->mController->getDB();
71 foreach($scanner->getSQL() as $sql)
75 $log->addError($db->error());
79 $log->addReport(_MI_SD2ND_INSTALL_MSG_DB_SETUP_FINISHED);
86 * @param string $query
87 * @param XoopsModule &$module
88 * @param Legacy_ModuleInstallLog &$log
92 public static function DBquery(/*** string ***/ $query,/*** XoopsModule ***/ &$module,/*** Legacy_ModuleInstallLog ***/ &$log)
94 require_once XOOPS_MODULE_PATH . '/legacy/admin/class/Legacy_SQLScanner.class.php'; // TODO will be use other class?
95 $scanner =& new Legacy_SQLScanner();
96 $scanner->setDB_PREFIX(XOOPS_DB_PREFIX);
97 $scanner->setDirname($module->get('dirname'));
98 $scanner->setBuffer($query);
100 $sqls = $scanner->getSQL();
102 $root =& XCube_Root::getSingleton();
105 foreach($sqls as $sql)
107 if($root->mController->mDB->query($sql))
110 XCube_Utils::formatString(
111 _MI_SD2ND_INSTALL_MSG_SQL_SUCCESS,
119 XCube_Utils::formatString(
120 _MI_SD2ND_INSTALL_MSG_SQL_ERROR,
124 $successFlag = false;
133 * @param string $from
134 * @param string $dirname
135 * @param string $trustDirname
137 * @return {string 'public',string 'trust'}
139 public static function replaceDirname(/*** string ***/ $from,/*** string ***/ $dirname,/*** string ***/ $trustDirname = null)
142 'public' => str_replace('{dirname}',$dirname,$from),
143 'trust' => ($trustDirname != null) ? str_replace('{dirname}',$trustDirname,$from) : null
150 * @param string $dirname
151 * @param string $trustDirname
152 * @param string $filename
153 * @param bool $isBlock
157 public static function readTemplateFile(/*** string ***/ $dirname,/*** string ***/ $trustDirname,/*** string ***/ $filename,/*** bool ***/ $isBlock = false)
160 '%s/%s/templates/%s%s',
163 ($isBlock ? 'blocks/' : ''),
167 if(!file_exists($filePath))
170 '%s/modules/%s/templates/%s%s',
173 ($isBlock ? 'blocks/' : ''),
176 if(!file_exists($filePath))
182 if(!($lines = file($filePath)))
188 foreach($lines as $line)
190 $tplData .= str_replace("\n","\r\n",str_replace("\r\n","\n",$line));
197 * installAllOfModuleTemplates
199 * @param XoopsModule &$module
200 * @param Legacy_ModuleInstallLog &$log
204 public static function installAllOfModuleTemplates(/*** XoopsModule ***/ &$module,/*** Legacy_ModuleInstallLog ***/ &$log)
206 $templates =& $module->getInfo('templates');
207 if(is_array($templates) && count($templates) > 0)
209 foreach($templates as $template)
211 Sd2nd_InstallUtils::installModuleTemplate($module,$template,$log);
217 * installModuleTemplate
219 * @param XoopsModule &$module
220 * @param string[] $template
221 * @param Legacy_ModuleInstallLog &$log
225 public static function installModuleTemplate(/*** XoopsModule ***/ &$module,/*** string[] ***/ $template,/*** Legacy_ModuleInstallLog ***/ &$log)
227 $dirname = $module->getVar('dirname');
228 $trustDirname =& $module->getInfo('trust_dirname');
229 $tplHandler =& Sd2nd_Utils::getXoopsHandler('tplfile');
230 $filename = Sd2nd_InstallUtils::replaceDirname(trim($template['file']),$dirname,$trustDirname);
231 $tplData = Sd2nd_InstallUtils::readTemplateFile($dirname,$trustDirname,$filename['trust']);
233 if($tplData == false)
238 $tplFile =& $tplHandler->create();
239 $tplFile->setVar('tpl_refid' ,$module->getVar('mid'));
240 $tplFile->setVar('tpl_lastimported',0);
241 $tplFile->setVar('tpl_lastmodified',time());
242 $tplFile->setVar('tpl_type' ,(substr($filename['trust'],-4) == '.css') ? 'css' : 'module');
243 $tplFile->setVar('tpl_source' ,$tplData,true);
244 $tplFile->setVar('tpl_module' ,$module->getVar('dirname'));
245 $tplFile->setVar('tpl_tplset' ,'default');
246 $tplFile->setVar('tpl_file' ,$filename['public'],true);
247 $tplFile->setVar('tpl_desc' ,isset($template['desctiption']) ? $template['description'] : '',true);
249 if($tplHandler->insert($tplFile))
252 XCube_Utils::formatString(
253 _MI_SD2ND_INSTALL_MSG_TPL_INSTALLED,
261 XCube_Utils::formatString(
262 _MI_SD2ND_INSTALL_ERROR_TPL_INSTALLED,
273 * uninstallAllOfModuleTemplates
275 * @param XoopsModule &$module
276 * @param Legacy_ModuleInstallLog &$log
277 * @param bool $defaultOnly
281 public static function uninstallAllOfModuleTemplates(/*** XoopsModule ***/ &$module,/*** Legacy_ModuleInstallLog ***/ &$log,/*** bool ***/ $defaultOnly = true)
283 $tplHandler =& Sd2nd_Utils::getXoopsHandler('tplfile');
285 $delTemplates =& $tplHandler->find($defaultOnly ? 'default' : null,'module',$module->get('mid'));
287 if(is_array($delTemplates) && count($delTemplates) > 0)
289 $xoopsTpl =& new XoopsTpl();
290 $xoopsTpl->clear_cache(null,'mod_' . $module->get('dirname'));
291 foreach($delTemplates as $tpl)
293 if(!$tplHandler->delete($tpl))
296 XCube_Utils::formatString(
297 _MI_SD2ND_INSTALL_ERROR_TPL_UNINSTALLED,
298 $tpl->get('tpl_file')
309 * @param XoopsModule &$module
310 * @param Legacy_ModuleInstallLog &$log
314 public static function installAllOfBlocks(/*** XoopsModule ***/ &$module,/*** Legacy_ModuleInstallLog ***/ &$log)
316 $blocks =& $module->getInfo('blocks');
317 if(is_array($blocks) && count($blocks) > 0)
319 foreach($blocks as $block)
321 $newBlock =& Sd2nd_InstallUtils::createBlockByInfo($module,$block);
322 Sd2nd_InstallUtils::installBlock($module,$newBlock,$block,$log);
331 * @param XoopsModule &$module
332 * @param string[] $block
336 public static function &createBlockByInfo(/*** XoopsModule ***/ &$module,/*** string[] ***/ $block)
338 $visible = isset($block['visible']) ?
340 (isset($block['visible_any']) ? $block['visible_any'] : 0);
341 $filename = isset($block['template']) ?
342 Sd2nd_InstallUtils::replaceDirname($block['template'],$module->get('dirname')) :
345 $blockHandler =& Sd2nd_Utils::getXoopsHandler('block');
346 $blockObj =& $blockHandler->create();
348 $blockObj->set('mid',$module->getVar('mid'));
349 $blockObj->set('options',isset($block['options']) ? $block['options'] : null);
350 $blockObj->set('name',$block['name']);
351 $blockObj->set('title',$block['name']);
352 $blockObj->set('block_type','M');
353 $blockObj->set('c_type','1');
354 $blockObj->set('isactive',1);
355 $blockObj->set('dirname',$module->getVar('dirname'));
356 $blockObj->set('func_file',$block['file']);
357 $blockObj->set('show_func','cl::' . $block['class']);
358 $blockObj->set('template',$filename['public']);
359 $blockObj->set('last_modified',time());
360 $blockObj->set('visible',$visible);
361 $blockObj->set('func_num',intval($block['func_num']));
368 * @param XoopsModule &$module
369 * @param XoopsBlock &$blockObj
370 * @param string[] &$block
371 * @param Legacy_ModuleInstallLog &$log
375 public static function installBlock(/*** XoopsModule ***/ &$module,/*** XoopsBlock ***/ &$blockObj,/*** string[] ***/ &$block,/*** Legacy_ModuleInstallLog ***/ &$log)
377 $isNew = $blockObj->isNew();
378 $blockHandler =& Sd2nd_Utils::getXoopsHandler('block');
379 $autoLink = isset($block['show_all_module']) ? $block['show_all_module'] : false;
381 if(!$blockHandler->insert($blockObj,$autoLink))
384 XCube_Utils::formatString(
385 _MI_SNEWS_INSTALL_ERROR_BLOCK_INSTALLED,
386 $blockObj->getVar('name')
393 XCube_Utils::formatString(
394 _MI_SD2ND_INSTALL_MSG_BLOCK_INSTALLED,
395 $blockObj->getVar('name')
399 Sd2nd_InstallUtils::installBlockTemplate($blockObj,$module,$log);
409 'insert into `%s` set (`block_id`,`module_id`) values (%d,0);',
410 $blockHandler->db->prefix('block_module_link'),
411 $blockObj->getVar('bid')
413 if(!$blockHandler->db->query($sql))
416 XCube_Utils::formatString(
417 _MI_SD2ND_INSTALL_ERROR_BLOCK_COULD_NOT_LINK,
418 $blockObj->getVar('name')
424 $gpermHandler =& Sd2nd_Utils::getXoopsHandler('groupperm');
425 $perm =& $gpermHandler->create();
426 $perm->setVar('gperm_itemid',$blockObj->getVar('bid'));
427 $perm->setVar('gperm_name','block_read');
428 $perm->setVar('gperm_modid',1);
429 if(isset($block['visible_any']) && $block['visible_any'])
431 $memberHandler =& Sd2nd_Utils::getXoopsHandler('member');
432 $groups =& $memberHandler->getGroups();
433 foreach($groups as $group)
435 $perm->setVar('gperm_groupid',$group->getVar('groupid'));
437 if(!$gpermHandler->insert($perm))
440 XCube_Utils::formatString(
441 _MI_SD2ND_INSTALL_ERROR_PERM_COULD_NOT_SET,
442 $blockObj->getVar('name')
450 $root =& XCube_Root::getSingleton();
451 $groups = $root->mContext->mXoopsUser->getGroups();
452 foreach($groups as $group)
454 $perm->setVar('gperm_groupid',$group);
456 if(!$gpermHandler->insert($perm))
459 XCube_Utils::formatString(
460 _MI_SD2ND_INSTALL_ERROR_BLOCK_PERM_SET,
461 $blockObj->getVar('name')
472 * installBlockTemplate
474 * @param XoopsBlock &$block
475 * @param XoopsModule &$module
476 * @param Legacy_ModuleInstallLog &$log
480 public static function installBlockTemplate(/*** XoopsBlock ***/ &$block,/*** XoopsModule ***/ &$module,/*** Legacy_ModuleInstallLog ***/ &$log)
482 if($block->get('template') == null)
487 $info =& $module->getInfo('blocks');
488 $filename = Sd2nd_InstallUtils::replaceDirname(
489 $info[$block->get('func_num')]['template'],
490 $module->get('dirname'),
491 $module->getInfo('trust_dirname')
493 $tplHandler =& Sd2nd_Utils::getXoopsHandler('tplfile');
495 $cri =& new CriteriaCompo();
496 $cri->add(new Criteria('tpl_type','block'));
497 $cri->add(new Criteria('tpl_tplset','default'));
498 $cri->add(new Criteria('tpl_module',$module->get('dirname')));
499 $cri->add(new Criteria('tpl_file',$filename['public']));
501 $tpls =& $tplHandler->getObjects($cri);
505 $tplFile =& $tpls[0];
509 $tplFile =& $tplHandler->create();
510 $tplFile->set('tpl_refid',$block->get('bid'));
511 $tplFile->set('tpl_tplset','default');
512 $tplFile->set('tpl_file',$filename['public']);
513 $tplFile->set('tpl_module',$module->get('dirname'));
514 $tplFile->set('tpl_type','block');
515 //$tplFile->set('tpl_desc',$block->get('description'));
516 $tplFile->set('tpl_lastimported',0);
519 $tplSource = Sd2nd_InstallUtils::readTemplateFile(
520 $module->get('dirname'),
521 $module->getInfo('trust_dirname'),
526 $tplFile->set('tpl_source',$tplSource);
527 $tplFile->set('tpl_lastmodified',time());
528 if($tplHandler->insert($tplFile))
531 XCube_Utils::formatString(
532 _MI_SD2ND_INSTALL_MSG_BLOCK_TPL_INSTALLED,
540 XCube_Utils::formatString(
541 _MI_SD2ND_INSTALL_ERROR_BLOCK_TPL_INSTALLED,
549 * uninstallAllOfBlocks
551 * @param XoopsModule &$module
552 * @param Legacy_ModuleInstallLog &$log
556 public static function uninstallAllOfBlocks(/*** XoopsModule ***/ &$module,/*** Legacy_ModuleInstallLog ***/ &$log)
560 $blockHandler =& Sd2nd_Utils::getXoopsHandler('block');
561 $gpermHandler =& Sd2nd_Utils::getXoopsHandler('groupperm');
562 $cri =& new Criteria('mid',$module->get('mid'));
563 $blocks =& $blockHandler->getObjectsDirectly($cri);
565 foreach($blocks as $block)
567 if($blockHandler->delete($block))
570 XCube_Utils::formatString(
571 _MI_SD2ND_INSTALL_MSG_BLOCK_UNINSTALLED,
579 XCube_Utils::formatString(
580 _MI_SD2ND_INSTALL_ERROR_BLOCK_UNINSTALLED,
584 $successFlag = false;
587 $cri =& new CriteriaCompo();
588 $cri->add(new Criteria('gperm_name','block_read'));
589 $cri->add(new Criteria('gperm_itemid',$block->get('bid')));
590 $cri->add(new Criteria('gperm_modid',1));
591 if(!$gpermHandler->deleteAll($cri))
594 XCube_Utils::formatString(
595 _MI_SD2ND_INSTALL_ERROR_BLOCK_PERM_DELETE,
599 $successFlag = false;
607 * smartUpdateAllOfBlocks
609 * @param XoopsModule &$module
610 * @param Legacy_ModuleInstallLog &$log
614 public static function smartUpdateAllOfBlocks(/*** XoopsModule ***/ &$module,/*** Legacy_ModuleInstallLog ***/ &$log)
616 $dirname = $module->get('dirname');
618 $fileReader =& new Legacy_ModinfoX2FileReader($dirname);
619 $dbReader =& new Legacy_ModinfoX2DBReader($dirname);
621 $blocks =& $dbReader->loadBlockInformations();
622 $blocks->update($fileReader->loadBlockInformations());
624 foreach($blocks->mBlocks as $block)
626 switch($block->mStatus)
628 case LEGACY_INSTALLINFO_STATUS_LOADED:
629 Sd2nd_InstallUtils::updateBlockTemplateByInfo($block,$module,$log);
631 case LEGACY_INSTALLINFO_STATUS_UPDATED:
632 Sd2nd_InstallUtils::updateBlockByInfo($block,$module,$log);
634 case LEGACY_INSTALLINFO_STATUS_NEW:
635 Sd2nd_InstallUtils::installBlockByInfo($block,$module,$log);
637 case LEGACY_INSTALLINFO_STATUS_DELETED:
638 Sd2nd_InstallUtils::uninstallBlockByFuncNum($block->mFuncNum,$module,$log);
647 * updateBlockTemplateByInfo
649 * @param Legacy_BlockInformation &$info
650 * @param XoopsModule &$module
651 * @param Legacy_ModuleInstallLog &$log
655 public static function updateBlockTemplateByInfo(/*** Legacy_BlockInformation ***/ &$info,/*** XoopsModule ***/ &$module,/*** Legacy_ModuleInstallLog ***/ &$log)
657 $blockHandler =& Sd2nd_Utils::getModuleHandler('newblocks','legacy');
658 $cri =& new CriteriaCompo();
659 $cri->add(new Criteria('dirname',$module->get('dirname')));
660 $cri->add(new Criteria('func_num',$info->mFuncNum));
661 $blocks =& $blockHandler->getObjects($cri);
663 foreach($blocks as $block)
665 Sd2nd_InstallUtils::uninstallBlockTemplate($block,$module,$log,true);
666 Sd2nd_InstallUtils::installBlockTemplate($block,$module,$log);
673 * @param Legacy_BlockInformation &$info
674 * @param XoopsModule &$module
675 * @param Legacy_ModuleInstallLog &$log
679 public static function updateBlockByInfo(/*** Legacy_BlockInformation ***/ &$info,/*** XoopsModule ***/ &$module,/*** Legacy_ModuleInstallLog ***/ &$log)
681 $blockHandler =& Sd2nd_Utils::getModuleHandler('newblocks','legacy');
682 $cri =& new CriteriaCompo();
683 $cri->add(new Criteria('dirname',$module->get('dirname')));
684 $cri->add(new Criteria('func_num',$info->mFuncNum));
685 $blocks =& $blockHandler->getObjects($cri);
687 foreach($blocks as $block)
689 $filename = Sd2nd_InstallUtils::replaceDirname(
691 $module->get('dirname'),
692 $module->getInfo('trust_dirname')
694 $block->set('options',$info->mOptions);
695 $block->set('name',$info->mName);
696 $block->set('func_file',$info->mFuncFile);
697 $block->set('show_func',$info->mShowFunc);
698 //$block->set('edit_func',$info->mEditFunc);
699 $block->set('template',$filename['public']);
700 if($blockHandler->insert($block))
703 XCube_Utils::formatString(
704 _MI_SD2ND_INSTALL_MSG_BLOCK_UPDATED,
712 XCube_Utils::formatString(
713 _MI_SD2ND_INSTALL_ERROR_BLOCK_UPDATED,
718 Sd2nd_InstallUtils::uninstallBlockTemplate($block,$module,$log,true);
719 Sd2nd_InstallUtils::installBlockTemplate($block,$module,$log);
726 * @param Legacy_BlockInformation &$info
727 * @param XoopsModule &$module
728 * @param Legacy_ModuleInstallLog &$log
732 public static function installBlockByInfo(/*** Legacy_BlockInformation ***/ &$info,/*** XoopsModule ***/ &$module,/*** Legacy_ModuleInstallLog ***/ &$log)
734 $filename = Sd2nd_InstallUtils::replaceDirname(
736 $module->get('dirname'),
737 $module->getInfo('trust_dirname')
740 $blockHandler =& Sd2nd_Utils::getXoopsHandler('block');
742 $block =& $blockHandler->create();
743 $block->set('mid',$module->get('mid'));
744 $block->set('func_num',$info->mFuncNum);
745 $block->set('options',$info->mOptions);
746 $block->set('name',$info->mName);
747 $block->set('title',$info->mName);
748 $block->set('dirname',$module->get('dirname'));
749 $block->set('func_file',$info->mFuncFile);
750 $block->set('show_func',$info->mShowFunc);
751 //$block->set('edit_func',$info->mEditFunc);
752 $block->set('template',$filename['public']);
753 $block->set('block_type','M');
754 $block->set('c_type',1);
756 if(!$blockHandler->insert($block))
759 XCube_Utils::formatString(
760 _MI_SD2ND_INSTALL_ERROR_BLOCK_INSTALLED,
768 XCube_Utils::formatString(
769 _MI_SD2ND_INSTALL_MSG_BLOCK_INSTALLED,
774 Sd2nd_InstallUtils::installBlockTemplate($block,$module,$log);
779 * uninstallBlockByFuncNum
781 * @param int $func_num
782 * @param XoopsModule &$module
783 * @param Legacy_ModuleInstallLog &$log
787 public static function uninstallBlockByFuncNum(/*** int ***/ $func_num,/*** XoopsModule ***/ &$module,/*** Legacy_ModuleInstallLog ***/ &$log)
789 $blockHandler =& Sd2nd_Utils::getModuleHandler('newblocks','legacy');
790 $cri =& new CriteriaCompo();
791 $cri->add(new Criteria('dirname',$module->get('dirname')));
792 $cri->add(new Criteria('func_num',$func_num));
793 $blocks =& $blockHandler->getObjects($cri);
796 foreach($blocks as $block)
798 if($blockHandler->delete($block))
801 XCube_Utils::formatString(
802 _MI_SD2ND_INSTALL_MSG_BLOCK_UNINSTALLED,
810 XCube_Utils::formatString(
811 _MI_SD2ND_INSTALL_ERROR_BLOCK_UNINSTALLED,
815 $successFlag = false;
822 * uninstallBlockTemplate
824 * @param XoopsBlock &$block
825 * @param XoopsModule &$module
826 * @param Legacy_ModuleInstallLog &$log
827 * @param bool $defaultOnly
831 public static function uninstallBlockTemplate(/*** XoopsBlock ***/ &$block,/*** XoopsModule ***/ &$module,/*** Legacy_ModuleInstallLog ***/ &$log,/*** bool ***/ $defaultOnly = false)
833 $tplHandler =& Sd2nd_Utils::getXoopsHandler('tplfile');
834 $delTemplates =& $tplHandler->find($defaultOnly ? 'default' : null,'block',$module->get('mid'),$module->get('dirname'),$block->get('template'));
836 if(is_array($delTemplates) && count($delTemplates) > 0)
838 foreach($delTemplates as $tpl)
840 if(!$tplHandler->delete($tpl))
843 XCube_Utils::formatString(
844 _MI_SD2ND_INSTALL_ERROR_TPL_UNINSTALLED,
845 $tpl->get('tpl_file')
853 XCube_Utils::formatString(
854 _MI_SD2ND_INSTALL_MSG_BLOCK_TPL_UNINSTALLED,
855 $block->get('template')
862 * installAllOfConfigs
864 * @param XoopsModule &$module
865 * @param Legacy_ModuleInstallLog &$log
869 public static function installAllOfConfigs(/*** XoopsModule ***/ &$module,/*** Legacy_ModuleInstallLog ***/ &$log)
872 $configHandler =& Sd2nd_Utils::getXoopsHandler('config');
873 $fileReader =& new Legacy_ModinfoX2FileReader($module->get('dirname')); // TODO will be use other class?
874 $preferences =& $fileReader->loadPreferenceInformations();
876 foreach($preferences->mPreferences as $info)
878 $config =& $configHandler->createConfig();
879 $config->set('conf_modid',$module->get('mid'));
880 $config->set('conf_catid',0);
881 $config->set('conf_name',$info->mName);
882 $config->set('conf_title',$info->mTitle);
883 $config->set('conf_desc',$info->mDescription);
884 $config->set('conf_formtype',$info->mFormType);
885 $config->set('conf_valuetype',$info->mValueType);
886 $config->setConfValueForInput($info->mDefault);
887 $config->set('conf_order',$info->mOrder);
889 if(count($info->mOption->mOptions) > 0)
891 foreach($info->mOption->mOptions as $opt)
893 $option = $configHandler->createConfigOption();
894 $option->set('confop_name',$opt->mName);
895 $option->set('confop_value',$opt->mValue);
896 $config->setConfOptions($option);
901 if($configHandler->insertConfig($config))
904 XCube_Utils::formatString(
905 _MI_SD2ND_INSTALL_MSG_CONFIG_ADDED,
906 $config->get('conf_name')
913 XCube_Utils::formatString(
914 _MI_SD2ND_INSTALL_ERROR_CONFIG_ADDED,
915 $config->get('conf_name')
918 $successFlag = false;
926 * installConfigByInfo
928 * @param Legacy_PreferenceInformation &$info
929 * @param XoopsModule &$module
930 * @param Legacy_ModuleInstallLog &$log
934 public static function installConfigByInfo(/*** Legacy_PreferenceInformation ***/ &$info,/*** XoopsModule ***/ &$module,/*** Legacy_ModuleInstallLog ***/ &$log)
936 $configHandler =& Sd2nd_Utils::getXoopsHandler('config');
937 $config =& $configHandler->createConfig();
938 $config->set('conf_modid',$module->get('mid'));
939 $config->set('conf_catid',0);
940 $config->set('conf_name',$info->mName);
941 $config->set('conf_title',$info->mTitle);
942 $config->set('conf_desc',$info->mDescription);
943 $config->set('conf_formtype',$info->mFormType);
944 $config->set('conf_valuetype',$info->mValueType);
945 $config->setConfValueForInput($info->mDefault);
946 $config->set('conf_order',$info->mOrder);
948 if(count($info->mOption->mOptions) > 0)
950 foreach($info->mOption->mOptions as $opt)
952 $option = $configHandler->createConfigOption();
953 $option->set('confop_name',$opt->mName);
954 $option->set('confop_value',$opt->mValue);
955 $config->setConfOptions($option);
960 if($configHandler->insertConfig($config))
963 XCube_Utils::formatString(
964 _MI_SD2ND_INSTALL_MSG_CONFIG_ADDED,
965 $config->get('conf_name')
972 XCube_Utils::formatString(
973 _MI_SD2ND_INSTALL_ERROR_CONFIG_ADDED,
974 $config->get('conf_name')
982 * uninstallAllOfConfigs
984 * @param XoopsModule &$module
985 * @param Legacy_ModuleInstallLog &$log
989 public static function uninstallAllOfConfigs(/*** XoopsModule ***/ &$module,/*** Legacy_ModuleInstallLog ***/ &$log)
991 if($module->get('hasconfig') == 0)
996 $configHandler =& Sd2nd_Utils::getXoopsHandler('config');
997 $configs =& $configHandler->getConfigs(new Criteria('conf_mofid',$module->get('mid')));
999 if(count($configs) == 0)
1005 foreach($configs as $config)
1007 if($configHandler->deleteConfig($config))
1010 XCube_Utils::formatString(
1011 _MI_SD2ND_INSTALL_MSG_CONFIG_DELETED,
1012 $config->getVar('conf_name')
1019 XCube_Utils::formatString(
1020 _MI_SD2ND_INSTALL_ERROR_CONFIG_DELETED,
1021 $config->getVar('conf_name')
1024 $sucessFlag = false;
1031 * uninstallConfigByOrder
1034 * @param XoopsModule &$module
1035 * @param Legacy_ModuleInstallLog &$log
1039 public static function uninstallConfigByOrder(/*** int ***/ $order,/*** XoopsModule ***/ &$module,/*** Legacy_ModuleInstallLog ***/ &$log)
1041 $configHandler =& Sd2nd_Utils::getXoopsHandler('config');
1043 $cri =& new CriteriaCompo();
1044 $cri->add(new Criteria('conf_modid',$module->get('mid')));
1045 $cri->add(new Criteria('conf_catid',0));
1046 $cri->add(new Criteria('conf_order',$order));
1047 $configs = $configHandler->getConfigs($cri);
1049 foreach($configs as $config)
1051 if($configHandler->deleteConfig($config))
1054 XCube_Utils::formatString(
1055 _MI_SD2ND_INSTALL_MSG_CONFIG_DELETED,
1056 $config->get('conf_name')
1063 XCube_Utils::formatString(
1064 _MI_SD2ND_INSTALL_ERROR_CONFIG_DELETED,
1065 $config->get('conf_name')
1073 * smartUpdateAllOfConfigs
1075 * @param XoopsModule &$module
1076 * @param Legacy_ModuleInstallLog &$log
1080 public static function smartUpdateAllOfConfigs(/*** XoopsModule ***/ &$module,/*** Legacy_ModuleInstallLog ***/ &$log)
1082 $dirname = $module->get('dirname');
1084 $fileReader =& new Legacy_ModinfoX2FileReader($dirname);
1085 $dbReader =& new Legacy_ModinfoX2DBReader($dirname);
1087 $configs =& $dbReader->loadPreferenceInformations();
1088 $configs->update($fileReader->loadPreferenceInformations());
1090 foreach($configs->mPreferences as $config)
1092 switch($config->mStatus)
1094 case LEGACY_INSTALLINFO_STATUS_UPDATED:
1095 Sd2nd_InstallUtils::updateConfigByInfo($config,$module,$log);
1097 case LEGACY_INSTALLINFO_STATUS_ORDER_UPDATED:
1098 Sd2nd_InstallUtils::updateConfigOrderByInfo($config,$module,$log);
1100 case LEGACY_INSTALLINFO_STATUS_NEW:
1101 Sd2nd_InstallUtils::installConfigByInfo($config,$module,$log);
1103 case LEGACY_INSTALLINFO_STATUS_DELETED:
1104 Sd2nd_InstallUtils::uninstallConfigByOrder($config->mOrder,$module,$log);
1113 * updateConfigByInfo
1115 * @param Legacy_PreferenceInformation &$info
1116 * @param XoopsModule &$module
1117 * @param Legacy_ModuleInstallLog &$log
1121 public static function updateConfigByInfo(/*** Legacy_PreferenceInformation ***/ &$info,/*** XoopsModule ***/ &$module,/*** Legacy_ModuleInstallLog ***/ &$log)
1123 $configHandler =& Sd2nd_Utils::getXoopsHandler('config');
1124 $cri =& new CriteriaCompo();
1125 $cri->add(new Criteria('conf_modid',$module->get('mid')));
1126 $cri->add(new Criteria('conf_catid',0));
1127 $cri->add(new Criteria('conf_name',$info->mName));
1128 $configs =& $configHandler->getConfigs($cri);
1130 if(!(count($configs) > 0 && is_object($configs[0])))
1132 $log->addError(_MISD2ND_INSTALL_ERROR_CONFIG_NOT_FOUND);
1136 $config =& $configs[0];
1137 $config->set('conf_title',$info->mTitle);
1138 $config->set('conf_desc',$info->mDescription);
1139 if($config->get('conf_formtype') != $info->mFormType && $config->get('conf_valuetype') != $info->mValueType)
1141 $config->set('conf_formtype',$info->mFormType);
1142 $config->set('conf_valuetype',$info->mValueType);
1143 $config->setConfValueForInput($info->mDefault);
1147 $config->set('conf_formtype',$info->mFormType);
1148 $config->set('conf_valuetype',$info->mValueType);
1150 $config->set('conf_order',$info->mOrder);
1152 $options =& $configHandler->getConfigOptions(new Criteria('conf_id',$config->get('conf_id')));
1153 if(is_array($options))
1155 foreach($options as $opt)
1157 $configHandler->_oHandler->delete($opt); // TODO will be use other method
1161 if(count($info->mOption->mOptions) > 0)
1163 foreach($info->mOption->mOptions as $opt)
1165 $option =& $configHandler->createConfigOption();
1166 $option->set('confop_name',$opt->mName);
1167 $option->set('confop_value',$opt->mValue);
1168 $option->set('conf_id',$option->get('conf_id')); // TODO check conf_id is right
1169 $config->setConfOptions($option);
1174 if($configHandler->insertConfig($config))
1177 XCube_Utils::formatString(
1178 _MI_SD2ND_INSTALL_MSG_CONFIG_UPDATED,
1179 $config->get('conf_name')
1186 XCube_Utils::formatString(
1187 _MI_SD2ND_INSTALL_ERROR_CONFIG_UPDATED,
1188 $config->get('conf_name')
1195 * updateConfigOrderByInfo
1197 * @param Legacy_PreferenceInformation &$info
1198 * @param XoopsModule &$module
1199 * @param Legacy_ModuleInstallLog &$log
1203 public static function updateConfigOrderByInfo(/*** Legacy_PreferenceInformation ***/ &$info,/*** XoopsModule ***/ &$module,/*** Legacy_ModuleInstallLog ***/ &$log)
1205 $configHandler =& Sd2nd_Utils::getXoopsHandler('config');
1206 $cri =& new CriteriaCompo();
1207 $cri->add(new Criteria('conf_modid',$module->get('mid')));
1208 $cri->add(new Criteria('conf_catid',0));
1209 $cri->add(new Criteria('conf_name',$info->mName));
1210 $configs =& $configHandler->getConfigs($cri);
1212 if(!(count($configs) > 0 && is_object($configs[0])))
1214 $log->addError(_MI_SD2ND_INSTALL_ERROR_CONFIG_NOT_FOUND);
1218 $config =& $configs[0];
1219 $config->set('conf_order',$info->mOrder);
1220 if(!$configHandler->insertConfig($config))
1223 XCube_Utils::formatString(
1224 _MI_SD2ND_INSTALL_ERROR_CONFIG_UPDATED,
1225 $config->get('conf_name')