Example #1
0
/**
 * Update from 0.85.3 to 0.85.5
 *
 * @return bool for success (will die for most error)
**/
function update0853to0855()
{
    global $DB, $migration;
    $updateresult = true;
    $ADDTODISPLAYPREF = array();
    //TRANS: %s is the number of new version
    $migration->displayTitle(sprintf(__('Update to %s'), '0.85.5'));
    $migration->setVersion('0.85.5');
    $backup_tables = false;
    $newtables = array();
    foreach ($newtables as $new_table) {
        // rename new tables if exists ?
        if (TableExists($new_table)) {
            $migration->dropTable("backup_{$new_table}");
            $migration->displayWarning("{$new_table} table already exists. " . "A backup have been done to backup_{$new_table}.");
            $backup_tables = true;
            $query = $migration->renameTable("{$new_table}", "backup_{$new_table}");
        }
    }
    if ($backup_tables) {
        $migration->displayWarning("You can delete backup tables if you have no need of them.", true);
    }
    $migration->addField("glpi_entities", 'inquest_duration', "integer", array('value' => 0));
    $migration->addKey('glpi_users', 'begin_date', 'begin_date');
    $migration->addKey('glpi_users', 'end_date', 'end_date');
    $migration->addKey('glpi_knowbaseitems', 'begin_date', 'begin_date');
    $migration->addKey('glpi_knowbaseitems', 'end_date', 'end_date');
    // must always be at the end
    $migration->executeMigration();
    return $updateresult;
}
Example #2
0
function plugin_vip_install()
{
    global $DB;
    $migration = new Migration(100);
    // Création de la table uniquement lors de la première installation
    if (!TableExists("glpi_plugin_vip_profiles")) {
        // Table des droits du profil
        $query = "CREATE TABLE `glpi_plugin_vip_profiles` (\n\t               `id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_profiles (id)',\n\t               `show_vip_tab` tinyint(1) collate utf8_unicode_ci default NULL,\n\t               PRIMARY KEY  (`id`)\n\t             ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query) or die("Error creating Vip Profiles table" . $DB->error());
        $migration->executeMigration();
        //creation du premier accès nécessaire lors de l'installation du plugin
        include_once GLPI_ROOT . "/plugins/vip/inc/profile.class.php";
        PluginVipProfile::createAdminAccess($_SESSION['glpiactiveprofile']['id']);
    }
    if (!TableExists("glpi_plugin_vip_groups")) {
        //
        $query = "CREATE TABLE `glpi_plugin_vip_groups` (\n                  `id` int(11) NOT NULL default 0 COMMENT 'RELATION to glpi_groups(id)',\n                  `isvip` tinyint(1) default '0',\n                  PRIMARY KEY (`id`)\n                ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query) or die("Erreur lors de la création de la table des groupes vip " . $DB->error());
        $query = "INSERT INTO `glpi_plugin_vip_groups`\n                  (`id`, `isvip`)\n                  VALUES ('0', '0')";
        $DB->query($query) or die("Erreur lors de l'insertion des valeurs par défaut dans la table des groupes vip " . $DB->error());
    }
    if (!TableExists("glpi_plugin_vip_tickets")) {
        $query = "CREATE TABLE glpi_plugin_vip_tickets (\n\t\t\t\t  id int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_tickets (id)',\n\t\t\t\t  isvip tinyint(1) default '0',\n\t\t\t\t  PRIMARY KEY (`id`)\n\t\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query) or die("Error creating Vip Tickets table");
    }
    $query = "INSERT INTO glpi_plugin_vip_tickets\n\t\t\t\t   SELECT id, '0'\n\t\t\t\t\t FROM glpi_tickets\n\t\t ON DUPLICATE KEY\n\t\t\t\t   UPDATE isvip = '0'";
    $DB->query($query) or die("Error inserting ticket in Vip Tickets table");
    $migration->executeMigration();
    return true;
}
 public static function install(Migration $migration)
 {
     $table = getTableForItemType(__CLASS__);
     if (!TableExists($table)) {
         $query = "CREATE TABLE IF NOT EXISTS `{$table}` (\n                     `id` int(11) NOT NULL auto_increment,\n                     `name` varchar(255) NOT NULL DEFAULT '',\n                     `comment` text collate utf8_unicode_ci,\n                     PRIMARY KEY (`id`),\n                     KEY `name` (`name`)\n                  ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
         $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error());
     }
     // Migration from previous version
     if (TableExists('glpi_plugin_formcreator_cats')) {
         $query = "INSERT IGNORE INTO `{$table}` (`id`, `name`)\n                     SELECT `id`,`name` FROM glpi_plugin_formcreator_cats";
         $GLOBALS['DB']->query($query);
         $GLOBALS['DB']->query("DROP TABLE glpi_plugin_formcreator_cats");
     }
     /**
      * Migration of special chars from previous versions
      *
      * @since 0.85-1.2.3
      */
     $query = "SELECT `id`, `name`, `comment`\n                 FROM `{$table}`";
     $result = $GLOBALS['DB']->query($query);
     while ($line = $GLOBALS['DB']->fetch_array($result)) {
         $query_update = "UPDATE `{$table}` SET\n                            `name`    = '" . plugin_formcreator_encode($line['name']) . "',\n                            `comment` = '" . plugin_formcreator_encode($line['comment']) . "'\n                          WHERE `id` = " . (int) $line['id'];
         $GLOBALS['DB']->query($query_update) or die($GLOBALS['DB']->error());
     }
     return true;
 }
Example #4
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());
             }
         }
     }
 }
Example #5
0
function plugin_fields_checkFiles()
{
    $plugin = new Plugin();
    if (isset($_SESSION['glpiactiveentities']) && $plugin->isInstalled('fields') && $plugin->isActivated('fields')) {
        Plugin::registerClass('PluginFieldsContainer');
        Plugin::registerClass('PluginFieldsDropdown');
        Plugin::registerClass('PluginFieldsField');
        if (TableExists("glpi_plugin_fields_containers")) {
            $container_obj = new PluginFieldsContainer();
            $containers = $container_obj->find();
            foreach ($containers as $container) {
                $classname = "PluginFields" . ucfirst($container['itemtype'] . preg_replace('/s$/', '', $container['name']));
                if (!class_exists($classname)) {
                    PluginFieldsContainer::generateTemplate($container);
                }
            }
        }
        if (TableExists("glpi_plugin_fields_fields")) {
            $fields_obj = new PluginFieldsField();
            $fields = $fields_obj->find("`type` = 'dropdown'");
            foreach ($fields as $field) {
                PluginFieldsDropdown::create($field);
            }
        }
    }
}
Example #6
0
function plugin_immobilizationsheets_install()
{
    global $DB;
    include_once GLPI_ROOT . "/plugins/immobilizationsheets/inc/profile.class.php";
    $update = false;
    if (!TableExists("glpi_plugin_immo_profiles") && !TableExists("glpi_plugin_immobilizationsheets_profiles")) {
        $DB->runFile(GLPI_ROOT . "/plugins/immobilizationsheets/sql/empty-1.3.0.sql");
    } else {
        if (TableExists("glpi_plugin_immo_profiles") && FieldExists("glpi_plugin_immo_profiles", "interface")) {
            $update = true;
            $DB->runFile(GLPI_ROOT . "/plugins/immobilizationsheets/sql/update-1.2.0.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/immobilizationsheets/sql/update-1.3.0.sql");
        } else {
            if (!TableExists("glpi_plugin_immobilizationsheets_profiles")) {
                $update = true;
                $DB->runFile(GLPI_ROOT . "/plugins/immobilizationsheets/sql/update-1.3.0.sql");
            }
        }
    }
    if ($update) {
        //Do One time on 0.78
        $query_ = "SELECT *\n            FROM `glpi_plugin_immobilizationsheets_profiles` ";
        $result_ = $DB->query($query_);
        if ($DB->numrows($result_) > 0) {
            while ($data = $DB->fetch_array($result_)) {
                $query = "UPDATE `glpi_plugin_immobilizationsheets_profiles`\n                  SET `profiles_id` = '" . $data["id"] . "'\n                  WHERE `id` = '" . $data["id"] . "';";
                $result = $DB->query($query);
            }
        }
        $query = "ALTER TABLE `glpi_plugin_immobilizationsheets_profiles`\n               DROP `name` ;";
        $result = $DB->query($query);
    }
    PluginImmobilizationsheetsProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
    return true;
}
function plugin_manufacturersimports_install()
{
    global $DB;
    include_once GLPI_ROOT . "/plugins/manufacturersimports/inc/profile.class.php";
    include_once GLPI_ROOT . "/plugins/manufacturersimports/inc/config.class.php";
    $migration = new Migration("1.7.0");
    $update = false;
    //Root of SQL files for DB installation or upgrade
    $sql_root = GLPI_ROOT . "/plugins/manufacturersimports/sql/";
    if (!TableExists("glpi_plugin_manufacturersimports_configs")) {
        $DB->runFile($sql_root . "/empty-1.7.0.sql");
    } else {
        if (TableExists("glpi_plugin_suppliertag_config") && !FieldExists("glpi_plugin_suppliertag_config", "FK_entities")) {
            $update = true;
            $DB->runFile($sql_root . "/update-1.1.sql");
            $DB->runFile($sql_root . "/update-1.2.0.sql");
            $DB->runFile($sql_root . "/update-1.3.0.sql");
            $DB->runFile($sql_root . "/update-1.4.1.sql");
            $DB->runFile($sql_root . "/update-1.5.0.sql");
            $DB->runFile($sql_root . "/update-1.7.0.sql");
        } else {
            if (TableExists("glpi_plugin_suppliertag_profiles") && FieldExists("glpi_plugin_suppliertag_profiles", "interface")) {
                $update = true;
                $DB->runFile($sql_root . "/update-1.2.0.sql");
                $DB->runFile($sql_root . "/update-1.3.0.sql");
                $DB->runFile($sql_root . "/update-1.4.1.sql");
                $DB->runFile($sql_root . "/update-1.5.0.sql");
                $DB->runFile($sql_root . "/update-1.7.0.sql");
            } else {
                if (!TableExists("glpi_plugin_manufacturersimports_profiles") && !FieldExists("glpi_plugin_manufacturersimports_configs", "supplier_key")) {
                    $update = true;
                    $DB->runFile($sql_root . "/update-1.3.0.sql");
                    $DB->runFile($sql_root . "/update-1.4.1.sql");
                    $DB->runFile($sql_root . "/update-1.5.0.sql");
                    $DB->runFile($sql_root . "/update-1.7.0.sql");
                } else {
                    if (!FieldExists("glpi_plugin_manufacturersimports_configs", "supplier_key")) {
                        $DB->runFile($sql_root . "/update-1.7.0.sql");
                    }
                }
            }
        }
    }
    $query = "UPDATE `glpi_plugin_manufacturersimports_configs` \n             SET `Supplier_url` = 'http://www.dell.com/support/troubleshooting/us/en/04/Index?c=us&l=en&s=bsd&cs=04&t=system&ServiceTag=' \n             WHERE `name` ='" . PluginManufacturersimportsConfig::DELL . "'";
    $DB->query($query);
    if ($update) {
        foreach ($DB->request('glpi_plugin_manufacturersimports_profiles') as $data) {
            $query = "UPDATE `glpi_plugin_manufacturersimports_profiles`\n                   SET `profiles_id` = '" . $data["id"] . "'\n                   WHERE `id` = '" . $data["id"] . "';";
            $DB->query($query);
        }
        $migration->dropField('glpi_plugin_manufacturersimports_profiles', 'name');
        Plugin::migrateItemType(array(2150 => 'PluginManufacturersimportsModel', 2151 => 'PluginManufacturersimportsConfig'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_tickets"), array("glpi_plugin_manufacturersimports_models", "glpi_plugin_manufacturersimports_logs"));
    }
    //Migrate profiles to the system introduced in 0.85
    PluginManufacturersimportsProfile::initProfile();
    PluginManufacturersimportsProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
    //Drop old profile table : not used anymore
    $migration->dropTable('glpi_plugin_manufacturersimports_profiles');
    return true;
}
 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);
         }
     }
 }
function plugin_moreticket_install()
{
    global $DB;
    include_once GLPI_ROOT . "/plugins/moreticket/inc/profile.class.php";
    if (!TableExists("glpi_plugin_moreticket_configs")) {
        // table sql creation
        $DB->runFile(GLPI_ROOT . "/plugins/moreticket/sql/empty-1.2.0.sql");
    }
    PluginMoreticketProfile::initProfile();
    PluginMoreticketProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
    $migration = new Migration("1.1.0");
    $migration->dropTable('glpi_plugin_moreticket_profiles');
    if (!FieldExists("glpi_plugin_moreticket_configs", "solution_status")) {
        $DB->runFile(GLPI_ROOT . "/plugins/moreticket/sql/update-1.1.1.sql");
    }
    if (FieldExists("glpi_plugin_moreticket_waitingtypes", "is_helpdeskvisible")) {
        $DB->runFile(GLPI_ROOT . "/plugins/moreticket/sql/update-1.1.2.sql");
    }
    if (!FieldExists("glpi_plugin_moreticket_closetickets", "documents_id")) {
        $DB->runFile(GLPI_ROOT . "/plugins/moreticket/sql/update-1.1.3.sql");
    }
    if (!FieldExists("glpi_plugin_moreticket_configs", "date_report_mandatory")) {
        $DB->runFile(GLPI_ROOT . "/plugins/moreticket/sql/update-1.2.0.sql");
    }
    return true;
}
Example #10
0
/**
 * Update from 0.90.1 to 0.90.5
 *
 * @return bool for success (will die for most error)
**/
function update0901to0905()
{
    global $DB, $migration;
    $updateresult = true;
    $ADDTODISPLAYPREF = array();
    //TRANS: %s is the number of new version
    $migration->displayTitle(sprintf(__('Update to %s'), '0.90.5'));
    $migration->setVersion('0.90.5');
    $backup_tables = false;
    $newtables = array();
    foreach ($newtables as $new_table) {
        // rename new tables if exists ?
        if (TableExists($new_table)) {
            $migration->dropTable("backup_{$new_table}");
            $migration->displayWarning("{$new_table} table already exists. " . "A backup have been done to backup_{$new_table}.");
            $backup_tables = true;
            $query = $migration->renameTable("{$new_table}", "backup_{$new_table}");
        }
    }
    if ($backup_tables) {
        $migration->displayWarning("You can delete backup tables if you have no need of them.", true);
    }
    // fix https://github.com/glpi-project/glpi/issues/820
    // remove empty suppliers in tickets
    $query = "DELETE FROM glpi_suppliers_tickets\n             WHERE suppliers_id = 0\n               AND alternative_email = ''";
    $DB->query($query);
    // ************ Keep it at the end **************
    $migration->executeMigration();
    return $updateresult;
}
function plugin_racks_install()
{
    global $DB;
    include_once GLPI_ROOT . "/plugins/racks/inc/profile.class.php";
    $migration = new Migration("1.5.0");
    $update = false;
    if (!TableExists("glpi_plugin_rack_profiles") && !TableExists("glpi_plugin_racks_profiles")) {
        $DB->runFile(GLPI_ROOT . "/plugins/racks/sql/empty-1.4.2.sql");
    } elseif (TableExists("glpi_plugin_rack_content") && !FieldExists("glpi_plugin_rack_content", "first_powersupply")) {
        $update = true;
        $DB->runFile(GLPI_ROOT . "/plugins/racks/sql/update-1.0.2.sql");
        $DB->runFile(GLPI_ROOT . "/plugins/racks/sql/update-1.1.0.sql");
    } elseif (!TableExists("glpi_plugin_racks_profiles")) {
        $update = true;
        $DB->runFile(GLPI_ROOT . "/plugins/racks/sql/update-1.1.0.sql");
    }
    //from 1.1 version
    if (TableExists("glpi_plugin_racks_racks") && !FieldExists("glpi_plugin_racks_racks", "otherserial")) {
        $DB->runFile(GLPI_ROOT . "/plugins/racks/sql/update-1.2.1.sql");
    }
    if (TableExists("glpi_plugin_racks_racks") && !FieldExists("glpi_plugin_racks_racks", "users_id_tech")) {
        $DB->runFile(GLPI_ROOT . "/plugins/racks/sql/update-1.3.0.sql");
    }
    if (!TableExists("glpi_plugin_racks_racktypes")) {
        $DB->runFile(GLPI_ROOT . "/plugins/racks/sql/update-1.3.2.sql");
    }
    if (TableExists("glpi_plugin_racks_racktypes") && !FieldExists("glpi_plugin_racks_racktypes", "is_recursive")) {
        $DB->runFile(GLPI_ROOT . "/plugins/racks/sql/update-1.4.1.sql");
    }
    if (TableExists("glpi_plugin_racks_profiles") && !FieldExists("glpi_plugin_racks_profiles", "open_ticket")) {
        $DB->runFile(GLPI_ROOT . "/plugins/racks/sql/update-1.4.2.sql");
    }
    if ($update) {
        foreach ($DB->request('glpi_plugin_racks_profiles') as $data) {
            $query = "UPDATE `glpi_plugin_racks_profiles`\n                    SET `profiles_id` = '" . $data["id"] . "'\n                    WHERE `id` = '" . $data["id"] . "';";
            $result = $DB->query($query);
        }
        $migration->dropField('glpi_plugin_racks_profiles', 'name');
        Plugin::migrateItemType(array(4450 => 'PluginRacksRack', 4451 => 'PluginRacksOther'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_tickets"), array("glpi_plugin_racks_racks_items", "glpi_plugin_racks_itemspecifications"));
    }
    $notepad_tables = array('glpi_plugin_racks_racks');
    foreach ($notepad_tables as $t) {
        // Migrate data
        if (FieldExists($t, 'notepad')) {
            $query = "SELECT id, notepad\n                      FROM `{$t}`\n                      WHERE notepad IS NOT NULL\n                            AND notepad <>'';";
            foreach ($DB->request($query) as $data) {
                $iq = "INSERT INTO `glpi_notepads`\n                             (`itemtype`, `items_id`, `content`, `date`, `date_mod`)\n                      VALUES ('" . getItemTypeForTable($t) . "', '" . $data['id'] . "',\n                              '" . addslashes($data['notepad']) . "', NOW(), NOW())";
                $DB->queryOrDie($iq, "0.85 migrate notepad data");
            }
            $query = "ALTER TABLE `glpi_plugin_racks_racks` DROP COLUMN `notepad`;";
            $DB->query($query);
        }
    }
    //Migrate profiles to the system introduced in 0.85
    PluginRacksProfile::initProfile();
    PluginRacksProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
    //Drop old profile table : not used anymore
    $migration->dropTable('glpi_plugin_racks_profiles');
    return true;
}
function plugin_environment_install()
{
    global $DB;
    include_once GLPI_ROOT . "/plugins/environment/inc/profile.class.php";
    $update = false;
    if (TableExists("glpi_plugin_environment_profiles") && FieldExists("glpi_plugin_environment_profiles", "interface")) {
        $update = true;
        $DB->runFile(GLPI_ROOT . "/plugins/environment/sql/update-1.3.0.sql");
        $DB->runFile(GLPI_ROOT . "/plugins/environment/sql/update-1.4.0.sql");
    } else {
        if (TableExists("glpi_plugin_environment_profiles") && FieldExists("glpi_plugin_environment_profiles", "connections")) {
            $update = true;
            $DB->runFile(GLPI_ROOT . "/plugins/environment/sql/update-1.4.0.sql");
        }
    }
    if ($update) {
        //Do One time on 0.78
        $query_ = "SELECT *\n            FROM `glpi_plugin_environment_profiles` ";
        $result_ = $DB->query($query_);
        if ($DB->numrows($result_) > 0) {
            while ($data = $DB->fetch_array($result_)) {
                $query = "UPDATE `glpi_plugin_environment_profiles`\n                  SET `profiles_id` = '" . $data["id"] . "'\n                  WHERE `id` = '" . $data["id"] . "';";
                $result = $DB->query($query);
            }
        }
        $query = "ALTER TABLE `glpi_plugin_environment_profiles`\n               DROP `name` ;";
        $result = $DB->query($query);
    }
    PluginEnvironmentProfile::initProfile();
    PluginEnvironmentProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
    $migration = new Migration("1.8.0");
    $migration->dropTable('glpi_plugin_environment_profiles');
    $_SESSION["glpi_plugin_environment_installed"] = 1;
    return true;
}
Example #13
0
 public static function install(Migration $migration)
 {
     global $DB;
     $table = getTableForItemType(__CLASS__);
     if (!TableExists($table)) {
         $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 '1',\n                     `name` varchar(255) NOT NULL DEFAULT '',\n                     `comment` text collate utf8_unicode_ci,\n                     `color` varchar(50) NOT NULL DEFAULT '' COLLATE 'utf8_unicode_ci',\n                     PRIMARY KEY (`id`),\n                     KEY `name` (`name`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
         $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error());
     }
     if (!FieldExists($table, 'type_menu')) {
         $migration->addField($table, 'type_menu', "varchar(50) NOT NULL DEFAULT ''");
         $migration->addKey($table, 'type_menu');
         $migration->migrationOneTable($table);
     }
     // Version 0.90-1.1
     $result = $DB->query("SHOW FIELDS FROM `{$table}` where Field ='type_menu'");
     if ($result && $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             if (stristr($data["Type"], 'varchar') !== FALSE) {
                 $DB->query("ALTER TABLE `{$table}` DROP INDEX `type_menu`;");
                 $DB->query("ALTER TABLE `{$table}` MODIFY `type_menu` text COLLATE utf8_unicode_ci;");
                 $datas = getAllDatasFromTable($table, "`type_menu` IS NOT NULL");
                 if (!empty($datas)) {
                     foreach ($datas as $data) {
                         $itemtypes = PluginTagTagItem::getItemtypes($data['type_menu']);
                         $DB->query("UPDATE `{$table}` SET `type_menu` = '" . json_encode($itemtypes) . "' WHERE `id` = '" . $data['id'] . "'");
                     }
                 }
                 break;
             }
         }
     }
     return true;
 }
Example #14
0
/**
 * DO NOT FORGET TO REPLACE XX AND XY OCCURENCES WITH CORRECT VALUES
 * Update from XX to XY
 *
 * @return bool for success (will die for most error)
**/
function updateXXtoXY()
{
    global $DB, $migration, $CFG_GLPI;
    $current_config = Config::getConfigurationValues('core');
    $updateresult = true;
    $ADDTODISPLAYPREF = array();
    //TRANS: %s is the number of new version
    $migration->displayTitle(sprintf(__('Update to %s'), 'XY'));
    $migration->setVersion('XY');
    $backup_tables = false;
    // table already exist but deleted during the migration
    // not table created during the migration
    $newtables = array();
    foreach ($newtables as $new_table) {
        // rename new tables if exists ?
        if (TableExists($new_table)) {
            $migration->dropTable("backup_{$new_table}");
            $migration->displayWarning("{$new_table} table already exists. " . "A backup have been done to backup_{$new_table}.");
            $backup_tables = true;
            $query = $migration->renameTable("{$new_table}", "backup_{$new_table}");
        }
    }
    if ($backup_tables) {
        $migration->displayWarning("You can delete backup tables if you have no need of them.", true);
    }
    //put you migration script here
    // ************ Keep it at the end **************
    $migration->executeMigration();
    return $updateresult;
}
/**
 * Fonction d'installation du plugin
 * @return boolean
 */
function plugin_groupead_install()
{
    global $DB;
    $miseAjour = false;
    //parcour du tableau des tables à créer
    foreach (plugin_groupead_getListeTable() as $id => $table) {
        if (!TableExists($id)) {
            $requeteInsert = "";
            foreach ($table as $key => $value) {
                if ($requeteInsert != "") {
                    $requeteInsert .= ",`" . $key . "` " . $value;
                } else {
                    $requeteInsert .= "`" . $key . "` " . $value;
                }
                //si premier enregistrement pas de virgule
            }
            $query = "CREATE TABLE `" . $id . "` (" . $requeteInsert . ") ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
            $DB->query($query) or die($DB->error());
        } else {
            $miseAjour = true;
        }
    }
    //enregistrement spéciaux
    //creation du premier accès nécessaire lors de l'installation du plugin
    if ($miseAjour) {
        plugin_groupead_miseAjour();
    } else {
        foreach (plugin_groupead_getFirstInsert() as $query) {
            $DB->query($query) or die($DB->error());
        }
    }
    return true;
}
Example #16
0
function plugin_dashboard_install()
{
    global $DB, $LANG;
    if (!TableExists("glpi_plugin_dashboard_count")) {
        $query = "CREATE TABLE `glpi_plugin_dashboard_count` \n        (`type` INTEGER , `id` INTEGER, `quant` INTEGER, PRIMARY KEY (`id`))\n\t\t\t\t\t\tENGINE = InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; ";
        $DB->query($query) or die("error creating glpi_plugin_dashboard_count " . $DB->error());
        $insert = "INSERT INTO glpi_plugin_dashboard_count (type,quant) VALUES ('1','1')";
        $DB->query($insert);
    } else {
        //remove old table
        $drop = "DROP TABLE glpi_plugin_dashboard_count";
        $DB->query($drop);
        $query = "CREATE TABLE `glpi_plugin_dashboard_count` \n        (`type` INTEGER , `id` INTEGER, `quant` INTEGER, PRIMARY KEY (`id`))\n\t\t\t\t\t\tENGINE = InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; ";
        $DB->query($query) or die("error creating table glpi_plugin_dashboard_count " . $DB->error());
        $insert = "INSERT INTO glpi_plugin_dashboard_count (type,quant) VALUES ('1','1')";
        $DB->query($insert);
    }
    //map
    if (!TableExists("glpi_plugin_dashboard_map")) {
        $query_map = "CREATE TABLE IF NOT EXISTS `glpi_plugin_dashboard_map` (\n  `id` int(4) NOT NULL AUTO_INCREMENT,\n  `entities_id` int(4) NOT NULL,\n  `location` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,\n  `lat` float NOT NULL,\n  `lng` float NOT NULL,\n  PRIMARY KEY (`id`,`entities_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;";
        $DB->query($query_map) or die("error creating table glpi_plugin_dashboard_map " . $DB->error());
    }
    //configs
    if (!TableExists("glpi_plugin_dashboard_config")) {
        $query_conf = "CREATE TABLE IF NOT EXISTS `glpi_plugin_dashboard_config` (\n  `id` int(4) NOT NULL AUTO_INCREMENT,\n  `name` varchar(50) NOT NULL,\n  `value` varchar(25) NOT NULL,\n  `users_id` varchar(25) NOT NULL DEFAULT '',\n  PRIMARY KEY (`id`,`name`,`value`,`users_id`),\n  UNIQUE KEY `name` (`name`,`users_id`),\n  KEY `name_2` (`name`,`users_id`)\n) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; ";
        $DB->query($query_conf) or die("error creating table glpi_plugin_dashboard_config " . $DB->error());
    }
    return true;
}
Example #17
0
function plugin_ticketmail_install()
{
    global $DB;
    $migration = new Migration(100);
    //Fresh install
    if (!TableExists('glpi_plugin_ticketmail_profiles')) {
        $query = "CREATE TABLE `glpi_plugin_ticketmail_profiles` (\n\t\t\t\t\t`id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_profiles (id)',\n\t\t\t\t\t`show_ticketmail_onglet` char(1) collate utf8_unicode_ci default NULL,\n\t\t\t\t\tPRIMARY KEY  (`id`)\n\t\t\t\t  ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
        $DB->queryOrDie($query, $DB->error());
        $migration->executeMigration();
        include_once GLPI_ROOT . "/plugins/ticketmail/inc/profile.class.php";
        PluginTicketmailProfile::createAdminAccess($_SESSION['glpiactiveprofile']['id']);
    } else {
        // Since v0.84 remove "profiles_id" column and use "id"
        if (FieldExists('glpi_plugin_ticketmail_profiles', 'profiles_id')) {
            $drop_column_query = "ALTER TABLE glpi_plugin_ticketmail_profiles DROP COLUMN `id`;";
            $rename_column_query = "ALTER TABLE glpi_plugin_ticketmail_profiles\n\t\t\t\t\t\t\t\t\tCHANGE profiles_id id int(11) NOT NULL default '0'\n\t\t\t\t\t\t\t\t\tCOMMENT 'RELATION to glpi_profiles (id)';";
            $DB->queryOrDie($drop_column_query, $DB->error());
            $DB->queryOrDie($rename_column_query, $DB->error());
            $add_primarykey_query = "ALTER TABLE glpi_plugin_ticketmail_profiles\n\t\t\t\t\t\t\t\t\t ADD PRIMARY KEY (id);";
            $drop_old_index_query = "ALTER TABLE glpi_plugin_ticketmail_profiles\n\t\t\t\t\t\t\t\t\t DROP INDEX profiles_id;";
            $DB->queryOrDie($add_primarykey_query, $DB->error());
            $DB->queryOrDie($drop_old_index_query, $DB->error());
        }
    }
    return true;
}
 static function initSession()
 {
     global $DB;
     if (TableExists("glpi_plugin_fusioninventory_config")) {
         if (FieldExists("glpi_plugin_fusioninventory_config", "ID")) {
             $profile = new PluginFusioninventoryProfile();
             $query = "SELECT DISTINCT `glpi_profiles`.*\n                      FROM `glpi_users_profiles` INNER JOIN `glpi_profiles`\n                           ON (`glpi_users_profiles`.`FK_profiles` = `glpi_profiles`.`ID`)\n                      WHERE `glpi_users_profiles`.`FK_users`='" . $_SESSION["glpiID"] . "'";
             $result = $DB->query($query);
             $_SESSION['glpi_plugin_fusioninventory_profile'] = array();
             if ($DB->numrows($result)) {
                 while ($data = $DB->fetch_assoc($result)) {
                     $profile->fields = array();
                     if (isset($_SESSION["glpiactiveprofile"]["ID"])) {
                         $profile->getFromDB($_SESSION["glpiactiveprofile"]["ID"]);
                         $_SESSION['glpi_plugin_fusioninventory_profile'] = $profile->fields;
                     } else {
                         $profile->getFromDB($data['ID']);
                         $_SESSION['glpi_plugin_fusioninventory_profile'] = $profile->fields;
                     }
                     $_SESSION["glpi_plugin_fusioninventory_installed"] = 1;
                 }
             }
         }
     }
 }
/**
 * Update from 0.83.1 to 0.83.3
 *
 * @return bool for success (will die for most error)
**/
function update0831to0833()
{
    global $DB, $migration;
    $updateresult = true;
    $ADDTODISPLAYPREF = array();
    $migration->displayTitle(sprintf(__('Update to %s'), '0.83.3'));
    $migration->setVersion('0.83.3');
    $backup_tables = false;
    $newtables = array();
    foreach ($newtables as $new_table) {
        // rename new tables if exists ?
        if (TableExists($new_table)) {
            $migration->dropTable("backup_{$new_table}");
            $migration->displayWarning("{$new_table} table already exists. " . "A backup have been done to backup_{$new_table}.");
            $backup_tables = true;
            $query = $migration->renameTable("{$new_table}", "backup_{$new_table}");
        }
    }
    if ($backup_tables) {
        $migration->displayWarning("You can delete backup tables if you have no need of them.", true);
    }
    $migration->displayMessage(sprintf(__('Change of the database layout - %s'), 'Compute entities information on document links'));
    // Updating schema
    $query_doc_i = "UPDATE `glpi_documents_items` as `doc_i`\n                   INNER JOIN `glpi_documents` as `doc`\n                     ON  `doc`.`id` = `doc_i`.`documents_id`\n                   SET `doc_i`.`entities_id` = `doc`.`entities_id`,\n                       `doc_i`.`is_recursive` = `doc`.`is_recursive`";
    $DB->queryOrDie($query_doc_i, "0.83 update entities_id and is_recursive in glpi_documents_items");
    // ************ Keep it at the end **************
    $migration->displayMessage('Migration of glpi_displaypreferences');
    foreach ($ADDTODISPLAYPREF as $type => $tab) {
        $query = "SELECT DISTINCT `users_id`\n                FROM `glpi_displaypreferences`\n                WHERE `itemtype` = '{$type}'";
        if ($result = $DB->query($query)) {
            if ($DB->numrows($result) > 0) {
                while ($data = $DB->fetch_assoc($result)) {
                    $query = "SELECT MAX(`rank`)\n                         FROM `glpi_displaypreferences`\n                         WHERE `users_id` = '" . $data['users_id'] . "'\n                               AND `itemtype` = '{$type}'";
                    $result = $DB->query($query);
                    $rank = $DB->result($result, 0, 0);
                    $rank++;
                    foreach ($tab as $newval) {
                        $query = "SELECT *\n                            FROM `glpi_displaypreferences`\n                            WHERE `users_id` = '" . $data['users_id'] . "'\n                                  AND `num` = '{$newval}'\n                                  AND `itemtype` = '{$type}'";
                        if ($result2 = $DB->query($query)) {
                            if ($DB->numrows($result2) == 0) {
                                $query = "INSERT INTO `glpi_displaypreferences`\n                                         (`itemtype` ,`num` ,`rank` ,`users_id`)\n                                  VALUES ('{$type}', '{$newval}', '" . $rank++ . "',\n                                          '" . $data['users_id'] . "')";
                                $DB->query($query);
                            }
                        }
                    }
                }
            } else {
                // Add for default user
                $rank = 1;
                foreach ($tab as $newval) {
                    $query = "INSERT INTO `glpi_displaypreferences`\n                                (`itemtype` ,`num` ,`rank` ,`users_id`)\n                         VALUES ('{$type}', '{$newval}', '" . $rank++ . "', '0')";
                    $DB->query($query);
                }
            }
        }
    }
    // must always be at the end
    $migration->executeMigration();
    return $updateresult;
}
Example #20
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                  `type`                              VARCHAR(25)    DEFAULT NULL,\n                  `plugin_fields_containers_id`       INT(11)        NOT NULL DEFAULT '0',\n                  `ranking`                           INT(11)        NOT NULL DEFAULT '0',\n                  `default_value`                     VARCHAR(255)   DEFAULT NULL,\n                  `is_active`                         TINYINT(1)     NOT NULL DEFAULT '1',\n                  `is_readonly`                       TINYINT(1)     NOT NULL DEFAULT '1',\n                  `mandatory`                         TINYINT(1)     NOT NULL DEFAULT '0',\n                  PRIMARY KEY                         (`id`),\n                  KEY `plugin_fields_containers_id`   (`plugin_fields_containers_id`),\n                  KEY `is_active`                     (`is_active`),\n                  KEY `is_readonly`                   (`is_readonly`)\n               ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
         $DB->query($query) or die($DB->error());
     }
     $migration->displayMessage("Updating {$table}");
     if (!FieldExists($table, 'is_active')) {
         $migration->addField($table, 'is_active', 'bool', array('value' => 1));
         $migration->addKey($table, 'is_active', 'is_active');
     }
     if (!FieldExists($table, 'is_readonly')) {
         $migration->addField($table, 'is_readonly', 'bool', array('default' => false));
         $migration->addKey($table, 'is_readonly', 'is_readonly');
     }
     if (!FieldExists($table, 'mandatory')) {
         $migration->addField($table, 'mandatory', 'bool', array('value' => 0));
     }
     $migration->executeMigration();
     return true;
 }
Example #21
0
/**
 * Update from 0.90 to 0.90.1
 *
 * @return bool for success (will die for most error)
**/
function update090to0901()
{
    global $DB, $migration;
    $updateresult = true;
    $ADDTODISPLAYPREF = array();
    //TRANS: %s is the number of new version
    $migration->displayTitle(sprintf(__('Update to %s'), '0.90.1'));
    $migration->setVersion('0.90.1');
    $backup_tables = false;
    $newtables = array();
    foreach ($newtables as $new_table) {
        // rename new tables if exists ?
        if (TableExists($new_table)) {
            $migration->dropTable("backup_{$new_table}");
            $migration->displayWarning("{$new_table} table already exists. " . "A backup have been done to backup_{$new_table}.");
            $backup_tables = true;
            $query = $migration->renameTable("{$new_table}", "backup_{$new_table}");
        }
    }
    if ($backup_tables) {
        $migration->displayWarning("You can delete backup tables if you have no need of them.", true);
    }
    // Add missing fill in 0.90 empty version
    $migration->addField("glpi_entities", 'inquest_duration', "integer", array('value' => 0));
    // ************ Keep it at the end **************
    $migration->executeMigration();
    return $updateresult;
}
Example #22
0
/**
 * Update from 0.90.1 to 0.91
 *
 * @return bool for success (will die for most error)
**/
function update0901to091()
{
    global $DB, $migration;
    $updateresult = true;
    $ADDTODISPLAYPREF = array();
    //TRANS: %s is the number of new version
    $migration->displayTitle(sprintf(__('Update to %s'), '0.91'));
    $migration->setVersion('0.91');
    $backup_tables = false;
    $newtables = array();
    foreach ($newtables as $new_table) {
        // rename new tables if exists ?
        if (TableExists($new_table)) {
            $migration->dropTable("backup_{$new_table}");
            $migration->displayWarning("{$new_table} table already exists. " . "A backup have been done to backup_{$new_table}.");
            $backup_tables = true;
            $query = $migration->renameTable("{$new_table}", "backup_{$new_table}");
        }
    }
    if ($backup_tables) {
        $migration->displayWarning("You can delete backup tables if you have no need of them.", true);
    }
    Config::setConfigurationValues('core', array('set_default_requester' => 1));
    $migration->addField("glpi_users", "set_default_requester", "tinyint(1) NULL DEFAULT NULL");
    // ************ Keep it at the end **************
    $migration->executeMigration();
    return $updateresult;
}
Example #23
0
function plugin_typology_install()
{
    global $DB;
    include_once GLPI_ROOT . "/plugins/typology/inc/profile.class.php";
    if (!TableExists("glpi_plugin_typology_typologies")) {
        // table sql creation
        $DB->runFile(GLPI_ROOT . "/plugins/typology/sql/empty-1.0.0.sql");
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginTypologyTypology' AND `name` = 'Alert no validated typology'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##typology.action## : ##typology.entity##',\n                        '##FOREACHitems##\n   ##lang.typology.name## : ##typology.name##\n   ##lang.typology.itemtype## : ##typology.itemtype##\n   ##lang.typology.items_id## : ##typology.items_id##\n   ##lang.typology.itemlocation## : ##typology.itemlocation##\n   ##lang.typology.itemuser## : ##typology.itemuser##\n   ##lang.typology.error## : ##typology.error##\n   ##ENDFOREACHitems##',\n   '&lt;table class=\"tab_cadre\" border=\"1\" cellspacing=\"2\" cellpadding=\"3\"&gt;\n   &lt;tbody&gt;\n   &lt;tr&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.typology.name##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.typology.itemtype##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.typology.items_id##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.typology.itemlocation##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.typology.itemuser##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.typology.error##&lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   ##FOREACHtypologyitems##\n   &lt;tr&gt;\n   &lt;td&gt;&lt;a href=\"##typology.url##\" target=\"_blank\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##typology.name##&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##typology.itemtype##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;a href=\"##typology.itemurl##\" target=\"_blank\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##typology.items_id##&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##typology.itemlocation##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##typology.itemuser##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##typology.error##&lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   ##ENDFOREACHtypologyitems##\n   &lt;/tbody&gt;\n   &lt;/table&gt;');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Alert no validated typology', 0, 'PluginTypologyTypology', 'AlertNotValidatedTypology',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-02-17 22:36:46');";
        $result = $DB->query($query);
    }
    if (TableExists("glpi_plugin_typology_typologycriterias")) {
        $query = "UPDATE `glpi_plugin_typology_typologycriterias`\n                     SET `itemtype`='IPAddress'\n                     WHERE `itemtype`='NetworkPort'";
        $result = $DB->query($query);
        $query = "UPDATE `glpi_plugin_typology_typologycriteriadefinitions`\n                     SET `field`='name;glpi_ipaddresses;itemlink'\n                     WHERE `field` LIKE '%glpi_networkports%'";
        $result = $DB->query($query);
    }
    CronTask::Register('PluginTypologyTypology', 'UpdateTypology', DAY_TIMESTAMP);
    CronTask::Register('PluginTypologyTypology', 'NotValidated', DAY_TIMESTAMP);
    PluginTypologyProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
    return true;
}
/**
 * Summary of plugin_timezones_install
 * @return true or die!
 */
function plugin_timezones_install()
{
    global $DB;
    if (!TableExists("glpi_plugin_timezones_users")) {
        $query = "  CREATE TABLE `glpi_plugin_timezones_users` (\r\n\t                    `id` INT(11) NOT NULL AUTO_INCREMENT,\r\n\t                    `users_id` INT(11) NOT NULL,\r\n\t                    `timezone` VARCHAR(50) NOT NULL,\r\n\t                    PRIMARY KEY (`id`),\r\n\t                    UNIQUE INDEX `users_id` (`users_id`),\r\n\t                    INDEX `timezone` (`timezone`)\r\n                    )\r\n                    COLLATE='utf8_general_ci'\r\n                    ENGINE=InnoDB                    \r\n                    ;\r\n\t\t\t";
        $DB->query($query) or die("error creating glpi_plugin_timezones_users" . $DB->error());
    } else {
        if (!FieldExists("glpi_plugin_timezones_users", "users_id")) {
            $query = "  ALTER TABLE `glpi_plugin_timezones_users`\r\n\t                    ADD COLUMN `id` INT(11) NOT NULL AUTO_INCREMENT FIRST,\r\n\t                    CHANGE COLUMN `id` `users_id` INT(11) NOT NULL AFTER `id`,\r\n\t                    DROP PRIMARY KEY,\r\n\t                    ADD PRIMARY KEY (`id`),\r\n\t                    ADD UNIQUE INDEX `users_id` (`users_id`);\r\n                ";
            $DB->query($query) or die("error altering glpi_plugin_timezones_users" . $DB->error());
        }
    }
    if (!TableExists("glpi_plugin_timezones_dbbackups")) {
        $query = "  CREATE TABLE `glpi_plugin_timezones_dbbackups` (\r\n\t                `date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\r\n\t                `table_name` VARCHAR(255) NULL ,\r\n\t                `alter_table` TEXT NULL\r\n                )\r\n                COLLATE='utf8_general_ci'\r\n                ENGINE=InnoDB;\r\n\t\t\t";
        $DB->query($query) or die("error creating glpi_plugin_timezones_dbbackups" . $DB->error());
    }
    if (!TableExists("glpi_plugin_timezones_tasks_localtimes")) {
        $query = " CREATE TABLE `glpi_plugin_timezones_tasks_localtimes` (\r\n\t                    `id` INT(11) NOT NULL AUTO_INCREMENT,\r\n\t                    `items_type` VARCHAR(50) NOT NULL,\r\n\t                    `items_id` INT(11) NOT NULL,\r\n\t                    `begin` VARCHAR(20) NULL DEFAULT NULL COMMENT 'In order to keep local time',\r\n\t                    `end` VARCHAR(20) NULL DEFAULT NULL COMMENT 'In order to keep local time',\r\n\t                    PRIMARY KEY (`id`),\r\n\t                    UNIQUE INDEX `items_type_items_id` (`items_type`, `items_id`)\r\n                    )\r\n                    COLLATE='utf8_general_ci'\r\n                    ENGINE=InnoDB\r\n                    ;\r\n\t\t\t";
        $DB->query($query) or die("error creating glpi_plugin_timezones_tasks_localtimes" . $DB->error());
    }
    // here we update the time_zones mySQL tables.
    // with data from PHP module: php_timezonedb. See: https://pecl.php.net/package/timezonedb
    //$query = "TRUNCATE `mysql`.`time_zone`;";
    //$DB->query( $query ) or die("error truncating mysql.time_zone" . $DB->error());
    //$query = "TRUNCATE `mysql`.`time_zone_name`;";
    //$DB->query( $query ) or die("error truncating mysql.time_zonetime_zone_name" . $DB->error());
    //$query = "TRUNCATE `mysql`.`time_zone_transition`;";
    //$DB->query( $query ) or die("error truncating mysql.time_zone_transition" . $DB->error());
    //$query = "TRUNCATE `mysql`.`time_zone_transition_type`;";
    //$DB->query( $query ) or die("error truncating mysql.time_zone_transition_type" . $DB->error());
    //$query = "TRUNCATE `mysql`.`time_zone_leap_second`;";
    //$DB->query( $query ) or die("error truncating mysql.time_zone_leap_second" . $DB->error());
    //    $timezones = DateTimeZone::listIdentifiers( ) ;
    //    foreach( $timezones as $key => $tz ){
    //        $key++ ;
    //        // time_zone
    //        $query = "INSERT INTO `mysql`.`time_zone` (`Time_zone_id`, `Use_leap_seconds`) VALUES ($key, 'N');";
    //        $DB->query( $query ) or die("error inserting data into mysql.time_zone" . $DB->error());
    //        $query = "INSERT INTO `mysql`.`time_zone_name` (`Name`, `Time_zone_id`) VALUES ('$tz', $key);";
    //        $DB->query( $query ) or die("error inserting data into mysql.time_zone_name" . $DB->error());
    //        $tz_trans = (new DateTimeZone( $tz ))->getTransitions() ;
    //        $trans_array = array( ) ;
    //        $trans_type_id=0;
    //        foreach($tz_trans as $key_trans => $trans) {
    //            $trans_key = $trans['offset'].", ".($trans['isdst']?1:0).", '".$trans['abbr']."'";
    //            if( !in_array( $trans_key, $trans_array ) ){
    //                $trans_array[$trans_type_id++] = $trans_key ;
    //            }
    //            $query = "REPLACE INTO `mysql`.`time_zone_transition` (`Time_zone_id`, `Transition_time`, `Transition_type_id`) VALUES ($key, ".$trans['ts'].", ".$trans_type_id.");" ;
    //            $DB->query( $query ) or die("error inserting data into mysql.time_zone_transition" . $DB->error());
    //        }
    //        foreach( $trans_array as $trans_type_id => $trans_key ){
    //            $trans_type_id++;
    //            $query = "INSERT INTO `mysql`.`time_zone_transition_type` (`Time_zone_id`, `Transition_type_id`, `Offset`, `Is_DST`, `Abbreviation`) VALUES ($key, $trans_type_id, $trans_key);";
    //            $DB->query( $query ) or die("error inserting data into mysql.time_zone_transition_type" . $DB->error());
    //        }
    //    }
    return true;
}
/**
 * Update from 0.78 to 0.78.1
 *
 * @return bool for success (will die for most error)
 */
function update078to0781()
{
    global $DB, $migration;
    $updateresult = true;
    $migration->displayTitle(sprintf(__('Update to %s'), '0.78.1'));
    $migration->setVersion('0.78.1');
    //TRANS: %s is 'Clean reservation entity link'
    $migration->displayMessage(sprintf(__('Data migration - %s'), 'Clean reservation entity link'));
    // Updating schema
    $entities = getAllDatasFromTable('glpi_entities');
    $entities[0] = "Root";
    $query = "SELECT DISTINCT `itemtype` FROM `glpi_reservationitems`";
    if ($result = $DB->query($query)) {
        if ($DB->numrows($result) > 0) {
            while ($data = $DB->fetch_assoc($result)) {
                $itemtable = getTableForItemType($data['itemtype']);
                // ajout d'un contrôle pour voir si la table existe ( cas migration plugin non fait)
                if (!TableExists($itemtable)) {
                    $migration->displayWarning("*** Skip : no table {$itemtable} ***", true);
                    continue;
                }
                $do_recursive = false;
                if (FieldExists($itemtable, 'is_recursive', false)) {
                    $do_recursive = true;
                }
                foreach ($entities as $entID => $val) {
                    if ($do_recursive) {
                        // Non recursive ones
                        $query3 = "UPDATE `glpi_reservationitems`\n                           SET `entities_id`={$entID}, `is_recursive`=0\n                           WHERE `itemtype`='" . $data['itemtype'] . "'\n                              AND `items_id` IN (SELECT `id` FROM `{$itemtable}`\n                              WHERE `entities_id`={$entID} AND `is_recursive`=0)";
                        $DB->queryOrDie($query3, "0.78.1 update entities_id and is_recursive=0 in glpi_reservationitems for " . $data['itemtype']);
                        // Recursive ones
                        $query3 = "UPDATE `glpi_reservationitems`\n                           SET `entities_id`={$entID}, `is_recursive`=1\n                           WHERE `itemtype`='" . $data['itemtype'] . "'\n                              AND `items_id` IN (SELECT `id` FROM `{$itemtable}`\n                              WHERE `entities_id`={$entID} AND `is_recursive`=1)";
                        $DB->queryOrDie($query3, "0.78.1 update entities_id and is_recursive=1 in glpi_reservationitems for " . $data['itemtype']);
                    } else {
                        $query3 = "UPDATE `glpi_reservationitems`\n                           SET `entities_id`={$entID}\n                           WHERE `itemtype`='" . $data['itemtype'] . "'\n                              AND `items_id` IN (SELECT `id` FROM `{$itemtable}`\n                              WHERE `entities_id`={$entID})";
                        $DB->queryOrDie($query3, "0.78.1 update entities_id in glpi_reservationitems for " . $data['itemtype']);
                    }
                }
            }
        }
    }
    $query = "ALTER TABLE `glpi_tickets`\n             CHANGE `global_validation` `global_validation` VARCHAR(255) DEFAULT 'none'";
    $DB->query($query) or die("0.78.1 change ticket global_validation default state");
    $query = "UPDATE `glpi_tickets`\n             SET `global_validation`='none'\n             WHERE `id` NOT IN (SELECT DISTINCT `tickets_id`\n                                FROM `glpi_ticketvalidations`)";
    $DB->query($query) or die("0.78.1 update ticket global_validation state");
    if (!FieldExists('glpi_knowbaseitemcategories', 'entities_id', false)) {
        $query = "ALTER TABLE `glpi_knowbaseitemcategories`\n                    ADD `entities_id` INT NOT NULL DEFAULT '0' AFTER `id`,\n                    ADD `is_recursive` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `entities_id`,\n                    ADD INDEX `entities_id` (`entities_id`),ADD INDEX `is_recursive` (`is_recursive`)";
        $DB->queryOrDie($query, "0.78.1 add entities_id,is_recursive in glpi_knowbaseitemcategories");
        // Set existing categories recursive global
        $query = "UPDATE `glpi_knowbaseitemcategories` SET `is_recursive` = '1'";
        $DB->queryOrDie($query, "0.78.1 set value of is_recursive in glpi_knowbaseitemcategories");
        $query = "ALTER TABLE `glpi_knowbaseitemcategories` DROP INDEX `unicity` ,\n               ADD UNIQUE `unicity` ( `entities_id`, `knowbaseitemcategories_id` , `name` ) ";
        $DB->queryOrDie($query, "0.78.1 update unicity index on glpi_knowbaseitemcategories");
    }
    // must always be at the end (only for end message)
    $migration->executeMigration();
    return $updateresult;
}
function plugin_addressing_install()
{
    global $DB;
    include_once GLPI_ROOT . "/plugins/addressing/inc/profile.class.php";
    $update = false;
    if (!TableExists("glpi_plugin_addressing_display") && !TableExists("glpi_plugin_addressing") && !TableExists("glpi_plugin_addressing_configs")) {
        $DB->runFile(GLPI_ROOT . "/plugins/addressing/sql/empty-2.0.0.sql");
    } else {
        if (!TableExists("glpi_plugin_addressing_profiles") && TableExists("glpi_plugin_addressing_display") && !FieldExists("glpi_plugin_addressing_display", "ipconf1")) {
            //1.4
            $update = true;
            $DB->runFile(GLPI_ROOT . "/plugins/addressing/sql/update-1.4.sql");
        }
        if (!TableExists("glpi_plugin_addressing") && TableExists("glpi_plugin_addressing_display") && FieldExists("glpi_plugin_addressing_display", "ipconf1")) {
            $update = true;
            $DB->runFile(GLPI_ROOT . "/plugins/addressing/sql/update-1.5.sql");
        }
        if (TableExists("glpi_plugin_addressing_display") && !FieldExists("glpi_plugin_addressing", "ipdeb")) {
            $update = true;
            $DB->runFile(GLPI_ROOT . "/plugins/addressing/sql/update-1.6.sql");
        }
        if (TableExists("glpi_plugin_addressing_profiles") && FieldExists("glpi_plugin_addressing_profiles", "interface")) {
            $update = true;
            $DB->runFile(GLPI_ROOT . "/plugins/addressing/sql/update-1.7.0.sql");
        }
        if (!TableExists("glpi_plugin_addressing_configs")) {
            $DB->runFile(GLPI_ROOT . "/plugins/addressing/sql/update-1.8.0.sql");
            $update = true;
        }
        if (TableExists("glpi_plugin_addressing_profiles") && !FieldExists("glpi_plugin_addressing_profiles", "use_ping_in_equipment")) {
            $DB->runFile(GLPI_ROOT . "/plugins/addressing/sql/update-1.9.0.sql");
            $update = true;
        }
    }
    if ($update) {
        $query_ = "SELECT *\n                  FROM `glpi_plugin_addressing_profiles` ";
        $result_ = $DB->query($query_);
        if ($DB->numrows($result_) > 0) {
            while ($data = $DB->fetch_array($result_)) {
                $query = "UPDATE `glpi_plugin_addressing_profiles`\n                      SET `profiles_id` = '" . $data["id"] . "'\n                      WHERE `id` = '" . $data["id"] . "'";
                $result = $DB->query($query);
            }
        }
        if (FieldExists("glpi_plugin_addressing_profiles", "name")) {
            $query = "ALTER TABLE `glpi_plugin_addressing_profiles`\n                    DROP `name` ";
            $result = $DB->query($query);
        }
        Plugin::migrateItemType(array(5000 => 'PluginAddressingAddressing', 5001 => 'PluginAddressingReport'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_items_tickets"));
    }
    //0.85 : new profile system
    PluginAddressingProfile::migrateProfiles();
    //Add all rights for current user profile
    PluginAddressingProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
    //Drop old profile table : not used anymore
    $migration = new Migration("2.2.0");
    $migration->dropTable('glpi_plugin_addressing_profiles');
    return true;
}
Example #27
0
function plugin_init_escalade()
{
    global $PLUGIN_HOOKS;
    $PLUGIN_HOOKS['csrf_compliant']['escalade'] = true;
    $plugin = new Plugin();
    if (isset($_SESSION['glpiID']) && $plugin->isInstalled('escalade') && $plugin->isActivated('escalade')) {
        //load config in session
        if (TableExists("glpi_plugin_escalade_configs")) {
            PluginEscaladeConfig::loadInSession();
            // == Load js scripts ==
            if (isset($_SESSION['plugins']['escalade']['config'])) {
                $escalade_config = $_SESSION['plugins']['escalade']['config'];
                $PLUGIN_HOOKS['add_javascript']['escalade'][] = 'scripts/function.js';
                // on central page
                if (strpos($_SERVER['REQUEST_URI'], "central.php") !== false) {
                    //history and climb feature
                    if ($escalade_config['show_history']) {
                        $PLUGIN_HOOKS['add_javascript']['escalade'][] = 'scripts/central.js.php';
                    }
                }
                // on ticket page (in edition)
                if (strpos($_SERVER['REQUEST_URI'], "ticket.form.php") !== false && isset($_GET['id'])) {
                    //history and climb feature
                    if ($escalade_config['show_history']) {
                        $PLUGIN_HOOKS['add_javascript']['escalade'][] = 'scripts/escalade.js.php';
                    }
                    //remove btn feature
                    if (!$escalade_config['remove_delete_group_btn'] || !$escalade_config['remove_delete_user_btn']) {
                        $PLUGIN_HOOKS['add_javascript']['escalade'][] = 'scripts/remove_btn.js.php';
                    }
                    //clone ticket feature
                    if ($escalade_config['cloneandlink_ticket']) {
                        $PLUGIN_HOOKS['add_javascript']['escalade'][] = 'scripts/cloneandlink_ticket.js.php';
                    }
                    //filter group feature
                    if ($escalade_config['use_filter_assign_group']) {
                        $PLUGIN_HOOKS['add_javascript']['escalade'][] = 'scripts/filtergroup.js.php';
                    }
                }
                Plugin::registerClass('PluginEscaladeGroup_Group', array('addtabon' => 'Group'));
                Plugin::registerClass('PluginEscaladeUser', array('addtabon' => array('User')));
            }
        }
        $PLUGIN_HOOKS['add_css']['escalade'][] = 'escalade.css';
        // == Ticket modifications
        $PLUGIN_HOOKS['item_update']['escalade'] = array('Ticket' => 'plugin_escalade_item_update');
        $PLUGIN_HOOKS['item_add']['escalade'] = array('Group_Ticket' => 'plugin_escalade_item_add_group_ticket', 'Ticket_User' => 'plugin_escalade_item_add_user', 'Ticket' => 'plugin_escalade_item_add_ticket');
        $PLUGIN_HOOKS['pre_item_add']['escalade'] = array('Group_Ticket' => 'plugin_escalade_pre_item_add_group_ticket', 'Ticket' => 'plugin_escalade_pre_item_add_ticket');
        $PLUGIN_HOOKS['post_prepareadd']['escalade'] = array('Ticket' => 'plugin_escalade_post_prepareadd_ticket');
        $PLUGIN_HOOKS['item_purge']['escalade'] = array('User' => 'plugin_escalade_item_purge');
        $PLUGIN_HOOKS['item_add']['escalade']['User'] = '******';
        // == Interface links ==
        if (Session::haveRight('config', UPDATE)) {
            $PLUGIN_HOOKS['config_page']['escalade'] = 'front/config.form.php';
        }
        $PLUGIN_HOOKS['use_massive_action']['escalade'] = 1;
    }
}
Example #28
0
 public static function install(Migration $migration)
 {
     $table = getTableForItemType(__CLASS__);
     if (!TableExists($table)) {
         $query = "CREATE TABLE IF NOT EXISTS `{$table}` (\n            \t`id` INT(11) NOT NULL AUTO_INCREMENT,\n            \t`plugin_tag_tags_id` INT(11) NOT NULL DEFAULT '0',\n            \t`items_id` INT(11) NOT NULL DEFAULT '1',\n            \t`itemtype` VARCHAR(255) NOT NULL DEFAULT '' COLLATE 'utf8_unicode_ci',\n            \tPRIMARY KEY (`id`),\n            \tINDEX `name` (`itemtype`)\n            )\n            COLLATE='utf8_unicode_ci'\n            ENGINE=MyISAM";
         $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error());
     }
     return true;
 }
 static function install(Migration $migration)
 {
     $table = getTableForItemType(__CLASS__);
     if (!TableExists($table)) {
         $query = "CREATE TABLE IF NOT EXISTS `{$table}` (\n                     `plugin_formcreator_forms_id` INT NOT NULL ,\n                     `plugin_formcreator_profiles_id` INT NOT NULL ,\n                     PRIMARY KEY (`plugin_formcreator_forms_id`, `plugin_formcreator_profiles_id`)\n                  ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
         $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error());
     }
     return true;
 }
Example #30
0
 static function install(Migration $migration)
 {
     global $DB;
     $table = getTableForItemType(__CLASS__);
     if (!TableExists($table)) {
         $query = "CREATE TABLE IF NOT EXISTS `{$table}` (\n           `id` int(11) NOT NULL AUTO_INCREMENT,\n           `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,\n           `comment` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,\n           PRIMARY KEY (`id`),\n           KEY `name` (`name`)\n         ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
         $DB->query($query) or die("Error adding table {$table}");
     }
 }