本文整理汇总了PHP中Migration::changeField方法的典型用法代码示例。如果您正苦于以下问题:PHP Migration::changeField方法的具体用法?PHP Migration::changeField怎么用?PHP Migration::changeField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Migration
的用法示例。
在下文中一共展示了Migration::changeField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: install
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);
}
}
}
示例2: install
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());
}
}
}
}
示例3: install
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);
}
}
示例4: install
/**
* 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;
}
示例5: install
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");
}
示例6: install
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();
}
示例7: install
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();
}
}
示例8: install
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);
}
示例9: updateSchema
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');
}
示例10: install
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());
}
}
}
}
示例11: array
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 /> <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>";
示例12: install
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;
}
示例13: install
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();
}
示例14: install
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());
}
}
}
示例15: plugin_archires_updateTo210
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();
}