"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "install/update_91_92.php" between
glpi-9.3.3.tgz and glpi-9.4.0.tgz

About: GLPI is an IT and asset management software (Information Resource Manager).

update_91_92.php  (glpi-9.3.3.tgz):update_91_92.php  (glpi-9.4.0.tgz)
skipping to change at line 93 skipping to change at line 93
$migration->addField("glpi_softwarelicensetypes", "ancestors_cache", "longtex t"); $migration->addField("glpi_softwarelicensetypes", "ancestors_cache", "longtex t");
$migration->addField("glpi_softwarelicensetypes", "sons_cache", "longtext"); $migration->addField("glpi_softwarelicensetypes", "sons_cache", "longtext");
$migration->addField("glpi_softwarelicensetypes", "entities_id", "integer"); $migration->addField("glpi_softwarelicensetypes", "entities_id", "integer");
$migration->addField("glpi_softwarelicensetypes", "is_recursive", "bool"); $migration->addField("glpi_softwarelicensetypes", "is_recursive", "bool");
$tree = $migration->addField("glpi_softwarelicensetypes", "completename", "te xt"); $tree = $migration->addField("glpi_softwarelicensetypes", "completename", "te xt");
$migration->migrationOneTable('glpi_softwarelicensetypes'); $migration->migrationOneTable('glpi_softwarelicensetypes');
$migration->addKey("glpi_softwarelicensetypes", "softwarelicensetypes_id"); $migration->addKey("glpi_softwarelicensetypes", "softwarelicensetypes_id");
//First time the dropdown is changed from CommonDropdown to CommonTreeDropdow n //First time the dropdown is changed from CommonDropdown to CommonTreeDropdow n
if ($tree) { if ($tree) {
$query = "UPDATE `glpi_softwarelicensetypes` $DB->updateOrDie("glpi_softwarelicensetypes", [
SET `completename`=`name`, 'completename' => new \QueryExpression(DBmysql::quoteName("name")),
`is_recursive`='1'"; 'is_recursive' => "1"
$DB->queryOrDie($query, "9.2 make glpi_softwarelicensetypes a tree dropdow ],
n"); [true],
"9.2 make glpi_softwarelicensetypes a tree dropdown"
);
} }
// give READ right on components to profiles having UPDATE right // give READ right on components to profiles having UPDATE right
$query = "UPDATE `glpi_profilerights` $DB->updateOrDie("glpi_profilerights", [
SET `rights` = `rights` | " . READ . " 'rights' => new \QueryExpression($DB->quoteName("rights") . " | " . REA
WHERE (`rights` & " . UPDATE .") = '" . UPDATE ."' D)
AND `name` = 'device'"; ], [
$DB->queryOrDie($query, "grant READ right on components to profiles having UP new \QueryExpression(DBmysql::quoteName("rights") . " & " . DBmysql::qu
DATE right"); oteValue(UPDATE)),
'name' => "device"
],
"grant READ right on components to profiles having UPDATE right"
);
$migration->displayMessage(sprintf(__('Add of - %s to database'), 'Knowbase i tem link to tickets')); $migration->displayMessage(sprintf(__('Add of - %s to database'), 'Knowbase i tem link to tickets'));
if (!$DB->tableExists('glpi_knowbaseitems_items')) { if (!$DB->tableExists('glpi_knowbaseitems_items')) {
$query = "CREATE TABLE `glpi_knowbaseitems_items` ( $query = "CREATE TABLE `glpi_knowbaseitems_items` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`knowbaseitems_id` int(11) NOT NULL, `knowbaseitems_id` int(11) NOT NULL,
`itemtype` varchar(100) COLLATE utf8_unicode_ci NOT NULL, `itemtype` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`items_id` int(11) NOT NULL DEFAULT '0', `items_id` int(11) NOT NULL DEFAULT '0',
`date_creation` datetime DEFAULT NULL, `date_creation` datetime DEFAULT NULL,
`date_mod` datetime DEFAULT NULL, `date_mod` datetime DEFAULT NULL,
skipping to change at line 154 skipping to change at line 160
$migration->addKey("glpi_knowbaseitemtranslations", "users_id"); $migration->addKey("glpi_knowbaseitemtranslations", "users_id");
//set kb translations users... //set kb translations users...
foreach ($DB->request(['SELECT' => ['glpi_knowbaseitems.id', 'glpi_knowba seitems.users_id'], foreach ($DB->request(['SELECT' => ['glpi_knowbaseitems.id', 'glpi_knowba seitems.users_id'],
'FROM' => 'glpi_knowbaseitems', 'FROM' => 'glpi_knowbaseitems',
'INNER JOIN' => ["glpi_knowbaseitemtranslations" 'INNER JOIN' => ["glpi_knowbaseitemtranslations"
=> ['FKEY' => ['glpi_knowbaseitemtran slations' => 'knowbaseitems_id', => ['FKEY' => ['glpi_knowbaseitemtran slations' => 'knowbaseitems_id',
'glpi_knowbaseitems' => 'id']]]]) 'glpi_knowbaseitems' => 'id']]]])
as $knowitems) { as $knowitems) {
$query = "UPDATE `glpi_knowbaseitemtranslations` $DB->updateOrDie("glpi_knowbaseitemtranslations",
SET `users_id` = '{$knowitems['users_id']}' ['users_id' => $knowitems['users_id']],
WHERE `knowbaseitems_id` = '{$knowitems['id']}'"; ['knowbaseitems_id' => $knowitems['id']],
$DB->queryOrDie($query, 'Set knowledge base translations users'); "Set knowledge base translations users"
);
} }
$migration->addField("glpi_knowbaseitemtranslations", "date_mod", "DATETIME") ; $migration->addField("glpi_knowbaseitemtranslations", "date_mod", "DATETIME") ;
$migration->addField("glpi_knowbaseitemtranslations", "date_creation", "DATET IME"); $migration->addField("glpi_knowbaseitemtranslations", "date_creation", "DATET IME");
$migration->displayMessage(sprintf(__('Add of - %s to database'), 'Knowbase i tem comments')); $migration->displayMessage(sprintf(__('Add of - %s to database'), 'Knowbase i tem comments'));
if (!$DB->tableExists('glpi_knowbaseitems_comments')) { if (!$DB->tableExists('glpi_knowbaseitems_comments')) {
$query = "CREATE TABLE `glpi_knowbaseitems_comments` ( $query = "CREATE TABLE `glpi_knowbaseitems_comments` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`knowbaseitems_id` int(11) NOT NULL, `knowbaseitems_id` int(11) NOT NULL,
skipping to change at line 179 skipping to change at line 186
`language` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, `language` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL,
`comment` text COLLATE utf8_unicode_ci NOT NULL, `comment` text COLLATE utf8_unicode_ci NOT NULL,
`parent_comment_id` int(11) DEFAULT NULL, `parent_comment_id` int(11) DEFAULT NULL,
`date_creation` datetime DEFAULT NULL, `date_creation` datetime DEFAULT NULL,
`date_mod` datetime DEFAULT NULL, `date_mod` datetime DEFAULT NULL,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$DB->queryOrDie($query, "9.2 add table glpi_knowbaseitems_comments"); $DB->queryOrDie($query, "9.2 add table glpi_knowbaseitems_comments");
} }
$query = "UPDATE `glpi_profilerights` $DB->updateOrDie("glpi_profilerights", [
SET `rights` = `rights` | " . KnowbaseItem::COMMENTS ." 'rights' => new \QueryExpression(
WHERE `name` = 'knowbase'"; DBmysql::quoteName("rights") . " | " . DBmysql::quoteValue( Knowbase
$DB->queryOrDie($query, "9.2 update knowledge base with comment right"); Item::COMMENTS)
)
],
['name' => "knowbase"],
"9.2 update knowledge base with comment right"
);
// add kb category to task categories // add kb category to task categories
$migration->addField("glpi_taskcategories", "knowbaseitemcategories_id", "int eger"); $migration->addField("glpi_taskcategories", "knowbaseitemcategories_id", "int eger");
$migration->migrationOneTable("glpi_taskcategories"); $migration->migrationOneTable("glpi_taskcategories");
$migration->addKey("glpi_taskcategories", "knowbaseitemcategories_id"); $migration->addKey("glpi_taskcategories", "knowbaseitemcategories_id");
// #1476 - Add users_id on glpi_documents_items // #1476 - Add users_id on glpi_documents_items
$migration->addField("glpi_documents_items", "users_id", "integer", ['null' = > true]); $migration->addField("glpi_documents_items", "users_id", "integer", ['null' = > true]);
$migration->migrationOneTable("glpi_documents_items"); $migration->migrationOneTable("glpi_documents_items");
$migration->addKey("glpi_documents_items", "users_id"); $migration->addKey("glpi_documents_items", "users_id");
// TODO : can be improved when DBmysql->buildUpdate() support joins
$migration->addPostQuery("UPDATE `glpi_documents_items`, $migration->addPostQuery("UPDATE `glpi_documents_items`,
`glpi_documents` `glpi_documents`
SET `glpi_documents_items`.`users_id` = `glpi_docum ents`.`users_id` SET `glpi_documents_items`.`users_id` = `glpi_docum ents`.`users_id`
WHERE `glpi_documents_items`.`documents_id` = `glpi _documents`.`id`", WHERE `glpi_documents_items`.`documents_id` = `glpi _documents`.`id`",
"9.2 update set users_id on glpi_documents_items"); "9.2 update set users_id on glpi_documents_items");
//add product number //add product number
$product_types = ['Computer', $product_types = ['Computer',
'Printer', 'Printer',
'NetworkEquipment', 'NetworkEquipment',
skipping to change at line 500 skipping to change at line 512
`comment` text COLLATE utf8_unicode_ci, `comment` text COLLATE utf8_unicode_ci,
`date_mod` datetime DEFAULT NULL, `date_mod` datetime DEFAULT NULL,
`date_creation` datetime DEFAULT NULL, `date_creation` datetime DEFAULT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `name` (`name`), KEY `name` (`name`),
KEY `date_mod` (`date_mod`), KEY `date_mod` (`date_mod`),
KEY `date_creation` (`date_creation`) KEY `date_creation` (`date_creation`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$DB->queryOrDie($query, "9.2 add table glpi_devicefirmwaretypes"); $DB->queryOrDie($query, "9.2 add table glpi_devicefirmwaretypes");
$DB->queryOrDie("INSERT INTO `glpi_devicefirmwaretypes` VALUES ('1','BIOS' $DB->insertOrDie("glpi_devicefirmwaretypes", [
,NULL,NULL,NULL);"); 'id' => "1",
$DB->queryOrDie("INSERT INTO `glpi_devicefirmwaretypes` VALUES ('2','UEFI' 'name' => "BIOS",
,NULL,NULL,NULL);"); 'comment' => null,
$DB->queryOrDie("INSERT INTO `glpi_devicefirmwaretypes` VALUES ('3','Firmw 'date_mod' => null,
are',NULL,NULL,NULL);"); 'date_creation' => null
]);
$DB->insertOrDie("glpi_devicefirmwaretypes", [
'id' => "2",
'name' => "UEFI",
'comment' => null,
'date_mod' => null,
'date_creation' => null
]);
$DB->insertOrDie("glpi_devicefirmwaretypes", [
'id' => "3",
'name' => "Firmware",
'comment' => null,
'date_mod' => null,
'date_creation' => null
]);
} }
//Device sensors //Device sensors
if (!$DB->tableExists('glpi_devicesensors')) { if (!$DB->tableExists('glpi_devicesensors')) {
$query = "CREATE TABLE `glpi_devicesensors` ( $query = "CREATE TABLE `glpi_devicesensors` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`designation` varchar(255) COLLATE utf8_unicode_ci DEFAULT NUL L, `designation` varchar(255) COLLATE utf8_unicode_ci DEFAULT NUL L,
`devicesensortypes_id` int(11) NOT NULL DEFAULT '0', `devicesensortypes_id` int(11) NOT NULL DEFAULT '0',
`devicesensormodels_id` int(11) NOT NULL DEFAULT '0', `devicesensormodels_id` int(11) NOT NULL DEFAULT '0',
`comment` text COLLATE utf8_unicode_ci, `comment` text COLLATE utf8_unicode_ci,
skipping to change at line 582 skipping to change at line 614
COLLATE='utf8_unicode_ci' ENGINE=MyISAM;"; COLLATE='utf8_unicode_ci' ENGINE=MyISAM;";
$DB->queryOrDie($query, "9.2 add table glpi_devicesensortypes"); $DB->queryOrDie($query, "9.2 add table glpi_devicesensortypes");
} }
//Father/son for Software licenses //Father/son for Software licenses
$migration->addField("glpi_softwarelicenses", "softwarelicenses_id", "integer ", ['after' => 'softwares_id']); $migration->addField("glpi_softwarelicenses", "softwarelicenses_id", "integer ", ['after' => 'softwares_id']);
$new = $migration->addField("glpi_softwarelicenses", "completename", "text", ['after' => 'softwarelicenses_id']); $new = $migration->addField("glpi_softwarelicenses", "completename", "text", ['after' => 'softwarelicenses_id']);
$migration->addField("glpi_softwarelicenses", "level", "integer", ['after' => 'completename']); $migration->addField("glpi_softwarelicenses", "level", "integer", ['after' => 'completename']);
$migration->migrationOneTable("glpi_softwarelicenses"); $migration->migrationOneTable("glpi_softwarelicenses");
if ($new) { if ($new) {
$query = "UPDATE `glpi_softwarelicenses` $DB->updateOrDie("glpi_softwarelicenses", [
SET `completename`=`name`"; 'completename' => new \QueryExpression(DBmysql::quoteName("name"))
$DB->queryOrDie($query, "9.2 copy name to completename for software licens ],
es"); [true],
"9.2 copy name to completename for software licenses"
);
} }
// add template key to itiltasks // add template key to itiltasks
$migration->addField("glpi_tickettasks", "tasktemplates_id", "integer"); $migration->addField("glpi_tickettasks", "tasktemplates_id", "integer");
$migration->migrationOneTable('glpi_tickettasks'); $migration->migrationOneTable('glpi_tickettasks');
$migration->addKey("glpi_tickettasks", "tasktemplates_id"); $migration->addKey("glpi_tickettasks", "tasktemplates_id");
$migration->addField("glpi_problemtasks", "tasktemplates_id", "integer"); $migration->addField("glpi_problemtasks", "tasktemplates_id", "integer");
$migration->migrationOneTable('glpi_problemtasks'); $migration->migrationOneTable('glpi_problemtasks');
$migration->addKey("glpi_problemtasks", "tasktemplates_id"); $migration->addKey("glpi_problemtasks", "tasktemplates_id");
skipping to change at line 738 skipping to change at line 773
`tickets_id` int(11) NOT NULL DEFAULT '0', `tickets_id` int(11) NOT NULL DEFAULT '0',
`olalevels_id` int(11) NOT NULL DEFAULT '0', `olalevels_id` int(11) NOT NULL DEFAULT '0',
`date` datetime DEFAULT NULL, `date` datetime DEFAULT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `tickets_id` (`tickets_id`), KEY `tickets_id` (`tickets_id`),
KEY `olalevels_id` (`olalevels_id`), KEY `olalevels_id` (`olalevels_id`),
KEY `unicity` (`tickets_id`,`olalevels_id`) KEY `unicity` (`tickets_id`,`olalevels_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
$DB->queryOrDie($query, "9.2 add table glpi_olalevels_tickets"); $DB->queryOrDie($query, "9.2 add table glpi_olalevels_tickets");
$query = "REPLACE INTO `glpi_crontasks` $DB->updateOrInsert("glpi_crontasks", [
(`itemtype`, `name`, `frequency`, `param`, `state`, `mod 'frequency' => "604800",
e`, `allowmode`, 'param' => null,
`hourmin`, `hourmax`, `logs_lifetime`, `lastrun`, `lastc 'state' => "0",
ode`, `comment`) 'mode' => "1",
VALUES ('OlaLevel_Ticket', 'olaticket', 604800, NULL, 0, 1, 3, 'allowmode' => "3",
0, 24, 10, NULL, NULL, NULL); "; 'hourmin' => "0",
$DB->queryOrDie($query, "9.2 populate glpi_crontasks for olaticket"); 'hourmax' => "24",
'logs_lifetime' => "10",
'lastrun' => null,
'lastcode' => null,
'comment' => null
], [
'itemtype' => "OlaLevel_Ticket",
'name' => "olaticket"
]
);
} }
if (!$DB->tableExists('glpi_slms')) { if (!$DB->tableExists('glpi_slms')) {
// Changing the structure of the table 'glpi_slas' // Changing the structure of the table 'glpi_slas'
$migration->renameTable('glpi_slas', 'glpi_slms'); $migration->renameTable('glpi_slas', 'glpi_slms');
$migration->migrationOneTable('glpi_slas'); $migration->migrationOneTable('glpi_slas');
} }
// Changing the structure of the table 'glpi_slts' // Changing the structure of the table 'glpi_slts'
if ($DB->tableExists('glpi_slts')) { if ($DB->tableExists('glpi_slts')) {
skipping to change at line 844 skipping to change at line 890
//Problem changes //Problem changes
if ($DB->fieldExists("glpi_problems", "due_date")) { if ($DB->fieldExists("glpi_problems", "due_date")) {
$migration->changeField('glpi_problems', 'due_date', 'time_to_resolve', 'd atetime'); $migration->changeField('glpi_problems', 'due_date', 'time_to_resolve', 'd atetime');
$migration->migrationOneTable('glpi_problems'); $migration->migrationOneTable('glpi_problems');
$migration->dropKey('glpi_problems', 'due_date'); $migration->dropKey('glpi_problems', 'due_date');
$migration->addKey('glpi_problems', 'time_to_resolve'); $migration->addKey('glpi_problems', 'time_to_resolve');
} }
// ProfileRights changes // ProfileRights changes
$DB->queryOrDie("UPDATE `glpi_profilerights` $DB->updateOrDie("glpi_profilerights",
SET `name` = 'slm' ['name' => "slm"],
WHERE `name` = 'sla'", ['name' => "sla"],
"SLM profilerights migration"); "SLM profilerights migration"
);
//Sla rules criterias migration
$DB->queryOrDie("UPDATE `glpi_rulecriterias` //Sla rules criterias migration
SET `criteria` = 'slas_ttr_id' $DB->updateOrDie("glpi_rulecriterias",
WHERE `criteria` = 'slts_ttr_id'", ['criteria' => "slas_ttr_id"],
"SLA rulecriterias migration"); ['criteria' => "slts_ttr_id"],
"SLA rulecriterias migration"
$DB->queryOrDie("UPDATE `glpi_rulecriterias` );
SET `criteria` = 'slas_tto_id'
WHERE `criteria` = 'slts_tto_id'", $DB->updateOrDie("glpi_rulecriterias",
"SLA rulecriterias migration"); ['criteria' => "slas_tto_id"],
['criteria' => "slts_tto_id"],
"SLA rulecriterias migration"
);
// Sla rules actions migration // Sla rules actions migration
$DB->queryOrDie("UPDATE `glpi_ruleactions` $DB->updateOrDie("glpi_ruleactions",
SET `field` = 'slas_ttr_id' ['field' => "slas_ttr_id"],
WHERE `field` = 'slts_ttr_id'", ['field' => "slts_ttr_id"],
"SLA ruleactions migration"); "SLA ruleactions migration"
);
$DB->queryOrDie("UPDATE `glpi_ruleactions`
SET `field` = 'slas_tto_id' $DB->updateOrDie("glpi_ruleactions",
WHERE `field` = 'slts_tto_id'", ['field' => "slas_tto_id"],
"SLA ruleactions migration"); ['field' => "slts_tto_id"],
"SLA ruleactions migration"
);
/************** Auto login **************/ /************** Auto login **************/
$migration->addConfig([ $migration->addConfig([
'login_remember_time' => 604800, 'login_remember_time' => 604800,
'login_remember_default' => 1 'login_remember_default' => 1
]); ]);
if ($DB->tableExists('glpi_bookmarks')) { if ($DB->tableExists('glpi_bookmarks')) {
$migration->renameTable("glpi_bookmarks", "glpi_savedsearches"); $migration->renameTable("glpi_bookmarks", "glpi_savedsearches");
skipping to change at line 892 skipping to change at line 943
"tinyint(1) NOT NULL DEFAULT '2' COMMENT 'Do or do no t count results on list display; see SavedSearch::COUNT_* constants'"); "tinyint(1) NOT NULL DEFAULT '2' COMMENT 'Do or do no t count results on list display; see SavedSearch::COUNT_* constants'");
$migration->addField("glpi_savedsearches", "last_execution_date", $migration->addField("glpi_savedsearches", "last_execution_date",
"DATETIME NULL DEFAULT NULL"); "DATETIME NULL DEFAULT NULL");
$migration->addField("glpi_savedsearches", "counter", "int(11) NOT NULL DE FAULT '0'"); $migration->addField("glpi_savedsearches", "counter", "int(11) NOT NULL DE FAULT '0'");
$migration->migrationOneTable("glpi_savedsearches"); $migration->migrationOneTable("glpi_savedsearches");
$migration->addKey("glpi_savedsearches", 'last_execution_time'); $migration->addKey("glpi_savedsearches", 'last_execution_time');
$migration->addKey("glpi_savedsearches", 'do_count'); $migration->addKey("glpi_savedsearches", 'do_count');
$migration->addKey("glpi_savedsearches", 'last_execution_date'); $migration->addKey("glpi_savedsearches", 'last_execution_date');
} }
//ensure do_count is set to AUTO //ensure do_count is set to AUTO
$migration->addPostQuery("UPDATE `glpi_savedsearches` $migration->addPostQuery(
SET `do_count` = " . SavedSearch::COUNT_AUTO); $DB->buildUpdate("glpi_savedsearches",
$migration->addPostQuery("UPDATE `glpi_savedsearches` ['do_count' => SavedSearch::COUNT_AUTO],
SET `entities_id` = 0 [true]
WHERE `entities_id` = -1"); )
);
$migration->addPostQuery(
$DB->buildUpdate("glpi_savedsearches",
['entities_id' => "0"],
['entities_id' => "-1"]
)
);
if (!countElementsInTable('glpi_rules', if (!countElementsInTable('glpi_rules',
['sub_type' => 'RuleSoftwareCategory', ['sub_type' => 'RuleSoftwareCategory',
'uuid' => '500717c8-2bd6e957-53a12b5fd38869.86 003425'])) { 'uuid' => '500717c8-2bd6e957-53a12b5fd38869.86 003425'])) {
$rule = new Rule(); $rule = new Rule();
$rules_id = $rule->add(['name' => 'Import category from inventory t ool', $rules_id = $rule->add(['name' => 'Import category from inventory t ool',
'is_active' => 0, 'is_active' => 0,
'uuid' => '500717c8-2bd6e957-53a12b5fd38869 .86003425', 'uuid' => '500717c8-2bd6e957-53a12b5fd38869 .86003425',
'entities_id' => 0, 'entities_id' => 0,
'sub_type' => 'RuleSoftwareCategory', 'sub_type' => 'RuleSoftwareCategory',
skipping to change at line 928 skipping to change at line 987
$action->add(['rules_id' => $rules_id, $action->add(['rules_id' => $rules_id,
'action_type' => 'assign', 'action_type' => 'assign',
'field' => '_import_category', 'field' => '_import_category',
'value' => '1']); 'value' => '1']);
} }
} }
if ($DB->tableExists('glpi_queuedmails')) { if ($DB->tableExists('glpi_queuedmails')) {
$migration->renameTable("glpi_queuedmails", "glpi_queuednotifications"); $migration->renameTable("glpi_queuedmails", "glpi_queuednotifications");
} }
$migration->addPostQuery("UPDATE `glpi_crontasks`
SET `itemtype` = 'QueuedNotification' $migration->addPostQuery(
WHERE `itemtype` = 'QueuedMail'"); $DB->buildUpdate("glpi_crontasks",
$migration->addPostQuery("UPDATE `glpi_crontasks` ['itemtype' => "QueuedNotification"],
SET `name` = 'queuednotification' ['itemtype' => "QueuedMail"]
WHERE `name` = 'queuedmail'"); )
$migration->addPostQuery("UPDATE `glpi_crontasks` );
SET `name` = 'queuednotificationclean' $migration->addPostQuery(
WHERE `name` = 'queuedmailclean'"); $DB->buildUpdate("glpi_crontasks",
$migration->addPostQuery("UPDATE `glpi_profilerights` ['name' => "queuednotification"],
SET `name` = 'queuednotification' ['name' => "queuedmail"]
WHERE `name` = 'queuedmail'"); )
);
$migration->addPostQuery(
$DB->buildUpdate("glpi_crontasks",
['name' => "queuednotificationclean"],
['name' => "queuedmailclean"]
)
);
$migration->addPostQuery(
$DB->buildUpdate("glpi_profilerights",
['name' => "queuednotification"],
['name' => "queuedmail"]
)
);
if (isset($current_config['use_mailing']) && !isset($current_config['use_noti fications'])) { if (isset($current_config['use_mailing']) && !isset($current_config['use_noti fications'])) {
/** Notifications modes */ /** Notifications modes */
$migration->addConfig([ $migration->addConfig([
'use_notifications' => $current_config['use_mailing'], 'use_notifications' => $current_config['use_mailing'],
'notifications_mailing' => $current_con fig['use_mailing'], 'notifications_mailing' => $current_con fig['use_mailing'],
'notifications_ajax' => 0, 'notifications_ajax' => 0,
'notifications_ajax_check_interval' => '5' , 'notifications_ajax_check_interval' => '5' ,
'notifications_ajax_sound' => null, 'notifications_ajax_sound' => null,
'notifications_ajax_icon_url' => '/pics/glpi.png' 'notifications_ajax_icon_url' => '/pics/glpi.png'
skipping to change at line 969 skipping to change at line 1041
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `unicity` (`notifications_id`, `mode`, `notificatio ntemplates_id`), UNIQUE KEY `unicity` (`notifications_id`, `mode`, `notificatio ntemplates_id`),
KEY `notifications_id` (`notifications_id`), KEY `notifications_id` (`notifications_id`),
KEY `notificationtemplates_id` (`notificationtemplates_id`), KEY `notificationtemplates_id` (`notificationtemplates_id`),
KEY `mode` (`mode`) KEY `mode` (`mode`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$DB->queryOrDie($query, "9.2 add table glpi_notifications_notificationtemp lates"); $DB->queryOrDie($query, "9.2 add table glpi_notifications_notificationtemp lates");
} }
if ($DB->fieldExists("glpi_notifications", "mode", false)) { if ($DB->fieldExists("glpi_notifications", "mode", false)) {
// TODO can be done when DB::updateOrInsert() supports SELECT
$query = "REPLACE INTO `glpi_notifications_notificationtemplates` $query = "REPLACE INTO `glpi_notifications_notificationtemplates`
(`notifications_id`, `mode`, `notificationtemplates_id`) (`notifications_id`, `mode`, `notificationtemplates_id`)
SELECT `id`, `mode`, `notificationtemplates_id` SELECT `id`, `mode`, `notificationtemplates_id`
FROM `glpi_notifications`"; FROM `glpi_notifications`";
$DB->queryOrDie($query, "9.2 migrate notifications templates"); $DB->queryOrDie($query, "9.2 migrate notifications templates");
//migrate any existing mode before removing the field //migrate any existing mode before removing the field
$migration->dropField('glpi_notifications', 'mode'); $migration->dropField('glpi_notifications', 'mode');
$migration->dropField('glpi_notifications', 'notificationtemplates_id'); $migration->dropField('glpi_notifications', 'notificationtemplates_id');
$migration->migrationOneTable("glpi_notifications"); $migration->migrationOneTable("glpi_notifications");
} }
$migration->addField('glpi_queuednotifications', 'mode', $migration->addField('glpi_queuednotifications', 'mode',
'varchar(20) COLLATE utf8_unicode_ci NOT NULL COMMENT \' See Notification_NotificationTemplate::MODE_* constants\''); 'varchar(20) COLLATE utf8_unicode_ci NOT NULL COMMENT \' See Notification_NotificationTemplate::MODE_* constants\'');
$migration->migrationOneTable("glpi_queuednotifications"); $migration->migrationOneTable("glpi_queuednotifications");
$migration->addKey('glpi_queuednotifications', 'mode'); $migration->addKey('glpi_queuednotifications', 'mode');
$migration->addPostQuery("UPDATE `glpi_queuednotifications` $migration->addPostQuery(
SET `mode` = '" . Notification_NotificationTemplate $DB->buildUpdate("glpi_queuednotifications",
::MODE_MAIL . "'", ['mode' => Notification_NotificationTemplate::MODE_MAIL],
'9.2 set default mode in queue'); [true]
$migration->addPostQuery("UPDATE `glpi_notifications_notificationtemplates` ),
SET `mode` = '" . Notification_NotificationTemplate "9.2 set default mode in queue"
::MODE_MAIL . "' );
WHERE `mode` = 'mail'",
'9.2 set default mode in notifications templates'); $migration->addPostQuery(
$DB->buildUpdate("glpi_notifications_notificationtemplates",
['mode' => Notification_NotificationTemplate::MODE_MAIL],
['mode' => "mail"]
),
"9.2 set default mode in notifications templates"
);
// Migration Bookmark -> SavedSearch_Alert // Migration Bookmark -> SavedSearch_Alert
//TRANS: %s is the table or item to migrate //TRANS: %s is the table or item to migrate
if ($DB->tableExists('glpi_bookmarks_users')) { if ($DB->tableExists('glpi_bookmarks_users')) {
$migration->renameTable("glpi_bookmarks_users", "glpi_savedsearches_users" ); $migration->renameTable("glpi_bookmarks_users", "glpi_savedsearches_users" );
$migration->changeField('glpi_savedsearches_users', 'bookmarks_id', 'saved searches_id', $migration->changeField('glpi_savedsearches_users', 'bookmarks_id', 'saved searches_id',
'int(11) NOT NULL DEFAULT "0"'); 'int(11) NOT NULL DEFAULT "0"');
} }
if (!$DB->tableExists('glpi_savedsearches_alerts')) { if (!$DB->tableExists('glpi_savedsearches_alerts')) {
skipping to change at line 1028 skipping to change at line 1109
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$DB->queryOrDie($query, "9.2 add table glpi_savedsearches_alerts"); $DB->queryOrDie($query, "9.2 add table glpi_savedsearches_alerts");
} }
$migration->displayMessage(sprintf(__('Data migration - %s'), 'glpi_displaypr eferences')); $migration->displayMessage(sprintf(__('Data migration - %s'), 'glpi_displaypr eferences'));
$ADDTODISPLAYPREF['SavedSearch'] = [8, 9, 3, 10, 11]; $ADDTODISPLAYPREF['SavedSearch'] = [8, 9, 3, 10, 11];
foreach ($ADDTODISPLAYPREF as $type => $tab) { foreach ($ADDTODISPLAYPREF as $type => $tab) {
$rank = 1; $rank = 1;
foreach ($tab as $newval) { foreach ($tab as $newval) {
$query = "REPLACE INTO `glpi_displaypreferences` $DB->updateOrInsert("glpi_displaypreferences", [
(`itemtype` ,`num` ,`rank` ,`users_id`) 'rank' => $rank++
VALUES ('$type', '$newval', '".$rank++."', '0')"; ], [
$DB->query($query); 'users_id' => "0",
'itemtype' => $type,
'num' => $newval,
]);
} }
} }
if (countElementsInTable('glpi_logs') < 2000000) { if (countElementsInTable('glpi_logs') < 2000000) {
//add index only if this sounds... possible. //add index only if this sounds... possible.
$migration->addKey("glpi_logs", "id_search_option"); $migration->addKey("glpi_logs", "id_search_option");
} else { } else {
//Just display a Warning to the user. //Just display a Warning to the user.
$migration->displayWarning("An index must be added in the 'id_search_optio n' field " . $migration->displayWarning("An index must be added in the 'id_search_optio n' field " .
"of the 'glpi_logs table'; but your glpi_logs table is " . "of the 'glpi_logs table'; but your glpi_logs table is " .
"too huge. You'll have to add it on your database " . "too huge. You'll have to add it on your database " .
"with the following query:\n" . "with the following query:\n" .
"'ALTER TABLE glpi_logs ADD INDEX id_search_option(id_search_option);'" ); "'ALTER TABLE glpi_logs ADD INDEX id_search_option(id_search_option);'" );
} }
// count cron task // count cron task
if (!countElementsInTable('glpi_crontasks', if (!countElementsInTable('glpi_crontasks',
['itemtype' => 'SavedSearch', 'name' => 'countAll'] )) { ['itemtype' => 'SavedSearch', 'name' => 'countAll'] )) {
$query = "INSERT INTO `glpi_crontasks` $DB->insertOrDie("glpi_crontasks", [
(`itemtype`, `name`, `frequency`, `param`, `state`, `mode 'itemtype' => "SavedSearch",
`, `allowmode`, 'name' => "countAll",
`hourmin`, `hourmax`, `logs_lifetime`, `lastrun`, `lastc 'frequency' => "604800",
ode`, `comment`) 'param' => null,
VALUES ('SavedSearch', 'countAll', 604800, NULL, 0, 1, 3, 'state' => "0",
0, 24, 10, NULL, NULL, NULL); "; 'mode' => "1",
$DB->queryOrDie($query, "9.2 Add countAll SavedSearch cron task"); 'allowmode' => "3",
} 'hourmin' => "0",
'hourmax' => "24",
'logs_lifetime' => "10",
'lastrun' => null,
'lastcode' => null,
'comment' => null
],
"9.2 Add countAll SavedSearch cron task"
);
};
// alerts cron task // alerts cron task
if (!countElementsInTable('glpi_crontasks', if (!countElementsInTable('glpi_crontasks',
['itemtype' => 'SavedSearch_Alert', 'name' => 'save dsearchesalerts'])) { ['itemtype' => 'SavedSearch_Alert', 'name' => 'save dsearchesalerts'])) {
$query = "INSERT INTO `glpi_crontasks` $DB->insertOrDie("glpi_crontasks", [
(`itemtype`, `name`, `frequency`, `param`, `state`, `mode 'itemtype' => "SavedSearch_Alert",
`, `allowmode`, 'name' => "savedsearchesalerts",
`hourmin`, `hourmax`, `logs_lifetime`, `lastrun`, `lastc 'frequency' => "86400",
ode`, `comment`) 'param' => null,
VALUES ('SavedSearch_Alert', 'savedsearchesalerts', 86400, NULL, 'state' => "0",
0, 1, 3, 'mode' => "1",
0, 24, 10, NULL, NULL, NULL); "; 'allowmode' => "3",
$DB->queryOrDie($query, "9.2 Add saved searches alerts cron task"); 'hourmin' => "0",
'hourmax' => "24",
'logs_lifetime' => "10",
'lastrun' => null,
'lastcode' => null,
'comment' => null
],
"9.2 Add saved searches alerts cron task"
);
} }
if (!countElementsInTable('glpi_notifications', if (!countElementsInTable('glpi_notifications',
['itemtype' => 'SavedSearch_Alert'])) { ['itemtype' => 'SavedSearch_Alert'])) {
$query = "INSERT INTO `glpi_notifications` $DB->insertOrDie("glpi_notifications", [
(`id`, `name`, `entities_id`, `itemtype`, `event`, `comment`, 'id' => null,
`is_recursive`, `is_active`, `date_creation`, `date_mod`) 'name' => "Saved searches",
VALUES (null,'Saved searches','0','SavedSearch_Alert','alert', 'entities_id' => "0",
'', '1', '1', NOW(), NOW());"; 'itemtype' => "SavedSearch_Alert",
$DB->queryOrDie($query, "9.2 Add saved search alerts notification"); 'event' => "alert",
'comment' => "",
'is_recursive' => "1",
'is_active' => "1",
'date_creation' => new \QueryExpression("NOW()"),
'date_mod' => new \QueryExpression("NOW()")
],
"9.2 Add saved search alerts notification"
);
$notid = $DB->insert_id(); $notid = $DB->insert_id();
$query = "INSERT INTO `glpi_notificationtemplates` $DB->insertOrDie("glpi_notificationtemplates", [
(`name`, `itemtype`, `date_mod`) 'name' => "Saved searches alerts",
VALUES ('Saved searches alerts', 'SavedSearch_Alert', NOW())"; 'itemtype' => "SavedSearch_Alert",
$DB->queryOrDie($query, "9.2 Add saved search alerts notification template 'date_mod' => new \QueryExpression("NOW()")
"); ],
"9.2 Add saved search alerts notification template"
);
$nottid = $DB->insert_id(); $nottid = $DB->insert_id();
$where = [ $where = [
'notifications_id' => $notid, 'notifications_id' => $notid,
'mode' => Notification_NotificationTemplate::MODE_M AIL, 'mode' => Notification_NotificationTemplate::MODE_M AIL,
'notificationtemplates_id' => $nottid 'notificationtemplates_id' => $nottid
]; ];
if (countElementsInTable('glpi_notifications_notificationtemplates', $wher e)) { if (countElementsInTable('glpi_notifications_notificationtemplates', $wher e)) {
$query = "REPLACE INTO `glpi_notifications_notificationtemplates` $DB->updateOrInsert("glpi_notifications_notificationtemplates", [
VALUES (null, $notid, '".Notification_NotificationTemplate::M 'id' => null
ODE_MAIL."', $nottid);"; ], [
$DB->queryOrDie($query, "9.2 Add saved search alerts notification"); 'notifications_id' => $notid,
'mode' => Notification_NotificationTemplate::
MODE_MAIL,
'notificationtemplates_id' => $nottid
]
);
} }
$query = "INSERT INTO `glpi_notificationtargets` $DB->insertOrDie("glpi_notificationtargets", [
VALUES (null,'19','1','$notid');"; 'id' => null,
$DB->queryOrDie($query, "9.2 Add saved search alerts notification targets" 'items_id' => "19",
); 'type' => "1",
'notifications_id' => $notid
],
"9.2 Add saved search alerts notification targets"
);
$query = "INSERT INTO `glpi_notificationtemplatetranslations` $query = "INSERT INTO `glpi_notificationtemplatetranslations`
(`notificationtemplates_id`, `language`,`subject`, (`notificationtemplates_id`, `language`,`subject`,
`content_text`, `content_text`,
`content_html`) `content_html`)
VALUES ($notid, '', '##savedsearch.action## ##savedsearch.n ame##', VALUES ($notid, '', '##savedsearch.action## ##savedsearch.n ame##',
'##savedsearch.type## ###savedsearch.id## - ##savedsearch.n ame## '##savedsearch.type## ###savedsearch.id## - ##savedsearch.n ame##
##savedsearch.message## ##savedsearch.message##
skipping to change at line 1209 skipping to change at line 1336
`date_mod` datetime DEFAULT NULL, `date_mod` datetime DEFAULT NULL,
`date_creation` datetime DEFAULT NULL, `date_creation` datetime DEFAULT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `name` (`name`) KEY `name` (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$DB->queryOrDie($query, "9.2 add table glpi_operatingsystemeditions"); $DB->queryOrDie($query, "9.2 add table glpi_operatingsystemeditions");
} }
if ($DB->fieldExists('glpi_computers', 'operatingsystems_id')) { if ($DB->fieldExists('glpi_computers', 'operatingsystems_id')) {
//migrate data from computers table, and drop old fields //migrate data from computers table, and drop old fields
// TODO can be done when DB::updateOrInsert() supports SELECT
$query = "REPLACE INTO `glpi_items_operatingsystems` $query = "REPLACE INTO `glpi_items_operatingsystems`
(`itemtype`, `items_id`, `operatingsystems_id`, `operatin gsystemversions_id`, (`itemtype`, `items_id`, `operatingsystems_id`, `operatin gsystemversions_id`,
`operatingsystemservicepacks_id`, `operatingsystemarchit ectures_id`, `operatingsystemservicepacks_id`, `operatingsystemarchit ectures_id`,
`license_number`, `license_id`) `license_number`, `license_id`)
SELECT 'Computer', `id`, `operatingsystems_id`, `operatin gsystemversions_id`, SELECT 'Computer', `id`, `operatingsystems_id`, `operatin gsystemversions_id`,
`operatingsystemservicepacks_id`, `operatingsystem architectures_id`, `operatingsystemservicepacks_id`, `operatingsystem architectures_id`,
`os_license_number`, `os_licenseid` `os_license_number`, `os_licenseid`
FROM `glpi_computers` FROM `glpi_computers`
WHERE `operatingsystems_id` != 0 WHERE `operatingsystems_id` != 0
OR `operatingsystemservicepacks_id` != 0 OR `operatingsystemservicepacks_id` != 0
skipping to change at line 1241 skipping to change at line 1369
$key = md5($data['os_kernel_version']); $key = md5($data['os_kernel_version']);
if (!isset($mapping[$key])) { if (!isset($mapping[$key])) {
$mapping[$key] = []; $mapping[$key] = [];
} }
$kver->add(['version' => $DB->escape($data['os_kernel_version'])]); $kver->add(['version' => $DB->escape($data['os_kernel_version'])]);
$mapping[$key][$data['id']] = $kver->getID(); $mapping[$key][$data['id']] = $kver->getID();
} }
foreach ($mapping as $map) { foreach ($mapping as $map) {
foreach ($map as $computers_id => $kver_id) { foreach ($map as $computers_id => $kver_id) {
$query = "UPDATE glpi_items_operatingsystems $DB->updateOrDie("glpi_items_operatingsystems",
SET operatingsystemkernelversions_id = '$kver_id' ['operatingsystemkernelversions_id' => $kver_id],
WHERE itemtype='Computer' AND items_id = '$computers_id'"; [
$DB->queryOrDie($query); 'itemtype' => "Computer",
'items_id' => $computers_id
]
);
} }
} }
$migration->dropKey('glpi_computers', 'operatingsystems_id'); $migration->dropKey('glpi_computers', 'operatingsystems_id');
$migration->dropField('glpi_computers', 'operatingsystems_id'); $migration->dropField('glpi_computers', 'operatingsystems_id');
$migration->dropKey('glpi_computers', 'operatingsystemservicepacks_id'); $migration->dropKey('glpi_computers', 'operatingsystemservicepacks_id');
$migration->dropField('glpi_computers', 'operatingsystemservicepacks_id'); $migration->dropField('glpi_computers', 'operatingsystemservicepacks_id');
$migration->dropKey('glpi_computers', 'operatingsystemversions_id'); $migration->dropKey('glpi_computers', 'operatingsystemversions_id');
$migration->dropField('glpi_computers', 'operatingsystemversions_id'); $migration->dropField('glpi_computers', 'operatingsystemversions_id');
$migration->dropKey('glpi_computers', 'operatingsystemarchitectures_id'); $migration->dropKey('glpi_computers', 'operatingsystemarchitectures_id');
skipping to change at line 1386 skipping to change at line 1517
if (countElementsInTable("glpi_profilerights", ['name' => 'certificate']) == 0) { if (countElementsInTable("glpi_profilerights", ['name' => 'certificate']) == 0) {
//new right for certificate //new right for certificate
//give full rights to profiles having config right //give full rights to profiles having config right
foreach ($DB->request("glpi_profilerights", "`name` = 'config'") as $profr ights) { foreach ($DB->request("glpi_profilerights", "`name` = 'config'") as $profr ights) {
if ($profrights['rights'] && (READ + UPDATE)) { if ($profrights['rights'] && (READ + UPDATE)) {
$rightValue = CREATE | READ | UPDATE | DELETE | PURGE | READNOTE | UPDATENOTE | UNLOCK; $rightValue = CREATE | READ | UPDATE | DELETE | PURGE | READNOTE | UPDATENOTE | UNLOCK;
} else { } else {
$rightValue = 0; $rightValue = 0;
} }
$query = "INSERT INTO `glpi_profilerights`
(`id`, `profiles_id`, `name`, `rights`) $DB->insertOrDie("glpi_profilerights", [
VALUES (NULL, '".$profrights['profiles_id']."', 'certificate' 'id' => null,
, 'profiles_id' => $profrights['profiles_id'],
'".$rightValue."')"; 'name' => "certificate",
$DB->queryOrDie($query, "9.1 add right for certificates"); 'rights' => $rightValue,
],
"9.2 add right for certificates"
);
} }
} }
// add alert for certificates // add alert for certificates
$migration->addField("glpi_entities", 'use_certificates_alert', "integer", $migration->addField("glpi_entities", 'use_certificates_alert', "integer",
['value' => -2, ['value' => -2,
'after' => 'send_licenses_alert_before_delay']); 'after' => 'send_licenses_alert_before_delay']);
$migration->addField("glpi_entities", 'send_certificates_alert_before_delay', "integer", $migration->addField("glpi_entities", 'send_certificates_alert_before_delay', "integer",
['value' => -2, ['value' => -2,
'after' => 'use_certificates_alert', 'after' => 'use_certificates_alert',
skipping to change at line 1413 skipping to change at line 1548
CronTask::register( CronTask::register(
'Certificate', 'Certificate',
'certificate', 'certificate',
DAY_TIMESTAMP, DAY_TIMESTAMP,
[ [
'comment' => '', 'comment' => '',
'mode' => CronTask::MODE_INTERNAL 'mode' => CronTask::MODE_INTERNAL
] ]
); );
if (!countElementsInTable('glpi_notifications', ['itemtype' => 'Certificate'] )) { if (!countElementsInTable('glpi_notifications', ['itemtype' => 'Certificate'] )) {
$query = "INSERT INTO `glpi_notifications` $DB->insertOrDie("glpi_notifications", [
(`id`, `name`, `entities_id`, `itemtype`, `event`, `comment`, 'id' => null,
`is_recursive`, `is_active`, `date_creation`, `date_mod`) 'name' => "Certificates",
VALUES (null,'Certificates','0','Certificate','alert', 'entities_id' => "0",
'', '1', '1', NOW(), NOW());"; 'itemtype' => "Certificate",
$DB->queryOrDie($query, "9.2 Add certificate alerts notification"); 'event' => "alert",
'comment' => "",
'is_recursive' => "1",
'is_active' => "1",
'date_creation' => new \QueryExpression("NOW()"),
'date_mod' => new \QueryExpression("NOW()")
],
"9.2 Add certificate alerts notification"
);
$notid = $DB->insert_id(); $notid = $DB->insert_id();
$query = "INSERT INTO `glpi_notificationtemplates` (`name`, `itemtype`, `d $DB->insertOrDie("glpi_notificationtemplates", [
ate_mod`) 'name' => "Certificates alerts",
VALUES ('Certificates alerts', 'Certificate', NOW())"; 'itemtype' => "Certificate",
$DB->queryOrDie($query, "9.2 Add certifcate alerts notification template") 'date_mod' => new \QueryExpression("NOW()")
; ],
"9.2 Add certifcate alerts notification template"
);
$nottid = $DB->insert_id(); $nottid = $DB->insert_id();
$where = [ $where = [
'notifications_id' => $notid, 'notifications_id' => $notid,
'mode' => Notification_NotificationTemplate::MODE_M AIL, 'mode' => Notification_NotificationTemplate::MODE_M AIL,
'notificationtemplates_id' => $nottid 'notificationtemplates_id' => $nottid
]; ];
if (!countElementsInTable('glpi_notifications_notificationtemplates', $whe re)) { if (!countElementsInTable('glpi_notifications_notificationtemplates', $whe re)) {
$query = "REPLACE INTO `glpi_notifications_notificationtemplates` $DB->updateOrInsert("glpi_notifications_notificationtemplates", [
VALUES (null, $notid, '".Notification_NotificationTemplate::M 'id' => null
ODE_MAIL."', $nottid);"; ], [
$DB->queryOrDie($query, "9.2 Add certificates alerts notification templ 'notifications_id' => $notid,
ates"); 'mode' => Notification_NotificationTemplate::
MODE_MAIL,
'notificationtemplates_id' => $nottid,
]
);
} }
$query = "INSERT INTO `glpi_notificationtemplatetranslations` $query = "INSERT INTO `glpi_notificationtemplatetranslations`
(`notificationtemplates_id`, `language`, `subject`, `content_t ext`, `content_html`) (`notificationtemplates_id`, `language`, `subject`, `content_t ext`, `content_html`)
VALUES ($notid, '', '##certificate.action## ##certificate.entit y##', VALUES ($notid, '', '##certificate.action## ##certificate.entit y##',
'##lang.certificate.entity## : ##certificate.entity## '##lang.certificate.entity## : ##certificate.entity##
##FOREACHcertificates## ##FOREACHcertificates##
##lang.certificate.serial## : ##certificate.serial## ##lang.certificate.serial## : ##certificate.serial##
skipping to change at line 1544 skipping to change at line 1696
`date_creation` datetime DEFAULT NULL, `date_creation` datetime DEFAULT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `name` (`name`), KEY `name` (`name`),
KEY `date_mod` (`date_mod`), KEY `date_mod` (`date_mod`),
KEY `date_creation` (`date_creation`) KEY `date_creation` (`date_creation`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
$DB->queryOrDie($query, "9.2 add table glpi_devicesimcardtypes"); $DB->queryOrDie($query, "9.2 add table glpi_devicesimcardtypes");
} }
if (!countElementsInTable('glpi_devicesimcardtypes', ['name' => 'Full SIM'])) { if (!countElementsInTable('glpi_devicesimcardtypes', ['name' => 'Full SIM'])) {
$DB->queryOrDie("INSERT INTO `glpi_devicesimcardtypes` VALUES (NULL,'Full $DB->insertOrDie("glpi_devicesimcardtypes", [
SIM',NULL,NULL,NULL)"); 'id' => null,
'name' => "Full SIM",
'comment' => null,
'date_mod' => null,
'date_creation' => null
]);
} }
if (!countElementsInTable('glpi_devicesimcardtypes', ['name' => 'Mini SIM'])) { if (!countElementsInTable('glpi_devicesimcardtypes', ['name' => 'Mini SIM'])) {
$DB->queryOrDie("INSERT INTO `glpi_devicesimcardtypes` VALUES (NULL,'Mini $DB->insertOrDie("glpi_devicesimcardtypes", [
SIM',NULL,NULL,NULL)"); 'id' => null,
'name' => "Mini SIM",
'comment' => null,
'date_mod' => null,
'date_creation' => null
]);
} }
if (!countElementsInTable('glpi_devicesimcardtypes', ['name' => 'Micro SIM']) ) { if (!countElementsInTable('glpi_devicesimcardtypes', ['name' => 'Micro SIM']) ) {
$DB->queryOrDie("INSERT INTO `glpi_devicesimcardtypes` VALUES (NULL,'Micro $DB->insertOrDie("glpi_devicesimcardtypes", [
SIM',NULL,NULL,NULL)"); 'id' => null,
'name' => "Micro SIM",
'comment' => null,
'date_mod' => null,
'date_creation' => null
]);
} }
if (!countElementsInTable('glpi_devicesimcardtypes', ['name' => 'Nano SIM'])) { if (!countElementsInTable('glpi_devicesimcardtypes', ['name' => 'Nano SIM'])) {
$DB->queryOrDie("INSERT INTO `glpi_devicesimcardtypes` VALUES (NULL,'Nano $DB->insertOrDie("glpi_devicesimcardtypes", [
SIM',NULL,NULL,NULL)"); 'id' => null,
'name' => "Nano SIM",
'comment' => null,
'date_mod' => null,
'date_creation' => null
]);
} }
if (!$DB->tableExists('glpi_devicesimcards')) { if (!$DB->tableExists('glpi_devicesimcards')) {
$query = "CREATE TABLE IF NOT EXISTS `glpi_devicesimcards` ( $query = "CREATE TABLE IF NOT EXISTS `glpi_devicesimcards` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`designation` varchar(255) DEFAULT NULL, `designation` varchar(255) DEFAULT NULL,
`comment` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL, `comment` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL,
`entities_id` int(11) NOT NULL DEFAULT '0', `entities_id` int(11) NOT NULL DEFAULT '0',
`is_recursive` tinyint(1) NOT NULL DEFAULT '0', `is_recursive` tinyint(1) NOT NULL DEFAULT '0',
`manufacturers_id` int(11) NOT NULL DEFAULT '0', `manufacturers_id` int(11) NOT NULL DEFAULT '0',
skipping to change at line 1623 skipping to change at line 1799
if (countElementsInTable("glpi_profilerights", ['name' => 'line']) == 0) { if (countElementsInTable("glpi_profilerights", ['name' => 'line']) == 0) {
//new right for line //new right for line
//give full rights to profiles having config right //give full rights to profiles having config right
foreach ($DB->request("glpi_profilerights", "`name` = 'config'") as $profr ights) { foreach ($DB->request("glpi_profilerights", "`name` = 'config'") as $profr ights) {
if ($profrights['rights'] && (READ + UPDATE)) { if ($profrights['rights'] && (READ + UPDATE)) {
$rightValue = CREATE | READ | UPDATE | DELETE | PURGE | READNOTE | U PDATENOTE; $rightValue = CREATE | READ | UPDATE | DELETE | PURGE | READNOTE | U PDATENOTE;
} else { } else {
$rightValue = 0; $rightValue = 0;
} }
$query = "INSERT INTO `glpi_profilerights` $DB->insertOrDie("glpi_profilerights", [
(`id`, `profiles_id`, `name`, `rights`) 'id' => null,
VALUES (NULL, '".$profrights['profiles_id']."', 'line', 'profiles_id' => $profrights['profiles_id'],
'".$rightValue."')"; 'name' => "line",
$DB->queryOrDie($query, "9.1 add right for line"); 'rights' => $rightValue
],
"9.2 add right for line"
);
} }
} }
if (countElementsInTable("glpi_profilerights", ['name' => 'lineoperator']) == 0) { if (countElementsInTable("glpi_profilerights", ['name' => 'lineoperator']) == 0) {
//new right for lineoperator //new right for lineoperator
//give full rights to profiles having config right //give full rights to profiles having config right
foreach ($DB->request("glpi_profilerights", "`name` = 'config'") as $profr ights) { foreach ($DB->request("glpi_profilerights", "`name` = 'config'") as $profr ights) {
if ($profrights['rights'] && (READ + UPDATE)) { if ($profrights['rights'] && (READ + UPDATE)) {
$rightValue = CREATE | READ | UPDATE | DELETE | PURGE; $rightValue = CREATE | READ | UPDATE | DELETE | PURGE;
} else { } else {
$rightValue = 0; $rightValue = 0;
} }
$query = "INSERT INTO `glpi_profilerights` $DB->insertOrDie("glpi_profilerights", [
(`id`, `profiles_id`, `name`, `rights`) 'id' => null,
VALUES (NULL, '".$profrights['profiles_id']."', 'lineoperator 'profiles_id' => $profrights['profiles_id'],
', 'name' => "lineoperator",
'".$rightValue."')"; 'rights' => $rightValue
$DB->queryOrDie($query, "9.1 add right for lineoperator"); ],
"9.2 add right for lineoperator"
);
} }
} }
if (countElementsInTable("glpi_profilerights", ['name' => 'devicesimcard_pinp uk']) == 0) { if (countElementsInTable("glpi_profilerights", ['name' => 'devicesimcard_pinp uk']) == 0) {
//new right for simcard pin and puk //new right for simcard pin and puk
//give full rights to profiles having config right //give full rights to profiles having config right
foreach ($DB->request("glpi_profilerights", "`name` = 'config'") as $profr ights) { foreach ($DB->request("glpi_profilerights", "`name` = 'config'") as $profr ights) {
if ($profrights['rights'] && (READ + UPDATE)) { if ($profrights['rights'] && (READ + UPDATE)) {
$rightValue = READ | UPDATE; $rightValue = READ | UPDATE;
} else { } else {
$rightValue = 0; $rightValue = 0;
} }
$query = "INSERT INTO `glpi_profilerights` $DB->insertOrDie("glpi_profilerights", [
(`id`, `profiles_id`, `name`, `rights`) 'id' => null,
VALUES (NULL, '".$profrights['profiles_id']."', 'devicesimcar 'profiles_id' => $profrights['profiles_id'],
d_pinpuk', 'name' => "devicesimcard_pinpuk",
'".$rightValue."')"; 'rights' => $rightValue
$DB->queryOrDie($query, "9.1 add right for simcards pin and puk codes") ],
; "9.2 add right for simcards pin and puk codes"
);
} }
} }
//Firmware for phones //Firmware for phones
if ($DB->fieldExists('glpi_phones', 'firmware')) { if ($DB->fieldExists('glpi_phones', 'firmware')) {
$iterator = $DB->request([ $iterator = $DB->request([
'SELECT' => ['id', 'firmware'], 'SELECT' => ['id', 'firmware'],
'FROM' => 'glpi_phones', 'FROM' => 'glpi_phones',
'NOT' => ['firmware' => null] 'NOT' => ['firmware' => null]
]); ]);
skipping to change at line 1992 skipping to change at line 2177
//add timeline_position in ticketfollowups //add timeline_position in ticketfollowups
//add timeline_position in tickettasks //add timeline_position in tickettasks
//add timeline_position in documents_items //add timeline_position in documents_items
//add timeline_position in ticketvalidations //add timeline_position in ticketvalidations
$timeline_tables = ['glpi_ticketfollowups', 'glpi_tickettasks', 'glpi_documen ts_items', 'glpi_ticketvalidations']; $timeline_tables = ['glpi_ticketfollowups', 'glpi_tickettasks', 'glpi_documen ts_items', 'glpi_ticketvalidations'];
foreach ($timeline_tables as $tl_table) { foreach ($timeline_tables as $tl_table) {
//add timeline_position in $tl_table //add timeline_position in $tl_table
if (!$DB->fieldExists($tl_table, 'timeline_position')) { if (!$DB->fieldExists($tl_table, 'timeline_position')) {
$migration->addField($tl_table, "timeline_position", "tinyint(1) NOT NU LL DEFAULT '0'"); $migration->addField($tl_table, "timeline_position", "tinyint(1) NOT NU LL DEFAULT '0'");
$where = "`$tl_table`.`tickets_id` "; $where = [
if (!$DB->fieldExists( $tl_table, 'tickets_id')) { "$tl_table.tickets_id" => new \QueryExpression(
$where = "`$tl_table`.itemtype = 'Ticket' AND `$tl_table`.`items_id` DBmysql::quoteName("glpi_tickets_users.tickets_id")
"; ),
"$tl_table.users_id" => new \QueryExpression(
DBmysql::quoteName("glpi_tickets_users.users_id")
),
];
if (!$DB->fieldExists($tl_table, 'tickets_id')) {
$where = [
"$tl_table.itemtype" => "Ticket",
"$tl_table.items_id" => new \QueryExpression(
DBmysql::quoteName("glpi_tickets_users.tickets_id")
),
"$tl_table.users_id" => new \QueryExpression(
DBmysql::quoteName("glpi_tickets_users.users_id")
),
];
} }
$migration->addPostQuery("UPDATE `$tl_table`,
`glpi_tickets_users` $update = new \QueryExpression(
SET `$tl_table`.`timeline_position` = IF(`glp DBmysql::quoteName($tl_table) . ", " . DBmysql::quoteName("glpi_tick
i_tickets_users`.`type` NOT IN (1,3) AND `glpi_tickets_users`.`type` IN (2), 4, ets_users")
1) );
WHERE $where = `glpi_tickets_users`.`tickets_ $migration->addPostQuery(
id` $DB->buildUpdate($update, [
AND `$tl_table`.`users_id` = `glpi_tickets "$tl_table.timeline_position" => new \QueryExpression("IF(" .
_users`.`users_id`"); DBmysql::quoteName("glpi_tickets_users.type") . " NOT IN (1
$migration->addPostQuery("UPDATE `$tl_table`, ,3) AND " .
`glpi_groups_tickets`, DBmysql::quoteName("glpi_tickets_users.type") . " IN (2), 4
`glpi_groups_users` , 1)"
SET `$tl_table`.`timeline_position` = IF(`glp )
i_groups_tickets`.`type` NOT IN (1,3) AND `glpi_groups_tickets`.`type` IN (2), 4 ],
, 1) $where
WHERE $where = `glpi_groups_tickets`.`tickets )
_id` );
AND `glpi_groups_users`.`groups_id` = `glp
i_groups_tickets`.`groups_id` $where = [
AND `$tl_table`.`users_id` = `glpi_groups_ "$tl_table.tickets_id" => new \QueryExpression(
users`.`users_id`"); DBmysql::quoteName("glpi_groups_tickets.tickets_id")
$migration->addPostQuery("UPDATE `$tl_table` ),
SET `$tl_table`.`timeline_position` = 1 "glpi_groups_users.groups_id" => new \QueryExpression(
WHERE `$tl_table`.`timeline_position` = 0"); DBmysql::quoteName("glpi_groups_tickets.groups_id")
),
"$tl_table.users_id" => new \QueryExpression(
DBmysql::quoteName("glpi_groups_users.users_id")
),
];
if (!$DB->fieldExists($tl_table, 'tickets_id')) {
$where = [
"$tl_table.itemtype" => "Ticket",
"$tl_table.items_id" => new \QueryExpression(
DBmysql::quoteName("glpi_groups_tickets.tickets_id")
),
"glpi_groups_users.groups_id" => new \QueryExpression(
DBmysql::quoteName("glpi_groups_tickets.groups_id")
),
"$tl_table.users_id" => new \QueryExpression(
DBmysql::quoteName("glpi_groups_users.users_id")
),
];
}
$update = new \QueryExpression(
DBmysql::quoteName($tl_table) . ", " . DBmysql::quoteName("glpi_grou
ps_tickets") .
", " . DBmysql::quoteName("glpi_groups_users")
);
$migration->addPostQuery(
$DB->buildUpdate($update, [
"$tl_table.timeline_position" => new \QueryExpression("IF(" .
DBmysql::quoteName("glpi_groups_tickets.type") . " NOT IN (
1,3) AND " .
DBmysql::quoteName("glpi_groups_tickets.type") . " IN (2),
4, 1)"
)
],
$where
)
);
$migration->addPostQuery(
$DB->buildUpdate($tl_table,
["$tl_table.timeline_position" => "1"],
["$tl_table.timeline_position" => "0"]
)
);
} }
} }
// ************ Keep it at the end ************** // ************ Keep it at the end **************
$migration->executeMigration(); $migration->executeMigration();
return $updateresult; return $updateresult;
} }
 End of changes. 37 change blocks. 
209 lines changed or deleted 427 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)