diff --git a/install/migrations/update_10.0.17_to_10.0.18.php b/install/migrations/update_10.0.17_to_10.0.18.php new file mode 100644 index 00000000000..a50aa79bc01 --- /dev/null +++ b/install/migrations/update_10.0.17_to_10.0.18.php @@ -0,0 +1,72 @@ +. + * + * --------------------------------------------------------------------- + */ + +/** + * Update from 10.0.17 to 10.0.18 + * + * @return bool for success (will die for most error) + **/ +function update10017to10018() +{ + /** + * @var \DBmysql $DB + * @var \Migration $migration + */ + global $DB, $migration; + + $updateresult = true; + $ADDTODISPLAYPREF = []; + $DELFROMDISPLAYPREF = []; + $update_dir = __DIR__ . '/update_10.0.17_to_10.0.18/'; + + //TRANS: %s is the number of new version + $migration->displayTitle(sprintf(__('Update to %s'), '10.0.18')); + $migration->setVersion('10.0.18'); + + $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_10.0.17_to_10.0.18/models.php b/install/migrations/update_10.0.17_to_10.0.18/models.php new file mode 100644 index 00000000000..639c35880bd --- /dev/null +++ b/install/migrations/update_10.0.17_to_10.0.18/models.php @@ -0,0 +1,58 @@ +. + * + * --------------------------------------------------------------------- + */ + +/** + * @var \DBmysql $DB + * @var \Migration $migration + */ + +// Change model search options +$itemtypes = [ + 'ComputerModel', + 'EnclosureModel', + 'MonitorModel', + 'NetworkEquipmentModel', + 'PassiveDEquipmentModel', + 'PDUModel', + 'PeripheralModel', +]; +foreach ($itemtypes as $itemtype) { + $migration->changeSearchOption($itemtype, 131, 1500); + $migration->changeSearchOption($itemtype, 132, 1501); + $migration->changeSearchOption($itemtype, 133, 1502); + $migration->changeSearchOption($itemtype, 134, 1503); + $migration->changeSearchOption($itemtype, 135, 1504); + $migration->changeSearchOption($itemtype, 136, 1505); +} diff --git a/src/CommonDCModelDropdown.php b/src/CommonDCModelDropdown.php index b6c58ea5ce4..47c902a23de 100644 --- a/src/CommonDCModelDropdown.php +++ b/src/CommonDCModelDropdown.php @@ -135,7 +135,7 @@ public function rawSearchOptions() if ($DB->fieldExists($table, 'weight')) { $options[] = [ - 'id' => '131', + 'id' => '1500', 'table' => $table, 'field' => 'weight', 'name' => __('Weight'), @@ -145,7 +145,7 @@ public function rawSearchOptions() if ($DB->fieldExists($table, 'required_units')) { $options[] = [ - 'id' => '132', + 'id' => '1501', 'table' => $table, 'field' => 'required_units', 'name' => __('Required units'), @@ -155,7 +155,7 @@ public function rawSearchOptions() if ($DB->fieldExists($table, 'depth')) { $options[] = [ - 'id' => '133', + 'id' => '1502', 'table' => $table, 'field' => 'depth', 'name' => __('Depth'), @@ -164,7 +164,7 @@ public function rawSearchOptions() if ($DB->fieldExists($table, 'power_connections')) { $options[] = [ - 'id' => '134', + 'id' => '1503', 'table' => $table, 'field' => 'power_connections', 'name' => __('Power connections'), @@ -174,7 +174,7 @@ public function rawSearchOptions() if ($DB->fieldExists($table, 'power_consumption')) { $options[] = [ - 'id' => '135', + 'id' => '1504', 'table' => $table, 'field' => 'power_consumption', 'name' => __('Power consumption'), @@ -184,7 +184,77 @@ public function rawSearchOptions() if ($DB->fieldExists($table, 'is_half_rack')) { $options[] = [ - 'id' => '136', + 'id' => '1505', + 'table' => $table, + 'field' => 'is_half_rack', + 'name' => __('Is half rack'), + 'datatype' => 'bool' + ]; + } + + return $options; + } + + public static function rawSearchOptionsToAdd() + { + /** @var DBmysql $DB */ + global $DB; + + $options = []; + $table = self::getTable(); + + if ($DB->fieldExists($table, 'weight')) { + $options[] = [ + 'id' => '1500', + 'table' => $table, + 'field' => 'weight', + 'name' => __('Weight'), + 'datatype' => 'decimal' + ]; + } + + if ($DB->fieldExists($table, 'required_units')) { + $options[] = [ + 'id' => '1501', + 'table' => $table, + 'field' => 'required_units', + 'name' => __('Required units'), + 'datatype' => 'number' + ]; + } + + if ($DB->fieldExists($table, 'depth')) { + $options[] = [ + 'id' => '1502', + 'table' => $table, + 'field' => 'depth', + 'name' => __('Depth'), + ]; + } + + if ($DB->fieldExists($table, 'power_connections')) { + $options[] = [ + 'id' => '1503', + 'table' => $table, + 'field' => 'power_connections', + 'name' => __('Power connections'), + 'datatype' => 'number' + ]; + } + + if ($DB->fieldExists($table, 'power_consumption')) { + $options[] = [ + 'id' => '1504', + 'table' => $table, + 'field' => 'power_consumption', + 'name' => __('Power consumption'), + 'datatype' => 'decimal' + ]; + } + + if ($DB->fieldExists($table, 'is_half_rack')) { + $options[] = [ + 'id' => '1505', 'table' => $table, 'field' => 'is_half_rack', 'name' => __('Is half rack'), diff --git a/src/Computer.php b/src/Computer.php index 1931250c69c..3cac743016a 100644 --- a/src/Computer.php +++ b/src/Computer.php @@ -579,6 +579,8 @@ public function rawSearchOptions() 'datatype' => 'dropdown' ]; + $tab = array_merge($tab, ComputerModel::rawSearchOptionsToAdd()); + // add operating system search options $tab = array_merge($tab, Item_OperatingSystem::rawSearchOptionsToAdd(get_class($this))); diff --git a/src/Monitor.php b/src/Monitor.php index 3d39b5ef911..8af306d9612 100644 --- a/src/Monitor.php +++ b/src/Monitor.php @@ -453,6 +453,8 @@ public function rawSearchOptions() 'massiveaction' => false ]; + $tab = array_merge($tab, MonitorModel::rawSearchOptionsToAdd()); + $tab = array_merge($tab, Notepad::rawSearchOptionsToAdd()); $tab = array_merge($tab, Datacenter::rawSearchOptionsToAdd(get_class($this))); diff --git a/src/NetworkEquipment.php b/src/NetworkEquipment.php index 1e4b30771ba..165163595e7 100644 --- a/src/NetworkEquipment.php +++ b/src/NetworkEquipment.php @@ -493,6 +493,8 @@ public function rawSearchOptions() 'massiveaction' => false ]; + $tab = array_merge($tab, NetworkEquipmentModel::rawSearchOptionsToAdd()); + // add operating system search options $tab = array_merge($tab, Item_OperatingSystem::rawSearchOptionsToAdd(get_class($this)));