dropTable() public method

Drop immediatly a table if it exists
public dropTable ( $table )
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;
}
示例#2
0
 static function install(Migration $migration)
 {
     global $DB;
     // Table no longer needed in GLPI 0.85+; drop it. Needed for upgrades
     $migration->dropTable(getTableForItemType(__CLASS__));
     PluginSimcardProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
 }
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;
}
function plugin_financialreports_install()
{
    global $DB;
    include_once GLPI_ROOT . "/plugins/financialreports/inc/profile.class.php";
    $update = false;
    if (!TableExists("glpi_plugin_state_profiles") && !TableExists("glpi_plugin_financialreports_configs")) {
        $DB->runFile(GLPI_ROOT . "/plugins/financialreports/sql/empty-2.1.0.sql");
    } else {
        if (TableExists("glpi_plugin_state_parameters") && !FieldExists("glpi_plugin_state_parameters", "monitor")) {
            $update = true;
            $DB->runFile(GLPI_ROOT . "/plugins/financialreports/sql/update-1.5.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/financialreports/sql/update-1.6.0.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/financialreports/sql/update-1.7.0.sql");
        } else {
            if (TableExists("glpi_plugin_state_profiles") && FieldExists("glpi_plugin_state_profiles", "interface")) {
                $update = true;
                $DB->runFile(GLPI_ROOT . "/plugins/financialreports/sql/update-1.6.0.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/financialreports/sql/update-1.7.0.sql");
            } else {
                if (!TableExists("glpi_plugin_financialreports_configs")) {
                    $update = true;
                    $DB->runFile(GLPI_ROOT . "/plugins/financialreports/sql/update-1.7.0.sql");
                }
            }
        }
    }
    if ($update) {
        //Do One time on 0.78
        $query_ = "SELECT *\n            FROM `glpi_plugin_financialreports_profiles` ";
        $result_ = $DB->query($query_);
        if ($DB->numrows($result_) > 0) {
            while ($data = $DB->fetch_array($result_)) {
                $query = "UPDATE `glpi_plugin_financialreports_profiles`\n                  SET `profiles_id` = '" . $data["id"] . "'\n                  WHERE `id` = '" . $data["id"] . "';";
                $result = $DB->query($query);
            }
        }
        $query = "ALTER TABLE `glpi_plugin_financialreports_profiles`\n               DROP `name` ;";
        $result = $DB->query($query);
        Plugin::migrateItemType(array(3450 => 'PluginFinancialreportsDisposalItem'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_tickets"), array("glpi_plugin_financialreports_disposalitems"));
    }
    //Migrate profiles to the new system
    PluginFinancialreportsProfile::initProfile();
    PluginFinancialreportsProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
    $migration = new Migration("2.0.0");
    $migration->dropTable('glpi_plugin_financialreports_profiles');
    return true;
}
示例#5
0
function plugin_timelineticket_install()
{
    global $DB;
    include_once GLPI_ROOT . "/plugins/timelineticket/inc/profile.class.php";
    include_once GLPI_ROOT . "/plugins/timelineticket/inc/config.class.php";
    $migration = new Migration(160);
    // installation
    if (!TableExists("glpi_plugin_timelineticket_states")) {
        $query = "CREATE TABLE `glpi_plugin_timelineticket_states` (\n                  `id` int(11) NOT NULL AUTO_INCREMENT,\n                  `tickets_id` int(11) NOT NULL DEFAULT '0',\n                  `date` datetime DEFAULT NULL,\n                  `old_status` varchar(255) DEFAULT NULL,\n                  `new_status` varchar(255) DEFAULT NULL,\n                  `delay` INT( 11 ) NULL,\n                  PRIMARY KEY (`id`),\n                  KEY `tickets_id` (`tickets_id`)\n                ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query) or die($DB->error());
    }
    if (!TableExists("glpi_plugin_timelineticket_assigngroups")) {
        $query = "CREATE TABLE `glpi_plugin_timelineticket_assigngroups` (\n                  `id` int(11) NOT NULL AUTO_INCREMENT,\n                  `tickets_id` int(11) NOT NULL DEFAULT '0',\n                  `date` datetime DEFAULT NULL,\n                  `groups_id` varchar(255) DEFAULT NULL,\n                  `begin` INT( 11 ) NULL,\n                  `delay` INT( 11 ) NULL,\n                  PRIMARY KEY (`id`),\n                  KEY `tickets_id` (`tickets_id`)\n                ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query) or die($DB->error());
    }
    if (!TableExists("glpi_plugin_timelineticket_assignusers")) {
        $query = "CREATE TABLE `glpi_plugin_timelineticket_assignusers` (\n                  `id` int(11) NOT NULL AUTO_INCREMENT,\n                  `tickets_id` int(11) NOT NULL DEFAULT '0',\n                  `date` datetime DEFAULT NULL,\n                  `users_id` varchar(255) DEFAULT NULL,\n                  `begin` INT(11) NULL,\n                  `delay` INT(11) NULL,\n                  PRIMARY KEY (`id`),\n                  KEY `tickets_id` (`tickets_id`)\n                ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query) or die($DB->error());
    }
    if (!TableExists("glpi_plugin_timelineticket_grouplevels")) {
        $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_timelineticket_grouplevels` (\n               `id` int(11) NOT NULL AUTO_INCREMENT,\n               `entities_id` int(11) NOT NULL DEFAULT '0',\n               `is_recursive` tinyint(1) NOT NULL default '0',\n               `name` varchar(255) collate utf8_unicode_ci default NULL,\n               `groups` longtext collate utf8_unicode_ci,\n               `rank` smallint(6) NOT NULL default '0',\n               `comment` 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());
    }
    if (!TableExists("glpi_plugin_timelineticket_configs")) {
        $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_timelineticket_configs` (\n              `id` int(11) NOT NULL AUTO_INCREMENT,\n              `add_waiting` int(11) NOT NULL DEFAULT '1',\n              PRIMARY KEY  (`id`)\n            ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
        $DB->query($query) or die($DB->error());
    }
    $status = array('new' => Ticket::INCOMING, 'assign' => Ticket::ASSIGNED, 'plan' => Ticket::PLANNED, 'waiting' => Ticket::WAITING, 'solved' => Ticket::SOLVED, 'closed' => Ticket::CLOSED);
    // Update field in tables
    foreach (array('glpi_plugin_timelineticket_states') as $table) {
        // Migrate datas
        foreach ($status as $old => $new) {
            $query = "UPDATE `{$table}`\n                   SET `old_status` = '{$new}'\n                   WHERE `old_status` = '{$old}'";
            $DB->queryOrDie($query, "0.84 status in {$table} {$old} to {$new}");
            $query = "UPDATE `{$table}`\n                   SET `new_status` = '{$new}'\n                   WHERE `new_status` = '{$old}'";
            $DB->queryOrDie($query, "0.84 status in {$table} {$old} to {$new}");
        }
    }
    PluginTimelineticketConfig::createFirstConfig();
    if (isset($_SESSION['glpiactiveprofile']) && isset($_SESSION['glpiactiveprofile']['id'])) {
        PluginTimelineticketProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
    }
    $migration = new Migration("0.90+1.0");
    $migration->dropTable('glpi_plugin_timelineticket_profiles');
    return true;
}
示例#6
0
文件: hook.php 项目: sx3052/racks
function plugin_racks_uninstall()
{
    global $DB;
    include_once GLPI_ROOT . "/plugins/racks/inc/profile.class.php";
    include_once GLPI_ROOT . "/plugins/racks/inc/menu.class.php";
    $migration = new Migration("1.6.1");
    $tables = array("glpi_plugin_racks_racks", "glpi_plugin_racks_racks_items", "glpi_plugin_racks_itemspecifications", "glpi_plugin_racks_rackmodels", "glpi_plugin_racks_roomlocations", "glpi_plugin_racks_connections", "glpi_plugin_racks_configs", "glpi_plugin_racks_others", "glpi_plugin_racks_othermodels", "glpi_plugin_racks_racktypes", "glpi_plugin_racks_rackstates");
    foreach ($tables as $table) {
        $migration->dropTable($table);
    }
    //old versions
    $tables = array("glpi_plugin_rack", "glpi_plugin_rack_content", "glpi_plugin_rack_device_spec", "glpi_plugin_rack_profiles", "glpi_plugin_racks_profiles", "glpi_plugin_rack_config", "glpi_dropdown_plugin_rack_room_locations", "glpi_dropdown_plugin_rack_ways", "glpi_plugin_rack_others", "glpi_dropdown_plugin_rack_others_type");
    foreach ($tables as $table) {
        $migration->dropTable($table);
    }
    $tables_glpi = array("glpi_displaypreferences", "glpi_documents_items", "glpi_bookmarks", "glpi_logs", "glpi_items_tickets", "glpi_dropdowntranslations");
    foreach ($tables_glpi as $table_glpi) {
        $DB->query("DELETE FROM `{$table_glpi}` WHERE `itemtype` LIKE 'PluginRacks%';");
    }
    //Delete rights associated with the plugin
    $profileRight = new ProfileRight();
    foreach (PluginRacksProfile::getAllRights() as $right) {
        $profileRight->deleteByCriteria(array('name' => $right['field']));
    }
    PluginRacksProfile::removeRightsFromSession();
    PluginRacksProfile::removeRightsFromDB();
    PluginRacksMenu::removeRightsFromSession();
    return true;
}
示例#7
0
function plugin_pdf_uninstall()
{
    global $DB;
    $tables = array("glpi_plugin_pdf_preference", "glpi_plugin_pdf_preferences", "glpi_plugin_pdf_profiles");
    $migration = new Migration('0.84');
    foreach ($tables as $table) {
        $migration->dropTable($table);
    }
    return true;
}
示例#8
0
function plugin_positions_install()
{
    global $DB, $CFG_GLPI;
    include_once GLPI_ROOT . "/plugins/positions/inc/profile.class.php";
    if (!TableExists("glpi_plugin_positions_positions")) {
        $DB->runFile(GLPI_ROOT . "/plugins/positions/sql/empty-4.2.2.sql");
    }
    //v1.0.0 to V2.0.0
    if (TableExists("glpi_plugin_positions_positions_items") && !FieldExists("glpi_plugin_positions_positions_items", "items_id")) {
        $query = "ALTER TABLE `glpi_plugin_positions_positions` \r\n                ADD `items_id` int(11) NOT NULL default '0' COMMENT 'RELATION to various tables, according to itemtype (id)';";
        $result = $DB->query($query);
        $query = "ALTER TABLE `glpi_plugin_positions_positions` \r\n                ADD `itemtype` varchar(100) collate utf8_unicode_ci NOT NULL COMMENT 'see .class.php file';";
        $result = $DB->query($query);
        $query_ = "SELECT *\r\n                 FROM `glpi_plugin_positions_positions_items` ";
        $result_ = $DB->query($query_);
        if ($DB->numrows($result_) > 0) {
            while ($data = $DB->fetch_array($result_)) {
                $query = "UPDATE `glpi_plugin_positions_positions`\r\n                      SET `items_id` = '" . $data["items_id"] . "',\r\n                          `itemtype` = '" . $data["itemtype"] . "'\r\n                      WHERE `id` = '" . $data["id"] . "';";
                $result = $DB->query($query);
            }
        }
        $query = "DROP TABLE `glpi_plugin_positions_positions_items`;";
        $result = $DB->query($query);
    }
    //v1.0.0 to V2.0.0
    if (!TableExists("glpi_plugin_positions_infos")) {
        $query = "CREATE TABLE `glpi_plugin_positions_infos` (\r\n                  `id` int(11) NOT NULL auto_increment,\r\n                  `name` varchar(255) collate utf8_unicode_ci default NULL,\r\n                  `entities_id` int(11) NOT NULL default '0',\r\n                  `is_recursive` tinyint(1) NOT NULL default '0',\r\n                  `itemtype` varchar(100) collate utf8_unicode_ci NOT NULL COMMENT 'see .class.php file',\r\n                  `fields` text collate utf8_unicode_ci,\r\n                  `comment` text collate utf8_unicode_ci,\r\n                  `notepad` longtext collate utf8_unicode_ci,\r\n                  `date_mod` datetime NULL default NULL,\r\n                  `is_active` tinyint(1) NOT NULL DEFAULT '0',\r\n                  `is_deleted` tinyint(1) NOT NULL default '0',\r\n                  PRIMARY KEY  (`id`)\r\n               ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
        $result = $DB->query($query);
    }
    //to V3.0.0
    if (TableExists("glpi_plugin_positions_positions") && FieldExists("glpi_plugin_positions_positions", "documents_id")) {
        $query = "ALTER TABLE `glpi_plugin_positions_positions` DROP `documents_id`;";
        $result = $DB->query($query);
    }
    // Update to 4.0.1
    if (!FieldExists("glpi_plugin_positions_positions", "width") && !FieldExists("glpi_plugin_positions_positions", "height")) {
        $DB->runFile(GLPI_ROOT . "/plugins/positions/sql/update-4.0.1.sql");
    }
    //to v4.2.2
    if (!TableExists("glpi_plugin_positions_configs")) {
        //add table config
        $query = "CREATE TABLE `glpi_plugin_positions_configs` (\r\n               `id` int(11) NOT NULL auto_increment,\r\n               `use_view_all_object` tinyint(1) NOT NULL default '0',\r\n               PRIMARY KEY  (`id`)\r\n            )ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_plugin_positions_configs` (`id`,`use_view_all_object`) VALUES ('1', '0');";
        $DB->query($query);
        //add fields locations_id
        $query = "ALTER TABLE `glpi_plugin_positions_positions` \r\n                ADD `locations_id` int(11) NOT NULL default '0' COMMENT 'RELATION to table glpi_locations';";
        $result = $DB->query($query);
        include GLPI_ROOT . "/plugins/positions/sql/update_421_422.php";
        update421to422();
    }
    if (TableExists("glpi_plugin_positions_profiles")) {
        $notepad_tables = array('glpi_plugin_positions_positions');
        foreach ($notepad_tables as $t) {
            // Migrate data
            if (FieldExists($t, 'notepad')) {
                $query = "SELECT id, notepad\r\n                      FROM `{$t}`\r\n                      WHERE notepad IS NOT NULL\r\n                            AND notepad <>'';";
                foreach ($DB->request($query) as $data) {
                    $iq = "INSERT INTO `glpi_notepads`\r\n                             (`itemtype`, `items_id`, `content`, `date`, `date_mod`)\r\n                      VALUES ('PluginPositionsPosition', '" . $data['id'] . "',\r\n                              '" . addslashes($data['notepad']) . "', NOW(), NOW())";
                    $DB->queryOrDie($iq, "0.85 migrate notepad data");
                }
                $query = "ALTER TABLE `glpi_plugin_positions_positions` DROP COLUMN `notepad`;";
                $DB->query($query);
            }
        }
    }
    $rep_files_positions = GLPI_PLUGIN_DOC_DIR . "/positions";
    if (!is_dir($rep_files_positions)) {
        mkdir($rep_files_positions);
    }
    $rep_files_positions_pics = GLPI_PLUGIN_DOC_DIR . "/positions/pics";
    if (!is_dir($rep_files_positions_pics)) {
        mkdir($rep_files_positions_pics);
    }
    PluginPositionsProfile::initProfile();
    PluginPositionsProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
    $migration = new Migration("4.2.2");
    $migration->dropTable('glpi_plugin_positions_profiles');
    return true;
}
function plugin_databases_install()
{
    global $DB;
    include_once GLPI_ROOT . "/plugins/databases/inc/profile.class.php";
    $update = false;
    if (!TableExists("glpi_plugin_sgbd") && !TableExists("glpi_plugin_databases_databases")) {
        $DB->runFile(GLPI_ROOT . "/plugins/databases/sql/empty-1.7.0.sql");
    } else {
        if (TableExists("glpi_plugin_sgbd") && !TableExists("glpi_plugin_sgbd_instances")) {
            $update = true;
            $DB->runFile(GLPI_ROOT . "/plugins/databases/sql/update-1.1.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/databases/sql/update-1.2.0.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/databases/sql/update-1.2.1.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/databases/sql/update-1.3.0.sql");
        } else {
            if (TableExists("glpi_plugin_sgbd") && !TableExists("glpi_dropdown_plugin_sgbd_category")) {
                $update = true;
                $DB->runFile(GLPI_ROOT . "/plugins/databases/sql/update-1.2.0.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/databases/sql/update-1.2.1.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/databases/sql/update-1.3.0.sql");
            } else {
                if (TableExists("glpi_plugin_sgbd") && !FieldExists("glpi_plugin_sgbd", "helpdesk_visible")) {
                    $update = true;
                    $DB->runFile(GLPI_ROOT . "/plugins/databases/sql/update-1.2.1.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/databases/sql/update-1.3.0.sql");
                } else {
                    if (!TableExists("glpi_plugin_databases_databases")) {
                        $update = true;
                        $DB->runFile(GLPI_ROOT . "/plugins/databases/sql/update-1.3.0.sql");
                    }
                }
            }
        }
    }
    //from 1.3 version
    if (TableExists("glpi_plugin_databases_databases") && !FieldExists("glpi_plugin_databases_databases", "users_id_tech")) {
        $DB->runFile(GLPI_ROOT . "/plugins/databases/sql/update-1.5.0.sql");
    }
    if (TableExists("glpi_plugin_databases_profiles")) {
        $notepad_tables = array('glpi_plugin_databases_databases');
        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_databases_databases` DROP COLUMN `notepad`;";
                $DB->query($query);
            }
        }
    }
    if ($update) {
        $query_ = "SELECT *\n            FROM `glpi_plugin_databases_profiles` ";
        $result_ = $DB->query($query_);
        if ($DB->numrows($result_) > 0) {
            while ($data = $DB->fetch_array($result_)) {
                $query = "UPDATE `glpi_plugin_databases_profiles`\n                  SET `profiles_id` = '" . $data["id"] . "'\n                  WHERE `id` = '" . $data["id"] . "';";
                $result = $DB->query($query);
            }
        }
        $query = "ALTER TABLE `glpi_plugin_databases_profiles`\n               DROP `name` ;";
        $result = $DB->query($query);
        $query = "SELECT `entities_id`,`is_recursive`,`id` FROM `glpi_plugin_databases_databases` ";
        $result = $DB->query($query);
        $number = $DB->numrows($result);
        if ($number) {
            while ($data = $DB->fetch_array($result)) {
                $query = "UPDATE `glpi_plugin_databases_instances`\n                  SET `entities_id` = '" . $data["entities_id"] . "'\n                  AND `is_recursive` = '" . $data["is_recursive"] . "'\n                  WHERE `plugin_databases_databases_id` = '" . $data["id"] . "' ";
                $DB->query($query) or die($DB->error());
                $query = "UPDATE `glpi_plugin_databases_scripts`\n                  SET `entities_id` = '" . $data["entities_id"] . "'\n                  AND `is_recursive` = '" . $data["is_recursive"] . "'\n                  WHERE `plugin_databases_databases_id` = '" . $data["id"] . "' ";
                $DB->query($query) or die($DB->error());
            }
        }
        Plugin::migrateItemType(array(2400 => 'PluginDatabasesDatabase'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_items_tickets"), array("glpi_plugin_databases_databases_items"));
        Plugin::migrateItemType(array(1200 => "PluginAppliancesAppliance", 1300 => "PluginWebapplicationsWebapplication"), array("glpi_plugin_databases_databases_items"));
    }
    PluginDatabasesProfile::initProfile();
    PluginDatabasesProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
    $migration = new Migration("1.7.0");
    $migration->dropTable('glpi_plugin_databases_profiles');
    return true;
}
示例#10
0
文件: hook.php 项目: AssAB/badges
function plugin_badges_install()
{
    global $DB;
    include_once GLPI_ROOT . "/plugins/badges/inc/profile.class.php";
    $install = false;
    $update78 = false;
    $update85 = false;
    $update201 = false;
    if (!TableExists("glpi_plugin_badges") && !TableExists("glpi_plugin_badges_badgetypes")) {
        $install = true;
        $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/empty-2.0.1.sql");
    } else {
        if (TableExists("glpi_plugin_badges_users") && !TableExists("glpi_plugin_badges_default")) {
            $update78 = true;
            $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/update-1.4.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/update-1.5.0.sql");
            plugin_badges_configure15();
            $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/update-1.5.1.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/update-1.6.0.sql");
        } else {
            if (TableExists("glpi_plugin_badges_profiles") && FieldExists("glpi_plugin_badges_profiles", "interface")) {
                $update78 = true;
                $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/update-1.5.0.sql");
                plugin_badges_configure15();
                $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/update-1.5.1.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/update-1.6.0.sql");
            } else {
                if (TableExists("glpi_plugin_badges") && !FieldExists("glpi_plugin_badges", "date_mod")) {
                    $update78 = true;
                    $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/update-1.5.1.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/update-1.6.0.sql");
                } else {
                    if (!TableExists("glpi_plugin_badges_badgetypes")) {
                        $update78 = true;
                        $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/update-1.6.0.sql");
                    } else {
                        if (TableExists("glpi_plugin_badges_profiles")) {
                            $update85 = true;
                        }
                    }
                }
            }
        }
    }
    if (!TableExists("glpi_plugin_badges_requests")) {
        $update201 = true;
        $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/update-2.0.1.sql");
    }
    if ($install || $update201) {
        // Badge request notification
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginBadgesBadge' AND `name` = 'Access Badges Request'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        if (empty($itemtype)) {
            $query_id = "INSERT INTO `glpi_notificationtemplates`(`id`, `name`, `itemtype`, `date_mod`, `comment`, `css`) VALUES ('','Access Badges Request','PluginBadgesBadge', NOW(),'','');";
            $result = $DB->query($query_id) or die($DB->error());
            $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginBadgesBadge' AND `name` = 'Access Badges Request'";
            $result = $DB->query($query_id) or die($DB->error());
            $itemtype = $DB->result($result, 0, 'id');
        }
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\r\n                                 VALUES(NULL, '" . $itemtype . "', '','##badge.action## : ##badge.entity##',\r\n                        '##lang.badge.entity## :##badge.entity##\r\n                        ##FOREACHbadgerequest## \r\n                        ##lang.badgerequest.arrivaldate## : ##badgerequest.arrivaldate##\t\r\n                        ##lang.badgerequest.requester## : ##badgerequest.requester##\t\r\n                        ##lang.badgerequest.visitorfirstname## : ##badgerequest.visitorfirstname##\t\r\n                        ##lang.badgerequest.visitorrealname## : ##badgerequest.visitorrealname##\r\n                        ##lang.badgerequest.visitorsociety## : ##badgerequest.visitorsociety##\r\n                        ##ENDFOREACHbadgerequest##',\r\n                        '&lt;p&gt;##lang.badge.entity## :##badge.entity##&lt;br /&gt; &lt;br /&gt;\r\n                        ##FOREACHbadgerequest##&lt;br /&gt;\r\n                        ##lang.badgerequest.arrivaldate## : ##badgerequest.arrivaldate##&lt;br /&gt;\t\r\n                        ##lang.badgerequest.requester## : ##badgerequest.requester##&lt;br /&gt;\r\n                        ##lang.badgerequest.visitorfirstname## : ##badgerequest.visitorfirstname##&lt;br /&gt;\r\n                        ##lang.badgerequest.visitorrealname## : ##badgerequest.visitorrealname##&lt;br /&gt;\r\n                        ##lang.badgerequest.visitorsociety## : ##badgerequest.visitorsociety##&lt;br /&gt;\r\n                        ##ENDFOREACHbadgerequest##&lt;/p&gt;');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\r\n                                   VALUES (NULL, 'Access badge request', 0, 'PluginBadgesBadge', 'AccessBadgeRequest',\r\n                                          'mail','" . $itemtype . "',\r\n                                          '', 1, 1, '" . date('Y-m-d H:i:s') . "');";
        $result = $DB->query($query);
    }
    // Badge expiration alert notification
    $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginBadgesBadge' AND `name` = 'Access Badges Return'";
    $result = $DB->query($query_id) or die($DB->error());
    $itemtype = $DB->result($result, 0, 'id');
    if (empty($itemtype)) {
        $query_id = "INSERT INTO `glpi_notificationtemplates`(`id`, `name`, `itemtype`, `date_mod`, `comment`, `css`) VALUES ('','Access Badges Return','PluginBadgesBadge', NOW(),'','');";
        $result = $DB->query($query_id) or die($DB->error());
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginBadgesBadge' AND `name` = 'Access Badges Return'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
    }
    $query = "INSERT INTO `glpi_notificationtemplatetranslations`\r\n                              VALUES(NULL, '" . $itemtype . "', '','##badge.action## : ##badge.entity##',\r\n                     '##lang.badge.entity## :##badge.entity##\r\n                     ##FOREACHbadgerequest## \r\n                     ##lang.badgerequest.arrivaldate## : ##badgerequest.arrivaldate##\t\r\n                     ##lang.badgerequest.requester## : ##badgerequest.requester##\t\r\n                     ##lang.badgerequest.visitorfirstname## : ##badgerequest.visitorfirstname##\t\r\n                     ##lang.badgerequest.visitorrealname## : ##badgerequest.visitorrealname##\r\n                     ##lang.badgerequest.visitorsociety## : ##badgerequest.visitorsociety##\r\n                     ##ENDFOREACHbadgerequest##',\r\n                     '&lt;p&gt;##lang.badge.entity## :##badge.entity##&lt;br /&gt; &lt;br /&gt;\r\n                     ##FOREACHbadgerequest##&lt;br /&gt;\r\n                     ##lang.badgerequest.arrivaldate## : ##badgerequest.arrivaldate##&lt;br /&gt;\t\r\n                     ##lang.badgerequest.requester## : ##badgerequest.requester##&lt;br /&gt;\r\n                     ##lang.badgerequest.visitorfirstname## : ##badgerequest.visitorfirstname##&lt;br /&gt;\r\n                     ##lang.badgerequest.visitorrealname## : ##badgerequest.visitorrealname##&lt;br /&gt;\r\n                     ##lang.badgerequest.visitorsociety## : ##badgerequest.visitorsociety##&lt;br /&gt;\r\n                     ##ENDFOREACHbadgerequest##&lt;/p&gt;');";
    $result = $DB->query($query);
    $query = "INSERT INTO `glpi_notifications`\r\n                                VALUES (NULL, 'Access badge return', 0, 'PluginBadgesBadge', 'BadgesReturn',\r\n                                       'mail','" . $itemtype . "',\r\n                                       '', 1, 1, '" . date('Y-m-d H:i:s') . "');";
    $result = $DB->query($query);
    if ($update78) {
        $query_ = "SELECT *\r\n            FROM `glpi_plugin_badges_profiles` ";
        $result_ = $DB->query($query_);
        if ($DB->numrows($result_) > 0) {
            while ($data = $DB->fetch_array($result_)) {
                $query = "UPDATE `glpi_plugin_badges_profiles`\r\n                  SET `profiles_id` = '" . $data["id"] . "'\r\n                  WHERE `id` = '" . $data["id"] . "';";
                $result = $DB->query($query);
            }
        }
        $query = "ALTER TABLE `glpi_plugin_badges_profiles`\r\n               DROP `name` ;";
        $result = $DB->query($query);
        Plugin::migrateItemType(array(1600 => 'PluginBadgesBadge'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_items_tickets"));
    }
    if ($update85) {
        $notepad_tables = array('glpi_plugin_badges_badges');
        foreach ($notepad_tables as $t) {
            // Migrate data
            if (FieldExists($t, 'notepad')) {
                $query = "SELECT id, notepad\r\n                      FROM `{$t}`\r\n                      WHERE notepad IS NOT NULL\r\n                            AND notepad <>'';";
                foreach ($DB->request($query) as $data) {
                    $iq = "INSERT INTO `glpi_notepads`\r\n                             (`itemtype`, `items_id`, `content`, `date`, `date_mod`)\r\n                      VALUES ('" . getItemTypeForTable($t) . "', '" . $data['id'] . "',\r\n                              '" . addslashes($data['notepad']) . "', NOW(), NOW())";
                    $DB->queryOrDie($iq, "0.85 migrate notepad data");
                }
                $query = "ALTER TABLE `glpi_plugin_badges_badges` DROP COLUMN `notepad`;";
                $DB->query($query);
            }
        }
    }
    CronTask::Register('PluginBadgesBadge', 'BadgesAlert', DAY_TIMESTAMP);
    CronTask::Register('PluginBadgesReturn', 'BadgesReturnAlert', DAY_TIMESTAMP);
    PluginBadgesProfile::initProfile();
    PluginBadgesProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
    $migration = new Migration("2.0.0");
    $migration->dropTable('glpi_plugin_badges_profiles');
    return true;
}
示例#11
0
function plugin_archires_updateTo15()
{
    $migration = new Migration(15);
    $migration->changeField("glpi_plugin_archires_profiles", "is_default", "is_default", "smallint(6) NOT NULL default '0'");
    $query = "UPDATE `glpi_plugin_archires_profiles`\n             SET `is_default` = '0'\n             WHERE `is_default` = '1'";
    $DB->queryOrDie($query, __('1.5 insert into glpi_plugin_archires_profiles ', 'archires') . $DB->error());
    $query = "UPDATE `glpi_plugin_archires_profiles`\n             SET `is_default` = '1'\n             WHERE `is_default` = '2'";
    $DB->queryOrDie($query, __('1.5 insert into glpi_plugin_archires_profiles ', 'archires') . $DB->error());
    $migration->renameTable("glpi_plugin_archires_color", "glpi_plugin_archires_color_iface");
    $migration->renameTable("glpi_plugin_archires_config", "glpi_plugin_archires_image_device");
    $migration->dropTable("glpi_plugin_archires_display");
    if (!TableExists("glpi_plugin_archires_color_state")) {
        $query = "CREATE TABLE `glpi_plugin_archires_color_state` (\n                  `ID` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,\n                  `state` INT( 11 ) NOT NULL ,\n                  `color` VARCHAR( 50 ) collate utf8_unicode_ci NOT NULL\n                ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->queryOrDie($query, __('1.5 create glpi_plugin_archires_color_state ', 'archires') . $DB->error());
    }
    if (!TableExists("glpi_plugin_archires_query_location")) {
        $query = "CREATE TABLE `glpi_plugin_archires_query_location` (\n                  `ID` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,\n                  `FK_entities` int(11) NOT NULL default '0',\n                  `name` VARCHAR( 50 ) collate utf8_unicode_ci NOT NULL,\n                  `location` VARCHAR( 50 ) collate utf8_unicode_ci NOT NULL DEFAULT '0',\n                  `child` smallint(6) NOT NULL default '0',\n                  `network` INT( 11 ) NOT NULL DEFAULT '0',\n                  `status` INT( 11 ) NOT NULL DEFAULT '0',\n                  `FK_group` INT( 11 ) NOT NULL DEFAULT '0',\n                  `FK_config` INT( 11 ) NOT NULL DEFAULT '0',\n                  `FK_vlan` INT( 11 ) NOT NULL DEFAULT '0',\n                  `link` smallint(6) NOT NULL default '1',\n                  `notes` LONGTEXT,\n                  `deleted` smallint(6) NOT NULL default '0'\n                ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->queryOrDie($query, __('1.5 create glpi_plugin_archires_query_location ', 'archires') . $DB->error());
    }
    if (!TableExists("glpi_plugin_archires_query_switch")) {
        $query = "CREATE TABLE `glpi_plugin_archires_query_switch` (\n                  `ID` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,\n                  `FK_entities` int(11) NOT NULL default '0',\n                  `name` VARCHAR( 50 ) collate utf8_unicode_ci NOT NULL,\n                  `switch` INT( 11 ) NOT NULL DEFAULT '0',\n                  `network` INT( 11 ) NOT NULL DEFAULT '0',\n                  `status` INT( 11 ) NOT NULL DEFAULT '0',\n                  `FK_group` INT( 11 ) NOT NULL DEFAULT '0',\n                  `FK_config` INT( 11 ) NOT NULL DEFAULT '0',\n                  `FK_vlan` INT( 11 ) NOT NULL DEFAULT '0',\n                  `link` smallint(6) NOT NULL default '1',\n                  `notes` LONGTEXT,\n                  `deleted` smallint(6) NOT NULL default '0'\n                ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->queryOrDie($query, __('1.5 create glpi_plugin_archires_query_switch ', 'archires') . $DB->error());
    }
    if (!TableExists("glpi_plugin_archires_query_applicatifs")) {
        $query = "CREATE TABLE `glpi_plugin_archires_query_applicatifs` (\n                  `ID` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,\n                  `FK_entities` int(11) NOT NULL default '0',\n                  `name` VARCHAR( 50 ) collate utf8_unicode_ci NOT NULL,\n                  `applicatifs` INT( 11 ) NOT NULL DEFAULT '0',\n                  `network` INT( 11 ) NOT NULL DEFAULT '0',\n                  `status` INT( 11 ) NOT NULL DEFAULT '0',\n                  `FK_group` INT( 11 ) NOT NULL DEFAULT '0',\n                  `FK_config` INT( 11 ) NOT NULL DEFAULT '0',\n                  `FK_vlan` INT( 11 ) NOT NULL DEFAULT '0',\n                  `link` smallint(6) NOT NULL default '1',\n                  `notes` LONGTEXT,\n                  `deleted` smallint(6) NOT NULL default '0'\n                ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->queryOrDie($query, __('1.5 create glpi_plugin_archires_query_applicatifs ', 'archires') . $DB->error());
    }
    if (!TableExists("glpi_plugin_archires_query_type")) {
        $query = "CREATE TABLE `glpi_plugin_archires_query_type` (\n                  `ID` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,\n                  `type_query` INT( 11 ) NOT NULL ,\n                  `type` INT( 11 ) NOT NULL ,\n                  `device_type` INT( 11 ) NOT NULL,\n                  `FK_query` INT( 11 ) NOT NULL\n                ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->queryOrDie($query, __('1.5 create glpi_plugin_archires_query_type ', 'archires') . $DB->error());
    }
    if (!TableExists("glpi_plugin_archires_config")) {
        $query = "CREATE TABLE `glpi_plugin_archires_config` (\n                  `ID` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,\n                  `FK_entities` int(11) NOT NULL default '0',\n                  `name` VARCHAR( 250 ) collate utf8_unicode_ci NOT NULL,\n                  `computer` smallint(6) NOT NULL default '0',\n                  `networking` smallint(6) NOT NULL default '0',\n                  `printer` smallint(6) NOT NULL default '0',\n                  `peripheral` smallint(6) NOT NULL default '0',\n                  `phone` smallint(6) NOT NULL default '0',\n                  `display_ports` smallint(6) NOT NULL default '0',\n                  `display_ip` smallint(6) NOT NULL default '0',\n                  `display_type` smallint(6) NOT NULL default '0',\n                  `display_state` smallint(6) NOT NULL default '0',\n                  `display_location` smallint(6) NOT NULL default '0',\n                  `display_entity` smallint(6) NOT NULL default '0',\n                  `system` smallint(6) NOT NULL default '0',\n                  `engine` smallint(6) NOT NULL default '0',\n                  `format` smallint(6) NOT NULL default '0',\n                  `deleted` smallint(6) NOT NULL default '0'\n                ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->queryOrDie($query, __('1.5 create glpi_plugin_archires_config ', 'archires') . $DB->error());
    }
    $query = "INSERT INTO `glpi_plugin_archires_config`\n                    (`ID`,`FK_entities`,`name`, `computer` , `networking`, `printer`, `peripheral`,\n                     `phone`, `display_ports`, `display_ip`, `display_type`, `display_state`,\n                     `display_location`, `display_entity`, `system`,`engine`, `format`)\n             VALUES ('1', '0', 'default', '1', '1', '1', '1', '1', '0', '0', '0', '0', '0', '0',\n                     '0', '0', '1')";
    $DB->queryOrDie($query, __('1.5 insert into glpi_plugin_archires_config ', 'archires') . $DB->error());
    $query = "INSERT INTO `glpi_displaypreferences`\n                    (`ID` , `type` , `num` , `rank` , `FK_users` )\n             VALUES (NULL, '3000', '2', '1', '0'),\n                    (NULL, '3000', '3', '2', '0'),\n                    (NULL, '3000', '4', '3', '0'),\n                    (NULL, '3000', '5', '4', '0'),\n                    (NULL, '3000', '6', '5', '0'),\n                    (NULL, '3000', '7', '6', '0'),\n                    (NULL, '3000', '8', '7', '0'),\n                    (NULL, '3000', '9', '8', '0'),\n                    (NULL, '3001', '2', '1', '0'),\n                    (NULL, '3001', '3', '2', '0'),\n                    (NULL, '3001', '4', '3', '0'),\n                    (NULL, '3001', '5', '4', '0'),\n                    (NULL, '3001', '6', '5', '0'),\n                    (NULL, '3001', '7', '6', '0'),\n                    (NULL, '3001', '8', '7', '0'),\n                    (NULL, '3002', '2', '1', '0'),\n                    (NULL, '3002', '3', '2', '0'),\n                    (NULL, '3002', '4', '3', '0'),\n                    (NULL, '3002', '5', '4', '0'),\n                    (NULL, '3002', '6', '5', '0'),\n                    (NULL, '3002', '7', '6', '0'),\n                    (NULL, '3002', '8', '7', '0')";
    $DB->queryOrDie($query, __('1.5 insert into glpi_displaypreferences ', 'archires') . $DB->error());
    $migration->executeMigration();
}
示例#12
0
 public static function install(Migration $migration)
 {
     global $DB;
     if (TableExists("glpi_plugin_order_profiles") && !FieldExists("glpi_plugin_order_profiles", "plugin_order_generate_order_without_validation")) {
         $DB->query("ALTER TABLE `glpi_plugin_order_profiles` ADD `plugin_order_generate_order_without_validation` char(1) default NULL;");
     }
     self::initProfile();
     self::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
     $migration->dropTable('glpi_plugin_order_profiles');
     //if (TableExists("glpi_plugin_order_profiles")){
     //   $DB->query("DROP TABLE `glpi_plugin_order_profiles`;");
     //}
 }
示例#13
0
 /**
  *  Add and save all models from specified file
  *
  * @param $inputFile
  */
 public function addAllModelsFromFile($inputFile)
 {
     $oldModelFile = array();
     // Get the cached model definitions file to compare against
     if (\File::exists($this->getModelCacheFile())) {
         $cachedFile = file($this->getModelCacheFile());
         $oldModelFile = $this->getCachedModels($cachedFile, false);
     }
     // Loop through the file and create all associated files
     foreach ($inputFile as $line_num => $modelAndProperties) {
         $modelAndProperties = trim($modelAndProperties);
         if (!empty($modelAndProperties)) {
             if (preg_match("/^resource =/", $modelAndProperties)) {
                 $this->isResource = trim(substr($modelAndProperties, strpos($modelAndProperties, "=") + 1));
                 continue;
             }
             if (preg_match("/^namespace =/", $modelAndProperties)) {
                 $this->namespaceGlobal = true;
                 $this->namespace = trim(substr($modelAndProperties, strpos($modelAndProperties, "=") + 1));
                 $this->fileCreator->namespace = $this->namespace;
                 continue;
             }
             $this->saveModelAndProperties($modelAndProperties, $oldModelFile);
             $this->createFiles();
         }
     }
     // If any models existed in the cached file,
     // and not in the current file, drop that table
     foreach ($oldModelFile as $tableName => $modelData) {
         if (!array_key_exists($tableName, $this->models)) {
             $migration = new Migration($this->configSettings['pathTo']['migrations'], $modelData['model'], $this->fileCreator);
             $migration->dropTable($this->lastTimeStamp);
         }
     }
     copy($this->configSettings['modelDefinitionsFile'], $this->getModelCacheFile());
 }
 static function uninstall(Migration $migration)
 {
     $migration->dropTable(getTableForItemType(__CLASS__));
 }
function plugin_racks_uninstall()
{
    include_once GLPI_ROOT . "/plugins/racks/inc/profile.class.php";
    include_once GLPI_ROOT . "/plugins/racks/inc/menu.class.php";
    $migration = new Migration("1.5.0");
    $tables = array("glpi_plugin_racks_racks", "glpi_plugin_racks_racks_items", "glpi_plugin_racks_itemspecifications", "glpi_plugin_racks_rackmodels", "glpi_plugin_racks_roomlocations", "glpi_plugin_racks_connections", "glpi_plugin_racks_configs", "glpi_plugin_racks_others", "glpi_plugin_racks_othermodels", "glpi_plugin_racks_racktypes", "glpi_plugin_racks_rackstates");
    foreach ($tables as $table) {
        $migration->dropTable($table);
    }
    //old versions
    $tables = array("glpi_plugin_rack", "glpi_plugin_rack_content", "glpi_plugin_rack_device_spec", "glpi_plugin_rack_profiles", "glpi_plugin_racks_profiles", "glpi_plugin_rack_config", "glpi_dropdown_plugin_rack_room_locations", "glpi_dropdown_plugin_rack_ways", "glpi_plugin_rack_others", "glpi_dropdown_plugin_rack_others_type");
    foreach ($tables as $table) {
        $migration->dropTable($table);
    }
    $itemtypes = array("DisplayPreference", "Document_Item", "Bookmark", "Log", "Ticket");
    foreach ($itemtypes as $itemtype) {
        $item = new $itemtype();
        $item->deleteByCriteria(array('itemtype' => 'PluginRacksRack'));
    }
    //Delete rights associated with the plugin
    $profileRight = new ProfileRight();
    foreach (PluginRacksProfile::getAllRights() as $right) {
        $profileRight->deleteByCriteria(array('name' => $right['field']));
    }
    PluginRacksProfile::removeRightsFromSession();
    PluginRacksProfile::removeRightsFromDB();
    PluginRacksMenu::removeRightsFromSession();
    return true;
}
示例#16
0
function plugin_accounts_install()
{
    global $DB, $CFG_GLPI;
    include_once GLPI_ROOT . "/plugins/accounts/inc/profile.class.php";
    $install = false;
    $update78 = false;
    $update80 = false;
    $update171 = false;
    if (!TableExists("glpi_plugin_compte") && !TableExists("glpi_plugin_comptes") && !TableExists("glpi_comptes") && !TableExists("glpi_plugin_accounts_accounts")) {
        $install = true;
        $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/empty-2.0.0.sql");
    } else {
        if (TableExists("glpi_comptes") && !FieldExists("glpi_comptes", "notes")) {
            $update78 = true;
            $update80 = true;
            $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.1.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.3.sql");
            plugin_accounts_updatev14();
            $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.0.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.1.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.3.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.6.0.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.0.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.1.sql");
            $_SESSION['plugin_acounts_upgrading'] = 1;
        } else {
            if (TableExists("glpi_plugin_comptes") && !FieldExists("glpi_plugin_comptes", "all_users")) {
                $update78 = true;
                $update80 = true;
                $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.3.sql");
                plugin_accounts_updatev14();
                $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.0.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.1.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.3.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.6.0.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.0.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.1.sql");
                $_SESSION['plugin_acounts_upgrading'] = 1;
            } else {
                if (TableExists("glpi_plugin_compte_profiles") && !FieldExists("glpi_plugin_compte_profiles", "my_groups")) {
                    $update78 = true;
                    $update80 = true;
                    plugin_accounts_updatev14();
                    $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.0.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.1.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.3.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.6.0.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.0.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.1.sql");
                    $_SESSION['plugin_acounts_upgrading'] = 1;
                } else {
                    if (TableExists("glpi_plugin_compte_profiles") && FieldExists("glpi_plugin_compte_profiles", "interface")) {
                        $update78 = true;
                        $update80 = true;
                        $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.0.sql");
                        $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.1.sql");
                        $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.3.sql");
                        $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.6.0.sql");
                        $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.0.sql");
                        $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.1.sql");
                        $_SESSION['plugin_acounts_upgrading'] = 1;
                    } else {
                        if (TableExists("glpi_plugin_compte") && !FieldExists("glpi_plugin_compte", "date_mod")) {
                            $update78 = true;
                            $update80 = true;
                            $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.1.sql");
                            $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.3.sql");
                            $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.6.0.sql");
                            $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.0.sql");
                            $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.1.sql");
                        } else {
                            if (TableExists("glpi_plugin_compte") && !TableExists("glpi_plugin_compte_aeskey")) {
                                $update78 = true;
                                $update80 = true;
                                $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.3.sql");
                                $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.6.0.sql");
                                $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.0.sql");
                                $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.1.sql");
                            } else {
                                if (TableExists("glpi_plugin_compte") && !TableExists("glpi_plugin_accounts_accounts")) {
                                    $update78 = true;
                                    $update80 = true;
                                    $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.6.0.sql");
                                    $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.0.sql");
                                    $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.1.sql");
                                } else {
                                    if (TableExists("glpi_plugin_accounts_accounts") && !FieldExists("glpi_plugin_accounts_accounts", "locations_id")) {
                                        $update80 = true;
                                        $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.0.sql");
                                        $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.1.sql");
                                    } else {
                                        if (TableExists("glpi_plugin_accounts_hashes") && !FieldExists("glpi_plugin_accounts_hashes", "entities_id")) {
                                            $update171 = true;
                                            $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.1.sql");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    //from 1.6 version
    if (TableExists("glpi_plugin_accounts_accounts") && !FieldExists("glpi_plugin_accounts_accounts", "users_id_tech")) {
        $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.8.0.sql");
    }
    //from 1.9 version
    if (TableExists("glpi_plugin_accounts_accounttypes") && !FieldExists("glpi_plugin_accounts_accounttypes", "is_recursive")) {
        $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.9.0.sql");
    }
    if ($install || $update78) {
        //Do One time on 0.78
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates`\n               WHERE `itemtype`='PluginAccountsAccount'\n               AND `name` = 'New Accounts'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n               VALUES(NULL, " . $itemtype . ", '','##lang.account.title##',\n                        '##lang.account.url## : ##account.url##\r\n\r\n\n                        ##lang.account.entity## : ##account.entity##\r\n\n                        ##IFaccount.name####lang.account.name## : ##account.name##\r\n##ENDIFaccount.name##\n                        ##IFaccount.type####lang.account.type## : ##account.type##\r\n##ENDIFaccount.type##\n                        ##IFaccount.state####lang.account.state## : ##account.state##\r\n##ENDIFaccount.state##\n                        ##IFaccount.login####lang.account.login## : ##account.login##\r\n##ENDIFaccount.login##\n                        ##IFaccount.users_id####lang.account.users_id## : ##account.users_id##\r\n##ENDIFaccount.users_id##\n                        ##IFaccount.groups_id####lang.account.groups_id## : ##account.groups_id##\r\n##ENDIFaccount.groups_id##\n                        ##IFaccount.others####lang.account.others## : ##account.others##\r\n##ENDIFaccount.others##\n                        ##IFaccount.datecreation####lang.account.datecreation## : ##account.datecreation##\r\n##ENDIFaccount.datecreation##\n                        ##IFaccount.dateexpiration####lang.account.dateexpiration## : ##account.dateexpiration##\r\n##ENDIFaccount.dateexpiration##\n                        ##IFaccount.comment####lang.account.comment## : ##account.comment##\r\n##ENDIFaccount.comment##',\n                        '&lt;p&gt;&lt;strong&gt;##lang.account.url##&lt;/strong&gt; : &lt;a href=\"##account.url##\"&gt;##account.url##&lt;/a&gt;&lt;/p&gt;\n                        &lt;p&gt;&lt;strong&gt;##lang.account.entity##&lt;/strong&gt; : ##account.entity##&lt;br /&gt; ##IFaccount.name##&lt;strong&gt;##lang.account.name##&lt;/strong&gt; : ##account.name##&lt;br /&gt;##ENDIFaccount.name##  ##IFaccount.type##&lt;strong&gt;##lang.account.type##&lt;/strong&gt; : ##account.type##&lt;br /&gt;##ENDIFaccount.type##  ##IFaccount.state##&lt;strong&gt;##lang.account.state##&lt;/strong&gt; : ##account.state##&lt;br /&gt;##ENDIFaccount.state##  ##IFaccount.login##&lt;strong&gt;##lang.account.login##&lt;/strong&gt; : ##account.login##&lt;br /&gt;##ENDIFaccount.login##  ##IFaccount.users##&lt;strong&gt;##lang.account.users##&lt;/strong&gt; : ##account.users##&lt;br /&gt;##ENDIFaccount.users##  ##IFaccount.groups##&lt;strong&gt;##lang.account.groups##&lt;/strong&gt; : ##account.groups##&lt;br /&gt;##ENDIFaccount.groups##  ##IFaccount.others##&lt;strong&gt;##lang.account.others##&lt;/strong&gt; : ##account.others##&lt;br /&gt;##ENDIFaccount.others##  ##IFaccount.datecreation##&lt;strong&gt;##lang.account.datecreation##&lt;/strong&gt; : ##account.datecreation##&lt;br /&gt;##ENDIFaccount.datecreation##  ##IFaccount.dateexpiration##&lt;strong&gt;##lang.account.dateexpiration##&lt;/strong&gt; : ##account.dateexpiration##&lt;br /&gt;##ENDIFaccount.dateexpiration##  ##IFaccount.comment##&lt;strong&gt;##lang.account.comment##&lt;/strong&gt; : ##account.comment####ENDIFaccount.comment##&lt;/p&gt;');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n               VALUES (NULL, 'New Accounts', 0, 'PluginAccountsAccount', 'new',\n               'mail'," . $itemtype . ",\n                        '', 1, 1, '2010-02-17 22:36:46');";
        $result = $DB->query($query);
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates`\n               WHERE `itemtype`='PluginAccountsAccount'\n               AND `name` = 'Alert Accounts'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n               VALUES(NULL, " . $itemtype . ", '','##account.action## : ##account.entity##',\n                        '##lang.account.entity## :##account.entity##\n                        ##FOREACHaccounts##\n                        ##lang.account.name## : ##account.name## - ##lang.account.dateexpiration## : ##account.dateexpiration##\n                        ##ENDFOREACHaccounts##',\n                        '&lt;p&gt;##lang.account.entity## :##account.entity##&lt;br /&gt; &lt;br /&gt;\n                        ##FOREACHaccounts##&lt;br /&gt;\n                        ##lang.account.name##  : ##account.name## - ##lang.account.dateexpiration## :  ##account.dateexpiration##&lt;br /&gt;\n                        ##ENDFOREACHaccounts##&lt;/p&gt;');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n               VALUES (NULL, 'Alert Expired Accounts', 0, 'PluginAccountsAccount', 'ExpiredAccounts',\n               'mail'," . $itemtype . ",\n                        '', 1, 1, '2010-02-17 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n               VALUES (NULL, 'Alert Accounts Which Expire', 0, 'PluginAccountsAccount', 'AccountsWhichExpire',\n               'mail'," . $itemtype . ",\n                        '', 1, 1, '2010-02-17 22:36:46');";
        $result = $DB->query($query);
    }
    if ($update78) {
        //Do One time on 0.78
        $query_ = "SELECT *\n               FROM `glpi_plugin_accounts_profiles` ";
        $result_ = $DB->query($query_);
        if ($DB->numrows($result_) > 0) {
            while ($data = $DB->fetch_array($result_)) {
                $query = "UPDATE `glpi_plugin_accounts_profiles`\n                     SET `profiles_id` = '" . $data["id"] . "'\n                              WHERE `id` = '" . $data["id"] . "';";
                $result = $DB->query($query);
            }
        }
        $query = "ALTER TABLE `glpi_plugin_accounts_profiles`\n               DROP `name` ;";
        $result = $DB->query($query);
        Plugin::migrateItemType(array(1900 => 'PluginAccountsAccount', 1901 => 'PluginAccountsHelpdesk', 1902 => 'PluginAccountsGroup'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_items_tickets"), array("glpi_plugin_accounts_accounts_items"));
        Plugin::migrateItemType(array(1200 => "PluginAppliancesAppliance", 1300 => "PluginWebapplicationsWebapplication", 1700 => "PluginCertificatesCertificate", 4400 => "PluginDomainsDomain", 2400 => "PluginDatabasesDatabase"), array("glpi_plugin_accounts_accounts_items"));
    }
    if ($update171) {
        $query = "UPDATE `glpi_plugin_accounts_hashes`\n               SET `is_recursive` = '1'\n               WHERE `id` = '1';";
        $result = $DB->query($query);
        $query = "UPDATE `glpi_plugin_accounts_aeskeys`\n               SET `plugin_accounts_hashes_id` = '1'\n               WHERE `id` = '1';";
        $result = $DB->query($query);
    }
    if (isset($_SESSION['plugin_acounts_upgrading'])) {
        $msg = __('After plugin installation, you must do upgrade of your passwords from here : ', 'accounts');
        $msg .= "<a href='" . $CFG_GLPI["root_doc"] . "/plugins/accounts/front/upgrade.form.php'>" . __('Upgrading page', 'accounts') . "</a>";
        Session::addMessageAfterRedirect($msg, ERROR);
    }
    $notepad_tables = array('glpi_plugin_accounts_accounts');
    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_accounts_accounts` DROP COLUMN `notepad`;";
            $DB->query($query);
        }
    }
    CronTask::Register('PluginAccountsAccount', 'AccountsAlert', DAY_TIMESTAMP);
    PluginAccountsProfile::initProfile();
    PluginAccountsProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
    $migration = new Migration("2.0.0");
    $migration->dropTable('glpi_plugin_accounts_profiles');
    return true;
}
function plugin_addressing_uninstall()
{
    global $DB;
    include_once GLPI_ROOT . "/plugins/addressing/inc/profile.class.php";
    include_once GLPI_ROOT . "/plugins/addressing/inc/menu.class.php";
    $migration = new Migration("2.2.0");
    $tables = array("glpi_plugin_addressing_addressings", "glpi_plugin_addressing_configs");
    foreach ($tables as $table) {
        $migration->dropTable($table);
    }
    $itemtypes = array('DisplayPreference', 'Bookmark');
    foreach ($itemtypes as $itemtype) {
        $item = new $itemtype();
        $item->deleteByCriteria(array('itemtype' => 'PluginAddressingAddressing'));
    }
    //Delete rights associated with the plugin
    $profileRight = new ProfileRight();
    foreach (PluginAddressingProfile::getAllRights() as $right) {
        $profileRight->deleteByCriteria(array('name' => $right['field']));
    }
    //Remove rigth from $_SESSION['glpiactiveprofile'] if exists
    PluginAddressingProfile::removeRightsFromSession();
    PluginAddressingMenu::removeRightsFromSession();
    return true;
}
示例#18
0
function plugin_datainjection_update170_20()
{
    global $DB;
    $migration = new Migration('2.0');
    $migration->changeField('glpi_plugin_datainjection_models', 'ID', 'id', 'autoincrement');
    $migration->changeField('glpi_plugin_datainjection_models', 'type', 'filetype', 'string', array('value' => 'csv'));
    $migration->addField('glpi_plugin_datainjection_models', 'step', 'integer');
    $migration->changeField('glpi_plugin_datainjection_models', 'comments', 'comment', 'text');
    $migration->changeField('glpi_plugin_datainjection_models', 'device_type', 'itemtype', 'string', array('value' => ''));
    $migration->changeField('glpi_plugin_datainjection_models', 'FK_entities', 'entities_id', 'integer');
    $migration->changeField('glpi_plugin_datainjection_models', 'private', 'is_private', 'bool');
    $migration->changeField('glpi_plugin_datainjection_models', 'FK_users', 'users_id', 'integer');
    $migration->changeField('glpi_plugin_datainjection_models', 'recursive', 'is_recursive', 'bool');
    $migration->migrationOneTable('glpi_plugin_datainjection_models');
    $query = "UPDATE `glpi_plugin_datainjection_models`\n             SET `step` = '5'";
    $DB->query($query);
    $query = "UPDATE `glpi_plugin_datainjection_models`\n             SET `filetype` = 'csv'";
    $DB->queryOrDie($query, "update filetype of glpi_plugin_datainjection_models");
    $migration->dropTable('glpi_plugin_datainjection_filetype');
    $migration->renameTable('glpi_plugin_datainjection_models_csv', 'glpi_plugin_datainjection_modelcsvs');
    $migration->changeField('glpi_plugin_datainjection_modelcsvs', 'model_id', 'models_id', 'integer');
    $migration->changeField('glpi_plugin_datainjection_modelcsvs', 'device_type', 'itemtype', 'string', array('value' => ''));
    $migration->changeField('glpi_plugin_datainjection_modelcsvs', 'header_present', 'is_header_present', 'bool', array('value' => 1));
    $migration->changeField('glpi_plugin_datainjection_mappings', 'mandatory', 'is_mandatory', 'bool');
    $migration->changeField('glpi_plugin_datainjection_mappings', 'type', 'itemtype', 'string', array('value' => ''));
    $migration->changeField('glpi_plugin_datainjection_mappings', 'model_id', 'models_id', 'integer');
    $migration->changeField('glpi_plugin_datainjection_infos', 'type', 'itemtype', 'string', array('value' => ''));
    $migration->changeField('glpi_plugin_datainjection_infos', 'model_id', 'models_id', 'integer');
    $migration->changeField('glpi_plugin_datainjection_infos', 'mandatory', 'is_mandatory', 'bool');
    $glpitables = array('glpi_plugin_datainjection_models', 'glpi_plugin_datainjection_mappings', 'glpi_plugin_datainjection_infos', 'glpi_plugin_datainjection_modelcsvs', 'glpi_plugin_datainjection_profiles');
    foreach ($glpitables as $table) {
        $migration->changeField($table, 'ID', 'id', 'autoincrement');
    }
    $migration->migrationOneTable('glpi_plugin_datainjection_mappings');
    $migration->migrationOneTable('glpi_plugin_datainjection_infos');
    $migration->migrationOneTable('glpi_plugin_datainjection_modelcsvs');
    $glpitables = array('glpi_plugin_datainjection_models', 'glpi_plugin_datainjection_mappings', 'glpi_plugin_datainjection_infos', 'glpi_plugin_datainjection_modelcsvs');
    Plugin::migrateItemType(array(), array(), $glpitables);
    $query = "UPDATE `glpi_plugin_datainjection_mappings`\n             SET `itemtype` = 'none' ,\n                 `value`='none'\n             WHERE `itemtype` = '-1'";
    $DB->queryOrDie($query, "Datainjection mappings tables : error updating not mapped fields");
    $migration->migrationOneTable('glpi_plugin_datainjection_infos');
    $query = "UPDATE `glpi_plugin_datainjection_infos`\n             SET `itemtype` = 'none', `value` = 'none'\n             WHERE `itemtype` = '-1'";
    $DB->queryOrDie($query, "Datainjection infos table : error updating not mapped fields");
    $foreignkeys = array('assign' => array(array('to' => 'users_id_assign', 'tables' => array('glpi_tickets'))), 'assign_group' => array(array('to' => 'groups_id_assign', 'tables' => array('glpi_tickets'))), 'assign_ent' => array(array('to' => 'suppliers_id_assign', 'tables' => array('glpi_tickets'))), 'auth_method' => array(array('to' => 'authtype', 'noindex' => array('glpi_users'), 'tables' => array('glpi_users'))), 'author' => array(array('to' => 'users_id', 'tables' => array('glpi_ticketfollowups', 'glpi_knowbaseitems', 'glpi_tickets'))), 'auto_update' => array(array('to' => 'autoupdatesystems_id', 'tables' => array('glpi_computers'))), 'budget' => array(array('to' => 'budgets_id', 'tables' => array('glpi_infocoms'))), 'buy_version' => array(array('to' => 'softwareversions_id_buy', 'tables' => array('glpi_softwarelicenses'))), 'category' => array(array('to' => 'ticketcategories_id', 'tables' => array('glpi_tickets')), array('to' => 'softwarecategories_id', 'tables' => array('glpi_softwares'))), 'categoryID' => array(array('to' => 'knowbaseitemcategories_id', 'tables' => array('glpi_knowbaseitems'))), 'cID' => array(array('to' => 'computers_id', 'tables' => array('glpi_computers_softwareversions'))), 'computer' => array(array('to' => 'items_id', 'tables' => array('glpi_tickets'))), 'computer_id' => array(array('to' => 'computers_id', 'tables' => array('glpi_registrykeys'))), 'contract_type' => array(array('to' => 'contracttypes_id', 'tables' => array('glpi_contracts'))), 'default_rubdoc_tracking' => array(array('to' => 'documentcategories_id_forticket', 'tables' => array('glpi_configs'), 'comments' => array('glpi_configs' => 'default category for documents added with a ticket'))), 'device_type' => array(array('to' => 'itemtype', 'tables' => array('glpi_alerts', 'glpi_contracts_items', 'glpi_documents_items', 'glpi_infocoms', 'glpi_bookmarks', 'glpi_bookmarks_users', 'glpi_links_itemtypes', 'glpi_networkports', 'glpi_reservationitems', 'glpi_tickets'))), 'domain' => array(array('to' => 'domains_id', 'tables' => array('glpi_computers', 'glpi_networkequipments', 'glpi_printers'))), 'end1' => array(array('to' => 'items_id', 'tables' => array('glpi_computers_items'), 'comments' => array('glpi_computers_items' => 'RELATION to various table, according to itemtype (ID)')), array('to' => 'networkports_id_1', 'tables' => array('glpi_networkports_networkports'))), 'end2' => array(array('to' => 'computers_id', 'tables' => array('glpi_computers_items')), array('to' => 'networkports_id_2', 'tables' => array('glpi_networkports_networkports'))), 'firmware' => array(array('to' => 'networkequipmentfirmwares_id', 'tables' => array('glpi_networkequipments'))), 'FK_bookmark' => array(array('to' => 'bookmarks_id', 'tables' => array('glpi_bookmarks_users'))), 'FK_computers' => array(array('to' => 'computers_id', 'tables' => array('glpi_computerdisks', 'glpi_softwarelicenses'))), 'FK_contact' => array(array('to' => 'contacts_id', 'tables' => array('glpi_contacts_suppliers'))), 'FK_contract' => array(array('to' => 'contracts_id', 'tables' => array('glpi_contracts_suppliers', 'glpi_contracts_items'))), 'FK_device' => array(array('to' => 'items_id', 'tables' => array('glpi_alerts', 'glpi_contracts_items', 'glpi_documents_items', 'glpi_infocoms'))), 'FK_doc' => array(array('to' => 'documents_id', 'tables' => array('glpi_documents_items'))), 'manufacturer' => array(array('to' => 'suppliers_id', 'tables' => array('glpi_contacts_suppliers', 'glpi_contracts_suppliers', 'glpi_infocoms')), array('to' => 'manufacturers_id', 'tables' => array('glpi_cartridgeitems', 'glpi_computers', 'glpi_consumableitems', 'glpi_devicecases', 'glpi_devicecontrols', 'glpi_devicedrives', 'glpi_devicegraphiccards', 'glpi_deviceharddrives', 'glpi_devicenetworkcards', 'glpi_devicemotherboards', 'glpi_devicepcis', 'glpi_devicepowersupplies', 'glpi_deviceprocessors', 'glpi_devicememories', 'glpi_devicesoundcards', 'glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_softwares'))), 'FK_entities' => array(array('to' => 'entities_id', 'tables' => array('glpi_bookmarks', 'glpi_cartridgeitems', 'glpi_computers', 'glpi_consumableitems', 'glpi_contacts', 'glpi_contracts', 'glpi_documents', 'glpi_locations', 'glpi_netpoints', 'glpi_suppliers', 'glpi_entitydatas', 'glpi_groups', 'glpi_knowbaseitems', 'glpi_links', 'glpi_mailcollectors', 'glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_reminders', 'glpi_rules', 'glpi_softwares', 'glpi_softwarelicenses', 'glpi_softwareversions', 'glpi_tickets', 'glpi_users', 'glpi_profiles_users'), 'default' => array('glpi_bookmarks' => "-1"))), 'FK_filesystems' => array(array('to' => 'filesystems_id', 'tables' => array('glpi_computerdisks'))), 'FK_glpi_cartridges_type' => array(array('to' => 'cartridgeitems_id', 'tables' => array('glpi_cartridges', 'glpi_cartridges_printermodels'))), 'FK_glpi_consumables_type' => array(array('to' => 'consumableitems_id', 'tables' => array('glpi_consumables'))), 'FK_glpi_dropdown_model_printers' => array(array('to' => 'printermodels_id', 'tables' => array('glpi_cartridges_printermodels'))), 'FK_glpi_printers' => array(array('to' => 'printers_id', 'tables' => array('glpi_cartridges'))), 'FK_group' => array(array('to' => 'groups_id', 'tables' => array('glpi_tickets'))), 'FK_groups' => array(array('to' => 'groups_id', 'tables' => array('glpi_computers', 'glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_softwares', 'glpi_groups_users'))), 'FK_interface' => array(array('to' => 'interfacetypes_id', 'tables' => array('glpi_devicegraphiccards'))), 'FK_item' => array(array('to' => 'items_id', 'tables' => array('glpi_mailingsettings'))), 'FK_links' => array(array('to' => 'links_id', 'tables' => array('glpi_links_itemtypes'))), 'FK_port' => array(array('to' => 'networkports_id', 'tables' => array('glpi_networkports_vlans'))), 'FK_profiles' => array(array('to' => 'profiles_id', 'tables' => array('glpi_profiles_users', 'glpi_users'))), 'FK_users' => array(array('to' => 'users_id', 'tables' => array('glpi_bookmarks', 'glpi_displaypreferences', 'glpi_documents', 'glpi_groups', 'glpi_reminders', 'glpi_bookmarks_users', 'glpi_groups_users', 'glpi_profiles_users', 'glpi_computers', 'glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_softwares'))), 'FK_vlan' => array(array('to' => 'vlans_id', 'tables' => array('glpi_networkports_vlans'))), 'glpi_id' => array(array('to' => 'computers_id', 'tables' => array('glpi_ocslinks'))), 'id_assign' => array(array('to' => 'users_id', 'tables' => array('glpi_ticketplannings'))), 'id_auth' => array(array('to' => 'auths_id', 'tables' => array('glpi_users'))), 'id_device' => array(array('to' => 'items_id', 'tables' => array('glpi_reservationitems'))), 'id_item' => array(array('to' => 'reservationitems_id', 'tables' => array('glpi_reservations'))), 'id_user' => array(array('to' => 'users_id', 'tables' => array('glpi_consumables', 'glpi_reservations'))), 'iface' => array(array('to' => 'networkinterfaces_id', 'tables' => array('glpi_networkports'))), 'interface' => array(array('to' => 'interfacetypes_id', 'tables' => array('glpi_devicecontrols', 'glpi_deviceharddrives', 'glpi_devicedrives'))), 'location' => array(array('to' => 'locations_id', 'tables' => array('glpi_cartridgeitems', 'glpi_computers', 'glpi_consumableitems', 'glpi_netpoints', 'glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_users', 'glpi_softwares'))), 'model' => array(array('to' => 'computermodels_id', 'tables' => array('glpi_computers')), array('to' => 'monitormodels_id', 'tables' => array('glpi_monitors')), array('to' => 'networkequipmentmodels_id', 'tables' => array('glpi_networkequipments')), array('to' => 'peripheralmodels_id', 'tables' => array('glpi_peripherals')), array('to' => 'phonemodels_id', 'tables' => array('glpi_phones')), array('to' => 'printermodels_id', 'tables' => array('glpi_printers'))), 'netpoint' => array(array('to' => 'netpoints_id', 'tables' => array('glpi_networkports'))), 'network' => array(array('to' => 'networks_id', 'tables' => array('glpi_computers', 'glpi_networkequipments', 'glpi_printers'))), 'on_device' => array(array('to' => 'items_id', 'tables' => array('glpi_networkports'))), 'os' => array(array('to' => 'operatingsystems_id', 'tables' => array('glpi_computers'))), 'os_license_id' => array(array('to' => 'os_licenseid', 'tables' => array('glpi_computers'))), 'os_version' => array(array('to' => 'operatingsystemversions_id', 'tables' => array('glpi_computers'))), 'parentID' => array(array('to' => 'knowbaseitemcategories_id', 'tables' => array('glpi_knowbaseitemcategories')), array('to' => 'locations_id', 'tables' => array('glpi_locations')), array('to' => 'ticketcategories_id', 'tables' => array('glpi_ticketcategories')), array('to' => 'entities_id', 'tables' => array('glpi_entities'))), 'platform' => array(array('to' => 'operatingsystems_id', 'tables' => array('glpi_softwares'))), 'power' => array(array('to' => 'phonepowersupplies_id', 'tables' => array('glpi_phones'))), 'recipient' => array(array('to' => 'users_id_recipient', 'tables' => array('glpi_tickets'))), 'rubrique' => array(array('to' => 'documentcategories_id', 'tables' => array('glpi_documents'))), 'sID' => array(array('to' => 'softwares_id', 'tables' => array('glpi_softwarelicenses', 'glpi_softwareversions'))), 'state' => array(array('to' => 'states_id', 'tables' => array('glpi_computers', 'glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_softwareversions'))), 'tech_num' => array(array('to' => 'users_id_tech', 'tables' => array('glpi_cartridgeitems', 'glpi_computers', 'glpi_consumableitems', 'glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_softwares'))), 'title' => array(array('to' => 'usertitles_id', 'tables' => array('glpi_users'))), 'type' => array(array('to' => 'cartridgeitemtypes_id', 'tables' => array('glpi_cartridgeitems')), array('to' => 'computertypes_id', 'tables' => array('glpi_computers')), array('to' => 'consumableitemtypes_id', 'tables' => array('glpi_consumableitems')), array('to' => 'contacttypes_id', 'tables' => array('glpi_contacts')), array('to' => 'devicecasetypes_id', 'tables' => array('glpi_devicecases')), array('to' => 'devicememorytypes_id', 'tables' => array('glpi_devicememories')), array('to' => 'suppliertypes_id', 'tables' => array('glpi_suppliers')), array('to' => 'monitortypes_id', 'tables' => array('glpi_monitors')), array('to' => 'networkequipmenttypes_id', 'tables' => array('glpi_networkequipments')), array('to' => 'peripheraltypes_id', 'tables' => array('glpi_peripherals')), array('to' => 'phonetypes_id', 'tables' => array('glpi_phones')), array('to' => 'printertypes_id', 'tables' => array('glpi_printers')), array('to' => 'softwarelicensetypes_id', 'tables' => array('glpi_softwarelicenses')), array('to' => 'usercategories_id', 'tables' => array('glpi_users')), array('to' => 'itemtype', 'tables' => array('glpi_computers_items', 'glpi_displaypreferences'))), 'update_software' => array(array('to' => 'softwares_id', 'tables' => array('glpi_softwares'))), 'use_version' => array(array('to' => 'softwareversions_id_use', 'tables' => array('glpi_softwarelicenses'))), 'vID' => array(array('to' => 'softwareversions_id', 'tables' => array('glpi_computers_softwareversions'))), 'conpta_num' => array(array('to' => 'accounting_number', 'tables' => array('glpi_contracts'))), 'num_commande' => array(array('to' => 'order_number', 'tables' => array('glpi_infocoms'))), 'bon_livraison' => array(array('to' => 'delivery_number', 'tables' => array('glpi_infocoms'))), 'num_immo' => array(array('to' => 'immo_number', 'tables' => array('glpi_infocoms'))), 'facture' => array(array('to' => 'bill', 'tables' => array('glpi_infocoms'))), 'amort_time' => array(array('to' => 'sink_time', 'tables' => array('glpi_infocoms'))), 'amort_type' => array(array('to' => 'sink_type', 'tables' => array('glpi_infocoms'))), 'ifmac' => array(array('to' => 'mac', 'tables' => array('glpi_networkequipments'))), 'ifaddr' => array(array('to' => 'ip', 'tables' => array('glpi_networkequipments', 'glpi_networkports'))), 'ramSize' => array(array('to' => 'memory_size', 'tables' => array('glpi_printers'))), 'ramSize' => array(array('to' => 'memory_size', 'tables' => array('glpi_printers'))), 'facturation' => array(array('to' => 'billing', 'tables' => array('glpi_contracts'))), 'monday' => array(array('to' => 'use_monday', 'tables' => array('glpi_contracts'))), 'saturday' => array(array('to' => 'use_saturday', 'tables' => array('glpi_contracts'))), 'recursive' => array(array('to' => 'is_recursive', 'tables' => array('glpi_networkequipments', 'glpi_groups', 'glpi_contracts', 'glpi_contacts', 'glpi_suppliers', 'glpi_printers', 'glpi_softwares', 'glpi_softwareversions', 'glpi_softwarelicences'))), 'faq' => array(array('to' => 'is_faq', 'tables' => array('glpi_knowbaseitems'))), 'flags_micro' => array(array('to' => 'have_micro', 'tables' => array('glpi_monitors'))), 'flags_speaker' => array(array('to' => 'have_speaker', 'tables' => array('glpi_monitors'))), 'flags_subd' => array(array('to' => 'have_subd', 'tables' => array('glpi_monitors'))), 'flags_bnc' => array(array('to' => 'have_bnc', 'tables' => array('glpi_monitors'))), 'flags_dvi' => array(array('to' => 'have_dvi', 'tables' => array('glpi_monitors'))), 'flags_pivot' => array(array('to' => 'have_pivot', 'tables' => array('glpi_monitors'))), 'flags_hp' => array(array('to' => 'have_hp', 'tables' => array('glpi_phones'))), 'flags_casque' => array(array('to' => 'have_headset', 'tables' => array('glpi_phones'))), 'flags_usb' => array(array('to' => 'have_usb', 'tables' => array('glpi_printers'))), 'flags_par' => array(array('to' => 'have_parallel', 'tables' => array('glpi_printers'))), 'flags_serial' => array(array('to' => 'have_serial', 'tables' => array('glpi_printers'))), 'initial_pages' => array(array('to' => 'init_pages_counter', 'tables' => array('glpi_printers'))), 'global' => array(array('to' => 'is_global', 'tables' => array('glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_softwares'))), 'template' => array(array('to' => 'template_name', 'tables' => array('glpi_cartridgeitems', 'glpi_computers', 'glpi_consumableitems', 'glpi_devicecases', 'glpi_devicecontrols', 'glpi_devicedrives', 'glpi_devicegraphiccards', 'glpi_deviceharddrives', 'glpi_devicenetworkcards', 'glpi_devicemotherboards', 'glpi_devicepcis', 'glpi_devicepowersupplies', 'glpi_deviceprocessors', 'glpi_devicememories', 'glpi_devicesoundcards', 'glpi_monitors', 'glpi_networkequipments', 'glpi_peripherals', 'glpi_phones', 'glpi_printers', 'glpi_softwares'))), 'comments' => array(array('to' => 'comment', 'tables' => array('glpi_cartridgeitems', 'glpi_computers', 'glpi_consumableitems', 'glpi_contacts', 'glpi_contracts', 'glpi_documents', 'glpi_autoupdatesystems', 'glpi_budgets', 'glpi_cartridgeitemtypes', 'glpi_devicecasetypes', 'glpi_consumableitemtypes', 'glpi_contacttypes', 'glpi_contracttypes', 'glpi_domains', 'glpi_suppliertypes', 'glpi_filesystems', 'glpi_networkequipmentfirmwares', 'glpi_networkinterfaces', 'glpi_interfacetypes', 'glpi_knowbaseitemcategories', 'glpi_softwarelicensetypes', 'glpi_locations', 'glpi_manufacturers', 'glpi_computermodels', 'glpi_monitormodels', 'glpi_networkequipmentmodels', 'glpi_peripheralmodels', 'glpi_phonemodels', 'glpi_printermodels', 'glpi_netpoints', 'glpi_networks', 'glpi_operatingsystems', 'glpi_operatingsystemservicepacks', 'glpi_operatingsystemversions', 'glpi_phonepowersupplies', 'glpi_devicememorytypes', 'glpi_documentcategories', 'glpi_softwarecategories', 'glpi_states', 'glpi_ticketcategories', 'glpi_usertitles', 'glpi_usercategories', 'glpi_vlans', 'glpi_suppliers', 'glpi_entities', 'glpi_groups', 'glpi_infocoms', 'glpi_monitors', 'glpi_phones', 'glpi_printers', 'glpi_peripherals', 'glpi_networkequipments', 'glpi_reservationitems', 'glpi_rules', 'glpi_softwares', 'glpi_softwarelicenses', 'glpi_softwareversions', 'glpi_computertypes', 'glpi_monitortypes', 'glpi_networkequipmenttypes', 'glpi_peripheraltypes', 'glpi_phonetypes', 'glpi_printertypes', 'glpi_users'))), 'notes' => array(array('to' => 'notepad', 'tables' => array('glpi_cartridgeitems', 'glpi_computers', 'glpi_consumableitems', 'glpi_contacts', 'glpi_contracts', 'glpi_documents', 'glpi_suppliers', 'glpi_entitydatas', 'glpi_printers', 'glpi_monitors', 'glpi_phones', 'glpi_peripherals', 'glpi_networkequipments', 'glpi_softwares'))));
    $foreignkeys = Plugin::doHookFunction("plugin_datainjection_migratefields", $foreignkeys);
    $query = "SELECT `itemtype`, `value`\n              FROM `glpi_plugin_datainjection_mappings`\n              WHERE `itemtype` NOT IN ('none')\n              GROUP BY `itemtype`,`value`";
    foreach ($DB->request($query) as $data) {
        if (isset($foreignkeys[$data['value']])) {
            foreach ($foreignkeys[$data['value']] as $field_info) {
                $table = getTableForItemType($data['itemtype']);
                if (in_array($table, $field_info['tables'])) {
                    $query = "UPDATE `glpi_plugin_datainjection_mappings`\n                          SET `value` = '" . $field_info['to'] . "'\n                          WHERE `itemtype` = '" . $data['itemtype'] . "'\n                                AND `value` = '" . $data['value'] . "'";
                    $DB->queryOrDie($query, "Datainjection : error converting mapping fields");
                    $query = "UPDATE `glpi_plugin_datainjection_infos`\n                          SET `value` = '" . $field_info['to'] . "'\n                          WHERE `itemtype` = '" . $data['itemtype'] . "'\n                                AND `value` = '" . $data['value'] . "'";
                    $DB->queryOrDie($query, "Datainjection : error converting infos fields");
                }
            }
        }
    }
}
示例#19
0
 public function remove()
 {
     $this->migrate->dropTable($this->getName());
 }
示例#20
0
 /**
  * @inheritdoc
  */
 public function dropTable($table)
 {
     if (empty($this->_deleted[$table])) {
         foreach ($this->getForeignTables($table) as $foreign_table) {
             $this->dropTable($foreign_table);
         }
         parent::dropTable($table);
         $this->_deleted[$table] = true;
     }
 }
function plugin_additionalalerts_install()
{
    global $DB;
    include_once GLPI_ROOT . "/plugins/additionalalerts/inc/profile.class.php";
    $install = false;
    $update78 = false;
    $update80 = false;
    if (!TableExists("glpi_plugin_alerting_config") && !TableExists("glpi_plugin_additionalalerts_notificationstates")) {
        $install = true;
        $DB->runFile(GLPI_ROOT . "/plugins/additionalalerts/sql/empty-1.7.0.sql");
    } else {
        if (TableExists("glpi_plugin_alerting_profiles") && FieldExists("glpi_plugin_alerting_profiles", "interface")) {
            $update78 = true;
            $update80 = true;
            $DB->runFile(GLPI_ROOT . "/plugins/additionalalerts/sql/update-1.2.0.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/additionalalerts/sql/update-1.3.0.sql");
        } else {
            if (!TableExists("glpi_plugin_additionalalerts_notificationstates")) {
                $update78 = true;
                $update80 = true;
                $DB->runFile(GLPI_ROOT . "/plugins/additionalalerts/sql/update-1.3.0.sql");
            } else {
                if (TableExists("glpi_plugin_additionalalerts_reminderalerts")) {
                    $DB->runFile(GLPI_ROOT . "/plugins/additionalalerts/sql/update-1.5.0.sql");
                    $notif = new Notification();
                    $options = array('itemtype' => 'PluginAdditionalalertsReminderAlert', 'event' => 'reminder', 'FIELDS' => 'id');
                    foreach ($DB->request('glpi_notifications', $options) as $data) {
                        $notif->delete($data);
                    }
                    $template = new NotificationTemplate();
                    $translation = new NotificationTemplateTranslation();
                    $options = array('itemtype' => 'PluginAdditionalalertsReminderAlert', 'FIELDS' => 'id');
                    foreach ($DB->request('glpi_notificationtemplates', $options) as $data) {
                        $options_template = array('notificationtemplates_id' => $data['id'], 'FIELDS' => 'id');
                        foreach ($DB->request('glpi_notificationtemplatetranslations', $options_template) as $data_template) {
                            $translation->delete($data_template);
                        }
                        $template->delete($data);
                    }
                    $temp = new CronTask();
                    if ($temp->getFromDBbyName('PluginAdditionalalertsReminderAlert', 'AdditionalalertsReminder')) {
                        $temp->delete(array('id' => $temp->fields["id"]));
                    }
                }
            }
        }
    }
    if ($install || $update78) {
        //Do One time on 0.78
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginAdditionalalertsInfocomAlert' AND `name` = 'Alert infocoms'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##lang.notinfocom.title## : ##notinfocom.entity##',\n                        '##FOREACHnotinfocoms##\n   ##lang.notinfocom.name## : ##notinfocom.name##\n   ##lang.notinfocom.computertype## : ##notinfocom.computertype##\n   ##lang.notinfocom.operatingsystem## : ##notinfocom.operatingsystem##\n   ##lang.notinfocom.state## : ##notinfocom.state##\n   ##lang.notinfocom.location## : ##notinfocom.location##\n   ##lang.notinfocom.user## : ##notinfocom.user## / ##notinfocom.group## / ##notinfocom.contact##\n   ##ENDFOREACHnotinfocoms##',\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.notinfocom.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.notinfocom.computertype##&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.notinfocom.operatingsystem##&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.notinfocom.state##&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.notinfocom.location##&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.notinfocom.user##&lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   ##FOREACHnotinfocoms##            \n   &lt;tr&gt;\n   &lt;td&gt;&lt;a href=\"##notinfocom.urlname##\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##notinfocom.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;##notinfocom.computertype##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##notinfocom.operatingsystem##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##notinfocom.state##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##notinfocom.location##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;a href=\"##notinfocom.urluser##\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##notinfocom.user##&lt;/span&gt;&lt;/a&gt; / &lt;a href=\"##notinfocom.urlgroup##\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##notinfocom.group##&lt;/span&gt;&lt;/a&gt; / &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##notinfocom.contact##&lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   ##ENDFOREACHnotinfocoms##\n   &lt;/tbody&gt;\n   &lt;/table&gt;');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Alert infocoms', 0, 'PluginAdditionalalertsInfocomAlert', 'notinfocom',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-03-13 10:36:46');";
        $result = $DB->query($query);
        ////////////////////
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginAdditionalalertsOcsAlert' AND `name` = 'Alert machines ocs'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##lang.ocsmachine.title## : ##ocsmachine.entity##',\n                        '##FOREACHocsmachines##\n   ##lang.ocsmachine.name## : ##ocsmachine.name##\n   ##lang.ocsmachine.operatingsystem## : ##ocsmachine.operatingsystem##\n   ##lang.ocsmachine.state## : ##ocsmachine.state##\n   ##lang.ocsmachine.location## : ##ocsmachine.location##\n   ##lang.ocsmachine.user## : ##ocsmachine.user## / ##lang.ocsmachine.group## : ##ocsmachine.group## / ##lang.ocsmachine.contact## : ##ocsmachine.contact##\n   ##lang.ocsmachine.lastocsupdate## : ##ocsmachine.lastocsupdate##\n   ##lang.ocsmachine.lastupdate## : ##ocsmachine.lastupdate##\n   ##lang.ocsmachine.ocsserver## : ##ocsmachine.ocsserver##\n   ##ENDFOREACHocsmachines##',\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.ocsmachine.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.ocsmachine.operatingsystem##&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.ocsmachine.state##&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.ocsmachine.location##&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.ocsmachine.user##&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.ocsmachine.lastocsupdate##&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.ocsmachine.lastupdate##&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.ocsmachine.ocsserver##&lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   ##FOREACHocsmachines##                 \n   &lt;tr&gt;\n   &lt;td&gt;&lt;a href=\"##ocsmachine.urlname##\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##ocsmachine.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;##ocsmachine.operatingsystem##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##ocsmachine.state##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##ocsmachine.location##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;##IFocsmachine.user##&lt;a href=\"##ocsmachine.urluser##\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##ocsmachine.user##&lt;/span&gt;&lt;/a&gt; / ##ENDIFocsmachine.user####IFocsmachine.group##&lt;a href=\"##ocsmachine.urlgroup##\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##ocsmachine.group##&lt;/span&gt;&lt;/a&gt; / ##ENDIFocsmachine.group####IFocsmachine.contact##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##ocsmachine.contact####ENDIFocsmachine.contact##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##ocsmachine.lastocsupdate##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##ocsmachine.lastupdate##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##ocsmachine.ocsserver##&lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   ##ENDFOREACHocsmachines##\n   &lt;/tbody&gt;\n   &lt;/table&gt;');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Alert new machines ocs', 0, 'PluginAdditionalalertsOcsAlert', 'newocs',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-03-20 10:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Alert ocs synchronization', 0, 'PluginAdditionalalertsOcsAlert', 'ocs',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-03-20 10:36:46');";
        $result = $DB->query($query);
    }
    if ($update78) {
        //Do One time on 0.78
        $query_ = "SELECT *\n            FROM `glpi_plugin_additionalalerts_profiles` ";
        $result_ = $DB->query($query_);
        if ($DB->numrows($result_) > 0) {
            while ($data = $DB->fetch_array($result_)) {
                $query = "UPDATE `glpi_plugin_additionalalerts_profiles`\n                  SET `profiles_id` = '" . $data["id"] . "'\n                  WHERE `id` = '" . $data["id"] . "';";
                $result = $DB->query($query);
            }
        }
        $query = "ALTER TABLE `glpi_plugin_additionalalerts_profiles`\n               DROP `name` ;";
        $result = $DB->query($query);
    }
    // To be called for each task the plugin manage
    CronTask::Register('PluginAdditionalalertsOcsAlert', 'AdditionalalertsOcs', DAY_TIMESTAMP);
    CronTask::Register('PluginAdditionalalertsOcsAlert', 'AdditionalalertsNewOcs', HOUR_TIMESTAMP);
    CronTask::Register('PluginAdditionalalertsInfocomAlert', 'AdditionalalertsNotInfocom', HOUR_TIMESTAMP);
    PluginAdditionalalertsProfile::initProfile();
    PluginAdditionalalertsProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
    $migration = new Migration("1.7.0");
    $migration->dropTable('glpi_plugin_accounts_profiles');
    return true;
}
function plugin_manufacturersimports_uninstall()
{
    global $DB;
    include_once GLPI_ROOT . "/plugins/manufacturersimports/inc/profile.class.php";
    include_once GLPI_ROOT . "/plugins/manufacturersimports/inc/menu.class.php";
    $migration = new Migration("1.7.0");
    $tables = array("glpi_plugin_manufacturersimports_configs", "glpi_plugin_manufacturersimports_models", "glpi_plugin_manufacturersimports_logs");
    foreach ($tables as $table) {
        $migration->dropTable($table);
    }
    //old versions
    $tables = array("glpi_plugin_suppliertag_config", "glpi_plugin_suppliertag_profiles", "glpi_plugin_suppliertag_models", "glpi_plugin_suppliertag_imported");
    foreach ($tables as $table) {
        $migration->dropTable($table);
    }
    $profileRight = new ProfileRight();
    foreach (PluginManufacturersimportsProfile::getAllRights() as $right) {
        $profileRight->deleteByCriteria(array('name' => $right['field']));
    }
    //Remove rigth from $_SESSION['glpiactiveprofile'] if exists
    PluginManufacturersimportsProfile::removeRightsFromSession();
    //Remove entries in GLPI's menu and breadcrumb
    PluginManufacturersimportsMenu::removeRightsFromSession();
    return true;
}
示例#23
0
function plugin_certificates_install() {
   global $DB;
   
   include_once (GLPI_ROOT."/plugins/certificates/inc/profile.class.php");
   
   $install=false;
   $update78=false;
   $update80=false;
   
   if (!TableExists("glpi_plugin_certificates") && !TableExists("glpi_plugin_certificates_certificatetypes")) {
      
      $install=true;
      $DB->runFile(GLPI_ROOT ."/plugins/certificates/sql/empty-2.0.0.sql");

   } else if (TableExists("glpi_plugin_certificates_mailing") && !FieldExists("glpi_plugin_certificates","recursive")) {
      
      $update78=true;
      $update80=true;
      $DB->runFile(GLPI_ROOT ."/plugins/certificates/sql/update-1.4.sql");
      $DB->runFile(GLPI_ROOT ."/plugins/certificates/sql/update-1.5.0.sql");
      $DB->runFile(GLPI_ROOT ."/plugins/certificates/sql/update-1.5.1.sql");
      $DB->runFile(GLPI_ROOT ."/plugins/certificates/sql/update-1.6.0.sql");

   } else if (TableExists("glpi_plugin_certificates_profiles") && FieldExists("glpi_plugin_certificates_profiles","interface")) {
      
      $update78=true;
      $update80=true;
      $DB->runFile(GLPI_ROOT ."/plugins/certificates/sql/update-1.5.0.sql");
      $DB->runFile(GLPI_ROOT ."/plugins/certificates/sql/update-1.5.1.sql");
      $DB->runFile(GLPI_ROOT ."/plugins/certificates/sql/update-1.6.0.sql");

   } else if (TableExists("glpi_plugin_certificates") && !FieldExists("glpi_plugin_certificates","date_mod")) {
      
      $update78=true;
      $update80=true;
      $DB->runFile(GLPI_ROOT ."/plugins/certificates/sql/update-1.5.1.sql");
      $DB->runFile(GLPI_ROOT ."/plugins/certificates/sql/update-1.6.0.sql");

   } else if (!TableExists("glpi_plugin_certificates_certificatetypes")) {
      
      $update78=true;
      $update80=true;
      $DB->runFile(GLPI_ROOT ."/plugins/certificates/sql/update-1.6.0.sql");
      
   }
   //from 1.6 version
   if (TableExists("glpi_plugin_certificates_certificates") 
      && !FieldExists("glpi_plugin_certificates_certificates","users_id_tech")) {
      $DB->runFile(GLPI_ROOT ."/plugins/certificates/sql/update-1.8.0.sql");
   }
   
   if (TableExists("glpi_plugin_certificates_profiles")) {
   
      $notepad_tables = array('glpi_plugin_certificates_certificates');

      foreach ($notepad_tables as $t) {
         // Migrate data
         if (FieldExists($t, 'notepad')) {
            $query = "SELECT id, notepad
                      FROM `$t`
                      WHERE notepad IS NOT NULL
                            AND notepad <>'';";
            foreach ($DB->request($query) as $data) {
               $iq = "INSERT INTO `glpi_notepads`
                             (`itemtype`, `items_id`, `content`, `date`, `date_mod`)
                      VALUES ('".getItemTypeForTable($t)."', '".$data['id']."',
                              '".addslashes($data['notepad'])."', NOW(), NOW())";
               $DB->queryOrDie($iq, "0.85 migrate notepad data");
            }
            $query = "ALTER TABLE `glpi_plugin_certificates_certificates` DROP COLUMN `notepad`;";
            $DB->query($query);
         }
      }
   }
   
   if ($install || $update78) {

      //Do One time on 0.78
      $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginCertificatesCertificate' AND `name` = 'Alert Certificates'";
      $result = $DB->query($query_id) or die ($DB->error());
      $itemtype = $DB->result($result,0,'id');
      
      $query="INSERT INTO `glpi_notificationtemplatetranslations`
                                 VALUES(NULL, ".$itemtype.", '','##certificate.action## : ##certificate.entity##',
                        '##lang.certificate.entity## :##certificate.entity##
   ##FOREACHcertificates##
   ##lang.certificate.name## : ##certificate.name## - ##lang.certificate.dateexpiration## : ##certificate.dateexpiration##
   ##ENDFOREACHcertificates##',
                        '&lt;p&gt;##lang.certificate.entity## :##certificate.entity##&lt;br /&gt; &lt;br /&gt;
                        ##FOREACHcertificates##&lt;br /&gt;
                        ##lang.certificate.name##  : ##certificate.name## - ##lang.certificate.dateexpiration## :  ##certificate.dateexpiration##&lt;br /&gt; 
                        ##ENDFOREACHcertificates##&lt;/p&gt;');";
      $result=$DB->query($query);
      
      $query = "INSERT INTO `glpi_notifications`
                                   VALUES (NULL, 'Alert Expired Certificates', 0, 'PluginCertificatesCertificate', 'ExpiredCertificates',
                                          'mail',".$itemtype.",
                                          '', 1, 1, '2010-02-17 22:36:46');";
      
      $result=$DB->query($query);
      
      $query = "INSERT INTO `glpi_notifications`
                                   VALUES (NULL, 'Alert Certificates Which Expire', 0, 'PluginCertificatesCertificate', 'CertificatesWhichExpire',
                                          'mail',".$itemtype.",
                                          '', 1, 1, '2010-02-17 22:36:46');";
      
      $result=$DB->query($query);
   }
   
   if ($update78) {
      $query_="SELECT *
            FROM `glpi_plugin_certificates_profiles` ";
      $result_=$DB->query($query_);
      if ($DB->numrows($result_)>0) {

         while ($data=$DB->fetch_array($result_)) {
            $query="UPDATE `glpi_plugin_certificates_profiles`
                  SET `profiles_id` = '".$data["id"]."'
                  WHERE `id` = '".$data["id"]."';";
            $result=$DB->query($query);

         }
      }
      
      $query="ALTER TABLE `glpi_plugin_certificates_profiles`
               DROP `name` ;";
      $result=$DB->query($query);
   
      Plugin::migrateItemType(
         array(1700=>'PluginCertificatesCertificate'),
         array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences",
               "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_tickets"),
         array("glpi_plugin_certificates_certificates_items"));
      
      Plugin::migrateItemType(
         array(1200 => "PluginAppliancesAppliance",1300 => "PluginWebapplicationsWebapplication"),
         array("glpi_plugin_certificates_certificates_items"));
   }
   
   CronTask::Register('PluginCertificatesCertificate', 'CertificatesAlert', DAY_TIMESTAMP);

   PluginCertificatesProfile::initProfile();
   PluginCertificatesProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
   $migration = new Migration("2.0.0");
   $migration->dropTable('glpi_plugin_certificates_profiles');
   
   return true;
}
 static function install(Migration $migration)
 {
     global $DB;
     $table = getTableForItemType(__CLASS__);
     if (isset($_SESSION['glpiactiveprofile'])) {
         PluginGeninventorynumberProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
     }
     if (TableExists("glpi_plugin_geninventorynumber_profiles")) {
         foreach (getAllDatasFromTable($table) as $data) {
             $profile = new self();
             foreach ($profile->getAllRights() as $right => $rights) {
                 if (!countElementsInTable('glpi_profilerights', "`profiles_id`='" . $data['profiles_id'] . "' \n                                            AND `name`='" . $rights['field'] . "'")) {
                     $profileRight = new ProfileRight();
                     $myright = array();
                     $myright['name'] = $rights['field'];
                     $myright['profiles_id'] = $data['profiles_id'];
                     if (!strcmp($data['plugin_geninventorynumber_generate'], 'w')) {
                         $myright['rights'] = CREATE;
                     }
                     if (!strcmp($data['plugin_geninventorynumber_overwrite'], 'w')) {
                         $myright['rights'] += UPDATE;
                     }
                     $profileRight->add($myright);
                 }
             }
         }
         $migration->dropTable($table);
     }
 }
示例#25
0
/**
 * Migrate tables from plugin fusinvdeploy to fusioninventory
 *    all datas in exploded tables are merged and stored in json in order table
 * @param  Migration $migration
 * @return nothing
 */
function migrateTablesFromFusinvDeploy($migration)
{
    global $DB;
    if (TableExists("glpi_plugin_fusioninventory_deployorders") && TableExists("glpi_plugin_fusinvdeploy_checks") && TableExists("glpi_plugin_fusinvdeploy_files") && TableExists("glpi_plugin_fusinvdeploy_actions")) {
        //add json field in deploy order table to store datas from old misc tables
        $field_created = $migration->addField("glpi_plugin_fusioninventory_deployorders", "json", "longtext DEFAULT NULL");
        $migration->migrationOneTable("glpi_plugin_fusioninventory_deployorders");
        $final_datas = array();
        //== glpi_plugin_fusioninventory_deployorders ==
        $o_query = "SELECT * FROM glpi_plugin_fusioninventory_deployorders";
        $o_res = $DB->query($o_query);
        while ($o_datas = $DB->fetch_assoc($o_res)) {
            $order_id = $o_datas['id'];
            $o_line = array();
            $of_line = array();
            $o_line['checks'] = array();
            $o_line['actions'] = array();
            $o_line['associatedFiles'] = array();
            //=== Checks ===
            if (TableExists("glpi_plugin_fusinvdeploy_checks")) {
                $c_query = "SELECT type, path, value, 'error' as `return`\n               FROM glpi_plugin_fusinvdeploy_checks\n               WHERE plugin_fusinvdeploy_orders_id = {$order_id}\n               ORDER BY ranking ASC";
                $c_res = $DB->query($c_query);
                $c_i = 0;
                while ($c_datas = $DB->fetch_assoc($c_res)) {
                    foreach ($c_datas as $c_key => $c_value) {
                        //specific case for filesytem sizes, convert to bytes
                        if (!empty($c_value) && is_numeric($c_value) && $c_datas['type'] !== 'freespaceGreater') {
                            $c_value = $c_value * 1024 * 1024;
                        }
                        //construct job check entry
                        $o_line['checks'][$c_i][$c_key] = $c_value;
                    }
                    $c_i++;
                }
            }
            $files_list = array();
            //=== Files ===
            if (TableExists("glpi_plugin_fusinvdeploy_files")) {
                $f_query = "SELECT id, name, is_p2p as p2p, filesize, mimetype, " . "p2p_retention_days as `p2p-retention-duration`, uncompress, sha512 " . "FROM glpi_plugin_fusinvdeploy_files " . "WHERE plugin_fusinvdeploy_orders_id = {$order_id}";
                $f_res = $DB->query($f_query);
                while ($f_datas = $DB->fetch_assoc($f_res)) {
                    //jump to next entry if sha512 is empty
                    // This kind of entries could happen sometimes on upload errors
                    if (empty($f_datas['sha512'])) {
                        continue;
                    }
                    //construct job file entry
                    $o_line['associatedFiles'][] = $f_datas['sha512'];
                    foreach ($f_datas as $f_key => $f_value) {
                        //we don't store the sha512 field in json
                        if ($f_key == "sha512" || $f_key == "id" || $f_key == "filesize" || $f_key == "mimetype") {
                            continue;
                        }
                        //construct order file entry
                        $of_line[$f_datas['sha512']][$f_key] = $f_value;
                    }
                    if (!in_array($f_datas['sha512'], $files_list)) {
                        $files_list[] = $f_datas['sha512'];
                    }
                }
            }
            //=== Actions ===
            $cmdStatus['RETURNCODE_OK'] = 'okCode';
            $cmdStatus['RETURNCODE_KO'] = 'errorCode';
            $cmdStatus['REGEX_OK'] = 'okPattern';
            $cmdStatus['REGEX_KO'] = 'errorPattern';
            if (TableExists("glpi_plugin_fusinvdeploy_actions")) {
                $a_query = "SELECT *\n               FROM glpi_plugin_fusinvdeploy_actions\n               WHERE plugin_fusinvdeploy_orders_id = {$order_id}\n               ORDER BY ranking ASC";
                $a_res = $DB->query($a_query);
                $a_i = 0;
                while ($a_datas = $DB->fetch_assoc($a_res)) {
                    //get type
                    $type = strtolower(str_replace("PluginFusinvdeployAction_", "", $a_datas['itemtype']));
                    //specific case for command type
                    $type = str_replace("command", "cmd", $type);
                    //table for action itemtype
                    $a_table = getTableForItemType($a_datas['itemtype']);
                    //get table fields
                    $at_query = "SELECT *\n                  FROM {$a_table}\n                  WHERE id = " . $a_datas['items_id'];
                    $at_res = $DB->query($at_query);
                    while ($at_datas = $DB->fetch_assoc($at_res)) {
                        foreach ($at_datas as $at_key => $at_value) {
                            //we don't store the id field of action itemtype table in json
                            if ($at_key == "id") {
                                continue;
                            }
                            //specific case for 'path' field
                            if ($at_key == "path") {
                                $o_line['actions'][$a_i][$type]['list'][] = $at_value;
                            } else {
                                //construct job actions entry
                                $o_line['actions'][$a_i][$type][$at_key] = $at_value;
                            }
                        }
                        //specific case for commands : we must add status and env vars
                        if ($a_datas['itemtype'] === "PluginFusinvdeployAction_Command") {
                            $ret_cmd_query = "SELECT type, value\n                        FROM glpi_plugin_fusinvdeploy_actions_commandstatus\n                        WHERE plugin_fusinvdeploy_commands_id = " . $at_datas['id'];
                            $ret_cmd_res = $DB->query($ret_cmd_query);
                            while ($res_cmd_datas = $DB->fetch_assoc($ret_cmd_res)) {
                                // Skip empty retchecks type:
                                // This surely means they have been drop at some point but entry has not been
                                // removed from database.
                                if (!empty($res_cmd_datas['type'])) {
                                    //construct command status array entry
                                    $o_line['actions'][$a_i][$type]['retChecks'][] = array('type' => $cmdStatus[$res_cmd_datas['type']], 'values' => array($res_cmd_datas['value']));
                                }
                            }
                        }
                    }
                    $a_i++;
                }
            }
            $final_datas[$order_id]['jobs'] = $o_line;
            $final_datas[$order_id]['associatedFiles'] = $of_line;
            unset($o_line);
            unset($of_line);
        }
        $options = 0;
        if (version_compare(PHP_VERSION, '5.3.3') >= 0) {
            $options = $options | JSON_NUMERIC_CHECK;
        }
        if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
            $options = $options | JSON_UNESCAPED_SLASHES;
        }
        //store json in order table
        foreach ($final_datas as $order_id => $data) {
            $json = $DB->escape(json_encode($data, $options));
            $order_query = "UPDATE glpi_plugin_fusioninventory_deployorders\n            SET json = '{$json}'\n            WHERE id = {$order_id}";
            $DB->query($order_query);
        }
    }
    //=== Fileparts ===
    if (TableExists('glpi_plugin_fusinvdeploy_fileparts') && TableExists('glpi_plugin_fusinvdeploy_files')) {
        $files_list = $DB->request('glpi_plugin_fusinvdeploy_files');
        // multipart file datas
        foreach ($files_list as $file) {
            $sha = $file['sha512'];
            if (empty($sha)) {
                continue;
            }
            $shortsha = substr($sha, 0, 6);
            $fp_query = "SELECT  fp.`sha512` as filepart_hash, " . "        f.`sha512`  as file_hash      " . "FROM `glpi_plugin_fusinvdeploy_files` as f " . "INNER JOIN `glpi_plugin_fusinvdeploy_fileparts` as fp " . "ON   f.`id` = fp.`plugin_fusinvdeploy_files_id` " . "     AND f.`shortsha512` = '{$shortsha}' " . "GROUP BY fp.`sha512` " . "ORDER BY fp.`id`";
            $fp_res = $DB->query($fp_query);
            if ($DB->numrows($fp_res) > 0) {
                //print("writing file : " . GLPI_PLUGIN_DOC_DIR."/fusioninventory/files/manifests/{$sha}" . "\n");
                $fhandle = fopen(GLPI_PLUGIN_DOC_DIR . "/fusioninventory/files/manifests/{$sha}", 'w+');
                while ($fp_datas = $DB->fetch_assoc($fp_res)) {
                    if ($fp_datas['file_hash'] === $sha) {
                        fwrite($fhandle, $fp_datas['filepart_hash'] . "\n");
                    }
                }
                fclose($fhandle);
            }
        }
    }
    //migrate fusinvdeploy_files to fusioninventory_deployfiles
    if (TableExists("glpi_plugin_fusinvdeploy_files")) {
        $DB->query("TRUNCATE TABLE `glpi_plugin_fusioninventory_deployfiles`");
        if (FieldExists("glpi_plugin_fusinvdeploy_files", "filesize")) {
            $f_query = implode(array("SELECT  files.`id`, files.`name`,", "        files.`filesize`, files.`mimetype`,", "        files.`sha512`, files.`shortsha512`,", "        files.`create_date`,", "        pkgs.`entities_id`, pkgs.`is_recursive`", "FROM glpi_plugin_fusinvdeploy_files as files", "LEFT JOIN glpi_plugin_fusioninventory_deployorders as orders", "  ON orders.`id` = files.`plugin_fusinvdeploy_orders_id`", "LEFT JOIN glpi_plugin_fusioninventory_deploypackages as pkgs", "  ON orders.`plugin_fusioninventory_deploypackages_id` = pkgs.`id`", "WHERE", "  files.`shortsha512` != \"\""), " \n");
            $f_res = $DB->query($f_query);
            while ($f_datas = $DB->fetch_assoc($f_res)) {
                $entry = array("id" => $f_datas["id"], "name" => $f_datas["name"], "filesize" => $f_datas["filesize"], "mimetype" => $f_datas["mimetype"], "shortsha512" => $f_datas["shortsha512"], "sha512" => $f_datas["sha512"], "comments" => "", "date_mod" => $f_datas["create_date"], "entities_id" => $f_datas["entities_id"], "is_recursive" => $f_datas["is_recursive"]);
                $migration->displayMessage("\n");
                // Check if file exists
                $i_DeployFile = new PluginFusioninventoryDeployFile();
                $migration->displayMessage("migrating file " . $entry['name'] . " sha:" . $entry['sha512'] . "\n");
                if ($i_DeployFile->checkPresenceManifest($entry['sha512'])) {
                    $migration->displayMessage("manifest exists" . "\n");
                    $migration->insertInTable("glpi_plugin_fusioninventory_deployfiles", $entry);
                }
            }
        }
    }
    /**
     * JSON orders fixer:
     *    This piece of code makes sure that JSON orders in database are valid and will fix it
     *    otherwise.
     */
    $orders = $DB->request('glpi_plugin_fusioninventory_deployorders');
    foreach ($orders as $order_config) {
        $pfDeployOrder = new PluginFusioninventoryDeployOrder();
        $json_order = json_decode($order_config['json']);
        //print("deployorders fixer : actual order structure for ID ".$order_config['id']."\n" . print_r($json_order,true) ."\n");
        // Checks for /jobs json property
        if (!isset($json_order->jobs) || !is_object($json_order->jobs)) {
            //print("deployorders fixer : create missing required 'jobs' property\n");
            $json_order->jobs = new stdClass();
        }
        if (!isset($json_order->jobs->checks)) {
            //print("deployorders fixer : create missing required '/jobs/checks' array property\n");
            $json_order->jobs->checks = array();
        }
        if (!isset($json_order->jobs->actions)) {
            //print("deployorders fixer : create missing required '/jobs/actions' array property\n");
            $json_order->jobs->actions = array();
        }
        if (!isset($json_order->jobs->associatedFiles)) {
            //print("deployorders fixer : create missing required '/jobs/associatedFiles' array property\n");
            $json_order->jobs->associatedFiles = array();
        }
        // Checks for /associatedFiles json property
        if (!isset($json_order->associatedFiles) || !is_object($json_order->associatedFiles)) {
            //print("deployorders fixer : create missing required 'associatedFiles' property\n");
            $json_order->associatedFiles = new stdClass();
        }
        //print(
        //"deployorders fixer : final order structure for ID ".$order_config['id']."\n" .
        //   json_encode($json_order,JSON_PRETTY_PRINT) ."\n"
        //);
        $pfDeployOrder::updateOrderJson($order_config['id'], $json_order);
    }
    /**
     * Drop unused tables
     */
    $old_deploy_tables = array('glpi_plugin_fusinvdeploy_actions', 'glpi_plugin_fusinvdeploy_actions_commandenvvariables', 'glpi_plugin_fusinvdeploy_actions_commands', 'glpi_plugin_fusinvdeploy_actions_commandstatus', 'glpi_plugin_fusinvdeploy_actions_copies', 'glpi_plugin_fusinvdeploy_actions_deletes', 'glpi_plugin_fusinvdeploy_actions_messages', 'glpi_plugin_fusinvdeploy_actions_mkdirs', 'glpi_plugin_fusinvdeploy_actions_moves', 'glpi_plugin_fusinvdeploy_checks', 'glpi_plugin_fusinvdeploy_fileparts', 'glpi_plugin_fusinvdeploy_files', 'glpi_plugin_fusinvdeploy_files_mirrors');
    foreach ($old_deploy_tables as $table) {
        $migration->dropTable($table);
    }
    //drop unused views
    $old_deploy_views = array('glpi_plugin_fusinvdeploy_taskjobs', 'glpi_plugin_fusinvdeploy_tasks');
    foreach ($old_deploy_views as $view) {
        $DB->query("DROP VIEW IF EXISTS {$view}");
    }
}
示例#26
0
function plugin_ocsinventoryng_install()
{
    global $DB;
    include_once GLPI_ROOT . "/plugins/ocsinventoryng/inc/profile.class.php";
    $migration = new Migration(110);
    if (!TableExists("glpi_plugin_ocsinventoryng_ocsservers_profiles") && !TableExists("glpi_plugin_ocsinventoryng_ocsservers")) {
        $install = true;
        $DB->runFile(GLPI_ROOT . "/plugins/ocsinventoryng/install/mysql/1.1.0-empty.sql");
        $migration->createRule(array('sub_type' => 'RuleImportEntity', 'entities_id' => 0, 'is_recursive' => 1, 'is_active' => 1, 'match' => 'AND', 'name' => 'RootOcs'), array(array('criteria' => 'TAG', 'condition' => Rule::PATTERN_IS, 'pattern' => '*'), array('criteria' => 'OCS_SERVER', 'condition' => Rule::PATTERN_IS, 'pattern' => 1)), array(array('field' => 'entities_id', 'action_type' => 'assign', 'value' => 0)));
    } else {
        if (!TableExists("glpi_plugin_ocsinventoryng_ocsservers") && !TableExists("ocs_glpi_ocsservers")) {
            CronTask::Register('PluginOcsinventoryngOcsServer', 'ocsng', MINUTE_TIMESTAMP * 5);
            $migration->createRule(array('sub_type' => 'RuleImportEntity', 'entities_id' => 0, 'is_recursive' => 1, 'is_active' => 1, 'match' => 'AND', 'name' => 'RootOcs'), array(array('criteria' => 'TAG', 'condition' => Rule::PATTERN_IS, 'pattern' => '*'), array('criteria' => 'OCS_SERVER', 'condition' => Rule::PATTERN_IS, 'pattern' => 1)), array(array('field' => 'entities_id', 'action_type' => 'assign', 'value' => 0)));
        } else {
            if (!TableExists("glpi_plugin_ocsinventoryng_ocsservers") && TableExists("ocs_glpi_ocsservers")) {
                $update = true;
                $DB->runFile(GLPI_ROOT . "/plugins/ocsinventoryng/install/mysql/1.0.0-update.sql");
                // recuperation des droits du core
                // creation de la table glpi_plugin_ocsinventoryng_profiles vide
                if (TableExists("ocs_glpi_profiles") && (TableExists('ocs_glpi_ocsservers') && countElementsInTable('ocs_glpi_ocsservers') > 0)) {
                    $query = "INSERT INTO `glpi_plugin_ocsinventoryng_profiles`\n                          (`profiles_id`, `ocsng`, `sync_ocsng`, `view_ocsng`, `clean_ocsng`,\n                           `rule_ocs`)\n                           SELECT `id`, `ocsng`, `sync_ocsng`, `view_ocsng`, `clean_ocsng`,\n                                  `rule_ocs`\n                           FROM `ocs_glpi_profiles`";
                    $DB->queryOrDie($query, "1.0.0 insert profiles for OCS in plugin");
                }
                // recuperation des paramètres du core
                if (TableExists("ocs_glpi_crontasks")) {
                    $query = "INSERT INTO `glpi_crontasks`\n                          SELECT *\n                          FROM `ocs_glpi_crontasks`\n                          WHERE `itemtype` = 'OcsServer'";
                    $DB->queryOrDie($query, "1.0.0 insert crontasks for plugin ocsinventoryng");
                    $query = "UPDATE `glpi_crontasks`\n                   SET `itemtype` = 'PluginOcsinventoryngOcsServer'\n                   WHERE `itemtype` = 'OcsServer'";
                    $DB->queryOrDie($query, "1.0.0 update ocsinventoryng crontask");
                }
                if (TableExists("ocs_glpi_displaypreferences")) {
                    $query = "INSERT INTO `glpi_displaypreferences`\n                          SELECT *\n                          FROM `ocs_glpi_displaypreferences`\n                          WHERE `itemtype` = 'OcsServer'";
                    $DB->queryOrDie($query, "1.0.0 insert displaypreferences for plugin ocsinventoryng");
                    $query = "UPDATE `glpi_displaypreferences`\n                   SET `itemtype` = 'PluginOcsinventoryngOcsServer'\n                   WHERE `itemtype` = 'OcsServer'";
                    $DB->queryOrDie($query, "1.0.0 update ocsinventoryng displaypreferences");
                }
                plugin_ocsinventoryng_migrateComputerLocks($migration);
            }
        }
    }
    //Update 1.0.3
    if (TableExists("glpi_plugin_ocsinventoryng_networkports") && !FieldExists('glpi_plugin_ocsinventoryng_networkports', 'speed')) {
        $query = "ALTER TABLE `glpi_plugin_ocsinventoryng_networkports` \n               ADD `speed` varchar(255) COLLATE utf8_unicode_ci DEFAULT '10mb/s';";
        $DB->queryOrDie($query, "1.0.3 update table glpi_plugin_ocsinventoryng_networkports");
    }
    // Update 1.0.4
    if (TableExists("glpi_plugin_ocsinventoryng_ocsservers") && !FieldExists('glpi_plugin_ocsinventoryng_ocsservers', 'conn_type')) {
        $query = "ALTER TABLE `glpi_plugin_ocsinventoryng_ocsservers` \n               ADD `conn_type` tinyint(1) NOT NULL DEFAULT '0';";
        $DB->queryOrDie($query, "1.0.4 update table glpi_plugin_ocsinventoryng_ocsservers");
    }
    //Update 1.1.0
    if (!TableExists("glpi_plugin_ocsinventoryng_ocsservers_profiles")) {
        $query = "CREATE TABLE `glpi_plugin_ocsinventoryng_ocsservers_profiles` (\n                  `id` int(11) NOT NULL auto_increment,\n                  `plugin_ocsinventoryng_ocsservers_id` int(11) NOT NULL default '0',\n                  `profiles_id` int(11) NOT NULL default '0',\n                PRIMARY KEY (`id`),\n                KEY `plugin_ocsinventoryng_ocsservers_id` (`plugin_ocsinventoryng_ocsservers_id`),\n                KEY `profiles_id` (`profiles_id`)\n                ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->queryOrDie($query, 'Creating glpi_plugin_ocsinventoryng_ocsservers_profiles' . "<br>" . $DB->error());
    }
    if (TableExists("glpi_plugin_ocsinventoryng_ocslinks") && !FieldExists('glpi_plugin_ocsinventoryng_ocslinks', 'last_ocs_conn')) {
        $query = "ALTER TABLE `glpi_plugin_ocsinventoryng_ocslinks` \n               ADD `last_ocs_conn` datetime default NULL;";
        $DB->queryOrDie($query, "1.1.0 update table glpi_plugin_ocsinventoryng_ocslinks");
    }
    if (TableExists("glpi_plugin_ocsinventoryng_ocslinks") && !FieldExists('glpi_plugin_ocsinventoryng_ocslinks', 'ip_src')) {
        $query = "ALTER TABLE `glpi_plugin_ocsinventoryng_ocslinks` \n               ADD `ip_src` varchar(255) collate utf8_unicode_ci default NULL;";
        $DB->queryOrDie($query, "1.1.0 update table glpi_plugin_ocsinventoryng_ocslinks");
    }
    if (TableExists("glpi_plugin_ocsinventoryng_ocsservers") && !FieldExists('glpi_plugin_ocsinventoryng_ocsservers', 'import_device_bios')) {
        $query = "ALTER TABLE `glpi_plugin_ocsinventoryng_ocsservers` \n                     ADD `import_device_bios` tinyint(1) NOT NULL DEFAULT '1';";
        $DB->queryOrDie($query, "1.1.0 update table glpi_plugin_ocsinventoryng_ocsservers");
    }
    if (!TableExists("glpi_plugin_ocsinventoryng_devicebiosdatas")) {
        $query = "CREATE TABLE `glpi_plugin_ocsinventoryng_devicebiosdatas` (\n                    `id` int(11) NOT NULL AUTO_INCREMENT,\n                    `designation` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,\n                    `comment` text COLLATE utf8_unicode_ci,\n                    `date` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,\n                    `assettag` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,\n                    `manufacturers_id` int(11) NOT NULL DEFAULT '0',\n                    `entities_id` int(11) NOT NULL DEFAULT '0',\n                    `is_recursive` tinyint(1) NOT NULL DEFAULT '0',\n                    PRIMARY KEY (`id`),\n                    KEY `manufacturers_id` (`manufacturers_id`),\n                    KEY `entities_id` (`entities_id`),\n                    KEY `is_recursive` (`is_recursive`)\n                  ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
        $DB->queryOrDie($query, "1.1.0 add table glpi_plugin_ocsinventoryng_devicebiosdatas");
    }
    if (!TableExists("glpi_plugin_ocsinventoryng_items_devicebiosdatas")) {
        $query = "CREATE TABLE `glpi_plugin_ocsinventoryng_items_devicebiosdatas` (\n                    `id` int(11) NOT NULL AUTO_INCREMENT,\n                    `items_id` int(11) NOT NULL DEFAULT '0',\n                    `itemtype` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,\n                    `plugin_ocsinventoryng_devicebiosdatas_id` int(11) NOT NULL DEFAULT '0',\n                    `is_deleted` tinyint(1) NOT NULL DEFAULT '0',\n                    `is_dynamic` tinyint(1) NOT NULL DEFAULT '0',\n                    `entities_id` int(11) NOT NULL DEFAULT '0',\n                    `is_recursive` tinyint(1) NOT NULL DEFAULT '0',\n                    PRIMARY KEY (`id`),\n                    KEY `computers_id` (`items_id`),\n                    KEY `plugin_ocsinventoryng_devicebiosdatas_id` (`plugin_ocsinventoryng_devicebiosdatas_id`),\n                    KEY `is_deleted` (`is_deleted`),\n                    KEY `is_dynamic` (`is_dynamic`),\n                    KEY `entities_id` (`entities_id`),\n                    KEY `is_recursive` (`is_recursive`),\n                    KEY `item` (`itemtype`,`items_id`)\n                  ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
        $DB->queryOrDie($query, "1.1.0 add table glpi_plugin_ocsinventoryng_items_devicebiosdatas");
    }
    PluginOcsinventoryngProfile::initProfile();
    PluginOcsinventoryngProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
    if (TableExists("glpi_plugin_ocsinventoryng_ocsservers") && TableExists("glpi_plugin_ocsinventoryng_profiles") && countElementsInTable("glpi_plugin_ocsinventoryng_ocsservers", "`is_active` = 1") == 1) {
        foreach ($DB->request("glpi_plugin_ocsinventoryng_ocsservers") as $server) {
            foreach ($DB->request("glpi_plugin_ocsinventoryng_profiles", "`ocsng` IS NOT NULL") as $rights) {
                $query = "INSERT INTO `glpi_plugin_ocsinventoryng_ocsservers_profiles`\n                       SET `profiles_id` = '" . $rights['profiles_id'] . "',\n                           `plugin_ocsinventoryng_ocsservers_id` = '" . $server['id'] . "'";
                $DB->queryOrDie($query, "insert into glpi_plugin_ocsinventoryng_ocsservers_profiles");
            }
        }
    }
    $migration = new Migration("1.1.0");
    $migration->dropTable('glpi_plugin_ocsinventoryng_profiles');
    // Si massocsimport import est installe, on verifie qu'il soit bien dans la dernière version
    if (TableExists("glpi_plugin_mass_ocs_import")) {
        //1.1 ou 1.2
        if (!FieldExists('glpi_plugin_mass_ocs_import_config', 'warn_if_not_imported')) {
            //1.1
            plugin_ocsinventoryng_upgrademassocsimport11to12();
        }
    }
    if (TableExists("glpi_plugin_mass_ocs_import")) {
        //1.2 because if before
        plugin_ocsinventoryng_upgrademassocsimport121to13();
    }
    if (TableExists("glpi_plugin_massocsimport")) {
        //1.3 ou 1.4
        if (FieldExists('glpi_plugin_massocsimport', 'ID')) {
            //1.3
            plugin_ocsinventoryng_upgrademassocsimport13to14();
        }
    }
    if (TableExists('glpi_plugin_massocsimport_threads') && !FieldExists('glpi_plugin_massocsimport_threads', 'not_unique_machines_number')) {
        plugin_ocsinventoryng_upgrademassocsimport14to15();
    }
    //Tables from massocsimport
    if (!TableExists('glpi_plugin_ocsinventoryng_threads') && !TableExists('glpi_plugin_massocsimport_threads')) {
        //not installed
        $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_ocsinventoryng_threads` (\n                  `id` int(11) NOT NULL auto_increment,\n                  `threadid` int(11) NOT NULL default '0',\n                  `start_time` datetime default NULL,\n                  `end_time` datetime default NULL,\n                  `status` int(11) NOT NULL default '0',\n                  `error_msg` text NOT NULL,\n                  `imported_machines_number` int(11) NOT NULL default '0',\n                  `synchronized_machines_number` int(11) NOT NULL default '0',\n                  `failed_rules_machines_number` int(11) NOT NULL default '0',\n                  `linked_machines_number` int(11) NOT NULL default '0',\n                  `notupdated_machines_number` int(11) NOT NULL default '0',\n                  `not_unique_machines_number` int(11) NOT NULL default '0',\n                  `link_refused_machines_number` int(11) NOT NULL default '0',\n                  `total_number_machines` int(11) NOT NULL default '0',\n                  `plugin_ocsinventoryng_ocsservers_id` int(11) NOT NULL default '1',\n                  `processid` int(11) NOT NULL default '0',\n                  `entities_id` int(11) NOT NULL DEFAULT 0,\n                  `rules_id` int(11) NOT NULL DEFAULT 0,\n                  PRIMARY KEY  (`id`),\n                  KEY `end_time` (`end_time`),\n                  KEY `process_thread` (`processid`,`threadid`)\n                ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ";
        $DB->queryOrDie($query, $DB->error());
        $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_ocsinventoryng_configs` (\n                  `id` int(11) NOT NULL auto_increment,\n                  `thread_log_frequency` int(11) NOT NULL default '10',\n                  `is_displayempty` int(1) NOT NULL default '1',\n                  `import_limit` int(11) NOT NULL default '0',\n                  `delay_refresh` int(11) NOT NULL default '0',\n                  `allow_ocs_update` tinyint(1) NOT NULL default '0',\n                  `comment` text,\n                  PRIMARY KEY (`id`)\n                ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ";
        $DB->queryOrDie($query, $DB->error());
        $query = "INSERT INTO `glpi_plugin_ocsinventoryng_configs`\n                       (`id`,`thread_log_frequency`,`is_displayempty`,`import_limit`)\n                VALUES (1, 2, 1, 0);";
        $DB->queryOrDie($query, $DB->error());
        $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_ocsinventoryng_details` (\n                  `id` int(11) NOT NULL auto_increment,\n                  `entities_id` int(11) NOT NULL default '0',\n                  `plugin_ocsinventoryng_threads_id` int(11) NOT NULL default '0',\n                  `rules_id` TEXT,\n                  `threadid` int(11) NOT NULL default '0',\n                  `ocsid` int(11) NOT NULL default '0',\n                  `computers_id` int(11) NOT NULL default '0',\n                  `action` int(11) NOT NULL default '0',\n                  `process_time` datetime DEFAULT NULL,\n                  `plugin_ocsinventoryng_ocsservers_id` int(11) NOT NULL default '1',\n                  PRIMARY KEY (`id`),\n                  KEY `end_time` (`process_time`),\n                  KEY `process_thread` (`plugin_ocsinventoryng_threads_id`,`threadid`)\n                ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->queryOrDie($query, $DB->error());
        $query = "INSERT INTO `glpi_displaypreferences` (`itemtype`, `num`, `rank`, `users_id`)\n                VALUES ('PluginOcsinventoryngNotimportedcomputer', 2, 1, 0),\n                       ('PluginOcsinventoryngNotimportedcomputer', 3, 2, 0),\n                       ('PluginOcsinventoryngNotimportedcomputer', 4, 3, 0),\n                       ('PluginOcsinventoryngNotimportedcomputer', 5, 4, 0),\n                       ('PluginOcsinventoryngNotimportedcomputer', 6, 5, 0),\n                       ('PluginOcsinventoryngNotimportedcomputer', 7, 6, 0),\n                       ('PluginOcsinventoryngNotimportedcomputer', 8, 7, 0),\n                       ('PluginOcsinventoryngNotimportedcomputer', 9, 8, 0),\n                       ('PluginOcsinventoryngNotimportedcomputer', 10, 9, 0),\n                       ('PluginOcsinventoryngDetail', 5, 1, 0),\n                       ('PluginOcsinventoryngDetail', 2, 2, 0),\n                       ('PluginOcsinventoryngDetail', 3, 3, 0),\n                       ('PluginOcsinventoryngDetail', 4, 4, 0),\n                       ('PluginOcsinventoryngDetail', 6, 5, 0),\n                       ('PluginOcsinventoryngDetail', 80, 6, 0)";
        $DB->queryOrDie($query, $DB->error());
        $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_ocsinventoryng_notimportedcomputers` (\n                  `id` INT( 11 ) NOT NULL  auto_increment,\n                  `entities_id` int(11) NOT NULL default '0',\n                  `rules_id` TEXT,\n                  `comment` text NULL,\n                  `ocsid` INT( 11 ) NOT NULL DEFAULT '0',\n                  `plugin_ocsinventoryng_ocsservers_id` INT( 11 ) NOT NULL ,\n                  `ocs_deviceid` VARCHAR( 255 ) NOT NULL ,\n                  `useragent` VARCHAR( 255 ) NOT NULL ,\n                  `tag` VARCHAR( 255 ) NOT NULL ,\n                  `serial` VARCHAR( 255 ) NOT NULL ,\n                  `name` VARCHAR( 255 ) NOT NULL ,\n                  `ipaddr` VARCHAR( 255 ) NOT NULL ,\n                  `domain` VARCHAR( 255 ) NOT NULL ,\n                  `last_inventory` DATETIME ,\n                  `reason` INT( 11 ) NOT NULL ,\n                  PRIMARY KEY ( `id` ),\n                  UNIQUE KEY `ocs_id` (`plugin_ocsinventoryng_ocsservers_id`,`ocsid`)\n                ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ";
        $DB->queryOrDie($query, $DB->error());
        $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_ocsinventoryng_servers` (\n                  `id` int(11) NOT NULL AUTO_INCREMENT,\n                  `plugin_ocsinventoryng_ocsservers_id` int(11) NOT NULL DEFAULT '0',\n                  `max_ocsid` int(11) DEFAULT NULL,\n                  `max_glpidate` datetime DEFAULT NULL,\n                  PRIMARY KEY (`id`),\n                  UNIQUE KEY `plugin_ocsinventoryng_ocsservers_id` (`plugin_ocsinventoryng_ocsservers_id`)\n                ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ";
        $DB->queryOrDie($query, $DB->error());
    } else {
        if (!TableExists('glpi_plugin_ocsinventoryng_threads') && TableExists('glpi_plugin_massocsimport_threads')) {
            if (TableExists('glpi_plugin_massocsimport_threads') && !FieldExists('glpi_plugin_massocsimport_threads', 'not_unique_machines_number')) {
                plugin_ocsinventoryng_upgrademassocsimport14to15();
            }
            $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_ocsinventoryng_threads` (\n                  `id` int(11) NOT NULL auto_increment,\n                  `threadid` int(11) NOT NULL default '0',\n                  `start_time` datetime default NULL,\n                  `end_time` datetime default NULL,\n                  `status` int(11) NOT NULL default '0',\n                  `error_msg` text NOT NULL,\n                  `imported_machines_number` int(11) NOT NULL default '0',\n                  `synchronized_machines_number` int(11) NOT NULL default '0',\n                  `failed_rules_machines_number` int(11) NOT NULL default '0',\n                  `linked_machines_number` int(11) NOT NULL default '0',\n                  `notupdated_machines_number` int(11) NOT NULL default '0',\n                  `not_unique_machines_number` int(11) NOT NULL default '0',\n                  `link_refused_machines_number` int(11) NOT NULL default '0',\n                  `total_number_machines` int(11) NOT NULL default '0',\n                  `ocsservers_id` int(11) NOT NULL default '1',\n                  `processid` int(11) NOT NULL default '0',\n                  `entities_id` int(11) NOT NULL DEFAULT 0,\n                  `rules_id` int(11) NOT NULL DEFAULT 0,\n                  PRIMARY KEY  (`id`),\n                  KEY `end_time` (`end_time`),\n                  KEY `process_thread` (`processid`,`threadid`)\n                ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ";
            $DB->queryOrDie($query, $DB->error());
            //error of massocsimport 1.5.0 installaton
            $migration->addField("glpi_plugin_massocsimport_threads", "entities_id", 'integer');
            $migration->addField("glpi_plugin_massocsimport_threads", "rules_id", 'integer');
            foreach (getAllDatasFromTable('glpi_plugin_massocsimport_threads') as $thread) {
                if (is_null($thread['rules_id']) || $thread['rules_id'] == '') {
                    $rules_id = 0;
                } else {
                    $rules_id = $thread['rules_id'];
                }
                $query = "INSERT INTO `glpi_plugin_ocsinventoryng_threads`\n                   VALUES ('" . $thread['id'] . "',\n                           '" . $thread['threadid'] . "',\n                           '" . $thread['start_time'] . "',\n                           '" . $thread['end_time'] . "',\n                           '" . $thread['status'] . "',\n                           '" . $thread['error_msg'] . "',\n                           '" . $thread['imported_machines_number'] . "',\n                           '" . $thread['synchronized_machines_number'] . "',\n                           '" . $thread['failed_rules_machines_number'] . "',\n                           '" . $thread['linked_machines_number'] . "',\n                           '" . $thread['notupdated_machines_number'] . "',\n                           '" . $thread['not_unique_machines_number'] . "',\n                           '" . $thread['link_refused_machines_number'] . "',\n                           '" . $thread['total_number_machines'] . "',\n                           '" . $thread['ocsservers_id'] . "',\n                           '" . $thread['processid'] . "',\n                           '" . $thread['entities_id'] . "',\n                           '" . $rules_id . "');";
                $DB->queryOrDie($query, $DB->error());
            }
            $migration->renameTable("glpi_plugin_massocsimport_threads", "backup_glpi_plugin_massocsimport_threads");
            $migration->changeField("glpi_plugin_ocsinventoryng_threads", "ocsservers_id", "plugin_ocsinventoryng_ocsservers_id", 'integer');
            $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_ocsinventoryng_configs` (\n                  `id` int(11) NOT NULL auto_increment,\n                  `thread_log_frequency` int(11) NOT NULL default '10',\n                  `is_displayempty` int(1) NOT NULL default '1',\n                  `import_limit` int(11) NOT NULL default '0',\n                  `ocsservers_id` int(11) NOT NULL default '-1',\n                  `delay_refresh` int(11) NOT NULL default '0',\n                  `allow_ocs_update` tinyint(1) NOT NULL default '0',\n                  `comment` text,\n                  PRIMARY KEY (`id`)\n                ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ";
            $DB->query($query) or die($DB->error());
            foreach (getAllDatasFromTable('glpi_plugin_massocsimport_configs') as $thread) {
                $query = "INSERT INTO `glpi_plugin_ocsinventoryng_configs`\n                   VALUES('" . $thread['id'] . "',\n                          '" . $thread['thread_log_frequency'] . "',\n                          '" . $thread['is_displayempty'] . "',\n                          '" . $thread['import_limit'] . "',\n                          '" . $thread['ocsservers_id'] . "',\n                          '" . $thread['delay_refresh'] . "',\n                          '" . $thread['allow_ocs_update'] . "',\n                          '" . $thread['comment'] . "');";
                $DB->queryOrDie($query, $DB->error());
            }
            $migration->renameTable("glpi_plugin_massocsimport_configs", "backup_glpi_plugin_massocsimport_configs");
            $migration->dropField("glpi_plugin_ocsinventoryng_configs", "ocsservers_id");
            $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_ocsinventoryng_details` (\n                  `id` int(11) NOT NULL auto_increment,\n                  `entities_id` int(11) NOT NULL default '0',\n                  `plugin_massocsimport_threads_id` int(11) NOT NULL default '0',\n                  `rules_id` TEXT,\n                  `threadid` int(11) NOT NULL default '0',\n                  `ocsid` int(11) NOT NULL default '0',\n                  `computers_id` int(11) NOT NULL default '0',\n                  `action` int(11) NOT NULL default '0',\n                  `process_time` datetime DEFAULT NULL,\n                  `ocsservers_id` int(11) NOT NULL default '1',\n                  PRIMARY KEY (`id`),\n                  KEY `end_time` (`process_time`),\n                  KEY `process_thread` (`ocsservers_id`,`threadid`)\n                ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
            $DB->queryOrDie($query, $DB->error());
            foreach (getAllDatasFromTable('glpi_plugin_massocsimport_details') as $thread) {
                $query = "INSERT INTO `glpi_plugin_ocsinventoryng_details`\n                   VALUES ('" . $thread['id'] . "',\n                           '" . $thread['entities_id'] . "',\n                           '" . $thread['plugin_massocsimport_threads_id'] . "',\n                           '" . $thread['rules_id'] . "',\n                           '" . $thread['threadid'] . "',\n                           '" . $thread['ocsid'] . "',\n                           '" . $thread['computers_id'] . "',\n                           '" . $thread['action'] . "',\n                           '" . $thread['process_time'] . "',\n                           '" . $thread['ocsservers_id'] . "');";
                $DB->query($query) or die($DB->error());
            }
            $migration->renameTable("glpi_plugin_massocsimport_details", "backup_glpi_plugin_massocsimport_details");
            $migration->changeField("glpi_plugin_ocsinventoryng_details", "plugin_massocsimport_threads_id", "plugin_ocsinventoryng_threads_id", 'integer');
            $migration->changeField("glpi_plugin_ocsinventoryng_details", "ocsservers_id", "plugin_ocsinventoryng_ocsservers_id", 'integer');
            $query = "UPDATE `glpi_displaypreferences`\n                SET `itemtype` = 'PluginOcsinventoryngNotimportedcomputer'\n                WHERE `itemtype` = 'PluginMassocsimportNotimported'";
            $DB->queryOrDie($query, $DB->error());
            $query = "UPDATE `glpi_displaypreferences`\n                SET `itemtype` = 'PluginOcsinventoryngDetail'\n                WHERE `itemtype` = 'PluginMassocsimportDetail';";
            $DB->queryOrDie($query, $DB->error());
            $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_ocsinventoryng_notimportedcomputers` (\n                  `id` INT( 11 ) NOT NULL  auto_increment,\n                  `entities_id` int(11) NOT NULL default '0',\n                  `rules_id` TEXT,\n                  `comment` text NULL,\n                  `ocsid` INT( 11 ) NOT NULL DEFAULT '0',\n                  `ocsservers_id` INT( 11 ) NOT NULL ,\n                  `ocs_deviceid` VARCHAR( 255 ) NOT NULL ,\n                  `useragent` VARCHAR( 255 ) NOT NULL ,\n                  `tag` VARCHAR( 255 ) NOT NULL ,\n                  `serial` VARCHAR( 255 ) NOT NULL ,\n                  `name` VARCHAR( 255 ) NOT NULL ,\n                  `ipaddr` VARCHAR( 255 ) NOT NULL ,\n                  `domain` VARCHAR( 255 ) NOT NULL ,\n                  `last_inventory` DATETIME ,\n                  `reason` INT( 11 ) NOT NULL ,\n                  PRIMARY KEY ( `id` ),\n                  UNIQUE KEY `ocs_id` (`ocsservers_id`,`ocsid`)\n                ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ";
            $DB->queryOrDie($query, $DB->error());
            if (TableExists("glpi_plugin_massocsimport_notimported")) {
                foreach (getAllDatasFromTable('glpi_plugin_massocsimport_notimported') as $thread) {
                    $query = "INSERT INTO `glpi_plugin_ocsinventoryng_notimportedcomputers`\n                      VALUES ('" . $thread['id'] . "', '" . $thread['entities_id'] . "',\n                              '" . $thread['rules_id'] . "', '" . $thread['comment'] . "',\n                              '" . $thread['ocsid'] . "', '" . $thread['ocsservers_id'] . "',\n                              '" . $thread['ocs_deviceid'] . "', '" . $thread['useragent'] . "',\n                              '" . $thread['tag'] . "', '" . $thread['serial'] . "', '" . $thread['name'] . "',\n                              '" . $thread['ipaddr'] . "', '" . $thread['domain'] . "',\n                              '" . $thread['last_inventory'] . "', '" . $thread['reason'] . "')";
                    $DB->queryOrDie($query, $DB->error());
                }
                $migration->renameTable("glpi_plugin_massocsimport_notimported", "backup_glpi_plugin_massocsimport_notimported");
            }
            $migration->changeField("glpi_plugin_ocsinventoryng_notimportedcomputers", "ocsservers_id", "plugin_ocsinventoryng_ocsservers_id", 'integer');
            $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_ocsinventoryng_servers` (\n                  `id` int(11) NOT NULL AUTO_INCREMENT,\n                  `ocsservers_id` int(11) NOT NULL DEFAULT '0',\n                  `max_ocsid` int(11) DEFAULT NULL,\n                  `max_glpidate` datetime DEFAULT NULL,\n                  PRIMARY KEY (`id`),\n                  UNIQUE KEY `ocsservers_id` (`ocsservers_id`)\n                ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ";
            $DB->query($query) or die($DB->error());
            foreach (getAllDatasFromTable('glpi_plugin_massocsimport_servers') as $thread) {
                $query = "INSERT INTO `glpi_plugin_ocsinventoryng_servers`\n                          (`id` ,`ocsservers_id` ,`max_ocsid` ,`max_glpidate`)\n                   VALUES ('" . $thread['id'] . "',\n                           '" . $thread['ocsservers_id'] . "',\n                           '" . $thread['max_ocsid'] . "',\n                           '" . $thread['max_glpidate'] . "');";
                $DB->queryOrDie($query, $DB->error());
            }
            $migration->renameTable("glpi_plugin_massocsimport_servers", "backup_glpi_plugin_massocsimport_servers");
            $migration->changeField("glpi_plugin_ocsinventoryng_servers", "ocsservers_id", "plugin_ocsinventoryng_ocsservers_id", 'integer');
            $query = "UPDATE `glpi_notificationtemplates`\n                SET `itemtype` = 'PluginOcsinventoryngNotimportedcomputer'\n                WHERE `itemtype` = 'PluginMassocsimportNotimported'";
            $DB->queryOrDie($query, $DB->error());
            $query = "UPDATE `glpi_notifications`\n                SET `itemtype` = 'PluginOcsinventoryngNotimportedcomputer'\n                WHERE `itemtype` = 'PluginMassocsimportNotimported'";
            $DB->queryOrDie($query, $DB->error());
            $query = "UPDATE `glpi_crontasks`\n                SET `itemtype` = 'PluginOcsinventoryngThread'\n                WHERE `itemtype` = 'PluginMassocsimportThread';";
            $DB->queryOrDie($query, $DB->error());
            $query = "UPDATE `glpi_alerts`\n                SET `itemtype` = 'PluginOcsinventoryngNotimportedcomputer'\n                WHERE `itemtype` IN ('PluginMassocsimportNotimported')";
            $DB->queryOrDie($query, $DB->error());
        }
    }
    $migration->executeMigration();
    $query = "SELECT `id`\n                FROM `glpi_notificationtemplates`\n                WHERE `itemtype` = 'PluginOcsinventoryngNotimportedcomputer'";
    $result = $DB->query($query);
    if (!$DB->numrows($result)) {
        //Add template
        $query = "INSERT INTO `glpi_notificationtemplates`\n                VALUES (NULL, 'Computers not imported', 'PluginOcsinventoryngNotimportedcomputer',\n                        NOW(), '', NULL);";
        $DB->queryOrDie($query, $DB->error());
        $templates_id = $DB->insert_id();
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                VALUES (NULL, {$templates_id}, '',\n                        '##lang.notimported.action## : ##notimported.entity##',\n                '\r\n\n##lang.notimported.action## :&#160;##notimported.entity##\n\n" . "##FOREACHnotimported##&#160;\n##lang.notimported.reason## : ##notimported.reason##\n" . "##lang.notimported.name## : ##notimported.name##\n" . "##lang.notimported.deviceid## : ##notimported.deviceid##\n" . "##lang.notimported.tag## : ##notimported.tag##\n##lang.notimported.serial## : ##notimported.serial## \r\n\n" . " ##notimported.url## \n##ENDFOREACHnotimported## \r\n', '&lt;p&gt;##lang.notimported.action## :&#160;##notimported.entity##&lt;br /&gt;&lt;br /&gt;" . "##FOREACHnotimported##&#160;&lt;br /&gt;##lang.notimported.reason## : ##notimported.reason##&lt;br /&gt;" . "##lang.notimported.name## : ##notimported.name##&lt;br /&gt;" . "##lang.notimported.deviceid## : ##notimported.deviceid##&lt;br /&gt;" . "##lang.notimported.tag## : ##notimported.tag##&lt;br /&gt;" . "##lang.notimported.serial## : ##notimported.serial##&lt;/p&gt;\r\n&lt;p&gt;&lt;a href=\"##notimported.url##\"&gt;" . "##notimported.url##&lt;/a&gt;&lt;br /&gt;##ENDFOREACHnotimported##&lt;/p&gt;');";
        $DB->queryOrDie($query, $DB->error());
        $query = "INSERT INTO `glpi_notifications`\n                VALUES (NULL, 'Computers not imported', 0, 'PluginOcsinventoryngNotimportedcomputer',\n                        'not_imported', 'mail'," . $templates_id . ", '', 1, 1, NOW());";
        $DB->queryOrDie($query, $DB->error());
    }
    $cron = new CronTask();
    if (!$cron->getFromDBbyName('PluginOcsinventoryngThread', 'CleanOldThreads')) {
        CronTask::Register('PluginOcsinventoryngThread', 'CleanOldThreads', HOUR_TIMESTAMP, array('param' => 24));
    }
    if (!$cron->getFromDBbyName('PluginOcsinventoryngNotimportedcomputer', 'SendAlerts')) {
        // creation du cron - param = duree de conservation
        CronTask::Register('PluginOcsinventoryngNotimportedcomputer', 'SendAlerts', 10 * MINUTE_TIMESTAMP, array('param' => 24));
    }
    return true;
}