示例#1
0
/**
 * @return bool
 */
function plugin_ocsinventoryng_uninstall()
{
    global $DB;
    include_once GLPI_ROOT . "/plugins/ocsinventoryng/inc/profile.class.php";
    include_once GLPI_ROOT . "/plugins/ocsinventoryng/inc/menu.class.php";
    $tables = array("glpi_plugin_ocsinventoryng_ocsservers", "glpi_plugin_ocsinventoryng_ocslinks", "glpi_plugin_ocsinventoryng_ocsadmininfoslinks", "glpi_plugin_ocsinventoryng_profiles", "glpi_plugin_ocsinventoryng_threads", "glpi_plugin_ocsinventoryng_snmpocslinks", "glpi_plugin_ocsinventoryng_ipdiscoverocslinks", "glpi_plugin_ocsinventoryng_servers", "glpi_plugin_ocsinventoryng_configs", "glpi_plugin_ocsinventoryng_notimportedcomputers", "glpi_plugin_ocsinventoryng_details", "glpi_plugin_ocsinventoryng_registrykeys", "glpi_plugin_ocsinventoryng_networkports", "glpi_plugin_ocsinventoryng_networkporttypes", "glpi_plugin_ocsinventoryng_ocsservers_profiles", "glpi_plugin_ocsinventoryng_devicebiosdatas", "glpi_plugin_ocsinventoryng_items_devicebiosdatas");
    foreach ($tables as $table) {
        $DB->query("DROP TABLE IF EXISTS `{$table}`;");
    }
    $tables_glpi = array("glpi_bookmarks", "glpi_displaypreferences", "glpi_logs");
    foreach ($tables_glpi as $table_glpi) {
        $DB->query("DELETE\r\n                  FROM `" . $table_glpi . "`\r\n                  WHERE `itemtype` IN ('PluginMassocsimportNotimported',\r\n                                       'PluginMassocsimportDetail',\r\n                                       'PluginOcsinventoryngOcsServer',\r\n                                       'PluginOcsinventoryngNotimportedcomputer',\r\n                                       'PluginOcsinventoryngDetail')");
    }
    $tables_ocs = array("ocs_glpi_crontasks", "ocs_glpi_displaypreferences", "ocs_glpi_ocsadmininfoslinks", "ocs_glpi_ocslinks", "ocs_glpi_ocsservers", "ocs_glpi_registrykeys", "ocs_glpi_profiles");
    foreach ($tables_ocs as $table_ocs) {
        $DB->query("DROP TABLE IF EXISTS `{$table_ocs}`;");
    }
    $tables_mass = array("backup_glpi_plugin_massocsimport_configs", "backup_glpi_plugin_massocsimport_details", "backup_glpi_plugin_massocsimport_notimported", "backup_glpi_plugin_massocsimport_servers", "backup_glpi_plugin_massocsimport_threads");
    foreach ($tables_mass as $table_mass) {
        $DB->query("DROP TABLE IF EXISTS `{$table_mass}`;");
    }
    $query = "DELETE\r\n             FROM `glpi_alerts`\r\n             WHERE `itemtype` IN ('PluginMassocsimportNotimported',\r\n                                  'PluginOcsinventoryngNotimportedcomputer')";
    $DB->queryOrDie($query, $DB->error());
    // clean rules
    $rule = new RuleImportEntity();
    foreach ($DB->request("glpi_rules", array('sub_type' => 'RuleImportEntity')) as $data) {
        $rule->delete($data);
    }
    $rule = new RuleImportComputer();
    foreach ($DB->request("glpi_rules", array('sub_type' => 'RuleImportComputer')) as $data) {
        $rule->delete($data);
    }
    $notification = new Notification();
    foreach (getAllDatasFromTable($notification->getTable(), "`itemtype` IN ('PluginMassocsimportNotimported',\r\n                                                 'PluginOcsinventoryngNotimportedcomputer')") as $data) {
        $notification->delete($data);
    }
    $template = new NotificationTemplate();
    foreach (getAllDatasFromTable($template->getTable(), "`itemtype` IN ('PluginMassocsimportNotimported',\r\n                                                 'PluginOcsinventoryngNotimportedcomputer')") as $data) {
        $template->delete($data);
    }
    $cron = new CronTask();
    if ($cron->getFromDBbyName('PluginMassocsimportThread', 'CleanOldThreads')) {
        CronTask::Unregister('massocsimport');
        CronTask::Unregister('CleanOldThreads');
    }
    if ($cron->getFromDBbyName('PluginOcsinventoryngOcsServer', 'ocsng')) {
        CronTask::Unregister('ocsinventoryng');
        CronTask::Unregister('ocsng');
    }
    if ($cron->getFromDBbyName('PluginOcsinventoryngNotimportedcomputer', 'SendAlerts')) {
        CronTask::Unregister('SendAlerts');
    }
    if ($cron->getFromDBbyName('PluginOcsinventoryngOcsServer', 'CleanOldAgents')) {
        CronTask::Unregister('CleanOldAgents');
    }
    //Delete rights associated with the plugin
    $profileRight = new ProfileRight();
    foreach (PluginOcsinventoryngProfile::getAllRights() as $right) {
        $profileRight->deleteByCriteria(array('name' => $right['field']));
    }
    PluginOcsinventoryngMenu::removeRightsFromSession();
    PluginOcsinventoryngProfile::removeRightsFromSession();
    return true;
}
示例#2
0
function plugin_ocsinventoryng_install()
{
    global $DB;
    include_once GLPI_ROOT . "/plugins/ocsinventoryng/inc/profile.class.php";
    $migration = new Migration(100);
    if (!TableExists("glpi_plugin_ocsinventoryng_ocsservers") && !TableExists("ocs_glpi_ocsservers")) {
        $install = true;
        $DB->runFile(GLPI_ROOT . "/plugins/ocsinventoryng/install/mysql/1.0.0-empty.sql");
        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);
        }
    }
    PluginOcsinventoryngProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
    // 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());
        $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## : ##notimported.entity##\n\n" . "##FOREACHnotimported## \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', '<p>##lang.notimported.action## : ##notimported.entity##<br /><br />" . "##FOREACHnotimported## <br />##lang.notimported.reason## : ##notimported.reason##<br />" . "##lang.notimported.name## : ##notimported.name##<br />" . "##lang.notimported.deviceid## : ##notimported.deviceid##<br />" . "##lang.notimported.tag## : ##notimported.tag##<br />" . "##lang.notimported.serial## : ##notimported.serial##</p>\r\n<p><a href=\"##notimported.url##\">" . "##notimported.url##</a><br />##ENDFOREACHnotimported##</p>');";
            $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());
        }
        CronTask::Register('PluginOcsinventoryngThread', 'CleanOldThreads', HOUR_TIMESTAMP, array('param' => 24));
    } 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();
    $cron = new CronTask();
    if (!$cron->getFromDBbyName('PluginOcsinventoryngNotimportedcomputer', 'SendAlerts')) {
        // creation du cron - param = duree de conservation
        CronTask::Register('PluginOcsinventoryngNotimportedcomputer', 'SendAlerts', 10 * MINUTE_TIMESTAMP, array('param' => 24));
    }
    return true;
}
示例#3
0
Ocsinventoryng plugin for GLPI
Copyright (C) 2012-2013 by the ocsinventoryng plugin Development Team.

https://forge.indepnet.net/projects/ocsinventoryng
-------------------------------------------------------------------------

LICENSE

This file is part of ocsinventoryng.

Ocsinventoryng plugin is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

Ocsinventoryng plugin is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with ocsinventoryng. If not, see <http://www.gnu.org/licenses/>.
---------------------------------------------------------------------------------------------------------------------------------------------------- */
include '../../../inc/includes.php';
Session::checkRight("profile", "r");
$prof = new PluginOcsinventoryngProfile();
//Save profile
if (isset($_POST['update'])) {
    $prof->update($_POST);
    Html::back();
}