changeField() public méthode

Modify field for migration
public changeField ( $table, $oldfield, $newfield, $type, $options = [] )
$table string
$oldfield string old name of the field
$newfield string new name of the field
$type string (see fieldFormat)
$options array - default_value new field's default value, if a specific default value needs to be used - comment comment to be added during field creation - nodefault : do not define default value (default false)
 static function install(Migration $migration)
 {
     global $DB, $GENINVENTORYNUMBER_TYPES;
     $table = getTableForItemType(__CLASS__);
     if (TableExists("glpi_plugin_geninventorynumber_fields")) {
         //Only migrate itemtypes when it's only necessary, otherwise it breaks upgrade procedure !
         $migration->renameTable("glpi_plugin_geninventorynumber_fields", $table);
     }
     if (!TableExists($table)) {
         $query = "CREATE TABLE IF NOT EXISTS `{$table}` (\n            `id` int(11) NOT NULL auto_increment,\n            `plugin_geninventorynumber_configs_id` int(11) NOT NULL default '0',\n            `itemtype` varchar(255) COLLATE utf8_unicode_ci DEFAULT '',\n            `template` varchar(255) COLLATE utf8_unicode_ci DEFAULT '',\n            `is_active` tinyint(1) NOT NULL default '0',\n            `use_index` tinyint(1) NOT NULL default '0',\n            `index` bigint(20) NOT NULL default '0',\n            PRIMARY KEY  (`id`)\n            ) ENGINE=MyISAM  CHARSET=utf8 COLLATE=utf8_unicode_ci;";
         $DB->query($query);
     } else {
         $migration->changeField($table, 'ID', 'id', 'autoincrement');
         $migration->changeField($table, 'config_id', 'plugin_geninventorynumber_configs_id', 'integer');
         if ($migration->changeField($table, 'device_type', 'itemtype', 'string')) {
             $migration->migrationOneTable($table);
             Plugin::migrateItemType(array(), array("glpi_displaypreferences"), array($table));
         }
         $migration->changeField($table, 'enabled', 'is_active', 'boolean');
         $migration->changeField($table, 'use_index', 'use_index', 'boolean');
         $migration->migrationOneTable($table);
     }
     $field = new self();
     foreach ($GENINVENTORYNUMBER_TYPES as $type) {
         if (!countElementsInTable($table, "`itemtype`='{$type}'")) {
             $input["plugin_geninventorynumber_configs_id"] = 1;
             $input["itemtype"] = $type;
             $input["template"] = "<#######>";
             $input["is_active"] = 0;
             $input["index"] = 0;
             $field->add($input);
         }
     }
 }
Exemple #2
0
 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;
     $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);
     }
 }
 /**
  * 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;
 }
Exemple #5
0
 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");
 }
Exemple #6
0
 static function install(Migration $migration)
 {
     global $DB;
     $table = getTableForItemType(__CLASS__);
     if (!TableExists($table)) {
         $query = "CREATE TABLE `{$table}` (\n                           `id` INT( 11 ) NOT NULL AUTO_INCREMENT,\n                           `entities_id` INT( 11 ) NOT NULL DEFAULT 0,\n                           `itemtype` varchar(255) collate utf8_unicode_ci default NULL,\n                           `is_active` tinyint(1) NOT NULL default '0',\n                           `name` varchar(255) collate utf8_unicode_ci default NULL,\n                           `comment` text NULL,\n                           `date_mod` datetime DEFAULT NULL,\n                           `date_creation` datetime DEFAULT NULL,\n                           `use_global_search` tinyint(1) NOT NULL default '0',\n                           `use_unicity` tinyint(1) NOT NULL default '0',\n                           `use_history` tinyint(1) NOT NULL default '0',\n                           `use_infocoms` tinyint(1) NOT NULL default '0',\n                           `use_contracts` tinyint(1) NOT NULL default '0',\n                           `use_documents` tinyint(1) NOT NULL default '0',\n                           `use_tickets` tinyint(1) NOT NULL default '0',\n                           `use_links` tinyint(1) NOT NULL default '0',\n                           `use_loans` tinyint(1) NOT NULL default '0',\n                           `use_network_ports` tinyint(1) NOT NULL default '0',\n                           `use_direct_connections` tinyint(1) NOT NULL default '0',\n                           `use_plugin_datainjection` tinyint(1) NOT NULL default '0',\n                           `use_plugin_pdf` tinyint(1) NOT NULL default '0',\n                           `use_plugin_order` tinyint(1) NOT NULL default '0',\n                           `use_plugin_uninstall` tinyint(1) NOT NULL default '0',\n                           `use_plugin_geninventorynumber` tinyint(1) NOT NULL default '0',\n                           `use_menu_entry` tinyint(1) NOT NULL default '0',\n                           `use_projects` tinyint(1) NOT NULL default '0',\n                           `linked_itemtypes` text NULL,\n                           `plugin_genericobject_typefamilies_id` INT( 11 ) NOT NULL DEFAULT 0,\n                           PRIMARY KEY ( `id` )\n                           ) ENGINE = MYISAM COMMENT = 'Object types definition table' DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
         $DB->query($query) or die($DB->error());
     }
     $migration->addField($table, "use_network_ports", "bool");
     $migration->addField($table, "use_direct_connections", "bool");
     $migration->addField($table, "use_plugin_geninventorynumber", "bool");
     $migration->addField($table, "use_contracts", "bool");
     $migration->addField($table, "use_menu_entry", "bool");
     $migration->addField($table, "use_global_search", "bool");
     $migration->addField($table, "use_projects", "bool");
     $migration->addField($table, "use_notepad", "bool");
     $migration->addField($table, "comment", "text");
     if (!$migration->addField($table, "date_mod", "datetime")) {
         $migration->changeField($table, "date_mod", "date_mod", "datetime");
     }
     $migration->addField($table, "date_creation", "datetime");
     $migration->addField($table, "linked_itemtypes", "text");
     $migration->addField($table, "plugin_genericobject_typefamilies_id", "integer");
     $migration->addField($table, "use_plugin_simcard", "bool");
     $migration->migrationOneTable($table);
     // Migrate notepad data
     $allGenericObjectTypes = PluginGenericobjectType::getTypes(true);
     $notepad = new Notepad();
     foreach ($allGenericObjectTypes as $genericObjectType => $genericObjectData) {
         $genericObjectTypeInstance = new $genericObjectType();
         if (FieldExists($genericObjectTypeInstance->getTable(), "notepad")) {
             $query = "INSERT INTO `" . $notepad->getTable() . "`\n                  (`items_id`,\n                  `itemtype`,\n                  `date`,\n                  `date_mod`,\n                  `content`\n               )\n               SELECT\n                  `id` as `items_id`,\n                  '" . $genericObjectType . "' as `itemtype`,\n                  now() as `date`,\n                  now() as `date_mod`,\n                  `notepad` as `content`\n               FROM `" . $genericObjectTypeInstance->getTable() . "`\n               WHERE notepad IS NOT NULL\n               AND notepad <> ''";
             $DB->query($query) or die($DB->error());
         }
         $query = "UPDATE`" . $notepad->getTable() . "`";
         $migration->dropField($genericObjectTypeInstance->getTable(), "notepad");
         $migration->migrationOneTable($genericObjectTypeInstance->getTable());
     }
     //Displayprefs
     $prefs = array(10 => 6, 9 => 5, 8 => 4, 7 => 3, 6 => 2, 2 => 1, 4 => 1, 11 => 7, 12 => 8, 14 => 10, 15 => 11);
     foreach ($prefs as $num => $rank) {
         if (!countElementsInTable("glpi_displaypreferences", "`itemtype`='" . __CLASS__ . "' AND `num`='{$num}'\n                                       AND `users_id`='0'")) {
             $preference = new DisplayPreference();
             $tmp['itemtype'] = __CLASS__;
             $tmp['num'] = $num;
             $tmp['rank'] = $rank;
             $tmp['users_id'] = 0;
             $preference->add($tmp);
         }
     }
     //If files are missing, recreate them!
     self::checkClassAndFilesForItemType();
 }
 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();
     }
 }
 static function install(Migration $migration)
 {
     global $DB;
     $table = getTableForItemType(__CLASS__);
     if (TableExists("glpi_plugin_generateinventorynumber_config")) {
         $fields = array('template_computer', 'template_monitor', 'template_printer', 'template_peripheral', 'template_phone', 'template_networking', 'generate_ocs', 'generate_data_injection', 'generate_internal', 'computer_gen_enabled', 'monitor_gen_enabled', 'printer_gen_enabled', 'peripheral_gen_enabled', 'phone_gen_enabled', 'networking_gen_enabled', 'computer_global_index', 'monitor_global_index', 'printer_global_index', 'peripheral_global_index', 'phone_global_index', 'networking_global_index');
         foreach ($fields as $field) {
             $migration->dropField("glpi_plugin_generateinventorynumber_config", $field);
         }
         $migration->renameTable("glpi_plugin_generateinventorynumber_config", $table);
     }
     if (TableExists("glpi_plugin_geninventorynumber_config")) {
         $migration->renameTable("glpi_plugin_geninventorynumber_config", $table);
     }
     if (!TableExists($table)) {
         $sql = "CREATE TABLE IF NOT EXISTS `{$table}` (\n      \t    `id` int(11) NOT NULL auto_increment,\n      \t    `name`  varchar(255) COLLATE utf8_unicode_ci DEFAULT '',\n      \t    `entities_id` int(11)  NOT NULL default '-1',\n      \t    `is_active` tinyint(1)  NOT NULL default 0,\n      \t    `index` int(11)  NOT NULL default 0,\n      \t    `comment` text COLLATE utf8_unicode_ci,\n      \t    PRIMARY KEY  (`id`)\n      \t    ) ENGINE=MyISAM CHARSET=utf8 COLLATE=utf8_unicode_ci;";
         $DB->query($sql) or die($DB->error());
         $tmp['id'] = 1;
         $tmp['name'] = 'otherserial';
         $tmp['is_active'] = 1;
         $tmp['entities_id'] = 0;
         $tmp['index'] = 0;
         $config = new self();
         $config->add($tmp);
     } else {
         $migration->addField($table, 'name', 'string', array('value' => 'otherserial'));
         $migration->addField($table, 'field', 'string', array('value' => 'otherserial'));
         $migration->changeField($table, 'ID', 'id', 'autoincrement');
         $migration->changeField($table, 'FK_entities', 'entities_id', 'integer', array('value' => -1));
         $migration->changeField($table, 'active', 'is_active', 'bool');
         if (!$migration->addField($table, 'comment', 'text')) {
             $migration->changeField($table, 'comments', 'comment', 'text');
         }
         $migration->changeField($table, 'is_active', 'is_active', 'bool');
         $migration->changeField($table, 'next_number', 'index', 'integer');
         $migration->dropField($table, 'field');
     }
     //Remove unused table
     if (TableExists('glpi_plugin_geninventorynumber_indexes')) {
         $migration->dropTable('glpi_plugin_geninventorynumber_indexes');
     }
     $migration->migrationOneTable($table);
 }
 static function updateSchema(Migration $migration)
 {
     $migration->displayTitle(sprintf(__('%1$s: %2$s'), __('Update'), self::getTypeName(9)));
     $table = getTableForItemType(__CLASS__);
     // Version 1.6.1
     $migration->changeField($table, 'notes', 'notepad', 'text');
     // Version 1.8.0
     $migration->addKey($table, 'users_id');
     $migration->addKey($table, 'groups_id');
     $migration->addKey($table, 'plugin_appliances_appliancetypes_id');
     $migration->addKey($table, 'plugin_appliances_environments_id');
     $migration->addField($table, 'states_id', 'integer', array('after' => 'date_mod'));
     $migration->addKey($table, 'states_id');
     $migration->addField($table, 'users_id_tech', 'integer', array('after' => 'users_id'));
     $migration->addKey($table, 'users_id_tech');
     $migration->addField($table, 'groups_id_tech', 'integer', array('after' => 'groups_id'));
     $migration->addKey($table, 'groups_id_tech');
 }
 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());
             }
         }
     }
 }
Html::header(__('Duplicate computers', 'reports'), $_SERVER['PHP_SELF'], "config", "plugins");
$types = array(1 => __('MAC'), 2 => __('IP'), 3 => __('Serial number'));
if (isset($_POST["delete"]) && isset($_POST['id'])) {
    $query = "DELETE\n             FROM `glpi_plugin_reports_doublons_backlists`\n             WHERE `id` = '" . $_POST['id'] . "'";
    $DB->query($query);
} else {
    if (isset($_POST["add"]) && isset($_POST["type"]) && isset($_POST["addr"]) && strlen($_POST["addr"])) {
        $query = "INSERT INTO `glpi_plugin_reports_doublons_backlists`\n             SET `type` = '" . $_POST["type"] . "',\n                 `addr` = '" . trim($_POST["addr"]) . "',\n                 `comment` = '" . trim($_POST["comment"]) . "'";
        $DB->query($query);
    }
}
// Initial creation
if (TableExists("glpi_plugin_reports_doublons_backlist")) {
    $migration = new Migration(160);
    $migration->renameTable("glpi_plugin_reports_doublons_backlist", "glpi_plugin_reports_doublons_backlists");
    $migration->changeField("glpi_plugin_reports_doublons_backlists", "ID", "id", 'autoincrement');
    $migration->executeMigration();
} else {
    if (!TableExists("glpi_plugin_reports_doublons_backlists")) {
        $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_reports_doublons_backlists` (\n               `id` int(11) NOT NULL AUTO_INCREMENT,\n               `type` int(11) NOT NULL DEFAULT '0',\n               `addr` varchar(255) DEFAULT NULL,\n               `comment` varchar(255) DEFAULT NULL,\n               PRIMARY KEY (`id`)\n             ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query) or die($DB->error());
        $query = "INSERT INTO`glpi_plugin_reports_doublons_backlists`\n                    (`type`, `addr`, `comment`)\n             VALUES (1, '44:45:53:54:42:00', 'Nortel IPSECSHM Adapter'),\n                    (1, 'BA:D0:BE:EF:FA:CE', 'GlobeTrotter Module 3G+ Network Card'),\n                    (1, '00:53:45:00:00:00', 'WAN (PPP/SLIP) Interface'),\n                    (1, '80:00:60:0F:E8:00', 'Windows Mobile-based'),\n                    (2, '127.0.0.1', 'loopback'),\n                    (3, 'INVALID', 'from OCSNG'),\n                    (3, 'XxXxXxX', 'from IBM')";
        $DB->query($query);
    }
}
// ---------- Form ------------
echo "<div class='center'><table class='tab_cadre' cellpadding='5'>\n";
echo "<tr class='tab_bg_1 center'><th><a href='" . GLPI_ROOT . "/plugins/reports/front/config.form.php'>" . __('Reports plugin configuration', 'reports') . "</a><br />&nbsp;<br />" . sprintf(__('%1$s: %2$s'), __('Report configuration', 'reports'), __('Duplicate computers', 'reports')) . "</th></tr>\n";
$plug = new Plugin();
if ($plug->isActivated('reports')) {
    echo "<tr class='tab_bg_1 center'><td>";
 static function install(Migration $migration)
 {
     global $DB;
     // From 0.2 to 1.0.0
     $table = 'glpi_plugin_uninstallcomputer_preference';
     if (TableExists($table)) {
         $migration->changeField($table, 'user_id', 'FK_users', "integer");
         $migration->addField($table, 'FK_template', 'integer');
         $migration->renameTable($table, getTableForItemType(__CLASS__));
     }
     $table = getTableForItemType(__CLASS__);
     // plugin already installed
     if (TableExists($table)) {
         // from 1.0.0 to 1.3.0
         if (FieldExists($table, 'ID')) {
             $migration->changeField($table, 'ID', 'id', 'autoincrement');
             $migration->changeField($table, 'FK_users', 'users_id', 'integer');
             $migration->changeField($table, 'FK_entities', 'entities_id', 'integer');
             $migration->changeField($table, 'FK_template', 'templates_id', 'integer');
             $migration->changeField($table, 'location', 'locations_id', "integer");
         }
         // plugin nevers installed
     } else {
         $query = "CREATE TABLE `" . $table . "` (\n                     `id` int(11) NOT NULL AUTO_INCREMENT,\n                     `users_id` int(11) NOT NULL,\n                     `entities_id` int(11) DEFAULT '0',\n                     `templates_id` int(11) DEFAULT '0',\n                     `locations_id` int(11) DEFAULT '0',\n                     PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
         $DB->queryOrDie($query, $DB->error());
     }
     return true;
 }
Exemple #13
0
 static function install(Migration $migration)
 {
     global $DB;
     $table = getTableForItemType(__CLASS__);
     if (!TableExists($table)) {
         $migration->displayMessage("Installing {$table}");
         $query = "CREATE TABLE `glpi_plugin_order_profiles` (\n               `id` int(11) NOT NULL auto_increment,\n               `profiles_id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_profiles (id)',\n               `order` char(1) collate utf8_unicode_ci default NULL,\n               `reference` char(1) collate utf8_unicode_ci default NULL,\n               `validation` char(1) collate utf8_unicode_ci default NULL,\n               `cancel` char(1) collate utf8_unicode_ci default NULL,\n               `undo_validation` char(1) collate utf8_unicode_ci default NULL,\n               `bill` char(1) collate utf8_unicode_ci default NULL,\n               `delivery` char(1) collate utf8_unicode_ci default NULL,\n               `generate_order_odt` char(1) collate utf8_unicode_ci default NULL,\n               `open_ticket` char(1) default NULL,\n               PRIMARY KEY  (`id`),\n               KEY `profiles_id` (`profiles_id`)\n            ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
         $DB->query($query) or die($DB->error());
         PluginOrderProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
     } else {
         $migration->displayMessage("Upgrading {$table}");
         //1.2.0
         $migration->changeField($table, "ID", "id", "int(11) NOT NULL auto_increment");
         foreach (array('order', 'reference', 'budget', 'validation', 'cancel', 'undo_validation') as $right) {
             $migration->changeField($table, $right, $right, "char(1) collate utf8_unicode_ci default NULL");
         }
         $migration->migrationOneTable($table);
         if ($migration->addField($table, "profiles_id", "int(11) NOT NULL default '0'")) {
             $migration->addKey($table, "profiles_id");
             $migration->migrationOneTable($table);
             //Migration profiles
             $DB->query("UPDATE `{$table}` SET `profiles_id`=`id`");
         }
         //1.4.0
         $migration->dropField($table, "budget");
         $migration->dropField($table, "name");
         $migration->migrationOneTable($table);
         //1.5.0
         $migration->addField($table, "bill", "char");
         $migration->migrationOneTable($table);
         self::addRightToProfile($_SESSION['glpiactiveprofile']['id'], "bill", "w");
         //1.5.3
         //Add delivery right
         if ($migration->addField($table, "delivery", "char")) {
             $migration->migrationOneTable($table);
             //Update profiles : copy order right not to change current behavior
             $update = "UPDATE `{$table}` SET `delivery`=`order`";
             $DB->query($update);
             self::addRightToProfile($_SESSION['glpiactiveprofile']['id'], "delivery", "w");
         }
         if ($migration->addField($table, "generate_order_odt", "char")) {
             $migration->migrationOneTable($table);
             //Update profiles : copy order right not to change current behavior
             $update = "UPDATE `{$table}` SET `generate_order_odt`=`order`";
             $DB->query($update);
             self::addRightToProfile($_SESSION['glpiactiveprofile']['id'], "generate_order_odt", "w");
         }
     }
     //1.7.2
     $migration->addField($table, "open_ticket", "char");
     $migration->migrationOneTable($table);
     self::addRightToProfile($_SESSION['glpiactiveprofile']['id'], "open_ticket", "w");
     self::changeProfile();
 }
 public static function install(Migration $migration)
 {
     global $DB;
     //Only avaiable since 1.3.0
     $table = getTableForItemType(__CLASS__);
     if (!TableExists("glpi_plugin_order_surveysuppliers")) {
         $migration->displayMessage("Installing {$table}");
         //Installation
         $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_order_surveysuppliers` (\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                  `answer1` int(11) NOT NULL default 0,\n                  `answer2` int(11) NOT NULL default 0,\n                  `answer3` int(11) NOT NULL default 0,\n                  `answer4` int(11) NOT NULL default 0,\n                  `answer5` int(11) NOT NULL default 0,\n                  `comment` text collate utf8_unicode_ci,\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->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, "FK_enterprise", "suppliers_id", "int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_suppliers (id)'");
         $migration->changeField($table, "comment", "comment", "text collate utf8_unicode_ci");
         $migration->addField($table, "entities_id", "int(11) NOT NULL default '0'");
         $migration->addField($table, "is_recursive", "tinyint(1) NOT NULL default '0'");
         $migration->addKey($table, "plugin_order_orders_id");
         $migration->addKey($table, "suppliers_id");
         $migration->migrationOneTable($table);
         $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_surveysuppliers` 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());
         }
     }
 }
Exemple #15
0
function plugin_datainjection_update170_20()
{
    global $DB;
    $migration = new Migration('2.0');
    $migration->changeField('glpi_plugin_datainjection_models', 'ID', 'id', 'autoincrement');
    $migration->changeField('glpi_plugin_datainjection_models', 'type', 'filetype', 'string', array('value' => 'csv'));
    $migration->addField('glpi_plugin_datainjection_models', 'step', 'integer');
    $migration->changeField('glpi_plugin_datainjection_models', 'comments', 'comment', 'text');
    $migration->changeField('glpi_plugin_datainjection_models', 'device_type', 'itemtype', 'string', array('value' => ''));
    $migration->changeField('glpi_plugin_datainjection_models', 'FK_entities', 'entities_id', 'integer');
    $migration->changeField('glpi_plugin_datainjection_models', 'private', 'is_private', 'bool');
    $migration->changeField('glpi_plugin_datainjection_models', 'FK_users', 'users_id', 'integer');
    $migration->changeField('glpi_plugin_datainjection_models', 'recursive', 'is_recursive', 'bool');
    $migration->migrationOneTable('glpi_plugin_datainjection_models');
    $query = "UPDATE `glpi_plugin_datainjection_models`\n             SET `step` = '5'";
    $DB->query($query);
    $query = "UPDATE `glpi_plugin_datainjection_models`\n             SET `filetype` = 'csv'";
    $DB->queryOrDie($query, "update filetype of glpi_plugin_datainjection_models");
    $migration->dropTable('glpi_plugin_datainjection_filetype');
    $migration->renameTable('glpi_plugin_datainjection_models_csv', 'glpi_plugin_datainjection_modelcsvs');
    $migration->changeField('glpi_plugin_datainjection_modelcsvs', 'model_id', 'models_id', 'integer');
    $migration->changeField('glpi_plugin_datainjection_modelcsvs', 'device_type', 'itemtype', 'string', array('value' => ''));
    $migration->changeField('glpi_plugin_datainjection_modelcsvs', 'header_present', 'is_header_present', 'bool', array('value' => 1));
    $migration->changeField('glpi_plugin_datainjection_mappings', 'mandatory', 'is_mandatory', 'bool');
    $migration->changeField('glpi_plugin_datainjection_mappings', 'type', 'itemtype', 'string', array('value' => ''));
    $migration->changeField('glpi_plugin_datainjection_mappings', 'model_id', 'models_id', 'integer');
    $migration->changeField('glpi_plugin_datainjection_infos', 'type', 'itemtype', 'string', array('value' => ''));
    $migration->changeField('glpi_plugin_datainjection_infos', 'model_id', 'models_id', 'integer');
    $migration->changeField('glpi_plugin_datainjection_infos', 'mandatory', 'is_mandatory', 'bool');
    $glpitables = array('glpi_plugin_datainjection_models', 'glpi_plugin_datainjection_mappings', 'glpi_plugin_datainjection_infos', 'glpi_plugin_datainjection_modelcsvs', 'glpi_plugin_datainjection_profiles');
    foreach ($glpitables as $table) {
        $migration->changeField($table, 'ID', 'id', 'autoincrement');
    }
    $migration->migrationOneTable('glpi_plugin_datainjection_mappings');
    $migration->migrationOneTable('glpi_plugin_datainjection_infos');
    $migration->migrationOneTable('glpi_plugin_datainjection_modelcsvs');
    $glpitables = array('glpi_plugin_datainjection_models', 'glpi_plugin_datainjection_mappings', 'glpi_plugin_datainjection_infos', 'glpi_plugin_datainjection_modelcsvs');
    Plugin::migrateItemType(array(), array(), $glpitables);
    $query = "UPDATE `glpi_plugin_datainjection_mappings`\n             SET `itemtype` = 'none' ,\n                 `value`='none'\n             WHERE `itemtype` = '-1'";
    $DB->queryOrDie($query, "Datainjection mappings tables : error updating not mapped fields");
    $migration->migrationOneTable('glpi_plugin_datainjection_infos');
    $query = "UPDATE `glpi_plugin_datainjection_infos`\n             SET `itemtype` = 'none', `value` = 'none'\n             WHERE `itemtype` = '-1'";
    $DB->queryOrDie($query, "Datainjection infos table : error updating not mapped fields");
    $foreignkeys = array('assign' => array(array('to' => 'users_id_assign', 'tables' => array('glpi_tickets'))), 'assign_group' => array(array('to' => 'groups_id_assign', 'tables' => array('glpi_tickets'))), 'assign_ent' => array(array('to' => 'suppliers_id_assign', 'tables' => array('glpi_tickets'))), 'auth_method' => array(array('to' => 'authtype', 'noindex' => array('glpi_users'), 'tables' => array('glpi_users'))), 'author' => array(array('to' => 'users_id', 'tables' => array('glpi_ticketfollowups', 'glpi_knowbaseitems', 'glpi_tickets'))), 'auto_update' => array(array('to' => 'autoupdatesystems_id', 'tables' => array('glpi_computers'))), 'budget' => array(array('to' => 'budgets_id', 'tables' => array('glpi_infocoms'))), 'buy_version' => array(array('to' => 'softwareversions_id_buy', 'tables' => array('glpi_softwarelicenses'))), 'category' => array(array('to' => 'ticketcategories_id', 'tables' => array('glpi_tickets')), array('to' => 'softwarecategories_id', 'tables' => array('glpi_softwares'))), 'categoryID' => array(array('to' => 'knowbaseitemcategories_id', 'tables' => array('glpi_knowbaseitems'))), 'cID' => array(array('to' => 'computers_id', 'tables' => array('glpi_computers_softwareversions'))), 'computer' => array(array('to' => 'items_id', 'tables' => array('glpi_tickets'))), 'computer_id' => array(array('to' => 'computers_id', 'tables' => array('glpi_registrykeys'))), 'contract_type' => array(array('to' => 'contracttypes_id', 'tables' => array('glpi_contracts'))), 'default_rubdoc_tracking' => array(array('to' => 'documentcategories_id_forticket', 'tables' => array('glpi_configs'), 'comments' => array('glpi_configs' => 'default category for documents added with a ticket'))), 'device_type' => array(array('to' => 'itemtype', 'tables' => array('glpi_alerts', 'glpi_contracts_items', 'glpi_documents_items', 'glpi_infocoms', 'glpi_bookmarks', 'glpi_bookmarks_users', 'glpi_links_itemtypes', 'glpi_networkports', 'glpi_reservationitems', 'glpi_tickets'))), 'domain' => array(array('to' => 'domains_id', 'tables' => array('glpi_computers', 'glpi_networkequipments', 'glpi_printers'))), 'end1' => array(array('to' => 'items_id', 'tables' => array('glpi_computers_items'), 'comments' => array('glpi_computers_items' => 'RELATION to various table, according to itemtype (ID)')), array('to' => 'networkports_id_1', 'tables' => array('glpi_networkports_networkports'))), 'end2' => array(array('to' => 'computers_id', 'tables' => array('glpi_computers_items')), array('to' => 'networkports_id_2', 'tables' => array('glpi_networkports_networkports'))), 'firmware' => array(array('to' => 'networkequipmentfirmwares_id', 'tables' => array('glpi_networkequipments'))), 'FK_bookmark' => array(array('to' => 'bookmarks_id', 'tables' => array('glpi_bookmarks_users'))), 'FK_computers' => array(array('to' => 'computers_id', 'tables' => array('glpi_computerdisks', 'glpi_softwarelicenses'))), 'FK_contact' => array(array('to' => 'contacts_id', 'tables' => array('glpi_contacts_suppliers'))), 'FK_contract' => array(array('to' => 'contracts_id', 'tables' => array('glpi_contracts_suppliers', 'glpi_contracts_items'))), 'FK_device' => array(array('to' => 'items_id', 'tables' => array('glpi_alerts', 'glpi_contracts_items', 'glpi_documents_items', 'glpi_infocoms'))), 'FK_doc' => array(array('to' => 'documents_id', 'tables' => array('glpi_documents_items'))), 'manufacturer' => array(array('to' => 'suppliers_id', 'tables' => array('glpi_contacts_suppliers', 'glpi_contracts_suppliers', 'glpi_infocoms')), array('to' => 'manufacturers_id', 'tables' => array('glpi_cartridgeitems', 'glpi_computers', 'glpi_consumableitems', 'glpi_devicecases', 'glpi_devicecontrols', 'glpi_devicedrives', 'glpi_devicegraphiccards', 'glpi_deviceharddrives', 'glpi_devicenetworkcards', 'glpi_devicemotherboards', 'glpi_devicepcis', 'glpi_devicepowersupplies', 'glpi_deviceprocessors', 'glpi_devicememories', 'glpi_devicesoundcards', 'glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_softwares'))), 'FK_entities' => array(array('to' => 'entities_id', 'tables' => array('glpi_bookmarks', 'glpi_cartridgeitems', 'glpi_computers', 'glpi_consumableitems', 'glpi_contacts', 'glpi_contracts', 'glpi_documents', 'glpi_locations', 'glpi_netpoints', 'glpi_suppliers', 'glpi_entitydatas', 'glpi_groups', 'glpi_knowbaseitems', 'glpi_links', 'glpi_mailcollectors', 'glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_reminders', 'glpi_rules', 'glpi_softwares', 'glpi_softwarelicenses', 'glpi_softwareversions', 'glpi_tickets', 'glpi_users', 'glpi_profiles_users'), 'default' => array('glpi_bookmarks' => "-1"))), 'FK_filesystems' => array(array('to' => 'filesystems_id', 'tables' => array('glpi_computerdisks'))), 'FK_glpi_cartridges_type' => array(array('to' => 'cartridgeitems_id', 'tables' => array('glpi_cartridges', 'glpi_cartridges_printermodels'))), 'FK_glpi_consumables_type' => array(array('to' => 'consumableitems_id', 'tables' => array('glpi_consumables'))), 'FK_glpi_dropdown_model_printers' => array(array('to' => 'printermodels_id', 'tables' => array('glpi_cartridges_printermodels'))), 'FK_glpi_printers' => array(array('to' => 'printers_id', 'tables' => array('glpi_cartridges'))), 'FK_group' => array(array('to' => 'groups_id', 'tables' => array('glpi_tickets'))), 'FK_groups' => array(array('to' => 'groups_id', 'tables' => array('glpi_computers', 'glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_softwares', 'glpi_groups_users'))), 'FK_interface' => array(array('to' => 'interfacetypes_id', 'tables' => array('glpi_devicegraphiccards'))), 'FK_item' => array(array('to' => 'items_id', 'tables' => array('glpi_mailingsettings'))), 'FK_links' => array(array('to' => 'links_id', 'tables' => array('glpi_links_itemtypes'))), 'FK_port' => array(array('to' => 'networkports_id', 'tables' => array('glpi_networkports_vlans'))), 'FK_profiles' => array(array('to' => 'profiles_id', 'tables' => array('glpi_profiles_users', 'glpi_users'))), 'FK_users' => array(array('to' => 'users_id', 'tables' => array('glpi_bookmarks', 'glpi_displaypreferences', 'glpi_documents', 'glpi_groups', 'glpi_reminders', 'glpi_bookmarks_users', 'glpi_groups_users', 'glpi_profiles_users', 'glpi_computers', 'glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_softwares'))), 'FK_vlan' => array(array('to' => 'vlans_id', 'tables' => array('glpi_networkports_vlans'))), 'glpi_id' => array(array('to' => 'computers_id', 'tables' => array('glpi_ocslinks'))), 'id_assign' => array(array('to' => 'users_id', 'tables' => array('glpi_ticketplannings'))), 'id_auth' => array(array('to' => 'auths_id', 'tables' => array('glpi_users'))), 'id_device' => array(array('to' => 'items_id', 'tables' => array('glpi_reservationitems'))), 'id_item' => array(array('to' => 'reservationitems_id', 'tables' => array('glpi_reservations'))), 'id_user' => array(array('to' => 'users_id', 'tables' => array('glpi_consumables', 'glpi_reservations'))), 'iface' => array(array('to' => 'networkinterfaces_id', 'tables' => array('glpi_networkports'))), 'interface' => array(array('to' => 'interfacetypes_id', 'tables' => array('glpi_devicecontrols', 'glpi_deviceharddrives', 'glpi_devicedrives'))), 'location' => array(array('to' => 'locations_id', 'tables' => array('glpi_cartridgeitems', 'glpi_computers', 'glpi_consumableitems', 'glpi_netpoints', 'glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_users', 'glpi_softwares'))), 'model' => array(array('to' => 'computermodels_id', 'tables' => array('glpi_computers')), array('to' => 'monitormodels_id', 'tables' => array('glpi_monitors')), array('to' => 'networkequipmentmodels_id', 'tables' => array('glpi_networkequipments')), array('to' => 'peripheralmodels_id', 'tables' => array('glpi_peripherals')), array('to' => 'phonemodels_id', 'tables' => array('glpi_phones')), array('to' => 'printermodels_id', 'tables' => array('glpi_printers'))), 'netpoint' => array(array('to' => 'netpoints_id', 'tables' => array('glpi_networkports'))), 'network' => array(array('to' => 'networks_id', 'tables' => array('glpi_computers', 'glpi_networkequipments', 'glpi_printers'))), 'on_device' => array(array('to' => 'items_id', 'tables' => array('glpi_networkports'))), 'os' => array(array('to' => 'operatingsystems_id', 'tables' => array('glpi_computers'))), 'os_license_id' => array(array('to' => 'os_licenseid', 'tables' => array('glpi_computers'))), 'os_version' => array(array('to' => 'operatingsystemversions_id', 'tables' => array('glpi_computers'))), 'parentID' => array(array('to' => 'knowbaseitemcategories_id', 'tables' => array('glpi_knowbaseitemcategories')), array('to' => 'locations_id', 'tables' => array('glpi_locations')), array('to' => 'ticketcategories_id', 'tables' => array('glpi_ticketcategories')), array('to' => 'entities_id', 'tables' => array('glpi_entities'))), 'platform' => array(array('to' => 'operatingsystems_id', 'tables' => array('glpi_softwares'))), 'power' => array(array('to' => 'phonepowersupplies_id', 'tables' => array('glpi_phones'))), 'recipient' => array(array('to' => 'users_id_recipient', 'tables' => array('glpi_tickets'))), 'rubrique' => array(array('to' => 'documentcategories_id', 'tables' => array('glpi_documents'))), 'sID' => array(array('to' => 'softwares_id', 'tables' => array('glpi_softwarelicenses', 'glpi_softwareversions'))), 'state' => array(array('to' => 'states_id', 'tables' => array('glpi_computers', 'glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_softwareversions'))), 'tech_num' => array(array('to' => 'users_id_tech', 'tables' => array('glpi_cartridgeitems', 'glpi_computers', 'glpi_consumableitems', 'glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_softwares'))), 'title' => array(array('to' => 'usertitles_id', 'tables' => array('glpi_users'))), 'type' => array(array('to' => 'cartridgeitemtypes_id', 'tables' => array('glpi_cartridgeitems')), array('to' => 'computertypes_id', 'tables' => array('glpi_computers')), array('to' => 'consumableitemtypes_id', 'tables' => array('glpi_consumableitems')), array('to' => 'contacttypes_id', 'tables' => array('glpi_contacts')), array('to' => 'devicecasetypes_id', 'tables' => array('glpi_devicecases')), array('to' => 'devicememorytypes_id', 'tables' => array('glpi_devicememories')), array('to' => 'suppliertypes_id', 'tables' => array('glpi_suppliers')), array('to' => 'monitortypes_id', 'tables' => array('glpi_monitors')), array('to' => 'networkequipmenttypes_id', 'tables' => array('glpi_networkequipments')), array('to' => 'peripheraltypes_id', 'tables' => array('glpi_peripherals')), array('to' => 'phonetypes_id', 'tables' => array('glpi_phones')), array('to' => 'printertypes_id', 'tables' => array('glpi_printers')), array('to' => 'softwarelicensetypes_id', 'tables' => array('glpi_softwarelicenses')), array('to' => 'usercategories_id', 'tables' => array('glpi_users')), array('to' => 'itemtype', 'tables' => array('glpi_computers_items', 'glpi_displaypreferences'))), 'update_software' => array(array('to' => 'softwares_id', 'tables' => array('glpi_softwares'))), 'use_version' => array(array('to' => 'softwareversions_id_use', 'tables' => array('glpi_softwarelicenses'))), 'vID' => array(array('to' => 'softwareversions_id', 'tables' => array('glpi_computers_softwareversions'))), 'conpta_num' => array(array('to' => 'accounting_number', 'tables' => array('glpi_contracts'))), 'num_commande' => array(array('to' => 'order_number', 'tables' => array('glpi_infocoms'))), 'bon_livraison' => array(array('to' => 'delivery_number', 'tables' => array('glpi_infocoms'))), 'num_immo' => array(array('to' => 'immo_number', 'tables' => array('glpi_infocoms'))), 'facture' => array(array('to' => 'bill', 'tables' => array('glpi_infocoms'))), 'amort_time' => array(array('to' => 'sink_time', 'tables' => array('glpi_infocoms'))), 'amort_type' => array(array('to' => 'sink_type', 'tables' => array('glpi_infocoms'))), 'ifmac' => array(array('to' => 'mac', 'tables' => array('glpi_networkequipments'))), 'ifaddr' => array(array('to' => 'ip', 'tables' => array('glpi_networkequipments', 'glpi_networkports'))), 'ramSize' => array(array('to' => 'memory_size', 'tables' => array('glpi_printers'))), 'ramSize' => array(array('to' => 'memory_size', 'tables' => array('glpi_printers'))), 'facturation' => array(array('to' => 'billing', 'tables' => array('glpi_contracts'))), 'monday' => array(array('to' => 'use_monday', 'tables' => array('glpi_contracts'))), 'saturday' => array(array('to' => 'use_saturday', 'tables' => array('glpi_contracts'))), 'recursive' => array(array('to' => 'is_recursive', 'tables' => array('glpi_networkequipments', 'glpi_groups', 'glpi_contracts', 'glpi_contacts', 'glpi_suppliers', 'glpi_printers', 'glpi_softwares', 'glpi_softwareversions', 'glpi_softwarelicences'))), 'faq' => array(array('to' => 'is_faq', 'tables' => array('glpi_knowbaseitems'))), 'flags_micro' => array(array('to' => 'have_micro', 'tables' => array('glpi_monitors'))), 'flags_speaker' => array(array('to' => 'have_speaker', 'tables' => array('glpi_monitors'))), 'flags_subd' => array(array('to' => 'have_subd', 'tables' => array('glpi_monitors'))), 'flags_bnc' => array(array('to' => 'have_bnc', 'tables' => array('glpi_monitors'))), 'flags_dvi' => array(array('to' => 'have_dvi', 'tables' => array('glpi_monitors'))), 'flags_pivot' => array(array('to' => 'have_pivot', 'tables' => array('glpi_monitors'))), 'flags_hp' => array(array('to' => 'have_hp', 'tables' => array('glpi_phones'))), 'flags_casque' => array(array('to' => 'have_headset', 'tables' => array('glpi_phones'))), 'flags_usb' => array(array('to' => 'have_usb', 'tables' => array('glpi_printers'))), 'flags_par' => array(array('to' => 'have_parallel', 'tables' => array('glpi_printers'))), 'flags_serial' => array(array('to' => 'have_serial', 'tables' => array('glpi_printers'))), 'initial_pages' => array(array('to' => 'init_pages_counter', 'tables' => array('glpi_printers'))), 'global' => array(array('to' => 'is_global', 'tables' => array('glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_softwares'))), 'template' => array(array('to' => 'template_name', 'tables' => array('glpi_cartridgeitems', 'glpi_computers', 'glpi_consumableitems', 'glpi_devicecases', 'glpi_devicecontrols', 'glpi_devicedrives', 'glpi_devicegraphiccards', 'glpi_deviceharddrives', 'glpi_devicenetworkcards', 'glpi_devicemotherboards', 'glpi_devicepcis', 'glpi_devicepowersupplies', 'glpi_deviceprocessors', 'glpi_devicememories', 'glpi_devicesoundcards', 'glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_softwares'))), 'comments' => array(array('to' => 'comment', 'tables' => array('glpi_cartridgeitems', 'glpi_computers', 'glpi_consumableitems', 'glpi_contacts', 'glpi_contracts', 'glpi_documents', 'glpi_autoupdatesystems', 'glpi_budgets', 'glpi_cartridgeitemtypes', 'glpi_devicecasetypes', 'glpi_consumableitemtypes', 'glpi_contacttypes', 'glpi_contracttypes', 'glpi_domains', 'glpi_suppliertypes', 'glpi_filesystems', 'glpi_networkequipmentfirmwares', 'glpi_networkinterfaces', 'glpi_interfacetypes', 'glpi_knowbaseitemcategories', 'glpi_softwarelicensetypes', 'glpi_locations', 'glpi_manufacturers', 'glpi_computermodels', 'glpi_monitormodels', 'glpi_networkequipmentmodels', 'glpi_peripheralmodels', 'glpi_phonemodels', 'glpi_printermodels', 'glpi_netpoints', 'glpi_networks', 'glpi_operatingsystems', 'glpi_operatingsystemservicepacks', 'glpi_operatingsystemversions', 'glpi_phonepowersupplies', 'glpi_devicememorytypes', 'glpi_documentcategories', 'glpi_softwarecategories', 'glpi_states', 'glpi_ticketcategories', 'glpi_usertitles', 'glpi_usercategories', 'glpi_vlans', 'glpi_suppliers', 'glpi_entities', 'glpi_groups', 'glpi_infocoms', 'glpi_monitors', 'glpi_phones', 'glpi_printers', 'glpi_peripherals', 'glpi_networkequipments', 'glpi_reservationitems', 'glpi_rules', 'glpi_softwares', 'glpi_softwarelicenses', 'glpi_softwareversions', 'glpi_computertypes', 'glpi_monitortypes', 'glpi_networkequipmenttypes', 'glpi_peripheraltypes', 'glpi_phonetypes', 'glpi_printertypes', 'glpi_users'))), 'notes' => array(array('to' => 'notepad', 'tables' => array('glpi_cartridgeitems', 'glpi_computers', 'glpi_consumableitems', 'glpi_contacts', 'glpi_contracts', 'glpi_documents', 'glpi_suppliers', 'glpi_entitydatas', 'glpi_printers', 'glpi_monitors', 'glpi_phones', 'glpi_peripherals', 'glpi_networkequipments', 'glpi_softwares'))));
    $foreignkeys = Plugin::doHookFunction("plugin_datainjection_migratefields", $foreignkeys);
    $query = "SELECT `itemtype`, `value`\n              FROM `glpi_plugin_datainjection_mappings`\n              WHERE `itemtype` NOT IN ('none')\n              GROUP BY `itemtype`,`value`";
    foreach ($DB->request($query) as $data) {
        if (isset($foreignkeys[$data['value']])) {
            foreach ($foreignkeys[$data['value']] as $field_info) {
                $table = getTableForItemType($data['itemtype']);
                if (in_array($table, $field_info['tables'])) {
                    $query = "UPDATE `glpi_plugin_datainjection_mappings`\n                          SET `value` = '" . $field_info['to'] . "'\n                          WHERE `itemtype` = '" . $data['itemtype'] . "'\n                                AND `value` = '" . $data['value'] . "'";
                    $DB->queryOrDie($query, "Datainjection : error converting mapping fields");
                    $query = "UPDATE `glpi_plugin_datainjection_infos`\n                          SET `value` = '" . $field_info['to'] . "'\n                          WHERE `itemtype` = '" . $data['itemtype'] . "'\n                                AND `value` = '" . $data['value'] . "'";
                    $DB->queryOrDie($query, "Datainjection : error converting infos fields");
                }
            }
        }
    }
}
Exemple #16
0
function plugin_archires_updateTo210()
{
    $migration = new Migration(210);
    $migration->changeField("glpi_plugin_archires_appliancequeries", "appliances_id", "plugin_appliances_appliances_id", 'integer', array('comment' => 'RELATION to glpi_plugin_appliances (id)'));
    $migration->executeMigration();
}
Exemple #17
0
 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);
         }
     }
 }
Exemple #18
0
function plugin_pdf_install()
{
    global $DB;
    $migration = new Migration('0.84');
    if (!TableExists('glpi_plugin_pdf_profiles')) {
        $query = "CREATE TABLE IF NOT EXISTS\n               `glpi_plugin_pdf_profiles` (\n                  `id` int(11) NOT NULL,\n                  `profile` varchar(255) default NULL,\n                  `use` tinyint(1) default 0,\n                  PRIMARY KEY (`id`)\n               ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->queryOrDir($query, $DB->error());
    } else {
        if (FieldExists('glpi_plugin_pdf_profiles', 'ID')) {
            //< 0.7.0
            $migration->changeField('glpi_plugin_pdf_profiles', 'ID', 'id', 'autoincrement');
        }
    }
    if (!TableExists('glpi_plugin_pdf_preference')) {
        $query = "CREATE TABLE IF NOT EXISTS\n               `glpi_plugin_pdf_preferences` (\n                  `id` int(11) NOT NULL AUTO_INCREMENT,\n                  `users_id` int(11) NOT NULL COMMENT 'RELATION to glpi_users (id)',\n                  `itemtype` VARCHAR(100) NOT NULL COMMENT 'see define.php *_TYPE constant',\n                  `tabref` varchar(255) NOT NULL COMMENT 'ref of tab to display, or plugname_#, or option name',\n                  PRIMARY KEY (`id`)\n               ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query) or die($DB->error());
    } else {
        $migration->renameTable('glpi_plugin_pdf_preference', 'glpi_plugin_pdf_preferences');
        // 0.6.0
        if (FieldExists('glpi_plugin_pdf_preferences', 'user_id')) {
            $migration->changeField('glpi_plugin_pdf_preferences', 'user_id', 'users_id', 'integer', array('comment' => 'RELATION to glpi_users (id)'));
        }
        // 0.6.1
        if (FieldExists('glpi_plugin_pdf_preferences', 'FK_users')) {
            $migration->changeField('glpi_plugin_pdf_preferences', 'FK_users', 'users_id', 'integer', array('comment' => 'RELATION to glpi_users (id)'));
        }
        // 0.6.0
        if (FieldExists('glpi_plugin_pdf_preferences', 'cat')) {
            $migration->changeField('glpi_plugin_pdf_preferences', 'cat', 'itemtype', 'VARCHAR(100) NOT NULL', array('comment' => 'see define.php *_TYPE constant'));
        }
        // 0.6.1
        if (FieldExists('glpi_plugin_pdf_preferences', 'device_type')) {
            $migration->changeField('glpi_plugin_pdf_preferences', 'device_type', 'itemtype', 'VARCHAR(100) NOT NULL', array('comment' => 'see define.php *_TYPE constant'));
        }
        // 0.6.0
        if (FieldExists('glpi_plugin_pdf_preferences', 'table_num')) {
            $migration->changeField('glpi_plugin_pdf_preferences', 'table_num', 'tabref', 'string', array('comment' => 'ref of tab to display, or plugname_#, or option name'));
        }
        $migration->executeMigration();
    }
    // Give right to current Profile
    include_once GLPI_ROOT . '/plugins/pdf/inc/profile.class.php';
    $prof = new PluginPdfProfile();
    if (!$prof->getFromDB($_SESSION['glpiactiveprofile']['id'])) {
        $prof->add(array('id' => $_SESSION['glpiactiveprofile']['id'], 'profile' => $_SESSION['glpiactiveprofile']['name'], 'use' => 1));
    }
    return true;
}
 static function install(Migration $migration)
 {
     global $DB;
     $table = 'glpi_plugin_webservices_clients';
     $migration->renameTable('glpi_plugin_webservices', $table);
     if (TableExists('glpi_plugin_webservices_clients')) {
         $migration->changeField($table, 'ID', 'id', 'autoincrement');
         $migration->changeField($table, 'FK_entities', 'entities_id', 'integer');
         $migration->changeField($table, 'recursive', 'is_recursive', 'bool');
         $migration->changeField($table, 'active', 'is_active', 'bool');
         $migration->changeField($table, 'comments', 'comment', 'text');
         $migration->changeField($table, 'FK_entities', 'entities_id', 'integer');
         $migration->addField($table, 'deflate', 'bool', array('after' => 'is_active'));
         $migration->addField($table, 'debug', 'bool', array('after' => 'do_log'));
         $migration->addKey($table, 'entities_id');
         // Version 1.3.0
         $opt = array('after' => 'ip_end', 'update' => "'::1'", 'condition' => "WHERE `ip_start`=INET_ATON('127.0.0.1')");
         $migration->addField($table, 'ipv6', 'string', $opt);
     } else {
         $sql = "CREATE TABLE `glpi_plugin_webservices_clients` (\n                  `id` INT NOT NULL AUTO_INCREMENT,\n                  `entities_id` INT NOT NULL DEFAULT '0',\n                  `is_recursive` TINYINT( 1 ) NOT NULL DEFAULT '0',\n                  `name` VARCHAR( 255 ) NOT NULL ,\n                  `pattern` VARCHAR( 255 ) NOT NULL ,\n                  `ip_start` BIGINT NULL ,\n                  `ip_end` BIGINT NULL ,\n                  `ipv6`  VARCHAR( 255 ) NULL,\n                  `username` VARCHAR( 255 ) NULL ,\n                  `password` VARCHAR( 255 ) NULL ,\n                  `do_log` TINYINT NOT NULL DEFAULT '0',\n                  `debug` TINYINT NOT NULL DEFAULT '0',\n                  `is_active` TINYINT NOT NULL DEFAULT '0',\n                  `deflate` TINYINT NOT NULL DEFAULT '0',\n                  `comment` TEXT NULL ,\n                  PRIMARY KEY (`id`),\n                  KEY `entities_id` (`entities_id`)\n                ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_unicode_ci ";
         $DB->queryOrDie($sql, "SQL Error");
         $sql = "INSERT INTO\n                 `glpi_plugin_webservices_clients` (`id`, `entities_id`, `is_recursive`, `name`,\n                                                    `pattern`, `ip_start`, `ip_end` , `ipv6`,\n                                                    `do_log`, `is_active`, `comment`)\n                 VALUES (NULL, 0, 1, '" . __('Local', 'webservices') . "',\n                         '.*', INET_ATON('127.0.0.1'), INET_ATON('127.0.0.1'), '::1',\n                         1, 1, '" . __('Allow all from local', 'webservices') . "')";
         $DB->query($sql);
     }
 }
 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());
         }
     }
 }
Exemple #21
0
 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);
 }
 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);
     }
 }
Exemple #23
0
 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'");
     }
 }
Exemple #24
0
function plugin_ocsinventoryng_upgrademassocsimport13to14()
{
    global $DB;
    $migration = new Migration(14);
    $migration->renameTable("glpi_plugin_massocsimport", "glpi_plugin_massocsimport_threads");
    $migration->changeField("glpi_plugin_massocsimport_threads", "ID", "id", 'autoincrement');
    $migration->changeField("glpi_plugin_massocsimport_threads", "thread_id", "threadid", 'integer');
    $migration->changeField("glpi_plugin_massocsimport_threads", "status", "status", 'integer');
    $migration->changeField("glpi_plugin_massocsimport_threads", "ocs_server_id", "ocsservers_id", 'integer', array('value' => 1));
    $migration->changeField("glpi_plugin_massocsimport_threads", "process_id", "processid", 'integer');
    $migration->changeField("glpi_plugin_massocsimport_threads", "noupdate_machines_number", "notupdated_machines_number", 'integer');
    $migration->migrationOneTable("glpi_plugin_massocsimport_threads");
    $migration->addKey("glpi_plugin_massocsimport_threads", array("processid", "threadid"), "process_thread");
    $migration->renameTable("glpi_plugin_massocsimport_config", "glpi_plugin_massocsimport_configs");
    $migration->dropField("glpi_plugin_massocsimport_configs", "delete_frequency");
    $migration->dropField("glpi_plugin_massocsimport_configs", "enable_logging");
    $migration->dropField("glpi_plugin_massocsimport_configs", "delete_empty_frequency");
    $migration->dropField("glpi_plugin_massocsimport_configs", "warn_if_not_imported");
    $migration->dropField("glpi_plugin_massocsimport_configs", "not_imported_threshold");
    $migration->changeField("glpi_plugin_massocsimport_configs", "ID", "id", 'autoincrement');
    $migration->changeField("glpi_plugin_massocsimport_configs", "thread_log_frequency", "thread_log_frequency", 'integer', array('value' => 10));
    $migration->changeField("glpi_plugin_massocsimport_configs", "display_empty", "is_displayempty", 'int(1) NOT NULL default 1');
    $migration->changeField("glpi_plugin_massocsimport_configs", "default_ocs_server", "ocsservers_id", 'integer', array('value' => -1));
    $migration->changeField("glpi_plugin_massocsimport_configs", "delay_refresh", "delay_refresh", 'integer');
    $migration->changeField("glpi_plugin_massocsimport_configs", "comments", "comment", 'text');
    $migration->changeField("glpi_plugin_massocsimport_details", "ID", "id", 'autoincrement');
    $migration->changeField("glpi_plugin_massocsimport_details", "process_id", "plugin_massocsimport_threads_id", 'integer');
    $migration->changeField("glpi_plugin_massocsimport_details", "thread_id", "threadid", 'integer');
    $migration->changeField("glpi_plugin_massocsimport_details", "ocs_id", "ocsid", 'integer');
    $migration->changeField("glpi_plugin_massocsimport_details", "glpi_id", "computers_id", 'integer');
    $migration->changeField("glpi_plugin_massocsimport_details", "ocs_server_id", "ocsservers_id", 'integer', array('value' => 1));
    $migration->migrationOneTable('glpi_plugin_massocsimport_details');
    $migration->addKey("glpi_plugin_massocsimport_details", array("plugin_massocsimport_threads_id", "threadid"), "process_thread");
    $migration->renameTable("glpi_plugin_massocsimport_not_imported", "glpi_plugin_massocsimport_notimported");
    $migration->changeField("glpi_plugin_massocsimport_notimported", "ID", "id", 'autoincrement');
    $migration->changeField("glpi_plugin_massocsimport_notimported", "ocs_id", "ocsid", 'integer');
    $migration->changeField("glpi_plugin_massocsimport_notimported", "ocs_server_id", "ocsservers_id", 'integer');
    $migration->changeField("glpi_plugin_massocsimport_notimported", "deviceid", "ocs_deviceid", 'string');
    $migration->changeField("glpi_plugin_massocsimport_servers", "ID", "id", 'autoincrement');
    $migration->changeField("glpi_plugin_massocsimport_servers", "ocs_server_id", "ocsservers_id", 'integer');
    $migration->changeField("glpi_plugin_massocsimport_servers", "max_ocs_id", "max_ocsid", 'int(11) DEFAULT NULL');
    $migration->changeField("glpi_plugin_massocsimport_servers", "max_glpi_date", "max_glpidate", 'datetime DEFAULT NULL');
    $migration->executeMigration();
}