diff --git a/install/empty_data.php b/install/empty_data.php index b687dbb2ed8..18d06687d18 100644 --- a/install/empty_data.php +++ b/install/empty_data.php @@ -4610,34 +4610,29 @@ public function getEmptyData(): array 'id' => '187', 'items_id' => '1', 'type' => '1', - 'notifications_id' => '71', - ], [ - 'id' => '188', - 'items_id' => '1', - 'type' => '1', 'notifications_id' => '72', ], [ - 'id' => '189', + 'id' => '188', 'items_id' => '1', 'type' => '1', 'notifications_id' => '74', ], [ - 'id' => '190', + 'id' => '189', 'items_id' => '1', 'type' => '1', 'notifications_id' => '75', ], [ - 'id' => '191', + 'id' => '190', 'items_id' => '1', 'type' => '1', 'notifications_id' => '80', ], [ - 'id' => '192', + 'id' => '191', 'items_id' => '1', 'type' => '1', 'notifications_id' => '81', ], [ - 'id' => '193', + 'id' => '192', 'items_id' => '1', 'type' => '1', 'notifications_id' => '82', diff --git a/install/migrations/update_11.0.5_to_11.0.6.php b/install/migrations/update_11.0.5_to_11.0.6.php new file mode 100644 index 00000000000..e14cb07638b --- /dev/null +++ b/install/migrations/update_11.0.5_to_11.0.6.php @@ -0,0 +1,72 @@ +. + * + * --------------------------------------------------------------------- + */ + +use function Safe\preg_match; +use function Safe\scandir; + +/** + * Update from 11.0.5 to 11.0.6 + * + * @return bool for success (will die for most error) + **/ +function update1105to1106() +{ + /** + * @var DBmysql $DB + * @var Migration $migration + */ + global $DB, $migration; + + $updateresult = true; + $ADDTODISPLAYPREF = []; + $DELFROMDISPLAYPREF = []; + $update_dir = __DIR__ . '/update_11.0.5_to_11.0.6/'; + + $migration->setVersion('11.0.6'); + + $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; +} diff --git a/install/migrations/update_11.0.5_to_11.0.6/notificationtargets.php b/install/migrations/update_11.0.5_to_11.0.6/notificationtargets.php new file mode 100644 index 00000000000..1970d51cfba --- /dev/null +++ b/install/migrations/update_11.0.5_to_11.0.6/notificationtargets.php @@ -0,0 +1,64 @@ +. + * + * --------------------------------------------------------------------- + */ + +/** + * @var DBmysql $DB + * @var Migration $migration + */ + +// Remove duplicates targets +$duplicates_targets_iterator = $DB->request([ + 'SELECT' => [ + 'notifications_id', + 'items_id', + 'type', + 'MIN' => 'id AS min_id', + 'COUNT' => '* AS count', + ], + 'FROM' => 'glpi_notificationtargets', + 'GROUPBY' => ['notifications_id', 'items_id', 'type'], + 'HAVING' => ['count' => ['>', 1]], +]); + +foreach ($duplicates_targets_iterator as $target) { + $DB->delete('glpi_notificationtargets', [ + 'notifications_id' => $target['notifications_id'], + 'items_id' => $target['items_id'], + 'type' => $target['type'], + 'id' => ['>', $target['min_id']], + ]); +} + +$migration->dropKey('glpi_notificationtargets', 'notifications_id'); +$migration->addKey('glpi_notificationtargets', ['notifications_id', 'items_id', 'type'], 'unicity', 'UNIQUE'); diff --git a/install/mysql/glpi-empty.sql b/install/mysql/glpi-empty.sql index 4521f392153..1d6e4f73d13 100644 --- a/install/mysql/glpi-empty.sql +++ b/install/mysql/glpi-empty.sql @@ -5075,8 +5075,8 @@ CREATE TABLE `glpi_notificationtargets` ( `notifications_id` int unsigned NOT NULL DEFAULT '0', `is_exclusion` tinyint NOT NULL DEFAULT '0', PRIMARY KEY (`id`), + UNIQUE KEY `unicity` (`notifications_id`,`items_id`,`type`), KEY `items` (`type`,`items_id`), - KEY `notifications_id` (`notifications_id`), KEY `is_exclusion` (`is_exclusion`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;