function plugin_manufacturersimports_install() { global $DB; include_once GLPI_ROOT . "/plugins/manufacturersimports/inc/profile.class.php"; include_once GLPI_ROOT . "/plugins/manufacturersimports/inc/config.class.php"; $migration = new Migration("1.7.0"); $update = false; //Root of SQL files for DB installation or upgrade $sql_root = GLPI_ROOT . "/plugins/manufacturersimports/sql/"; if (!TableExists("glpi_plugin_manufacturersimports_configs")) { $DB->runFile($sql_root . "/empty-1.7.0.sql"); } else { if (TableExists("glpi_plugin_suppliertag_config") && !FieldExists("glpi_plugin_suppliertag_config", "FK_entities")) { $update = true; $DB->runFile($sql_root . "/update-1.1.sql"); $DB->runFile($sql_root . "/update-1.2.0.sql"); $DB->runFile($sql_root . "/update-1.3.0.sql"); $DB->runFile($sql_root . "/update-1.4.1.sql"); $DB->runFile($sql_root . "/update-1.5.0.sql"); $DB->runFile($sql_root . "/update-1.7.0.sql"); } else { if (TableExists("glpi_plugin_suppliertag_profiles") && FieldExists("glpi_plugin_suppliertag_profiles", "interface")) { $update = true; $DB->runFile($sql_root . "/update-1.2.0.sql"); $DB->runFile($sql_root . "/update-1.3.0.sql"); $DB->runFile($sql_root . "/update-1.4.1.sql"); $DB->runFile($sql_root . "/update-1.5.0.sql"); $DB->runFile($sql_root . "/update-1.7.0.sql"); } else { if (!TableExists("glpi_plugin_manufacturersimports_profiles") && !FieldExists("glpi_plugin_manufacturersimports_configs", "supplier_key")) { $update = true; $DB->runFile($sql_root . "/update-1.3.0.sql"); $DB->runFile($sql_root . "/update-1.4.1.sql"); $DB->runFile($sql_root . "/update-1.5.0.sql"); $DB->runFile($sql_root . "/update-1.7.0.sql"); } else { if (!FieldExists("glpi_plugin_manufacturersimports_configs", "supplier_key")) { $DB->runFile($sql_root . "/update-1.7.0.sql"); } } } } } $query = "UPDATE `glpi_plugin_manufacturersimports_configs` \n SET `Supplier_url` = 'http://www.dell.com/support/troubleshooting/us/en/04/Index?c=us&l=en&s=bsd&cs=04&t=system&ServiceTag=' \n WHERE `name` ='" . PluginManufacturersimportsConfig::DELL . "'"; $DB->query($query); if ($update) { foreach ($DB->request('glpi_plugin_manufacturersimports_profiles') as $data) { $query = "UPDATE `glpi_plugin_manufacturersimports_profiles`\n SET `profiles_id` = '" . $data["id"] . "'\n WHERE `id` = '" . $data["id"] . "';"; $DB->query($query); } $migration->dropField('glpi_plugin_manufacturersimports_profiles', 'name'); Plugin::migrateItemType(array(2150 => 'PluginManufacturersimportsModel', 2151 => 'PluginManufacturersimportsConfig'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_tickets"), array("glpi_plugin_manufacturersimports_models", "glpi_plugin_manufacturersimports_logs")); } //Migrate profiles to the system introduced in 0.85 PluginManufacturersimportsProfile::initProfile(); PluginManufacturersimportsProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']); //Drop old profile table : not used anymore $migration->dropTable('glpi_plugin_manufacturersimports_profiles'); return true; }
public static function install(Migration $migration) { global $DB; $table = getTableForItemType(__CLASS__); if (!TableExists($table)) { $query = "CREATE TABLE IF NOT EXISTS `{$table}` (\n `id` int(11) NOT NULL auto_increment,\n `entities_id` int(11) NOT NULL DEFAULT '0',\n `is_recursive` tinyint(1) NOT NULL DEFAULT '1',\n `name` varchar(255) NOT NULL DEFAULT '',\n `comment` text collate utf8_unicode_ci,\n `color` varchar(50) NOT NULL DEFAULT '' COLLATE 'utf8_unicode_ci',\n PRIMARY KEY (`id`),\n KEY `name` (`name`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); } if (!FieldExists($table, 'type_menu')) { $migration->addField($table, 'type_menu', "varchar(50) NOT NULL DEFAULT ''"); $migration->addKey($table, 'type_menu'); $migration->migrationOneTable($table); } // Version 0.90-1.1 $result = $DB->query("SHOW FIELDS FROM `{$table}` where Field ='type_menu'"); if ($result && $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { if (stristr($data["Type"], 'varchar') !== FALSE) { $DB->query("ALTER TABLE `{$table}` DROP INDEX `type_menu`;"); $DB->query("ALTER TABLE `{$table}` MODIFY `type_menu` text COLLATE utf8_unicode_ci;"); $datas = getAllDatasFromTable($table, "`type_menu` IS NOT NULL"); if (!empty($datas)) { foreach ($datas as $data) { $itemtypes = PluginTagTagItem::getItemtypes($data['type_menu']); $DB->query("UPDATE `{$table}` SET `type_menu` = '" . json_encode($itemtypes) . "' WHERE `id` = '" . $data['id'] . "'"); } } break; } } } return true; }
function plugin_moreticket_install() { global $DB; include_once GLPI_ROOT . "/plugins/moreticket/inc/profile.class.php"; if (!TableExists("glpi_plugin_moreticket_configs")) { // table sql creation $DB->runFile(GLPI_ROOT . "/plugins/moreticket/sql/empty-1.2.0.sql"); } PluginMoreticketProfile::initProfile(); PluginMoreticketProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']); $migration = new Migration("1.1.0"); $migration->dropTable('glpi_plugin_moreticket_profiles'); if (!FieldExists("glpi_plugin_moreticket_configs", "solution_status")) { $DB->runFile(GLPI_ROOT . "/plugins/moreticket/sql/update-1.1.1.sql"); } if (FieldExists("glpi_plugin_moreticket_waitingtypes", "is_helpdeskvisible")) { $DB->runFile(GLPI_ROOT . "/plugins/moreticket/sql/update-1.1.2.sql"); } if (!FieldExists("glpi_plugin_moreticket_closetickets", "documents_id")) { $DB->runFile(GLPI_ROOT . "/plugins/moreticket/sql/update-1.1.3.sql"); } if (!FieldExists("glpi_plugin_moreticket_configs", "date_report_mandatory")) { $DB->runFile(GLPI_ROOT . "/plugins/moreticket/sql/update-1.2.0.sql"); } return true; }
function plugin_immobilizationsheets_install() { global $DB; include_once GLPI_ROOT . "/plugins/immobilizationsheets/inc/profile.class.php"; $update = false; if (!TableExists("glpi_plugin_immo_profiles") && !TableExists("glpi_plugin_immobilizationsheets_profiles")) { $DB->runFile(GLPI_ROOT . "/plugins/immobilizationsheets/sql/empty-1.3.0.sql"); } else { if (TableExists("glpi_plugin_immo_profiles") && FieldExists("glpi_plugin_immo_profiles", "interface")) { $update = true; $DB->runFile(GLPI_ROOT . "/plugins/immobilizationsheets/sql/update-1.2.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/immobilizationsheets/sql/update-1.3.0.sql"); } else { if (!TableExists("glpi_plugin_immobilizationsheets_profiles")) { $update = true; $DB->runFile(GLPI_ROOT . "/plugins/immobilizationsheets/sql/update-1.3.0.sql"); } } } if ($update) { //Do One time on 0.78 $query_ = "SELECT *\n FROM `glpi_plugin_immobilizationsheets_profiles` "; $result_ = $DB->query($query_); if ($DB->numrows($result_) > 0) { while ($data = $DB->fetch_array($result_)) { $query = "UPDATE `glpi_plugin_immobilizationsheets_profiles`\n SET `profiles_id` = '" . $data["id"] . "'\n WHERE `id` = '" . $data["id"] . "';"; $result = $DB->query($query); } } $query = "ALTER TABLE `glpi_plugin_immobilizationsheets_profiles`\n DROP `name` ;"; $result = $DB->query($query); } PluginImmobilizationsheetsProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']); return true; }
function plugin_racks_install() { global $DB; include_once GLPI_ROOT . "/plugins/racks/inc/profile.class.php"; $migration = new Migration("1.5.0"); $update = false; if (!TableExists("glpi_plugin_rack_profiles") && !TableExists("glpi_plugin_racks_profiles")) { $DB->runFile(GLPI_ROOT . "/plugins/racks/sql/empty-1.4.2.sql"); } elseif (TableExists("glpi_plugin_rack_content") && !FieldExists("glpi_plugin_rack_content", "first_powersupply")) { $update = true; $DB->runFile(GLPI_ROOT . "/plugins/racks/sql/update-1.0.2.sql"); $DB->runFile(GLPI_ROOT . "/plugins/racks/sql/update-1.1.0.sql"); } elseif (!TableExists("glpi_plugin_racks_profiles")) { $update = true; $DB->runFile(GLPI_ROOT . "/plugins/racks/sql/update-1.1.0.sql"); } //from 1.1 version if (TableExists("glpi_plugin_racks_racks") && !FieldExists("glpi_plugin_racks_racks", "otherserial")) { $DB->runFile(GLPI_ROOT . "/plugins/racks/sql/update-1.2.1.sql"); } if (TableExists("glpi_plugin_racks_racks") && !FieldExists("glpi_plugin_racks_racks", "users_id_tech")) { $DB->runFile(GLPI_ROOT . "/plugins/racks/sql/update-1.3.0.sql"); } if (!TableExists("glpi_plugin_racks_racktypes")) { $DB->runFile(GLPI_ROOT . "/plugins/racks/sql/update-1.3.2.sql"); } if (TableExists("glpi_plugin_racks_racktypes") && !FieldExists("glpi_plugin_racks_racktypes", "is_recursive")) { $DB->runFile(GLPI_ROOT . "/plugins/racks/sql/update-1.4.1.sql"); } if (TableExists("glpi_plugin_racks_profiles") && !FieldExists("glpi_plugin_racks_profiles", "open_ticket")) { $DB->runFile(GLPI_ROOT . "/plugins/racks/sql/update-1.4.2.sql"); } if ($update) { foreach ($DB->request('glpi_plugin_racks_profiles') as $data) { $query = "UPDATE `glpi_plugin_racks_profiles`\n SET `profiles_id` = '" . $data["id"] . "'\n WHERE `id` = '" . $data["id"] . "';"; $result = $DB->query($query); } $migration->dropField('glpi_plugin_racks_profiles', 'name'); Plugin::migrateItemType(array(4450 => 'PluginRacksRack', 4451 => 'PluginRacksOther'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_tickets"), array("glpi_plugin_racks_racks_items", "glpi_plugin_racks_itemspecifications")); } $notepad_tables = array('glpi_plugin_racks_racks'); foreach ($notepad_tables as $t) { // Migrate data if (FieldExists($t, 'notepad')) { $query = "SELECT id, notepad\n FROM `{$t}`\n WHERE notepad IS NOT NULL\n AND notepad <>'';"; foreach ($DB->request($query) as $data) { $iq = "INSERT INTO `glpi_notepads`\n (`itemtype`, `items_id`, `content`, `date`, `date_mod`)\n VALUES ('" . getItemTypeForTable($t) . "', '" . $data['id'] . "',\n '" . addslashes($data['notepad']) . "', NOW(), NOW())"; $DB->queryOrDie($iq, "0.85 migrate notepad data"); } $query = "ALTER TABLE `glpi_plugin_racks_racks` DROP COLUMN `notepad`;"; $DB->query($query); } } //Migrate profiles to the system introduced in 0.85 PluginRacksProfile::initProfile(); PluginRacksProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']); //Drop old profile table : not used anymore $migration->dropTable('glpi_plugin_racks_profiles'); return true; }
function plugin_ticketmail_install() { global $DB; $migration = new Migration(100); //Fresh install if (!TableExists('glpi_plugin_ticketmail_profiles')) { $query = "CREATE TABLE `glpi_plugin_ticketmail_profiles` (\n\t\t\t\t\t`id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_profiles (id)',\n\t\t\t\t\t`show_ticketmail_onglet` char(1) collate utf8_unicode_ci default NULL,\n\t\t\t\t\tPRIMARY KEY (`id`)\n\t\t\t\t ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $DB->queryOrDie($query, $DB->error()); $migration->executeMigration(); include_once GLPI_ROOT . "/plugins/ticketmail/inc/profile.class.php"; PluginTicketmailProfile::createAdminAccess($_SESSION['glpiactiveprofile']['id']); } else { // Since v0.84 remove "profiles_id" column and use "id" if (FieldExists('glpi_plugin_ticketmail_profiles', 'profiles_id')) { $drop_column_query = "ALTER TABLE glpi_plugin_ticketmail_profiles DROP COLUMN `id`;"; $rename_column_query = "ALTER TABLE glpi_plugin_ticketmail_profiles\n\t\t\t\t\t\t\t\t\tCHANGE profiles_id id int(11) NOT NULL default '0'\n\t\t\t\t\t\t\t\t\tCOMMENT 'RELATION to glpi_profiles (id)';"; $DB->queryOrDie($drop_column_query, $DB->error()); $DB->queryOrDie($rename_column_query, $DB->error()); $add_primarykey_query = "ALTER TABLE glpi_plugin_ticketmail_profiles\n\t\t\t\t\t\t\t\t\t ADD PRIMARY KEY (id);"; $drop_old_index_query = "ALTER TABLE glpi_plugin_ticketmail_profiles\n\t\t\t\t\t\t\t\t\t DROP INDEX profiles_id;"; $DB->queryOrDie($add_primarykey_query, $DB->error()); $DB->queryOrDie($drop_old_index_query, $DB->error()); } } return true; }
function update0712to0713() { global $DB, $CFG_GLPI; if (!FieldExists("glpi_rule_cache_software", "ignore_ocs_import", false)) { $query = "ALTER TABLE `glpi_rule_cache_software`\n ADD `ignore_ocs_import` VARCHAR( 255 ) NULL "; $DB->queryOrDie($query, "0.71.3 add ignore_ocs_import field in dictionnary cache"); } // Update to longtext for fields which may be very long if (FieldExists("glpi_kbitems", "answer", false)) { if (isIndex("glpi_kbitems", "fulltext")) { // to avoid pb in altering column answer $query = "ALTER TABLE `glpi_kbitems`\n DROP INDEX `fulltext`"; $DB->queryOrDie($query, "0.71.3 alter kbitem drop index Fulltext"); } // field question : only to change latin1 to utf-8 if not done in update 0.68.3 to 0.71 // before creating index fulltext based on 2 fields (perhaps both are not in same encoding) $query = "ALTER TABLE `glpi_kbitems`\n CHANGE `question` `question` TEXT,\n CHANGE `answer` `answer` LONGTEXT NULL DEFAULT NULL "; $DB->queryOrDie($query, "0.71.3 alter kbitem answer field to longtext"); $query = "ALTER TABLE `glpi_kbitems`\n ADD FULLTEXT `fulltext` (`question`,`answer`)"; $DB->queryOrDie($query, "0.71.3 alter kbitem re-add index Fulltext"); } if (FieldExists("glpi_tracking", "contents", false)) { $query = "ALTER TABLE `glpi_tracking`\n CHANGE `contents` `contents` LONGTEXT NULL DEFAULT NULL "; $DB->queryOrDie($query, "0.71.3 alter tracking contents field to longtext"); } }
function plugin_environment_install() { global $DB; include_once GLPI_ROOT . "/plugins/environment/inc/profile.class.php"; $update = false; if (TableExists("glpi_plugin_environment_profiles") && FieldExists("glpi_plugin_environment_profiles", "interface")) { $update = true; $DB->runFile(GLPI_ROOT . "/plugins/environment/sql/update-1.3.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/environment/sql/update-1.4.0.sql"); } else { if (TableExists("glpi_plugin_environment_profiles") && FieldExists("glpi_plugin_environment_profiles", "connections")) { $update = true; $DB->runFile(GLPI_ROOT . "/plugins/environment/sql/update-1.4.0.sql"); } } if ($update) { //Do One time on 0.78 $query_ = "SELECT *\n FROM `glpi_plugin_environment_profiles` "; $result_ = $DB->query($query_); if ($DB->numrows($result_) > 0) { while ($data = $DB->fetch_array($result_)) { $query = "UPDATE `glpi_plugin_environment_profiles`\n SET `profiles_id` = '" . $data["id"] . "'\n WHERE `id` = '" . $data["id"] . "';"; $result = $DB->query($query); } } $query = "ALTER TABLE `glpi_plugin_environment_profiles`\n DROP `name` ;"; $result = $DB->query($query); } PluginEnvironmentProfile::initProfile(); PluginEnvironmentProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']); $migration = new Migration("1.8.0"); $migration->dropTable('glpi_plugin_environment_profiles'); $_SESSION["glpi_plugin_environment_installed"] = 1; return true; }
function pluginMonitoringGetCurrentVersion($version) { global $DB; if (!TableExists("glpi_plugin_monitoring_configs")) { return '0'; } else { if (!FieldExists("glpi_plugin_monitoring_configs", "timezones")) { // Version before 0.80+1.0 (test version) return "1.0.0"; } else { if (!FieldExists("glpi_plugin_monitoring_configs", "version")) { return "0.80+1.0"; } else { if (FieldExists("glpi_plugin_monitoring_configs", "version")) { $query = "SELECT `version`\n FROM `glpi_plugin_monitoring_configs`\n WHERE `id` = '1'"; $result = $DB->query($query); if ($DB->numrows($result) > 0) { $data = $DB->fetch_assoc($result); if ($data['version'] != $version) { return $data['version']; } } else { return "0.80+1.0"; } } else { return $version; } } } } return $version; }
static function install(Migration $migration) { global $DB; $obj = new self(); $table = $obj->getTable(); if (!TableExists($table)) { $migration->displayMessage("Installing {$table}"); $query = "CREATE TABLE IF NOT EXISTS `{$table}` (\n `id` INT(11) NOT NULL auto_increment,\n `name` VARCHAR(255) DEFAULT NULL,\n `label` VARCHAR(255) DEFAULT NULL,\n `type` VARCHAR(25) DEFAULT NULL,\n `plugin_fields_containers_id` INT(11) NOT NULL DEFAULT '0',\n `ranking` INT(11) NOT NULL DEFAULT '0',\n `default_value` VARCHAR(255) DEFAULT NULL,\n `is_active` TINYINT(1) NOT NULL DEFAULT '1',\n `is_readonly` TINYINT(1) NOT NULL DEFAULT '1',\n `mandatory` TINYINT(1) NOT NULL DEFAULT '0',\n PRIMARY KEY (`id`),\n KEY `plugin_fields_containers_id` (`plugin_fields_containers_id`),\n KEY `is_active` (`is_active`),\n KEY `is_readonly` (`is_readonly`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $DB->query($query) or die($DB->error()); } $migration->displayMessage("Updating {$table}"); if (!FieldExists($table, 'is_active')) { $migration->addField($table, 'is_active', 'bool', array('value' => 1)); $migration->addKey($table, 'is_active', 'is_active'); } if (!FieldExists($table, 'is_readonly')) { $migration->addField($table, 'is_readonly', 'bool', array('default' => false)); $migration->addKey($table, 'is_readonly', 'is_readonly'); } if (!FieldExists($table, 'mandatory')) { $migration->addField($table, 'mandatory', 'bool', array('value' => 0)); } $migration->executeMigration(); return true; }
static function initSession() { global $DB; if (TableExists("glpi_plugin_fusioninventory_config")) { if (FieldExists("glpi_plugin_fusioninventory_config", "ID")) { $profile = new PluginFusioninventoryProfile(); $query = "SELECT DISTINCT `glpi_profiles`.*\n FROM `glpi_users_profiles` INNER JOIN `glpi_profiles`\n ON (`glpi_users_profiles`.`FK_profiles` = `glpi_profiles`.`ID`)\n WHERE `glpi_users_profiles`.`FK_users`='" . $_SESSION["glpiID"] . "'"; $result = $DB->query($query); $_SESSION['glpi_plugin_fusioninventory_profile'] = array(); if ($DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $profile->fields = array(); if (isset($_SESSION["glpiactiveprofile"]["ID"])) { $profile->getFromDB($_SESSION["glpiactiveprofile"]["ID"]); $_SESSION['glpi_plugin_fusioninventory_profile'] = $profile->fields; } else { $profile->getFromDB($data['ID']); $_SESSION['glpi_plugin_fusioninventory_profile'] = $profile->fields; } $_SESSION["glpi_plugin_fusioninventory_installed"] = 1; } } } } }
/** * Summary of plugin_timezones_install * @return true or die! */ function plugin_timezones_install() { global $DB; if (!TableExists("glpi_plugin_timezones_users")) { $query = " CREATE TABLE `glpi_plugin_timezones_users` (\r\n\t `id` INT(11) NOT NULL AUTO_INCREMENT,\r\n\t `users_id` INT(11) NOT NULL,\r\n\t `timezone` VARCHAR(50) NOT NULL,\r\n\t PRIMARY KEY (`id`),\r\n\t UNIQUE INDEX `users_id` (`users_id`),\r\n\t INDEX `timezone` (`timezone`)\r\n )\r\n COLLATE='utf8_general_ci'\r\n ENGINE=InnoDB \r\n ;\r\n\t\t\t"; $DB->query($query) or die("error creating glpi_plugin_timezones_users" . $DB->error()); } else { if (!FieldExists("glpi_plugin_timezones_users", "users_id")) { $query = " ALTER TABLE `glpi_plugin_timezones_users`\r\n\t ADD COLUMN `id` INT(11) NOT NULL AUTO_INCREMENT FIRST,\r\n\t CHANGE COLUMN `id` `users_id` INT(11) NOT NULL AFTER `id`,\r\n\t DROP PRIMARY KEY,\r\n\t ADD PRIMARY KEY (`id`),\r\n\t ADD UNIQUE INDEX `users_id` (`users_id`);\r\n "; $DB->query($query) or die("error altering glpi_plugin_timezones_users" . $DB->error()); } } if (!TableExists("glpi_plugin_timezones_dbbackups")) { $query = " CREATE TABLE `glpi_plugin_timezones_dbbackups` (\r\n\t `date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\r\n\t `table_name` VARCHAR(255) NULL ,\r\n\t `alter_table` TEXT NULL\r\n )\r\n COLLATE='utf8_general_ci'\r\n ENGINE=InnoDB;\r\n\t\t\t"; $DB->query($query) or die("error creating glpi_plugin_timezones_dbbackups" . $DB->error()); } if (!TableExists("glpi_plugin_timezones_tasks_localtimes")) { $query = " CREATE TABLE `glpi_plugin_timezones_tasks_localtimes` (\r\n\t `id` INT(11) NOT NULL AUTO_INCREMENT,\r\n\t `items_type` VARCHAR(50) NOT NULL,\r\n\t `items_id` INT(11) NOT NULL,\r\n\t `begin` VARCHAR(20) NULL DEFAULT NULL COMMENT 'In order to keep local time',\r\n\t `end` VARCHAR(20) NULL DEFAULT NULL COMMENT 'In order to keep local time',\r\n\t PRIMARY KEY (`id`),\r\n\t UNIQUE INDEX `items_type_items_id` (`items_type`, `items_id`)\r\n )\r\n COLLATE='utf8_general_ci'\r\n ENGINE=InnoDB\r\n ;\r\n\t\t\t"; $DB->query($query) or die("error creating glpi_plugin_timezones_tasks_localtimes" . $DB->error()); } // here we update the time_zones mySQL tables. // with data from PHP module: php_timezonedb. See: https://pecl.php.net/package/timezonedb //$query = "TRUNCATE `mysql`.`time_zone`;"; //$DB->query( $query ) or die("error truncating mysql.time_zone" . $DB->error()); //$query = "TRUNCATE `mysql`.`time_zone_name`;"; //$DB->query( $query ) or die("error truncating mysql.time_zonetime_zone_name" . $DB->error()); //$query = "TRUNCATE `mysql`.`time_zone_transition`;"; //$DB->query( $query ) or die("error truncating mysql.time_zone_transition" . $DB->error()); //$query = "TRUNCATE `mysql`.`time_zone_transition_type`;"; //$DB->query( $query ) or die("error truncating mysql.time_zone_transition_type" . $DB->error()); //$query = "TRUNCATE `mysql`.`time_zone_leap_second`;"; //$DB->query( $query ) or die("error truncating mysql.time_zone_leap_second" . $DB->error()); // $timezones = DateTimeZone::listIdentifiers( ) ; // foreach( $timezones as $key => $tz ){ // $key++ ; // // time_zone // $query = "INSERT INTO `mysql`.`time_zone` (`Time_zone_id`, `Use_leap_seconds`) VALUES ($key, 'N');"; // $DB->query( $query ) or die("error inserting data into mysql.time_zone" . $DB->error()); // $query = "INSERT INTO `mysql`.`time_zone_name` (`Name`, `Time_zone_id`) VALUES ('$tz', $key);"; // $DB->query( $query ) or die("error inserting data into mysql.time_zone_name" . $DB->error()); // $tz_trans = (new DateTimeZone( $tz ))->getTransitions() ; // $trans_array = array( ) ; // $trans_type_id=0; // foreach($tz_trans as $key_trans => $trans) { // $trans_key = $trans['offset'].", ".($trans['isdst']?1:0).", '".$trans['abbr']."'"; // if( !in_array( $trans_key, $trans_array ) ){ // $trans_array[$trans_type_id++] = $trans_key ; // } // $query = "REPLACE INTO `mysql`.`time_zone_transition` (`Time_zone_id`, `Transition_time`, `Transition_type_id`) VALUES ($key, ".$trans['ts'].", ".$trans_type_id.");" ; // $DB->query( $query ) or die("error inserting data into mysql.time_zone_transition" . $DB->error()); // } // foreach( $trans_array as $trans_type_id => $trans_key ){ // $trans_type_id++; // $query = "INSERT INTO `mysql`.`time_zone_transition_type` (`Time_zone_id`, `Transition_type_id`, `Offset`, `Is_DST`, `Abbreviation`) VALUES ($key, $trans_type_id, $trans_key);"; // $DB->query( $query ) or die("error inserting data into mysql.time_zone_transition_type" . $DB->error()); // } // } return true; }
protected function setUp() { global $DB; $DB->connect(); // Store Max(id) for each glpi tables $result = $DB->list_tables(); while ($data=$DB->fetch_row($result)) { $query = "SELECT MAX(`id`) AS MAXID FROM `".$data[0]."`"; foreach ($DB->request($query) as $row) { $this->tables[$data[0]] = (empty($row['MAXID']) ? 0 : $row['MAXID']); } } $DB->free_result($result); $tab = array(); $auth = new Auth(); // First session $auth->Login('glpi', 'glpi') ; // Create entity tree $entity = new Entity(); $tab['entity'][0] = $entity->add(array('name' => 'PHP Unit root', 'entities_id' => 0)); if (!$tab['entity'][0] // Crash detection || !FieldExists('glpi_profiles','notification') // Schema detection || countElementsInTable('glpi_rules')!=6) { // Old rules if (!$tab['entity'][0]) { echo "Couldn't run test (previous run not cleaned)\n"; } else { echo "Schema need to be updated\n"; } echo "Loading a fresh empty database:"; $DB->runFile(GLPI_ROOT ."/install/mysql/glpi-0.84-empty.sql"); die(" done\nTry again\n"); } $tab['entity'][1] = $entity->add(array('name' => 'PHP Unit Child 1', 'entities_id' => $tab['entity'][0])); $tab['entity'][2] = $entity->add(array('name' => 'PHP Unit Child 2', 'entities_id' => $tab['entity'][0])); $tab['entity'][3] = $entity->add(array('name' => 'PHP Unit Child 2.1', 'entities_id' => $tab['entity'][2])); $tab['entity'][4] = $entity->add(array('name' => 'PHP Unit Child 2.2', 'entities_id' => $tab['entity'][2])); // New session with all the entities $auth->Login('glpi', 'glpi') or die("Login glpi/glpi invalid !\n"); // Shared this with all tests $this->sharedFixture = $tab; }
/** * Update from 0.78 to 0.78.1 * * @return bool for success (will die for most error) */ function update078to0781() { global $DB, $migration; $updateresult = true; $migration->displayTitle(sprintf(__('Update to %s'), '0.78.1')); $migration->setVersion('0.78.1'); //TRANS: %s is 'Clean reservation entity link' $migration->displayMessage(sprintf(__('Data migration - %s'), 'Clean reservation entity link')); // Updating schema $entities = getAllDatasFromTable('glpi_entities'); $entities[0] = "Root"; $query = "SELECT DISTINCT `itemtype` FROM `glpi_reservationitems`"; if ($result = $DB->query($query)) { if ($DB->numrows($result) > 0) { while ($data = $DB->fetch_assoc($result)) { $itemtable = getTableForItemType($data['itemtype']); // ajout d'un contrôle pour voir si la table existe ( cas migration plugin non fait) if (!TableExists($itemtable)) { $migration->displayWarning("*** Skip : no table {$itemtable} ***", true); continue; } $do_recursive = false; if (FieldExists($itemtable, 'is_recursive', false)) { $do_recursive = true; } foreach ($entities as $entID => $val) { if ($do_recursive) { // Non recursive ones $query3 = "UPDATE `glpi_reservationitems`\n SET `entities_id`={$entID}, `is_recursive`=0\n WHERE `itemtype`='" . $data['itemtype'] . "'\n AND `items_id` IN (SELECT `id` FROM `{$itemtable}`\n WHERE `entities_id`={$entID} AND `is_recursive`=0)"; $DB->queryOrDie($query3, "0.78.1 update entities_id and is_recursive=0 in glpi_reservationitems for " . $data['itemtype']); // Recursive ones $query3 = "UPDATE `glpi_reservationitems`\n SET `entities_id`={$entID}, `is_recursive`=1\n WHERE `itemtype`='" . $data['itemtype'] . "'\n AND `items_id` IN (SELECT `id` FROM `{$itemtable}`\n WHERE `entities_id`={$entID} AND `is_recursive`=1)"; $DB->queryOrDie($query3, "0.78.1 update entities_id and is_recursive=1 in glpi_reservationitems for " . $data['itemtype']); } else { $query3 = "UPDATE `glpi_reservationitems`\n SET `entities_id`={$entID}\n WHERE `itemtype`='" . $data['itemtype'] . "'\n AND `items_id` IN (SELECT `id` FROM `{$itemtable}`\n WHERE `entities_id`={$entID})"; $DB->queryOrDie($query3, "0.78.1 update entities_id in glpi_reservationitems for " . $data['itemtype']); } } } } } $query = "ALTER TABLE `glpi_tickets`\n CHANGE `global_validation` `global_validation` VARCHAR(255) DEFAULT 'none'"; $DB->query($query) or die("0.78.1 change ticket global_validation default state"); $query = "UPDATE `glpi_tickets`\n SET `global_validation`='none'\n WHERE `id` NOT IN (SELECT DISTINCT `tickets_id`\n FROM `glpi_ticketvalidations`)"; $DB->query($query) or die("0.78.1 update ticket global_validation state"); if (!FieldExists('glpi_knowbaseitemcategories', 'entities_id', false)) { $query = "ALTER TABLE `glpi_knowbaseitemcategories`\n ADD `entities_id` INT NOT NULL DEFAULT '0' AFTER `id`,\n ADD `is_recursive` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `entities_id`,\n ADD INDEX `entities_id` (`entities_id`),ADD INDEX `is_recursive` (`is_recursive`)"; $DB->queryOrDie($query, "0.78.1 add entities_id,is_recursive in glpi_knowbaseitemcategories"); // Set existing categories recursive global $query = "UPDATE `glpi_knowbaseitemcategories` SET `is_recursive` = '1'"; $DB->queryOrDie($query, "0.78.1 set value of is_recursive in glpi_knowbaseitemcategories"); $query = "ALTER TABLE `glpi_knowbaseitemcategories` DROP INDEX `unicity` ,\n ADD UNIQUE `unicity` ( `entities_id`, `knowbaseitemcategories_id` , `name` ) "; $DB->queryOrDie($query, "0.78.1 update unicity index on glpi_knowbaseitemcategories"); } // must always be at the end (only for end message) $migration->executeMigration(); return $updateresult; }
function plugin_addressing_install() { global $DB; include_once GLPI_ROOT . "/plugins/addressing/inc/profile.class.php"; $update = false; if (!TableExists("glpi_plugin_addressing_display") && !TableExists("glpi_plugin_addressing") && !TableExists("glpi_plugin_addressing_configs")) { $DB->runFile(GLPI_ROOT . "/plugins/addressing/sql/empty-2.0.0.sql"); } else { if (!TableExists("glpi_plugin_addressing_profiles") && TableExists("glpi_plugin_addressing_display") && !FieldExists("glpi_plugin_addressing_display", "ipconf1")) { //1.4 $update = true; $DB->runFile(GLPI_ROOT . "/plugins/addressing/sql/update-1.4.sql"); } if (!TableExists("glpi_plugin_addressing") && TableExists("glpi_plugin_addressing_display") && FieldExists("glpi_plugin_addressing_display", "ipconf1")) { $update = true; $DB->runFile(GLPI_ROOT . "/plugins/addressing/sql/update-1.5.sql"); } if (TableExists("glpi_plugin_addressing_display") && !FieldExists("glpi_plugin_addressing", "ipdeb")) { $update = true; $DB->runFile(GLPI_ROOT . "/plugins/addressing/sql/update-1.6.sql"); } if (TableExists("glpi_plugin_addressing_profiles") && FieldExists("glpi_plugin_addressing_profiles", "interface")) { $update = true; $DB->runFile(GLPI_ROOT . "/plugins/addressing/sql/update-1.7.0.sql"); } if (!TableExists("glpi_plugin_addressing_configs")) { $DB->runFile(GLPI_ROOT . "/plugins/addressing/sql/update-1.8.0.sql"); $update = true; } if (TableExists("glpi_plugin_addressing_profiles") && !FieldExists("glpi_plugin_addressing_profiles", "use_ping_in_equipment")) { $DB->runFile(GLPI_ROOT . "/plugins/addressing/sql/update-1.9.0.sql"); $update = true; } } if ($update) { $query_ = "SELECT *\n FROM `glpi_plugin_addressing_profiles` "; $result_ = $DB->query($query_); if ($DB->numrows($result_) > 0) { while ($data = $DB->fetch_array($result_)) { $query = "UPDATE `glpi_plugin_addressing_profiles`\n SET `profiles_id` = '" . $data["id"] . "'\n WHERE `id` = '" . $data["id"] . "'"; $result = $DB->query($query); } } if (FieldExists("glpi_plugin_addressing_profiles", "name")) { $query = "ALTER TABLE `glpi_plugin_addressing_profiles`\n DROP `name` "; $result = $DB->query($query); } Plugin::migrateItemType(array(5000 => 'PluginAddressingAddressing', 5001 => 'PluginAddressingReport'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_items_tickets")); } //0.85 : new profile system PluginAddressingProfile::migrateProfiles(); //Add all rights for current user profile PluginAddressingProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']); //Drop old profile table : not used anymore $migration = new Migration("2.2.0"); $migration->dropTable('glpi_plugin_addressing_profiles'); return true; }
function plugin_webapplications_install() { global $DB; include_once GLPI_ROOT . "/plugins/webapplications/inc/profile.class.php"; $update = false; if (!TableExists("glpi_application") && !TableExists("glpi_plugin_appweb") && !TableExists("glpi_plugin_webapplications_webapplications")) { $DB->runFile(GLPI_ROOT . "/plugins/webapplications/sql/empty-1.8.0.sql"); } else { if (TableExists("glpi_application") && !TableExists("glpi_plugin_appweb")) { $update = true; $DB->runFile(GLPI_ROOT . "/plugins/webapplications/sql/update-1.1.sql"); } //from 1.1 version if (TableExists("glpi_plugin_appweb") && !FieldExists("glpi_plugin_appweb", "location")) { $update = true; $DB->runFile(GLPI_ROOT . "/plugins/webapplications/sql/update-1.3.sql"); } //from 1.3 version if (TableExists("glpi_plugin_appweb") && !FieldExists("glpi_plugin_appweb", "recursive")) { $update = true; $DB->runFile(GLPI_ROOT . "/plugins/webapplications/sql/update-1.4.sql"); } if (TableExists("glpi_plugin_appweb_profiles") && FieldExists("glpi_plugin_appweb_profiles", "interface")) { $update = true; $DB->runFile(GLPI_ROOT . "/plugins/webapplications/sql/update-1.5.0.sql"); } if (TableExists("glpi_plugin_appweb") && !FieldExists("glpi_plugin_appweb", "helpdesk_visible")) { $update = true; $DB->runFile(GLPI_ROOT . "/plugins/webapplications/sql/update-1.5.1.sql"); } if (!TableExists("glpi_plugin_webapplications_webapplications")) { $update = true; $DB->runFile(GLPI_ROOT . "/plugins/webapplications/sql/update-1.6.0.sql"); } //from 1.6 version if (TableExists("glpi_plugin_webapplications_webapplications") && !FieldExists("glpi_plugin_webapplications_webapplications", "users_id_tech")) { $DB->runFile(GLPI_ROOT . "/plugins/webapplications/sql/update-1.8.0.sql"); } } if ($update) { $query_ = "SELECT *\n FROM `glpi_plugin_webapplications_profiles` "; $result_ = $DB->query($query_); if ($DB->numrows($result_) > 0) { while ($data = $DB->fetch_array($result_)) { $query = "UPDATE `glpi_plugin_webapplications_profiles`\n SET `profiles_id` = '" . $data["id"] . "'\n WHERE `id` = '" . $data["id"] . "';"; $result = $DB->query($query); } } $query = "ALTER TABLE `glpi_plugin_webapplications_profiles`\n DROP `name` ;"; $result = $DB->query($query); Plugin::migrateItemType(array(1300 => 'PluginWebapplicationsWebapplication'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_tickets"), array("glpi_plugin_webapplications_webapplications_items")); Plugin::migrateItemType(array(1200 => "PluginAppliancesAppliance"), array("glpi_plugin_webapplications_webapplications_items")); } PluginWebapplicationsProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']); return true; }
function plugin_datainjection_install() { global $DB; include_once GLPI_ROOT . "/plugins/datainjection/inc/profile.class.php"; $migration = new Migration('2.3.0'); switch (plugin_datainjection_needUpdateOrInstall()) { case -1: plugin_datainjection_update220_230(); plugin_datainjection_upgrade23_240($migration); return true; case 0: $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_datainjection_models` (\n `id` int(11) NOT NULL auto_increment,\n `name` varchar(255) NOT NULL,\n `comment` text NULL,\n `date_mod` datetime NOT NULL default '0000-00-00 00:00:00',\n `filetype` varchar(255) NOT NULL default 'csv',\n `itemtype` varchar(255) NOT NULL default '',\n `entities_id` int(11) NOT NULL default '0',\n `behavior_add` tinyint(1) NOT NULL default '1',\n `behavior_update` tinyint(1) NOT NULL default '0',\n `can_add_dropdown` tinyint(1) NOT NULL default '0',\n `can_overwrite_if_not_empty` int(1) NOT NULL default '1',\n `is_private` tinyint(1) NOT NULL default '1',\n `is_recursive` tinyint(1) NOT NULL default '0',\n `perform_network_connection` tinyint(1) NOT NULL default '0',\n `users_id` int(11) NOT NULL,\n `date_format` varchar(11) NOT NULL default 'yyyy-mm-dd',\n `float_format` tinyint( 1 ) NOT NULL DEFAULT '0',\n `port_unicity` tinyint( 1 ) NOT NULL DEFAULT '0',\n `step` int( 11 ) NOT NULL DEFAULT '0',\n PRIMARY KEY (`id`)\n ) ENGINE=MyISAM CHARSET=utf8 COLLATE=utf8_unicode_ci"; $DB->queryOrDie($query, $DB->error()); $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_datainjection_modelcsvs` (\n `id` int(11) NOT NULL auto_increment,\n `models_id` int(11) NOT NULL,\n `itemtype` varchar(255) NOT NULL default '',\n `delimiter` varchar(1) NOT NULL default ';',\n `is_header_present` tinyint(1) NOT NULL default '1',\n PRIMARY KEY (`ID`)\n ) ENGINE=MyISAM CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $DB->queryOrDie($query, $DB->error()); $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_datainjection_mappings` (\n `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,\n `models_id` INT( 11 ) NOT NULL ,\n `itemtype` varchar(255) NOT NULL default '',\n `rank` INT( 11 ) NOT NULL ,\n `name` VARCHAR( 255 ) NOT NULL ,\n `value` VARCHAR( 255 ) NOT NULL ,\n `is_mandatory` TINYINT( 1 ) NOT NULL DEFAULT '0'\n ) ENGINE = MYISAM CHARSET=utf8 COLLATE=utf8_unicode_ci ;"; $DB->queryOrDie($query, $DB->error()); $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_datainjection_infos` (\n `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,\n `models_id` INT( 11 ) NOT NULL ,\n `itemtype` varchar(255) NOT NULL default '',\n `value` VARCHAR( 255 ) NOT NULL ,\n `is_mandatory` TINYINT( 1 ) NOT NULL DEFAULT '0'\n ) ENGINE = MYISAM CHARSET=utf8 COLLATE=utf8_unicode_ci ;"; $DB->queryOrDie($query, $DB->error()); if (!is_dir(PLUGIN_DATAINJECTION_UPLOAD_DIR)) { @mkdir(PLUGIN_DATAINJECTION_UPLOAD_DIR) or die(sprintf(__('%1$s %2$s'), __("Can't create folder", 'datainjection'), PLUGIN_DATAINJECTION_UPLOAD_DIR)); PluginDatainjectionProfile::createFirstAccess($_SESSION["glpiactiveprofile"]["id"]); } break; default: break; case 1: //When updating, check if the upload folder is already present if (!is_dir(PLUGIN_DATAINJECTION_UPLOAD_DIR)) { @mkdir(PLUGIN_DATAINJECTION_UPLOAD_DIR) or die(sprintf(__('%1$s %2$s'), __("Can't create folder", 'datainjection'), PLUGIN_DATAINJECTION_UPLOAD_DIR)); } //Old temporary directory, needs to be removed ! if (is_dir(GLPI_PLUGIN_DOC_DIR . "/data_injection/")) { Toolbox::deleteDir(GLPI_PLUGIN_DOC_DIR . "/data_injection/"); } if (TableExists("glpi_plugin_data_injection_models") && !FieldExists("glpi_plugin_data_injection_models", "recursive")) { // Update plugin_datainjection_update131_14(); } if (TableExists("glpi_plugin_data_injection_models") && !FieldExists("glpi_plugin_data_injection_models", "port_unicity")) { $migration->addField('glpi_plugin_data_injection_models', 'port_unicity', 'bool'); $migration->executeMigration(); } if (!TableExists("glpi_plugin_datainjection_models")) { plugin_datainjection_update15_170(); } if (!TableExists("glpi_plugin_datainjection_modelcsvs")) { plugin_datainjection_update170_20(); } plugin_datainjection_update210_220(); plugin_datainjection_update220_230(); plugin_datainjection_upgrade23_240($migration); break; } return true; }
function plugin_mreporting_install() { global $DB; //get version $plugin = new Plugin(); $found = $plugin->find("name = 'mreporting'"); $plugin_mreporting = array_shift($found); //init migration $migration = new Migration($plugin_mreporting['version']); //create profiles table $queries = array(); $queries[] = "CREATE TABLE IF NOT EXISTS `glpi_plugin_mreporting_profiles` (\n `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,\n `profiles_id` VARCHAR(45) NOT NULL,\n `reports` CHAR(1),\n `config` CHAR(1),\n PRIMARY KEY (`id`)\n )\n ENGINE = MyISAM;"; //create configuration table $queries[] = "CREATE TABLE IF NOT EXISTS `glpi_plugin_mreporting_configs` (\n `id` int(11) NOT NULL auto_increment,\n `name` varchar(255) collate utf8_unicode_ci default NULL,\n `classname` varchar(255) collate utf8_unicode_ci default NULL,\n `is_active` tinyint(1) NOT NULL default '0',\n `is_notified` tinyint(1) NOT NULL default '1',\n `show_graph` tinyint(1) NOT NULL default '0',\n `show_area` tinyint(1) NOT NULL default '0',\n `spline` tinyint(1) NOT NULL default '0',\n `show_label` VARCHAR(10) default NULL,\n `flip_data` tinyint(1) NOT NULL default '0',\n `unit` VARCHAR(10) default NULL,\n `default_delay` VARCHAR(10) default NULL,\n `condition` VARCHAR(255) default NULL,\n `graphtype` VARCHAR(255) default 'GLPI',\n PRIMARY KEY (`id`),\n KEY `is_active` (`is_active`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $queries[] = "CREATE TABLE IF NOT EXISTS `glpi_plugin_mreporting_preferences` (\n `id` int(11) NOT NULL auto_increment,\n `users_id` int(11) NOT NULL default 0,\n `template` varchar(255) collate utf8_unicode_ci default NULL,\n PRIMARY KEY (`id`),\n KEY `users_id` (`users_id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; // add display preferences $query_display_pref = "SELECT id \n FROM glpi_displaypreferences\n WHERE itemtype = 'PluginMreportingConfig'"; $res_display_pref = $DB->query($query_display_pref); if ($DB->numrows($res_display_pref) == 0) { $queries[] = "INSERT INTO `glpi_displaypreferences` \n VALUES (NULL,'PluginMreportingConfig','2','2','0');"; $queries[] = "INSERT INTO `glpi_displaypreferences` \n VALUES (NULL,'PluginMreportingConfig','3','3','0');"; $queries[] = "INSERT INTO `glpi_displaypreferences` \n VALUES (NULL,'PluginMreportingConfig','4','4','0');"; $queries[] = "INSERT INTO `glpi_displaypreferences` \n VALUES (NULL,'PluginMreportingConfig','5','5','0');"; $queries[] = "INSERT INTO `glpi_displaypreferences` \n VALUES (NULL,'PluginMreportingConfig','6','6','0');"; $queries[] = "INSERT INTO `glpi_displaypreferences` \n VALUES (NULL,'PluginMreportingConfig','8','8','0');"; } $queries[] = "CREATE TABLE IF NOT EXISTS `glpi_plugin_mreporting_notifications` (\n `id` int(11) NOT NULL auto_increment,\n `entities_id` int(11) NOT NULL default '0',\n `is_recursive` tinyint(1) NOT NULL default '0',\n `name` varchar(255) collate utf8_unicode_ci default NULL,\n `notepad` longtext collate utf8_unicode_ci,\n `date_envoie` DATE DEFAULT NULL,\n `notice`INT(11) NOT NULL DEFAULT 0,\n `alert` INT(11) NOT NULL DEFAULT 0,\n `comment` text collate utf8_unicode_ci,\n `date_mod` datetime default NULL,\n `is_deleted` tinyint(1) NOT NULL default '0',\n PRIMARY KEY (`id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; foreach ($queries as $query) { $DB->query($query); } // == Update to 2.1 == if (!FieldExists('glpi_plugin_mreporting_configs', 'is_notified')) { $migration->addField('glpi_plugin_mreporting_configs', 'is_notified', 'tinyint(1) NOT NULL default "1"', array('after' => 'is_active')); $migration->migrationOneTable('glpi_plugin_mreporting_configs'); } require_once "inc/profile.class.php"; PluginMreportingProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']); $rep_files_mreporting = GLPI_PLUGIN_DOC_DIR . "/mreporting"; if (!is_dir($rep_files_mreporting)) { mkdir($rep_files_mreporting); } $notifications_folder = GLPI_PLUGIN_DOC_DIR . "/mreporting/notifications"; if (!is_dir($notifications_folder)) { mkdir($notifications_folder); } require_once "inc/notification.class.php"; PluginMreportingNotification::install(); CronTask::Register('PluginMreportingNotification', 'SendNotifications', MONTH_TIMESTAMP); require_once "inc/baseclass.class.php"; require_once "inc/common.class.php"; require_once "inc/config.class.php"; $config = new PluginMreportingConfig(); $config->createFirstConfig(); return true; }
static function install(Migration $migration) { global $DB; if (!$DB->query("CREATE TABLE IF NOT EXISTS `glpi_plugin_talk_userprefs` (\n `id` INT(11) NOT NULL auto_increment,\n `users_id` INT(11) NOT NULL default '0',\n `talk_tab` TINYINT(1) NOT NULL default '1',\n `old_tabs` TINYINT(1) NOT NULL default '1',\n `split_view` TINYINT(1) NOT NULL default '0',\n PRIMARY KEY (`id`),\n UNIQUE KEY (`users_id`),\n KEY `talk_tab` (`talk_tab`),\n KEY `split_view` (`split_view`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci")) { return false; } if (!FieldExists('glpi_plugin_talk_userprefs', 'old_tabs')) { $migration->addField('glpi_plugin_talk_userprefs', 'old_tabs', 'bool'); $migration->migrationOneTable('glpi_plugin_talk_userprefs'); } }
/** * Install or update containers * * @param Migration $migration Migration instance * @param string $version Plugin current version * * @return boolean */ static function install(Migration $migration, $version) { global $DB; $obj = new self(); $table = $obj->getTable(); if (!TableExists($table)) { $migration->displayMessage(sprintf(__("Installing %s"), $table)); $query = "CREATE TABLE IF NOT EXISTS `{$table}` (\n `id` INT(11) NOT NULL auto_increment,\n `name` VARCHAR(255) DEFAULT NULL,\n `label` VARCHAR(255) DEFAULT NULL,\n `itemtypes` LONGTEXT DEFAULT NULL,\n `type` VARCHAR(255) DEFAULT NULL,\n `subtype` VARCHAR(255) DEFAULT NULL,\n `entities_id` INT(11) NOT NULL DEFAULT '0',\n `is_recursive` TINYINT(1) NOT NULL DEFAULT '0',\n `is_active` TINYINT(1) NOT NULL DEFAULT '0',\n PRIMARY KEY (`id`),\n KEY `entities_id` (`entities_id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $DB->query($query) or die($DB->error()); } // multiple itemtype for one container if (!FieldExists($table, "itemtypes")) { $migration->changeField($table, 'itemtype', 'itemtypes', 'longtext'); $migration->migrationOneTable($table); $query = "UPDATE `{$table}` SET `itemtypes` = CONCAT('[\"', `itemtypes`, '\"]')"; $DB->query($query) or die($DB->error()); } //add display preferences for this class $d_pref = new DisplayPreference(); $found = $d_pref->find("itemtype = '" . __CLASS__ . "'"); if (count($found) == 0) { for ($i = 2; $i <= 5; $i++) { $DB->query("REPLACE INTO glpi_displaypreferences VALUES\n (NULL, '" . __CLASS__ . "', {$i}, " . ($i - 1) . ", 0)"); } } if (!FieldExists($table, "subtype")) { $migration->addField($table, 'subtype', 'VARCHAR(255) DEFAULT NULL', array('after' => 'type')); $migration->migrationOneTable($table); } $migration->displayMessage(__("Updating generated containers files", "fields")); // -> 0.90-1.3: generated class moved // OLD path: GLPI_ROOT."/plugins/fields/inc/$class_filename" // NEW path: PLUGINFIELDS_CLASS_PATH . "/$class_filename" $obj = new self(); $containers = $obj->find(); foreach ($containers as $container) { //First, drop old fields from plugin directories $itemtypes = count($container['itemtypes']) > 0 ? json_decode($container['itemtypes'], true) : array(); foreach ($itemtypes as $itemtype) { $class_filename = strtolower($itemtype . preg_replace('/s$/', '', $container['name']) . ".class.php"); if (file_exists(GLPI_ROOT . "/plugins/fields/inc/{$class_filename}")) { unlink(GLPI_ROOT . "/plugins/fields/inc/{$class_filename}"); } $injclass_filename = strtolower($itemtype . preg_replace('/s$/', '', $container['name']) . "injection.class.php"); if (file_exists(GLPI_ROOT . "/plugins/fields/inc/{$injclass_filename}")) { unlink(GLPI_ROOT . "/plugins/fields/inc/{$injclass_filename}"); } } //Second, create new files self::generateTemplate($container); } return true; }
/** * Database table installation for the item type * * @param Migration $migration * @return boolean True on success */ public static function install(Migration $migration) { $obj = new self(); $table = $obj->getTable(); // Create new table if (!TableExists($table)) { $migration->displayMessage("Installing {$table}"); // Create questions table $query = "CREATE TABLE IF NOT EXISTS `{$table}` (\n `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,\n `plugin_formcreator_forms_id` int(11) NOT NULL,\n `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n `order` int(11) NOT NULL DEFAULT '0'\n )\n ENGINE = MyISAM\n DEFAULT CHARACTER SET = utf8\n COLLATE = utf8_unicode_ci;"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); } else { /** * Migration of special chars from previous versions * * @since 0.85-1.2.3 */ $query = "SELECT `id`, `name`\n FROM `{$table}`"; $result = $GLOBALS['DB']->query($query); while ($line = $GLOBALS['DB']->fetch_array($result)) { $query_update = 'UPDATE `' . $table . '` SET `name` = "' . plugin_formcreator_encode($line['name']) . '" WHERE `id` = ' . $line['id']; $GLOBALS['DB']->query($query_update) or die($GLOBALS['DB']->error()); } } // Migration from previous version => Remove useless target field if (FieldExists($table, 'plugin_formcreator_targets_id', false)) { $GLOBALS['DB']->query("ALTER TABLE `{$table}` DROP `plugin_formcreator_targets_id`;"); } // Migration from previous version => Rename "position" into "order" and start order from 1 instead of 0 if (FieldExists($table, 'position', false)) { $GLOBALS['DB']->query("ALTER TABLE `{$table}` CHANGE `position` `order` INT(11) NOT NULL DEFAULT '0';"); $GLOBALS['DB']->query("UPDATE `{$table}` SET `order` = `order` + 1;"); } // Migration from previous version => Update Question table, then create a "description" question from content if (FieldExists($table, 'content', false)) { $version = plugin_version_formcreator(); $migration = new Migration($version['version']); PluginFormcreatorQuestion::install($migration); $table_questions = getTableForItemType('PluginFormcreatorQuestion'); // Increment the order of questions which are in a section with a description $query = "UPDATE `{$table_questions}`\n SET `order` = `order` + 1\n WHERE `plugin_formcreator_sections_id` IN (\n SELECT `id`\n FROM {$table}\n WHERE `content` != ''\n );"; $GLOBALS['DB']->query($query); // Create description from content $query = "INSERT INTO `{$table_questions}` (`plugin_formcreator_sections_id`, `fieldtype`, `name`, `description`, `order`)\n SELECT `id`, 'description' AS fieldtype, CONCAT('Description ', `id`) AS name, `content`, 1 AS `order`\n FROM {$table}\n WHERE `content` != ''"; $GLOBALS['DB']->query($query); // Delete content column $GLOBALS['DB']->query("ALTER TABLE `{$table}` DROP `content`;"); } return true; }
function plugin_manufacturersimports_install() { global $DB; include_once GLPI_ROOT . "/plugins/manufacturersimports/inc/profile.class.php"; $update = false; if (!TableExists("glpi_plugin_suppliertag_profiles") && !TableExists("glpi_plugin_manufacturersimports_profiles")) { $DB->runFile(GLPI_ROOT . "/plugins/manufacturersimports/sql/empty-1.5.0.sql"); } else { if (TableExists("glpi_plugin_suppliertag_config") && !FieldExists("glpi_plugin_suppliertag_config", "FK_entities")) { $update = true; $DB->runFile(GLPI_ROOT . "/plugins/manufacturersimports/sql/update-1.1.sql"); $DB->runFile(GLPI_ROOT . "/plugins/manufacturersimports/sql/update-1.2.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/manufacturersimports/sql/update-1.3.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/manufacturersimports/sql/update-1.4.1.sql"); $DB->runFile(GLPI_ROOT . "/plugins/manufacturersimports/sql/update-1.5.0.sql"); } else { if (TableExists("glpi_plugin_suppliertag_profiles") && FieldExists("glpi_plugin_suppliertag_profiles", "interface")) { $update = true; $DB->runFile(GLPI_ROOT . "/plugins/manufacturersimports/sql/update-1.2.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/manufacturersimports/sql/update-1.3.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/manufacturersimports/sql/update-1.4.1.sql"); $DB->runFile(GLPI_ROOT . "/plugins/manufacturersimports/sql/update-1.5.0.sql"); } else { if (!TableExists("glpi_plugin_manufacturersimports_profiles")) { $update = true; $DB->runFile(GLPI_ROOT . "/plugins/manufacturersimports/sql/update-1.3.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/manufacturersimports/sql/update-1.4.1.sql"); $DB->runFile(GLPI_ROOT . "/plugins/manufacturersimports/sql/update-1.5.0.sql"); } } } } $query = "UPDATE `glpi_plugin_manufacturersimports_configs` \n SET `Supplier_url` = 'http://www.dell.com/support/troubleshooting/us/en/04/Index?c=us&l=en&s=bsd&cs=04&t=system&ServiceTag=' \n WHERE `name` ='Dell'"; $DB->query($query); if ($update) { $query_ = "SELECT *\n FROM `glpi_plugin_manufacturersimports_profiles` "; $result_ = $DB->query($query_); if ($DB->numrows($result_) > 0) { while ($data = $DB->fetch_array($result_)) { $query = "UPDATE `glpi_plugin_manufacturersimports_profiles`\n SET `profiles_id` = '" . $data["id"] . "'\n WHERE `id` = '" . $data["id"] . "';"; $result = $DB->query($query); } } $query = "ALTER TABLE `glpi_plugin_manufacturersimports_profiles`\n DROP `name` ;"; $result = $DB->query($query); Plugin::migrateItemType(array(2150 => 'PluginManufacturersimportsModel', 2151 => 'PluginManufacturersimportsConfig'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_tickets"), array("glpi_plugin_manufacturersimports_models", "glpi_plugin_manufacturersimports_logs")); } PluginManufacturersimportsProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']); return true; }
function plugin_appliances_install() { global $DB; if (TableExists("glpi_plugin_applicatifs_profiles")) { if (FieldExists("glpi_plugin_applicatifs_profiles", "create_applicatifs")) { // version <1.3 $DB->runFile(GLPI_ROOT . "/plugins/appliances/sql/update-1.3.sql"); } } if (TableExists("glpi_plugin_applicatifs")) { if (!FieldExists("glpi_plugin_applicatifs", "recursive")) { // version 1.3 $DB->runFile(GLPI_ROOT . "/plugins/appliances/sql/update-1.4.sql"); } if (!FieldExists("glpi_plugin_applicatifs", "FK_groups")) { // version 1.4 $DB->runFile(GLPI_ROOT . "/plugins/appliances/sql/update-1.5.0.sql"); } if (!FieldExists("glpi_plugin_applicatifs", "helpdesk_visible")) { // version 1.5.0 $DB->runFile(GLPI_ROOT . "/plugins/appliances/sql/update-1.5.1.sql"); } if (FieldExists("glpi_plugin_applicatifs", "state")) { // empty 1.5.0 not in update 1.5.0 $DB->query("ALTER TABLE `glpi_plugin_applicatifs` DROP `state`"); } if (isIndex("glpi_plugin_applicatifs_optvalues_machines", "optvalue_ID")) { // in empty 1.5.0 not in update 1.5.0 $DB->query("ALTER TABLE `glpi_plugin_applicatifs_optvalues_machines`\n DROP KEY `optvalue_ID`"); } $DB->runFile(GLPI_ROOT . "/plugins/appliances/sql/update-1.6.0.sql"); Plugin::migrateItemType(array(1200 => 'PluginAppliancesAppliance'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_tickets"), array("glpi_plugin_appliances_appliances_items", "glpi_plugin_appliances_optvalues_items")); Plugin::migrateItemType(array(4450 => "PluginRacksRack"), array("glpi_plugin_appliances_appliances_items")); } if (!TableExists("glpi_plugin_appliances_appliances")) { // not installed $DB->runFile(GLPI_ROOT . '/plugins/appliances/sql/empty-1.8.0.sql'); } else { $migration = new Migration(180); include_once GLPI_ROOT . "/plugins/appliances/inc/appliance.class.php"; PluginAppliancesAppliance::updateSchema($migration); $migration->executeMigration(); } // required cause autoload don't work for unactive plugin' include_once GLPI_ROOT . "/plugins/appliances/inc/profile.class.php"; PluginAppliancesProfile::createAdminAccess($_SESSION['glpiactiveprofile']['id']); return true; }
function plugin_racks_install() { global $DB; include_once GLPI_ROOT . "/plugins/racks/inc/profile.class.php"; $update = false; if (!TableExists("glpi_plugin_rack_profiles") && !TableExists("glpi_plugin_racks_profiles")) { $DB->runFile(GLPI_ROOT . "/plugins/racks/sql/empty-1.4.1.sql"); } else { if (TableExists("glpi_plugin_rack_content") && !FieldExists("glpi_plugin_rack_content", "first_powersupply")) { $update = true; $DB->runFile(GLPI_ROOT . "/plugins/racks/sql/update-1.0.2.sql"); $DB->runFile(GLPI_ROOT . "/plugins/racks/sql/update-1.1.0.sql"); } else { if (!TableExists("glpi_plugin_racks_profiles")) { $update = true; $DB->runFile(GLPI_ROOT . "/plugins/racks/sql/update-1.1.0.sql"); } } } //from 1.1 version if (TableExists("glpi_plugin_racks_racks") && !FieldExists("glpi_plugin_racks_racks", "otherserial")) { $DB->runFile(GLPI_ROOT . "/plugins/racks/sql/update-1.2.1.sql"); } if (TableExists("glpi_plugin_racks_racks") && !FieldExists("glpi_plugin_racks_racks", "users_id_tech")) { $DB->runFile(GLPI_ROOT . "/plugins/racks/sql/update-1.3.0.sql"); } if (!TableExists("glpi_plugin_racks_racktypes")) { $DB->runFile(GLPI_ROOT . "/plugins/racks/sql/update-1.3.2.sql"); } if (TableExists("glpi_plugin_racks_racktypes") && !FieldExists("glpi_plugin_racks_racktypes", "is_recursive")) { $DB->runFile(GLPI_ROOT . "/plugins/racks/sql/update-1.4.1.sql"); } if ($update) { $query_ = "SELECT *\n FROM `glpi_plugin_racks_profiles` "; $result_ = $DB->query($query_); if ($DB->numrows($result_) > 0) { while ($data = $DB->fetch_array($result_)) { $query = "UPDATE `glpi_plugin_racks_profiles`\n SET `profiles_id` = '" . $data["id"] . "'\n WHERE `id` = '" . $data["id"] . "';"; $result = $DB->query($query); } } $query = "ALTER TABLE `glpi_plugin_racks_profiles`\n DROP `name` ;"; $result = $DB->query($query); Plugin::migrateItemType(array(4450 => 'PluginRacksRack', 4451 => 'PluginRacksOther'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_tickets"), array("glpi_plugin_racks_racks_items", "glpi_plugin_racks_itemspecifications")); } PluginRacksProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']); return true; }
function plugin_financialreports_install() { global $DB; include_once GLPI_ROOT . "/plugins/financialreports/inc/profile.class.php"; $update = false; if (!TableExists("glpi_plugin_state_profiles") && !TableExists("glpi_plugin_financialreports_configs")) { $DB->runFile(GLPI_ROOT . "/plugins/financialreports/sql/empty-2.1.0.sql"); } else { if (TableExists("glpi_plugin_state_parameters") && !FieldExists("glpi_plugin_state_parameters", "monitor")) { $update = true; $DB->runFile(GLPI_ROOT . "/plugins/financialreports/sql/update-1.5.sql"); $DB->runFile(GLPI_ROOT . "/plugins/financialreports/sql/update-1.6.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/financialreports/sql/update-1.7.0.sql"); } else { if (TableExists("glpi_plugin_state_profiles") && FieldExists("glpi_plugin_state_profiles", "interface")) { $update = true; $DB->runFile(GLPI_ROOT . "/plugins/financialreports/sql/update-1.6.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/financialreports/sql/update-1.7.0.sql"); } else { if (!TableExists("glpi_plugin_financialreports_configs")) { $update = true; $DB->runFile(GLPI_ROOT . "/plugins/financialreports/sql/update-1.7.0.sql"); } } } } if ($update) { //Do One time on 0.78 $query_ = "SELECT *\n FROM `glpi_plugin_financialreports_profiles` "; $result_ = $DB->query($query_); if ($DB->numrows($result_) > 0) { while ($data = $DB->fetch_array($result_)) { $query = "UPDATE `glpi_plugin_financialreports_profiles`\n SET `profiles_id` = '" . $data["id"] . "'\n WHERE `id` = '" . $data["id"] . "';"; $result = $DB->query($query); } } $query = "ALTER TABLE `glpi_plugin_financialreports_profiles`\n DROP `name` ;"; $result = $DB->query($query); Plugin::migrateItemType(array(3450 => 'PluginFinancialreportsDisposalItem'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_tickets"), array("glpi_plugin_financialreports_disposalitems")); } //Migrate profiles to the new system PluginFinancialreportsProfile::initProfile(); PluginFinancialreportsProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']); $migration = new Migration("2.0.0"); $migration->dropTable('glpi_plugin_financialreports_profiles'); return true; }
static function install(Migration $migration) { global $DB; $table = getTableForItemType(__CLASS__); if (!TableExists($table)) { $query = "CREATE TABLE IF NOT EXISTS `{$table}` (\n `id` INT(11) NOT NULL AUTO_INCREMENT,\n `plugin_itilcategorygroups_categories_id` INT(11) NOT NULL DEFAULT '0',\n `level` TINYINT(1) NOT NULL DEFAULT '0',\n `itilcategories_id` INT(11) NOT NULL DEFAULT '0',\n `groups_id` INT(11) NOT NULL DEFAULT '0',\n PRIMARY KEY (`id`),\n UNIQUE KEY `group_lvl_unicity` (plugin_itilcategorygroups_categories_id, level, groups_id),\n KEY `plugin_itilcategorygroups_categories_id` (`plugin_itilcategorygroups_categories_id`),\n KEY `level` (`level`),\n KEY `itilcategories_id` (`itilcategories_id`),\n KEY `groups_id` (`groups_id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;"; $DB->query($query); } $parent_table = "glpi_plugin_itilcategorygroups_categories"; //we must migrate groups datas in sub table if (FieldExists($parent_table, 'groups_id_levelone')) { $all_lvl = $cat_groups = array(); //foreach old levels foreach (array(1 => 'one', 2 => 'two', 3 => 'three', 4 => 'four') as $lvl_num => $lvl_str) { $query = "SELECT id, itilcategories_id, groups_id_level{$lvl_str} FROM {$parent_table}"; $res = $DB->query($query); while ($data = $DB->fetch_assoc($res)) { //specific case (all group of this lvl), store it for further treatment if ($data["groups_id_level{$lvl_str}"] == -1) { $all_lvl[$data['itilcategories_id']][$lvl_num] = $lvl_str; } if ($data["groups_id_level{$lvl_str}"] > 0) { $cat_groups[] = array('plugin_itilcategorygroups_categories_id' => $data['id'], 'level' => $lvl_num, 'itilcategories_id' => $data['itilcategories_id'], 'groups_id' => $data["groups_id_level{$lvl_str}"]); } } //insert "all groups for this lvl' foreach ($all_lvl as $itilcategories_id => $lvl) { foreach ($lvl as $lvl_num => $lvl_str) { $DB->query("UPDATE {$parent_table} SET view_all_lvl{$lvl_num} = 1\n WHERE itilcategories_id = {$itilcategories_id}"); } } //insert groups in sub table foreach ($cat_groups as $cat_groups_data) { $DB->query("REPLACE INTO glpi_plugin_itilcategorygroups_categories_groups\n (plugin_itilcategorygroups_categories_id,\n level,\n itilcategories_id,\n groups_id)\n VALUES (\n " . $cat_groups_data['plugin_itilcategorygroups_categories_id'] . ",\n " . $cat_groups_data['level'] . ",\n " . $cat_groups_data['itilcategories_id'] . ",\n " . $cat_groups_data['groups_id'] . "\n )"); } } //drop migrated fields $migration->dropField($parent_table, "groups_id_levelone"); $migration->dropField($parent_table, "groups_id_leveltwo"); $migration->dropField($parent_table, "groups_id_levelthree"); $migration->dropField($parent_table, "groups_id_levelfour"); $migration->migrationOneTable($parent_table); } return true; }
function plugin_connections_install() { global $DB; include_once GLPI_ROOT . "/plugins/connections/inc/profile.class.php"; $update = false; //TODO: Use "Migration" class instead (available since GLPI v0.80) // Go for 1.7.0 if (!TableExists('glpi_plugin_connection') && !TableExists('glpi_plugin_connections_connections')) { // Fresh install $DB->runFile(GLPI_ROOT . '/plugins/connections/sql/empty-1.7.0.sql'); // We're 1.6.0 update to 1.6.4 } elseif (TableExists('glpi_plugin_connections_connectionratesguaranteed') && !TableExists('glpi_plugin_connectiond_device')) { $DB->runFile(GLPI_ROOT . '/plugins/connections/sql/update-1.6.0-to-1.6.4.sql'); } elseif (TableExists("glpi_plugin_connection") && !FieldExists("glpi_plugin_connection", "recursive")) { $update = true; $DB->runFile(GLPI_ROOT . "/plugins/connections/sql/update-1.3.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/connections/sql/update-1.4.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/connections/sql/update-1.5.0.sql"); } elseif (TableExists("glpi_plugin_connection_profiles") && FieldExists("glpi_plugin_connection_profiles", "interface")) { $update = true; $DB->runFile(GLPI_ROOT . "/plugins/connections/sql/update-1.4.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/connections/sql/update-1.3.0.sql"); } elseif (TableExists("glpi_plugin_connection") && !FieldExists("glpi_plugin_connection", "helpdesk_visible")) { $update = true; $DB->runFile(GLPI_ROOT . "/plugins/connections/sql/update-1.3.0.sql"); } if ($update) { $query_ = "SELECT * FROM `glpi_plugin_connections_profiles` "; $result_ = $DB->query($query_); if ($DB->numrows($result_) > 0) { while ($data = $DB->fetch_array($result_)) { $query = "UPDATE `glpi_plugin_connections_profiles`\r\n SET `profiles_id` = '" . $data["id"] . "'\r\n WHERE `id` = '" . $data["id"] . "';"; $result = $DB->query($query); } } $DB->query("ALTER TABLE `glpi_plugin_connections_profiles` DROP `name`;"); Plugin::migrateItemType(array(4400 => 'PluginConnectionsConnection'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_tickets"), array("glpi_plugin_connections_connections_items")); Plugin::migrateItemType(array(1200 => "PluginAppliancesAppliance", 1300 => "PluginWebapplicationsWebapplication"), array("glpi_plugin_connections_connections_items")); } if (TableExists("glpi_plugin_connections_profiles")) { PluginConnectionsProfile::migrateProfiles(); } PluginConnectionsProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']); return true; }
function plugin_positions_install() { global $DB, $CFG_GLPI; include_once GLPI_ROOT . "/plugins/positions/inc/profile.class.php"; if (!TableExists("glpi_plugin_positions_positions")) { $DB->runFile(GLPI_ROOT . "/plugins/positions/sql/empty-2.0.0.sql"); } //v1.0.0 to V2.0.0 if (TableExists("glpi_plugin_positions_positions_items") && !FieldExists("glpi_plugin_positions_positions_items", "items_id")) { $query = "ALTER TABLE `glpi_plugin_positions_positions` \n ADD `items_id` int(11) NOT NULL default '0' COMMENT 'RELATION to various tables, according to itemtype (id)';"; $result = $DB->query($query); $query = "ALTER TABLE `glpi_plugin_positions_positions` \n ADD `itemtype` varchar(100) collate utf8_unicode_ci NOT NULL COMMENT 'see .class.php file';"; $result = $DB->query($query); $query_ = "SELECT *\n FROM `glpi_plugin_positions_positions_items` "; $result_ = $DB->query($query_); if ($DB->numrows($result_) > 0) { while ($data = $DB->fetch_array($result_)) { $query = "UPDATE `glpi_plugin_positions_positions`\n SET `items_id` = '" . $data["items_id"] . "',\n `itemtype` = '" . $data["itemtype"] . "'\n WHERE `id` = '" . $data["id"] . "';"; $result = $DB->query($query); } } $query = "DROP TABLE `glpi_plugin_positions_positions_items`;"; $result = $DB->query($query); } //v1.0.0 to V2.0.0 if (!TableExists("glpi_plugin_positions_infos")) { $query = "CREATE TABLE `glpi_plugin_positions_infos` (\n `id` int(11) NOT NULL auto_increment,\n `name` varchar(255) collate utf8_unicode_ci default NULL,\n `entities_id` int(11) NOT NULL default '0',\n `is_recursive` tinyint(1) NOT NULL default '0',\n `itemtype` varchar(100) collate utf8_unicode_ci NOT NULL COMMENT 'see .class.php file',\n `fields` text collate utf8_unicode_ci,\n `comment` text collate utf8_unicode_ci,\n `notepad` longtext collate utf8_unicode_ci,\n `date_mod` datetime NULL default NULL,\n `is_active` tinyint(1) NOT NULL DEFAULT '0',\n `is_deleted` tinyint(1) NOT NULL default '0',\n PRIMARY KEY (`id`)\n) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $result = $DB->query($query); } //to V3.0.0 if (TableExists("glpi_plugin_positions_positions") && FieldExists("glpi_plugin_positions_positions", "documents_id")) { $query = "ALTER TABLE `glpi_plugin_positions_positions` DROP `documents_id`;"; $result = $DB->query($query); } $rep_files_positions = GLPI_PLUGIN_DOC_DIR . "/positions"; if (!is_dir($rep_files_positions)) { mkdir($rep_files_positions); } $rep_files_positions_pics = GLPI_PLUGIN_DOC_DIR . "/positions/pics"; if (!is_dir($rep_files_positions_pics)) { mkdir($rep_files_positions_pics); } PluginPositionsProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']); return true; }
function plugin_routetables_install() { global $DB; include_once GLPI_ROOT . "/plugins/routetables/inc/profile.class.php"; $update = false; if (!TableExists("glpi_plugin_routetable_profiles") && !TableExists("glpi_plugin_routetables_profiles")) { $DB->runFile(GLPI_ROOT . "/plugins/routetables/sql/empty-1.2.0.sql"); } else { if (TableExists("glpi_plugin_routetable_profiles") && FieldExists("glpi_plugin_routetable_profiles", "interface")) { $update = true; $DB->runFile(GLPI_ROOT . "/plugins/routetables/sql/update-1.1.0.sql"); $DB->runFile(GLPI_ROOT . "/plugins/routetables/sql/update-1.1.1.sql"); $DB->runFile(GLPI_ROOT . "/plugins/routetables/sql/update-1.2.0.sql"); } else { if (TableExists("glpi_plugin_routetable") && !FieldExists("glpi_plugin_routetable", "helpdesk_visible")) { $update = true; $DB->runFile(GLPI_ROOT . "/plugins/routetables/sql/update-1.1.1.sql"); $DB->runFile(GLPI_ROOT . "/plugins/routetables/sql/update-1.2.0.sql"); } else { if (!TableExists("glpi_plugin_routetables_profiles")) { $update = true; $DB->runFile(GLPI_ROOT . "/plugins/routetables/sql/update-1.2.0.sql"); } } } } if ($update) { $query_ = "SELECT *\n FROM `glpi_plugin_routetables_profiles` "; $result_ = $DB->query($query_); if ($DB->numrows($result_) > 0) { while ($data = $DB->fetch_array($result_)) { $query = "UPDATE `glpi_plugin_routetables_profiles`\n SET `profiles_id` = '" . $data["id"] . "'\n WHERE `id` = '" . $data["id"] . "';"; $result = $DB->query($query); } } $query = "ALTER TABLE `glpi_plugin_routetables_profiles`\n DROP `name` ;"; $result = $DB->query($query); Plugin::migrateItemType(array(5100 => 'PluginRoutetablesRoutetable'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_tickets"), array("glpi_plugin_routetables_routetables_items")); } PluginRoutetablesProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']); return true; }
function update05to051() { global $DB; echo "<p class='center'>Version 0.51 </p>"; /*******************************GLPI 0.51***********************************************/ if (!FieldExists("glpi_infocoms", "facture", false)) { $query = "ALTER TABLE `glpi_infocoms`\n ADD `facture` char(255) NOT NULL default ''"; $DB->queryOrDie($query, "0.51 add field facture"); } if (!FieldExists("glpi_enterprises", "fax", false)) { $query = "ALTER TABLE `glpi_enterprises`\n ADD `fax` char(255) NOT NULL default ''"; $DB->queryOrDie($query, "0.51 add field fax"); } if (!FieldExists("glpi_docs", "link", false)) { $query = "ALTER TABLE `glpi_docs`\n ADD `link` char(255) NOT NULL default ''"; $DB->queryOrDie($query, "0.51 add field fax"); } if (!TableExists("glpi_dropdown_contact_type")) { $query = "CREATE TABLE `glpi_dropdown_contact_type` (\n `ID` int(11) NOT NULL auto_increment,\n `name` varchar(255) NOT NULL default '',\n PRIMARY KEY (`ID`)\n ) TYPE=MyISAM"; $DB->queryOrDie($query, "0.51 add table dropdown_contact_type"); $query = "INSERT INTO `glpi_dropdown_contact_type`\n (`name`)\n VALUES ('" . __('Technician') . "')"; $DB->queryOrDie($query, "0.51 add entries to dropdown_contact_type"); $query = "INSERT INTO `glpi_dropdown_contact_type`\n (`name`)\n VALUES ('" . __('Commercial') . "')"; $DB->queryOrDie($query, "0.51 add entries to dropdown_contact_type"); } if (!FieldExists("glpi_config", "cartridges_alarm", false)) { $query = "ALTER TABLE `glpi_config`\n ADD `cartridges_alarm` int(11) NOT NULL default '10'"; $DB->queryOrDie($query, "0.51 add field cartridges_alarm"); } if (!TableExists("glpi_state_item")) { $query = "ALTER TABLE `glpi_repair_item`\n RENAME `glpi_state_item`"; $DB->queryOrDie($query, "0.51 alter glpi_state_item table name"); $query = "ALTER TABLE `glpi_state_item`\n ADD `state` INT DEFAULT '1'"; $DB->queryOrDie($query, "0.51 add state field"); } if (!TableExists("glpi_dropdown_state")) { $query = "CREATE TABLE `glpi_dropdown_state` (\n `ID` int(11) NOT NULL auto_increment,\n `name` varchar(255) default NULL,\n PRIMARY KEY (`ID`)\n ) TYPE=MyISAM"; $DB->queryOrDie($query, "0.51 add state field"); } }