Пример #1
0
function plugin_shellcommands_install()
{
    global $DB;
    include_once GLPI_ROOT . "/plugins/shellcommands/inc/profile.class.php";
    $update = false;
    if (!TableExists("glpi_plugin_cmd_profiles") && !TableExists("glpi_plugin_shellcommands_shellcommands")) {
        $DB->runFile(GLPI_ROOT . "/plugins/shellcommands/sql/empty-1.7.0.sql");
    } else {
        if (TableExists("glpi_plugin_cmd_profiles") && !TableExists("glpi_plugin_cmd_path")) {
            $update = true;
            $DB->runFile(GLPI_ROOT . "/plugins/shellcommands/sql/update-1.1.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/shellcommands/sql/update-1.2.0.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/shellcommands/sql/update-1.3.0.sql");
        } else {
            if (TableExists("glpi_plugin_cmd_profiles") && FieldExists("glpi_plugin_cmd_profiles", "interface")) {
                $update = true;
                $DB->runFile(GLPI_ROOT . "/plugins/shellcommands/sql/update-1.2.0.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/shellcommands/sql/update-1.3.0.sql");
            } else {
                if (!TableExists("glpi_plugin_shellcommands_shellcommands")) {
                    $update = true;
                    $DB->runFile(GLPI_ROOT . "/plugins/shellcommands/sql/update-1.3.0.sql");
                } else {
                    if (!TableExists("glpi_plugin_shellcommands_commandgroups")) {
                        $DB->runFile(GLPI_ROOT . "/plugins/shellcommands/sql/update-1.7.0.sql");
                    }
                }
            }
        }
    }
    if ($update) {
        $query_ = "SELECT *\n            FROM `glpi_plugin_shellcommands_profiles` ";
        $result_ = $DB->query($query_);
        if ($DB->numrows($result_) > 0) {
            while ($data = $DB->fetch_array($result_)) {
                $query = "UPDATE `glpi_plugin_shellcommands_profiles`\n                  SET `profiles_id` = '" . $data["id"] . "'\n                  WHERE `id` = '" . $data["id"] . "';";
                $result = $DB->query($query);
            }
        }
        $query = "ALTER TABLE `glpi_plugin_shellcommands_profiles`\n               DROP `name` ;";
        $result = $DB->query($query);
    }
    PluginShellcommandsProfile::initProfile();
    PluginShellcommandsProfile::createfirstAccess($_SESSION['glpiactiveprofile']['id']);
    return true;
}