From 52e3877996e78b7e355f5a1ed2e7c1e9c565ac56 Mon Sep 17 00:00:00 2001 From: Jan Dolejs Date: Sun, 17 Dec 2023 17:58:11 +0100 Subject: [PATCH 1/5] add use default for authmails --- .../is_default_for_authmail.php | 40 +++++++++++++++++++ install/mysql/glpi-empty.sql | 1 + src/Auth.php | 3 ++ src/AuthMail.php | 15 +++++++ 4 files changed, 59 insertions(+) create mode 100644 install/migrations/update_10.0.10_to_10.0.11/is_default_for_authmail.php diff --git a/install/migrations/update_10.0.10_to_10.0.11/is_default_for_authmail.php b/install/migrations/update_10.0.10_to_10.0.11/is_default_for_authmail.php new file mode 100644 index 00000000000..a9dfd19445a --- /dev/null +++ b/install/migrations/update_10.0.10_to_10.0.11/is_default_for_authmail.php @@ -0,0 +1,40 @@ +. + * + * --------------------------------------------------------------------- + */ + +/** + * @var \Migration $migration + */ + +$migration->addField('glpi_authmails', 'is_default', "tinyint", ['value' => '0']); diff --git a/install/mysql/glpi-empty.sql b/install/mysql/glpi-empty.sql index a523ed903c1..d1ab34f8e39 100644 --- a/install/mysql/glpi-empty.sql +++ b/install/mysql/glpi-empty.sql @@ -141,6 +141,7 @@ CREATE TABLE `glpi_authmails` ( `date_creation` timestamp NULL DEFAULT NULL, `comment` text, `is_active` tinyint NOT NULL DEFAULT '0', + `is_default` tinyint(4) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `name` (`name`), KEY `date_mod` (`date_mod`), diff --git a/src/Auth.php b/src/Auth.php index aa392f5e4e1..ee3a3594829 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -1861,6 +1861,9 @@ public static function getLoginAuthMethods() ]); foreach ($iterator as $data) { $elements['mail-' . $data['id']] = $data['name']; + if ($data['is_default'] == 1) { + $elements['_default'] = 'mail-' . $data['id']; + } } return $elements; diff --git a/src/AuthMail.php b/src/AuthMail.php index a89f0d30c7a..f420ae44723 100644 --- a/src/AuthMail.php +++ b/src/AuthMail.php @@ -139,6 +139,15 @@ public function rawSearchOptions() 'datatype' => 'bool' ]; + $tab[] = [ + 'id' => '7', + 'table' => $this->getTable(), + 'field' => 'is_default', + 'name' => __('Default server'), + 'datatype' => 'bool', + 'massiveaction' => false + ]; + $tab[] = [ 'id' => '19', 'table' => $this->getTable(), @@ -192,6 +201,12 @@ public function showForm($ID, array $options = []) Dropdown::showYesNo('is_active', $this->fields['is_active']); echo ""; + $defaultrand = mt_rand(); + echo ""; + echo ""; + Dropdown::showYesNo('is_default', $this->fields['is_default'], -1, ['rand' => $defaultrand]); + echo ""; + echo ""; echo "" . __('Email domain Name (users email will be login@domain)') . ""; echo ""; From 4d94a6072e892af9cf576a90d2f2c77bcd452985 Mon Sep 17 00:00:00 2001 From: Jan Dolejs Date: Sun, 17 Dec 2023 18:32:24 +0100 Subject: [PATCH 2/5] move back --- .../is_default_for_authmail.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename install/migrations/{update_10.0.10_to_10.0.11 => update_10.0.11_to_10.0.12}/is_default_for_authmail.php (100%) diff --git a/install/migrations/update_10.0.10_to_10.0.11/is_default_for_authmail.php b/install/migrations/update_10.0.11_to_10.0.12/is_default_for_authmail.php similarity index 100% rename from install/migrations/update_10.0.10_to_10.0.11/is_default_for_authmail.php rename to install/migrations/update_10.0.11_to_10.0.12/is_default_for_authmail.php From ac402959a4c97a87991792b8ed64e5340bd76867 Mon Sep 17 00:00:00 2001 From: Jan Dolejs Date: Sun, 17 Dec 2023 18:40:57 +0100 Subject: [PATCH 3/5] register update --- .../migrations/update_10.0.11_to_10.0.12.php | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 install/migrations/update_10.0.11_to_10.0.12.php diff --git a/install/migrations/update_10.0.11_to_10.0.12.php b/install/migrations/update_10.0.11_to_10.0.12.php new file mode 100644 index 00000000000..76acd917e3c --- /dev/null +++ b/install/migrations/update_10.0.11_to_10.0.12.php @@ -0,0 +1,72 @@ +. + * + * --------------------------------------------------------------------- + */ + +/** + * Update from 10.0.11 to 10.0.12 + * + * @return bool for success (will die for most error) + **/ +function update10011to10012() +{ + /** + * @var \DBmysql $DB + * @var \Migration $migration + */ + global $DB, $migration; + + $updateresult = true; + $ADDTODISPLAYPREF = []; + $DELFROMDISPLAYPREF = []; + $update_dir = __DIR__ . '/update_10.0.11_to_10.0.12/'; + + //TRANS: %s is the number of new version + $migration->displayTitle(sprintf(__('Update to %s'), '10.0.12')); + $migration->setVersion('10.0.12'); + + $update_scripts = scandir($update_dir); + foreach ($update_scripts as $update_script) { + if (preg_match('/\.php$/', $update_script) !== 1) { + continue; + } + require $update_dir . $update_script; + } + + // ************ Keep it at the end ************** + $migration->updateDisplayPrefs($ADDTODISPLAYPREF, $DELFROMDISPLAYPREF); + + $migration->executeMigration(); + + return $updateresult; +} From 6715ec1e489709b0830ab85f0ab277897a6cd774 Mon Sep 17 00:00:00 2001 From: Jan Dolejs Date: Tue, 19 Dec 2023 11:11:04 +0100 Subject: [PATCH 4/5] fix installer --- .../update_10.0.11_to_10.0.12/is_default_for_authmail.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/migrations/update_10.0.11_to_10.0.12/is_default_for_authmail.php b/install/migrations/update_10.0.11_to_10.0.12/is_default_for_authmail.php index a9dfd19445a..4d5ae54ab0f 100644 --- a/install/migrations/update_10.0.11_to_10.0.12/is_default_for_authmail.php +++ b/install/migrations/update_10.0.11_to_10.0.12/is_default_for_authmail.php @@ -37,4 +37,4 @@ * @var \Migration $migration */ -$migration->addField('glpi_authmails', 'is_default', "tinyint", ['value' => '0']); +$migration->addField("glpi_authmails", "is_default", "TINYINT NOT NULL DEFAULT 0"); From 26f5141c58b4d810c588901a77066dbe349585b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Dolej=C5=A1?= Date: Tue, 20 Feb 2024 09:22:31 +0100 Subject: [PATCH 5/5] Update year in copyright --- .../update_10.0.11_to_10.0.12/is_default_for_authmail.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/migrations/update_10.0.11_to_10.0.12/is_default_for_authmail.php b/install/migrations/update_10.0.11_to_10.0.12/is_default_for_authmail.php index 4d5ae54ab0f..bd3b3f1c570 100644 --- a/install/migrations/update_10.0.11_to_10.0.12/is_default_for_authmail.php +++ b/install/migrations/update_10.0.11_to_10.0.12/is_default_for_authmail.php @@ -7,7 +7,7 @@ * * http://glpi-project.org * - * @copyright 2015-2023 Teclib' and contributors. + * @copyright 2015-2024 Teclib' and contributors. * @copyright 2003-2014 by the INDEPNET Development Team. * @licence https://www.gnu.org/licenses/gpl-3.0.html *