Exemplo n.º 1
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;
}
Exemplo n.º 2
0
/**
 * @return bool
 */
function plugin_ocsinventoryng_install()
{
    global $DB;
    include_once GLPI_ROOT . "/plugins/ocsinventoryng/inc/profile.class.php";
    $migration = new Migration(132);
    if (!TableExists("glpi_plugin_ocsinventoryng_ocsservers_profiles") && !TableExists("glpi_plugin_ocsinventoryng_ocsservers") && !TableExists("ocs_glpi_ocsservers")) {
        $install = true;
        $DB->runFile(GLPI_ROOT . "/plugins/ocsinventoryng/install/mysql/1.3.2-empty.sql");
        $migration->createRule(array('sub_type' => 'RuleImportComputer', 'entities_id' => 0, 'is_recursive' => 0, 'is_active' => 1, 'match' => 'AND', 'name' => 'RootComputerOcs'), array(array('criteria' => 'serial', 'condition' => Rule::PATTERN_FIND, 'pattern' => '1')), array(array('field' => '_fusion', 'action_type' => 'assign', 'value' => 0)));
        $migration->createRule(array('sub_type' => 'RuleImportEntity', 'entities_id' => 0, 'is_recursive' => 1, 'is_active' => 1, 'match' => 'AND', 'name' => 'RootEntityOcs'), 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' => 'RuleImportComputer', 'entities_id' => 0, 'is_recursive' => 0, 'is_active' => 1, 'match' => 'AND', 'name' => 'RootComputerOcs'), array(array('criteria' => 'serial', 'condition' => Rule::PATTERN_FIND, 'pattern' => '1')), array(array('field' => '_fusion', 'action_type' => 'assign', 'value' => 0)));
            $migration->createRule(array('sub_type' => 'RuleImportEntity', 'entities_id' => 0, 'is_recursive' => 1, 'is_active' => 1, 'match' => 'AND', 'name' => 'RootEntityOcs'), 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`\r\n                          (`profiles_id`, `ocsng`, `sync_ocsng`, `view_ocsng`, `clean_ocsng`,\r\n                           `rule_ocs`)\r\n                           SELECT `id`, `ocsng`, `sync_ocsng`, `view_ocsng`, `clean_ocsng`,\r\n                                  `rule_ocs`\r\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`\r\n                          SELECT *\r\n                          FROM `ocs_glpi_crontasks`\r\n                          WHERE `itemtype` = 'OcsServer'";
                    $DB->queryOrDie($query, "1.0.0 insert crontasks for plugin ocsinventoryng");
                    $query = "UPDATE `glpi_crontasks`\r\n                   SET `itemtype` = 'PluginOcsinventoryngOcsServer'\r\n                   WHERE `itemtype` = 'OcsServer'";
                    $DB->queryOrDie($query, "1.0.0 update ocsinventoryng crontask");
                }
                if (TableExists("ocs_glpi_displaypreferences")) {
                    $query = "INSERT INTO `glpi_displaypreferences`\r\n                          SELECT *\r\n                          FROM `ocs_glpi_displaypreferences`\r\n                          WHERE `itemtype` = 'OcsServer'";
                    $DB->queryOrDie($query, "1.0.0 insert displaypreferences for plugin ocsinventoryng");
                    $query = "UPDATE `glpi_displaypreferences`\r\n                   SET `itemtype` = 'PluginOcsinventoryngOcsServer'\r\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` \r\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` \r\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` (\r\n                  `id` INT(11) NOT NULL AUTO_INCREMENT,\r\n                  `plugin_ocsinventoryng_ocsservers_id` INT(11) NOT NULL DEFAULT '0',\r\n                  `profiles_id` INT(11) NOT NULL DEFAULT '0',\r\n                PRIMARY KEY (`id`),\r\n                KEY `plugin_ocsinventoryng_ocsservers_id` (`plugin_ocsinventoryng_ocsservers_id`),\r\n                KEY `profiles_id` (`profiles_id`)\r\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` \r\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` \r\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` \r\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` (\r\n                    `id` INT(11) NOT NULL AUTO_INCREMENT,\r\n                    `designation` VARCHAR(255) COLLATE utf8_unicode_ci DEFAULT NULL,\r\n                    `comment` TEXT COLLATE utf8_unicode_ci,\r\n                    `date` VARCHAR(255) COLLATE utf8_unicode_ci DEFAULT NULL,\r\n                    `assettag` VARCHAR(255) COLLATE utf8_unicode_ci DEFAULT NULL,\r\n                    `manufacturers_id` INT(11) NOT NULL DEFAULT '0',\r\n                    `entities_id` INT(11) NOT NULL DEFAULT '0',\r\n                    `is_recursive` TINYINT(1) NOT NULL DEFAULT '0',\r\n                    PRIMARY KEY (`id`),\r\n                    KEY `manufacturers_id` (`manufacturers_id`),\r\n                    KEY `entities_id` (`entities_id`),\r\n                    KEY `is_recursive` (`is_recursive`)\r\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` (\r\n                    `id` INT(11) NOT NULL AUTO_INCREMENT,\r\n                    `items_id` INT(11) NOT NULL DEFAULT '0',\r\n                    `itemtype` VARCHAR(255) COLLATE utf8_unicode_ci DEFAULT NULL,\r\n                    `plugin_ocsinventoryng_devicebiosdatas_id` INT(11) NOT NULL DEFAULT '0',\r\n                    `is_deleted` TINYINT(1) NOT NULL DEFAULT '0',\r\n                    `is_dynamic` TINYINT(1) NOT NULL DEFAULT '0',\r\n                    `entities_id` INT(11) NOT NULL DEFAULT '0',\r\n                    `is_recursive` TINYINT(1) NOT NULL DEFAULT '0',\r\n                    PRIMARY KEY (`id`),\r\n                    KEY `computers_id` (`items_id`),\r\n                    KEY `plugin_ocsinventoryng_devicebiosdatas_id` (`plugin_ocsinventoryng_devicebiosdatas_id`),\r\n                    KEY `is_deleted` (`is_deleted`),\r\n                    KEY `is_dynamic` (`is_dynamic`),\r\n                    KEY `entities_id` (`entities_id`),\r\n                    KEY `is_recursive` (`is_recursive`),\r\n                    KEY `item` (`itemtype`,`items_id`)\r\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`\r\n                       SET `profiles_id` = '" . $rights['profiles_id'] . "',\r\n                           `plugin_ocsinventoryng_ocsservers_id` = '" . $server['id'] . "'";
                $DB->queryOrDie($query, "insert glpi_plugin_ocsinventoryng_ocsservers_profiles");
            }
        }
    }
    $migration->dropTable('glpi_plugin_ocsinventoryng_profiles');
    //Update 1.2.2
    if (TableExists("glpi_plugin_ocsinventoryng_ocsservers") && !FieldExists('glpi_plugin_ocsinventoryng_ocsservers', 'import_device_motherboard')) {
        $query = "ALTER TABLE `glpi_plugin_ocsinventoryng_ocsservers` \r\n               ADD `import_device_motherboard` TINYINT(1) NOT NULL DEFAULT '0';";
        $DB->queryOrDie($query, "1.2.2 update table glpi_plugin_ocsinventoryng_ocsservers");
    }
    //Update 1.2.3
    if (!TableExists("glpi_plugin_ocsinventoryng_ipdiscoverocslinks")) {
        $query = "CREATE TABLE `glpi_plugin_ocsinventoryng_ipdiscoverocslinks` (\r\n                `id` INT(11) NOT NULL AUTO_INCREMENT,\r\n                `items_id` INT(11) NOT NULL,\r\n                `itemtype` VARCHAR(255) COLLATE utf8_unicode_ci DEFAULT NULL,\r\n                `macaddress` VARCHAR(255) COLLATE utf8_unicode_ci NOT NULL UNIQUE,\r\n                `last_update` DATETIME COLLATE utf8_unicode_ci DEFAULT NULL,\r\n                `subnet` VARCHAR(40) COLLATE utf8_unicode_ci DEFAULT NULL,\r\n                `plugin_ocsinventoryng_ocsservers_id` INT(11) NOT NULL DEFAULT '0',\r\n                 PRIMARY KEY (`id`)\r\n                 ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
        $DB->queryOrDie($query, "1.2.3 add table glpi_plugin_ocsinventoryng_ipdiscoverocslinks");
    }
    // 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();
        }
    }
    //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` (\r\n                  `id` INT(11) NOT NULL AUTO_INCREMENT,\r\n                  `threadid` INT(11) NOT NULL DEFAULT '0',\r\n                  `start_time` DATETIME DEFAULT NULL,\r\n                  `end_time` DATETIME DEFAULT NULL,\r\n                  `status` INT(11) NOT NULL DEFAULT '0',\r\n                  `error_msg` TEXT NOT NULL,\r\n                  `imported_machines_number` INT(11) NOT NULL DEFAULT '0',\r\n                  `synchronized_machines_number` INT(11) NOT NULL DEFAULT '0',\r\n                  `failed_rules_machines_number` INT(11) NOT NULL DEFAULT '0',\r\n                  `linked_machines_number` INT(11) NOT NULL DEFAULT '0',\r\n                  `notupdated_machines_number` INT(11) NOT NULL DEFAULT '0',\r\n                  `not_unique_machines_number` INT(11) NOT NULL DEFAULT '0',\r\n                  `link_refused_machines_number` INT(11) NOT NULL DEFAULT '0',\r\n                  `total_number_machines` INT(11) NOT NULL DEFAULT '0',\r\n                  `plugin_ocsinventoryng_ocsservers_id` INT(11) NOT NULL DEFAULT '1',\r\n                  `processid` INT(11) NOT NULL DEFAULT '0',\r\n                  `entities_id` INT(11) NOT NULL DEFAULT 0,\r\n                  `rules_id` INT(11) NOT NULL DEFAULT 0,\r\n                  PRIMARY KEY  (`id`),\r\n                  KEY `end_time` (`end_time`),\r\n                  KEY `process_thread` (`processid`,`threadid`)\r\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` (\r\n                  `id` INT(11) NOT NULL AUTO_INCREMENT,\r\n                  `thread_log_frequency` INT(11) NOT NULL DEFAULT '10',\r\n                  `is_displayempty` INT(1) NOT NULL DEFAULT '1',\r\n                  `import_limit` INT(11) NOT NULL DEFAULT '0',\r\n                  `delay_refresh` INT(11) NOT NULL DEFAULT '0',\r\n                  `allow_ocs_update` TINYINT(1) NOT NULL DEFAULT '0',\r\n                  `comment` TEXT,\r\n                  PRIMARY KEY (`id`)\r\n                ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ";
        $DB->queryOrDie($query, $DB->error());
        $query = "INSERT INTO `glpi_plugin_ocsinventoryng_configs`\r\n                       (`id`,`thread_log_frequency`,`is_displayempty`,`import_limit`)\r\n                VALUES (1, 2, 1, 0);";
        $DB->queryOrDie($query, $DB->error());
        $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_ocsinventoryng_details` (\r\n                  `id` INT(11) NOT NULL AUTO_INCREMENT,\r\n                  `entities_id` INT(11) NOT NULL DEFAULT '0',\r\n                  `plugin_ocsinventoryng_threads_id` INT(11) NOT NULL DEFAULT '0',\r\n                  `rules_id` TEXT,\r\n                  `threadid` INT(11) NOT NULL DEFAULT '0',\r\n                  `ocsid` INT(11) NOT NULL DEFAULT '0',\r\n                  `computers_id` INT(11) NOT NULL DEFAULT '0',\r\n                  `action` INT(11) NOT NULL DEFAULT '0',\r\n                  `process_time` DATETIME DEFAULT NULL,\r\n                  `plugin_ocsinventoryng_ocsservers_id` INT(11) NOT NULL DEFAULT '1',\r\n                  PRIMARY KEY (`id`),\r\n                  KEY `end_time` (`process_time`),\r\n                  KEY `process_thread` (`plugin_ocsinventoryng_threads_id`,`threadid`)\r\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`)\r\n                VALUES ('PluginOcsinventoryngNotimportedcomputer', 2, 1, 0),\r\n                       ('PluginOcsinventoryngNotimportedcomputer', 3, 2, 0),\r\n                       ('PluginOcsinventoryngNotimportedcomputer', 4, 3, 0),\r\n                       ('PluginOcsinventoryngNotimportedcomputer', 5, 4, 0),\r\n                       ('PluginOcsinventoryngNotimportedcomputer', 6, 5, 0),\r\n                       ('PluginOcsinventoryngNotimportedcomputer', 7, 6, 0),\r\n                       ('PluginOcsinventoryngNotimportedcomputer', 8, 7, 0),\r\n                       ('PluginOcsinventoryngNotimportedcomputer', 9, 8, 0),\r\n                       ('PluginOcsinventoryngNotimportedcomputer', 10, 9, 0),\r\n                       ('PluginOcsinventoryngDetail', 5, 1, 0),\r\n                       ('PluginOcsinventoryngDetail', 2, 2, 0),\r\n                       ('PluginOcsinventoryngDetail', 3, 3, 0),\r\n                       ('PluginOcsinventoryngDetail', 4, 4, 0),\r\n                       ('PluginOcsinventoryngDetail', 6, 5, 0),\r\n                       ('PluginOcsinventoryngDetail', 80, 6, 0)";
        $DB->queryOrDie($query, $DB->error());
        $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_ocsinventoryng_notimportedcomputers` (\r\n                  `id` INT( 11 ) NOT NULL  AUTO_INCREMENT,\r\n                  `entities_id` INT(11) NOT NULL DEFAULT '0',\r\n                  `rules_id` TEXT,\r\n                  `comment` TEXT NULL,\r\n                  `ocsid` INT( 11 ) NOT NULL DEFAULT '0',\r\n                  `plugin_ocsinventoryng_ocsservers_id` INT( 11 ) NOT NULL ,\r\n                  `ocs_deviceid` VARCHAR( 255 ) NOT NULL ,\r\n                  `useragent` VARCHAR( 255 ) NOT NULL ,\r\n                  `tag` VARCHAR( 255 ) NOT NULL ,\r\n                  `serial` VARCHAR( 255 ) NOT NULL ,\r\n                  `name` VARCHAR( 255 ) NOT NULL ,\r\n                  `ipaddr` VARCHAR( 255 ) NOT NULL ,\r\n                  `domain` VARCHAR( 255 ) NOT NULL ,\r\n                  `last_inventory` DATETIME ,\r\n                  `reason` INT( 11 ) NOT NULL ,\r\n                  PRIMARY KEY ( `id` ),\r\n                  UNIQUE KEY `ocs_id` (`plugin_ocsinventoryng_ocsservers_id`,`ocsid`)\r\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` (\r\n                  `id` INT(11) NOT NULL AUTO_INCREMENT,\r\n                  `plugin_ocsinventoryng_ocsservers_id` INT(11) NOT NULL DEFAULT '0',\r\n                  `max_ocsid` INT(11) DEFAULT NULL,\r\n                  `max_glpidate` DATETIME DEFAULT NULL,\r\n                  PRIMARY KEY (`id`),\r\n                  UNIQUE KEY `plugin_ocsinventoryng_ocsservers_id` (`plugin_ocsinventoryng_ocsservers_id`)\r\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` (\r\n                  `id` INT(11) NOT NULL AUTO_INCREMENT,\r\n                  `threadid` INT(11) NOT NULL DEFAULT '0',\r\n                  `start_time` DATETIME DEFAULT NULL,\r\n                  `end_time` DATETIME DEFAULT NULL,\r\n                  `status` INT(11) NOT NULL DEFAULT '0',\r\n                  `error_msg` TEXT NOT NULL,\r\n                  `imported_machines_number` INT(11) NOT NULL DEFAULT '0',\r\n                  `synchronized_machines_number` INT(11) NOT NULL DEFAULT '0',\r\n                  `failed_rules_machines_number` INT(11) NOT NULL DEFAULT '0',\r\n                  `linked_machines_number` INT(11) NOT NULL DEFAULT '0',\r\n                  `notupdated_machines_number` INT(11) NOT NULL DEFAULT '0',\r\n                  `not_unique_machines_number` INT(11) NOT NULL DEFAULT '0',\r\n                  `link_refused_machines_number` INT(11) NOT NULL DEFAULT '0',\r\n                  `total_number_machines` INT(11) NOT NULL DEFAULT '0',\r\n                  `ocsservers_id` INT(11) NOT NULL DEFAULT '1',\r\n                  `processid` INT(11) NOT NULL DEFAULT '0',\r\n                  `entities_id` INT(11) NOT NULL DEFAULT 0,\r\n                  `rules_id` INT(11) NOT NULL DEFAULT 0,\r\n                  PRIMARY KEY  (`id`),\r\n                  KEY `end_time` (`end_time`),\r\n                  KEY `process_thread` (`processid`,`threadid`)\r\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`\r\n                   VALUES ('" . $thread['id'] . "',\r\n                           '" . $thread['threadid'] . "',\r\n                           '" . $thread['start_time'] . "',\r\n                           '" . $thread['end_time'] . "',\r\n                           '" . $thread['status'] . "',\r\n                           '" . $thread['error_msg'] . "',\r\n                           '" . $thread['imported_machines_number'] . "',\r\n                           '" . $thread['synchronized_machines_number'] . "',\r\n                           '" . $thread['failed_rules_machines_number'] . "',\r\n                           '" . $thread['linked_machines_number'] . "',\r\n                           '" . $thread['notupdated_machines_number'] . "',\r\n                           '" . $thread['not_unique_machines_number'] . "',\r\n                           '" . $thread['link_refused_machines_number'] . "',\r\n                           '" . $thread['total_number_machines'] . "',\r\n                           '" . $thread['ocsservers_id'] . "',\r\n                           '" . $thread['processid'] . "',\r\n                           '" . $thread['entities_id'] . "',\r\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` (\r\n                  `id` INT(11) NOT NULL AUTO_INCREMENT,\r\n                  `thread_log_frequency` INT(11) NOT NULL DEFAULT '10',\r\n                  `is_displayempty` INT(1) NOT NULL DEFAULT '1',\r\n                  `import_limit` INT(11) NOT NULL DEFAULT '0',\r\n                  `ocsservers_id` INT(11) NOT NULL DEFAULT '-1',\r\n                  `delay_refresh` INT(11) NOT NULL DEFAULT '0',\r\n                  `allow_ocs_update` TINYINT(1) NOT NULL DEFAULT '0',\r\n                  `comment` TEXT,\r\n                  PRIMARY KEY (`id`)\r\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`\r\n                   VALUES('" . $thread['id'] . "',\r\n                          '" . $thread['thread_log_frequency'] . "',\r\n                          '" . $thread['is_displayempty'] . "',\r\n                          '" . $thread['import_limit'] . "',\r\n                          '" . $thread['ocsservers_id'] . "',\r\n                          '" . $thread['delay_refresh'] . "',\r\n                          '" . $thread['allow_ocs_update'] . "',\r\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` (\r\n                  `id` INT(11) NOT NULL AUTO_INCREMENT,\r\n                  `entities_id` INT(11) NOT NULL DEFAULT '0',\r\n                  `plugin_massocsimport_threads_id` INT(11) NOT NULL DEFAULT '0',\r\n                  `rules_id` TEXT,\r\n                  `threadid` INT(11) NOT NULL DEFAULT '0',\r\n                  `ocsid` INT(11) NOT NULL DEFAULT '0',\r\n                  `computers_id` INT(11) NOT NULL DEFAULT '0',\r\n                  `action` INT(11) NOT NULL DEFAULT '0',\r\n                  `process_time` DATETIME DEFAULT NULL,\r\n                  `ocsservers_id` INT(11) NOT NULL DEFAULT '1',\r\n                  PRIMARY KEY (`id`),\r\n                  KEY `end_time` (`process_time`),\r\n                  KEY `process_thread` (`ocsservers_id`,`threadid`)\r\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`\r\n                   VALUES ('" . $thread['id'] . "',\r\n                           '" . $thread['entities_id'] . "',\r\n                           '" . $thread['plugin_massocsimport_threads_id'] . "',\r\n                           '" . $thread['rules_id'] . "',\r\n                           '" . $thread['threadid'] . "',\r\n                           '" . $thread['ocsid'] . "',\r\n                           '" . $thread['computers_id'] . "',\r\n                           '" . $thread['action'] . "',\r\n                           '" . $thread['process_time'] . "',\r\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`\r\n                SET `itemtype` = 'PluginOcsinventoryngNotimportedcomputer'\r\n                WHERE `itemtype` = 'PluginMassocsimportNotimported'";
            $DB->queryOrDie($query, $DB->error());
            $query = "UPDATE `glpi_displaypreferences`\r\n                SET `itemtype` = 'PluginOcsinventoryngDetail'\r\n                WHERE `itemtype` = 'PluginMassocsimportDetail';";
            $DB->queryOrDie($query, $DB->error());
            $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_ocsinventoryng_notimportedcomputers` (\r\n                  `id` INT( 11 ) NOT NULL  AUTO_INCREMENT,\r\n                  `entities_id` INT(11) NOT NULL DEFAULT '0',\r\n                  `rules_id` TEXT,\r\n                  `comment` TEXT NULL,\r\n                  `ocsid` INT( 11 ) NOT NULL DEFAULT '0',\r\n                  `ocsservers_id` INT( 11 ) NOT NULL ,\r\n                  `ocs_deviceid` VARCHAR( 255 ) NOT NULL ,\r\n                  `useragent` VARCHAR( 255 ) NOT NULL ,\r\n                  `tag` VARCHAR( 255 ) NOT NULL ,\r\n                  `serial` VARCHAR( 255 ) NOT NULL ,\r\n                  `name` VARCHAR( 255 ) NOT NULL ,\r\n                  `ipaddr` VARCHAR( 255 ) NOT NULL ,\r\n                  `domain` VARCHAR( 255 ) NOT NULL ,\r\n                  `last_inventory` DATETIME ,\r\n                  `reason` INT( 11 ) NOT NULL ,\r\n                  PRIMARY KEY ( `id` ),\r\n                  UNIQUE KEY `ocs_id` (`ocsservers_id`,`ocsid`)\r\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`\r\n                      VALUES ('" . $thread['id'] . "', '" . $thread['entities_id'] . "',\r\n                              '" . $thread['rules_id'] . "', '" . $thread['comment'] . "',\r\n                              '" . $thread['ocsid'] . "', '" . $thread['ocsservers_id'] . "',\r\n                              '" . $thread['ocs_deviceid'] . "', '" . $thread['useragent'] . "',\r\n                              '" . $thread['tag'] . "', '" . $thread['serial'] . "', '" . $thread['name'] . "',\r\n                              '" . $thread['ipaddr'] . "', '" . $thread['domain'] . "',\r\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` (\r\n                  `id` INT(11) NOT NULL AUTO_INCREMENT,\r\n                  `ocsservers_id` INT(11) NOT NULL DEFAULT '0',\r\n                  `max_ocsid` INT(11) DEFAULT NULL,\r\n                  `max_glpidate` DATETIME DEFAULT NULL,\r\n                  PRIMARY KEY (`id`),\r\n                  UNIQUE KEY `ocsservers_id` (`ocsservers_id`)\r\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`\r\n                          (`id` ,`ocsservers_id` ,`max_ocsid` ,`max_glpidate`)\r\n                   VALUES ('" . $thread['id'] . "',\r\n                           '" . $thread['ocsservers_id'] . "',\r\n                           '" . $thread['max_ocsid'] . "',\r\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`\r\n                SET `itemtype` = 'PluginOcsinventoryngNotimportedcomputer'\r\n                WHERE `itemtype` = 'PluginMassocsimportNotimported'";
            $DB->queryOrDie($query, $DB->error());
            $query = "UPDATE `glpi_notifications`\r\n                SET `itemtype` = 'PluginOcsinventoryngNotimportedcomputer'\r\n                WHERE `itemtype` = 'PluginMassocsimportNotimported'";
            $DB->queryOrDie($query, $DB->error());
            $query = "UPDATE `glpi_crontasks`\r\n                SET `itemtype` = 'PluginOcsinventoryngThread'\r\n                WHERE `itemtype` = 'PluginMassocsimportThread';";
            $DB->queryOrDie($query, $DB->error());
            $query = "UPDATE `glpi_alerts`\r\n                SET `itemtype` = 'PluginOcsinventoryngNotimportedcomputer'\r\n                WHERE `itemtype` IN ('PluginMassocsimportNotimported')";
            $DB->queryOrDie($query, $DB->error());
        }
    }
    $migration->executeMigration();
    $query = "SELECT `id`\r\n                FROM `glpi_notificationtemplates`\r\n                WHERE `itemtype` = 'PluginOcsinventoryngNotimportedcomputer'";
    $result = $DB->query($query);
    if (!$DB->numrows($result)) {
        //Add template
        $query = "INSERT INTO `glpi_notificationtemplates`\r\n                VALUES (NULL, 'Computers not imported', 'PluginOcsinventoryngNotimportedcomputer',\r\n                        NOW(), '', NULL,\r\n                        NOW());";
        $DB->queryOrDie($query, $DB->error());
        $templates_id = $DB->insert_id();
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\r\n                VALUES (NULL, {$templates_id}, '',\r\n                        '##lang.notimported.action## : ##notimported.entity##',\r\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`\r\n                VALUES (NULL, 'Computers not imported', 0, 'PluginOcsinventoryngNotimportedcomputer',\r\n                        'not_imported', 'mail'," . $templates_id . ", '', 1, 1, NOW(), NOW());";
        $DB->queryOrDie($query, $DB->error());
    }
    /*1.2.2*/
    if (TableExists('glpi_plugin_ocsinventoryng_ocsservers') && !FieldExists('glpi_plugin_ocsinventoryng_ocsservers', 'use_cleancron')) {
        $query = "ALTER TABLE `glpi_plugin_ocsinventoryng_ocsservers` \r\n               ADD `use_cleancron` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `importsnmp_name` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `importsnmp_serial` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `importsnmp_comment` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `importsnmp_contact` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `importsnmp_location` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `importsnmp_domain` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `importsnmp_manufacturer` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `importsnmp_createport` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `importsnmp_last_pages_counter` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `importsnmp_firmware` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `importsnmp_power` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `importsnmp_fan` TINYINT(1) NOT NULL DEFAULT '0';";
        $DB->queryOrDie($query, "1.2.2 update table glpi_plugin_ocsinventoryng_ocsservers add use_cleancron");
    }
    if (!TableExists("glpi_plugin_ocsinventoryng_snmpocslinks")) {
        $query = "CREATE TABLE `glpi_plugin_ocsinventoryng_snmpocslinks` (\r\n                  `id` INT(11) NOT NULL AUTO_INCREMENT,\r\n                  `items_id` INT(11) NOT NULL DEFAULT '0',\r\n                  `ocs_id` INT(11) NOT NULL DEFAULT '0',\r\n                  `itemtype` VARCHAR(255) COLLATE utf8_unicode_ci DEFAULT NULL,\r\n                  `last_update` DATETIME COLLATE utf8_unicode_ci DEFAULT NULL,\r\n                  `plugin_ocsinventoryng_ocsservers_id` INT(11) NOT NULL DEFAULT '0',\r\n                  PRIMARY KEY (`id`)\r\n               ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
        $DB->queryOrDie($query, "add table for snmp");
    }
    /*1.2.3*/
    if (TableExists('glpi_plugin_ocsinventoryng_ocsservers') && !FieldExists('glpi_plugin_ocsinventoryng_ocsservers', 'dohistory')) {
        $query = "ALTER TABLE `glpi_plugin_ocsinventoryng_ocsservers` \r\n               ADD `dohistory` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `history_hardware` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `history_bios` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `history_drives` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `history_network` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `history_devices` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `history_monitor` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `history_printer` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `history_peripheral` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `history_software` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `history_vm` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `history_admininfos` TINYINT(1) NOT NULL DEFAULT '0';";
        $DB->queryOrDie($query, "1.2.3 update table glpi_plugin_ocsinventoryng_ocsservers add history");
    }
    if (TableExists('glpi_plugin_ocsinventoryng_ocsservers') && !FieldExists('glpi_plugin_ocsinventoryng_ocsservers', 'import_device_controller')) {
        $query = "ALTER TABLE `glpi_plugin_ocsinventoryng_ocsservers` \r\n               ADD `import_device_controller` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `import_device_slot` TINYINT(1) NOT NULL DEFAULT '0';";
        $DB->queryOrDie($query, "1.2.3 update table glpi_plugin_ocsinventoryng_ocsservers add import_device_controller & slot");
    }
    /**/
    /*1.3.0*/
    if (TableExists('glpi_plugin_ocsinventoryng_ocsservers') && !FieldExists('glpi_plugin_ocsinventoryng_ocsservers', 'import_antivirus')) {
        $query = "ALTER TABLE `glpi_plugin_ocsinventoryng_ocsservers` \r\n               ADD `import_antivirus` TINYINT(1) NOT NULL DEFAULT '0';";
        $DB->queryOrDie($query, "1.3.0 update table glpi_plugin_ocsinventoryng_ocsservers add import_antivirus");
    }
    if (TableExists('glpi_plugin_ocsinventoryng_ocsservers') && !FieldExists('glpi_plugin_ocsinventoryng_ocsservers', 'use_locks')) {
        $query = "ALTER TABLE `glpi_plugin_ocsinventoryng_ocsservers` \r\n               ADD `use_locks` TINYINT(1) NOT NULL DEFAULT '1';";
        $DB->queryOrDie($query, "1.3.0 update table glpi_plugin_ocsinventoryng_ocsservers add use_locks");
    }
    if (TableExists('glpi_plugin_ocsinventoryng_ocsservers') && !FieldExists('glpi_plugin_ocsinventoryng_ocsservers', 'importsnmp_printermemory')) {
        $query = "ALTER TABLE `glpi_plugin_ocsinventoryng_ocsservers` \r\n               ADD `importsnmp_printermemory` TINYINT(1) NOT NULL DEFAULT '0';";
        $DB->queryOrDie($query, "1.3.0 update table glpi_plugin_ocsinventoryng_ocsservers add importsnmp_printermemory");
    }
    if (TableExists('glpi_plugin_ocsinventoryng_snmpocslinks') && !FieldExists('glpi_plugin_ocsinventoryng_snmpocslinks', 'linked')) {
        $query = "ALTER TABLE `glpi_plugin_ocsinventoryng_snmpocslinks` \r\n               ADD `linked` TINYINT(1) NOT NULL DEFAULT '0';";
        $DB->queryOrDie($query, "1.3.0 update table glpi_plugin_ocsinventoryng_snmpocslinks add linked");
    }
    if (TableExists('glpi_plugin_ocsinventoryng_ocsservers') && !FieldExists('glpi_plugin_ocsinventoryng_ocsservers', 'linksnmp_name')) {
        $query = "ALTER TABLE `glpi_plugin_ocsinventoryng_ocsservers` \r\n               ADD `linksnmp_name` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `linksnmp_serial` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `linksnmp_comment` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `linksnmp_contact` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `linksnmp_location` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `linksnmp_domain` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `linksnmp_manufacturer` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `linksnmp_createport` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `linksnmp_last_pages_counter` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `linksnmp_firmware` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `linksnmp_power` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `linksnmp_fan` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `linksnmp_printermemory` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `importsnmp_computernetworkcards` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `importsnmp_computermemory` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `importsnmp_computerprocessors` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `importsnmp_computersoftwares` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `importsnmp_computervm` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `linksnmp_computernetworkcards` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `linksnmp_computermemory` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `linksnmp_computerprocessors` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `linksnmp_computersoftwares` TINYINT(1) NOT NULL DEFAULT '0',\r\n               ADD `linksnmp_computervm` TINYINT(1) NOT NULL DEFAULT '0';";
        $DB->queryOrDie($query, "1.3.0 update table glpi_plugin_ocsinventoryng_ocsservers add linksnmp fields");
    }
    if (TableExists('glpi_plugin_ocsinventoryng_ocsservers') && FieldExists('glpi_plugin_ocsinventoryng_ocsservers', 'history_sofware')) {
        $query = "ALTER TABLE `glpi_plugin_ocsinventoryng_ocsservers` \r\n                CHANGE `history_sofware` `history_software` TINYINT(1) NOT NULL DEFAULT '0';";
        $DB->queryOrDie($query, "1.3.0 update table glpi_plugin_ocsinventoryng_ocsservers change history_software");
    }
    /*1.3.0*/
    if (TableExists('glpi_plugin_ocsinventoryng_ipdiscoverocslinks') && FieldExists('glpi_plugin_ocsinventoryng_ipdiscoverocslinks', 'address')) {
        $query = "ALTER TABLE `glpi_plugin_ocsinventoryng_ipdiscoverocslinks` \r\n               CHANGE `address` `subnet` VARCHAR(40) COLLATE utf8_unicode_ci DEFAULT NULL;";
        $DB->queryOrDie($query, "1.3.0 update table glpi_plugin_ocsinventoryng_ipdiscoverocslinks change subnet");
    }
    /**/
    /*1.3.2*/
    if (TableExists('glpi_plugin_ocsinventoryng_ocslinks') && !FieldExists('glpi_plugin_ocsinventoryng_ocslinks', 'uptime')) {
        $query = "ALTER TABLE `glpi_plugin_ocsinventoryng_ocslinks` \r\n               ADD `uptime` varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL;";
        $DB->queryOrDie($query, "1.3.2 update table glpi_plugin_ocsinventoryng_ocslinks add uptime");
    }
    if (TableExists('glpi_plugin_ocsinventoryng_ocsservers') && !FieldExists('glpi_plugin_ocsinventoryng_ocsservers', 'import_officepack')) {
        $query = "ALTER TABLE `glpi_plugin_ocsinventoryng_ocsservers` \r\n               ADD `import_officepack` tinyint(1) NOT NULL DEFAULT '0';";
        $DB->queryOrDie($query, "1.3.2 update table glpi_plugin_ocsinventoryng_ocsservers add import_officepack");
    }
    /**/
    $cron = new CronTask();
    if (!$cron->getFromDBbyName('PluginOcsinventoryngThread', 'CleanOldThreads')) {
        CronTask::Register('PluginOcsinventoryngThread', 'CleanOldThreads', HOUR_TIMESTAMP, array('param' => 24));
    }
    if (!$cron->getFromDBbyName('PluginOcsinventoryngOcsServer', 'ocsng')) {
        CronTask::Register('PluginOcsinventoryngOcsServer', 'ocsng', MINUTE_TIMESTAMP * 5);
    }
    if (!$cron->getFromDBbyName('PluginOcsinventoryngNotimportedcomputer', 'SendAlerts')) {
        // creation du cron - param = duree de conservation
        CronTask::Register('PluginOcsinventoryngNotimportedcomputer', 'SendAlerts', 10 * MINUTE_TIMESTAMP, array('param' => 24));
    }
    if (!$cron->getFromDBbyName('PluginOcsinventoryngOcsServer', 'CleanOldAgents')) {
        CronTask::Register('PluginOcsinventoryngOcsServer', 'CleanOldAgents', DAY_TIMESTAMP, array('state' => CronTask::STATE_DISABLE));
    }
    /*Now delete old tables*/
    $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}`;");
    }
    return true;
}