Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
320 changes: 171 additions & 149 deletions SQL/0000-00-03-ConfigTables.sql

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions SQL/9999-99-99-drop_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ DROP TABLE IF EXISTS `help`;
DROP TABLE IF EXISTS `ConfigI18n`;
DROP TABLE IF EXISTS `Config`;
DROP TABLE IF EXISTS `ConfigSettings`;
DROP TABLE IF EXISTS `ConfigCategories`;
DROP TABLE IF EXISTS `menu_categories`;

-- issues must be deleted before `modules` table
Expand Down
36 changes: 36 additions & 0 deletions SQL/New_patches/2026-05-31_config-categories.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
CREATE TABLE `ConfigCategories` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Name` varchar(255) NOT NULL,
`Description` varchar(255) DEFAULT NULL,
`Visible` tinyint(1) DEFAULT '0',
`Label` varchar(255) DEFAULT NULL,
`OrderNumber` int(11) DEFAULT NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `Name` (`Name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO ConfigCategories (Name, Description, Visible, Label, OrderNumber)
SELECT Name, Description, Visible, Label, OrderNumber
FROM ConfigSettings
WHERE Parent IS NULL AND DataType IS NULL;

ALTER TABLE ConfigSettings
ADD COLUMN CategoryID int(11) DEFAULT NULL AFTER Parent;

UPDATE ConfigSettings child
JOIN ConfigSettings category_setting ON child.Parent=category_setting.ID
JOIN ConfigCategories category ON category.Name=category_setting.Name
SET child.CategoryID=category.ID,
child.Parent=NULL
WHERE category_setting.Parent IS NULL AND category_setting.DataType IS NULL;

DELETE FROM ConfigSettings
WHERE Parent IS NULL AND DataType IS NULL;

ALTER TABLE ConfigSettings
ADD KEY `fk_ConfigSettings_CategoryID_idx` (`CategoryID`),
ADD CONSTRAINT `fk_ConfigSettings_CategoryID`
FOREIGN KEY (`CategoryID`)
REFERENCES `ConfigCategories` (`ID`)
ON DELETE SET NULL
ON UPDATE CASCADE;
2 changes: 0 additions & 2 deletions modules/configuration/ajax/process.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ function getPathIDs(string $table): array
*/
$query = "SELECT c.ID FROM Config c "
. "LEFT JOIN ConfigSettings cs ON (c.ConfigID = cs.ID) "
. "JOIN ConfigSettings csp ON (cs.Parent = csp.ID) "
. "WHERE cs.DataType = 'web_path';";
break;
case 'ConfigSettings':
Expand Down Expand Up @@ -263,4 +262,3 @@ function validPath($value)
}
return true;
}

58 changes: 44 additions & 14 deletions modules/configuration/php/configuration.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ class Configuration extends \NDB_Form

$parentConfigItems = $DB->pselect(
"SELECT Label, Name
FROM ConfigSettings
WHERE Parent IS NULL AND Visible=1 ORDER BY OrderNumber",
FROM ConfigCategories
WHERE Visible=1 ORDER BY OrderNumber",
[]
);

Expand All @@ -129,6 +129,18 @@ class Configuration extends \NDB_Form
$config = \NDB_Config::singleton();
$DB = $this->loris->getDatabaseConnection();

$categories = iterator_to_array(
$DB->pselect(
"SELECT ID, Name, Description, Visible, 0 AS AllowMultiple,
NULL AS DataType, NULL AS Parent, Label, OrderNumber,
0 AS Multilingual
FROM ConfigCategories
WHERE Visible=1
ORDER BY OrderNumber",
[]
)
);

// Get the names and meta-information for the config settings in the database
$configs = iterator_to_array(
$DB->pselect(
Expand All @@ -143,18 +155,17 @@ class Configuration extends \NDB_Form
foreach ($configs as &$setting) {
try {
$setting['Disabled'] = 'Yes';
if ($setting['Parent'] != null) {
$valueFromXML = $config->getSettingFromXML($setting['Name']);
if (!is_array($valueFromXML)) {
$setting['Value'][0] = $valueFromXML;
} else {
$setting['Value'] = $valueFromXML;
}
$valueFromXML = $config->getSettingFromXML($setting['Name']);
if (!is_array($valueFromXML)) {
$setting['Value'][0] = $valueFromXML;
} else {
$setting['Value'] = $valueFromXML;
}
} catch (\ConfigurationException $e) {
$setting['Disabled'] = 'No';
}
}
unset($setting);

// Now check for config settings from the database for the fields not
// overridden in the config.xml
Expand All @@ -171,18 +182,37 @@ class Configuration extends \NDB_Form
}
}
}
unset($setting);

// build a tree from configs array
$tree = [];
$settingsByID = [];
$settingsByCategory = [];
foreach ($configs as &$node) {
$node['Children'] = [];
$tree[intval($node['ID'])] = &$node;
$node['Children'] = [];
$settingsByID[intval($node['ID'])] = &$node;
}
unset($node);

foreach ($configs as &$node) {
$tree[$node['Parent']]['Children'][] = &$node;
if ($node['Parent'] !== null) {
$settingsByID[intval($node['Parent'])]['Children'][] = &$node;
continue;
}

if ($node['CategoryID'] !== null) {
$settingsByCategory[intval($node['CategoryID'])][] = &$node;
}
}
unset($node);

foreach ($categories as &$category) {
$category['Disabled'] = 'No';
$category['Children'] = $settingsByCategory[intval($category['ID'])]
?? [];
}
unset($category);

return $configs;
return $categories;
}

/**
Expand Down
40 changes: 31 additions & 9 deletions php/libraries/NDB_Config.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,27 @@ class NDB_Config
if ($id === null) {
$configSetting = $db->pselect(
"SELECT cs.ID as ParentID, child.ID as ChildID,
cs.AllowMultiple, child.Name
cs.AllowMultiple, child.Name, 0 AS IsCategory
Comment thread
Montekkundan marked this conversation as resolved.
Outdated
FROM ConfigSettings cs
LEFT JOIN ConfigSettings child ON (child.Parent=cs.ID)
WHERE cs.Name=:nm",
["nm" => $name]
);

if (count($configSetting) === 0) {
$configSetting = $db->pselect(
"SELECT cc.ID as ParentID, child.ID as ChildID,
0 AS AllowMultiple, child.Name, 1 AS IsCategory
FROM ConfigCategories cc
LEFT JOIN ConfigSettings child ON (
child.CategoryID=cc.ID
AND child.Parent IS NULL
)
WHERE cc.Name=:nm",
["nm" => $name]
);
}

if (count($configSetting) === 0) {
throw new ConfigurationException(
"Config setting $name does not exist in database"
Expand All @@ -307,26 +321,32 @@ class NDB_Config
} else {
$configSetting = $db->pselect(
"SELECT cs.ID as ParentID, child.ID as ChildID,
cs.AllowMultiple, child.Name
cs.AllowMultiple, child.Name, 0 AS IsCategory
FROM ConfigSettings cs
LEFT JOIN ConfigSettings child ON (child.Parent=cs.ID)
WHERE cs.ID=:nm",
["nm" => $id]
);
}

$configSetting = array_values(iterator_to_array($configSetting));

// If 1 row is returned, there are no children so we just want to
// get the value from the database.
// If multiple rows are returned, it means that there are children
// for this element, so we need to build the tree to be consistent
// with what would have come from the config.xml.
if (count($configSetting) === 1) {
$firstConfigSetting = $configSetting[0] ?? null;
if (count($configSetting) === 1
&& $firstConfigSetting !== null
&& $firstConfigSetting['ChildID'] === null
&& intval($firstConfigSetting['IsCategory']) === 0
) {
// Trying to get a single value from the database.
$configSetting = $configSetting->getFirstRow();
if ($configSetting['AllowMultiple'] == '0') {
if ($firstConfigSetting['AllowMultiple'] == '0') {
$val = $db->pselectOne(
"SELECT Value FROM Config WHERE ConfigID=:CID",
['CID' => $configSetting['ParentID']]
['CID' => $firstConfigSetting['ParentID']]
);
if (empty($val)) {
return null;
Expand All @@ -337,18 +357,21 @@ class NDB_Config
// as ie. $config->getSetting("DoubleDataEntryInstruments")
$val = $db->pselect(
"SELECT Value FROM Config WHERE ConfigID=:CID",
['CID' => $configSetting['ParentID']]
['CID' => $firstConfigSetting['ParentID']]
);
$ret = [];
foreach ($val as $item) {
$ret[] = $item['Value'];
}
return $ret;
}
} else if (count($configSetting) > 1) {
} else if (count($configSetting) >= 1) {
// This was a parent element, so construct the children.
$tree = [];
foreach ($configSetting as $childSetting) {
if ($childSetting['ChildID'] === null) {
continue;
}
$childName = $childSetting['Name'];
$childID = $childSetting['ChildID'];
$childValue = $this->getSettingFromDB(
Expand Down Expand Up @@ -621,4 +644,3 @@ class NDB_Config

}
}

21 changes: 21 additions & 0 deletions raisinbread/RB_files/RB_ConfigCategories.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*M!999999\- enable the sandbox mode */
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE `ConfigCategories`;
LOCK TABLES `ConfigCategories` WRITE;
INSERT INTO `ConfigCategories` (`ID`, `Name`, `Description`, `Visible`, `Label`, `OrderNumber`) VALUES (1,'study','Settings related to details of the study',1,'Study',1);
INSERT INTO `ConfigCategories` (`ID`, `Name`, `Description`, `Visible`, `Label`, `OrderNumber`) VALUES (26,'paths','Specify directories where LORIS-related files are stored or created. Take care when editing these fields as changing them incorrectly can cause certain modules to lose functionality.',1,'Paths',2);
INSERT INTO `ConfigCategories` (`ID`, `Name`, `Description`, `Visible`, `Label`, `OrderNumber`) VALUES (39,'gui','Settings related to the overall display of LORIS',1,'GUI',3);
INSERT INTO `ConfigCategories` (`ID`, `Name`, `Description`, `Visible`, `Label`, `OrderNumber`) VALUES (43,'www','Web address settings',1,'WWW',4);
INSERT INTO `ConfigCategories` (`ID`, `Name`, `Description`, `Visible`, `Label`, `OrderNumber`) VALUES (45,'eeg_pipeline','EEG Pipeline settings',1,'EEG Pipeline',15);
INSERT INTO `ConfigCategories` (`ID`, `Name`, `Description`, `Visible`, `Label`, `OrderNumber`) VALUES (47,'dashboard','Settings that affect the appearance of the dashboard and its charts',1,'Dashboard',5);
INSERT INTO `ConfigCategories` (`ID`, `Name`, `Description`, `Visible`, `Label`, `OrderNumber`) VALUES (50,'imaging_modules','DICOM Archive and Imaging Browser settings',1,'Imaging Modules',6);
INSERT INTO `ConfigCategories` (`ID`, `Name`, `Description`, `Visible`, `Label`, `OrderNumber`) VALUES (57,'statistics','Statistics module settings',1,'Statistics',7);
INSERT INTO `ConfigCategories` (`ID`, `Name`, `Description`, `Visible`, `Label`, `OrderNumber`) VALUES (59,'mail','LORIS email settings for notifications sent to users',1,'Email',8);
INSERT INTO `ConfigCategories` (`ID`, `Name`, `Description`, `Visible`, `Label`, `OrderNumber`) VALUES (63,'uploads','Settings related to file uploading',1,'Uploads',9);
INSERT INTO `ConfigCategories` (`ID`, `Name`, `Description`, `Visible`, `Label`, `OrderNumber`) VALUES (65,'APIKeys','Specify any API keys required for LORIS',1,'API Keys',10);
INSERT INTO `ConfigCategories` (`ID`, `Name`, `Description`, `Visible`, `Label`, `OrderNumber`) VALUES (69,'imaging_pipeline','Imaging Pipeline settings',1,'Imaging Pipeline',14);
INSERT INTO `ConfigCategories` (`ID`, `Name`, `Description`, `Visible`, `Label`, `OrderNumber`) VALUES (111,'logs','Settings related to logging',1,'Log Settings',12);
INSERT INTO `ConfigCategories` (`ID`, `Name`, `Description`, `Visible`, `Label`, `OrderNumber`) VALUES (115,'minc2bids','Settings related to converting MINC to BIDS LORIS-MRI tool script',1,'MINC to BIDS Converter Tool Options',13);
INSERT INTO `ConfigCategories` (`ID`, `Name`, `Description`, `Visible`, `Label`, `OrderNumber`) VALUES (121,'aws','Settings related to AWS services',1,'AWS Settings',13);
INSERT INTO `ConfigCategories` (`ID`, `Name`, `Description`, `Visible`, `Label`, `OrderNumber`) VALUES (135,'biobank','Settings related to the biobank module',1,'Biobank',14);
UNLOCK TABLES;
Loading
Loading