public static function install(Migration $migration) { global $DB; $table = getTableForItemType(__CLASS__); if (!TableExists($table) && !TableExists("glpi_dropdown_plugin_order_taxes")) { $migration->displayMessage("Installing {$table}"); //Install $query = "CREATE TABLE `glpi_plugin_order_ordertaxes` (\n `id` int(11) NOT NULL auto_increment,\n `name` varchar(255) collate utf8_unicode_ci default NULL,\n `comment` text collate utf8_unicode_ci,\n PRIMARY KEY (`id`),\n KEY `name` (`name`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $DB->query($query) or die($DB->error()); $taxes = new self(); foreach (array('20', '5.5', '19.6') as $tax) { $taxes->add(array('name' => $tax)); } } else { //Update $migration->displayMessage("Migrating {$table}"); //1.2.0 $migration->renameTable("glpi_dropdown_plugin_order_taxes", $table); $migration->changeField($table, "ID", "id", "int(11) NOT NULL auto_increment"); $migration->changeField($table, "name", "name", "varchar(255) collate utf8_unicode_ci default NULL"); $migration->changeField($table, "comments", "comment", "text collate utf8_unicode_ci"); $migration->migrationOneTable($table); //Remplace , by . in taxes foreach ($DB->request("SELECT `name` FROM `{$table}`") as $data) { if (strpos($data["name"], ',')) { $name = str_replace(',', '.', $data["name"]); $query = "UPDATE `{$table}`\n SET `name` = '" . $name . "'\n WHERE `name`= '" . $data["name"] . "'"; $DB->query($query) or die($DB->error()); } } } }
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; }
/** * 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; }
/** * Install or update fields * * @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 `plugin_fields_itemtype` VARCHAR(30) NOT NULL,\n `plugin_fields_items_id` INT(11) NOT NULL,\n `language` VARCHAR(5) NOT NULL,\n `label` VARCHAR(255) DEFAULT NULL,\n PRIMARY KEY (`id`),\n KEY `plugin_fields_itemtype` (`plugin_fields_itemtype`),\n KEY `plugin_fields_items_id` (`plugin_fields_items_id`),\n KEY `language` (`language`),\n UNIQUE KEY `unicity` (`plugin_fields_itemtype`, `plugin_fields_items_id`, `language`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $DB->query($query) or die($DB->error()); } $migration->displayMessage("Updating {$table}"); $migration->executeMigration(); return true; }
/** * Install or update dropdowns * * @param Migration $migration Migration instance * @param string $version Plugin current version * * @return void */ static function install(Migration $migration, $version) { $migration->displayMessage(__("Updating generated dropdown 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" // OLD path: GLPI_ROOT."/plugins/fields/front/$class_filename" // NEW path: PLUGINFIELDS_FRONT_PATH . "/$class_filename" $obj = new PluginFieldsField(); $fields = $obj->find('type = "dropdown"'); foreach ($fields as $field) { //First, drop old fields from plugin directories $class_filename = $field['name'] . "dropdown.class.php"; if (file_exists(GLPI_ROOT . "/plugins/fields/inc/{$class_filename}")) { unlink(GLPI_ROOT . "/plugins/fields/inc/{$class_filename}"); } $front_filename = $field['name'] . "dropdown.php"; if (file_exists(GLPI_ROOT . "/plugins/fields/front/{$front_filename}")) { unlink(GLPI_ROOT . "/plugins/fields/front/{$front_filename}"); } $form_filename = $field['name'] . "dropdown.form.php"; if (file_exists(GLPI_ROOT . "/plugins/fields/front/{$form_filename}")) { unlink(GLPI_ROOT . "/plugins/fields/front/{$form_filename}"); } //Second, create new files self::create($field); } return true; }
public static function install(Migration $migration) { $table = getTableForItemType(__CLASS__); 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) NOT NULL DEFAULT '',\n `comment` text 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()); } // Migration from previous version if (TableExists('glpi_plugin_formcreator_cats')) { $query = "INSERT IGNORE INTO `{$table}` (`id`, `name`)\n SELECT `id`,`name` FROM glpi_plugin_formcreator_cats"; $GLOBALS['DB']->query($query); $GLOBALS['DB']->query("DROP TABLE glpi_plugin_formcreator_cats"); } /** * Migration of special chars from previous versions * * @since 0.85-1.2.3 */ $query = "SELECT `id`, `name`, `comment`\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']) . '", `comment` = "' . plugin_formcreator_encode($line['comment']) . '" WHERE `id` = ' . $line['id']; $GLOBALS['DB']->query($query_update) or die($GLOBALS['DB']->error()); } return true; }
static function install(Migration $migration) { global $DB; $table = getTableForItemType(__CLASS__); if (!TableExists($table) && !TableExists("glpi_dropdown_plugin_order_payment")) { $migration->displayMessage("Installing {$table}"); $query = "CREATE TABLE `glpi_plugin_order_orderpayments` (\n `id` int(11) NOT NULL auto_increment,\n `name` varchar(255) collate utf8_unicode_ci default NULL,\n `comment` text collate utf8_unicode_ci,\n PRIMARY KEY (`id`),\n KEY `name` (`name`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $DB->query($query) or die($DB->error()); } else { $migration->displayMessage("Upgrading {$table}"); //1.2.0 $migration->renameTable("glpi_dropdown_plugin_order_payment", $table); $migration->changeField($table, "ID", "id", "int(11) NOT NULL auto_increment"); $migration->changeField($table, "name", "name", "varchar(255) collate utf8_unicode_ci default NULL"); $migration->changeField($table, "comments", "comment", "text collate utf8_unicode_ci"); $migration->migrationOneTable($table); } }
static function install(Migration $migration) { global $DB; $table = getTableForItemType(__CLASS__); if (!TableExists($table)) { $migration->displayMessage("Installing {$table}"); $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_order_billtypes` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,\n `comment` text COLLATE utf8_unicode_ci,\n PRIMARY KEY (`id`),\n KEY `name` (`name`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;"; $DB->query($query) or die($DB->error()); } }
static function install(Migration $migration) { $table = getTableForItemType(__CLASS__); $migration->displayMessage("Installing {$table}"); if (!TableExists($table)) { $query = "CREATE TABLE IF NOT EXISTS `{$table}` (\n `plugin_formcreator_forms_id` INT NOT NULL ,\n `plugin_formcreator_profiles_id` INT NOT NULL ,\n PRIMARY KEY (`plugin_formcreator_forms_id`, `plugin_formcreator_profiles_id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); } return true; }
public static function install(Migration $migration) { $table = getTableForItemType(__CLASS__); if (!TableExists($table)) { $migration->displayMessage("Installing {$table}"); $query = "CREATE TABLE IF NOT EXISTS `{$table}` (\n\t\t\t\t\t `id` int(11) NOT NULL auto_increment,\n\t\t\t\t\t `plugin_formcreator_forms_id` int(11) NOT NULL default '0',\n\t\t\t\t\t `items_id` int(11) NOT NULL default '0',\n\t\t\t\t\t `itemtype` varchar(100) collate utf8_unicode_ci NOT NULL default '',\n\t\t\t\t\t PRIMARY KEY (`id`),\n\t\t\t\t\t UNIQUE KEY `unicity` (`plugin_formcreator_forms_id`,`items_id`,`itemtype`),\n\t\t\t\t\t KEY `plugin_formcreator_forms_id` (`plugin_formcreator_forms_id`),\n\t\t\t\t\t KEY `item` (`itemtype`,`items_id`)\n\t\t\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); } return true; }
static function install(Migration $migration) { global $DB; //Only avaiable since 1.3.0 $table = getTableForItemType(__CLASS__); if (!TableExists($table)) { $migration->displayMessage("Installing {$table}"); $query = "CREATE TABLE `glpi_plugin_order_ordertypes` (\n `id` int(11) NOT NULL auto_increment,\n `name` varchar(255) collate utf8_unicode_ci default NULL,\n `comment` text collate utf8_unicode_ci,\n PRIMARY KEY (`id`),\n KEY `name` (`name`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $DB->query($query) or die($DB->error()); } }
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 `profiles_id` INT(11) NOT NULL DEFAULT '0',\n `plugin_fields_containers_id` INT(11) NOT NULL DEFAULT '0',\n `right` CHAR(1) DEFAULT NULL,\n PRIMARY KEY (`id`),\n KEY `profiles_id` (`profiles_id`),\n KEY `plugin_fields_containers_id` (`plugin_fields_containers_id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $DB->query($query) or die($DB->error()); } 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; }
static function install(Migration $migration) { global $DB; $table = getTableForItemType(__CLASS__); if (!TableExists($table)) { $migration->displayMessage("Installing {$table}"); $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_order_billstates` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,\n `comment` text COLLATE utf8_unicode_ci,\n PRIMARY KEY (`id`),\n KEY `name` (`name`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $DB->query($query) or die($DB->error()); } if (countElementsInTable($table) < 2) { $state = new self(); foreach (array(self::PAID => __("Paid", "order"), self::NOTPAID => __("Not paid", "order")) as $id => $label) { $state->add(array('id' => $id, 'name' => Toolbox::addslashes_deep($label))); } } }
static function install(Migration $migration) { global $DB; $table = getTableForItemType(__CLASS__); //1.2.0 $DB->query("DROP TABLE IF EXISTS `glpi_dropdown_plugin_order_status`;"); if (!TableExists($table)) { $migration->displayMessage("Installing {$table}"); $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_order_orderstates` (\n `id` int(11) NOT NULL auto_increment,\n `name` varchar(255) collate utf8_unicode_ci default NULL,\n `comment` text collate utf8_unicode_ci,\n PRIMARY KEY (`id`),\n KEY `name` (`name`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $DB->query($query) or die($DB->error()); } $state = new self(); foreach (array(1 => __("Draft", "order"), 2 => __("Waiting for approval", "order"), 3 => __("Validated", "order"), 4 => __("Being delivered", "order"), 5 => __("Delivered", "order"), 6 => __("Canceled", "order"), 7 => __("Paid", "order")) as $id => $label) { if (!countElementsInTable($table, "`id`='{$id}'")) { $state->add(array('id' => $id, 'name' => Toolbox::addslashes_deep($label))); } } }
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 `itemtype` VARCHAR(255) 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()); } //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("INSERT 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); } return true; }
/** * Migrate tables from plugin fusinvdeploy to fusioninventory * all datas in exploded tables are merged and stored in json in order table * @param Migration $migration * @return nothing */ function migrateTablesFromFusinvDeploy($migration) { global $DB; if (TableExists("glpi_plugin_fusioninventory_deployorders") && TableExists("glpi_plugin_fusinvdeploy_checks") && TableExists("glpi_plugin_fusinvdeploy_files") && TableExists("glpi_plugin_fusinvdeploy_actions")) { //add json field in deploy order table to store datas from old misc tables $field_created = $migration->addField("glpi_plugin_fusioninventory_deployorders", "json", "longtext DEFAULT NULL"); $migration->migrationOneTable("glpi_plugin_fusioninventory_deployorders"); $final_datas = array(); //== glpi_plugin_fusioninventory_deployorders == $o_query = "SELECT * FROM glpi_plugin_fusioninventory_deployorders"; $o_res = $DB->query($o_query); while ($o_datas = $DB->fetch_assoc($o_res)) { $order_id = $o_datas['id']; $o_line = array(); $of_line = array(); $o_line['checks'] = array(); $o_line['actions'] = array(); $o_line['associatedFiles'] = array(); //=== Checks === if (TableExists("glpi_plugin_fusinvdeploy_checks")) { $c_query = "SELECT type, path, value, 'error' as `return`\n FROM glpi_plugin_fusinvdeploy_checks\n WHERE plugin_fusinvdeploy_orders_id = {$order_id}\n ORDER BY ranking ASC"; $c_res = $DB->query($c_query); $c_i = 0; while ($c_datas = $DB->fetch_assoc($c_res)) { foreach ($c_datas as $c_key => $c_value) { //specific case for filesytem sizes, convert to bytes if (!empty($c_value) && is_numeric($c_value) && $c_datas['type'] !== 'freespaceGreater') { $c_value = $c_value * 1024 * 1024; } //construct job check entry $o_line['checks'][$c_i][$c_key] = $c_value; } $c_i++; } } $files_list = array(); //=== Files === if (TableExists("glpi_plugin_fusinvdeploy_files")) { $f_query = "SELECT id, name, is_p2p as p2p, filesize, mimetype, " . "p2p_retention_days as `p2p-retention-duration`, uncompress, sha512 " . "FROM glpi_plugin_fusinvdeploy_files " . "WHERE plugin_fusinvdeploy_orders_id = {$order_id}"; $f_res = $DB->query($f_query); while ($f_datas = $DB->fetch_assoc($f_res)) { //jump to next entry if sha512 is empty // This kind of entries could happen sometimes on upload errors if (empty($f_datas['sha512'])) { continue; } //construct job file entry $o_line['associatedFiles'][] = $f_datas['sha512']; foreach ($f_datas as $f_key => $f_value) { //we don't store the sha512 field in json if ($f_key == "sha512" || $f_key == "id" || $f_key == "filesize" || $f_key == "mimetype") { continue; } //construct order file entry $of_line[$f_datas['sha512']][$f_key] = $f_value; } if (!in_array($f_datas['sha512'], $files_list)) { $files_list[] = $f_datas['sha512']; } } } //=== Actions === $cmdStatus['RETURNCODE_OK'] = 'okCode'; $cmdStatus['RETURNCODE_KO'] = 'errorCode'; $cmdStatus['REGEX_OK'] = 'okPattern'; $cmdStatus['REGEX_KO'] = 'errorPattern'; if (TableExists("glpi_plugin_fusinvdeploy_actions")) { $a_query = "SELECT *\n FROM glpi_plugin_fusinvdeploy_actions\n WHERE plugin_fusinvdeploy_orders_id = {$order_id}\n ORDER BY ranking ASC"; $a_res = $DB->query($a_query); $a_i = 0; while ($a_datas = $DB->fetch_assoc($a_res)) { //get type $type = strtolower(str_replace("PluginFusinvdeployAction_", "", $a_datas['itemtype'])); //specific case for command type $type = str_replace("command", "cmd", $type); //table for action itemtype $a_table = getTableForItemType($a_datas['itemtype']); //get table fields $at_query = "SELECT *\n FROM {$a_table}\n WHERE id = " . $a_datas['items_id']; $at_res = $DB->query($at_query); while ($at_datas = $DB->fetch_assoc($at_res)) { foreach ($at_datas as $at_key => $at_value) { //we don't store the id field of action itemtype table in json if ($at_key == "id") { continue; } //specific case for 'path' field if ($at_key == "path") { $o_line['actions'][$a_i][$type]['list'][] = $at_value; } else { //construct job actions entry $o_line['actions'][$a_i][$type][$at_key] = $at_value; } } //specific case for commands : we must add status and env vars if ($a_datas['itemtype'] === "PluginFusinvdeployAction_Command") { $ret_cmd_query = "SELECT type, value\n FROM glpi_plugin_fusinvdeploy_actions_commandstatus\n WHERE plugin_fusinvdeploy_commands_id = " . $at_datas['id']; $ret_cmd_res = $DB->query($ret_cmd_query); while ($res_cmd_datas = $DB->fetch_assoc($ret_cmd_res)) { // Skip empty retchecks type: // This surely means they have been drop at some point but entry has not been // removed from database. if (!empty($res_cmd_datas['type'])) { //construct command status array entry $o_line['actions'][$a_i][$type]['retChecks'][] = array('type' => $cmdStatus[$res_cmd_datas['type']], 'values' => array($res_cmd_datas['value'])); } } } } $a_i++; } } $final_datas[$order_id]['jobs'] = $o_line; $final_datas[$order_id]['associatedFiles'] = $of_line; unset($o_line); unset($of_line); } $options = 0; if (version_compare(PHP_VERSION, '5.3.3') >= 0) { $options = $options | JSON_NUMERIC_CHECK; } if (version_compare(PHP_VERSION, '5.4.0') >= 0) { $options = $options | JSON_UNESCAPED_SLASHES; } //store json in order table foreach ($final_datas as $order_id => $data) { $json = $DB->escape(json_encode($data, $options)); $order_query = "UPDATE glpi_plugin_fusioninventory_deployorders\n SET json = '{$json}'\n WHERE id = {$order_id}"; $DB->query($order_query); } } //=== Fileparts === if (TableExists('glpi_plugin_fusinvdeploy_fileparts') && TableExists('glpi_plugin_fusinvdeploy_files')) { $files_list = $DB->request('glpi_plugin_fusinvdeploy_files'); // multipart file datas foreach ($files_list as $file) { $sha = $file['sha512']; if (empty($sha)) { continue; } $shortsha = substr($sha, 0, 6); $fp_query = "SELECT fp.`sha512` as filepart_hash, " . " f.`sha512` as file_hash " . "FROM `glpi_plugin_fusinvdeploy_files` as f " . "INNER JOIN `glpi_plugin_fusinvdeploy_fileparts` as fp " . "ON f.`id` = fp.`plugin_fusinvdeploy_files_id` " . " AND f.`shortsha512` = '{$shortsha}' " . "GROUP BY fp.`sha512` " . "ORDER BY fp.`id`"; $fp_res = $DB->query($fp_query); if ($DB->numrows($fp_res) > 0) { //print("writing file : " . GLPI_PLUGIN_DOC_DIR."/fusioninventory/files/manifests/{$sha}" . "\n"); $fhandle = fopen(GLPI_PLUGIN_DOC_DIR . "/fusioninventory/files/manifests/{$sha}", 'w+'); while ($fp_datas = $DB->fetch_assoc($fp_res)) { if ($fp_datas['file_hash'] === $sha) { fwrite($fhandle, $fp_datas['filepart_hash'] . "\n"); } } fclose($fhandle); } } } //migrate fusinvdeploy_files to fusioninventory_deployfiles if (TableExists("glpi_plugin_fusinvdeploy_files")) { $DB->query("TRUNCATE TABLE `glpi_plugin_fusioninventory_deployfiles`"); if (FieldExists("glpi_plugin_fusinvdeploy_files", "filesize")) { $f_query = implode(array("SELECT files.`id`, files.`name`,", " files.`filesize`, files.`mimetype`,", " files.`sha512`, files.`shortsha512`,", " files.`create_date`,", " pkgs.`entities_id`, pkgs.`is_recursive`", "FROM glpi_plugin_fusinvdeploy_files as files", "LEFT JOIN glpi_plugin_fusioninventory_deployorders as orders", " ON orders.`id` = files.`plugin_fusinvdeploy_orders_id`", "LEFT JOIN glpi_plugin_fusioninventory_deploypackages as pkgs", " ON orders.`plugin_fusioninventory_deploypackages_id` = pkgs.`id`", "WHERE", " files.`shortsha512` != \"\""), " \n"); $f_res = $DB->query($f_query); while ($f_datas = $DB->fetch_assoc($f_res)) { $entry = array("id" => $f_datas["id"], "name" => $f_datas["name"], "filesize" => $f_datas["filesize"], "mimetype" => $f_datas["mimetype"], "shortsha512" => $f_datas["shortsha512"], "sha512" => $f_datas["sha512"], "comments" => "", "date_mod" => $f_datas["create_date"], "entities_id" => $f_datas["entities_id"], "is_recursive" => $f_datas["is_recursive"]); $migration->displayMessage("\n"); // Check if file exists $i_DeployFile = new PluginFusioninventoryDeployFile(); $migration->displayMessage("migrating file " . $entry['name'] . " sha:" . $entry['sha512'] . "\n"); if ($i_DeployFile->checkPresenceManifest($entry['sha512'])) { $migration->displayMessage("manifest exists" . "\n"); $migration->insertInTable("glpi_plugin_fusioninventory_deployfiles", $entry); } } } } /** * JSON orders fixer: * This piece of code makes sure that JSON orders in database are valid and will fix it * otherwise. */ $orders = $DB->request('glpi_plugin_fusioninventory_deployorders'); foreach ($orders as $order_config) { $pfDeployOrder = new PluginFusioninventoryDeployOrder(); $json_order = json_decode($order_config['json']); //print("deployorders fixer : actual order structure for ID ".$order_config['id']."\n" . print_r($json_order,true) ."\n"); // Checks for /jobs json property if (!isset($json_order->jobs) || !is_object($json_order->jobs)) { //print("deployorders fixer : create missing required 'jobs' property\n"); $json_order->jobs = new stdClass(); } if (!isset($json_order->jobs->checks)) { //print("deployorders fixer : create missing required '/jobs/checks' array property\n"); $json_order->jobs->checks = array(); } if (!isset($json_order->jobs->actions)) { //print("deployorders fixer : create missing required '/jobs/actions' array property\n"); $json_order->jobs->actions = array(); } if (!isset($json_order->jobs->associatedFiles)) { //print("deployorders fixer : create missing required '/jobs/associatedFiles' array property\n"); $json_order->jobs->associatedFiles = array(); } // Checks for /associatedFiles json property if (!isset($json_order->associatedFiles) || !is_object($json_order->associatedFiles)) { //print("deployorders fixer : create missing required 'associatedFiles' property\n"); $json_order->associatedFiles = new stdClass(); } //print( //"deployorders fixer : final order structure for ID ".$order_config['id']."\n" . // json_encode($json_order,JSON_PRETTY_PRINT) ."\n" //); $pfDeployOrder::updateOrderJson($order_config['id'], $json_order); } /** * Drop unused tables */ $old_deploy_tables = array('glpi_plugin_fusinvdeploy_actions', 'glpi_plugin_fusinvdeploy_actions_commandenvvariables', 'glpi_plugin_fusinvdeploy_actions_commands', 'glpi_plugin_fusinvdeploy_actions_commandstatus', 'glpi_plugin_fusinvdeploy_actions_copies', 'glpi_plugin_fusinvdeploy_actions_deletes', 'glpi_plugin_fusinvdeploy_actions_messages', 'glpi_plugin_fusinvdeploy_actions_mkdirs', 'glpi_plugin_fusinvdeploy_actions_moves', 'glpi_plugin_fusinvdeploy_checks', 'glpi_plugin_fusinvdeploy_fileparts', 'glpi_plugin_fusinvdeploy_files', 'glpi_plugin_fusinvdeploy_files_mirrors'); foreach ($old_deploy_tables as $table) { $migration->dropTable($table); } //drop unused views $old_deploy_views = array('glpi_plugin_fusinvdeploy_taskjobs', 'glpi_plugin_fusinvdeploy_tasks'); foreach ($old_deploy_views as $view) { $DB->query("DROP VIEW IF EXISTS {$view}"); } }
public static function install(Migration $migration) { global $DB; $table = getTableForItemType(__CLASS__); if (!TableExists($table) && !TableExists("glpi_plugin_order_references_manufacturers")) { $migration->displayMessage("Installing {$table}"); $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_order_references_suppliers` (\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 `plugin_order_references_id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_plugin_order_references (id)',\n `suppliers_id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_suppliers (id)',\n `price_taxfree` decimal(20,4) NOT NULL DEFAULT '0.0000',\n `reference_code` varchar(255) collate utf8_unicode_ci default NULL,\n PRIMARY KEY (`id`),\n KEY `entities_id` (`entities_id`),\n KEY `plugin_order_references_id` (`plugin_order_references_id`),\n KEY `suppliers_id` (`suppliers_id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $DB->query($query) or die($DB->error()); } else { $migration->displayMessage("Upgrading {$table}"); //1.1.0 if (TableExists("glpi_plugin_order_references_manufacturers")) { $migration->addField("glpi_plugin_order_references_manufacturers", "reference_code", "varchar(255) NOT NULL collate utf8_unicode_ci default ''"); $migration->migrationOneTable("glpi_plugin_order_references_manufacturers"); } //1.2.0 $migration->renameTable("glpi_plugin_order_references_manufacturers", $table); $migration->addField($table, "is_recursive", "int(11) NOT NULL default '0'"); $migration->addKey($table, "suppliers_id"); $migration->addKey($table, "plugin_order_references_id"); $migration->changeField($table, "ID", "id", "int(11) NOT NULL auto_increment"); $migration->changeField($table, "FK_entities", "entities_id", "int(11) NOT NULL default '0'"); $migration->changeField($table, "FK_reference", "plugin_order_references_id", "int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_plugin_order_references (id)'"); $migration->changeField($table, "FK_enterprise", "suppliers_id", "int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_suppliers (id)'"); $migration->changeField($table, "reference_code", "reference_code", "varchar(255) collate utf8_unicode_ci default NULL"); $migration->changeField($table, "price_taxfree", "price_taxfree", "decimal(20,4) NOT NULL DEFAULT '0.0000'"); $migration->migrationOneTable($table); Plugin::migrateItemType(array(3152 => 'PluginOrderReference_Supplier'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs"), array()); if (FieldExists('glpi_tickets', 'itemtype')) { Plugin::migrateItemType(array(3152 => 'PluginOrderReference_Supplier'), array("glpi_tickets"), array()); } //1.5.0 $query = "SELECT `entities_id`,`is_recursive`,`id` FROM `glpi_plugin_order_references` "; foreach ($DB->request($query) as $data) { $query = "UPDATE `glpi_plugin_order_references_suppliers`\n SET `entities_id` = '" . $data["entities_id"] . "',`is_recursive` = '" . $data["is_recursive"] . "'\n WHERE `plugin_order_references_id` = '" . $data["id"] . "' "; $DB->query($query) or die($DB->error()); } } }
/** * 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(); 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 `entities_id` int(11) NOT NULL DEFAULT '0',\n `is_recursive` tinyint(1) NOT NULL DEFAULT '0',\n `plugin_formcreator_forms_id` int(11) NOT NULL,\n `requester_id` int(11) NULL,\n `validator_id` int(11) NULL,\n `request_date` datetime NOT NULL,\n `status` enum('waiting', 'refused', 'accepted') NOT NULL DEFAULT 'waiting',\n `comment` text NULL DEFAULT NULL\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`, `comment`\n FROM `{$table}`"; $result = $GLOBALS['DB']->query($query); while ($line = $GLOBALS['DB']->fetch_array($result)) { $query_update = 'UPDATE `' . $table . '` SET `comment` = "' . plugin_formcreator_encode($line['comment']) . '" WHERE `id` = ' . $line['id']; $GLOBALS['DB']->query($query_update) or die($GLOBALS['DB']->error()); } } // Create standard search options $query = "INSERT IGNORE INTO `glpi_displaypreferences` (`id`, `itemtype`, `num`, `rank`, `users_id`) VALUES\n (NULL, '" . __CLASS__ . "', 2, 2, 0),\n (NULL, '" . __CLASS__ . "', 3, 3, 0),\n (NULL, '" . __CLASS__ . "', 4, 4, 0),\n (NULL, '" . __CLASS__ . "', 5, 5, 0),\n (NULL, '" . __CLASS__ . "', 6, 6, 0);"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); return true; }
static function install(Migration $migration) { global $DB; $table = getTableForItemType(__CLASS__); $config = new self(); //This class is available since version 1.3.0 if (!TableExists($table)) { $migration->displayMessage("Installing {$table}"); //Install $query = "CREATE TABLE `{$table}` (\n `id` int(11) NOT NULL auto_increment,\n `purge_computer_software_install` int(11) NOT NULL default '0',\n `purge_software_version_install` int(11) NOT NULL default '0',\n `purge_infocom_creation` int(11) NOT NULL default '0',\n `purge_profile_user` int(11) NOT NULL default '0',\n `purge_group_user` int(11) NOT NULL default '0',\n `purge_webservices_logs` int(11) NOT NULL default '0',\n `purge_ocsid_changes` int(11) NOT NULL default '0',\n `purge_ocsimport` int(11) NOT NULL default '0',\n `purge_ocslink` int(11) NOT NULL default '0',\n `purge_ocsdelete` int(11) NOT NULL default '0',\n `purge_adddevice` tinyint(1) NOT NULL default '0',\n `purge_updatedevice` tinyint(1) NOT NULL default '0',\n `purge_deletedevice` tinyint(1) NOT NULL default '0',\n `purge_connectdevice` tinyint(1) NOT NULL default '0',\n `purge_disconnectdevice` tinyint(1) NOT NULL default '0',\n `purge_userdeletedfromldap` tinyint(1) NOT NULL default '0',\n `purge_addrelation` tinyint(1) NOT NULL default '0',\n `purge_deleterelation` tinyint(1) NOT NULL default '0',\n `purge_createitem` tinyint(1) NOT NULL default '0',\n `purge_deleteitem` tinyint(1) NOT NULL default '0',\n `purge_restoreitem` tinyint(1) NOT NULL default '0',\n `purge_updateitem` tinyint(1) NOT NULL default '0',\n `purge_comments` tinyint(1) NOT NULL default '0',\n `purge_datemod` tinyint(1) NOT NULL default '0',\n `purge_genericobject_unusedtypes` tinyint(1) NOT NULL default '0',\n PRIMARY KEY (`id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $DB->query($query) or die($DB->error()); //Add config $config->add(array('id' => 1)); } }
public static function install(Migration $migration) { global $DB; $table = getTableForItemType(__CLASS__); //Installation if (!TableExists($table) && !TableExists("glpi_plugin_order")) { $migration->displayMessage("Installing {$table}"); $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_order_orders` (\n `id` int(11) NOT NULL auto_increment,\n `entities_id` int(11) NOT NULL default '0',\n `is_template` tinyint(1) NOT NULL default '0',\n `template_name` varchar(255) collate utf8_unicode_ci default NULL,\n `is_recursive` tinyint(1) NOT NULL default '0',\n `name` varchar(255) collate utf8_unicode_ci default NULL,\n `num_order` varchar(255) collate utf8_unicode_ci default NULL,\n `budgets_id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_budgets (id)',\n `plugin_order_ordertaxes_id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_plugin_order_ordertaxes (id)',\n `plugin_order_orderpayments_id` int (11) NOT NULL default '0' COMMENT 'RELATION to glpi_plugin_order_orderpayments (id)',\n `order_date` date default NULL,\n `duedate` date default NULL,\n `deliverydate` date default NULL,\n `is_late` tinyint(1) NOT NULL default '0',\n `suppliers_id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_suppliers (id)',\n `contacts_id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_contacts (id)',\n `locations_id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_locations (id)',\n `plugin_order_orderstates_id` int(11) NOT NULL default 1,\n `plugin_order_billstates_id` int(11) NOT NULL default 1,\n `port_price` float NOT NULL default 0,\n `comment` text collate utf8_unicode_ci,\n `notepad` longtext collate utf8_unicode_ci,\n `is_deleted` tinyint(1) NOT NULL default '0',\n `users_id` int(11) NOT NULL default '0',\n `groups_id` int(11) NOT NULL default '0',\n `users_id_delivery` int(11) NOT NULL default '0',\n `groups_id_delivery` int(11) NOT NULL default '0',\n `plugin_order_ordertypes_id` int (11) NOT NULL default '0' COMMENT 'RELATION to glpi_plugin_order_ordertypes (id)',\n `date_mod` datetime default NULL,\n `is_helpdesk_visible` tinyint(1) NOT NULL default '1',\n PRIMARY KEY (`id`),\n KEY `name` (`name`),\n KEY `entities_id` (`entities_id`),\n KEY `plugin_order_ordertaxes_id` (`plugin_order_ordertaxes_id`),\n KEY `plugin_order_orderpayments_id` (`plugin_order_orderpayments_id`),\n KEY `states_id` (`plugin_order_orderstates_id`),\n KEY `suppliers_id` (`suppliers_id`),\n KEY `contacts_id` (`contacts_id`),\n KEY `locations_id` (`locations_id`),\n KEY `is_late` (`locations_id`),\n KEY `is_template` (`is_template`),\n KEY `is_deleted` (`is_deleted`),\n KEY date_mod (date_mod)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $DB->query($query) or die($DB->error()); Crontask::Register(__CLASS__, 'computeLateOrders', HOUR_TIMESTAMP, array('param' => 24, 'mode' => CronTask::MODE_EXTERNAL)); } else { //Upgrade $migration->displayMessage("Upgrading {$table}"); if (TableExists('glpi_plugin_order')) { //Update to 1.1.0 $migration->addField('glpi_plugin_order', "port_price", "FLOAT NOT NULL default '0'"); $migration->addField('glpi_plugin_order', "taxes", "FLOAT NOT NULL default '0'"); if (FieldExists("glpi_plugin_order", "numordersupplier")) { foreach ($DB->request("glpi_plugin_order") as $data) { $query = "INSERT INTO `glpi_plugin_order_suppliers`\n (`ID`, `FK_order`, `numorder`, `numbill`) VALUES\n (NULL, '" . $data["ID"] . "', '" . $data["numordersupplier"] . "', '" . $data["numbill"] . "') "; $DB->query($query) or die($DB->error()); } } $migration->dropField('glpi_plugin_order', 'numordersupplier'); $migration->dropField('glpi_plugin_order', 'numbill'); $migration->migrationOneTable('glpi_plugin_order'); } //1.2.0 $domigration_itemtypes = false; if ($migration->renameTable("glpi_plugin_order", $table)) { $domigration_itemtypes = true; } $migration->changeField($table, "ID", "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->changeField($table, "FK_entities", "entities_id", "int(11) NOT NULL default 0"); $migration->changeField($table, "recursive", "is_recursive", "tinyint(1) NOT NULL default 0"); $migration->changeField($table, "name", "name", "varchar(255) collate utf8_unicode_ci default NULL"); $migration->changeField($table, "budget", "budgets_id", "int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_budgets (id)'"); $migration->changeField($table, "numorder", "num_order", "varchar(255) collate utf8_unicode_ci default NULL"); $migration->changeField($table, "taxes", "plugin_order_ordertaxes_id", "int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_plugin_order_ordertaxes (id)'"); $migration->changeField($table, "payment", "plugin_order_orderpayments_id", "int (11) NOT NULL default '0' COMMENT 'RELATION to glpi_plugin_order_orderpayments (id)'"); $migration->changeField($table, "date", "order_date", "date default NULL"); $migration->changeField($table, "FK_enterprise", "suppliers_id", "int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_suppliers (id)'"); $migration->changeField($table, "FK_contact", "contacts_id", "int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_contacts (id)'"); $migration->changeField($table, "location", "locations_id", "int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_locations (id)'"); $migration->changeField($table, "status", "states_id", "int(11) NOT NULL default '0'"); $migration->changeField($table, "comment", "comment", "text collate utf8_unicode_ci"); $migration->changeField($table, "notes", "notepad", "longtext collate utf8_unicode_ci"); $migration->changeField($table, "deleted", "is_deleted", "tinyint(1) NOT NULL default '0'"); $migration->addKey($table, "name"); $migration->addKey($table, "entities_id"); $migration->addKey($table, "plugin_order_ordertaxes_id"); $migration->addKey($table, "plugin_order_orderpayments_id"); $migration->addKey($table, "states_id"); $migration->addKey($table, "suppliers_id"); $migration->addKey($table, "contacts_id"); $migration->addKey($table, "locations_id"); $migration->addKey($table, "is_deleted"); $migration->migrationOneTable($table); //Only migrate itemtypes when it's only necessary, otherwise it breaks upgrade procedure ! if ($domigration_itemtypes) { Plugin::migrateItemType(array(3150 => 'PluginOrderOrder'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_tickets"), array()); } if (TableExists("glpi_plugin_order_budgets")) { //Manage budgets (here because class has been remove since 1.4.0) $migration->changeField("glpi_plugin_order_budgets", "ID", "id", " int(11) NOT NULL auto_increment"); $migration->changeField("glpi_plugin_order_budgets", "FK_entities", "entities_id", "int(11) NOT NULL default '0'"); $migration->changeField("glpi_plugin_order_budgets", "FK_budget", "budgets_id", "int(11) NOT NULL default '0'"); $migration->changeField("glpi_plugin_order_budgets", "comments", "comment", "text collate utf8_unicode_ci"); $migration->changeField("glpi_plugin_order_budgets", "deleted", "is_deleted", "tinyint(1) NOT NULL default '0'"); $migration->changeField("glpi_plugin_order_budgets", "startdate", "start_date", "date default NULL"); $migration->changeField("glpi_plugin_order_budgets", "enddate", "end_date", "date default NULL"); $migration->changeField("glpi_plugin_order_budgets", "value", "value", "float NOT NULL DEFAULT '0'"); $migration->addKey("glpi_plugin_order_budgets", "entities_id"); $migration->addKey("glpi_plugin_order_budgets", "is_deleted"); $migration->migrationOneTable("glpi_plugin_order_budgets"); Plugin::migrateItemType(array(3153 => 'PluginOrderBudget'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_tickets"), array()); //Manage budgets migration before dropping the table $budget = new Budget(); $matchings = array('budgets_id' => 'id', 'name' => 'name', 'start_date' => 'begin_date', 'end_date' => 'end_date', 'value' => 'value', 'comment' => 'comment', 'entities_id' => 'entities_id', 'is_deleted' => 'is_deleted'); foreach (getAllDatasFromTable("glpi_plugin_order_budgets") as $data) { $tmp = array(); $id = false; foreach ($matchings as $old => $new) { if (!is_null($data[$old])) { $tmp[$new] = $data[$old]; } } $tmp['comment'] = Toolbox::addslashes_deep($tmp['comment']); //Budget already exists in the core: update it if ($budget->getFromDB($data['budgets_id'])) { $budget->update($tmp); $id = $tmp['id']; } else { //Budget doesn't exists in the core: create it unset($tmp['id']); $id = $budget->add($tmp); } } $DB->query("DROP TABLE `glpi_plugin_order_budgets`"); foreach (array('glpi_displaypreferences', 'glpi_documents_items', 'glpi_bookmarks', 'glpi_logs') as $t) { $DB->query("DELETE FROM `{$t}` WHERE `itemtype` = 'PluginOrderBudget'"); } } //1.3.0 $migration->addField($table, "plugin_order_ordertypes_id", "int (11) NOT NULL default '0' COMMENT 'RELATION to glpi_plugin_order_ordertypes (id)'"); $migration->migrationOneTable($table); //1.4.0 if ($migration->changeField("glpi_plugin_order_orders", "states_id", "plugin_order_orderstates_id", "int(11) NOT NULL default 1")) { $migration->migrationOneTable($table); $query = "UPDATE `glpi_plugin_order_orders` SET `plugin_order_orderstates_id`=`plugin_order_orderstates_id`+1"; $DB->query($query) or die($DB->error()); } $migration->addField($table, "duedate", "DATETIME NULL"); $migration->migrationOneTable($table); //1.5.0 if (TableExists("glpi_dropdown_plugin_order_status")) { $DB->query("DROP TABLE `glpi_dropdown_plugin_order_status`") or die($DB->error()); } if (TableExists("glpi_plugin_order_mailing")) { $DB->query("DROP TABLE IF EXISTS `glpi_plugin_order_mailing`;") or die($DB->error()); } $migration->addField($table, 'plugin_order_billstates_id', "int(11) NOT NULL default 0"); //1.5.2 $migration->addField($table, 'deliverydate', "DATETIME NULL"); $migration->addField($table, "is_late", "TINYINT(1) NOT NULL DEFAULT '0'"); $migration->addKey($table, "is_late"); if (!countElementsInTable('glpi_crontasks', "`name`='computeLateOrders'")) { Crontask::Register(__CLASS__, 'computeLateOrders', HOUR_TIMESTAMP, array('param' => 24, 'mode' => CronTask::MODE_EXTERNAL)); } $migration->migrationOneTable($table); if ($migration->addField($table, "is_template", "tinyint(1) NOT NULL DEFAULT 0")) { $migration->addField($table, "template_name", "VARCHAR(255) collate utf8_unicode_ci default NULL"); $migration->migrationOneTable($table); } $migration->addField($table, "users_id", "INT(11) NOT NULL DEFAULT '0'"); $migration->addField($table, "groups_id", "INT(11) NOT NULL DEFAULT '0'"); $migration->addField($table, "users_id_delivery", "INT(11) NOT NULL DEFAULT '0'"); $migration->addField($table, "groups_id_delivery", "INT(11) NOT NULL DEFAULT '0'"); //1.7.0 $migration->addField($table, "date_mod", "datetime"); $migration->addKey($table, "date_mod"); //1.7.2 $migration->addField($table, "is_helpdesk_visible", "bool", array('value' => 1)); $migration->migrationOneTable($table); //Displayprefs $prefs = array(1 => 1, 2 => 2, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 10 => 10); foreach ($prefs as $num => $rank) { if (!countElementsInTable("glpi_displaypreferences", "`itemtype`='PluginOrderOrder' AND `num`='{$num}'\n AND `users_id`='0'")) { $DB->query("INSERT INTO glpi_displaypreferences\n VALUES (NULL,'PluginOrderOrder','{$num}','{$rank}','0');"); } } //Remove unused notifications $notification = new Notification(); $notification->deleteByCriteria("`itemtype`='PluginOrderOrder_Item'"); } }
public static function install(Migration $migration) { global $DB; $table = getTableForItemType(__CLASS__); $config = new self(); //This class is available since version 1.3.0 if (!TableExists($table) && !TableExists("glpi_plugin_order_config")) { $migration->displayMessage("Installing {$table}"); //Install $query = "CREATE TABLE `{$table}` (\n `id` int(11) NOT NULL auto_increment,\n `use_validation` tinyint(1) NOT NULL default '0',\n `use_supplier_satisfaction` tinyint(1) NOT NULL default '0',\n `use_supplier_informations` tinyint(1) NOT NULL default '0',\n `use_supplier_infos` tinyint(1) NOT NULL default '1',\n `generate_order_pdf` tinyint(1) NOT NULL default '0',\n `copy_documents` tinyint(1) NOT NULL default '0',\n `default_taxes` int(11) NOT NULL default '0',\n `generate_assets` int(11) NOT NULL default '0',\n `generated_name` varchar(255) collate utf8_unicode_ci default NULL,\n `generated_serial` varchar(255) collate utf8_unicode_ci default NULL,\n `generated_otherserial` varchar(255) collate utf8_unicode_ci default NULL,\n `default_asset_states_id` int(11) NOT NULL default '0',\n `tickettemplates_id_delivery` int(11) NOT NULL default '0',\n `order_status_draft` int(11) NOT NULL default '0',\n `order_status_waiting_approval` int(11) NOT NULL default '0',\n `order_status_approved` int(11) NOT NULL default '0',\n `order_status_partially_delivred` int(11) NOT NULL default '0',\n `order_status_completly_delivered` int(11) NOT NULL default '0',\n `order_status_canceled` int(11) NOT NULL default '0',\n `order_status_paid` int(11) NOT NULL default '0',\n `shoudbedelivered_color` char(20) collate utf8_unicode_ci default '#ff5555',\n `documentcategories_id` int(11) NOT NULL default '0',\n `groups_id_author` int(11) NOT NULL default '0',\n `groups_id_recipient` int(11) NOT NULL default '0',\n `users_id_recipient` int(11) NOT NULL default '0',\n `add_location` tinyint(1) NOT NULL default '0',\n `add_bill_details` tinyint(1) NOT NULL default '0',\n `hide_inactive_budgets` tinyint(1) NOT NULL default '0',\n `rename_documents` tinyint(1) NOT NULL default '0',\n `transmit_budget_change` tinyint(1) NOT NULL default '0',\n PRIMARY KEY (`id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $DB->query($query) or die($DB->error()); $tobefilled = "TOBEFILLED"; $tmp = array('id' => 1, 'use_validation' => 0, 'default_taxes' => 0, 'generate_assets' => 0, 'generated_name' => $tobefilled, 'generated_serial' => $tobefilled, 'generated_otherserial' => $tobefilled, 'default_asset_states_id' => 0, 'generated_title' => $tobefilled, 'generated_content' => $tobefilled, 'default_ticketcategories_id' => 0, 'shoudbedelivered_color' => '#ff5555'); $config->add($tmp); } else { //Upgrade $migration->displayMessage("Upgrading {$table}"); //1.2.0 $migration->renameTable("glpi_plugin_order_config", $table); if (!countElementsInTable("glpi_plugin_order_configs")) { $query = "INSERT INTO `glpi_plugin_order_configs`(`id`,`use_validation`,`default_taxes`) VALUES (1,0,0);"; $DB->query($query) or die($DB->error()); } $migration->changeField($table, "ID", "id", "int(11) NOT NULL auto_increment"); //1.3.0 $migration->addField($table, "generate_assets", "tinyint(1) NOT NULL default '0'"); $migration->addField($table, "generated_name", "varchar(255) collate utf8_unicode_ci default NULL"); $migration->addField($table, "generated_serial", "varchar(255) collate utf8_unicode_ci default NULL"); $migration->addField($table, "generated_otherserial", "varchar(255) collate utf8_unicode_ci default NULL"); $migration->addField($table, "default_asset_entities_id", "int(11) NOT NULL default '0'"); $migration->addField($table, "default_asset_states_id", "int(11) NOT NULL default '0'"); $migration->addField($table, "generated_title", "varchar(255) collate utf8_unicode_ci default NULL"); $migration->addField($table, "generated_content", "text collate utf8_unicode_ci"); $migration->addField($table, "default_ticketcategories_id", "int(11) NOT NULL default '0'"); $migration->addField($table, "use_supplier_satisfaction", "tinyint(1) NOT NULL default '0'"); $migration->addField($table, "generate_order_pdf", "tinyint(1) NOT NULL default '0'"); $migration->addField($table, "use_supplier_informations", "tinyint(1) NOT NULL default '1'"); $migration->addField($table, "shoudbedelivered_color", "char(20) collate utf8_unicode_ci default '#ff5555'"); $migration->addField($table, "copy_documents", "tinyint(1) NOT NULL DEFAULT '0'"); $migration->addField($table, "documentcategories_id", "integer"); $migration->addField($table, "groups_id_author", "integer"); $migration->addField($table, "groups_id_recipient", "integer"); $migration->addField($table, "users_id_recipient", "integer"); $migration->changeField($table, "default_ticketcategories_id", "default_itilcategories_id", "integer"); //1.9.0 $migration->addField($table, "add_location", "TINYINT(1) NOT NULL DEFAULT '0'"); $migration->addField($table, "add_bill_details", "TINYINT(1) NOT NULL DEFAULT '0'"); $config = new self(); $config->getFromDB(1); $templateID = false; $migration->addField($table, "tickettemplates_id_delivery", 'integer'); $migration->migrationOneTable($table); $migration->dropField($table, "generated_title"); $migration->dropField($table, "generated_content"); $migration->dropField($table, "default_itilcategories_id"); $migration->addField($table, "hide_inactive_budgets", "bool"); $migration->addField($table, "rename_documents", "bool"); //0.85+1.2 $migration->addField($table, "transmit_budget_change", "bool"); $migration->migrationOneTable($table); if ($templateID) { $config->update(array('id' => 1, 'tickettemplates_id_delivery' => $templateID)); } } $migration->displayMessage("Add default order state workflow"); $new_states = array('order_status_draft' => 1, 'order_status_waiting_approval' => 2, 'order_status_approved' => 3, 'order_status_partially_delivred' => 4, 'order_status_completly_delivered' => 5, 'order_status_canceled' => 6, 'order_status_paid' => 7); foreach ($new_states as $field => $value) { $migration->addField($table, $field, "int(11) NOT NULL default '0'"); } $migration->migrationOneTable($table); $new_states['id'] = 1; $config->update($new_states); }
public static function install(Migration $migration) { global $DB; $table = getTableForItemType(__CLASS__); if (!TableExists($table)) { if (!TableExists("glpi_plugin_order_suppliers")) { $migration->displayMessage("Installing {$table}"); //install $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_order_orders_suppliers` (\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 `plugin_order_orders_id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_plugin_order_orders (id)',\n `suppliers_id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_suppliers (id)',\n `num_quote` varchar(255) collate utf8_unicode_ci default NULL,\n `num_order` varchar(255) collate utf8_unicode_ci default NULL,\n `num_bill` varchar(255) collate utf8_unicode_ci default NULL,\n PRIMARY KEY (`id`),\n KEY `plugin_order_orders_id` (`plugin_order_orders_id`),\n KEY `entities_id` (`entities_id`),\n KEY `suppliers_id` (`suppliers_id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $DB->query($query) or die($DB->error()); } else { //Upgrade $migration->displayMessage("Upgrading {$table}"); //1.2.0 $migration->renameTable("glpi_plugin_order_suppliers", $table); $migration->addField($table, "entities_id", "int(11) NOT NULL default '0'"); $migration->addField($table, "is_recursive", "tinyint(1) NOT NULL default '0'"); $migration->addField($table, "suppliers_id", "int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_suppliers (id)'"); $migration->changeField($table, "ID", "id", "int(11) NOT NULL auto_increment"); $migration->changeField($table, "FK_order", "plugin_order_orders_id", "int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_plugin_order_orders (id)'"); $migration->changeField($table, "numquote", "num_quote", "varchar(255) collate utf8_unicode_ci default NULL"); $migration->changeField($table, "numbill", "num_bill", "varchar(255) collate utf8_unicode_ci default NULL"); $migration->changeField($table, "numorder", "num_order", "varchar(255) collate utf8_unicode_ci default NULL"); $migration->addKey($table, "plugin_order_orders_id"); $migration->addKey($table, "suppliers_id"); $migration->migrationOneTable($table); Plugin::migrateItemType(array(3154 => 'PluginOrderOrder_Supplier'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_items_tickets"), array()); //1.5.0 $query = "SELECT `suppliers_id`, `entities_id`,`is_recursive`,`id`\n FROM `glpi_plugin_order_orders` "; foreach ($DB->request($query) as $data) { $query = "UPDATE `glpi_plugin_order_orders_suppliers` SET\n `suppliers_id` = '{$data["suppliers_id"]}'\n WHERE `plugin_order_orders_id` = '{$data["id"]}' "; $DB->query($query) or die($DB->error()); $query = "UPDATE `glpi_plugin_order_orders_suppliers` SET\n `entities_id` = '{$data["entities_id"]}',\n `is_recursive` = '{$data["is_recursive"]}'\n WHERE `plugin_order_orders_id` = '{$data["id"]}' "; $DB->query($query) or die($DB->error()); } } } }
/** * 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(); 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_sections_id` int(11) NOT NULL,\n `fieldtype` varchar(30) NOT NULL DEFAULT 'text',\n `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n `required` boolean NOT NULL DEFAULT FALSE,\n `show_empty` boolean NOT NULL DEFAULT FALSE,\n `default_values` text NULL,\n `values` text NULL,\n `range_min` varchar(10) NULL DEFAULT NULL,\n `range_max` varchar(10) NULL DEFAULT NULL,\n `description` text NOT NULL,\n `regex` varchar(255) NULL DEFAULT NULL,\n `order` int(11) NOT NULL DEFAULT '0',\n `show_rule` enum('always','hidden','shown') NOT NULL DEFAULT 'always'\n )\n ENGINE = MyISAM\n DEFAULT CHARACTER SET = utf8\n COLLATE = utf8_unicode_ci"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); // Create questions conditions table (since 0.85-1.1) $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_questions_conditions` (\n `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,\n `plugin_formcreator_questions_id` int(11) NOT NULL,\n `show_field` int(11) DEFAULT NULL,\n `show_condition` enum('==','!=','<','>','<=','>=') DEFAULT NULL,\n `show_value` varchar(255) DEFAULT NULL,\n `show_logic` enum('AND','OR','XOR') DEFAULT NULL\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 0.83-1.0 => 0.85-1.0 if (!FieldExists($table, 'fieldtype', false)) { // Migration from previous version $query = "ALTER TABLE `{$table}`\n ADD `fieldtype` varchar(30) NOT NULL DEFAULT 'text',\n ADD `show_type` enum ('show', 'hide') NOT NULL DEFAULT 'show',\n ADD `show_field` int(11) DEFAULT NULL,\n ADD `show_condition` enum('equal','notequal','lower','greater') COLLATE utf8_unicode_ci DEFAULT NULL,\n ADD `show_value` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,\n ADD `required` tinyint(1) NOT NULL DEFAULT '0',\n ADD `show_empty` tinyint(1) NOT NULL DEFAULT '0',\n ADD `default_values` text COLLATE utf8_unicode_ci,\n ADD `values` text COLLATE utf8_unicode_ci,\n ADD `range_min` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,\n ADD `range_max` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,\n ADD `regex` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,\n CHANGE `content` `description` text COLLATE utf8_unicode_ci NOT NULL,\n CHANGE `position` `order` int(11) NOT NULL DEFAULT '0';"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); // order start from 1 instead of 0 $GLOBALS['DB']->query("UPDATE `{$table}` SET `order` = `order` + 1;") or die($GLOBALS['DB']->error()); // Match new type $query = "SELECT `id`, `type`, `data`, `option`\n FROM {$table}"; $result = $GLOBALS['DB']->query($query); while ($line = $GLOBALS['DB']->fetch_array($result)) { $datas = json_decode($line['data']); $options = json_decode($line['option']); $fieldtype = 'text'; $values = ''; $default = ''; $regex = ''; $required = 0; if (isset($datas->value) && !empty($datas->value)) { if (is_object($datas->value)) { foreach ($datas->value as $value) { if (!empty($value)) { $values .= urldecode($value) . "\r\n"; } } } else { $values .= urldecode($datas->value); } } switch ($line['type']) { case '1': $fieldtype = 'text'; if (isset($options->type)) { switch ($options->type) { case '2': $required = 1; break; case '3': $regex = '[[:alpha:]]'; break; case '4': $fieldtype = 'float'; break; case '5': $regex = urldecode($options->value); // Add leading and trailing regex marker (automaticaly added in V1) if (substr($regex, 0, 1) != '/') { $regex = '/' . $regex; } if (substr($regex, -1, 1) != '/') { $regex = $regex . '/'; } break; case '6': $fieldtype = 'email'; break; case '7': $fieldtype = 'date'; break; } } $default_values = $values; $values = ''; break; case '2': $fieldtype = 'select'; break; case '3': $fieldtype = 'checkboxes'; break; case '4': $fieldtype = 'textarea'; if (isset($options->type) && $options->type == 2) { $required = 1; } $default_values = $values; $values = ''; break; case '5': $fieldtype = 'file'; break; case '8': $fieldtype = 'select'; break; case '9': $fieldtype = 'select'; break; case '10': $fieldtype = 'dropdown'; break; default: $data = null; break; } $query_udate = 'UPDATE ' . $table . ' SET `fieldtype` = "' . $fieldtype . '", `values` = "' . htmlspecialchars($values) . '", `default_values` = "' . htmlspecialchars($default) . '", `regex` = "' . $regex . '", `required` = "' . $required . ' " WHERE `id` = ' . $line['id']; $GLOBALS['DB']->query($query_udate) or die($GLOBALS['DB']->error()); } $query = "ALTER TABLE `{$table}`\n DROP `type`,\n DROP `data`,\n DROP `option`,\n DROP `plugin_formcreator_forms_id`;"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); } // Migration 0.85-1.0 => 0.85-1.1 if (FieldExists($table, 'show_type', false)) { // Fix type of section ID if (!FieldExists('glpi_plugin_formcreator_questions', 'show_rule')) { $query = "ALTER TABLE `glpi_plugin_formcreator_questions`\n CHANGE `plugin_formcreator_sections_id` `plugin_formcreator_sections_id` INT NOT NULL,\n ADD `show_rule` enum('always','hidden','shown') NOT NULL DEFAULT 'always'"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); } // Create new table for conditionnal show of questions $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_questions_conditions` (\n `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,\n `plugin_formcreator_questions_id` int(11) NOT NULL,\n `show_field` int(11) DEFAULT NULL,\n `show_condition` enum('==','!=','<','>','<=','>=') DEFAULT NULL,\n `show_value` varchar(255) DEFAULT NULL,\n `show_logic` enum('AND','OR','XOR') DEFAULT NULL\n )\n ENGINE = MyISAM\n DEFAULT CHARACTER SET = utf8\n COLLATE = utf8_unicode_ci"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); // Migrate date from "questions" table to "questions_conditions" table $query = "SELECT `id`, `show_type`, `show_field`, `show_condition`, `show_value`\n FROM {$table}"; $result = $GLOBALS['DB']->query($query); while ($line = $GLOBALS['DB']->fetch_array($result)) { switch ($line['show_type']) { case 'hide': $show_rule = 'hidden'; break; default: $show_rule = 'always'; } switch ($line['show_condition']) { case 'notequal': $show_condition = '!='; break; case 'lower': $show_condition = '<'; break; case 'greater': $show_condition = '>'; break; default: $show_condition = '=='; } $line['show_value'] = addslashes($line['show_value']); $query_udate = "UPDATE `glpi_plugin_formcreator_questions` SET\n `show_rule` = '{$show_rule}'\n WHERE `id` = {$line['id']}"; $GLOBALS['DB']->query($query_udate) or die($GLOBALS['DB']->error()); $query_udate = "INSERT INTO `glpi_plugin_formcreator_questions_conditions` SET\n `plugin_formcreator_questions_id` = {$line['id']},\n `show_field` = '{$line['show_field']}',\n `show_condition` = '{$show_condition}',\n `show_value` = '{$line['show_value']}'"; $GLOBALS['DB']->query($query_udate) or die($GLOBALS['DB']->error()); } // Delete old fields $query = "ALTER TABLE `{$table}`\n DROP `show_type`,\n DROP `show_field`,\n DROP `show_condition`,\n DROP `show_value`;"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); } /** * Migration of special chars from previous versions * * @since 0.85-1.2.3 */ // Migrate "questions" table $query = "SELECT `id`, `name`, `values`, `default_values`, `description`\n FROM `glpi_plugin_formcreator_questions`"; $result = $GLOBALS['DB']->query($query); while ($line = $GLOBALS['DB']->fetch_array($result)) { $query_update = 'UPDATE `glpi_plugin_formcreator_questions` SET `name` = "' . plugin_formcreator_encode($line['name']) . '", `values` = "' . plugin_formcreator_encode($line['values']) . '", `default_values` = "' . plugin_formcreator_encode($line['default_values']) . '", `description` = "' . plugin_formcreator_encode($line['description']) . '" WHERE `id` = ' . $line['id']; $GLOBALS['DB']->query($query_update) or die($GLOBALS['DB']->error()); } // Migrate "question_conditions" table $query = "SELECT `id`, `show_value`\n FROM `glpi_plugin_formcreator_questions_conditions`"; $result = $GLOBALS['DB']->query($query); while ($line = $GLOBALS['DB']->fetch_array($result)) { $query_update = 'UPDATE `glpi_plugin_formcreator_questions_conditions` SET `show_value` = "' . plugin_formcreator_encode($line['show_value']) . '" WHERE `id` = ' . $line['id']; $GLOBALS['DB']->query($query_update) or die($GLOBALS['DB']->error()); } } return true; }
public static function install(Migration $migration) { global $DB; $table = getTableForItemType(__CLASS__); if (!TableExists($table)) { $migration->displayMessage("Installing {$table}"); //Install $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_order_references` (\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 `manufacturers_id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_manufacturers (id)',\n `manufacturers_reference` varchar(255) collate utf8_unicode_ci NOT NULL DEFAULT '',\n `types_id` int(11) NOT NULL default '0' COMMENT 'RELATION to various tables, according to itemtypes tables (id)',\n `models_id` int(11) NOT NULL default '0' COMMENT 'RELATION to various tables, according to itemmodels tables (id)',\n `itemtype` varchar(100) collate utf8_unicode_ci NOT NULL COMMENT 'see .class.php file',\n `templates_id` int(11) NOT NULL default '0' COMMENT 'RELATION to various tables, according to itemtype (id)',\n `comment` text collate utf8_unicode_ci,\n `is_deleted` tinyint(1) NOT NULL default '0',\n `is_active` tinyint(1) NOT NULL default '1',\n `notepad` longtext collate utf8_unicode_ci,\n `date_mod` datetime default NULL,\n PRIMARY KEY (`id`),\n KEY `name` (`name`),\n KEY `entities_id` (`entities_id`),\n KEY `manufacturers_id` (`manufacturers_id`),\n KEY `types_id` (`types_id`),\n KEY `models_id` (`models_id`),\n KEY `templates_id` (`templates_id`),\n KEY `is_active` (`is_active`),\n KEY `is_deleted` (`is_deleted`),\n KEY date_mod (date_mod)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $DB->query($query) or die($DB->error()); } else { //Upgrade $migration->displayMessage("Upgrading {$table}"); //1.1.0 $migration->changeField($table, "FK_manufacturer", "FK_glpi_enterprise", "int(11) NOT NULL DEFAULT '0'"); ///1.2.0 $migration->changeField($table, "ID", "id", "int(11) NOT NULL auto_increment"); $migration->changeField($table, "FK_entities", "entities_id", "int(11) NOT NULL default '0'"); $migration->changeField($table, "recursive", "is_recursive", "tinyint(1) NOT NULL default '0'"); $migration->changeField($table, "name", "name", "varchar(255) collate utf8_unicode_ci default NULL"); $migration->changeField($table, "FK_glpi_enterprise", "manufacturers_id", "int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_manufacturers (id)'"); $migration->changeField($table, "FK_type", "types_id", "int(11) NOT NULL default '0' COMMENT 'RELATION to various tables, according to itemtypes tables (id)'"); $migration->changeField($table, "FK_model", "models_id", "int(11) NOT NULL default '0' COMMENT 'RELATION to various tables, according to itemmodels tables (id)'"); $migration->changeField($table, "type", "itemtype", "varchar(100) collate utf8_unicode_ci NOT NULL COMMENT 'see .class.php file'"); $migration->changeField($table, "template", "templates_id", "int(11) NOT NULL default '0' COMMENT 'RELATION to various tables, according to itemtype (id)'"); $migration->changeField($table, "comments", "comment", "text collate utf8_unicode_ci"); $migration->changeField($table, "deleted", "is_deleted", "tinyint(1) NOT NULL default '0'"); $migration->addField($table, "notepad", "longtext collate utf8_unicode_ci"); $migration->addField($table, "is_active", "TINYINT(1) NOT NULL DEFAULT '1'"); $migration->addField($table, "date_mod", "datetime"); $migration->addKey($table, "name"); $migration->addKey($table, "entities_id"); $migration->addKey($table, "manufacturers_id"); $migration->addKey($table, "types_id"); $migration->addKey($table, "models_id"); $migration->addKey($table, "templates_id"); $migration->addKey($table, "is_deleted"); $migration->addKey($table, "is_active"); $migration->addKey($table, "date_mod"); $migration->migrationOneTable($table); Plugin::migrateItemType(array(3151 => 'PluginOrderReference'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs")); if (FieldExists('glpi_tickets', 'itemtype')) { Plugin::migrateItemType(array(3151 => 'PluginOrderReference'), array("glpi_tickets")); } Plugin::migrateItemType(array(), array(), array($table)); //1.3.0 $DB->query("UPDATE `glpi_plugin_order_references` SET\n `itemtype`='ConsumableItem'\n WHERE `itemtype` ='Consumable'") or die($DB->error()); $DB->query("UPDATE `glpi_plugin_order_references` SET\n `itemtype`='CartridgeItem'\n WHERE `itemtype` ='Cartridge'") or die($DB->error()); //1.7.0 $migration->addField($table, "date_mod", "DATETIME NULL"); $migration->addKey($table, "date_mod"); //Displayprefs $prefs = array(1 => 1, 2 => 4, 4 => 5, 5 => 9, 6 => 6, 7 => 7); foreach ($prefs as $num => $rank) { if (!countElementsInTable("glpi_displaypreferences", "`itemtype`='PluginOrderReference' AND `num`='{$num}'\n AND `users_id`='0'")) { $DB->query("INSERT INTO glpi_displaypreferences\n VALUES (NULL,'PluginOrderReference','{$num}','{$rank}','0');"); } } //Fix error naming field if (FieldExists($table, 'manufacturer_reference')) { $migration->changeField($table, "manufacturer_reference", "manufacturers_reference", "varchar(255) collate utf8_unicode_ci NOT NULL DEFAULT ''"); $migration->migrationOneTable($table); } //2.0.1 if (!FieldExists($table, 'manufacturers_reference')) { $migration->addField($table, "manufacturers_reference", "varchar(255) collate utf8_unicode_ci NOT NULL DEFAULT ''"); $migration->migrationOneTable($table); } } }
public static function install(Migration $migration) { global $DB; $table = getTableForItemType(__CLASS__); if (!TableExists($table)) { $migration->displayMessage("Installing {$table}"); $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_order_bills` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT '',\n `number` varchar(255) COLLATE utf8_unicode_ci DEFAULT '',\n `billdate` datetime DEFAULT NULL,\n `validationdate` datetime DEFAULT NULL,\n `comment` text COLLATE utf8_unicode_ci,\n `plugin_order_billstates_id` int(11) NOT NULL DEFAULT '0',\n `value` decimal(20,4) NOT NULL DEFAULT '0.0000',\n `plugin_order_billtypes_id` int(11) NOT NULL DEFAULT '0',\n `suppliers_id` int(11) NOT NULL DEFAULT '0',\n `plugin_order_orders_id` int(11) NOT NULL DEFAULT '0',\n `users_id_validation` int(11) NOT NULL DEFAULT '0',\n `entities_id` int(11) NOT NULL DEFAULT '0',\n `is_recursive` int(11) NOT NULL DEFAULT '0',\n `notepad` text COLLATE utf8_unicode_ci,\n PRIMARY KEY (`id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;"; $DB->query($query) or die($DB->error()); } else { if (FieldExists("glpi_plugin_order_orders_suppliers", "num_bill")) { //Migrate bills $bill = new PluginOrderBill(); $query = "SELECT * FROM `glpi_plugin_order_orders_suppliers`"; foreach (getAllDatasFromTable('glpi_plugin_order_orders_suppliers') as $data) { if (!is_null($data['num_bill']) && $data['num_bill'] != '' && !countElementsInTable('glpi_plugin_order_bills', "`number`='" . $data['num_bill'] . "'")) { //create new bill and link it to the order $tmp['name'] = $tmp['number'] = $data['num_bill']; //Get supplier from the order $tmp['suppliers_id'] = $data['suppliers_id']; //Bill has the same entities_id and is_recrusive $tmp['entities_id'] = $data['entities_id']; $tmp['is_recursive'] = $data['is_recursive']; //Link bill to order $tmp['plugin_order_orders_id'] = $data['plugin_order_orders_id']; //Create bill $bills_id = $bill->add($tmp); //All order items are now linked to this bill $query = "UPDATE `glpi_plugin_order_orders_items`\n SET `plugin_order_bills_id` = '{$bills_id}'\n WHERE `plugin_order_orders_id` = '" . $data['plugin_order_orders_id'] . "'"; $DB->query($query); } } } $migration->changeField($table, "value", "value", "decimal(20,4) NOT NULL DEFAULT '0.0000'"); $migration->migrationOneTable($table); } $migration->dropField("glpi_plugin_order_orders_suppliers", "num_bill"); $migration->migrationOneTable("glpi_plugin_order_orders_suppliers"); }
/** * 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 default request type $query = "SELECT id FROM `glpi_requesttypes` WHERE `name` LIKE 'Formcreator';"; $result = $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); if ($GLOBALS['DB']->numrows($result) > 0) { list($requesttype) = $GLOBALS['DB']->fetch_array($result); } else { $query = "INSERT INTO `glpi_requesttypes` SET `name` = 'Formcreator';"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); $requesttype = $GLOBALS['DB']->insert_id(); } if (!TableExists($table)) { $migration->displayMessage("Installing {$table}"); // Create Forms table $query = "CREATE TABLE IF NOT EXISTS `{$table}` (\n `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,\n `entities_id` int(11) NOT NULL DEFAULT '0',\n `is_recursive` tinyint(1) NOT NULL DEFAULT '0',\n `access_rights` tinyint(1) NOT NULL DEFAULT '1',\n `requesttype` int(11) NOT NULL DEFAULT '{$requesttype}',\n `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n `description` varchar(255) COLLATE utf8_unicode_ci,\n `content` longtext COLLATE utf8_unicode_ci,\n `plugin_formcreator_categories_id` tinyint(3) UNSIGNED NOT NULL,\n `is_active` tinyint(1) NOT NULL DEFAULT '0',\n `language` varchar(5) COLLATE utf8_unicode_ci NOT NULL,\n `helpdesk_home` tinyint(1) NOT NULL DEFAULT '0',\n `is_deleted` tinyint(1) NOT NULL DEFAULT '0',\n `validation_required` tinyint(1) 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 from previous version if (FieldExists($table, 'cat', false)) { $query = "ALTER TABLE `{$table}`\n CHANGE `cat` `plugin_formcreator_categories_id` tinyint(3) UNSIGNED NOT NULL DEFAULT '0';"; $GLOBALS['DB']->query($query); } // Migration from previous version if (!FieldExists($table, 'validation_required', false)) { $query = "ALTER TABLE `{$table}`\n ADD `validation_required` tinyint(1) NOT NULL DEFAULT '0';"; $GLOBALS['DB']->query($query); } // Migration from previous version if (!FieldExists($table, 'plugin_formcreator_categories_id', false)) { $query = "ALTER TABLE `{$table}`\n ADD `plugin_formcreator_categories_id` tinyint(3) UNSIGNED NOT NULL DEFAULT '1';"; $GLOBALS['DB']->query($query); } // Migration from previous version if (!FieldExists($table, 'requesttype', false)) { $query = "ALTER TABLE `{$table}`\n ADD `access_rights` tinyint(1) NOT NULL DEFAULT '1',\n ADD `requesttype` int(11) NOT NULL DEFAULT '{$requesttype}',\n ADD `description` varchar(255) COLLATE utf8_unicode_ci,\n ADD `helpdesk_home` tinyint(1) NOT NULL DEFAULT '0',\n ADD `is_deleted` tinyint(1) NOT NULL DEFAULT '0';"; $GLOBALS['DB']->query($query); } /** * Migration of special chars from previous versions * * @since 0.85-1.2.3 */ $query = "SELECT `id`, `name`, `description`, `content`\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']) . '", `description` = "' . plugin_formcreator_encode($line['description']) . '", `content` = "' . plugin_formcreator_encode($line['content']) . '" WHERE `id` = ' . $line['id']; $GLOBALS['DB']->query($query_update) or die($GLOBALS['DB']->error()); } } if (!TableExists('glpi_plugin_formcreator_formvalidators')) { $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_formvalidators` (\n `forms_id` int(11) NOT NULL,\n `users_id` int(11) NOT NULL,\n PRIMARY KEY (`forms_id`, `users_id`)\n )\n ENGINE = MyISAM\n DEFAULT CHARACTER SET = utf8\n COLLATE = utf8_unicode_ci;"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); } // Create standard search options $query = 'DELETE FROM `glpi_displaypreferences` WHERE `itemtype` = "PluginFormcreatorForm"'; $GLOBALS['DB']->query($query) or die("error deleting glpi_displaypreferences " . $GLOBALS['DB']->error()); $query = "INSERT IGNORE INTO `glpi_displaypreferences` (`id`, `itemtype`, `num`, `rank`, `users_id`) VALUES\n (NULL, '" . __CLASS__ . "', 30, 1, 0),\n (NULL, '" . __CLASS__ . "', 3, 2, 0),\n (NULL, '" . __CLASS__ . "', 10, 3, 0),\n (NULL, '" . __CLASS__ . "', 7, 4, 0),\n (NULL, '" . __CLASS__ . "', 8, 5, 0),\n (NULL, '" . __CLASS__ . "', 9, 6, 0);"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); 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(); 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_formanwers_id` int(11) NOT NULL,\n `plugin_formcreator_question_id` int(11) NOT NULL,\n `answer` text NOT NULL\n )\n ENGINE = MyISAM\n DEFAULT CHARACTER SET = utf8\n COLLATE = utf8_unicode_ci"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); } else { // Update field type from previous version (Need answer to be text since text can be WYSIWING). $query = "ALTER TABLE `{$table}` CHANGE `answer` `answer` text;"; $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); /** * Migration of special chars from previous versions * * @since 0.85-1.2.3 */ $query = "SELECT `id`, `answer`\n FROM `{$table}`"; $result = $GLOBALS['DB']->query($query); while ($line = $GLOBALS['DB']->fetch_array($result)) { $query_update = "UPDATE `{$table}` SET\n `answer` = '" . plugin_formcreator_encode($line['answer']) . "'\n WHERE `id` = " . (int) $line['id']; $GLOBALS['DB']->query($query_update) or die($GLOBALS['DB']->error()); } } return true; }
static function install(Migration $migration) { global $DB; //Only avaiable since 1.2.0 $table = getTableForItemType(__CLASS__); if (!TableExists($table)) { $migration->displayMessage("Installing {$table}"); $query = "CREATE TABLE `glpi_plugin_order_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 `sign` 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;"; $DB->query($query) or die($DB->error()); } else { //1.5.3 $migration->changeField($table, 'ID', 'id', "int(11) NOT NULL auto_increment"); $migration->changeField($table, 'user_id', 'users_id', "INT(11) NOT NULL DEFAULT '0'"); $migration->addKey($table, 'users_id'); $migration->migrationOneTable($table); } }
public static function install(Migration $migration) { global $DB; $table = getTableForItemType(__CLASS__); if (!TableExists($table) && !TableExists("glpi_plugin_order_detail")) { $migration->displayMessage("Installing {$table}"); //install $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 '0',\n `plugin_order_orders_id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_plugin_order_orders (id)',\n `itemtype` varchar(100) collate utf8_unicode_ci NOT NULL COMMENT 'see .class.php file',\n `items_id` int(11) NOT NULL default '0' COMMENT 'RELATION to various tables, according to itemtype (id)',\n `plugin_order_references_id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_plugin_order_references (id)',\n `plugin_order_deliverystates_id` int (11) NOT NULL default '0' COMMENT 'RELATION to glpi_plugin_order_deliverystates (id)',\n `plugin_order_ordertaxes_id` float NOT NULL default '0' COMMENT 'RELATION to glpi_plugin_order_ordertaxes (id)',\n `delivery_number` varchar(255) collate utf8_unicode_ci default NULL,\n `delivery_comment` text collate utf8_unicode_ci,\n `price_taxfree` decimal(20,6) NOT NULL DEFAULT '0.000000',\n `price_discounted` decimal(20,6) NOT NULL DEFAULT '0.000000',\n `discount` decimal(20,6) NOT NULL DEFAULT '0.000000',\n `price_ati` decimal(20,6) NOT NULL DEFAULT '0.000000',\n `states_id` int(11) NOT NULL default 1,\n `delivery_date` date default NULL,\n `plugin_order_bills_id` INT( 11 ) NOT NULL DEFAULT '0',\n `plugin_order_billstates_id` INT( 11 ) NOT NULL DEFAULT '0',\n `comment` text collate utf8_unicode_ci,\n PRIMARY KEY (`id`),\n KEY `FK_device` (`items_id`,`itemtype`),\n KEY `entities_id` (`entities_id`),\n KEY `item` (`itemtype`,`items_id`),\n KEY `plugin_order_references_id` (`plugin_order_references_id`),\n KEY `plugin_order_deliverystates_id` (`plugin_order_deliverystates_id`),\n KEY `states_id` (`states_id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $DB->query($query) or die($DB->error()); } else { //Upgrade $migration->displayMessage("Upgrading {$table}"); //1.1.2 if (TableExists("glpi_plugin_order_detail")) { $migration->addField("glpi_plugin_order_detail", "delivery_status", "int(1) NOT NULL default '0'"); $migration->addField("glpi_plugin_order_detail", "delivery_comments", "TEXT"); $migration->migrationOneTable("glpi_plugin_order_detail"); } //1.2.0 $migration->renameTable("glpi_plugin_order_detail", $table); $migration->changeField($table, "ID", "id", "int(11) NOT NULL AUTO_INCREMENT"); $migration->changeField($table, "FK_order", "plugin_order_orders_id", "int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_plugin_order_orders (id)'"); $migration->changeField($table, "device_type", "itemtype", "varchar(100) collate utf8_unicode_ci NOT NULL COMMENT 'see .class.php file'"); $migration->changeField($table, "FK_device", "items_id", "int(11) NOT NULL default '0' COMMENT 'RELATION to various tables, according to itemtype (id)'"); $migration->changeField($table, "FK_reference", "plugin_order_references_id", "int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_plugin_order_references (id)'"); $migration->changeField($table, "delivery_status", "plugin_order_deliverystates_id", "int (11) NOT NULL default '0' COMMENT 'RELATION to glpi_plugin_order_deliverystates (id)'"); $migration->changeField($table, "deliverynum", "delivery_number", "varchar(255) collate utf8_unicode_ci default NULL"); $migration->changeField($table, "delivery_comments", "delivery_comment", "text collate utf8_unicode_ci"); $migration->changeField($table, "status", "states_id", "int(11) NOT NULL default 1"); $migration->changeField($table, "date", "delivery_date", "date default NULL"); $migration->addKey($table, array("items_id", "itemtype"), "FK_device"); $migration->addKey($table, array("itemtype", "items_id"), "item"); $migration->addKey($table, "plugin_order_references_id"); $migration->addKey($table, "plugin_order_deliverystates_id"); $migration->addKey($table, "states_id"); $migration->migrationOneTable($table); Plugin::migrateItemType(array(), array(), array($table)); //1.4.0 $migration->addField($table, "plugin_order_ordertaxes_id", "INT (11) NOT NULL default '0' COMMENT 'RELATION to glpi_plugin_order_ordertaxes (id)'"); $migration->migrationOneTable($table); /* Migrate VAT */ foreach ($DB->request("glpi_plugin_order_orders") as $data) { $query = "UPDATE `glpi_plugin_order_orders_items`\n SET `plugin_order_ordertaxes_id` = '" . $data["plugin_order_ordertaxes_id"] . "'\n WHERE `plugin_order_orders_id` = '" . $data["id"] . "'"; $result = $DB->query($query) or die($DB->error()); } //1.5.0 $migration->addField($table, "entities_id", "INT( 11 ) NOT NULL DEFAULT '0'"); $migration->addField($table, "is_recursive", "TINYINT( 1 ) NOT NULL DEFAULT '0'"); $migration->addField($table, "plugin_order_bills_id", "INT( 11 ) NOT NULL DEFAULT '0'"); $migration->addField($table, "plugin_order_billstates_id", "INT( 11 ) NOT NULL DEFAULT '0'"); $migration->addKey($table, "entities_id"); $migration->addKey($table, "plugin_order_bills_id"); $migration->addKey($table, "plugin_order_billstates_id"); $migration->addField($table, "comment", "text collate utf8_unicode_ci"); $migration->migrationOneTable($table); //Change format for prices : from float to decimal $migration->changeField($table, "price_taxfree", "price_taxfree", "decimal(20,6) NOT NULL DEFAULT '0.000000'"); $migration->changeField($table, "price_discounted", "price_discounted", "decimal(20,6) NOT NULL DEFAULT '0.000000'"); $migration->changeField($table, "price_ati", "price_ati", "decimal(20,6) NOT NULL DEFAULT '0.000000'"); $migration->changeField($table, "discount", "discount", "decimal(20,6) NOT NULL DEFAULT '0.000000'"); //Drop unused fields from previous migration $migration->dropField($table, "price_taxfree2"); $migration->dropField($table, "price_discounted2"); $migration->migrationOneTable($table); //Forward entities_id and is_recursive into table glpi_plugin_order_orders_items $query = "SELECT `go`.`entities_id` as entities_id ,\n `go`.`is_recursive` as is_recursive, `goi`.`id` as items_id\n FROM `glpi_plugin_order_orders` as go, `{$table}` as `goi`\n WHERE `goi`.`plugin_order_orders_id`=`go`.`id`"; foreach ($DB->request($query) as $data) { $update = "UPDATE `{$table}`\n SET `entities_id`='" . $data['entities_id'] . "'\n AND `is_recursive`='" . $data['is_recursive'] . "'\n WHERE `id`='" . $data['items_id'] . "'"; $DB->query($update) or die($DB->error()); } $migration->executeMigration(); } }