diff --git a/admin/import/ams.php b/admin/import/ams.php index da00fc25..05d3141e 100644 --- a/admin/import/ams.php +++ b/admin/import/ams.php @@ -23,9 +23,11 @@ use Xmf\Request; use XoopsModules\Publisher\{Category, Constants, + Helper, File, Utility }; +/** @var Helper $helper */ const DIRNAME = 'ams'; @@ -169,10 +171,7 @@ //publisher_adminMenu(-1, _AM_PUBLISHER_IMPORT); // require_once dirname(dirname(__DIR__)) . '/include/common.php'; Utility::openCollapsableBar('amsimportgo', 'amsimportgoicon', sprintf(_AM_PUBLISHER_IMPORT_FROM, $importFromModuleName), _AM_PUBLISHER_IMPORT_RESULT); - /** @var \XoopsModuleHandler $moduleHandler */ - $moduleHandler = xoops_getHandler('module'); - $moduleObj = $moduleHandler->getByDirname(DIRNAME); - $ams_module_id = $moduleObj->getVar('mid'); + $moduleId = $helper->getModule()->getVar('mid'); /** @var \XoopsGroupPermHandler $grouppermHandler */ $grouppermHandler = xoops_getHandler('groupperm'); @@ -390,12 +389,12 @@ } // Saving category permissions - $groupsIds = $grouppermHandler->getGroupIds('nw_view', $arrCat['topic_id'], $ams_module_id); + $groupsIds = $grouppermHandler->getGroupIds('nw_view', $arrCat['topic_id'], $moduleId); Utility::saveCategoryPermissions($groupsIds, $categoryObj->categoryid(), 'category_read'); - $groupsIds = $grouppermHandler->getGroupIds('nw_submit', $arrCat['topic_id'], $ams_module_id); + $groupsIds = $grouppermHandler->getGroupIds('nw_submit', $arrCat['topic_id'], $moduleId); Utility::saveCategoryPermissions($groupsIds, $categoryObj->categoryid(), 'item_submit'); - $groupsIds = $grouppermHandler->getGroupIds('nw_approve', $arrCat['topic_id'], $ams_module_id); + $groupsIds = $grouppermHandler->getGroupIds('nw_approve', $arrCat['topic_id'], $moduleId); Utility::saveCategoryPermissions($groupsIds, $categoryObj->categoryid(), 'category_moderation'); $newCatArray[$newCat['oldid']] = $newCat; @@ -426,7 +425,7 @@ /** @var \XoopsCommentHandler $commentHandler */ $commentHandler = xoops_getHandler('comment'); $criteria = new \CriteriaCompo(); - $criteria->add(new \Criteria('com_modid', $ams_module_id)); + $criteria->add(new \Criteria('com_modid', $moduleId)); $comments = $commentHandler->getObjects($criteria); /** @var \XoopsComment $comment */ foreach ($comments as $comment) { diff --git a/admin/import/cjaycontent.php b/admin/import/cjaycontent.php index 55725548..52f8c593 100644 --- a/admin/import/cjaycontent.php +++ b/admin/import/cjaycontent.php @@ -25,6 +25,8 @@ Item, Utility }; +/** @var Helper $helper */ + const DIRNAME = 'cjaycontent'; require_once dirname(__DIR__) . '/admin_header.php'; @@ -93,10 +95,7 @@ //publisher_adminMenu(-1, _AM_PUBLISHER_IMPORT); // require_once dirname(dirname(__DIR__)) . '/include/common.php'; Utility::openCollapsableBar('cjaycontentimportgo', 'cjaycontentimportgoicon', sprintf(_AM_PUBLISHER_IMPORT_FROM, $importFromModuleName), _AM_PUBLISHER_IMPORT_RESULT); - /** @var \XoopsModuleHandler $moduleHandler */ - $moduleHandler = xoops_getHandler('module'); - $moduleObj = $moduleHandler->getByDirname(DIRNAME); - $cjaycontent_module_id = $moduleObj->getVar('mid'); + $moduleId = $helper->getModule()->getVar('mid'); /** @var \XoopsGroupPermHandler $grouppermHandler */ $grouppermHandler = xoops_getHandler('groupperm'); @@ -167,7 +166,7 @@ /** @var \XoopsCommentHandler $commentHandler */ $commentHandler = xoops_getHandler('comment'); $criteria = new \CriteriaCompo(); - $criteria->add(new \Criteria('com_modid', $cjaycontent_module_id)); + $criteria->add(new \Criteria('com_modid', $moduleId)); /** @var \XoopsComment $comment */ $comments = $commentHandler->getObjects($criteria); foreach ($comments as $comment) { diff --git a/admin/import/fmcontent.php b/admin/import/fmcontent.php index 853ad1e6..bfbbdee6 100644 --- a/admin/import/fmcontent.php +++ b/admin/import/fmcontent.php @@ -24,9 +24,11 @@ use Xmf\Request; use XoopsModules\Publisher\{Category, Constants, + Helper, Item, Utility }; +/** @var Helper $helper */ const DIRNAME = 'fmcontent'; @@ -48,20 +50,17 @@ Utility::cpHeader(); //publisher_adminMenu(-1, _AM_PUBLISHER_IMPORT); Utility::openCollapsableBar('fmimport', 'fmimporticon', sprintf(_AM_PUBLISHER_IMPORT_FROM, $importFromModuleName), _AM_PUBLISHER_IMPORT_INFO); - /** @var \XoopsModuleHandler $moduleHandler */ - $moduleHandler = xoops_getHandler('module'); - $moduleObj = $moduleHandler->getByDirname('fmcontent'); - $fm_module_id = $moduleObj->getVar('mid'); + $moduleId = $helper->getModule()->getVar('mid'); $fmTopicHdlr = xoops_getModuleHandler('topic', 'fmcontent'); - $fmTopicCount = $fmTopicHdlr->getCount(new \Criteria('topic_modid', $fm_module_id)); + $fmTopicCount = $fmTopicHdlr->getCount(new \Criteria('topic_modid', $moduleId)); if (empty($fmTopicCount)) { echo "" . _AM_PUBLISHER_IMPORT_NO_CATEGORY . ''; } else { require_once $GLOBALS['xoops']->path('www/class/xoopstree.php'); $fmContentHdlr = xoops_getModuleHandler('page', 'fmcontent'); - $fmContentCount = $fmContentHdlr->getCount(new \Criteria('content_modid', $fm_module_id)); + $fmContentCount = $fmContentHdlr->getCount(new \Criteria('content_modid', $moduleId)); if (empty($fmContentCount)) { echo "" . sprintf(_AM_PUBLISHER_IMPORT_MODULE_FOUND_NO_ITEMS, $importFromModuleName, $fmContentCount) . ''; @@ -75,7 +74,7 @@ . $GLOBALS['xoopsDB']->prefix('fmcontent_topic') . ' AS cat INNER JOIN ' . $GLOBALS['xoopsDB']->prefix('fmcontent_content') - . " AS art ON ((cat.topic_id=art.content_topic) AND (cat.topic_modid=art.content_modid)) WHERE cat.topic_modid={$fm_module_id} GROUP BY art.content_topic"; + . " AS art ON ((cat.topic_id=art.content_topic) AND (cat.topic_modid=art.content_modid)) WHERE cat.topic_modid={$moduleId} GROUP BY art.content_topic"; $result = $GLOBALS['xoopsDB']->query($sql); $catCboxOptions = []; @@ -86,7 +85,7 @@ } // now get articles in the top level category (content_topic=0) $criteria = new \CriteriaCompo(); - $criteria->add(new \Criteria('content_modid', $fm_module_id)); + $criteria->add(new \Criteria('content_modid', $moduleId)); $criteria->add(new \Criteria('content_topic', 0)); $cnt_tla_contents = $fmContentHdlr->getCount($criteria); if ($cnt_tla_contents) { @@ -141,11 +140,7 @@ Utility::cpHeader(); //publisher_adminMenu(-1, _AM_PUBLISHER_IMPORT); Utility::openCollapsableBar('fmimportgo', 'fmimportgoicon', sprintf(_AM_PUBLISHER_IMPORT_FROM, $importFromModuleName), _AM_PUBLISHER_IMPORT_RESULT); - - /** @var \XoopsModuleHandler $moduleHandler */ - $moduleHandler = xoops_getHandler('module'); - $moduleObj = $moduleHandler->getByDirname(DIRNAME); - $fm_module_id = $moduleObj->getVar('mid'); + $moduleId = $helper->getModule()->getVar('mid'); /** @var \XoopsGroupPermHandler $grouppermHandler */ $grouppermHandler = xoops_getHandler('groupperm'); @@ -158,7 +153,7 @@ $fmContentHdlr = xoops_getModuleHandler('page', 'fmcontent'); $criteria = new \CriteriaCompo(); - $criteria->add(new \Criteria('content_modid', $fm_module_id)); + $criteria->add(new \Criteria('content_modid', $moduleId)); $criteria->add(new \Criteria('content_topic', 0)); $fmContentObjs = $fmContentHdlr->getAll($criteria); @@ -231,9 +226,9 @@ } // Saving category permissions - $groupsIds = $grouppermHandler->getGroupIds('fmcontent_view', $thisFmContentObj->getVar('topic_id'), $fm_module_id); + $groupsIds = $grouppermHandler->getGroupIds('fmcontent_view', $thisFmContentObj->getVar('topic_id'), $moduleId); Utility::saveCategoryPermissions($groupsIds, $categoryObj->categoryid(), 'category_read'); - $groupsIds = $grouppermHandler->getGroupIds('fmcontent_submit', $thisFmContentObj->getVar('topic_id'), $fm_module_id); + $groupsIds = $grouppermHandler->getGroupIds('fmcontent_submit', $thisFmContentObj->getVar('topic_id'), $moduleId); Utility::saveCategoryPermissions($groupsIds, $categoryObj->categoryid(), 'item_submit'); unset($fmContentObjs, $itemObj, $categoryObj, $thisFmContentObj); @@ -245,7 +240,7 @@ $newArticleArray = []; $oldToNew = []; - $fmTopicObjs = $fmTopicHdlr->getAll(new \Criteria('topic_modid', $fm_module_id)); + $fmTopicObjs = $fmTopicHdlr->getAll(new \Criteria('topic_modid', $moduleId)); // first create FmContent Topics as Publisher Categories foreach ($fmTopicObjs as $thisFmTopicObj) { @@ -283,7 +278,7 @@ // retrieve all articles (content) for this category $criteria = new \CriteriaCompo(); - $criteria->add(new \Criteria('content_modid', $fm_module_id)); //only for this instance of fmcontent + $criteria->add(new \Criteria('content_modid', $moduleId)); //only for this instance of fmcontent $criteria->add(new \Criteria('content_topic', $thisFmTopicObj->getVar('topic_id'))); //for this category $fmContentObjs = $fmContentHdlr->getAll($criteria); @@ -330,9 +325,9 @@ } // Saving category permissions - $groupsIds = $grouppermHandler->getGroupIds('fmcontent_view', $thisFmContentObj->getVar('topic_id'), $fm_module_id); + $groupsIds = $grouppermHandler->getGroupIds('fmcontent_view', $thisFmContentObj->getVar('topic_id'), $moduleId); Utility::saveCategoryPermissions($groupsIds, $categoryObj->categoryid(), 'category_read'); - $groupsIds = $grouppermHandler->getGroupIds('fmcontent_submit', $thisFmContentObj->getVar('topic_id'), $fm_module_id); + $groupsIds = $grouppermHandler->getGroupIds('fmcontent_submit', $thisFmContentObj->getVar('topic_id'), $moduleId); Utility::saveCategoryPermissions($groupsIds, $categoryObj->categoryid(), 'item_submit'); $newCatArray[$catIds['oldid']] = $catIds; @@ -359,7 +354,7 @@ /** @var \XoopsCommentHandler $commentHandler */ $commentHandler = xoops_getHandler('comment'); $criteria = new \CriteriaCompo(); - $criteria->add(new \Criteria('com_modid', $fm_module_id)); + $criteria->add(new \Criteria('com_modid', $moduleId)); /** @var \XoopsComment $comment */ $comments = $commentHandler->getObjects($criteria); foreach ($comments as $comment) { diff --git a/admin/import/news.php b/admin/import/news.php index ae63c1fb..7d872ab5 100644 --- a/admin/import/news.php +++ b/admin/import/news.php @@ -23,9 +23,11 @@ use Xmf\Request; use XoopsModules\Publisher\{Category, Constants, + Helper, Item, Utility }; +/** @var Helper $helper */ const DIRNAME = 'news'; @@ -105,10 +107,7 @@ Utility::cpHeader(); //publisher_adminMenu(-1, _AM_PUBLISHER_IMPORT); Utility::openCollapsableBar('newsimportgo', 'newsimportgoicon', sprintf(_AM_PUBLISHER_IMPORT_FROM, $importFromModuleName), _AM_PUBLISHER_IMPORT_RESULT); - /** @var \XoopsModuleHandler $moduleHandler */ - $moduleHandler = xoops_getHandler('module'); - $moduleObj = $moduleHandler->getByDirname(DIRNAME); - $news_module_id = $moduleObj->getVar('mid'); + $moduleId = $helper->getModule()->getVar('mid'); /** @var \XoopsGroupPermHandler $grouppermHandler */ $grouppermHandler = xoops_getHandler('groupperm'); @@ -233,9 +232,9 @@ } // Saving category permissions - $groupsIds = $grouppermHandler->getGroupIds('news_view', $arrCat['topic_id'], $news_module_id); + $groupsIds = $grouppermHandler->getGroupIds('news_view', $arrCat['topic_id'], $moduleId); Utility::saveCategoryPermissions($groupsIds, $categoryObj->categoryid(), 'category_read'); - $groupsIds = $grouppermHandler->getGroupIds('news_submit', $arrCat['topic_id'], $news_module_id); + $groupsIds = $grouppermHandler->getGroupIds('news_submit', $arrCat['topic_id'], $moduleId); Utility::saveCategoryPermissions($groupsIds, $categoryObj->categoryid(), 'item_submit'); $newCatArray[$newCat['oldid']] = $newCat; @@ -265,7 +264,7 @@ /** @var \XoopsCommentHandler $commentHandler */ $commentHandler = xoops_getHandler('comment'); $criteria = new \CriteriaCompo(); - $criteria->add(new \Criteria('com_modid', $news_module_id)); + $criteria->add(new \Criteria('com_modid', $moduleId)); /** @var \XoopsComment $comment */ $comments = $commentHandler->getObjects($criteria); foreach ($comments as $comment) { diff --git a/admin/import/smartsection.php b/admin/import/smartsection.php index a77693f1..09dc6d80 100644 --- a/admin/import/smartsection.php +++ b/admin/import/smartsection.php @@ -27,6 +27,7 @@ Helper, Utility }; +/** @var Helper $helper */ const CATEGORY = 'smartsection_categories'; const ITEMID = 'itemid'; @@ -108,10 +109,8 @@ Utility::cpHeader(); //publisher_adminMenu(-1, _AM_PUBLISHER_IMPORT); Utility::openCollapsableBar('newsimportgo', 'newsimportgoicon', sprintf(_AM_PUBLISHER_IMPORT_FROM, $importFromModuleName), _AM_PUBLISHER_IMPORT_RESULT); - /** @var \XoopsModuleHandler $moduleHandler */ - $moduleHandler = xoops_getHandler('module'); - $moduleObj = $moduleHandler->getByDirname(DIRNAME); - $smartsection_module_id = $moduleObj->getVar('mid'); + $moduleId = $helper->getModule()->getVar('mid'); + /** @var \XoopsGroupPermHandler $grouppermHandler */ $grouppermHandler = xoops_getHandler('groupperm'); @@ -211,9 +210,9 @@ } // Saving category permissions - $groupsIds = $grouppermHandler->getGroupIds('category_read', $arrCat['categoryid'], $smartsection_module_id); + $groupsIds = $grouppermHandler->getGroupIds('category_read', $arrCat['categoryid'], $moduleId); Utility::saveCategoryPermissions($groupsIds, $categoryObj->categoryid(), 'category_read'); - $groupsIds = $grouppermHandler->getGroupIds('item_submit', $arrCat['categoryid'], $smartsection_module_id); + $groupsIds = $grouppermHandler->getGroupIds('item_submit', $arrCat['categoryid'], $moduleId); Utility::saveCategoryPermissions($groupsIds, $categoryObj->categoryid(), 'item_submit'); $newCatArray[$newCat['oldid']] = $newCat; @@ -243,7 +242,7 @@ /** @var \XoopsCommentHandler $commentHandler */ $commentHandler = xoops_getHandler('comment'); $criteria = new \CriteriaCompo(); - $criteria->add(new \Criteria('com_modid', $smartsection_module_id)); + $criteria->add(new \Criteria('com_modid', $moduleId)); /** @var \XoopsComment $comment */ $comments = $commentHandler->getObjects($criteria); foreach ($comments as $comment) { diff --git a/admin/import/wfsection.php b/admin/import/wfsection.php index 63bd41e3..38f768b9 100644 --- a/admin/import/wfsection.php +++ b/admin/import/wfsection.php @@ -24,9 +24,11 @@ use XoopsModules\Publisher\{Constants, Category, File, + Helper, Item, Utility }; +/** @var Helper $helper */ const CATEGORY = 'wfs_category'; const ITEMID = 'itemid'; @@ -252,16 +254,13 @@ // Looping through the comments to link them to the new articles and module echo _AM_PUBLISHER_IMPORT_COMMENTS . '
'; - /** @var \XoopsModuleHandler $moduleHandler */ - $moduleHandler = xoops_getHandler('module'); - $moduleObj = $moduleHandler->getByDirname(DIRNAME); - $news_module_id = $moduleObj->getVar('mid'); - + $moduleId = $helper->getModule()->getVar('mid'); + $publisher_module_id = $helper->getModule()->mid(); /** @var \XoopsCommentHandler $commentHandler */ $commentHandler = xoops_getHandler('comment'); $criteria = new \CriteriaCompo(); - $criteria->add(new \Criteria('com_modid', $news_module_id)); + $criteria->add(new \Criteria('com_modid', $moduleId)); /** @var \XoopsComment $comment */ $comments = $commentHandler->getObjects($criteria); foreach ($comments as $comment) { diff --git a/admin/import/xfsection.php b/admin/import/xfsection.php index fd2a9c4e..f2090324 100644 --- a/admin/import/xfsection.php +++ b/admin/import/xfsection.php @@ -24,9 +24,11 @@ use XoopsModules\Publisher\{Constants, Category, File, + Helper, Item, Utility }; +/** @var Helper $helper */ const CATEGORY = 'xfs_category'; const ITEMID = 'articleid'; @@ -250,16 +252,13 @@ // Looping through the comments to link them to the new articles and module echo _AM_PUBLISHER_IMPORT_COMMENTS . '
'; - /** @var \XoopsModuleHandler $moduleHandler */ - $moduleHandler = xoops_getHandler('module'); - $moduleObj = $moduleHandler->getByDirname(DIRNAME); - $news_module_id = $moduleObj->getVar('mid'); - + $moduleId = $helper->getModule()->getVar('mid'); + $publisher_module_id = $helper->getModule()->mid(); /** @var \XoopsCommentHandler $commentHandler */ $commentHandler = xoops_getHandler('comment'); $criteria = new \CriteriaCompo(); - $criteria->add(new \Criteria('com_modid', $news_module_id)); + $criteria->add(new \Criteria('com_modid', $moduleId)); /** @var \XoopsComment $comment */ $comments = $commentHandler->getObjects($criteria); foreach ($comments as $comment) { diff --git a/admin/import/xnews.php b/admin/import/xnews.php index 419cc6b2..b149eb5e 100644 --- a/admin/import/xnews.php +++ b/admin/import/xnews.php @@ -24,9 +24,11 @@ use XoopsModules\Publisher\{Constants, Category, File, + Helper, Item, Utility }; +/** @var Helper $helper */ const DIRNAME = 'xnews'; @@ -171,10 +173,8 @@ //publisher_adminMenu(-1, _AM_PUBLISHER_IMPORT); // require_once dirname(dirname(__DIR__)) . '/include/common.php'; Utility::openCollapsableBar('xnewsimportgo', 'xnewsimportgoicon', sprintf(_AM_PUBLISHER_IMPORT_FROM, $importFromModuleName), _AM_PUBLISHER_IMPORT_RESULT); - /** @var \XoopsModuleHandler $moduleHandler */ - $moduleHandler = xoops_getHandler('module'); - $moduleObj = $moduleHandler->getByDirname(DIRNAME); - $xnews_module_id = $moduleObj->getVar('mid'); + $moduleId = $helper->getModule()->getVar('mid'); + /** @var \XoopsGroupPermHandler $grouppermHandler */ $grouppermHandler = xoops_getHandler('groupperm'); @@ -390,12 +390,12 @@ } // Saving category permissions - $groupsIds = $grouppermHandler->getGroupIds('nw_view', $arrCat['topic_id'], $xnews_module_id); + $groupsIds = $grouppermHandler->getGroupIds('nw_view', $arrCat['topic_id'], $moduleId); Utility::saveCategoryPermissions($groupsIds, $categoryObj->categoryid(), 'category_read'); - $groupsIds = $grouppermHandler->getGroupIds('nw_submit', $arrCat['topic_id'], $xnews_module_id); + $groupsIds = $grouppermHandler->getGroupIds('nw_submit', $arrCat['topic_id'], $moduleId); Utility::saveCategoryPermissions($groupsIds, $categoryObj->categoryid(), 'item_submit'); - $groupsIds = $grouppermHandler->getGroupIds('nw_approve', $arrCat['topic_id'], $xnews_module_id); + $groupsIds = $grouppermHandler->getGroupIds('nw_approve', $arrCat['topic_id'], $moduleId); Utility::saveCategoryPermissions($groupsIds, $categoryObj->categoryid(), 'category_moderation'); $newCatArray[$newCat['oldid']] = $newCat; @@ -426,7 +426,7 @@ /** @var XoopsCommentHandler $commentHandler */ $commentHandler = xoops_getHandler('comment'); $criteria = new \CriteriaCompo(); - $criteria->add(new \Criteria('com_modid', $xnews_module_id)); + $criteria->add(new \Criteria('com_modid', $moduleId)); $comments = $commentHandler->getObjects($criteria); /** @var XoopsComment $comment */ foreach ($comments as $comment) { diff --git a/testdata/index.php b/testdata/index.php index bb933680..bcacb54a 100644 --- a/testdata/index.php +++ b/testdata/index.php @@ -24,6 +24,8 @@ }; use Xmf\Yaml; +/** @var Helper $helper */ + require_once dirname(__DIR__, 3) . '/include/cp_header.php'; require dirname(__DIR__) . '/preloads/autoloader.php'; @@ -64,6 +66,7 @@ function loadSampleData() $utility = new Utility(); $configurator = new Common\Configurator(); + $helper = Helper::getInstance(); $tables = \Xmf\Module\Helper::getHelper($moduleDirName)->getModule()->getInfo('tables'); @@ -82,8 +85,8 @@ function loadSampleData() // load permissions $table = 'group_permission'; $tabledata = Yaml::readWrapped($language . $table . '.yml'); - $mid = \Xmf\Module\Helper::getHelper($moduleDirName)->getModule()->getVar('mid'); - loadTableFromArrayWithReplace($table, $tabledata, 'gperm_modid', $mid); + $moduleId = $helper->getModule()->getVar('mid'); + loadTableFromArrayWithReplace($table, $tabledata, 'gperm_modid', $moduleId); // --- COPY test folder files --------------- if (is_array($configurator->copyTestFolders) && count($configurator->copyTestFolders) > 0) { @@ -102,8 +105,10 @@ function saveSampleData() global $xoopsConfig; $moduleDirName = basename(dirname(__DIR__)); $moduleDirNameUpper = mb_strtoupper($moduleDirName); + $helper = Helper::getInstance(); + $moduleId = $helper->getModule()->getVar('mid'); - $tables = \Xmf\Module\Helper::getHelper($moduleDirName)->getModule()->getInfo('tables'); + $tables = $helper->getModule()->getInfo('tables'); $languageFolder = __DIR__ . '/' . $xoopsConfig['language']; if (!file_exists($languageFolder . '/')) { @@ -119,7 +124,7 @@ function saveSampleData() // save permissions $criteria = new \CriteriaCompo(); - $criteria->add(new \Criteria('gperm_modid', \Xmf\Module\Helper::getHelper($moduleDirName)->getModule()->getVar('mid'))); + $criteria->add(new \Criteria('gperm_modid', $moduleId)); $skipColumns[] = 'gperm_id'; TableLoad::saveTableToYamlFile('group_permission', $exportFolder . 'group_permission.yml', $criteria, $skipColumns); unset($criteria);