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;
}
Beispiel #2
0
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.5.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 ($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_tickets"), array("glpi_plugin_databases_databases_items"));
        Plugin::migrateItemType(array(1200 => "PluginAppliancesAppliance", 1300 => "PluginWebapplicationsWebapplication"), array("glpi_plugin_databases_databases_items"));
    }
    PluginDatabasesProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
    return true;
}