Migration::migrationOneTable PHP Method

migrationOneTable() public method

Execute migration for only one table
public migrationOneTable ( $table )
$table string
    function migrationOneTable($table)
    {
        global $DB;
        if (isset($this->change[$table])) {
            $query = "ALTER TABLE `{$table}` " . implode($this->change[$table], " ,\n") . " ";
            $this->displayMessage(sprintf(__('Change of the database layout - %s'), $table));
            $DB->queryOrDie($query, $this->version . " multiple alter in {$table}");
            unset($this->change[$table]);
        }
    }

Usage Example

 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);
         }
     }
 }
All Usage Examples Of Migration::migrationOneTable