"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "install/update_0905_91.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_0905_91.php  (glpi-9.3.3.tgz):update_0905_91.php  (glpi-9.4.0.tgz)
skipping to change at line 175 skipping to change at line 175
($ro_p_id, 'ticketcost', '1'), ($ro_p_id, 'ticketcost', '1'),
($ro_p_id, 'ticketrecurrent', '1'), ($ro_p_id, 'ticketrecurrent', '1'),
($ro_p_id, 'tickettemplate', '1'), ($ro_p_id, 'tickettemplate', '1'),
($ro_p_id, 'ticketvalidation', '0'), ($ro_p_id, 'ticketvalidation', '0'),
($ro_p_id, 'transfer', '1'), ($ro_p_id, 'transfer', '1'),
($ro_p_id, 'typedoc', '1'), ($ro_p_id, 'typedoc', '1'),
($ro_p_id, 'user', '2177')"); ($ro_p_id, 'user', '2177')");
// updates rights for Super-Admin profile // updates rights for Super-Admin profile
foreach ($CFG_GLPI['lock_lockable_objects'] as $itemtype) { foreach ($CFG_GLPI['lock_lockable_objects'] as $itemtype) {
$rightnames[] = "'".$itemtype::$rightname."'"; $rightnames[] = $itemtype::$rightname;
} }
$query = "UPDATE `glpi_profilerights`
SET `rights` = `rights` | ".UNLOCK." $DB->updateOrDie("glpi_profilerights", [
WHERE `profiles_id` = '4' 'rights' => new \QueryExpression(
AND `name` IN (".implode( ",", $rightnames ).")"; DBmysql::quoteName("rights") . " | " . DBmysql::quoteValue(UNLOCK
$DB->queryOrDie($query, "update super-admin profile with UNLOCK right"); )
)
], [
'profiles_id' => 4,
'name' => $rightnames
],
"update super-admin profile with UNLOCK right"
);
Config::setConfigurationValues('core', ['lock_use_lock_item' = > 0, Config::setConfigurationValues('core', ['lock_use_lock_item' = > 0,
'lock_autolock_mode' => 1, 'lock_autolock_mode' => 1,
'lock_directunlock_notificati on' => 0, 'lock_directunlock_notificati on' => 0,
'lock_item_list' => '[]', 'lock_item_list' => '[]',
'lock_lockprofile_id' => $ro_p_id]); 'lock_lockprofile_id' => $ro_p_id]);
} }
// cron task // cron task
if (!countElementsInTable('glpi_crontasks', if (!countElementsInTable('glpi_crontasks',
['itemtype' => 'ObjectLock', 'name' => 'unlockobjec t'])) { ['itemtype' => 'ObjectLock', 'name' => 'unlockobjec t'])) {
$query = "INSERT INTO `glpi_crontasks` $DB->insertOrDie("glpi_crontasks", [
(`itemtype`, `name`, `frequency`, `param`, `state`, `mode 'itemtype' => "ObjectLock",
`, `allowmode`, 'name' => "unlockobject",
`hourmin`, `hourmax`, `logs_lifetime`, `lastrun`, `lastc 'frequency' => 86400,
ode`, `comment`) 'param' => 4,
VALUES ('ObjectLock', 'unlockobject', 86400, 4, 0, 1, 3, 'state' => 0,
0, 24, 30, NULL, NULL, NULL); "; 'mode' => 1,
$DB->queryOrDie($query, "9.1 Add UnlockObject cron task"); 'allowmode' => 3,
'hourmin' => 0,
'hourmax' => 24,
'logs_lifetime' => 30,
'lastrun' => null,
'lastcode' => null,
'comment' => null
],
"9.1 Add UnlockObject cron task"
);
} }
// notification template // notification template
$query = "SELECT * $notificationtemplatesIterator = $DB->request([
FROM `glpi_notificationtemplates` 'FROM' => "glpi_notificationtemplates",
WHERE `itemtype` = 'ObjectLock'"; 'WHERE' => ['itemtype' => "ObjectLock"]
]);
if ($result = $DB->query($query)) {
if ($DB->numrows($result) == 0) { if (count($notificationtemplatesIterator) == 0) {
$query = "INSERT INTO `glpi_notificationtemplates` $DB->insertOrDie("glpi_notificationtemplates", [
(`name`, `itemtype`, `date_mod`) 'name' => "Unlock Item request",
VALUES ('Unlock Item request', 'ObjectLock', NOW())"; 'itemtype' => "ObjectLock",
$DB->queryOrDie($query, "9.1 Add unlock request notification template") 'date_mod' => new \QueryExpression("NOW()")
; ],
$notid = $DB->insert_id(); "9.1 Add unlock request notification template"
);
$query = "INSERT INTO `glpi_notificationtemplatetranslations` $notid = $DB->insert_id();
(`notificationtemplates_id`, `language`,
`subject`, $contentText =
`content_text`, '##objectlock.type## ###objectlock.id## - ##objectlock.name##
`content_html`)
VALUES ($notid, '', '##objectlock.action##', ##lang.objectlock.url##
'##objectlock.type## ###objectlock.id## - ##objectlock.name## ##objectlock.url##
##lang.objectlock.url## ##lang.objectlock.date_mod##
##objectlock.url## ##objectlock.date_mod##
##lang.objectlock.date_mod## Hello ##objectlock.lockedby.firstname##,
##objectlock.date_mod## Could go to this item and unlock it for me?
Thank you,
Hello ##objectlock.lockedby.firstname##, Regards,
Could go to this item and unlock it for me? ##objectlock.requester.firstname##';
Thank you,
Regards, $contentHtml =
##objectlock.requester.firstname##', '<table>
'<table> <tbody>
<tbody> <tr><th colspan=\"2\"><a href=\"##objectlock.url##\">
<tr><th colspan=\"2\"><a href=\"##objectlock.url##\">##o ##objectlock.type## ###objectlock.id## - ##objectlock.name##</a></th&gt
bjectlock.type## ###objectlock.id## - ##objectlock.name##</a></th>&l ;</tr>
t;/tr> <tr>
<tr> <td>##lang.objectlock.url##</td>
<td>##lang.objectlock.url##</td> <td>##objectlock.url##</td>
<td>##objectlock.url##</td> </tr>
</tr> <tr>
<tr> <td>##lang.objectlock.date_mod##</td>
<td>##lang.objectlock.date_mod##</td> <td>##objectlock.date_mod##</td>
<td>##objectlock.date_mod##</td> </tr>
</tr> </tbody>
</tbody> </table>
</table> <p><span style=\"font-size: small;\">Hello ##objectlock.loc
<p><span style=\"font-size: small;\">Hello ##objectlock.locked kedby.firstname##,<br />Could go to this item and unlock it for me?<br
by.firstname##,<br />Could go to this item and unlock it for me?<br /&g />Thank you,<br />Regards,<br />##objectlock.requester.firstname#
t;Thank you,<br />Regards,<br />##objectlock.requester.firstname## # # ##objectlock.requester.lastname##</span></p>';
#objectlock.requester.lastname##</span></p>')";
$DB->insertOrDie("glpi_notificationtemplatetranslations", [
$DB->queryOrDie($query, "9.1 add Unlock Request notification translatio 'notificationtemplates_id' => $notid,
n"); 'language' => "",
'subject' => "##objectlock.action##",
$query = "INSERT INTO `glpi_notifications` 'content_text' => $contentText,
(`name`, `entities_id`, `itemtype`, `event`, `mo 'content_html' => $contentHtml
de`, ],
`notificationtemplates_id`, `comment`, `is_recu "9.1 add Unlock Request notification translation"
rsive`, `is_active`, );
`date_mod`)
VALUES ('Request Unlock Items', 0, 'ObjectLock', 'unloc $DB->insertOrDie("glpi_notifications", [
k', 'mail', 'name' => "Request Unlock Item",
$notid, '', 1, 1, NOW())"; 'entities_id' => 0,
$DB->queryOrDie($query, "9.1 add Unlock Request notification"); 'itemtype' => "ObjectLock",
$notifid = $DB->insert_id(); 'event' => "unlock",
'mode' => "mail",
$query = "INSERT INTO `glpi_notificationtargets` 'notificationtemplates_id' => $notid,
(`id`, `notifications_id`, `type`, `items_id`) 'comment' => "",
VALUES (NULL, $notifid, ".Notification::USER_TYPE.", ". 'is_recursive' => 1,
Notification::USER.");"; 'is_active' => 1,
$DB->queryOrDie($query, "9.1 add Unlock Request notification target"); 'date_mod' => new \QueryExpression("NOW()")
} ],
"9.1 add Unlock Request notification"
);
$notifid = $DB->insert_id();
$DB->insertOrDie("glpi_notificationtargets", [
'id' => null,
'notifications_id' => $notifid,
'type' => Notification::USER_TYPE,
'items_id' => Notification::USER_TYPE
],
"9.1 add Unlock Request notification target"
);
} }
$migration->addField("glpi_users", "lock_autolock_mode", "tinyint(1) NULL DEF AULT NULL"); $migration->addField("glpi_users", "lock_autolock_mode", "tinyint(1) NULL DEF AULT NULL");
$migration->addField("glpi_users", "lock_directunlock_notification", "tinyint (1) NULL DEFAULT NULL"); $migration->addField("glpi_users", "lock_directunlock_notification", "tinyint (1) NULL DEFAULT NULL");
/************** Default Requester *************/ /************** Default Requester *************/
Config::setConfigurationValues('core', ['set_default_requester' => 1]); Config::setConfigurationValues('core', ['set_default_requester' => 1]);
$migration->addField("glpi_users", "set_default_requester", "tinyint(1) NULL DEFAULT NULL"); $migration->addField("glpi_users", "set_default_requester", "tinyint(1) NULL DEFAULT NULL");
// ************ Networkport ethernets ************** // ************ Networkport ethernets **************
if (!$DB->tableExists("glpi_networkportfiberchannels")) { if (!$DB->tableExists("glpi_networkportfiberchannels")) {
$query = "CREATE TABLE `glpi_networkportfiberchannels` ( $query = "CREATE TABLE `glpi_networkportfiberchannels` (
skipping to change at line 359 skipping to change at line 395
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, "add table glpi_budgettypes"); $DB->queryOrDie($query, "add table glpi_budgettypes");
} }
$new = $migration->addField("glpi_budgets", "budgettypes_id", "integer"); $new = $migration->addField("glpi_budgets", "budgettypes_id", "integer");
$migration->addKey("glpi_budgets", "budgettypes_id"); $migration->addKey("glpi_budgets", "budgettypes_id");
if ($new) { if ($new) {
$query = "UPDATE `glpi_displaypreferences` $DB->updateOrDie("glpi_displaypreferences", [
SET `num`='6' WHERE `itemtype`='Budget' AND `num`='4'"; 'num' => 6
$DB->queryOrDie($query, "change budget display preference"); ], [
'itemtype' => "Budget",
'num' => 4,
],
"change budget display preference"
);
} }
/************** New Planning with fullcalendar.io *************/ /************** New Planning with fullcalendar.io *************/
$migration->addField("glpi_users", "plannings", "text"); $migration->addField("glpi_users", "plannings", "text");
/************** API Rest *************/ /************** API Rest *************/
Config::setConfigurationValues('core', ['enable_api' => 0]); Config::setConfigurationValues('core', ['enable_api' => 0]);
Config::setConfigurationValues('core', ['enable_api_login_credentials' => 0]); Config::setConfigurationValues('core', ['enable_api_login_credentials' => 0]);
Config::setConfigurationValues('core', ['enable_api_login_external_token' => 1]); Config::setConfigurationValues('core', ['enable_api_login_external_token' => 1]);
Config::setConfigurationValues('core', ['url_base_api' => trim($current_confi g['url_base'], "/")."/apirest.php/"]); Config::setConfigurationValues('core', ['url_base_api' => trim($current_confi g['url_base'], "/")."/apirest.php/"]);
skipping to change at line 393 skipping to change at line 434
`app_token` VARCHAR( 255 ) NULL, `app_token` VARCHAR( 255 ) NULL,
`app_token_date` DATETIME DEFAULT NULL, `app_token_date` DATETIME DEFAULT NULL,
`dolog_method` TINYINT NOT NULL DEFAULT '0', `dolog_method` TINYINT NOT NULL DEFAULT '0',
`comment` TEXT NULL , `comment` TEXT NULL ,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `date_mod` (`date_mod`), KEY `date_mod` (`date_mod`),
KEY `is_active` (`is_active`) KEY `is_active` (`is_active`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
$DB->queryOrDie($query, "9.1 add table glpi_apiclients"); $DB->queryOrDie($query, "9.1 add table glpi_apiclients");
$query = "INSERT INTO `glpi_apiclients` $DB->insertOrDie("glpi_apiclients", [
VALUES (1, 0, 1, 'full access from localhost', NOW(), 1, INET_AT 'id' => 1,
ON('127.0.0.1'), 'entities_id' => 0,
INET_ATON('127.0.0.1'), '::1', '', NULL, 0, NULL);"; 'is_recursive' => 1,
$DB->queryOrDie($query, "9.1 insert first line into table glpi_apiclients" 'name' => "full access from localhost",
); 'date_mod' => new \QueryExpression("NOW()"),
'is_active' => 1,
'ipv4_range_start' => new \QueryExpression("INET_ATON('127.0.0.1')
"),
'ipv4_range_end' => new \QueryExpression("INET_ATON('127.0.0.1')
"),
'ipv6' => "::1",
'app_token' => "",
'app_token_date' => null,
'dolog_method' => 0,
'comment' => null
],
"9.1 insert first line into table glpi_apiclients"
);
} }
/************** Date mod/creation for itemtypes *************/ /************** Date mod/creation for itemtypes *************/
$migration->displayMessage(sprintf(__('date_mod and date_creation'))); $migration->displayMessage(sprintf(__('date_mod and date_creation')));
$types = ['AuthLDAP', 'Blacklist', 'BlacklistedMailContent', 'Budget', 'Cale ndar', $types = ['AuthLDAP', 'Blacklist', 'BlacklistedMailContent', 'Budget', 'Cale ndar',
'CartridgeItemType', 'Change', 'ChangeTask', 'ComputerDisk', 'CartridgeItemType', 'Change', 'ChangeTask', 'ComputerDisk',
'ComputerVirtualMachine', 'ConsumableItemType', 'Contact', 'Co ntactType', 'ComputerVirtualMachine', 'ConsumableItemType', 'Contact', 'Co ntactType',
'Contract', 'ContractType', 'Crontask', 'DeviceCaseType', 'Dev iceMemoryType', 'Contract', 'ContractType', 'Crontask', 'DeviceCaseType', 'Dev iceMemoryType',
'Document', 'DocumentCategory', 'DocumentType', 'Domain', 'En tity', 'FQDN', 'Document', 'DocumentCategory', 'DocumentType', 'Domain', 'En tity', 'FQDN',
'Fieldblacklist', 'FieldUnicity', 'Filesystem', 'Group', 'Holi day', 'Infocom', 'Fieldblacklist', 'FieldUnicity', 'Filesystem', 'Group', 'Holi day', 'Infocom',
skipping to change at line 481 skipping to change at line 535
$columns = []; $columns = [];
switch ($table) { switch ($table) {
case 'glpi_tickettemplatepredefinedfields' : case 'glpi_tickettemplatepredefinedfields' :
$columns = ['num', 'value', 'tickettemplates_id']; $columns = ['num', 'value', 'tickettemplates_id'];
break; break;
default : default :
$columns = ['num', 'tickettemplates_id']; $columns = ['num', 'tickettemplates_id'];
break; break;
} }
$query = "SELECT `".implode('`,`', $columns)."`
FROM `$table` $iterator = $DB->request([
WHERE `num` = '$item_num' 'SELECT' => $columns,
OR `num` = '$itemtype_num';"; 'FROM' => $table,
'WHERE' => [
'OR' => [
'num' => $item_num,
'num' => $itemtype_num
]
]
]);
$items_to_update = []; $items_to_update = [];
if ($result = $DB->query($query)) { if (count($iterator)) {
if ($DB->numrows($result) > 0) { while ($data = $iterator->next()) {
while ($data = $DB->fetch_assoc($result)) { if ($data['num'] == $itemtype_num) {
if ($data['num'] == $itemtype_num) { $items_to_update[$data['tickettemplates_id']]['itemtype']
$items_to_update[$data['tickettemplates_id']]['itemtype'] = isset($data['value']) ? $data['value'] : 0;
= isset($data['value']) ? $data['value'] : 0; } else if ($data['num'] == $item_num) {
} else if ($data['num'] == $item_num) { $items_to_update[$data['tickettemplates_id']]['items_id']
$items_to_update[$data['tickettemplates_id']]['items_id'] = isset($data['value']) ? $data['value'] : 0;
= isset($data['value']) ? $data['value'] : 0;
}
} }
} }
} }
switch ($table) { switch ($table) {
case 'glpi_tickettemplatepredefinedfields' : // Update predefined items case 'glpi_tickettemplatepredefinedfields' : // Update predefined items
foreach ($items_to_update as $templates_id => $type) { foreach ($items_to_update as $templates_id => $type) {
if (isset($type['itemtype'])) { if (isset($type['itemtype'])) {
if (isset($type['items_id'])) { if (isset($type['items_id'])) {
$DB->queryOrDie("UPDATE `$table` $DB->updateOrDie($table, [
SET `value` = '".$type['itemtype']."_".$ty 'value' => $type['itemtype'] . "_" . $type['items_id'
pe['items_id']."' ]
WHERE `num` = '".$item_num."' ], [
AND `tickettemplates_id` = '".$templates_i 'num' => $item_num,
d."'", 'tickettemplates_id' => $templates_id,
"Associated items migration : update predef ],
ined items"); "Associated items migration : update predefined items"
);
$DB->queryOrDie("DELETE FROM `$table`
WHERE `num` = '".$itemtype_num."' $DB->deleteOrDie($table, [
AND `tickettemplates_id` = '".$templ 'num' => $itemtype_num,
ates_id."'", 'tickettemplates_id' => $templates_id,
"Associated items migration : delete $table ],
itemtypes"); "Associated items migration : delete $table itemtypes"
);
} }
} }
} }
break; break;
default: // Update mandatory and hidden items default: // Update mandatory and hidden items
foreach ($items_to_update as $templates_id => $type) { foreach ($items_to_update as $templates_id => $type) {
if (isset($type['itemtype'])) { if (isset($type['itemtype'])) {
if (isset($type['items_id'])) { if (isset($type['items_id'])) {
$DB->queryOrDie("DELETE FROM `$table` $DB->deleteOrDie($table, [
WHERE `num` = '".$item_num."' 'num' => $item_num,
AND `tickettemplates_id` = '".$templ 'tickettemplates_id' => $templates_id,
ates_id."'", ],
"Associated items migration : delete $table "Associated items migration : delete $table itemtypes"
itemtypes"); );
} }
$DB->queryOrDie("UPDATE `$table` $DB->updateOrDie($table, [
SET `num` = '".$item_num."' 'num' => $item_num
WHERE `num` = '".$itemtype_num."' ], [
AND `tickettemplates_id` = '".$template 'num' => $itemtype_num,
s_id."'", 'tickettemplates_id' => $templates_id,
"Associated items migration : delete $table ite ],
mtypes"); "Associated items migration : update $table itemtypes"
);
} }
} }
break; break;
} }
} }
/************** Add more fields to software licenses */ /************** Add more fields to software licenses */
$migration->addField("glpi_softwarelicenses", "is_deleted", "bool"); $migration->addField("glpi_softwarelicenses", "is_deleted", "bool");
$migration->addField("glpi_softwarelicenses", "locations_id", "integer"); $migration->addField("glpi_softwarelicenses", "locations_id", "integer");
$migration->addField("glpi_softwarelicenses", "users_id_tech", "integer"); $migration->addField("glpi_softwarelicenses", "users_id_tech", "integer");
skipping to change at line 614 skipping to change at line 683
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 AU TO_INCREMENT=1;"; ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AU TO_INCREMENT=1;";
$DB->queryOrDie($query, "Add antivirus table"); $DB->queryOrDie($query, "Add antivirus table");
} }
if (countElementsInTable("glpi_profilerights", ['name' => 'license']) == 0) { if (countElementsInTable("glpi_profilerights", ['name' => 'license']) == 0) {
//new right for software license //new right for software license
//copy the software right value to the new license right //copy the software right value to the new license right
foreach ($DB->request("glpi_profilerights", "`name` = 'software'") as $pro frights) { foreach ($DB->request("glpi_profilerights", "`name` = 'software'") as $pro frights) {
$query = "INSERT INTO `glpi_profilerights` $DB->insertOrDie("glpi_profilerights", [
(`id`, `profiles_id`, `name`, `rights`) 'id' => null,
VALUES (NULL, '".$profrights['profiles_id']."', 'license', 'profiles_id' => $profrights['profiles_id'],
'".$profrights['rights']."')"; 'name' => "license",
$DB->queryOrDie($query, "9.1 add right for softwarelicense"); 'rights' => $profrights['rights'],
],
"9.1 add right for softwarelicense"
);
} }
} }
//new right for survey //new right for survey
foreach ($DB->request("glpi_profilerights", "`name` = 'ticket'") as $profrigh ts) { foreach ($DB->request("glpi_profilerights", "`name` = 'ticket'") as $profrigh ts) {
$query = "UPDATE `glpi_profilerights` $DB->updateOrDie("glpi_profilerights", [
SET `rights` = `rights` | " . Ticket::SURVEY ." 'rights' => new \QueryExpression(
WHERE `profiles_id` = '".$profrights['profiles_id']."' DBmysql::quoteName("rights") . " | " . DBmysql::quoteValue(Ticket
AND `name` = 'ticket'"; ::SURVEY)
$DB->queryOrDie($query, "9.1 update ticket with survey right"); )
], [
'profiles_id' => $profrights['profiles_id'],
'name' => "ticket"
],
"9.1 update ticket with survey right"
);
} }
//new field //new field
$migration->addField('glpi_authldaps', 'location_field', 'string', ['after' = > 'email4_field']); $migration->addField('glpi_authldaps', 'location_field', 'string', ['after' = > 'email4_field']);
//TRANS: %s is the table or item to migrate //TRANS: %s is the table or item to migrate
$migration->displayMessage(sprintf(__('Data migration - %s'), 'glpi_displaypr eferences')); $migration->displayMessage(sprintf(__('Data migration - %s'), 'glpi_displaypr eferences'));
$ADDTODISPLAYPREF['SoftwareLicense'] = [3, 10, 162, 5]; $ADDTODISPLAYPREF['SoftwareLicense'] = [3, 10, 162, 5];
foreach ($ADDTODISPLAYPREF as $type => $tab) { foreach ($ADDTODISPLAYPREF as $type => $tab) {
$query = "SELECT DISTINCT `users_id` $displaypreferencesIterator = $DB->request([
FROM `glpi_displaypreferences` 'SELECT DISTINCT' => "users_id",
WHERE `itemtype` = '$type'"; 'FROM' => "glpi_displaypreferences",
'WHERE' => ['itemtype' => $type]
if ($result = $DB->query($query)) { ]);
if ($DB->numrows($result)>0) {
while ($data = $DB->fetch_assoc($result)) { if (count($displaypreferencesIterator)) {
$query = "SELECT MAX(`rank`) while ($data = $displaypreferencesIterator->next()) {
FROM `glpi_displaypreferences` $rank = $DB->request([
WHERE `users_id` = '".$data['users_id']."' 'SELECT DISTINCT' => ['MAX' => "rank AS max_rank"],
AND `itemtype` = '$type'"; 'FROM' => "glpi_displaypreferences",
$result = $DB->query($query); 'WHERE' => [
$rank = $DB->result($result, 0, 0); 'users_id' => $data['users_id'],
$rank++; 'itemtype' => $type
]
foreach ($tab as $newval) { ])->next();
$query = "SELECT * $rank = $rank ? $rank['max_rank']++ : 1;
FROM `glpi_displaypreferences`
WHERE `users_id` = '".$data['users_id']."'
AND `num` = '$newval'
AND `itemtype` = '$type'";
if ($result2 = $DB->query($query)) {
if ($DB->numrows($result2) == 0) {
$query = "INSERT INTO `glpi_displaypreferences`
(`itemtype` ,`num` ,`rank` ,`users_id`)
VALUES ('$type', '$newval', '".$rank++."',
'".$data['users_id']."')";
$DB->query($query);
}
}
}
}
} else { // Add for default user
$rank = 1;
foreach ($tab as $newval) { foreach ($tab as $newval) {
$query = "INSERT INTO `glpi_displaypreferences` $iterator = $DB->request([
(`itemtype` ,`num` ,`rank` ,`users_id`) 'FROM' => "glpi_displaypreferences",
VALUES ('$type', '$newval', '".$rank++."', '0')"; 'WHERE' => [
$DB->query($query); 'users_id' => $data['users_id'],
'num' => $newval,
'itemtype' => $type
],
]);
if (count($iterator) == 0) {
$DB->insert("glpi_displaypreferences", [
'itemtype' => $type,
'num' => $newval,
'rank' => $rank++,
'users_id' => $data['users_id'],
]);
}
} }
} }
} else { // Add for default user
$rank = 1;
foreach ($tab as $newval) {
$DB->insert("glpi_displaypreferences", [
'itemtype' => $type,
'num' => $newval,
'rank' => $rank++,
'users_id' => 0,
]);
}
} }
} }
/** ************ New SLA structure ************ */ /** ************ New SLA structure ************ */
if (!$DB->tableExists('glpi_slts')) { if (!$DB->tableExists('glpi_slts')) {
$query = "CREATE TABLE `glpi_slts` ( $query = "CREATE TABLE `glpi_slts` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT 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',
skipping to change at line 710 skipping to change at line 793
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `name` (`name`), KEY `name` (`name`),
KEY `calendars_id` (`calendars_id`), KEY `calendars_id` (`calendars_id`),
KEY `date_mod` (`date_mod`), KEY `date_mod` (`date_mod`),
KEY `date_creation` (`date_creation`), KEY `date_creation` (`date_creation`),
KEY `slas_id` (`slas_id`) KEY `slas_id` (`slas_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
$DB->queryOrDie($query, "9.1 add table glpi_slts"); $DB->queryOrDie($query, "9.1 add table glpi_slts");
// Sla migration // Sla migration
$query = "SELECT * $slasIterator = $DB->request("glpi_slas");
FROM `glpi_slas`"; if (count($slasIterator)) {
if ($result = $DB->query($query)) { while ($data = $slasIterator->next()) {
if ($DB->numrows($result) > 0) { $DB->insertOrDie("glpi_slts", [
while ($data = $DB->fetch_assoc($result)) { 'id' => $data['id'],
$query = "INSERT INTO `glpi_slts` 'name' => Toolbox::addslashes_deep($data['name']
(`id`, `name`,`entities_id`, `is_recursive`, `ty ),
pe`, `comment`, 'entities_id' => $data['entities_id'],
`number_time`, `date_mod`, `definition_time`, 'is_recursive' => $data['is_recursive'],
`end_of_working_day`, `date_creation`, `slas_id 'type' => SLM::TTR,
`) 'comment' => addslashes($data['comment']),
VALUES ('".$data['id']."', '".Toolbox::addslashes_deep( 'number_time' => $data['resolution_time'],
$data['name'])."', 'date_mod' => $data['date_mod'],
'".$data['entities_id']."', 'definition_time' => $data['definition_time'],
'".$data['is_recursive']."', '".SLM::TTR."', 'end_of_working_day' => $data['end_of_working_day'],
'".addslashes($data['comment'])."', '".$data['r 'date_creation' => date('Y-m-d H:i:s'),
esolution_time']."', 'slas_id' => $data['id']
'".$data['date_mod']."', ],
'".$data['definition_time']."', '".$data['end_o "SLA migration to SLT"
f_working_day']."', );
'".date('Y-m-d H:i:s')."', '".$data['id']."');"
;
$DB->queryOrDie($query, "SLA migration to SLT");
}
} }
} }
// Delete deprecated fields of SLA // Delete deprecated fields of SLA
// save table before delete fields // save table before delete fields
$migration->copyTable('glpi_slas', 'backup_glpi_slas'); $migration->copyTable('glpi_slas', 'backup_glpi_slas');
foreach (['number_time', 'definition_time', foreach (['number_time', 'definition_time',
'end_of_working_day'] as $field) { 'end_of_working_day'] as $field) {
$migration->dropField('glpi_slas', $field); $migration->dropField('glpi_slas', $field);
skipping to change at line 779 skipping to change at line 863
$migration->migrationOneTable('glpi_tickets'); $migration->migrationOneTable('glpi_tickets');
$migration->dropKey('glpi_tickets', 'slalevels_id'); $migration->dropKey('glpi_tickets', 'slalevels_id');
$migration->addKey('glpi_tickets', 'ttr_slalevels_id'); $migration->addKey('glpi_tickets', 'ttr_slalevels_id');
} }
// Unique key for slalevel_ticket // Unique key for slalevel_ticket
$migration->addKey('glpi_slalevels_tickets', ['tickets_id', 'slalevels_id'], $migration->addKey('glpi_slalevels_tickets', ['tickets_id', 'slalevels_id'],
'unicity', 'UNIQUE'); 'unicity', 'UNIQUE');
// Sla rules criterias migration // Sla rules criterias migration
$DB->queryOrDie("UPDATE `glpi_rulecriterias` $DB->updateOrDie("glpi_rulecriterias",
SET `criteria` = 'slts_ttr_id' ['criteria' => "slts_ttr_id" ],
WHERE `criteria` = 'slas_id'", ['criteria' => "slas_id"],
"SLA rulecriterias migration"); "SLA rulecriterias migration"
);
// Sla rules actions migration // Sla rules actions migration
$DB->queryOrDie("UPDATE `glpi_ruleactions` $DB->updateOrDie("glpi_ruleactions",
SET `field` = 'slts_ttr_id' ['field' => "slts_ttr_id" ],
WHERE `field` = 'slas_id'", ['field' => "slas_id"],
"SLA ruleactions migration"); "SLA ruleactions migration"
);
// to delete in next version - fix change in update // to delete in next version - fix change in update
if (!$DB->fieldExists('glpi_slas', 'calendars_id')) { if (!$DB->fieldExists('glpi_slas', 'calendars_id')) {
$migration->addField("glpi_slas", "calendars_id", "integer", ['after' => ' is_recursive']); $migration->addField("glpi_slas", "calendars_id", "integer", ['after' => ' is_recursive']);
$migration->addKey('glpi_slas', 'calendars_id'); $migration->addKey('glpi_slas', 'calendars_id');
} }
if ($DB->fieldExists('glpi_slts', 'resolution_time') if ($DB->fieldExists('glpi_slts', 'resolution_time')
&& !$DB->fieldExists('glpi_slts', 'number_time')) { && !$DB->fieldExists('glpi_slts', 'number_time')) {
$migration->changeField('glpi_slts', 'resolution_time', 'number_time', 'in teger'); $migration->changeField('glpi_slts', 'resolution_time', 'number_time', 'in teger');
} }
skipping to change at line 844 skipping to change at line 930
$migration->addField("glpi_requesttypes", "is_ticketheader", "bool", ['value' => 1]); $migration->addField("glpi_requesttypes", "is_ticketheader", "bool", ['value' => 1]);
$migration->addKey("glpi_requesttypes", "is_ticketheader"); $migration->addKey("glpi_requesttypes", "is_ticketheader");
$migration->addField("glpi_requesttypes", "is_ticketfollowup", "bool", ['valu e' => 1]); $migration->addField("glpi_requesttypes", "is_ticketfollowup", "bool", ['valu e' => 1]);
$migration->addKey("glpi_requesttypes", "is_ticketfollowup"); $migration->addKey("glpi_requesttypes", "is_ticketfollowup");
$migration->addField("glpi_requesttypes", "is_followup_default", "bool", ['va lue' => 0]); $migration->addField("glpi_requesttypes", "is_followup_default", "bool", ['va lue' => 0]);
$migration->addKey("glpi_requesttypes", "is_followup_default"); $migration->addKey("glpi_requesttypes", "is_followup_default");
$migration->addField("glpi_requesttypes", "is_mailfollowup_default", "bool", ['value' => 0]); $migration->addField("glpi_requesttypes", "is_mailfollowup_default", "bool", ['value' => 0]);
$migration->addKey("glpi_requesttypes", "is_mailfollowup_default"); $migration->addKey("glpi_requesttypes", "is_mailfollowup_default");
/************** Fix autoclose_delay for root_entity in glpi_entities (from -1 to 0) **************/ /************** Fix autoclose_delay for root_entity in glpi_entities (from -1 to 0) **************/
$query = "UPDATE `glpi_entities` $DB->updateOrDie("glpi_entities", [
SET `autoclose_delay` = 0 'autoclose_delay' => 0
WHERE `autoclose_delay` = '-1' ], [
AND `id` = 0"; 'autoclose_delay' => -1,
$DB->queryOrDie($query, "glpi_entities root_entity change autoclose_delay val 'id' => 0
ue from -1 to 0"); ],
"glpi_entities root_entity change autoclose_delay value from -1 to 0"
);
// ************ Keep it at the end ************** // ************ Keep it at the end **************
$migration->executeMigration(); $migration->executeMigration();
return $updateresult; return $updateresult;
} }
 End of changes. 22 change blocks. 
224 lines changed or deleted 293 lines changed or added

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