summaryrefslogtreecommitdiffstats
path: root/modules-available/sysconfig/addmodule.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/sysconfig/addmodule.inc.php')
-rw-r--r--modules-available/sysconfig/addmodule.inc.php53
1 files changed, 40 insertions, 13 deletions
diff --git a/modules-available/sysconfig/addmodule.inc.php b/modules-available/sysconfig/addmodule.inc.php
index 4564537e..32752c03 100644
--- a/modules-available/sysconfig/addmodule.inc.php
+++ b/modules-available/sysconfig/addmodule.inc.php
@@ -151,6 +151,9 @@ class AddModule_Assign extends AddModule_Base
protected function preprocessInternal()
{
+ if (!User::hasPermission('config.edit'))
+ Util::redirect('?do=SysConfig', false, true);
+
$assign = Request::any('assign', false, 'boolean');
if ($assign) {
@@ -159,39 +162,51 @@ class AddModule_Assign extends AddModule_Base
$moduleType = $this->edit->moduleType();
if (ConfigModule::getList()[$moduleType]['unique']) {
+ // Is a unique type module
$moduleIds = [];
foreach (ConfigModule::getAll($moduleType) ?? [] as $module) {
$moduleIds[] = $module->id();
}
-
- Database::exec("DELETE FROM configtgz_x_module WHERE configid IN (:configids) AND moduleid IN (:moduleids)",
- array('configids' => $configIds, 'moduleids' => $moduleIds));
+ // First, delete all modules of given type from all involved configs
+ Database::exec("DELETE FROM configtgz_x_module
+ WHERE configid IN (:configids)
+ AND moduleid IN (:moduleids)
+ AND moduleid <> :moduleid",
+ ['configids' => $configIds, 'moduleids' => $moduleIds, 'moduleid' => $moduleId]);
}
+ // Not delete module from all configs that are not selected
+ Database::exec("DELETE FROM configtgz_x_module WHERE moduleid = :moduleid AND configid NOT IN (:configids)",
+ ['configids' => $configIds, 'moduleid' => $moduleId]);
+ // Finally, (re)insert for all configs selected
foreach ($configIds as $configId) {
- Database::exec("INSERT INTO configtgz_x_module (configid, moduleid) VALUES (:configid, :moduleid)", array(
+ Database::exec("INSERT IGNORE INTO configtgz_x_module (configid, moduleid) VALUES (:configid, :moduleid)", array(
'configid' => $configId,
'moduleid' => $moduleId
));
- ConfigTgz::get($configId)->generate();
+ $config = ConfigTgz::get($configId);
+ $config->markOutdated();
+ $config->generate();
}
- Util::redirect('?do=SysConfig');
+ Util::redirect('?do=SysConfig', false, true);
}
}
protected function renderInternal()
{
$data = ['configs' => SysConfig::getAll()];
- if (count($data['configs']) === 0)
- Util::redirect('?do=SysConfig');
+ if (count($data['configs']) === 0) // Nothing to do
+ Util::redirect('?do=SysConfig', false, true);
$moduleType = $this->edit->moduleType();
+ // If this is a module of type unique, mark all configs that already contain a module of that type
if (ConfigModule::getList()[$moduleType]['unique']) {
- $modules = Database::queryAll('SELECT configtgz_module.moduleid as moduleid, configtgz_module.title as title, configtgz_x_module.configid as configid'
- . ' FROM configtgz_module INNER JOIN configtgz_x_module ON configtgz_module.moduleid = configtgz_x_module.moduleid'
- . ' WHERE configtgz_module.moduletype = :moduletype',
- array('moduletype' => $moduleType));
+ $modules = Database::queryAll("SELECT cm.moduleid as moduleid, cm.title as title, cxm.configid as configid
+ FROM configtgz_module cm
+ INNER JOIN configtgz_x_module cxm ON (cm.moduleid = cxm.moduleid)
+ WHERE cm.moduletype = :moduletype AND cxm.moduleid <> :moduleid",
+ ['moduletype' => $moduleType, 'moduleid' => $this->edit->id()]);
$modulesByConfigId = [];
foreach ($modules as $module) {
@@ -199,12 +214,24 @@ class AddModule_Assign extends AddModule_Base
}
foreach ($data['configs'] as &$config) {
- if (!isset($modulesByConfigId[$config['configid']])) continue;
+ if (!isset($modulesByConfigId[$config['configid']]))
+ continue;
$config['replaces'] = $modulesByConfigId[$config['configid']]['title'];
}
}
+ // Pre-check those that are already included
+ $tgzs = [];
+ foreach (ConfigTgz::getAllForModule($this->edit->id()) as $tgz) {
+ $tgzs[$tgz->id()] = 1;
+ }
+ foreach ($data['configs'] as &$config) {
+ if (!isset($tgzs[$config['configid']]))
+ continue;
+ $config['checked'] = 'checked';
+ }
$data['edit'] = $this->edit->id();
+ $data['name'] = $this->edit->title();
Render::addDialog(Dictionary::translate('lang_moduleAssign'), false, 'assign', $data);
}