예제 #1
0
 /**
  * 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;
 }
예제 #2
0
 static function install(Migration $migration)
 {
     global $DB;
     $obj = new self();
     $table = $obj->getTable();
     if (!TableExists($table)) {
         $migration->displayMessage("Installing {$table}");
         $query = "CREATE TABLE IF NOT EXISTS `{$table}` (\n                  `id`           INT(11)        NOT NULL auto_increment,\n                  `name`         VARCHAR(255)   DEFAULT NULL,\n                  `label`        VARCHAR(255)   DEFAULT NULL,\n                  `itemtype`     VARCHAR(255)   DEFAULT NULL,\n                  `type`         VARCHAR(255)   DEFAULT NULL,\n                  `subtype`      VARCHAR(255) DEFAULT NULL,\n                  `entities_id`  INT(11)        NOT NULL DEFAULT '0',\n                  `is_recursive` TINYINT(1)     NOT NULL DEFAULT '0',\n                  `is_active`    TINYINT(1)     NOT NULL DEFAULT '0',\n                  PRIMARY KEY    (`id`),\n                  KEY            `entities_id`  (`entities_id`)\n               ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
         $DB->query($query) or die($DB->error());
     }
     //add display preferences for this class
     $d_pref = new DisplayPreference();
     $found = $d_pref->find("itemtype = '" . __CLASS__ . "'");
     if (count($found) == 0) {
         for ($i = 2; $i <= 5; $i++) {
             $DB->query("INSERT INTO glpi_displaypreferences VALUES\n               (NULL, '" . __CLASS__ . "', {$i}, " . ($i - 1) . ", 0)");
         }
     }
     if (!FieldExists($table, "subtype")) {
         $migration->addField($table, 'subtype', 'VARCHAR(255) DEFAULT NULL', array('after' => 'type'));
         $migration->migrationOneTable($table);
     }
     return true;
 }