Register() public static method

Register new task for plugin (called by plugin during install)
public static Register ( $itemtype, $name, $frequency, $options = [] ) : boolean
$itemtype itemtype of the plugin object
$name of the task
$frequency of execution
$options array of optional options (state, mode, allowmode, hourmin, hourmax, logs_lifetime, param, comment)
return boolean for success
Ejemplo n.º 1
0
function plugin_typology_install()
{
    global $DB;
    include_once GLPI_ROOT . "/plugins/typology/inc/profile.class.php";
    if (!TableExists("glpi_plugin_typology_typologies")) {
        // table sql creation
        $DB->runFile(GLPI_ROOT . "/plugins/typology/sql/empty-1.0.0.sql");
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginTypologyTypology' AND `name` = 'Alert no validated typology'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##typology.action## : ##typology.entity##',\n                        '##FOREACHitems##\n   ##lang.typology.name## : ##typology.name##\n   ##lang.typology.itemtype## : ##typology.itemtype##\n   ##lang.typology.items_id## : ##typology.items_id##\n   ##lang.typology.itemlocation## : ##typology.itemlocation##\n   ##lang.typology.itemuser## : ##typology.itemuser##\n   ##lang.typology.error## : ##typology.error##\n   ##ENDFOREACHitems##',\n   '<table class=\"tab_cadre\" border=\"1\" cellspacing=\"2\" cellpadding=\"3\">\n   <tbody>\n   <tr>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.typology.name##</span></td>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.typology.itemtype##</span></td>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.typology.items_id##</span></td>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.typology.itemlocation##</span></td>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.typology.itemuser##</span></td>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.typology.error##</span></td>\n   </tr>\n   ##FOREACHtypologyitems##\n   <tr>\n   <td><a href=\"##typology.url##\" target=\"_blank\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##typology.name##</span></a></td>\n   <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##typology.itemtype##</span></td>\n   <td><a href=\"##typology.itemurl##\" target=\"_blank\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##typology.items_id##</span></a></td>\n   <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##typology.itemlocation##</span></td>\n   <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##typology.itemuser##</span></td>\n   <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##typology.error##</span></td>\n   </tr>\n   ##ENDFOREACHtypologyitems##\n   </tbody>\n   </table>');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Alert no validated typology', 0, 'PluginTypologyTypology', 'AlertNotValidatedTypology',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-02-17 22:36:46');";
        $result = $DB->query($query);
    }
    if (TableExists("glpi_plugin_typology_typologycriterias")) {
        $query = "UPDATE `glpi_plugin_typology_typologycriterias`\n                     SET `itemtype`='IPAddress'\n                     WHERE `itemtype`='NetworkPort'";
        $result = $DB->query($query);
        $query = "UPDATE `glpi_plugin_typology_typologycriteriadefinitions`\n                     SET `field`='name;glpi_ipaddresses;itemlink'\n                     WHERE `field` LIKE '%glpi_networkports%'";
        $result = $DB->query($query);
    }
    CronTask::Register('PluginTypologyTypology', 'UpdateTypology', DAY_TIMESTAMP);
    CronTask::Register('PluginTypologyTypology', 'NotValidated', DAY_TIMESTAMP);
    PluginTypologyProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
    return true;
}
Ejemplo n.º 2
0
function install120()
{
    global $DB;
    //Do One time on 0.80
    $query = "INSERT INTO `glpi_notificationtemplates` VALUES(NULL, 'Projets', 'PluginProjetProjet', '2010-12-29 11:04:46','',NULL);";
    $result = $DB->query($query);
    $query = "INSERT INTO `glpi_notificationtemplates` VALUES(NULL, 'Alert Projets Tasks', 'PluginProjetProjet', '2010-12-29 11:04:46','',NULL);";
    $result = $DB->query($query);
    $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginProjetProjet' AND `name` = 'Projets'";
    $result = $DB->query($query_id) or die($DB->error());
    $itemtype = $DB->result($result, 0, 'id');
    $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                              VALUES(NULL, " . $itemtype . ", '','##lang.projet.title## - ##projet.name##',\n                     '##lang.projet.url## : ##projet.url##\n\n##lang.projet.entity## : ##projet.entity##\n##IFprojet.name####lang.projet.name## : ##projet.name####ENDIFprojet.name##\n##IFprojet.datebegin####lang.projet.datebegin## : ##projet.datebegin####ENDIFprojet.datebegin##\n##IFprojet.dateend####lang.projet.dateend## : ##projet.dateend####ENDIFprojet.dateend##\n##IFprojet.users####lang.projet.users## : ##projet.users####ENDIFprojet.users##\n##IFprojet.groups####lang.projet.groups## : ##projet.groups####ENDIFprojet.groups##\n##IFprojet.status####lang.projet.status## : ##projet.status####ENDIFprojet.status##\n##IFprojet.parent####lang.projet.parent## : ##projet.parent####ENDIFprojet.parent##\n##IFprojet.advance####lang.projet.advance## : ##projet.advance####ENDIFprojet.advance##\n##IFprojet.comment## ##lang.projet.comment## : ##projet.comment####ENDIFprojet.comment##\n##IFprojet.description####lang.projet.description## : ##projet.description####ENDIFprojet.description##\n##IFprojet.helpdesk####lang.projet.helpdesk## : ##projet.helpdesk####ENDIFprojet.helpdesk##\n##FOREACHupdates##----------\n##lang.update.title## : \n##IFupdate.name####lang.projet.name## : ##update.name####ENDIFupdate.name##\n##IFupdate.datebegin####lang.projet.datebegin## : ##update.datebegin####ENDIFupdate.datebegin##\n##IFupdate.dateend####lang.projet.dateend## : ##update.dateend####ENDIFupdate.dateend##\n##IFupdate.users####lang.projet.users## : ##update.users####ENDIFupdate.users##\n##IFupdate.groups####lang.projet.groups## : ##update.groups####ENDIFupdate.groups##\n##IFupdate.status####lang.projet.status## : ##update.status####ENDIFupdate.status##\n##IFupdate.parent####lang.projet.parent## : ##update.parent####ENDIFupdate.parent##\n##IFupdate.advance####lang.projet.advance## : ##update.advance####ENDIFupdate.advance##\n##IFupdate.comment## ##lang.projet.comment## : ##update.comment####ENDIFupdate.comment##\n##IFupdate.description####lang.projet.description## : ##update.description####ENDIFupdate.description##\n##IFupdate.helpdesk####lang.projet.helpdesk## : ##update.helpdesk####ENDIFupdate.helpdesk##\n##ENDFOREACHupdates##----------\n##IFtask.title## ##lang.task.title####ENDIFtask.title##\n##FOREACHtasks##----------\n##IFtask.name####lang.task.name## : ##task.name####ENDIFtask.name##\n##IFtask.users####lang.task.users## : ##task.users####ENDIFtask.users##\n##IFtask.groups####lang.task.groups## : ##task.groups####ENDIFtask.groups##\n##IFtask.contacts## ##lang.task.contacts## : ##task.contacts####ENDIFtask.contacts##\n##IFtask.type####lang.task.type## : ##task.type####ENDIFtask.type##\n##IFtask.status####lang.task.status## : ##task.status####ENDIFtask.status##\n##IFtask.location####lang.task.location## : ##task.location####ENDIFtask.location##\n##IFtask.advance####lang.task.advance## : ##task.advance####ENDIFtask.advance##\n##IFtask.priority####lang.task.priority## : ##task.priority####ENDIFtask.priority##\n##IFtask.comment####lang.task.comment## : ##task.comment####ENDIFtask.comment##\n##IFtask.sub####lang.task.sub## : ##task.sub####ENDIFtask.sub##\n##IFtask.others####lang.task.others## : ##task.others####ENDIFtask.others##\n##IFtask.affect####lang.task.affect## : ##task.affect####ENDIFtask.affect##\n##IFtask.depends####lang.task.depends## : ##task.depends####ENDIFtask.depends##\n##IFtask.parenttask####lang.task.parenttask## : ##task.parenttask####ENDIFtask.parenttask##\n##IFtask.realtime####lang.task.realtime## : ##task.realtime## ##ENDIFtask.realtime##\n----------##ENDFOREACHtasks##',\n                     '<p><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.projet.url##</strong> : <a href=\"##projet.url##\">##projet.url##</a></span> <br /><br /> <span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.projet.entity##</strong> : ##projet.entity##</span> <br /> ##IFprojet.name##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.projet.name##</strong> : ##projet.name##<br /></span>##ENDIFprojet.name## ##IFprojet.datebegin##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.projet.datebegin##</strong> :  ##projet.datebegin##<br /></span>##ENDIFprojet.datebegin## ##IFprojet.dateend##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.projet.dateend##</strong> :  ##projet.dateend##<br /></span>##ENDIFprojet.dateend## ##IFprojet.users##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.projet.users##</strong> :  ##projet.users##<br /></span>##ENDIFprojet.users## ##IFprojet.groups##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.projet.groups##</strong> :  ##projet.groups##<br /></span>##ENDIFprojet.groups## ##IFprojet.status##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.projet.status##</strong> :  ##projet.status##<br /></span>##ENDIFprojet.status## ##IFprojet.parent##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.projet.parent##</strong> :  ##projet.parent##<br /></span>##ENDIFprojet.parent## ##IFprojet.advance##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.projet.advance##</strong> :  ##projet.advance##<br /></span>##ENDIFprojet.advance## ##IFprojet.comment##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.projet.comment##</strong> :  ##projet.comment##<br /></span>##ENDIFprojet.comment## ##IFprojet.description##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.projet.description##</strong> :  ##projet.description##<br /></span>##ENDIFprojet.description## ##IFprojet.helpdesk##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.projet.helpdesk##</strong> :  ##projet.helpdesk##<br /></span>##ENDIFprojet.helpdesk##  ##FOREACHupdates##----------<br /><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.update.title## :</strong></span> <br /> ##IFupdate.name##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.projet.name##</strong> : ##update.name##<br /></span>##ENDIFupdate.name## ##IFupdate.datebegin##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.projet.datebegin##</strong> : ##update.datebegin##<br /></span>##ENDIFupdate.datebegin## ##IFupdate.dateend##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.projet.dateend##</strong> : ##update.dateend##<br /></span>##ENDIFupdate.dateend## ##IFupdate.users##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.projet.users##</strong> : ##update.users##<br /></span>##ENDIFupdate.users## ##IFupdate.groups##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.projet.groups##</strong> : ##update.groups##<br /></span>##ENDIFupdate.groups## ##IFupdate.status##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.projet.status##</strong> : ##update.status##<br /></span>##ENDIFupdate.status## ##IFupdate.parent##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.projet.parent##</strong> : ##update.parent##<br /></span>##ENDIFupdate.parent## ##IFupdate.advance##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.projet.advance##</strong> : ##update.advance##<br /></span>##ENDIFupdate.advance## ##IFupdate.comment##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.projet.comment##</strong> : ##update.comment##<br /></span>##ENDIFupdate.comment## ##IFupdate.description##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.projet.description##</strong> : ##update.description##<br /></span>##ENDIFupdate.description## ##IFupdate.helpdesk##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.projet.helpdesk##</strong> : ##update.helpdesk##<br /></span>##ENDIFupdate.helpdesk##  ##ENDFOREACHupdates##----------<br /> ##IFtask.title##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.task.title##</strong></span><br />##ENDIFtask.title## ##FOREACHtasks##----------<br /> ##IFtask.name##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.task.name##</strong> : ##task.name##<br /></span>##ENDIFtask.name## ##IFtask.users##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.task.users##</strong> : ##task.users##<br /></span>##ENDIFtask.users## ##IFtask.groups##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.task.groups##</strong> : ##task.groups##<br /></span>##ENDIFtask.groups## ##IFtask.contacts##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.task.contacts##</strong> : ##task.contacts##<br /></span>##ENDIFtask.contacts## ##IFtask.type##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.task.type##</strong> : ##task.type##<br /></span>##ENDIFtask.type## ##IFtask.status##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.task.status##</strong> : ##task.status##<br /></span>##ENDIFtask.status## ##IFtask.location##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.task.location##</strong> : ##task.location##<br /></span>##ENDIFtask.location## ##IFtask.advance##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.task.advance##</strong> : ##task.advance##<br /></span>##ENDIFtask.advance## ##IFtask.priority##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.task.priority##</strong> : ##task.priority##<br /></span>##ENDIFtask.priority## ##IFtask.comment##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.task.comment##</strong> : ##task.comment##<br /></span>##ENDIFtask.comment## ##IFtask.sub##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.task.sub##</strong> : ##task.sub##<br /></span>##ENDIFtask.sub## ##IFtask.others##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.task.others##</strong> : ##task.others##<br /></span>##ENDIFtask.others## ##IFtask.affect##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.task.affect##</strong> : ##task.affect##<br /></span>##ENDIFtask.affect## ##IFtask.depends##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.task.depends##</strong> : ##task.depends##<br /></span>##ENDIFtask.depends## ##IFtask.parenttask##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.task.parenttask##</strong> : ##task.parenttask##<br /></span>##ENDIFtask.parenttask## ##IFtask.realtime##<span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"><strong>##lang.task.realtime##</strong> : ##task.realtime##</span>##ENDIFtask.realtime## <br />----------##ENDFOREACHtasks##</p>');";
    $result = $DB->query($query);
    $query = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'New Project', 0, 'PluginProjetProjet', 'new',\n                                       'mail'," . $itemtype . ",\n                                       '', 1, 1, '2010-05-16 22:36:46');";
    $result = $DB->query($query);
    $query = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'Update Project', 0, 'PluginProjetProjet', 'update',\n                                       'mail'," . $itemtype . ",\n                                       '', 1, 1, '2010-05-16 22:36:46');";
    $result = $DB->query($query);
    $query = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'Delete Project', 0, 'PluginProjetProjet', 'delete',\n                                       'mail'," . $itemtype . ",\n                                       '', 1, 1, '2010-05-16 22:36:46');";
    $result = $DB->query($query);
    $query = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'New Project Task', 0, 'PluginProjetProjet', 'newtask',\n                                       'mail'," . $itemtype . ",\n                                       '', 1, 1, '2010-05-16 22:36:46');";
    $result = $DB->query($query);
    $query = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'Update Project Task', 0, 'PluginProjetProjet', 'updatetask',\n                                       'mail'," . $itemtype . ",\n                                       '', 1, 1, '2010-05-16 22:36:46');";
    $result = $DB->query($query);
    $query = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'Delete Project Task', 0, 'PluginProjetProjet', 'deletetask',\n                                       'mail'," . $itemtype . ",\n                                       '', 1, 1, '2010-05-16 22:36:46');";
    $result = $DB->query($query);
    $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginProjetProjet' AND `name` = 'Alert Projets Tasks'";
    $result = $DB->query($query_id) or die($DB->error());
    $itemtype = $DB->result($result, 0, 'id');
    $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##projet.action## : ##projet.entity##',\n                        '##FOREACHtasks## \n   ##lang.task.name## : ##task.name##\n   ##lang.task.type## : ##task.type##\n   ##lang.task.users## : ##task.users##\n   ##lang.task.groups## : ##task.groups##\n   ##lang.task.datebegin## : ##task.datebegin##\n   ##lang.task.dateend## : ##task.dateend##\n   ##lang.task.comment## : ##task.comment##\n   ##lang.task.projet## : ##task.projet##\n   ##ENDFOREACHtasks##',\n                           '<table class=\"tab_cadre\" border=\"1\" cellspacing=\"2\" cellpadding=\"3\">\n   <tbody>\n   <tr>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.task.name##</span></td>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.task.type##</span></td>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.task.users##</span></td>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.task.groups##</span></td>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.task.datebegin##</span></td>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.task.dateend##</span></td>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.task.comment##</span></td>\n   <td style=\"text-align: left;\" bgcolor=\"#cccccc\"><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##lang.task.projet##</span></td>\n   </tr>\n   ##FOREACHtasks##                 \n   <tr>\n   <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##task.name##</span></td>\n   <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##task.type##</span></td>\n   <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##task.users##</span></td>\n   <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##task.groups##</span></td>\n   <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##task.datebegin##</span></td>\n   <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##task.dateend##</span></td>\n   <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##task.comment##</span></td>\n   <td><span style=\"font-family: Verdana; font-size: 11px; text-align: left;\">##task.projet##</span></td>\n   </tr>\n   ##ENDFOREACHtasks##\n   </tbody>\n   </table>');";
    $result = $DB->query($query);
    $query = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'Alert Expired Projects Tasks', 0, 'PluginProjetProjet', 'AlertExpiredTasks',\n                                       'mail'," . $itemtype . ",\n                                       '', 1, 1, '2010-02-17 22:36:46');";
    $result = $DB->query($query);
    CronTask::Register('PluginProjetTask', 'ProjetTask', WEEK_TIMESTAMP);
}
Ejemplo n.º 3
0
function plugin_mreporting_install()
{
    global $DB;
    //get version
    $plugin = new Plugin();
    $found = $plugin->find("name = 'mreporting'");
    $plugin_mreporting = array_shift($found);
    //init migration
    $migration = new Migration($plugin_mreporting['version']);
    //create profiles table
    $queries = array();
    $queries[] = "CREATE TABLE IF NOT EXISTS `glpi_plugin_mreporting_profiles` (\n      `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,\n      `profiles_id` VARCHAR(45) NOT NULL,\n      `reports` CHAR(1),\n      `config` CHAR(1),\n   PRIMARY KEY (`id`)\n   )\n   ENGINE = MyISAM;";
    //create configuration table
    $queries[] = "CREATE TABLE IF NOT EXISTS `glpi_plugin_mreporting_configs` (\n   `id` int(11) NOT NULL auto_increment,\n   `name` varchar(255) collate utf8_unicode_ci default NULL,\n   `classname` varchar(255) collate utf8_unicode_ci default NULL,\n   `is_active` tinyint(1) NOT NULL default '0',\n   `is_notified` tinyint(1) NOT NULL default '1',\n   `show_graph` tinyint(1) NOT NULL default '0',\n   `show_area` tinyint(1) NOT NULL default '0',\n   `spline` tinyint(1) NOT NULL default '0',\n   `show_label` VARCHAR(10) default NULL,\n   `flip_data` tinyint(1) NOT NULL default '0',\n   `unit` VARCHAR(10) default NULL,\n   `default_delay` VARCHAR(10) default NULL,\n   `condition` VARCHAR(255) default NULL,\n   `graphtype` VARCHAR(255) default 'GLPI',\n   PRIMARY KEY  (`id`),\n   KEY `is_active` (`is_active`)\n   ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
    $queries[] = "CREATE TABLE  IF NOT EXISTS `glpi_plugin_mreporting_preferences` (\n   `id` int(11) NOT NULL auto_increment,\n   `users_id` int(11) NOT NULL default 0,\n   `template` varchar(255) collate utf8_unicode_ci default NULL,\n   PRIMARY KEY  (`id`),\n   KEY `users_id` (`users_id`)\n   ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
    // add display preferences
    $query_display_pref = "SELECT id \n      FROM glpi_displaypreferences\n      WHERE itemtype = 'PluginMreportingConfig'";
    $res_display_pref = $DB->query($query_display_pref);
    if ($DB->numrows($res_display_pref) == 0) {
        $queries[] = "INSERT INTO `glpi_displaypreferences` \n         VALUES (NULL,'PluginMreportingConfig','2','2','0');";
        $queries[] = "INSERT INTO `glpi_displaypreferences` \n         VALUES (NULL,'PluginMreportingConfig','3','3','0');";
        $queries[] = "INSERT INTO `glpi_displaypreferences` \n         VALUES (NULL,'PluginMreportingConfig','4','4','0');";
        $queries[] = "INSERT INTO `glpi_displaypreferences` \n         VALUES (NULL,'PluginMreportingConfig','5','5','0');";
        $queries[] = "INSERT INTO `glpi_displaypreferences` \n         VALUES (NULL,'PluginMreportingConfig','6','6','0');";
        $queries[] = "INSERT INTO `glpi_displaypreferences` \n         VALUES (NULL,'PluginMreportingConfig','8','8','0');";
    }
    $queries[] = "CREATE TABLE IF NOT EXISTS `glpi_plugin_mreporting_notifications` (\n      `id` int(11) NOT NULL auto_increment,\n      `entities_id` int(11) NOT NULL default '0',\n      `is_recursive` tinyint(1) NOT NULL default '0',\n      `name` varchar(255) collate utf8_unicode_ci default NULL,\n      `notepad` longtext collate utf8_unicode_ci,\n      `date_envoie` DATE DEFAULT NULL,\n      `notice`INT(11) NOT NULL DEFAULT 0,\n      `alert` INT(11) NOT NULL DEFAULT 0,\n      `comment` text collate utf8_unicode_ci,\n      `date_mod` datetime default NULL,\n      `is_deleted` tinyint(1) NOT NULL default '0',\n      PRIMARY KEY  (`id`)\n      ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
    foreach ($queries as $query) {
        $DB->query($query);
    }
    // == Update to 2.1 ==
    if (!FieldExists('glpi_plugin_mreporting_configs', 'is_notified')) {
        $migration->addField('glpi_plugin_mreporting_configs', 'is_notified', 'tinyint(1) NOT NULL default "1"', array('after' => 'is_active'));
        $migration->migrationOneTable('glpi_plugin_mreporting_configs');
    }
    require_once "inc/profile.class.php";
    PluginMreportingProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
    $rep_files_mreporting = GLPI_PLUGIN_DOC_DIR . "/mreporting";
    if (!is_dir($rep_files_mreporting)) {
        mkdir($rep_files_mreporting);
    }
    $notifications_folder = GLPI_PLUGIN_DOC_DIR . "/mreporting/notifications";
    if (!is_dir($notifications_folder)) {
        mkdir($notifications_folder);
    }
    require_once "inc/notification.class.php";
    PluginMreportingNotification::install();
    CronTask::Register('PluginMreportingNotification', 'SendNotifications', MONTH_TIMESTAMP);
    require_once "inc/baseclass.class.php";
    require_once "inc/common.class.php";
    require_once "inc/config.class.php";
    $config = new PluginMreportingConfig();
    $config->createFirstConfig();
    return true;
}
Ejemplo n.º 4
0
function plugin_formcreator_install()
{
    global $DB;
    if (!TableExists("glpi_plugin_formcreator_forms")) {
        $query = "CREATE TABLE `glpi_plugin_formcreator_forms` (\n                  `id` int(11) NOT NULL auto_increment,\n                  `name` varchar(255) NOT NULL collate utf8_unicode_ci,\n                  `content` longtext collate utf8_unicode_ci,\n                  `is_active` tinyint(1) NOT NULL default '0',\n                  `is_recursive` tinyint(1) NOT NULL default '0',\n                  `entities_id` int(11) NOT NULL default '0',\n\t\t\t\t  `language` varchar(5) NOT NULL collate utf8_unicode_ci,\n\t\t\t\t  `cat` INT( 3 ) NOT NULL,\n                PRIMARY KEY (`id`)\n               ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query) or die("error creating glpi_plugin_formcreator_forms " . $DB->error());
    }
    if (!TableExists("glpi_plugin_formcreator_targets")) {
        $query = "CREATE TABLE `glpi_plugin_formcreator_targets` (\n                  `id` int(11) NOT NULL auto_increment,\n                  `name` varchar(255) NOT NULL collate utf8_unicode_ci,\n                  `content` longtext collate utf8_unicode_ci,\n                  `urgency` int(11) NOT NULL default '1',\n                  `priority` int(11) NOT NULL default '1',\n                  `type` tinyint(1) NOT NULL default '2',\n                  `itilcategories_id` int(11) NOT NULL default '0',\n                  `plugin_formcreator_forms_id` int(11) NOT NULL,\n                PRIMARY KEY (`id`)\n               ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query) or die("error creating glpi_plugin_formcreator_targets " . $DB->error());
    }
    if (!TableExists("glpi_plugin_formcreator_sections")) {
        $query = "CREATE TABLE `glpi_plugin_formcreator_sections` (\n                  `id` int(11) NOT NULL auto_increment,\n                  `name` varchar(255) NOT NULL collate utf8_unicode_ci,\n                  `content` longtext collate utf8_unicode_ci,\n                  `position` int(11) NOT NULL default '0',\n                  `plugin_formcreator_targets_id` tinyint(1) NOT NULL,\n                  `plugin_formcreator_forms_id` int(11) NOT NULL,\n                PRIMARY KEY (`id`)\n               ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query) or die("error creating glpi_plugin_formcreator_sections " . $DB->error());
    } else {
        $query = "ALTER TABLE `glpi_plugin_formcreator_questions`\n\t\t\t\tCHANGE `plugin_formcreator_sections_id`\n\t\t\t\t`plugin_formcreator_sections_id` INT( 11 ) NOT NULL";
        $DB->query($query) or die("error creating glpi_plugin_formcreator_sections " . $DB->error());
    }
    if (!TableExists("glpi_plugin_formcreator_questions")) {
        $query = "CREATE TABLE `glpi_plugin_formcreator_questions` (\n                  `id` int(11) NOT NULL auto_increment,\n                  `name` varchar(255) NOT NULL collate utf8_unicode_ci,\n                  `type` int(11) NOT NULL default '0',\n                  `data` longtext collate utf8_unicode_ci,\n                  `content` longtext collate utf8_unicode_ci,\n                  `option` longtext collate utf8_unicode_ci,\n                  `position` int(11) NOT NULL default '0',\n                  `plugin_formcreator_sections_id` tinyint(1) NOT NULL,\n                  `plugin_formcreator_forms_id` int(11) NOT NULL,\n                PRIMARY KEY (`id`)\n               ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query) or die("error creating glpi_plugin_formcreator_questions " . $DB->error());
    }
    if (!TableExists("glpi_plugin_formcreator_cats")) {
        $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_cats` (\n\t\t\t  `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t  `name` varchar(255) NOT NULL,\n\t\t\t  `position` int(3) NOT NULL,\n\t\t\t  PRIMARY KEY (`id`)\n\t\t\t) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=14 ;";
        $DB->query($query) or die("error creating glpi_plugin_formcreator_cats " . $DB->error());
    }
    if (!TableExists("glpi_plugin_formcreator_titles")) {
        $query = "CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_titles` (\n\t\t\t  `id` int(2) NOT NULL AUTO_INCREMENT,\n\t\t\t  `name` longtext NOT NULL,\n\t\t\t  `language` varchar(5) NOT NULL,\n\t\t\t  PRIMARY KEY (`id`)\n\t\t\t) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;";
        $DB->query($query) or die("error creating glpi_plugin_formcreator_cats " . $DB->error());
    }
    $query = 'DELETE FROM `glpi_displaypreferences` WHERE `itemtype` = "PluginFormcreatorForm"';
    $DB->query($query) or die("error deleting glpi_displaypreferences " . $DB->error());
    $query_displayprefs = array();
    $query_displayprefs[] = "INSERT INTO `glpi_displaypreferences` \n                            VALUES (NULL,'PluginFormcreatorForm','0','0','0')";
    $query_displayprefs[] = "INSERT INTO `glpi_displaypreferences` \n                            VALUES (NULL,'PluginFormcreatorForm','1','1','0')";
    $query_displayprefs[] = "INSERT INTO `glpi_displaypreferences` \n                            VALUES (NULL,'PluginFormcreatorForm','2','2','0')";
    $query_displayprefs[] = "INSERT INTO `glpi_displaypreferences` \n                            VALUES (NULL,'PluginFormcreatorForm','3','3','0')";
    $query_displayprefs[] = "INSERT INTO `glpi_displaypreferences` \n                            VALUES (NULL,'PluginFormcreatorForm','4','4','0')";
    $query = "INSERT INTO `glpi_plugin_formcreator_cats` (`id`, `name`, `position`) VALUES (0, 'Default cat', 0);";
    foreach ($query_displayprefs as $query) {
        $DB->query($query) or die("error insert glpi_displaypreferences datas from  \n                                 glpi_plugin_formcreator_forms" . $DB->error());
    }
    //ajout d'une catégorie sinon pas d'affichage s'il n'y en pas
    $query = "INSERT INTO `glpi_plugin_formcreator_cats` (`name`, `position`) VALUES ('Default cat', 0);";
    $DB->query($query) or die("error inserting cat " . $DB->error());
    CronTask::Register('PluginFormcreator', 'Init', DAY_TIMESTAMP, array('param' => 50));
    return true;
}
Ejemplo n.º 5
0
function plugin_reservation_install()
{
    global $DB;
    $migration = new Migration(100);
    if (!TableExists("glpi_plugin_reservation_manageresa")) {
        //INSTALL
        $query = "CREATE TABLE `glpi_plugin_reservation_manageresa` (\n      `id` int(11) NOT NULL AUTO_INCREMENT,\n      `resaid` int(11) NOT NULL,\n      `matid` int(11) NOT NULL,\n      `date_return` datetime,\n      `date_theorique` datetime NOT NULL,\n      `itemtype` VARCHAR(100) NOT NULL,\n      `dernierMail` datetime,\n      PRIMARY KEY (`id`)\n\t) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->queryOrDie($query, $DB->error());
    } else {
        // UPDATE
    }
    if (TableExists("glpi_plugin_reservation_config")) {
        $query = "RENAME TABLE `glpi_plugin_reservation_config` TO `glpi_plugin_reservation_configdayforauto`";
        $DB->query($query) or die($DB->error());
    }
    if (!TableExists("glpi_plugin_reservation_configdayforauto")) {
        // Création de la table config
        $query = "CREATE TABLE `glpi_plugin_reservation_configdayforauto` (\n        `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,\n        `jour` char(32) NOT NULL default '',\n        `actif` int(1) NOT NULL default '1'\n        )ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query) or die($DB->error());
        $query = "INSERT INTO `glpi_plugin_reservation_configdayforauto` (`jour` , `actif`)\n                VALUES (\"lundi\",1),\n                       (\"mardi\",1),\n                       (\"mercredi\",1),\n                       (\"jeudi\",1),\n                       (\"vendredi\",1),\n                       (\"samedi\",0),\n                       (\"dimanche\",0)";
        $DB->queryOrDie($query) or die($DB->error());
    } else {
        // UPDATE
    }
    if (!TableExists("glpi_plugin_reservation_config")) {
        // Création de la table config
        $query = "CREATE TABLE `glpi_plugin_reservation_config` (\n        `name` VARCHAR(10) NOT NULL PRIMARY KEY,\n        `value` VARCHAR(10) NOT NULL\n        )ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query) or die($DB->error());
        $query = "INSERT INTO `glpi_plugin_reservation_config` (`name` , `value`)\n                VALUES (\"methode\",\"manual\")";
        $DB->queryOrDie($query) or die($DB->error());
    } else {
        // UPDATE
    }
    $cron = new CronTask();
    if (!$cron->getFromDBbyName('PluginReservationTask', 'SurveilleResa')) {
        CronTask::Register('PluginReservationTask', 'SurveilleResa', 5 * MINUTE_TIMESTAMP, array('param' => 24, 'mode' => 2, 'logs_lifetime' => 10));
    }
    if (!$cron->getFromDBbyName('PluginReservationTask', 'MailUserDelayedResa')) {
        CronTask::Register('PluginReservationTask', 'MailUserDelayedResa', DAY_TIMESTAMP, array('hourmin' => 23, 'hourmax' => 24, 'mode' => 2, 'logs_lifetime' => 30, 'state' => 0));
    }
    return true;
}
Ejemplo n.º 6
0
function update110to120()
{
    global $DB;
    echo "<strong>Update 1.1.0 to 1.2.0</strong><br/>";
    if (FieldExists("glpi_plugin_projet_projets", "begin_date")) {
        $query = "ALTER TABLE `glpi_plugin_projet_projets` \n                  CHANGE `begin_date` `date_begin` date default NULL";
        $DB->query($query);
    }
    if (FieldExists("glpi_plugin_projet_projets", "end_date")) {
        $query = "ALTER TABLE `glpi_plugin_projet_projets` \n                  CHANGE `end_date` `date_end` date default NULL";
        $DB->query($query);
    }
    if (FieldExists("glpi_plugin_projet_projets", "notes")) {
        $query = "ALTER TABLE `glpi_plugin_projet_projets` \n                  CHANGE `notes` `notepad` longtext collate utf8_unicode_ci";
        $DB->query($query);
    }
    if (!FieldExists("glpi_plugin_projet_projets", "is_helpdesk_visible")) {
        $query = "ALTER TABLE `glpi_plugin_projet_projets` \n                  ADD `is_helpdesk_visible` int(11) NOT NULL default '1'";
        $DB->query($query);
    }
    if (!FieldExists("glpi_plugin_projet_projets", "date_mod")) {
        $query = "ALTER TABLE `glpi_plugin_projet_projets` \n                  ADD `date_mod` datetime default NULL";
        $DB->query($query);
    }
    if (FieldExists("glpi_plugin_projet_projets", "show_export")) {
        $query = "ALTER TABLE `glpi_plugin_projet_projets` \n                  DROP `show_export`";
        $DB->query($query);
    }
    if (TableExists("glpi_plugin_projet_projets")) {
        $query = "ALTER TABLE `glpi_plugin_projet_projets` \n                  ADD INDEX (`name`),\n                  ADD INDEX (`entities_id`),\n                  ADD INDEX (`users_id`),\n                  ADD INDEX (`groups_id`),\n                  ADD INDEX (`date_mod`),\n                  ADD INDEX (`is_helpdesk_visible`),\n                  ADD INDEX (`is_template`),\n                  ADD INDEX (`is_deleted`)";
        $DB->query($query);
    }
    if (TableExists("glpi_plugin_projet_mailings")) {
        $query = "DROP TABLE `glpi_plugin_projet_mailings`";
        $DB->query($query);
    }
    if (!FieldExists("glpi_plugin_projet_projetstates", "color")) {
        $query = "ALTER TABLE `glpi_plugin_projet_projetstates` \n                  ADD `color` char(20) COLLATE utf8_unicode_ci DEFAULT '#CCCCCC'";
        $DB->query($query);
    }
    if (!FieldExists("glpi_plugin_projet_projetstates", "type")) {
        $query = "ALTER TABLE `glpi_plugin_projet_projetstates` \n                  ADD `type` tinyint(1) NOT NULL default '0'";
        $DB->query($query);
    }
    if (TableExists("glpi_plugin_projet_projetitems")) {
        $query = "RENAME TABLE `glpi_plugin_projet_projetitems` TO `glpi_plugin_projet_projets_items` ";
        $DB->query($query);
    }
    if (!FieldExists("glpi_plugin_projet_tasks", "entities_id")) {
        $query = "ALTER TABLE `glpi_plugin_projet_tasks` \n                  ADD `entities_id` int(11) NOT NULL default '0'";
        $DB->query($query);
    }
    if (!FieldExists("glpi_plugin_projet_tasks", "is_recursive")) {
        $query = "ALTER TABLE `glpi_plugin_projet_tasks` \n                  ADD `is_recursive` tinyint(1) NOT NULL default '0'";
        $DB->query($query);
    }
    if (!FieldExists("glpi_plugin_projet_tasks", "contacts_id")) {
        $query = "ALTER TABLE `glpi_plugin_projet_tasks` \n                  CHANGE `suppliers_id` `contacts_id` int(11) NOT NULL default '0';";
        $DB->query($query);
    }
    if (FieldExists("glpi_plugin_projet_tasks", "begin_date")) {
        $query = "ALTER TABLE `glpi_plugin_projet_tasks` \n                   CHANGE `begin_date` `date_begin` datetime default NULL";
        $DB->query($query);
    }
    if (FieldExists("glpi_plugin_projet_tasks", "end_date")) {
        $query = "ALTER TABLE `glpi_plugin_projet_tasks` \n                  CHANGE `end_date` `date_end` datetime default NULL";
        $DB->query($query);
    }
    if (FieldExists("glpi_plugin_projet_tasks", "contents")) {
        $query = "ALTER TABLE `glpi_plugin_projet_tasks` \n                  CHANGE `contents` `comment` text collate utf8_unicode_ci";
        $DB->query($query);
    }
    if (FieldExists("glpi_plugin_projet_tasks", "use_planning")) {
        $query = "ALTER TABLE `glpi_plugin_projet_tasks` \n                  DROP `use_planning`";
        $DB->query($query);
    }
    if (FieldExists("glpi_plugin_projet_tasks", "show_export")) {
        $query = "ALTER TABLE `glpi_plugin_projet_tasks` \n                  DROP `show_export`";
        $DB->query($query);
    }
    if (!FieldExists("glpi_plugin_projet_tasks", "date_mod")) {
        $query = "ALTER TABLE `glpi_plugin_projet_tasks` \n                  ADD `date_mod` datetime default NULL";
        $DB->query($query);
    }
    if (TableExists("glpi_plugin_projet_tasks")) {
        $query = "ALTER TABLE `glpi_plugin_projet_tasks` \n                  ADD INDEX (`name`),\n                  ADD INDEX (`entities_id`),\n                  ADD INDEX (`users_id`),\n                  ADD INDEX (`groups_id`),\n                  ADD INDEX (`locations_id`),\n                  ADD INDEX (`plugin_projet_tasktypes_id`),\n                  ADD INDEX (`is_template`),\n                  ADD INDEX (`is_deleted`)";
        $DB->query($query);
    }
    if (!TableExists("glpi_plugin_projet_taskplannings")) {
        $query = "CREATE TABLE `glpi_plugin_projet_taskplannings` (\n                 `id` int(11) NOT NULL auto_increment,\n                 `plugin_projet_tasks_id` int(11) NOT NULL default '0'COMMENT 'RELATION to glpi_plugin_projet_tasks (id)',\n                 `begin` datetime default NULL,\n                 `end` datetime default NULL,\n                 PRIMARY KEY  (`id`),\n                 KEY `begin` (`begin`),\n                 KEY `end` (`end`),\n                 KEY `plugin_projet_tasks_id` (`plugin_projet_tasks_id`)\n               ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
        $DB->query($query);
    }
    if (TableExists("glpi_plugin_projet_taskitems")) {
        $query = "RENAME TABLE `glpi_plugin_projet_taskitems` TO `glpi_plugin_projet_tasks_items` ";
        $DB->query($query);
    }
    if (!FieldExists("glpi_plugin_projet_taskstates", "color")) {
        $query = "ALTER TABLE `glpi_plugin_projet_taskstates` \n                  ADD `color` char(20) COLLATE utf8_unicode_ci DEFAULT '#CCCCCC'";
        $DB->query($query);
    }
    if (!FieldExists("glpi_plugin_projet_taskstates", "for_dependency")) {
        $query = "ALTER TABLE `glpi_plugin_projet_taskstates` \n                  ADD `for_dependency` tinyint(1) NOT NULL default '0'";
        $DB->query($query);
    }
    if (!FieldExists("glpi_plugin_projet_taskstates", "for_planning")) {
        $query = "ALTER TABLE `glpi_plugin_projet_taskstates` \n                  ADD `for_planning` tinyint(1) NOT NULL default '0'";
        $DB->query($query);
    }
    // ** Update glpi_plugin_projet_profiles
    if (!FieldExists("glpi_plugin_projet_profiles", "profiles_id")) {
        $query = "ALTER TABLE `glpi_plugin_projet_profiles` \n                  ADD `profiles_id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_profiles (id)',\n                  ADD INDEX (`profiles_id`);";
        $DB->query($query);
    }
    //Clean profiles
    $query_ = "SELECT *\n            FROM `glpi_plugin_projet_profiles` ";
    $result_ = $DB->query($query_);
    if ($DB->numrows($result_) > 0) {
        while ($data = $DB->fetch_array($result_)) {
            $query = "UPDATE `glpi_plugin_projet_profiles`\n                  SET `profiles_id` = '" . $data["id"] . "'\n                  WHERE `id` = '" . $data["id"] . "';";
            $result = $DB->query($query);
        }
    }
    $query = "ALTER TABLE `glpi_plugin_projet_profiles`\n            DROP `name` ;";
    $result = $DB->query($query);
    Plugin::migrateItemType(array(2300 => 'PluginProjetProjet', 2301 => 'PluginProjetTask'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_tickets"), array("glpi_plugin_projet_projets_items", "glpi_plugin_projet_tasks_items"));
    Plugin::migrateItemType(array(1200 => "PluginAppliancesAppliance"), array("glpi_plugin_projet_projets_items", "glpi_plugin_projet_tasks_items"));
    // ADD entities to tasks
    $PluginProjetTask = new PluginProjetTask();
    $tasks = getAllDatasFromTable("glpi_plugin_projet_tasks");
    if (!empty($tasks)) {
        foreach ($tasks as $task) {
            $restrict = "`id` = '" . $task["plugin_projet_projets_id"] . "'";
            $projets = getAllDatasFromTable("glpi_plugin_projet_projets", $restrict);
            if (!empty($projets)) {
                foreach ($projets as $projet) {
                    $input["entities_id"] = $projet["entities_id"];
                }
            }
            $query = "UPDATE `glpi_plugin_projet_tasks` SET `entities_id` = '" . $input["entities_id"] . "' \n                  WHERE `glpi_plugin_projet_tasks`.`id` ='" . $task["id"] . "';";
            $result = $DB->query($query);
        }
    }
    // ADD plannings for tasks
    $PluginProjetTask = new PluginProjetTask();
    $PluginProjetTaskPlanning = new PluginProjetTaskPlanning();
    $restrict = "`date_begin` IS NOT NULL";
    $tasks = getAllDatasFromTable("glpi_plugin_projet_tasks", $restrict);
    if (!empty($tasks)) {
        foreach ($tasks as $task) {
            $query = "INSERT INTO `glpi_plugin_projet_taskplannings` (\n                  `id` ,\n                  `plugin_projet_tasks_id` ,\n                  `begin` ,\n                  `end`\n                  )\n                  VALUES (\n                  NULL , '" . $task["id"] . "', '" . $task["date_begin"] . "', '" . $task["date_end"] . "');";
            $result = $DB->query($query);
            unset($input);
        }
    }
    $query = "ALTER TABLE `glpi_plugin_projet_tasks`\n            DROP `date_begin`, DROP `date_end` ;";
    $result = $DB->query($query);
    //Do One time on 0.80
    $query = "INSERT INTO `glpi_notificationtemplates` VALUES(NULL, 'Projets', 'PluginProjetProjet', '2010-12-29 11:04:46','',NULL);";
    $result = $DB->query($query);
    $query = "INSERT INTO `glpi_notificationtemplates` VALUES(NULL, 'Alert Projets Tasks', 'PluginProjetProjet', '2010-12-29 11:04:46','',NULL);";
    $result = $DB->query($query);
    $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginProjetProjet' AND `name` = 'Projets'";
    $result = $DB->query($query_id) or die($DB->error());
    $itemtype = $DB->result($result, 0, 'id');
    $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                              VALUES(NULL, " . $itemtype . ", '','##lang.projet.title## - ##projet.name##',\n                     '##lang.projet.url## : ##projet.url##\n\n##lang.projet.entity## : ##projet.entity##\n##IFprojet.name####lang.projet.name## : ##projet.name####ENDIFprojet.name##\n##IFprojet.datebegin####lang.projet.datebegin## : ##projet.datebegin####ENDIFprojet.datebegin##\n##IFprojet.dateend####lang.projet.dateend## : ##projet.dateend####ENDIFprojet.dateend##\n##IFprojet.users####lang.projet.users## : ##projet.users####ENDIFprojet.users##\n##IFprojet.groups####lang.projet.groups## : ##projet.groups####ENDIFprojet.groups##\n##IFprojet.status####lang.projet.status## : ##projet.status####ENDIFprojet.status##\n##IFprojet.parent####lang.projet.parent## : ##projet.parent####ENDIFprojet.parent##\n##IFprojet.advance####lang.projet.advance## : ##projet.advance####ENDIFprojet.advance##\n##IFprojet.comment## ##lang.projet.comment## : ##projet.comment####ENDIFprojet.comment##\n##IFprojet.description####lang.projet.description## : ##projet.description####ENDIFprojet.description##\n##IFprojet.helpdesk####lang.projet.helpdesk## : ##projet.helpdesk####ENDIFprojet.helpdesk##\n##FOREACHupdates##----------\n##lang.update.title## : \n##IFupdate.name####lang.projet.name## : ##update.name####ENDIFupdate.name##\n##IFupdate.datebegin####lang.projet.datebegin## : ##update.datebegin####ENDIFupdate.datebegin##\n##IFupdate.dateend####lang.projet.dateend## : ##update.dateend####ENDIFupdate.dateend##\n##IFupdate.users####lang.projet.users## : ##update.users####ENDIFupdate.users##\n##IFupdate.groups####lang.projet.groups## : ##update.groups####ENDIFupdate.groups##\n##IFupdate.status####lang.projet.status## : ##update.status####ENDIFupdate.status##\n##IFupdate.parent####lang.projet.parent## : ##update.parent####ENDIFupdate.parent##\n##IFupdate.advance####lang.projet.advance## : ##update.advance####ENDIFupdate.advance##\n##IFupdate.comment## ##lang.projet.comment## : ##update.comment####ENDIFupdate.comment##\n##IFupdate.description####lang.projet.description## : ##update.description####ENDIFupdate.description##\n##IFupdate.helpdesk####lang.projet.helpdesk## : ##update.helpdesk####ENDIFupdate.helpdesk##\n##ENDFOREACHupdates##----------\n##IFtask.title## ##lang.task.title####ENDIFtask.title##\n##FOREACHtasks##----------\n##IFtask.name####lang.task.name## : ##task.name####ENDIFtask.name##\n##IFtask.users####lang.task.users## : ##task.users####ENDIFtask.users##\n##IFtask.groups####lang.task.groups## : ##task.groups####ENDIFtask.groups##\n##IFtask.contacts## ##lang.task.contacts## : ##task.contacts####ENDIFtask.contacts##\n##IFtask.type####lang.task.type## : ##task.type####ENDIFtask.type##\n##IFtask.status####lang.task.status## : ##task.status####ENDIFtask.status##\n##IFtask.location####lang.task.location## : ##task.location####ENDIFtask.location##\n##IFtask.advance####lang.task.advance## : ##task.advance####ENDIFtask.advance##\n##IFtask.priority####lang.task.priority## : ##task.priority####ENDIFtask.priority##\n##IFtask.comment####lang.task.comment## : ##task.comment####ENDIFtask.comment##\n##IFtask.sub####lang.task.sub## : ##task.sub####ENDIFtask.sub##\n##IFtask.others####lang.task.others## : ##task.others####ENDIFtask.others##\n##IFtask.affect####lang.task.affect## : ##task.affect####ENDIFtask.affect##\n##IFtask.depends####lang.task.depends## : ##task.depends####ENDIFtask.depends##\n##IFtask.parenttask####lang.task.parenttask## : ##task.parenttask####ENDIFtask.parenttask##\n##IFtask.realtime####lang.task.realtime## : ##task.realtime## ##ENDIFtask.realtime##\n----------##ENDFOREACHtasks##',\n                     '&lt;p&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.projet.url##&lt;/strong&gt; : &lt;a href=\"##projet.url##\"&gt;##projet.url##&lt;/a&gt;&lt;/span&gt; &lt;br /&gt;&lt;br /&gt; &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.projet.entity##&lt;/strong&gt; : ##projet.entity##&lt;/span&gt; &lt;br /&gt; ##IFprojet.name##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.projet.name##&lt;/strong&gt; : ##projet.name##&lt;br /&gt;&lt;/span&gt;##ENDIFprojet.name## ##IFprojet.datebegin##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.projet.datebegin##&lt;/strong&gt; :  ##projet.datebegin##&lt;br /&gt;&lt;/span&gt;##ENDIFprojet.datebegin## ##IFprojet.dateend##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.projet.dateend##&lt;/strong&gt; :  ##projet.dateend##&lt;br /&gt;&lt;/span&gt;##ENDIFprojet.dateend## ##IFprojet.users##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.projet.users##&lt;/strong&gt; :  ##projet.users##&lt;br /&gt;&lt;/span&gt;##ENDIFprojet.users## ##IFprojet.groups##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.projet.groups##&lt;/strong&gt; :  ##projet.groups##&lt;br /&gt;&lt;/span&gt;##ENDIFprojet.groups## ##IFprojet.status##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.projet.status##&lt;/strong&gt; :  ##projet.status##&lt;br /&gt;&lt;/span&gt;##ENDIFprojet.status## ##IFprojet.parent##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.projet.parent##&lt;/strong&gt; :  ##projet.parent##&lt;br /&gt;&lt;/span&gt;##ENDIFprojet.parent## ##IFprojet.advance##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.projet.advance##&lt;/strong&gt; :  ##projet.advance##&lt;br /&gt;&lt;/span&gt;##ENDIFprojet.advance## ##IFprojet.comment##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.projet.comment##&lt;/strong&gt; :  ##projet.comment##&lt;br /&gt;&lt;/span&gt;##ENDIFprojet.comment## ##IFprojet.description##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.projet.description##&lt;/strong&gt; :  ##projet.description##&lt;br /&gt;&lt;/span&gt;##ENDIFprojet.description## ##IFprojet.helpdesk##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.projet.helpdesk##&lt;/strong&gt; :  ##projet.helpdesk##&lt;br /&gt;&lt;/span&gt;##ENDIFprojet.helpdesk##  ##FOREACHupdates##----------&lt;br /&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.update.title## :&lt;/strong&gt;&lt;/span&gt; &lt;br /&gt; ##IFupdate.name##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.projet.name##&lt;/strong&gt; : ##update.name##&lt;br /&gt;&lt;/span&gt;##ENDIFupdate.name## ##IFupdate.datebegin##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.projet.datebegin##&lt;/strong&gt; : ##update.datebegin##&lt;br /&gt;&lt;/span&gt;##ENDIFupdate.datebegin## ##IFupdate.dateend##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.projet.dateend##&lt;/strong&gt; : ##update.dateend##&lt;br /&gt;&lt;/span&gt;##ENDIFupdate.dateend## ##IFupdate.users##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.projet.users##&lt;/strong&gt; : ##update.users##&lt;br /&gt;&lt;/span&gt;##ENDIFupdate.users## ##IFupdate.groups##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.projet.groups##&lt;/strong&gt; : ##update.groups##&lt;br /&gt;&lt;/span&gt;##ENDIFupdate.groups## ##IFupdate.status##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.projet.status##&lt;/strong&gt; : ##update.status##&lt;br /&gt;&lt;/span&gt;##ENDIFupdate.status## ##IFupdate.parent##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.projet.parent##&lt;/strong&gt; : ##update.parent##&lt;br /&gt;&lt;/span&gt;##ENDIFupdate.parent## ##IFupdate.advance##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.projet.advance##&lt;/strong&gt; : ##update.advance##&lt;br /&gt;&lt;/span&gt;##ENDIFupdate.advance## ##IFupdate.comment##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.projet.comment##&lt;/strong&gt; : ##update.comment##&lt;br /&gt;&lt;/span&gt;##ENDIFupdate.comment## ##IFupdate.description##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.projet.description##&lt;/strong&gt; : ##update.description##&lt;br /&gt;&lt;/span&gt;##ENDIFupdate.description## ##IFupdate.helpdesk##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.projet.helpdesk##&lt;/strong&gt; : ##update.helpdesk##&lt;br /&gt;&lt;/span&gt;##ENDIFupdate.helpdesk##  ##ENDFOREACHupdates##----------&lt;br /&gt; ##IFtask.title##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.task.title##&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;##ENDIFtask.title## ##FOREACHtasks##----------&lt;br /&gt; ##IFtask.name##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.task.name##&lt;/strong&gt; : ##task.name##&lt;br /&gt;&lt;/span&gt;##ENDIFtask.name## ##IFtask.users##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.task.users##&lt;/strong&gt; : ##task.users##&lt;br /&gt;&lt;/span&gt;##ENDIFtask.users## ##IFtask.groups##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.task.groups##&lt;/strong&gt; : ##task.groups##&lt;br /&gt;&lt;/span&gt;##ENDIFtask.groups## ##IFtask.contacts##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.task.contacts##&lt;/strong&gt; : ##task.contacts##&lt;br /&gt;&lt;/span&gt;##ENDIFtask.contacts## ##IFtask.type##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.task.type##&lt;/strong&gt; : ##task.type##&lt;br /&gt;&lt;/span&gt;##ENDIFtask.type## ##IFtask.status##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.task.status##&lt;/strong&gt; : ##task.status##&lt;br /&gt;&lt;/span&gt;##ENDIFtask.status## ##IFtask.location##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.task.location##&lt;/strong&gt; : ##task.location##&lt;br /&gt;&lt;/span&gt;##ENDIFtask.location## ##IFtask.advance##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.task.advance##&lt;/strong&gt; : ##task.advance##&lt;br /&gt;&lt;/span&gt;##ENDIFtask.advance## ##IFtask.priority##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.task.priority##&lt;/strong&gt; : ##task.priority##&lt;br /&gt;&lt;/span&gt;##ENDIFtask.priority## ##IFtask.comment##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.task.comment##&lt;/strong&gt; : ##task.comment##&lt;br /&gt;&lt;/span&gt;##ENDIFtask.comment## ##IFtask.sub##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.task.sub##&lt;/strong&gt; : ##task.sub##&lt;br /&gt;&lt;/span&gt;##ENDIFtask.sub## ##IFtask.others##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.task.others##&lt;/strong&gt; : ##task.others##&lt;br /&gt;&lt;/span&gt;##ENDIFtask.others## ##IFtask.affect##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.task.affect##&lt;/strong&gt; : ##task.affect##&lt;br /&gt;&lt;/span&gt;##ENDIFtask.affect## ##IFtask.depends##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.task.depends##&lt;/strong&gt; : ##task.depends##&lt;br /&gt;&lt;/span&gt;##ENDIFtask.depends## ##IFtask.parenttask##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.task.parenttask##&lt;/strong&gt; : ##task.parenttask##&lt;br /&gt;&lt;/span&gt;##ENDIFtask.parenttask## ##IFtask.realtime##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.task.realtime##&lt;/strong&gt; : ##task.realtime##&lt;/span&gt;##ENDIFtask.realtime## &lt;br /&gt;----------##ENDFOREACHtasks##&lt;/p&gt;');";
    $result = $DB->query($query);
    $query = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'New Project', 0, 'PluginProjetProjet', 'new',\n                                       'mail'," . $itemtype . ",\n                                       '', 1, 1, '2010-05-16 22:36:46');";
    $result = $DB->query($query);
    $query = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'Update Project', 0, 'PluginProjetProjet', 'update',\n                                       'mail'," . $itemtype . ",\n                                       '', 1, 1, '2010-05-16 22:36:46');";
    $result = $DB->query($query);
    $query = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'Delete Project', 0, 'PluginProjetProjet', 'delete',\n                                       'mail'," . $itemtype . ",\n                                       '', 1, 1, '2010-05-16 22:36:46');";
    $result = $DB->query($query);
    $query = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'New Project Task', 0, 'PluginProjetProjet', 'newtask',\n                                       'mail'," . $itemtype . ",\n                                       '', 1, 1, '2010-05-16 22:36:46');";
    $result = $DB->query($query);
    $query = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'Update Project Task', 0, 'PluginProjetProjet', 'updatetask',\n                                       'mail'," . $itemtype . ",\n                                       '', 1, 1, '2010-05-16 22:36:46');";
    $result = $DB->query($query);
    $query = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'Delete Project Task', 0, 'PluginProjetProjet', 'deletetask',\n                                       'mail'," . $itemtype . ",\n                                       '', 1, 1, '2010-05-16 22:36:46');";
    $result = $DB->query($query);
    $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginProjetProjet' AND `name` = 'Alert Projets Tasks'";
    $result = $DB->query($query_id) or die($DB->error());
    $itemtype = $DB->result($result, 0, 'id');
    $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##projet.action## : ##projet.entity##',\n                        '##FOREACHtasks## \n   ##lang.task.name## : ##task.name##\n   ##lang.task.type## : ##task.type##\n   ##lang.task.users## : ##task.users##\n   ##lang.task.groups## : ##task.groups##\n   ##lang.task.datebegin## : ##task.datebegin##\n   ##lang.task.dateend## : ##task.dateend##\n   ##lang.task.comment## : ##task.comment##\n   ##lang.task.projet## : ##task.projet##\n   ##ENDFOREACHtasks##',\n                           '&lt;table class=\"tab_cadre\" border=\"1\" cellspacing=\"2\" cellpadding=\"3\"&gt;\n   &lt;tbody&gt;\n   &lt;tr&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.task.name##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.task.type##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.task.users##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.task.groups##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.task.datebegin##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.task.dateend##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.task.comment##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.task.projet##&lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   ##FOREACHtasks##                 \n   &lt;tr&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##task.name##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##task.type##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##task.users##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##task.groups##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##task.datebegin##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##task.dateend##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##task.comment##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##task.projet##&lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   ##ENDFOREACHtasks##\n   &lt;/tbody&gt;\n   &lt;/table&gt;');";
    $result = $DB->query($query);
    $query = "INSERT INTO `glpi_notifications`\n                                VALUES (NULL, 'Alert Expired Projects Tasks', 0, 'PluginProjetProjet', 'AlertExpiredTasks',\n                                       'mail'," . $itemtype . ",\n                                       '', 1, 1, '2010-02-17 22:36:46');";
    $result = $DB->query($query);
    CronTask::Register('PluginProjetTask', 'ProjetTask', WEEK_TIMESTAMP);
}
Ejemplo n.º 7
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## :&#160;##notimported.entity##\n\n" . "##FOREACHnotimported##&#160;\n##lang.notimported.reason## : ##notimported.reason##\n" . "##lang.notimported.name## : ##notimported.name##\n" . "##lang.notimported.deviceid## : ##notimported.deviceid##\n" . "##lang.notimported.tag## : ##notimported.tag##\n##lang.notimported.serial## : ##notimported.serial## \r\n\n" . " ##notimported.url## \n##ENDFOREACHnotimported## \r\n', '&lt;p&gt;##lang.notimported.action## :&#160;##notimported.entity##&lt;br /&gt;&lt;br /&gt;" . "##FOREACHnotimported##&#160;&lt;br /&gt;##lang.notimported.reason## : ##notimported.reason##&lt;br /&gt;" . "##lang.notimported.name## : ##notimported.name##&lt;br /&gt;" . "##lang.notimported.deviceid## : ##notimported.deviceid##&lt;br /&gt;" . "##lang.notimported.tag## : ##notimported.tag##&lt;br /&gt;" . "##lang.notimported.serial## : ##notimported.serial##&lt;/p&gt;\r\n&lt;p&gt;&lt;a href=\"##notimported.url##\"&gt;" . "##notimported.url##&lt;/a&gt;&lt;br /&gt;##ENDFOREACHnotimported##&lt;/p&gt;');";
            $DB->queryOrDie($query, $DB->error());
            $query = "INSERT INTO `glpi_notifications`\n                   VALUES (NULL, 'Computers not imported', 0, 'PluginOcsinventoryngNotimportedcomputer',\n                           'not_imported', 'mail'," . $templates_id . ", '', 1, 1, NOW());";
            $DB->queryOrDie($query, $DB->error());
        }
        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;
}
Ejemplo n.º 8
0
 static function install(Migration $migration)
 {
     $cron = new CronTask();
     if (!$cron->getFromDBbyName(__CLASS__, 'purgeLogs')) {
         CronTask::Register(__CLASS__, 'purgeLogs', 7 * DAY_TIMESTAMP, array('param' => 24, 'mode' => CronTask::MODE_EXTERNAL));
     }
 }
Ejemplo n.º 9
0
function pluginMonitoringUpdate($current_version, $migrationname = 'Migration')
{
    global $DB;
    $migration = new $migrationname($current_version);
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/monitoring')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . "/monitoring");
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/monitoring/templates')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . "/monitoring/templates");
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/monitoring/weathermapbg')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . "/monitoring/weathermapbg");
    }
    $unavaibility_recalculate = 0;
    if (!TableExists("glpi_plugin_monitoring_unavaibilities") || !FieldExists("glpi_plugin_monitoring_unavaibilities", "duration")) {
        $unavaibility_recalculate = 1;
    }
    /*
     * Table glpi_plugin_monitoring_servicescatalogs
     */
    $newTable = "glpi_plugin_monitoring_servicescatalogs";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'entities_id', 'entities_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'is_recursive', 'is_recursive', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'comment', 'comment', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->changeField($newTable, 'last_check', 'last_check', "datetime DEFAULT NULL");
    $migration->changeField($newTable, 'state', 'state', "varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'state_type', 'state_type', "varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'plugin_monitoring_checks_id', 'plugin_monitoring_checks_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'calendars_id', 'calendars_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'entities_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'is_recursive', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'last_check', "datetime DEFAULT NULL");
    $migration->addField($newTable, 'state', "varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'state_type', "varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'plugin_monitoring_checks_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'calendars_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'is_acknowledged', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'is_acknowledgeconfirmed', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'acknowledge_comment', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'acknowledge_users_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addKey($newTable, "name");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_componentscatalogs
     */
    $newTable = "glpi_plugin_monitoring_componentscatalogs";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'entities_id', 'entities_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'is_recursive', 'is_recursive', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'comment', 'comment', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->changeField($newTable, 'notification_interval', 'notification_interval', "int(4) NOT NULL DEFAULT '30'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'entities_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'is_recursive', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'comment', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'notification_interval', "int(4) NOT NULL DEFAULT '30'");
    $migration->addKey($newTable, "name");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_components
     */
    $newTable = "glpi_plugin_monitoring_components";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'plugin_monitoring_commands_id', 'plugin_monitoring_commands_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'arguments', 'arguments', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->changeField($newTable, 'plugin_monitoring_checks_id', 'plugin_monitoring_checks_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'active_checks_enabled', 'active_checks_enabled', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'passive_checks_enabled', 'passive_checks_enabled', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'calendars_id', 'calendars_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'remotesystem', 'remotesystem', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'is_arguments', 'is_arguments', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'alias_command', 'alias_command', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->changeField($newTable, 'graph_template', 'graph_template', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'link', 'link', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'is_weathermap', 'is_weathermap', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'weathermap_regex', 'weathermap_regex_in', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->changeField($newTable, 'perfname', 'perfname', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->changeField($newTable, 'perfnameinvert', 'perfnameinvert', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->changeField($newTable, 'perfnamecolor', 'perfnamecolor', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, 'name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'plugin_monitoring_commands_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'arguments', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'plugin_monitoring_checks_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'active_checks_enabled', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'passive_checks_enabled', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'calendars_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'remotesystem', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'is_arguments', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'alias_command', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'graph_template', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'link', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'is_weathermap', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'weathermap_regex_in', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'weathermap_regex_out', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'perfname', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'perfnameinvert', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'perfnamecolor', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'plugin_monitoring_eventhandlers_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addKey($newTable, "plugin_monitoring_commands_id");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_componentscatalogs_components
     */
    $newTable = "glpi_plugin_monitoring_componentscatalogs_components";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'plugin_monitoring_componentscalalog_id', 'plugin_monitoring_componentscalalog_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'plugin_monitoring_components_id', 'plugin_monitoring_components_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'plugin_monitoring_componentscalalog_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'plugin_monitoring_components_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addKey($newTable, array('plugin_monitoring_componentscalalog_id', 'plugin_monitoring_components_id'), "unicity", "UNIQUE");
    $migration->addKey($newTable, "plugin_monitoring_componentscalalog_id");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_componentscatalogs_hosts
     */
    $newTable = "glpi_plugin_monitoring_componentscatalogs_hosts";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'plugin_monitoring_componentscalalog_id', 'plugin_monitoring_componentscalalog_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'is_static', 'is_static', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'items_id', 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'itemtype', 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'plugin_monitoring_componentscalalog_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'is_static', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->addKey($newTable, array('itemtype', 'items_id'), 'itemtype');
    $migration->addKey($newTable, 'plugin_monitoring_componentscalalog_id');
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_componentscatalogs_rules
     */
    $newTable = "glpi_plugin_monitoring_componentscatalogs_rules";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'plugin_monitoring_componentscalalog_id', 'plugin_monitoring_componentscalalog_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'itemtype', 'itemtype', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'condition', 'condition', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->dropField($newTable, 'entities_id');
    $migration->dropField($newTable, 'is_recursive');
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'plugin_monitoring_componentscalalog_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'itemtype', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'condition', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addKey($newTable, 'plugin_monitoring_componentscalalog_id');
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_services
     */
    $newTable = "glpi_plugin_monitoring_services";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'entities_id', 'entities_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'plugin_monitoring_components_id', 'plugin_monitoring_components_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'plugin_monitoring_componentscatalogs_hosts_id', 'plugin_monitoring_componentscatalogs_hosts_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'event', 'event', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'state', 'state', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'state_type', 'state_type', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'last_check', 'last_check', "datetime DEFAULT NULL");
    $migration->changeField($newTable, 'arguments', 'arguments', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->changeField($newTable, 'networkports_id', 'networkports_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->dropField($newTable, 'alias_command');
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'entities_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'plugin_monitoring_components_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'plugin_monitoring_componentscatalogs_hosts_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'event', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'state', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'state_type', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'last_check', "datetime DEFAULT NULL");
    $migration->addField($newTable, 'arguments', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'networkports_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'is_acknowledged', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'is_acknowledgeconfirmed', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'acknowledge_comment', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'acknowledge_users_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addKey($newTable, array('state', 'state_type'), 'state');
    $migration->addKey($newTable, 'plugin_monitoring_componentscatalogs_hosts_id');
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_servicegraphs
     */
    $newTable = "glpi_plugin_monitoring_servicegraphs";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` bigint(30) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "bigint(30) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'plugin_monitoring_services_id', 'plugin_monitoring_services_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'date', 'date', "datetime DEFAULT NULL");
    $migration->changeField($newTable, 'data', 'data', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->changeField($newTable, 'type', 'type', "varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'plugin_monitoring_services_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'date', "datetime DEFAULT NULL");
    $migration->addField($newTable, 'data', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'type', "varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addKey($newTable, array('plugin_monitoring_services_id', 'type'), 'plugin_monitoring_services_id');
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_contacttemplates
     */
    $newTable = "glpi_plugin_monitoring_contacttemplates";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'is_default', 'is_default', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'host_notifications_enabled', 'host_notifications_enabled', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'service_notifications_enabled', 'service_notifications_enabled', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'service_notification_period', 'service_notification_period', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'host_notification_period', 'host_notification_period', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'service_notification_options_w', 'service_notification_options_w', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'service_notification_options_u', 'service_notification_options_u', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'service_notification_options_c', 'service_notification_options_c', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'service_notification_options_r', 'service_notification_options_r', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'service_notification_options_f', 'service_notification_options_f', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'service_notification_options_n', 'service_notification_options_n', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'host_notification_options_d', 'host_notification_options_d', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'host_notification_options_u', 'host_notification_options_u', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'host_notification_options_r', 'host_notification_options_r', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'host_notification_options_f', 'host_notification_options_f', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'host_notification_options_s', 'host_notification_options_s', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'host_notification_options_n', 'host_notification_options_n', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'service_notification_commands', 'service_notification_commands', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'host_notification_commands', 'host_notification_commands', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'name', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'is_default', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'host_notifications_enabled', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'service_notifications_enabled', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'service_notification_period', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'host_notification_period', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'service_notification_options_w', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'service_notification_options_u', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'service_notification_options_c', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'service_notification_options_r', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'service_notification_options_f', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'service_notification_options_n', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'host_notification_options_d', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'host_notification_options_u', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'host_notification_options_r', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'host_notification_options_f', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'host_notification_options_s', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'host_notification_options_n', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'service_notification_commands', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'host_notification_commands', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_contacts
     */
    $newTable = "glpi_plugin_monitoring_contacts";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'users_id', 'users_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'plugin_monitoring_contacttemplates_id', 'plugin_monitoring_contacttemplates_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'users_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'plugin_monitoring_contacttemplates_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_contacts_items
     */
    $newTable = "glpi_plugin_monitoring_contacts_items";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'users_id', 'users_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'groups_id', 'groups_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'items_id', 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'itemtype', 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->changeField($newTable, 'entities_id', 'entities_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'users_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'groups_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->addField($newTable, 'entities_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_commandtemplates
     */
    $newTable = "glpi_plugin_monitoring_commandtemplates";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'plugin_monitoring_commands_id', 'plugin_monitoring_commands_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'key', 'key', "varchar(255) DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'plugin_monitoring_commands_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'key', "varchar(255) DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_rrdtooltemplates
     */
    $newTable = "glpi_plugin_monitoring_rrdtooltemplates";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'plugin_monitoring_commands_id', 'plugin_monitoring_commands_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'key', 'key', "varchar(255) DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'plugin_monitoring_commands_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'key', "varchar(255) DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_configs
     */
    $newTable = "glpi_plugin_monitoring_configs";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'timezones', 'timezones', "varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '[\"0\"]'");
    $migration->changeField($newTable, 'version', 'version', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'logretention', 'logretention', "int(5) NOT NULL DEFAULT '30'");
    $migration->dropField($newTable, 'phppath');
    $migration->dropField($newTable, 'rrdtoolpath');
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'timezones', "varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '[\"0\"]'");
    $migration->addField($newTable, 'version', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'logretention', "int(5) NOT NULL DEFAULT '30'");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_displayviews
     */
    $newTable = "glpi_plugin_monitoring_displayviews";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'entities_id', 'entities_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'is_recursive', 'is_recursive', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'is_active', 'is_active', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'users_id', 'users_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'counter', 'counter', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'in_central', 'in_central', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'width', 'width', "int(5) NOT NULL DEFAULT '950'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'entities_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'is_recursive', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'is_active', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'users_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'counter', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'in_central', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'width', "int(5) NOT NULL DEFAULT '950'");
    $migration->addField($newTable, 'is_frontview', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'comment', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_displayviews_groups
     */
    $newTable = "glpi_plugin_monitoring_displayviews_groups";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->addField($newTable, 'pluginmonitoringdisplayviews_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'groups_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'entities_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'is_recursive', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addKey($newTable, "pluginmonitoringdisplayviews_id");
    $migration->addKey($newTable, "groups_id");
    $migration->addKey($newTable, "entities_id");
    $migration->addKey($newTable, "is_recursive");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_displayviews_users
     */
    $newTable = "glpi_plugin_monitoring_displayviews_users";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->addField($newTable, 'pluginmonitoringdisplayviews_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'users_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addKey($newTable, "pluginmonitoringdisplayviews_id");
    $migration->addKey($newTable, "users_id");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_displayviews_items
     */
    $newTable = "glpi_plugin_monitoring_displayviews_items";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'plugin_monitoring_displayviews_id', 'plugin_monitoring_displayviews_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'x', 'x', "int(5) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'y', 'y', "int(5) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'items_id', 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'itemtype', 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->changeField($newTable, 'extra_infos', 'extra_infos', "varchar(255) DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'plugin_monitoring_displayviews_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'x', "int(5) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'y', "int(5) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->addField($newTable, 'extra_infos', "varchar(255) DEFAULT NULL");
    $migration->addKey($newTable, "plugin_monitoring_displayviews_id");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_displayviews_rules
     */
    $newTable = "glpi_plugin_monitoring_displayviews_rules";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'plugin_monitoring_displayviews_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'itemtype', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'type', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'condition', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addKey($newTable, 'plugin_monitoring_displayviews_id');
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_entities
     */
    $newTable = "glpi_plugin_monitoring_entities";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'entities_id', 'entities_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'tag', 'tag', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'entities_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'tag', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addKey($newTable, "entities_id");
    $migration->addKey($newTable, "tag");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_hostaddresses
     */
    $newTable = "glpi_plugin_monitoring_hostaddresses";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'items_id', 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'itemtype', 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->changeField($newTable, 'networkports_id', 'networkports_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'ipaddresses_id', 'ipaddresses_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->addField($newTable, 'networkports_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'ipaddresses_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_hostconfigs
     */
    $newTable = "glpi_plugin_monitoring_hostconfigs";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'items_id', 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'itemtype', 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->changeField($newTable, 'plugin_monitoring_commands_id', 'plugin_monitoring_commands_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'plugin_monitoring_checks_id', 'plugin_monitoring_checks_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'calendars_id', 'calendars_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'plugin_monitoring_realms_id', 'plugin_monitoring_realms_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'computers_id', 'computers_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->addField($newTable, 'plugin_monitoring_commands_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'plugin_monitoring_checks_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'calendars_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'plugin_monitoring_realms_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'computers_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_hosts
     */
    $newTable = "glpi_plugin_monitoring_hosts";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'items_id', 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'itemtype', 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->changeField($newTable, 'event', 'event', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'state', 'state', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'state_type', 'state_type', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'last_check', 'last_check', "datetime DEFAULT NULL");
    $migration->changeField($newTable, 'dependencies', 'dependencies', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->addField($newTable, 'event', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'state', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'state_type', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'last_check', "datetime DEFAULT NULL");
    $migration->addField($newTable, 'dependencies', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_logs
     */
    $newTable = "glpi_plugin_monitoring_logs";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` bigint(30) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "bigint(30) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'date_mod', 'date_mod', "datetime DEFAULT NULL");
    $migration->changeField($newTable, 'user_name', 'user_name', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'itemtype', 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->changeField($newTable, 'items_id', 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'action', 'action', "varchar(100) DEFAULT NULL");
    $migration->changeField($newTable, 'value', 'value', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'date_mod', "datetime DEFAULT NULL");
    $migration->addField($newTable, 'user_name', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->addField($newTable, 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'action', "varchar(100) DEFAULT NULL");
    $migration->addField($newTable, 'value', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_networkports
     */
    $newTable = "glpi_plugin_monitoring_networkports";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'items_id', 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'itemtype', 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->changeField($newTable, 'networkports_id', 'networkports_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->addField($newTable, 'networkports_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_realms
     */
    $newTable = "glpi_plugin_monitoring_realms";
    $insertrealm = 0;
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
        $insertrealm = 1;
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'comment', 'comment', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->changeField($newTable, 'date_mod', 'date_mod', "datetime DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'comment', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'date_mod', "datetime DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    if ($insertrealm == '1') {
        $query = "INSERT INTO `glpi_plugin_monitoring_realms` \n            (`id` ,`name` ,`comment` ,`date_mod`) VALUES (NULL , 'All', NULL , NULL)";
        $DB->query($query);
    }
    /*
     * Table glpi_plugin_monitoring_serviceevents
     */
    $newTable = "glpi_plugin_monitoring_serviceevents";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` bigint(30) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "bigint(30) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'plugin_monitoring_services_id', 'plugin_monitoring_services_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'date', 'date', "datetime DEFAULT NULL");
    $migration->changeField($newTable, 'event', 'event', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'perf_data', 'perf_data', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->changeField($newTable, 'output', 'output', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'state', 'state', "varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'state_type', 'state_type', "varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'latency', 'latency', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'execution_time', 'execution_time', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'unavailability', 'unavailability', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'plugin_monitoring_services_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'date', "datetime DEFAULT NULL");
    $migration->addField($newTable, 'event', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'perf_data', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'output', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'state', "varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'state_type', "varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'latency', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'execution_time', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'unavailability', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addKey($newTable, "plugin_monitoring_services_id");
    $migration->addKey($newTable, array('plugin_monitoring_services_id', 'date'), "plugin_monitoring_services_id_2");
    $migration->addKey($newTable, array('unavailability', 'state_type', 'plugin_monitoring_services_id'), "unavailability");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_commands
     */
    $newTable = "glpi_plugin_monitoring_commands";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'is_active', 'is_active', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'command_name', 'command_name', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'command_line', 'command_line', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->changeField($newTable, 'poller_tag', 'poller_tag', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'module_type', 'module_type', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'arguments', 'arguments', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->dropField($newTable, 'regex');
    $migration->dropField($newTable, 'legend');
    $migration->dropField($newTable, 'unit');
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'is_active', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'command_name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'command_line', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'poller_tag', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'module_type', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'arguments', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addKey($newTable, "name");
    $migration->addKey($newTable, "command_name");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_checks
     */
    $newTable = "glpi_plugin_monitoring_checks";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'max_check_attempts', 'max_check_attempts', "int(2) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'check_interval', 'check_interval', "int(5) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'retry_interval', 'retry_interval', "int(5) NOT NULL DEFAULT '1'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'name', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'max_check_attempts', "int(2) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'check_interval', "int(5) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'retry_interval', "int(5) NOT NULL DEFAULT '1'");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_businessrules
     */
    $newTable = "glpi_plugin_monitoring_businessrules";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'plugin_monitoring_businessrulegroups_id', 'plugin_monitoring_businessrulegroups_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'plugin_monitoring_services_id', 'plugin_monitoring_services_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'plugin_monitoring_businessrulegroups_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'plugin_monitoring_services_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_businessrulegroups
     */
    $newTable = "glpi_plugin_monitoring_businessrulegroups";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'plugin_monitoring_servicescatalogs_id', 'plugin_monitoring_servicescatalogs_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'operator', 'operator', "varchar(255) DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'plugin_monitoring_servicescatalogs_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'operator', "varchar(255) DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_eventhandlers
     */
    $newTable = "glpi_plugin_monitoring_eventhandlers";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'is_active', 'is_active', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'command_name', 'command_name', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'command_line', 'command_line', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'is_active', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'command_name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'command_line', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addKey($newTable, "name");
    $migration->addKey($newTable, "command_name");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_notificationcommands
     */
    $newTable = "glpi_plugin_monitoring_notificationcommands";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'is_active', 'is_active', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'command_name', 'command_name', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'command_line', 'command_line', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'is_active', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'command_name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'command_line', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addKey($newTable, "name");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_contactgroups
     */
    $newTable = "glpi_plugin_monitoring_contactgroups";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'name', "varchar(255) DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_contacts_contactgroups
     */
    $newTable = "glpi_plugin_monitoring_contacts_contactgroups";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'plugin_monitoring_contacts_id', 'plugin_monitoring_contacts_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'plugin_monitoring_contactgroups_id', 'plugin_monitoring_contactgroups_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'plugin_monitoring_contacts_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'plugin_monitoring_contactgroups_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addKey($newTable, array('plugin_monitoring_contacts_id', 'plugin_monitoring_contactgroups_id'), "unicity", "UNIQUE");
    $migration->addKey($newTable, "plugin_monitoring_contactgroups_id");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_contactgroups_contactgroups
     */
    $newTable = "glpi_plugin_monitoring_contactgroups_contactgroups";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'plugin_monitoring_contactgroups_id_1', 'plugin_monitoring_contactgroups_id_1', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'plugin_monitoring_contactgroups_id_2', 'plugin_monitoring_contactgroups_id_2', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'plugin_monitoring_contactgroups_id_1', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'plugin_monitoring_contactgroups_id_2', "int(11) NOT NULL DEFAULT '0'");
    $migration->addKey($newTable, array('plugin_monitoring_contactgroups_id_1', 'plugin_monitoring_contactgroups_id_2'), "unicity", "UNIQUE");
    $migration->addKey($newTable, "plugin_monitoring_contactgroups_id_2");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_profiles
     */
    $newTable = "glpi_plugin_monitoring_profiles";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `profiles_id` int(11) NOT NULL DEFAULT '0'\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'profiles_id', 'profiles_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'dashboard', 'dashboard', "char(1) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'servicescatalog', 'servicescatalog', "char(1) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'view', 'view', "char(1) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'componentscatalog', 'componentscatalog', "char(1) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'viewshomepage', 'viewshomepage', "char(1) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'weathermap', 'weathermap', "char(1) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'component', 'component', "char(1) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'command', 'command', "char(1) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'config', 'config', "char(1) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'check', 'check', "char(1) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'profiles_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'dashboard', "char(1) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'servicescatalog', "char(1) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'view', "char(1) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'componentscatalog', "char(1) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'viewshomepage', "char(1) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'weathermap', "char(1) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'component', "char(1) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'command', "char(1) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'config', "char(1) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'check', "char(1) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'allressources', "char(1) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'restartshinken', "char(1) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_servicedefs
     */
    $newTable = "glpi_plugin_monitoring_servicedefs";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'plugin_monitoring_commands_id', 'plugin_monitoring_commands_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'arguments', 'arguments', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->changeField($newTable, 'plugin_monitoring_checks_id', 'plugin_monitoring_checks_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'active_checks_enabled', 'active_checks_enabled', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'passive_checks_enabled', 'passive_checks_enabled', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'calendars_id', 'calendars_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'remotesystem', 'remotesystem', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'is_arguments', 'is_arguments', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'alias_command', 'alias_command', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->changeField($newTable, 'aliasperfdata_commands_id', 'aliasperfdata_commands_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'link', 'link', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'name', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'plugin_monitoring_commands_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'arguments', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'plugin_monitoring_checks_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'active_checks_enabled', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'passive_checks_enabled', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'calendars_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'remotesystem', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'is_arguments', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'alias_command', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'aliasperfdata_commands_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'link', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_unavaibilities
     */
    $newTable = "glpi_plugin_monitoring_unavaibilities";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    if (!FieldExists($newTable, "plugin_monitoring_services_id")) {
        $migration->changeField($newTable, 'items_id', 'plugin_monitoring_services_id', "int(11) NOT NULL DEFAULT '0'");
    }
    $migration->migrationOneTable($newTable);
    $migration->changeField($newTable, 'plugin_monitoring_services_id', 'plugin_monitoring_services_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'begin_date', 'begin_date', "datetime DEFAULT NULL");
    $migration->changeField($newTable, 'end_date', 'end_date', "datetime DEFAULT NULL");
    $migration->dropField($newTable, 'itemtype');
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'plugin_monitoring_services_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'begin_date', "datetime DEFAULT NULL");
    $migration->addField($newTable, 'end_date', "datetime DEFAULT NULL");
    $migration->addField($newTable, 'duration', "int(15) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_weathermaps
     */
    $newTable = "glpi_plugin_monitoring_weathermaps";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'width', 'width', "smallint(6) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'height', 'height', "smallint(6) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'background', 'background', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'name', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'width', "smallint(6) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'height', "smallint(6) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'background', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_weathermapnodes
     */
    $newTable = "glpi_plugin_monitoring_weathermapnodes";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'plugin_monitoring_weathermaps_id', 'plugin_monitoring_weathermaps_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'items_id', 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'itemtype', 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->changeField($newTable, 'x', 'x', "smallint(6) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'y', 'y', "smallint(6) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'name', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'plugin_monitoring_weathermaps_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->addField($newTable, 'x', "smallint(6) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'y', "smallint(6) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_weathermaplinks
     */
    $newTable = "glpi_plugin_monitoring_weathermaplinks";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'plugin_monitoring_weathermapnodes_id_1', 'plugin_monitoring_weathermapnodes_id_1', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'plugin_monitoring_weathermapnodes_id_2', 'plugin_monitoring_weathermapnodes_id_2', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'plugin_monitoring_services_id', 'plugin_monitoring_services_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'bandwidth_in', 'bandwidth_in', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'bandwidth_out', 'bandwidth_out', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'plugin_monitoring_weathermapnodes_id_1', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'plugin_monitoring_weathermapnodes_id_2', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'plugin_monitoring_services_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'bandwidth_in', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'bandwidth_out', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_shinkenwebservices
     */
    $newTable = "glpi_plugin_monitoring_shinkenwebservices";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->addField($newTable, 'url', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'action', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'cnt', "tinyint(2) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'fields_string', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_tags
     */
    $newTable = "glpi_plugin_monitoring_tags";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->addField($newTable, 'tag', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'ip', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'username', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'password', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    /*
     * Table Delete old table not used
     */
    if (TableExists("glpi_plugin_monitoring_servicesuggests")) {
        $DB->query("DROP TABLE `glpi_plugin_monitoring_servicesuggests`");
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/monitoring')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . "/monitoring");
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/monitoring/templates')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . "/monitoring/templates");
    }
    $query = "SELECT * FROM `glpi_calendars`\n      WHERE `name`='24x7'\n      LIMIT 1";
    $result = $DB->query($query);
    if ($DB->numrows($result) == 0) {
        $calendar = new Calendar();
        $input = array();
        $input['name'] = '24x7';
        $input['is_recursive'] = 1;
        $calendars_id = $calendar->add($input);
        $calendarSegment = new CalendarSegment();
        $input = array();
        $input['calendars_id'] = $calendars_id;
        $input['is_recursive'] = 1;
        $input['begin'] = '00:00:00';
        $input['end'] = '24:00:00';
        $input['day'] = '0';
        $calendarSegment->add($input);
        $input['day'] = '1';
        $calendarSegment->add($input);
        $input['day'] = '2';
        $calendarSegment->add($input);
        $input['day'] = '3';
        $calendarSegment->add($input);
        $input['day'] = '4';
        $calendarSegment->add($input);
        $input['day'] = '5';
        $calendarSegment->add($input);
        $input['day'] = '6';
        $calendarSegment->add($input);
    }
    $crontask = new CronTask();
    if (!$crontask->getFromDBbyName('PluginMonitoringServiceevent', 'updaterrd')) {
        CronTask::Register('PluginMonitoringServiceevent', 'updaterrd', '300', array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30));
    }
    if (!$crontask->getFromDBbyName('PluginMonitoringLog', 'cleanlogs')) {
        CronTask::Register('PluginMonitoringLog', 'cleanlogs', '96400', array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30));
    }
    if (!$crontask->getFromDBbyName('PluginMonitoringUnavaibility', 'unavaibility')) {
        CronTask::Register('PluginMonitoringUnavaibility', 'unavaibility', '300', array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30));
    }
    if (!$crontask->getFromDBbyName('PluginMonitoringDisplayview_rule', 'replayallviewrules')) {
        CronTask::Register('PluginMonitoringDisplayview_rule', 'replayallviewrules', '1200', array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30));
    }
    /*
     * Clean services not have host
     */
    $query = "SELECT `glpi_plugin_monitoring_services`.* FROM `glpi_plugin_monitoring_services`\n      LEFT JOIN `glpi_plugin_monitoring_componentscatalogs_hosts`\n         ON `glpi_plugin_monitoring_componentscatalogs_hosts`.`id` = `plugin_monitoring_componentscatalogs_hosts_id`\n   WHERE `is_static` IS NULL";
    $result = $DB->query($query);
    while ($data = $DB->fetch_array($result)) {
        $queryd = "DELETE FROM `glpi_plugin_monitoring_services`\n         WHERE `id`='" . $data['id'] . "'";
        $DB->query($queryd);
    }
    include GLPI_ROOT . "/plugins/monitoring/inc/hostconfig.class.php";
    $pmHostconfig = new PluginMonitoringHostconfig();
    $pmHostconfig->initConfig();
    include GLPI_ROOT . "/plugins/monitoring/inc/host.class.php";
    $pmHost = new PluginMonitoringHost();
    $pmHost->verifyHosts();
    if ($insertrealm == '1') {
        // Insert into hostconfigs
        $query = "UPDATE `glpi_plugin_monitoring_hostconfigs` \n         SET `plugin_monitoring_realms_id` = '1'\n         WHERE `items_id` = '0'\n            AND `itemtype` = 'Entity'";
        $DB->query($query);
    }
    include GLPI_ROOT . "/plugins/monitoring/inc/config.class.php";
    $pmConfig = new PluginMonitoringConfig();
    $pmConfig->initConfig();
    // * Recalculate unavaibility
    if ($unavaibility_recalculate == 1) {
        $query = "SELECT * FROM `glpi_plugin_monitoring_unavaibilities`\n            WHERE `end_date` IS NOT NULL";
        $result = $DB->query($query);
        while ($data = $DB->fetch_array($result)) {
            $time = strtotime($data['end_date']) - strtotime($data['begin_date']);
            $queryd = "UPDATE `glpi_plugin_monitoring_unavaibilities`\n               SET `duration`='" . $time . "'\n               WHERE `id`='" . $data['id'] . "'";
            $DB->query($queryd);
        }
    }
    $query = "UPDATE `glpi_plugin_monitoring_configs`\n      SET `version`='" . PLUGIN_MONITORING_VERSION . "'\n         WHERE `id`='1'";
    $DB->query($query);
}
Ejemplo n.º 10
0
function plugin_resources_install()
{
    global $DB;
    foreach (glob(GLPI_ROOT . '/plugins/resources/inc/*.php') as $file) {
        if (!preg_match('/resourceinjection/', $file) && !preg_match('/clientinjection/', $file) && !preg_match('/resourcepdf/', $file) && !preg_match('/datecriteria/', $file)) {
            include_once $file;
        }
    }
    $update = false;
    $update78 = false;
    $update80 = false;
    $update804 = false;
    $update83 = false;
    $install = false;
    if (!TableExists("glpi_plugin_resources_resources") && !TableExists("glpi_plugin_resources_employments")) {
        $install = true;
        //      $DB->runFile(GLPI_ROOT ."/plugins/resources/sql/empty-1.9.0.sql");
        //      $DB->runFile(GLPI_ROOT ."/plugins/resources/sql/update-1.9.1.sql");
        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/empty-1.9.1.sql");
        $query = "INSERT INTO `glpi_plugin_resources_contracttypes` ( `id`, `name`,`comment`)\n         VALUES (1, '" . __('Long term contract', 'resources') . "', '')";
        $DB->query($query) or die($DB->error());
        $query = "INSERT INTO `glpi_plugin_resources_contracttypes` ( `id`, `name`,`comment`)\n               VALUES (2, '" . __('Fixed term contract', 'resources') . "', '')";
        $DB->query($query) or die($DB->error());
        $query = "INSERT INTO `glpi_plugin_resources_contracttypes` ( `id`, `name`,`comment`)\n               VALUES (3, '" . __('Trainee', 'resources') . "', '')";
        $DB->query($query) or die($DB->error());
    } else {
        if (TableExists("glpi_plugin_resources") && !TableExists("glpi_plugin_resources_employee")) {
            $update = true;
            $update78 = true;
            $update80 = true;
            $update804 = true;
            $update83 = true;
            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.4.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.5.0.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.5.1.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.0.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.1.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.2.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.0.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.1.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.0.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.1.sql");
        } else {
            if (TableExists("glpi_plugin_resources_profiles") && FieldExists("glpi_plugin_resources_profiles", "interface")) {
                $update = true;
                $update78 = true;
                $update80 = true;
                $update804 = true;
                $update83 = true;
                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.5.0.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.5.1.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.0.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.1.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.2.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.0.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.1.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.0.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.1.sql");
            } else {
                if (TableExists("glpi_plugin_resources") && !FieldExists("glpi_plugin_resources", "helpdesk_visible")) {
                    $update = true;
                    $update78 = true;
                    $update80 = true;
                    $update804 = true;
                    $update83 = true;
                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.5.1.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.0.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.1.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.2.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.0.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.1.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.0.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.1.sql");
                } else {
                    if (!TableExists("glpi_plugin_resources_contracttypes")) {
                        $update = true;
                        $update78 = true;
                        $update80 = true;
                        $update804 = true;
                        $update83 = true;
                        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.0.sql");
                        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.1.sql");
                        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.2.sql");
                        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.0.sql");
                        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.1.sql");
                        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.0.sql");
                        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.1.sql");
                    } else {
                        if (TableExists("glpi_plugin_resources_contracttypes") && !FieldExists("glpi_plugin_resources_resources", "plugin_resources_resourcestates_id")) {
                            $update = true;
                            $update80 = true;
                            $update804 = true;
                            $update83 = true;
                            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.1.sql");
                            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.2.sql");
                            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.0.sql");
                            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.1.sql");
                            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.0.sql");
                            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.1.sql");
                        } else {
                            if (!TableExists("glpi_plugin_resources_reportconfigs")) {
                                $update = true;
                                $update80 = true;
                                $update804 = true;
                                $update83 = true;
                                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.6.2.sql");
                                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.0.sql");
                                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.1.sql");
                                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.0.sql");
                                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.1.sql");
                            } else {
                                if (!TableExists("glpi_plugin_resources_checklistconfigs")) {
                                    $update80 = true;
                                    $update804 = true;
                                    $update83 = true;
                                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.0.sql");
                                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.1.sql");
                                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.0.sql");
                                    $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.1.sql");
                                } else {
                                    if (!TableExists("glpi_plugin_resources_choiceitems")) {
                                        $update804 = true;
                                        $update83 = true;
                                        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.7.1.sql");
                                        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.0.sql");
                                        $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.1.sql");
                                    } else {
                                        if (!TableExists("glpi_plugin_resources_employments")) {
                                            $update83 = true;
                                            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.0.sql");
                                            $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.1.sql");
                                            $query = "SELECT *\n               FROM `glpi_plugin_resources_employers`";
                                            $result = $DB->query($query);
                                            if ($DB->numrows($result) > 0) {
                                                while ($data = $DB->fetch_array($result)) {
                                                    $queryUpdate = "UPDATE `glpi_plugin_resources_employers`\n                            SET `completename`= '" . $data["name"] . "'\n                            WHERE `id`= '" . $data["id"] . "'";
                                                    $DB->query($queryUpdate) or die($DB->error());
                                                }
                                            }
                                        } else {
                                            if (TableExists("glpi_plugin_resources_ranks") && !FieldExists("glpi_plugin_resources_ranks", "begin_date")) {
                                                $DB->runFile(GLPI_ROOT . "/plugins/resources/sql/update-1.9.1.sql");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if ($update78 || $install) {
        //Do One time on 0.78
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginResourcesResource' AND `name` = 'Resources'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##lang.resource.title## -  ##resource.firstname## ##resource.name##',\n                        '##lang.resource.url##  : ##resource.url##\n\n   ##lang.resource.entity## : ##resource.entity##\n   ##IFresource.name####lang.resource.name## : ##resource.name##\n   ##ENDIFresource.name## ##IFresource.firstname####lang.resource.firstname## : ##resource.firstname##\n   ##ENDIFresource.firstname## ##IFresource.type####lang.resource.type## : ##resource.type##\n   ##ENDIFresource.type## ##IFresource.users####lang.resource.users## : ##resource.users##\n   ##ENDIFresource.users## ##IFresource.usersrecipient####lang.resource.usersrecipient## : ##resource.usersrecipient##\n   ##ENDIFresource.usersrecipient## ##IFresource.datedeclaration####lang.resource.datedeclaration## : ##resource.datedeclaration##\n   ##ENDIFresource.datedeclaration## ##IFresource.datebegin####lang.resource.datebegin## : ##resource.datebegin##\n   ##ENDIFresource.datebegin## ##IFresource.dateend####lang.resource.dateend## : ##resource.dateend##\n   ##ENDIFresource.dateend## ##IFresource.department####lang.resource.department## : ##resource.department##\n   ##ENDIFresource.department## ##IFresource.status####lang.resource.status## : ##resource.status##\n   ##ENDIFresource.status## ##IFresource.location####lang.resource.location## : ##resource.location##\n   ##ENDIFresource.location## ##IFresource.comment####lang.resource.comment## : ##resource.comment##\n   ##ENDIFresource.comment## ##IFresource.usersleaving####lang.resource.usersleaving## : ##resource.usersleaving##\n   ##ENDIFresource.usersleaving## ##IFresource.leaving####lang.resource.leaving## : ##resource.leaving##\n   ##ENDIFresource.leaving## ##IFresource.helpdesk####lang.resource.helpdesk## : ##resource.helpdesk##\n   ##ENDIFresource.helpdesk## ##FOREACHupdates##----------\n   ##lang.update.title## :\n   ##IFupdate.name####lang.resource.name## : ##update.name##\n   ##ENDIFupdate.name## ##IFupdate.firstname####lang.resource.firstname## : ##update.firstname##\n   ##ENDIFupdate.firstname## ##IFupdate.type####lang.resource.type## : ##update.type##\n   ##ENDIFupdate.type## ##IFupdate.users####lang.resource.users## : ##update.users##\n   ##ENDIFupdate.users## ##IFupdate.usersrecipient####lang.resource.usersrecipient## : ##update.usersrecipient##\n   ##ENDIFupdate.usersrecipient## ##IFupdate.datedeclaration####lang.resource.datedeclaration## : ##update.datedeclaration##\n   ##ENDIFupdate.datedeclaration## ##IFupdate.datebegin####lang.resource.datebegin## : ##update.datebegin##\n   ##ENDIFupdate.datebegin## ##IFupdate.dateend####lang.resource.dateend## : ##update.dateend##\n   ##ENDIFupdate.dateend## ##IFupdate.department####lang.resource.department## : ##update.department##\n   ##ENDIFupdate.department## ##IFupdate.status####lang.resource.status## : ##update.status##\n   ##ENDIFupdate.status## ##IFupdate.location####lang.resource.location## : ##update.location##\n   ##ENDIFupdate.location## ##IFupdate.comment####lang.resource.comment## : ##update.comment##\n   ##ENDIFupdate.comment## ##IFupdate.usersleaving####lang.resource.usersleaving## : ##update.usersleaving##\n   ##ENDIFupdate.usersleaving## ##IFupdate.leaving####lang.resource.leaving## : ##update.leaving##\n   ##ENDIFupdate.leaving## ##IFupdate.helpdesk####lang.resource.helpdesk## : ##update.helpdesk##\n   ##ENDIFupdate.helpdesk## ----------##ENDFOREACHupdates##\n   ##FOREACHtasks####lang.task.title## :\n   ##IFtask.name####lang.task.name## : ##task.name##\n   ##ENDIFtask.name## ##IFtask.type####lang.task.type## : ##task.type##\n   ##ENDIFtask.type## ##IFtask.users####lang.task.users## : ##task.users##\n   ##ENDIFtask.users## ##IFtask.groups####lang.task.groups## : ##task.groups##\n   ##ENDIFtask.groups## ##IFtask.datebegin####lang.task.datebegin## : ##task.datebegin##\n   ##ENDIFtask.datebegin## ##IFtask.dateend####lang.task.dateend## : ##task.dateend##\n   ##ENDIFtask.dateend## ##IFtask.comment####lang.task.comment## : ##task.comment##\n   ##ENDIFtask.comment## ##IFtask.finished####lang.task.finished## : ##task.finished##\n   ##ENDIFtask.finished## ##IFtask.realtime####lang.task.realtime## : ##task.realtime##\n   ##ENDIFtask.realtime## ----------##ENDFOREACHtasks## ',\n                        '&lt;p&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.url##\n                        &lt;/strong&gt; :\n                        &lt;a href=\"##resource.url##\"&gt;##resource.url##\n                        &lt;/a&gt;&lt;/span&gt; &lt;br /&gt;&lt;br /&gt;\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.entity##&lt;/strong&gt; : ##resource.entity##\n                        &lt;/span&gt; &lt;br /&gt; ##IFresource.name##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.name##&lt;/strong&gt; : ##resource.name##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFresource.name## ##IFresource.firstname##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.firstname##&lt;/strong&gt; : ##resource.firstname##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFresource.firstname## ##IFresource.type##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.type##&lt;/strong&gt; :  ##resource.type##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFresource.type## ##IFresource.status##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.status##&lt;/strong&gt; :  ##resource.status##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFresource.status## ##IFresource.users##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.users##&lt;/strong&gt; :  ##resource.users##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFresource.users## ##IFresource.usersrecipient##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.usersrecipient##\n                        &lt;/strong&gt; :  ##resource.usersrecipient##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFresource.usersrecipient## ##IFresource.datedeclaration##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.datedeclaration##\n                        &lt;/strong&gt; :  ##resource.datedeclaration##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFresource.datedeclaration## ##IFresource.datebegin##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.datebegin##&lt;/strong&gt; :  ##resource.datebegin##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFresource.datebegin## ##IFresource.dateend##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.dateend##&lt;/strong&gt; :  ##resource.dateend##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFresource.dateend## ##IFresource.department##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.department##&lt;/strong&gt; :  ##resource.department##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFresource.department## ##IFresource.location##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.location##&lt;/strong&gt; :  ##resource.location##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFresource.location## ##IFresource.comment##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.comment##&lt;/strong&gt; :  ##resource.comment##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFresource.comment## ##IFresource.usersleaving##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.usersleaving##&lt;/strong&gt; :  ##resource.usersleaving##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFresource.usersleaving## ##IFresource.leaving##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.leaving##&lt;/strong&gt; :  ##resource.leaving##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFresource.leaving## ##IFresource.helpdesk##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.helpdesk##&lt;/strong&gt; :  ##resource.helpdesk##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFresource.helpdesk##   ##FOREACHupdates##----------\n                        &lt;br /&gt;\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.update.title## :&lt;/strong&gt;&lt;/span&gt;\n                        &lt;br /&gt; ##IFupdate.name##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.name##&lt;/strong&gt; : ##update.name##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFupdate.name## ##IFupdate.firstname##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.firstname##&lt;/strong&gt; : ##update.firstname##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFupdate.firstname## ##IFupdate.type##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.type##&lt;/strong&gt; : ##update.type##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFupdate.type## ##IFupdate.status##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.status##&lt;/strong&gt; : ##update.status##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFupdate.status## ##IFupdate.users##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.users##&lt;/strong&gt; : ##update.users##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFupdate.users## ##IFupdate.usersrecipient##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.usersrecipient##&lt;/strong&gt; : ##update.usersrecipient##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFupdate.usersrecipient## ##IFupdate.datedeclaration##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.datedeclaration##\n                        &lt;/strong&gt; : ##update.datedeclaration##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFupdate.datedeclaration## ##IFupdate.datebegin##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.datebegin##&lt;/strong&gt; : ##update.datebegin##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFupdate.datebegin## ##IFupdate.dateend##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.dateend##&lt;/strong&gt; : ##update.dateend##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFupdate.dateend## ##IFupdate.department##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.department##&lt;/strong&gt; : ##update.department##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFupdate.department## ##IFupdate.location##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.location##&lt;/strong&gt; : ##update.location##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFupdate.location## ##IFupdate.comment##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.comment##&lt;/strong&gt; : ##update.comment##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFupdate.comment## ##IFupdate.usersleaving##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.usersleaving##\n                        &lt;/strong&gt; : ##update.usersleaving##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFupdate.usersleaving## ##IFupdate.leaving##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.leaving##&lt;/strong&gt; : ##update.leaving##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFupdate.leaving## ##IFupdate.helpdesk##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.resource.helpdesk##&lt;/strong&gt; : ##update.helpdesk##\n                        &lt;br /&gt;&lt;/span&gt;##ENDIFupdate.helpdesk####ENDFOREACHupdates##   ##FOREACHtasks##----------\n                        &lt;br /&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.task.title## :&lt;/strong&gt;&lt;/span&gt; &lt;br /&gt; ##IFtask.name##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.task.name##&lt;/strong&gt; : ##task.name##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFtask.name## ##IFtask.type##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.task.type##&lt;/strong&gt; : ##task.type##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFtask.type## ##IFtask.users##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.task.users##&lt;/strong&gt; : ##task.users##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFtask.users## ##IFtask.groups##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.task.groups##&lt;/strong&gt; : ##task.groups##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFtask.groups## ##IFtask.datebegin##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.task.datebegin##&lt;/strong&gt; : ##task.datebegin##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFtask.datebegin## ##IFtask.dateend##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.task.dateend##&lt;/strong&gt; : ##task.dateend##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFtask.dateend## ##IFtask.comment##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.task.comment##&lt;/strong&gt; : ##task.comment##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFtask.comment## ##IFtask.finished##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.task.finished##&lt;/strong&gt; : ##task.finished##&lt;br /&gt;\n                        &lt;/span&gt;##ENDIFtask.finished## ##IFtask.realtime##\n                        &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n                        &lt;strong&gt;##lang.task.realtime##&lt;/strong&gt; : ##task.realtime##\n                        &lt;/span&gt;##ENDIFtask.realtime##&lt;br /&gt;----------##ENDFOREACHtasks##&lt;/p&gt;');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'New Resource', 0, 'PluginResourcesResource', 'new',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Update Resource', 0, 'PluginResourcesResource', 'update',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Delete Resource', 0, 'PluginResourcesResource', 'delete',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'New Resource Task', 0, 'PluginResourcesResource', 'newtask',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Update Resource Task', 0, 'PluginResourcesResource', 'updatetask',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Delete Resource Task', 0, 'PluginResourcesResource', 'deletetask',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginResourcesResource' AND `name` = 'Alert Resources Tasks'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##resource.action## : ##resource.entity##',\n                        '##FOREACHtasks##\n   ##lang.task.name## : ##task.name##\n   ##lang.task.type## : ##task.type##\n   ##lang.task.users## : ##task.users##\n   ##lang.task.groups## : ##task.groups##\n   ##lang.task.datebegin## : ##task.datebegin##\n   ##lang.task.dateend## : ##task.dateend##\n   ##lang.task.comment## : ##task.comment##\n   ##lang.task.resource## : ##task.resource##\n   ##ENDFOREACHtasks##',\n                           '&lt;table class=\"tab_cadre\" border=\"1\" cellspacing=\"2\" cellpadding=\"3\"&gt;\n   &lt;tbody&gt;\n   &lt;tr&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.task.name##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.task.type##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.task.users##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.task.groups##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.task.datebegin##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.task.dateend##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.task.comment##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.task.resource##&lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   ##FOREACHtasks##\n   &lt;tr&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##task.name##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##task.type##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##task.users##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##task.groups##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##task.datebegin##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##task.dateend##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##task.comment##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##task.resource##&lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   ##ENDFOREACHtasks##\n   &lt;/tbody&gt;\n   &lt;/table&gt;');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Alert Expired Resources Tasks', 0, 'PluginResourcesResource', 'AlertExpiredTasks',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-02-17 22:36:46');";
        $result = $DB->query($query);
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginResourcesResource' AND `name` = 'Alert Leaving Resources'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##resource.action## : ##resource.entity##',\n                        '##FOREACHresources##\n   ##lang.resource.name## : ##resource.name##\n   ##lang.resource.firstname## : ##resource.firstname##\n   ##lang.resource.type## : ##resource.type##\n   ##lang.resource.location## : ##resource.location##\n   ##lang.resource.users## : ##resource.users##\n   ##lang.resource.dateend## : ##resource.dateend##\n   ##ENDFOREACHresources##',\n                           '&lt;table class=\"tab_cadre\" border=\"1\" cellspacing=\"2\" cellpadding=\"3\"&gt;\n   &lt;tbody&gt;\n   &lt;tr&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.name##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.firstname##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.type##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.location##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.users##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.dateend##&lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   ##FOREACHresources##\n   &lt;tr&gt;\n   &lt;td&gt;&lt;a href=\"##resource.url##\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.name##&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.firstname##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.type##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.location##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.users##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.dateend##&lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   ##ENDFOREACHresources##\n   &lt;/tbody&gt;\n   &lt;/table&gt;');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Alert Leaving Resources', 0, 'PluginResourcesResource', 'AlertLeavingResources',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-02-17 22:36:46');";
        $result = $DB->query($query);
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginResourcesResource' AND `name` = 'Alert Resources Checklists'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##checklist.action## : ##checklist.entity##',\n                        '##lang.checklist.title##\n\n   ##FOREACHchecklists##\n   ##lang.checklist.name## ##lang.checklist.firstname## : ##checklist.name## ##checklist.firstname##\n   ##lang.checklist.datebegin## : ##checklist.datebegin##\n   ##lang.checklist.dateend## : ##checklist.dateend##\n   ##lang.checklist.entity## : ##checklist.entity##\n   ##lang.checklist.location## : ##checklist.location##\n   ##lang.checklist.type## : ##checklist.type##\n\n   ##lang.checklist.title2## :\n   ##tasklist.name##\n   ##ENDFOREACHchecklists##',\n                           '&lt;table class=\"tab_cadre\" border=\"1\" cellspacing=\"2\" cellpadding=\"3\"&gt;\n   &lt;tbody&gt;\n   &lt;tr bgcolor=\"#d9c4b8\"&gt;\n   &lt;th colspan=\"7\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: center;\"&gt;##lang.checklist.title##&lt;/span&gt;&lt;/th&gt;\n   &lt;/tr&gt;\n   &lt;tr&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.checklist.name## ##lang.checklist.firstname##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.checklist.datebegin##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.checklist.dateend##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.checklist.entity##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.checklist.location##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.checklist.type##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.checklist.title2##&lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   ##FOREACHchecklists##\n   &lt;tr&gt;\n   &lt;td&gt;&lt;a href=\"##checklist.url##\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##checklist.name## ##checklist.firstname##&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##checklist.datebegin##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##checklist.dateend##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##checklist.entity##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##checklist.location##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##checklist.type##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n   &lt;table width=\"100%\"&gt;\n   &lt;tbody&gt;\n   &lt;tr&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt; ##tasklist.name## &lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   &lt;/tbody&gt;\n   &lt;/table&gt;\n   &lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   ##ENDFOREACHchecklists##\n   &lt;/tbody&gt;\n   &lt;/table&gt;');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Alert Arrival Checklists', 0, 'PluginResourcesResource', 'AlertArrivalChecklists',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-02-17 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Alert Leaving Checklists', 0, 'PluginResourcesResource', 'AlertLeavingChecklists',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-02-17 22:36:46');";
        $result = $DB->query($query);
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginResourcesResource' AND `name` = 'Leaving Resource'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##lang.resource.title## -  ##resource.firstname## ##resource.name##',\n                        '##lang.resource.title2##\n\n   ##lang.resource.url## : ##resource.url##\n\n   ##lang.resource.entity## : ##resource.entity##\n   ##IFresource.name## ##lang.resource.name## : ##resource.name##\n   ##ENDIFresource.name##\n   ##IFresource.firstname## ##lang.resource.firstname## : ##resource.firstname##\n   ##ENDIFresource.firstname##\n\n   ##lang.resource.badge##',\n                        '&lt;p&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.resource.title2##&lt;/strong&gt;\n   &lt;p&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n   &lt;strong&gt;##lang.resource.url##&lt;/strong&gt; :\n   &lt;a href=\"##resource.url##\"&gt;##resource.url##&lt;/a&gt;\n   &lt;/span&gt; &lt;br /&gt;&lt;br /&gt;\n   &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n   &lt;strong&gt;##lang.resource.entity##&lt;/strong&gt; : ##resource.entity##&lt;/span&gt;\n   &lt;br /&gt; ##IFresource.name##\n   &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n   &lt;strong&gt;##lang.resource.name##&lt;/strong&gt; : ##resource.name##&lt;br /&gt;\n   &lt;/span&gt;##ENDIFresource.name## ##IFresource.firstname##\n   &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n   &lt;strong&gt;##lang.resource.firstname##&lt;/strong&gt; : ##resource.firstname##\n   &lt;br /&gt;&lt;/span&gt;##ENDIFresource.firstname##&lt;/p&gt;\n   &lt;p&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;&lt;strong&gt;##lang.resource.badge##&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;\n   &lt;/span&gt;&lt;/p&gt;');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Leaving Resource', 0, 'PluginResourcesResource', 'LeavingResource',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
    }
    if ($update78) {
        $profiles = getAllDatasFromTable("glpi_plugin_resources_profiles");
        if (!empty($profiles)) {
            foreach ($profiles as $profile) {
                $query = "UPDATE `glpi_plugin_resources_profiles`\n                  SET `profiles_id` = '" . $resource["id"] . "'\n                  WHERE `id` = '" . $resource["id"] . "';";
                $result = $DB->query($query);
            }
        }
        $query = "ALTER TABLE `glpi_plugin_resources_profiles`\n               DROP `name` ;";
        $result = $DB->query($query);
        $tables = array("glpi_displaypreferences", "glpi_documents_items", "glpi_bookmarks", "glpi_logs", "glpi_tickets");
        foreach ($tables as $table) {
            $query = "DELETE FROM `{$table}` WHERE (`itemtype` = '4302' ) ";
            $DB->query($query);
        }
        Plugin::migrateItemType(array(4300 => 'PluginResourcesResource', 4301 => 'PluginResourcesTask', 4303 => 'PluginResourcesDirectory'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_tickets"), array("glpi_plugin_resources_resources_items", "glpi_plugin_resources_choices", "glpi_plugin_resources_tasks_items"));
        Plugin::migrateItemType(array(1600 => "PluginBadgesBadge"), array("glpi_plugin_resources_resources_items", "glpi_plugin_resources_choices", "glpi_plugin_resources_tasks_items"));
    }
    if ($update || $install) {
        //Do One time on 0.78 for 1.6.2
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginResourcesResource' AND `name` = 'Resource Report Creation'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##lang.resource.title## -  ##resource.firstname## ##resource.name##',\n                        '##lang.resource.creationtitle##\n\n##lang.resource.entity## : ##resource.entity##\n\n##lang.resource.name## : ##resource.name##\n##lang.resource.firstname## : ##resource.firstname##\n##lang.resource.department## : ##resource.department##\n##lang.resource.location## : ##resource.location##\n##lang.resource.users## : ##resource.users##\n##lang.resource.usersrecipient## : ##resource.usersrecipient##\n##lang.resource.datedeclaration## : ##resource.datedeclaration##\n##lang.resource.datebegin## : ##resource.datebegin##\n\n##lang.resource.creation##\n\n##lang.resource.datecreation## : ##resource.datecreation##\n##lang.resource.login## : ##resource.login##\n##lang.resource.email## : ##resource.email##\n\n##lang.resource.informationtitle##\n\n##IFresource.commentaires####lang.resource.commentaires## : ##resource.commentaires####ENDIFresource.commentaires##\n\n##IFresource.informations####lang.resource.informations## : ##resource.informations####ENDIFresource.informations##',\n                        '&lt;p style=\"text-align: center;\"&gt;&lt;span style=\"font-size: 11px; font-family: verdana;\"&gt;##lang.resource.creationtitle##&lt;/span&gt;&lt;/p&gt;\n&lt;table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\"&gt;\n&lt;tbody&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"2\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.entity##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" colspan=\"2\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.entity##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.name##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.name##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.firstname##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.firstname##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.department##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.department##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.location##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.location##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.users##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.users##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.usersrecipient##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.usersrecipient##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.datedeclaration##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.datedeclaration##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.datebegin##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.datebegin##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;/tbody&gt;\n&lt;/table&gt;\n&lt;p style=\"text-align: center;\"&gt;&lt;span style=\"font-size: 11px; font-family: verdana;\"&gt;##lang.resource.creation##&lt;/span&gt;&lt;/p&gt;\n&lt;table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\"&gt;\n&lt;tbody&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.datecreation##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.datecreation##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.login##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.login##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.email##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.email##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;/tbody&gt;\n&lt;/table&gt;\n&lt;p style=\"text-align: center;\"&gt;&lt;span style=\"font-size: 11px; font-family: verdana;\"&gt;##lang.resource.informationtitle##&lt;/span&gt;&lt;/p&gt;\n&lt;table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\"&gt;\n&lt;tbody&gt;\n##IFresource.commentaires##\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.commentaires##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.commentaires##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n##ENDIFresource.commentaires## ##IFresource.informations##\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.informations##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.informations##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n##ENDIFresource.informations##\n&lt;/tbody&gt;\n&lt;/table&gt;');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Resource Report Creation', 0, 'PluginResourcesResource', 'report',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-11-16 11:36:46');";
        $result = $DB->query($query);
    }
    if ($update80) {
        $restrict = "`plugin_resources_resources_id` ='-1'";
        $checklists = getAllDatasFromTable("glpi_plugin_resources_checklists", $restrict);
        $PluginResourcesChecklistconfig = new PluginResourcesChecklistconfig();
        if (!empty($checklists)) {
            foreach ($checklists as $checklist) {
                $values["name"] = addslashes($checklist["name"]);
                $values["address"] = addslashes($checklist["address"]);
                $values["comment"] = addslashes($checklist["comment"]);
                $values["tag"] = $checklist["tag"];
                $values["entities_id"] = $checklist["entities_id"];
                $PluginResourcesChecklistconfig->add($values);
            }
        }
        $query = "DELETE FROM `glpi_plugin_resources_checklists`\n               WHERE `plugin_resources_resources_id` ='-1'\n                  OR `plugin_resources_resources_id` ='0';";
        $DB->query($query);
        // Put realtime in seconds
        if (FieldExists('glpi_plugin_resources_tasks', 'realtime')) {
            $query = "ALTER TABLE `glpi_plugin_resources_tasks`\n            ADD `actiontime` INT( 11 ) NOT NULL DEFAULT 0 ;";
            $DB->queryOrDie($query, $this->version . " 0.80 Add actiontime in glpi_plugin_resources_tasks");
            $query = "UPDATE `glpi_plugin_resources_tasks`\n                   SET `actiontime` = ROUND(realtime * 3600)";
            $DB->queryOrDie($query, $this->version . " 0.80 Compute actiontime value in glpi_plugin_resources_tasks");
            $query = "ALTER TABLE `glpi_plugin_resources_tasks`\n            DROP `realtime` ;";
            $DB->queryOrDie($query, $this->version . " 0.80 DROP realtime in glpi_plugin_resources_tasks");
        }
        // ADD plannings for tasks
        $tasks = getAllDatasFromTable("glpi_plugin_resources_tasks");
        if (!empty($tasks)) {
            foreach ($tasks as $task) {
                $query = "INSERT INTO `glpi_plugin_resources_taskplannings`\n               ( `id` , `plugin_resources_tasks_id` , `begin` , `end` )\n               VALUES (NULL , '" . $task["id"] . "', '" . $task["date_begin"] . "', '" . $task["date_end"] . "') ;";
                $DB->query($query);
            }
        }
        unset($input);
        $query = "ALTER TABLE `glpi_plugin_resources_tasks`\n               DROP `date_begin`, DROP `date_end` ;";
        $DB->queryOrDie($query, $this->version . " 0.80 Drop date_begin and date_end in glpi_plugin_resources_tasks");
        // ADD tasks
        $PluginResourcesResource = new PluginResourcesResource();
        $taches = getAllDatasFromTable("glpi_plugin_resources_tasks");
        if (!empty($taches)) {
            foreach ($taches as $tache) {
                $PluginResourcesResource->getFromDB($tache["plugin_resources_resources_id"]);
                $input["entities_id"] = $PluginResourcesResource->fields["entities_id"];
                $query = "UPDATE `glpi_plugin_resources_tasks`\n               SET `entities_id` =  '" . $PluginResourcesResource->fields["entities_id"] . "' WHERE `id` = '" . $tache["id"] . "' ;";
                $DB->query($query);
            }
        }
    }
    if ($install || $update80) {
        $restrict = "`itemtype` = 'PluginResourcesResource'";
        $unicities = getAllDatasFromTable("glpi_fieldunicities", $restrict);
        if (empty($unicities)) {
            $query = "INSERT INTO `glpi_fieldunicities`\n                                      VALUES (NULL, 'Resources creation', 1, 'PluginResourcesResource', '0',\n                                             'name,firstname','1',\n                                             '1', '1', '');";
            $DB->queryOrDie($query, " 0.80 Create fieldunicities check");
        }
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginResourcesResource' AND `name` = 'Resource Resting'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##lang.resource.title## -  ##resource.firstname## ##resource.name##',\n                        '##lang.resource.restingtitle##\n##lang.resource.openby## : ##resource.openby##\n##lang.resource.entity## : ##resource.entity##\n\n##lang.resource.name## : ##resource.name##\n##lang.resource.firstname## : ##resource.firstname##\n\n##lang.resource.department## : ##resource.department##\n##lang.resource.users## : ##resource.users##\n\n##lang.resource.resting##\n\n##lang.resource.location## : ##resource.location##\n##lang.resource.home## : ##resource.home##\n##lang.resource.datebegin## : ##resource.datebegin##\n##lang.resource.dateend## : ##resource.dateend##\n\n##lang.resource.commentaires## : ##resource.commentaires##\n\n##FOREACHupdates##\n##lang.update.title##\n\n##IFupdate.datebegin####lang.resource.datebegin## : ##update.datebegin####ENDIFupdate.datebegin##\n##IFupdate.dateend####lang.resource.dateend## : ##update.dateend####ENDIFupdate.dateend##\n##IFupdate.location####lang.resource.location## : ##update.location###ENDIFupdate.location##\n##IFupdate.home####lang.resource.home## : ##update.home####ENDIFupdate.home##\n##IFupdate.comment####lang.resource.comment## : ##update.comment####ENDIFupdate.comment##\n##ENDFOREACHupdates##',\n                        '&lt;p style=\"text-align: center;\"&gt;&lt;span style=\"font-size: 11px; font-family: verdana;\"&gt;##lang.resource.restingtitle##&lt;/span&gt;&lt;/p&gt;\n&lt;table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\"&gt;\n&lt;tbody&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.entity##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.entity##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.openby##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.openby##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.name##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.name##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.firstname##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.firstname##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.department##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.department##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.users##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.users##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;/tbody&gt;\n&lt;/table&gt;\n&lt;p style=\"text-align: center;\"&gt;&lt;span style=\"font-size: 11px; font-family: verdana;\"&gt;##lang.resource.resting##&lt;/span&gt;&lt;/p&gt;\n&lt;table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\"&gt;\n&lt;tbody&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.location##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.location##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.home##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.home##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.datebegin##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.datebegin##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.dateend##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.dateend##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.commentaires##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.commentaires##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;/tbody&gt;\n&lt;/table&gt;\n&lt;p&gt;##FOREACHupdates##&lt;/p&gt;\n&lt;p style=\"text-align: center;\"&gt;&lt;span style=\"font-size: 11px; font-family: verdana;\"&gt;##lang.update.title##&lt;/span&gt;&lt;/p&gt;\n&lt;table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\"&gt;\n&lt;tbody&gt;\n##IFupdate.datebegin##\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.datebegin## : ##update.datebegin##\n&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n##ENDIFupdate.datebegin## ##IFupdate.dateend##\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.dateend## : ##update.dateend##\n&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n##ENDIFupdate.dateend## ##IFupdate.location##\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.location## : ##update.location##\n&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n##ENDIFupdate.location## ##IFupdate.home##\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.home## : ##update.home##\n&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n##ENDIFupdate.home## ##IFupdate.comment##\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.comment## : ##update.comment##\n&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n##ENDIFupdate.comment##\n&lt;/tbody&gt;\n&lt;/table&gt;\n&lt;p&gt;##ENDFOREACHupdates##&lt;/p&gt;');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'New Resource Resting', 0, 'PluginResourcesResource', 'newresting',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Update Resource Resting', 0, 'PluginResourcesResource', 'updateresting',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Delete Resource Resting', 0, 'PluginResourcesResource', 'deleteresting',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginResourcesResource' AND `name` = 'Resource Holiday'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##lang.resource.title## -  ##resource.firstname## ##resource.name##',\n                        '##lang.resource.holidaytitle##\n##lang.resource.openby## : ##resource.openby##\n##lang.resource.entity## : ##resource.entity##\n\n##lang.resource.name## : ##resource.name##\n##lang.resource.firstname## : ##resource.firstname##\n\n##lang.resource.department## : ##resource.department##\n##lang.resource.users## : ##resource.users##\n\n##lang.resource.holiday##\n\n##lang.resource.datebegin## : ##resource.datebegin##\n##lang.resource.dateend## : ##resource.dateend##\n\n##lang.resource.commentaires## : ##resource.commentaires##\n\n##FOREACHupdates##\n##lang.update.title##\n\n##IFupdate.datebegin####lang.resource.datebegin## : ##update.datebegin####ENDIFupdate.datebegin##\n##IFupdate.dateend####lang.resource.dateend## : ##update.dateend####ENDIFupdate.dateend##\n##IFupdate.comment####lang.resource.comment## : ##update.comment####ENDIFupdate.comment##\n##ENDFOREACHupdates##',\n                        '&lt;p style=\"text-align: center;\"&gt;&lt;span style=\"font-size: 11px; font-family: verdana;\"&gt;##lang.resource.holidaytitle##&lt;/span&gt;&lt;/p&gt;\n&lt;table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\"&gt;\n&lt;tbody&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.entity##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.entity##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.openby##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.openby##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.name##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.name##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.firstname##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.firstname##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.department##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.department##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.users##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.users##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;/tbody&gt;\n&lt;/table&gt;\n&lt;p style=\"text-align: center;\"&gt;&lt;span style=\"font-size: 11px; font-family: verdana;\"&gt;##lang.resource.holiday##&lt;/span&gt;&lt;/p&gt;\n&lt;table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\"&gt;\n&lt;tbody&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.datebegin##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.datebegin##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.dateend##&lt;/span&gt;&lt;/td&gt;\n&lt;td style=\"text-align: left;\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.dateend##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.commentaires##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##resource.commentaires##&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;/tbody&gt;\n&lt;/table&gt;\n&lt;p&gt;##FOREACHupdates##&lt;/p&gt;\n&lt;p style=\"text-align: center;\"&gt;&lt;span style=\"font-size: 11px; font-family: verdana;\"&gt;##lang.update.title##&lt;/span&gt;&lt;/p&gt;\n&lt;table border=\"1\" cellspacing=\"2\" cellpadding=\"3\" width=\"590px\" align=\"center\"&gt;\n&lt;tbody&gt;\n##IFupdate.datebegin##\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.datebegin## : ##update.datebegin##\n&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n##ENDIFupdate.datebegin## ##IFupdate.dateend##\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.dateend## : ##update.dateend##\n&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n##ENDIFupdate.dateend## ##IFupdate.comment##\n&lt;tr&gt;\n&lt;td style=\"text-align: left;\" colspan=\"4\" width=\"auto\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;\n&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.resource.comment## : ##update.comment##\n&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;\n&lt;/tr&gt;\n##ENDIFupdate.comment##\n&lt;/tbody&gt;\n&lt;/table&gt;\n&lt;p&gt;##ENDFOREACHupdates##&lt;/p&gt;');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'New Resource Holiday', 0, 'PluginResourcesResource', 'newholiday',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Update Resource Holiday', 0, 'PluginResourcesResource', 'updateholiday',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Delete Resource Holiday', 0, 'PluginResourcesResource', 'deleteholiday',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-05-16 22:36:46');";
        $result = $DB->query($query);
    }
    if ($update804) {
        $query = "SELECT * FROM `glpi_plugin_resources_choices`\n      WHERE `itemtype`!= ''\n      GROUP BY `comment`,`itemtype`";
        $result = $DB->query($query);
        $number = $DB->numrows($result);
        $affectedchoices = array();
        if (!empty($number)) {
            while ($data = $DB->fetch_assoc($result)) {
                $restrictaffected = "`itemtype` = '" . $data["itemtype"] . "'\n               AND `comment` = '" . addslashes($data["comment"]) . "'";
                $affected = getAllDatasFromTable("glpi_plugin_resources_choices", $restrictaffected);
                if (!empty($affected)) {
                    foreach ($affected as $affect) {
                        if ($affect["itemtype"] == $data["itemtype"] && $affect["comment"] == $data["comment"]) {
                            $affectedchoices[$data["id"]][] = $affect["plugin_resources_resources_id"];
                        }
                    }
                }
            }
        }
        $i = 0;
        if (!empty($affectedchoices)) {
            foreach ($affectedchoices as $key => $ressources) {
                $i++;
                $choice = new PluginResourcesChoice();
                $choice_item = new PluginResourcesChoiceItem();
                $types = array(__('Computer') => 'Computer', __('Monitor') => 'Monitor', __('Software') => 'Software', __('Network device') => 'NetworkEquipment', __('Printer') => 'Printer', __('Peripheral') => 'Peripheral', __('Phone') => 'Phone', __('Consumable model') => 'ConsumableItem', __('Specific network rights', 'resources') => '4303', __('Access to the applications', 'resources') => '4304', __('Specific securities groups', 'resources') => '4305', __('Specific distribution lists', 'resources') => '4306', __('Others needs', 'resources') => '4307', 'PluginBadgesBadge' => 'PluginBadgesBadge');
                if ($choice->getFromDB($key)) {
                    $key = array_search($choice->fields["itemtype"], $types);
                    if ($key) {
                        $name = $key;
                    } else {
                        $name = $choice->fields["itemtype"];
                    }
                    $valuesparent["name"] = $i . "." . $name;
                    $valuesparent["entities_id"] = 0;
                    $valuesparent["is_recursive"] = 1;
                    $newidparent = $choice_item->add($valuesparent);
                    $comment = "N/A";
                    if (!empty($choice->fields["comment"])) {
                        $comment = $choice->fields["comment"];
                    }
                    $valueschild["name"] = addslashes(Html::resume_text($comment, 50));
                    $valueschild["comment"] = addslashes($comment);
                    $valueschild["entities_id"] = 0;
                    $valueschild["is_recursive"] = 1;
                    $valueschild["plugin_resources_choiceitems_id"] = $newidparent;
                    $newidchild = $choice_item->add($valueschild);
                    foreach ($ressources as $id => $val) {
                        $query = "UPDATE `glpi_plugin_resources_choices`\n                           SET `plugin_resources_choiceitems_id` = '" . $newidchild . "'\n                          WHERE `plugin_resources_resources_id` = '" . $val . "'\n                          AND `itemtype` = '" . $choice->fields["itemtype"] . "'\n                           AND `comment` = '" . addslashes($choice->fields["comment"]) . "';";
                        $result = $DB->query($query);
                    }
                }
            }
        }
        $query = "ALTER TABLE `glpi_plugin_resources_choices`\n   DROP `itemtype`,\n   DROP `comment`,\n   ADD UNIQUE KEY `unicity` (`plugin_resources_resources_id`,`plugin_resources_choiceitems_id`);";
        $result = $DB->query($query);
        $query = "ALTER TABLE `glpi_plugin_resources_choices`\n   ADD `comment` text collate utf8_unicode_ci;";
        $result = $DB->query($query);
    }
    //0.83 - Drop Matricule
    if (TableExists("glpi_plugin_resources_employees") && FieldExists("glpi_plugin_resources_employees", "matricule")) {
        $query = "SELECT * FROM `glpi_users`";
        $result = $DB->query($query);
        $number = $DB->numrows($result);
        if (!empty($number)) {
            while ($data = $DB->fetch_assoc($result)) {
                $restrict = "`items_id` = '" . $data["id"] . "'\n               AND `itemtype` = 'User'";
                $links = getAllDatasFromTable("glpi_plugin_resources_resources_items", $restrict);
                if (!empty($links)) {
                    foreach ($links as $link) {
                        $employee = new PluginResourcesEmployee();
                        if ($employee->getFromDBbyResources($link["plugin_resources_resources_id"])) {
                            $matricule = $employee->fields["matricule"];
                            if (isset($matricule) && !empty($matricule)) {
                                $query = "UPDATE `glpi_users`\n                           SET `registration_number` = '" . $matricule . "'\n                           WHERE `id` ='" . $link["items_id"] . "'";
                                $DB->query($query);
                            }
                        }
                    }
                }
            }
        }
        $query = "ALTER TABLE `glpi_plugin_resources_employees`\n               DROP `matricule` ;";
        $result = $DB->query($query);
    }
    $rep_files_resources = GLPI_PLUGIN_DOC_DIR . "/resources";
    if (!is_dir($rep_files_resources)) {
        mkdir($rep_files_resources);
    }
    CronTask::Register('PluginResourcesResource', 'Resources', DAY_TIMESTAMP);
    CronTask::Register('PluginResourcesTask', 'ResourcesTask', DAY_TIMESTAMP);
    CronTask::Register('PluginResourcesChecklist', 'ResourcesChecklist', DAY_TIMESTAMP);
    CronTask::Register('PluginResourcesEmployment', 'ResourcesLeaving', DAY_TIMESTAMP, array('state' => CronTask::STATE_DISABLE));
    PluginResourcesProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
    return true;
}
Ejemplo n.º 11
0
function plugin_certificates_install() {
   global $DB;
   
   include_once (GLPI_ROOT."/plugins/certificates/inc/profile.class.php");
   
   $install=false;
   $update78=false;
   $update80=false;
   
   if (!TableExists("glpi_plugin_certificates") && !TableExists("glpi_plugin_certificates_certificatetypes")) {
      
      $install=true;
      $DB->runFile(GLPI_ROOT ."/plugins/certificates/sql/empty-2.0.0.sql");

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

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

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

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

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

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

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

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

   PluginCertificatesProfile::initProfile();
   PluginCertificatesProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
   $migration = new Migration("2.0.0");
   $migration->dropTable('glpi_plugin_certificates_profiles');
   
   return true;
}
Ejemplo n.º 12
0
function pluginMonitoringUpdate($current_version, $migrationname = 'Migration')
{
    global $DB;
    $migration = new $migrationname($current_version);
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/monitoring')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . "/monitoring");
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/monitoring/templates')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . "/monitoring/templates");
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/monitoring/weathermapbg')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . "/monitoring/weathermapbg");
    }
    $unavailability_recalculate = 0;
    if (!TableExists("glpi_plugin_monitoring_unavailabilities") || !FieldExists("glpi_plugin_monitoring_unavailabilities", "duration")) {
        $unavailability_recalculate = 1;
    }
    $unavailability_reset = 0;
    if (!TableExists("glpi_plugin_monitoring_unavailabilities")) {
        $unavailability_reset = 1;
    }
    /*
     * Table glpi_plugin_monitoring_servicescatalogs
     */
    $newTable = "glpi_plugin_monitoring_servicescatalogs";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'entities_id', 'entities_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'is_recursive', 'is_recursive', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'comment', 'comment', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->changeField($newTable, 'last_check', 'last_check', "datetime DEFAULT NULL");
    $migration->changeField($newTable, 'state', 'state', "varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'state_type', 'state_type', "varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'plugin_monitoring_checks_id', 'plugin_monitoring_checks_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'calendars_id', 'calendars_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'entities_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'is_recursive', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'last_check', "datetime DEFAULT NULL");
    $migration->addField($newTable, 'event', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'state', "varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'state_type', "varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'plugin_monitoring_checks_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'calendars_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'is_acknowledged', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'is_acknowledgeconfirmed', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'acknowledge_comment', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'acknowledge_users_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'notification_interval', "int(4) NOT NULL DEFAULT '30'");
    $migration->addField($newTable, 'business_priority', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'is_generic', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'plugin_monitoring_servicescatalogs_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addKey($newTable, "name");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_componentscatalogs
     */
    $newTable = "glpi_plugin_monitoring_componentscatalogs";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'entities_id', 'entities_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'is_recursive', 'is_recursive', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'comment', 'comment', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->changeField($newTable, 'notification_interval', 'notification_interval', "int(4) NOT NULL DEFAULT '30'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'entities_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'is_recursive', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'comment', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'notification_interval', "int(4) NOT NULL DEFAULT '30'");
    $migration->addKey($newTable, "name");
    $migration->migrationOneTable($newTable);
    /*
     * glpi_plugin_monitoring_perfdatas
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_monitoring_perfdatas';
    $a_table['oldname'] = array();
    $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => ''), 'name' => array('type' => 'string', 'value' => NULL), 'perfdata' => array('type' => 'text', 'value' => NULL));
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesMonitoring($migration, $a_table);
    /*
     * glpi_plugin_monitoring_customitems_counters
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_monitoring_customitems_counters';
    $a_table['oldname'] = array();
    $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => ''), 'name' => array('type' => 'string', 'value' => NULL), 'entities_id' => array('type' => 'integer', 'value' => NULL), 'is_recursive' => array('type' => 'bool', 'value' => NULL), 'type' => array('type' => 'string', 'value' => NULL), 'aggregate_items' => array('type' => 'text', 'value' => NULL), 'time' => array('type' => 'string', 'value' => NULL), 'time_specific' => array('type' => 'string', 'value' => NULL));
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesMonitoring($migration, $a_table);
    /*
     * glpi_plugin_monitoring_customitems_gauges
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_monitoring_customitems_gauges';
    $a_table['oldname'] = array();
    $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => ''), 'name' => array('type' => 'string', 'value' => NULL), 'entities_id' => array('type' => 'integer', 'value' => NULL), 'is_recursive' => array('type' => 'bool', 'value' => NULL), 'type' => array('type' => 'string', 'value' => NULL), 'aggregate_items' => array('type' => 'text', 'value' => NULL), 'aggregate_warn' => array('type' => 'text', 'value' => NULL), 'aggregate_crit' => array('type' => 'text', 'value' => NULL), 'aggregate_limit' => array('type' => 'text', 'value' => NULL), 'time' => array('type' => 'string', 'value' => NULL), 'time_specific' => array('type' => 'string', 'value' => NULL));
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesMonitoring($migration, $a_table);
    /*
     * glpi_plugin_monitoring_perfdatadetails
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_monitoring_perfdatadetails';
    $a_table['oldname'] = array();
    $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => ''), 'name' => array('type' => 'string', 'value' => NULL), 'dynamic_name' => array('type' => 'bool', 'value' => NULL), 'plugin_monitoring_perfdatas_id' => array('type' => 'integer', 'value' => NULL), 'position' => array('type' => "int(2) NOT NULL DEFAULT '0'", 'value' => NULL), 'dsname_num' => array('type' => 'tinyint(1) NOT NULL DEFAULT "1"', 'value' => NULL), 'dsname1' => array('type' => 'string', 'value' => NULL), 'dsname2' => array('type' => 'string', 'value' => NULL), 'dsname3' => array('type' => 'string', 'value' => NULL), 'dsname4' => array('type' => 'string', 'value' => NULL), 'dsname5' => array('type' => 'string', 'value' => NULL), 'dsname6' => array('type' => 'string', 'value' => NULL), 'dsname7' => array('type' => 'string', 'value' => NULL), 'dsname8' => array('type' => 'string', 'value' => NULL), 'dsname9' => array('type' => 'string', 'value' => NULL), 'dsname10' => array('type' => 'string', 'value' => NULL), 'dsname11' => array('type' => 'string', 'value' => NULL), 'dsname12' => array('type' => 'string', 'value' => NULL), 'dsname13' => array('type' => 'string', 'value' => NULL), 'dsname14' => array('type' => 'string', 'value' => NULL), 'dsname15' => array('type' => 'string', 'value' => NULL), 'dsnameincr1' => array('type' => 'bool', 'value' => 0), 'dsnameincr2' => array('type' => 'bool', 'value' => 0), 'dsnameincr3' => array('type' => 'bool', 'value' => 0), 'dsnameincr4' => array('type' => 'bool', 'value' => 0), 'dsnameincr5' => array('type' => 'bool', 'value' => 0), 'dsnameincr6' => array('type' => 'bool', 'value' => 0), 'dsnameincr7' => array('type' => 'bool', 'value' => 0), 'dsnameincr8' => array('type' => 'bool', 'value' => 0), 'dsnameincr9' => array('type' => 'bool', 'value' => 0), 'dsnameincr10' => array('type' => 'bool', 'value' => 0), 'dsnameincr11' => array('type' => 'bool', 'value' => 0), 'dsnameincr12' => array('type' => 'bool', 'value' => 0), 'dsnameincr13' => array('type' => 'bool', 'value' => 0), 'dsnameincr14' => array('type' => 'bool', 'value' => 0), 'dsnameincr15' => array('type' => 'bool', 'value' => 0));
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array(array('field' => 'plugin_monitoring_perfdatas_id', 'name' => '', 'type' => 'INDEX'));
    $a_table['oldkeys'] = array();
    migrateTablesMonitoring($migration, $a_table);
    if (countElementsInTable('glpi_plugin_monitoring_perfdatas') == 0) {
        include GLPI_ROOT . "/plugins/monitoring/inc/perfdata.class.php";
        include GLPI_ROOT . "/plugins/monitoring/inc/perfdatadetail.class.php";
        PluginMonitoringPerfdata::initDB();
    }
    /*
     * Table glpi_plugin_monitoring_components
     */
    if (TableExists('glpi_plugin_monitoring_components')) {
        $a_data = getAllDatasFromTable('glpi_plugin_monitoring_components');
        foreach ($a_data as $data) {
            if (!is_numeric($data['graph_template'])) {
                $a_perfs = getAllDatasFromTable('glpi_plugin_monitoring_perfdatas', '`name`="' . $data['graph_template'] . '"');
                if (count($a_perfs) == 0) {
                    $DB->query("UPDATE `glpi_plugin_monitoring_components`\n                     SET `graph_template`='0'\n                     WHERE `id`='" . $data['id'] . "'");
                } else {
                    $a_perf = current($a_perfs);
                    $DB->query("UPDATE `glpi_plugin_monitoring_components`\n                     SET `graph_template`='" . $a_perf['id'] . "'\n                     WHERE `id`='" . $data['id'] . "'");
                }
            }
        }
    }
    $newTable = "glpi_plugin_monitoring_components";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) DEFAULT NULL");
    // 0.84+1.3
    $migration->changeField($newTable, 'description', 'description', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'plugin_monitoring_commands_id', 'plugin_monitoring_commands_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'arguments', 'arguments', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->changeField($newTable, 'plugin_monitoring_checks_id', 'plugin_monitoring_checks_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'active_checks_enabled', 'active_checks_enabled', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'passive_checks_enabled', 'passive_checks_enabled', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'calendars_id', 'calendars_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'remotesystem', 'remotesystem', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'is_arguments', 'is_arguments', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'alias_command', 'alias_command', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->changeField($newTable, 'graph_template', 'graph_template', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'link', 'link', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'is_weathermap', 'is_weathermap', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'weathermap_regex', 'weathermap_regex_in', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->changeField($newTable, 'perfname', 'perfname', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->changeField($newTable, 'perfnameinvert', 'perfnameinvert', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->changeField($newTable, 'perfnamecolor', 'perfnamecolor', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, 'name', "varchar(255) DEFAULT NULL");
    // 0.84+1.3
    $migration->addField($newTable, 'description', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'plugin_monitoring_commands_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'arguments', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'plugin_monitoring_checks_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'active_checks_enabled', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'passive_checks_enabled', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'calendars_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'remotesystem', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'is_arguments', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'alias_command', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'graph_template', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'link', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'is_weathermap', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'weathermap_regex_in', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'weathermap_regex_out', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'perfname', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'perfnameinvert', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'perfnamecolor', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'plugin_monitoring_eventhandlers_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'freshness_count', "int(6) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'freshness_type', "varchar(255) DEFAULT 'seconds'");
    $migration->addKey($newTable, "plugin_monitoring_commands_id");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_componentscatalogs_components
     */
    $newTable = "glpi_plugin_monitoring_componentscatalogs_components";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'plugin_monitoring_componentscalalog_id', 'plugin_monitoring_componentscalalog_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'plugin_monitoring_components_id', 'plugin_monitoring_components_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'plugin_monitoring_componentscalalog_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'plugin_monitoring_components_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addKey($newTable, array('plugin_monitoring_componentscalalog_id', 'plugin_monitoring_components_id'), "unicity", "UNIQUE");
    $migration->addKey($newTable, "plugin_monitoring_componentscalalog_id");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_componentscatalogs_hosts
     */
    $newTable = "glpi_plugin_monitoring_componentscatalogs_hosts";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'plugin_monitoring_componentscalalog_id', 'plugin_monitoring_componentscalalog_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'is_static', 'is_static', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'items_id', 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'itemtype', 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'plugin_monitoring_componentscalalog_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'is_static', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->addKey($newTable, array('itemtype', 'items_id'), 'itemtype');
    $migration->addKey($newTable, 'plugin_monitoring_componentscalalog_id');
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_componentscatalogs_rules
     */
    $newTable = "glpi_plugin_monitoring_componentscatalogs_rules";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'plugin_monitoring_componentscalalog_id', 'plugin_monitoring_componentscalalog_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'itemtype', 'itemtype', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'condition', 'condition', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->dropField($newTable, 'entities_id');
    $migration->dropField($newTable, 'is_recursive');
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'plugin_monitoring_componentscalalog_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'itemtype', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'condition', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addKey($newTable, 'plugin_monitoring_componentscalalog_id');
    $migration->migrationOneTable($newTable);
    $DB->query("UPDATE `glpi_plugin_monitoring_componentscatalogs_rules`\n              SET `itemtype`='Computer' WHERE `itemtype`='PluginMonitoringComputer'");
    /*
     * Table glpi_plugin_monitoring_services
     */
    $newTable = "glpi_plugin_monitoring_services";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'entities_id', 'entities_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'plugin_monitoring_components_id', 'plugin_monitoring_components_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'plugin_monitoring_componentscatalogs_hosts_id', 'plugin_monitoring_componentscatalogs_hosts_id', "int(11) NOT NULL DEFAULT '0'");
    // Event should contain up to 4096 bytes (Nagios plugin specification)
    $migration->changeField($newTable, 'event', 'event', "varchar(4096) COLLATE utf8_unicode_ci DEFAULT NULL");
    // $migration->changeField($newTable,
    // 'event',
    // 'event',
    // "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'state', 'state', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'state_type', 'state_type', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'last_check', 'last_check', "datetime DEFAULT NULL");
    $migration->changeField($newTable, 'arguments', 'arguments', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->changeField($newTable, 'networkports_id', 'networkports_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->dropField($newTable, 'alias_command');
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'entities_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'plugin_monitoring_components_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'plugin_monitoring_componentscatalogs_hosts_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'event', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'state', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'state_type', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'last_check', "datetime DEFAULT NULL");
    $migration->addField($newTable, 'arguments', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'networkports_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'is_acknowledged', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'is_acknowledgeconfirmed', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'acknowledge_comment', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'acknowledge_users_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addKey($newTable, array('state', 'state_type'), 'state');
    $migration->addKey($newTable, 'plugin_monitoring_componentscatalogs_hosts_id');
    $migration->addKey($newTable, 'last_check');
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_contacttemplates
     */
    $newTable = "glpi_plugin_monitoring_contacttemplates";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'is_default', 'is_default', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'shinken_administrator', 'shinken_administrator', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'shinken_can_submit_commands', 'shinken_can_submit_commands', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'host_notifications_enabled', 'host_notifications_enabled', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'service_notifications_enabled', 'service_notifications_enabled', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'service_notification_period', 'service_notification_period', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'host_notification_period', 'host_notification_period', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'service_notification_options_w', 'service_notification_options_w', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'service_notification_options_u', 'service_notification_options_u', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'service_notification_options_c', 'service_notification_options_c', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'service_notification_options_r', 'service_notification_options_r', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'service_notification_options_f', 'service_notification_options_f', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'service_notification_options_n', 'service_notification_options_n', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'host_notification_options_d', 'host_notification_options_d', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'host_notification_options_u', 'host_notification_options_u', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'host_notification_options_r', 'host_notification_options_r', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'host_notification_options_f', 'host_notification_options_f', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'host_notification_options_s', 'host_notification_options_s', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'host_notification_options_n', 'host_notification_options_n', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'service_notification_commands', 'service_notification_commands', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'host_notification_commands', 'host_notification_commands', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'name', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'is_default', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'shinken_administrator', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'shinken_can_submit_commands', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'host_notifications_enabled', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'service_notifications_enabled', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'service_notification_period', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'host_notification_period', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'service_notification_options_w', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'service_notification_options_u', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'service_notification_options_c', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'service_notification_options_r', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'service_notification_options_f', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'service_notification_options_n', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'host_notification_options_d', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'host_notification_options_u', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'host_notification_options_r', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'host_notification_options_f', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'host_notification_options_s', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'host_notification_options_n', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'service_notification_commands', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'host_notification_commands', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_contacts
     */
    $newTable = "glpi_plugin_monitoring_contacts";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'users_id', 'users_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'plugin_monitoring_contacttemplates_id', 'plugin_monitoring_contacttemplates_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'users_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'plugin_monitoring_contacttemplates_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_contacts_items
     */
    $newTable = "glpi_plugin_monitoring_contacts_items";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'users_id', 'users_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'groups_id', 'groups_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'items_id', 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'itemtype', 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->changeField($newTable, 'entities_id', 'entities_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'users_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'groups_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->addField($newTable, 'entities_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_commandtemplates
     */
    $newTable = "glpi_plugin_monitoring_commandtemplates";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'plugin_monitoring_commands_id', 'plugin_monitoring_commands_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'key', 'key', "varchar(255) DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'plugin_monitoring_commands_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'key', "varchar(255) DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_rrdtooltemplates
     */
    $newTable = "glpi_plugin_monitoring_rrdtooltemplates";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'plugin_monitoring_commands_id', 'plugin_monitoring_commands_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'key', 'key', "varchar(255) DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'plugin_monitoring_commands_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'key', "varchar(255) DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_configs
     */
    $newTable = "glpi_plugin_monitoring_configs";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'timezones', 'timezones', "varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '[\"0\"]'");
    $migration->changeField($newTable, 'version', 'version', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'logretention', 'logretention', "int(5) NOT NULL DEFAULT '30'");
    $migration->changeField($newTable, 'nrpe_prefix_contener', 'nrpe_prefix_contener', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'append_id_hostname', 'append_id_hostname', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->dropField($newTable, 'phppath');
    $migration->dropField($newTable, 'rrdtoolpath');
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'timezones', "varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '[\"0\"]'");
    $migration->addField($newTable, 'version', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'logretention', "int(5) NOT NULL DEFAULT '30'");
    $migration->addField($newTable, 'extradebug', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'nrpe_prefix_contener', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'append_id_hostname', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_displayviews
     */
    $newTable = "glpi_plugin_monitoring_displayviews";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'entities_id', 'entities_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'is_recursive', 'is_recursive', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'is_active', 'is_active', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'users_id', 'users_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'counter', 'counter', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'in_central', 'in_central', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'width', 'width', "int(5) NOT NULL DEFAULT '950'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'entities_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'is_recursive', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'is_active', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'users_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'counter', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'in_central', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'width', "int(5) NOT NULL DEFAULT '950'");
    $migration->addField($newTable, 'is_frontview', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'comment', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_displayviews_groups
     */
    $newTable = "glpi_plugin_monitoring_displayviews_groups";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->addField($newTable, 'pluginmonitoringdisplayviews_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'groups_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'entities_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'is_recursive', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addKey($newTable, "pluginmonitoringdisplayviews_id");
    $migration->addKey($newTable, "groups_id");
    $migration->addKey($newTable, "entities_id");
    $migration->addKey($newTable, "is_recursive");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_displayviews_users
     */
    $newTable = "glpi_plugin_monitoring_displayviews_users";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->addField($newTable, 'pluginmonitoringdisplayviews_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'users_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addKey($newTable, "pluginmonitoringdisplayviews_id");
    $migration->addKey($newTable, "users_id");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_displayviews_items
     */
    $newTable = "glpi_plugin_monitoring_displayviews_items";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'plugin_monitoring_displayviews_id', 'plugin_monitoring_displayviews_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'x', 'x', "int(5) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'y', 'y', "int(5) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'items_id', 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'itemtype', 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->changeField($newTable, 'extra_infos', 'extra_infos', "varchar(255) DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'plugin_monitoring_displayviews_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'x', "int(5) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'y', "int(5) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->addField($newTable, 'extra_infos', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'is_minemap', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addKey($newTable, "plugin_monitoring_displayviews_id");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_displayviews_rules
     */
    $newTable = "glpi_plugin_monitoring_displayviews_rules";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'plugin_monitoring_displayviews_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'itemtype', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'type', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'condition', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addKey($newTable, 'plugin_monitoring_displayviews_id');
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_entities
     */
    $newTable = "glpi_plugin_monitoring_entities";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'entities_id', 'entities_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'tag', 'tag', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'entities_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'tag', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addKey($newTable, "entities_id");
    $migration->addKey($newTable, "tag");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_hostaddresses
     */
    $newTable = "glpi_plugin_monitoring_hostaddresses";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'items_id', 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'itemtype', 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->changeField($newTable, 'networkports_id', 'networkports_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'ipaddresses_id', 'ipaddresses_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->addField($newTable, 'networkports_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'ipaddresses_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_hostconfigs
     */
    $a_hostsconfig = array();
    if (TableExists('glpi_plugin_monitoring_hostconfigs') && FieldExists('glpi_plugin_monitoring_hostconfigs', 'plugin_monitoring_commands_id')) {
        $a_hostsconfig = getAllDatasFromTable('glpi_plugin_monitoring_hostconfigs');
    }
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_monitoring_hostconfigs';
    $a_table['oldname'] = array();
    $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => ''), 'items_id' => array('type' => 'integer', 'value' => NULL), 'itemtype' => array('type' => 'varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL', 'value' => NULL), 'plugin_monitoring_components_id' => array('type' => 'integer', 'value' => NULL), 'plugin_monitoring_realms_id' => array('type' => 'integer', 'value' => NULL), 'computers_id' => array('type' => 'integer', 'value' => NULL), 'jetlag' => array('type' => 'varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL', 'value' => '0'));
    $a_table['oldfields'] = array('plugin_monitoring_commands_id', 'plugin_monitoring_checks_id', 'calendars_id');
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesMonitoring($migration, $a_table);
    if (count($a_hostsconfig) > 0) {
        // Convert commands by components
        foreach ($a_hostsconfig as $data) {
            $a_components = getAllDatasFromTable('glpi_plugin_monitoring_components', "`plugin_monitoring_commands_id`='" . $data['plugin_monitoring_commands_id'] . "'");
            if (count($a_components) > 0) {
                $a_component = current($a_components);
                $DB->query("UPDATE `" . $a_table['name'] . "`\n                  SET `plugin_monitoring_components_id`='" . $a_component['id'] . "'\n                  WHERE `id`='" . $data['id'] . "'");
            }
        }
    }
    /*
     * Table glpi_plugin_monitoring_hosts
     */
    $newTable = "glpi_plugin_monitoring_hosts";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    if (TableExists($newTable)) {
        $a_hosts = getAllDatasFromTable($newTable, "`itemtype`='Computer'");
    }
    // Duplicate field with event
    $migration->dropField($newTable, 'ouput');
    $migration->migrationOneTable($newTable);
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'entities_id', 'entities_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'items_id', 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'itemtype', 'itemtype', "varchar(100) DEFAULT NULL");
    // Event should contain up to 4096 bytes (Nagios plugin specification)
    $migration->changeField($newTable, 'event', 'event', "varchar(4096) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'state', 'state', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'state_type', 'state_type', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'last_check', 'last_check', "datetime DEFAULT NULL");
    $migration->changeField($newTable, 'dependencies', 'dependencies', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'perf_data', 'perf_data', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    // Duplicate field with event
    // $migration->changeField($newTable,
    // 'output',
    // 'output',
    // "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'latency', 'latency', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'execution_time', 'execution_time', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'entities_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'is_acknowledged', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'is_acknowledgeconfirmed', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'acknowledge_comment', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'acknowledge_users_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->addField($newTable, 'event', "varchar(512) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'state', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'state_type', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'last_check', "datetime DEFAULT NULL");
    $migration->addField($newTable, 'dependencies', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'perf_data', "text COLLATE utf8_unicode_ci DEFAULT NULL");
    // Duplicate field with event
    // $migration->addField($newTable,
    // 'output',
    // "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'latency', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'execution_time', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addKey($newTable, array('itemtype', 'items_id'), 'itemtype');
    $migration->migrationOneTable($newTable);
    if (count($a_hosts) > 0) {
        // Convert commands by components
        foreach ($a_hosts as $data) {
            $a_computers = getAllDatasFromTable('glpi_computers', "`id`='" . $data['items_id'] . "'");
            if (count($a_computers) > 0) {
                $a_computer = current($a_computers);
                $DB->query("UPDATE `" . $newTable . "`\n                  SET `entities_id`='" . $a_computer['entities_id'] . "'\n                  WHERE `id`='" . $data['id'] . "'");
            }
        }
    }
    /*
     * Table glpi_plugin_monitoring_logs
     */
    $newTable = "glpi_plugin_monitoring_logs";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` bigint(30) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "bigint(30) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'date_mod', 'date_mod', "datetime DEFAULT NULL");
    $migration->changeField($newTable, 'user_name', 'user_name', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'itemtype', 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->changeField($newTable, 'items_id', 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'action', 'action', "varchar(100) DEFAULT NULL");
    $migration->changeField($newTable, 'value', 'value', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'date_mod', "datetime DEFAULT NULL");
    $migration->addField($newTable, 'user_name', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->addField($newTable, 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'action', "varchar(100) DEFAULT NULL");
    $migration->addField($newTable, 'value', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_networkports
     */
    $newTable = "glpi_plugin_monitoring_networkports";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'items_id', 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'itemtype', 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->changeField($newTable, 'networkports_id', 'networkports_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->addField($newTable, 'networkports_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_realms
     */
    $newTable = "glpi_plugin_monitoring_realms";
    $insertrealm = 0;
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
        $insertrealm = 1;
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'comment', 'comment', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->changeField($newTable, 'date_mod', 'date_mod', "datetime DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'comment', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'date_mod', "datetime DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    if ($insertrealm == '1') {
        $query = "INSERT INTO `glpi_plugin_monitoring_realms`\n            (`id` ,`name` ,`comment` ,`date_mod`) VALUES (NULL , 'All', NULL , NULL)";
        $DB->query($query);
    }
    /*
     * Table glpi_plugin_monitoring_serviceevents
     */
    $newTable = "glpi_plugin_monitoring_serviceevents";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` bigint(30) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    // Duplicate field with event
    $migration->dropField($newTable, 'ouput');
    $migration->migrationOneTable($newTable);
    $migration->changeField($newTable, 'id', 'id', "bigint(30) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'plugin_monitoring_services_id', 'plugin_monitoring_services_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'date', 'date', "datetime DEFAULT NULL");
    // Event should contain up to 4096 bytes (Nagios plugin specification)
    $migration->changeField($newTable, 'event', 'event', "varchar(4096) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'perf_data', 'perf_data', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    // Duplicate field with event
    // $migration->changeField($newTable,
    // 'output',
    // 'output',
    // "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'state', 'state', "varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'state_type', 'state_type', "varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'latency', 'latency', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'execution_time', 'execution_time', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'unavailability', 'unavailability', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'plugin_monitoring_services_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'date', "datetime DEFAULT NULL");
    $migration->addField($newTable, 'event', "varchar(512) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'perf_data', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    // Duplicate field with event
    // $migration->addField($newTable,
    // 'output',
    // "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'state', "varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'state_type', "varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'latency', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'execution_time', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'unavailability', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addKey($newTable, "plugin_monitoring_services_id");
    $migration->addKey($newTable, array('plugin_monitoring_services_id', 'date'), "plugin_monitoring_services_id_2");
    $migration->addKey($newTable, array('unavailability', 'state_type', 'plugin_monitoring_services_id'), "unavailability");
    $migration->addKey($newTable, array('plugin_monitoring_services_id', 'id'), "plugin_monitoring_services_id_3");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_commands
     */
    $newTable = "glpi_plugin_monitoring_commands";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'is_active', 'is_active', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'command_name', 'command_name', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'command_line', 'command_line', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->changeField($newTable, 'poller_tag', 'poller_tag', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'module_type', 'module_type', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'arguments', 'arguments', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->dropField($newTable, 'regex');
    $migration->dropField($newTable, 'legend');
    $migration->dropField($newTable, 'unit');
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'is_active', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'command_name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'command_line', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'poller_tag', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'module_type', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'arguments', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addKey($newTable, "name");
    $migration->addKey($newTable, "command_name");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_checks
     */
    $newTable = "glpi_plugin_monitoring_checks";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'max_check_attempts', 'max_check_attempts', "int(2) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'check_interval', 'check_interval', "int(5) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'retry_interval', 'retry_interval', "int(5) NOT NULL DEFAULT '1'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'name', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'max_check_attempts', "int(2) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'check_interval', "int(5) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'retry_interval', "int(5) NOT NULL DEFAULT '1'");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_businessrules
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_monitoring_businessrules';
    $a_table['oldname'] = array();
    $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => ''), 'plugin_monitoring_businessrulegroups_id' => array('type' => 'integer', 'value' => 0), 'plugin_monitoring_services_id' => array('type' => 'integer', 'value' => 0), 'is_dynamic' => array('type' => 'bool', 'value' => 0), 'is_generic' => array('type' => 'bool', 'value' => 0));
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesMonitoring($migration, $a_table);
    /*
     * glpi_plugin_monitoring_businessrules_components
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_monitoring_businessrules_components';
    $a_table['oldname'] = array();
    $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => ''), 'plugin_monitoring_businessrulegroups_id' => array('type' => 'integer', 'value' => 0), 'plugin_monitoring_componentscatalogs_components_id' => array('type' => 'integer', 'value' => 0));
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesMonitoring($migration, $a_table);
    /*
     * Table glpi_plugin_monitoring_businessrulegroups
     */
    $newTable = "glpi_plugin_monitoring_businessrulegroups";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'plugin_monitoring_servicescatalogs_id', 'plugin_monitoring_servicescatalogs_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'operator', 'operator', "varchar(255) DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'plugin_monitoring_servicescatalogs_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'operator', "varchar(255) DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_eventhandlers
     */
    $newTable = "glpi_plugin_monitoring_eventhandlers";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'is_active', 'is_active', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'command_name', 'command_name', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'command_line', 'command_line', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'is_active', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'command_name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'command_line', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addKey($newTable, "name");
    $migration->addKey($newTable, "command_name");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_notificationcommands
     */
    $newTable = "glpi_plugin_monitoring_notificationcommands";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'is_active', 'is_active', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'command_name', 'command_name', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'command_line', 'command_line', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->changeField($newTable, 'reactionner_tag', 'reactionner_tag', "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, 'module_type', 'module_type', "varchar(255) DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'is_active', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'command_name', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'command_line', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'reactionner_tag', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'module_type', "varchar(255) DEFAULT NULL");
    $migration->addKey($newTable, "name");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_contactgroups
     */
    $newTable = "glpi_plugin_monitoring_contactgroups";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'name', "varchar(255) DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_contacts_contactgroups
     */
    $newTable = "glpi_plugin_monitoring_contacts_contactgroups";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'plugin_monitoring_contacts_id', 'plugin_monitoring_contacts_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'plugin_monitoring_contactgroups_id', 'plugin_monitoring_contactgroups_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'plugin_monitoring_contacts_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'plugin_monitoring_contactgroups_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addKey($newTable, array('plugin_monitoring_contacts_id', 'plugin_monitoring_contactgroups_id'), "unicity", "UNIQUE");
    $migration->addKey($newTable, "plugin_monitoring_contactgroups_id");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_contactgroups_contactgroups
     */
    $newTable = "glpi_plugin_monitoring_contactgroups_contactgroups";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'plugin_monitoring_contactgroups_id_1', 'plugin_monitoring_contactgroups_id_1', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'plugin_monitoring_contactgroups_id_2', 'plugin_monitoring_contactgroups_id_2', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'plugin_monitoring_contactgroups_id_1', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'plugin_monitoring_contactgroups_id_2', "int(11) NOT NULL DEFAULT '0'");
    $migration->addKey($newTable, array('plugin_monitoring_contactgroups_id_1', 'plugin_monitoring_contactgroups_id_2'), "unicity", "UNIQUE");
    $migration->addKey($newTable, "plugin_monitoring_contactgroups_id_2");
    $migration->migrationOneTable($newTable);
    /*
     * glpi_plugin_monitoring_profiles
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_monitoring_profiles';
    $a_table['oldname'] = array();
    $a_table['fields'] = array('profiles_id' => array('type' => 'integer', 'value' => NULL), 'config' => array('type' => 'char', 'value' => NULL), 'config_views' => array('type' => 'char', 'value' => NULL), 'config_sliders' => array('type' => 'char', 'value' => NULL), 'config_services_catalogs' => array('type' => 'char', 'value' => NULL), 'config_components_catalogs' => array('type' => 'char', 'value' => NULL), 'config_weathermap' => array('type' => 'char', 'value' => NULL), 'dashboard' => array('type' => 'char', 'value' => NULL), 'dashboard_system_status' => array('type' => 'char', 'value' => NULL), 'dashboard_hosts_status' => array('type' => 'char', 'value' => NULL), 'dashboard_all_ressources' => array('type' => 'char', 'value' => NULL), 'dashboard_views' => array('type' => 'char', 'value' => NULL), 'dashboard_sliders' => array('type' => 'char', 'value' => NULL), 'dashboard_services_catalogs' => array('type' => 'char', 'value' => NULL), 'dashboard_components_catalogs' => array('type' => 'char', 'value' => NULL), 'dashboard_perfdatas' => array('type' => 'char', 'value' => NULL), 'homepage' => array('type' => 'char', 'value' => NULL), 'homepage_views' => array('type' => 'char', 'value' => NULL), 'homepage_services_catalogs' => array('type' => 'char', 'value' => NULL), 'homepage_components_catalogs' => array('type' => 'char', 'value' => NULL), 'homepage_system_status' => array('type' => 'char', 'value' => NULL), 'homepage_hosts_status' => array('type' => 'char', 'value' => NULL), 'homepage_perfdatas' => array('type' => 'char', 'value' => NULL), 'homepage_all_ressources' => array('type' => 'char', 'value' => NULL), 'acknowledge' => array('type' => 'char', 'value' => NULL), 'downtime' => array('type' => 'char', 'value' => NULL), 'counters' => array('type' => 'char', 'value' => NULL), 'restartshinken' => array('type' => 'char', 'value' => NULL), 'host_command' => array('type' => 'char', 'value' => NULL));
    $a_table['oldfields'] = array('servicescatalog', 'view', 'componentscatalog', 'viewshomepage', 'weathermap', 'component', 'command', 'check', 'allressources');
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesMonitoring($migration, $a_table);
    /*
     * Table glpi_plugin_monitoring_servicedefs
     */
    $newTable = "glpi_plugin_monitoring_servicedefs";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'plugin_monitoring_commands_id', 'plugin_monitoring_commands_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'arguments', 'arguments', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->changeField($newTable, 'plugin_monitoring_checks_id', 'plugin_monitoring_checks_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'active_checks_enabled', 'active_checks_enabled', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'passive_checks_enabled', 'passive_checks_enabled', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, 'calendars_id', 'calendars_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'remotesystem', 'remotesystem', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'is_arguments', 'is_arguments', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'alias_command', 'alias_command', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->changeField($newTable, 'aliasperfdata_commands_id', 'aliasperfdata_commands_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'link', 'link', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'name', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'plugin_monitoring_commands_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'arguments', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'plugin_monitoring_checks_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'active_checks_enabled', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'passive_checks_enabled', "tinyint(1) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, 'calendars_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'remotesystem', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'is_arguments', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'alias_command', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->addField($newTable, 'aliasperfdata_commands_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'link', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_sliders
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_monitoring_sliders';
    $a_table['oldname'] = array();
    $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => ''), 'name' => array('type' => 'string', 'value' => NULL), 'entities_id' => array('type' => 'integer', 'value' => NULL), 'is_recursive' => array('type' => 'bool', 'value' => NULL), 'is_active' => array('type' => 'bool', 'value' => NULL), 'users_id' => array('type' => 'integer', 'value' => NULL), 'in_central' => array('type' => 'bool', 'value' => NULL), 'is_frontview' => array('type' => 'bool', 'value' => NULL), 'comment' => array('type' => 'text', 'value' => NULL), 'duration' => array('type' => 'integer', 'value' => '2'));
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesMonitoring($migration, $a_table);
    /*
     * Table glpi_plugin_monitoring_sliders_groups
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_monitoring_sliders_groups';
    $a_table['oldname'] = array();
    $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => ''), 'pluginmonitoringsliders_id' => array('type' => 'integer', 'value' => NULL), 'groups_id' => array('type' => 'integer', 'value' => NULL), 'entities_id' => array('type' => 'integer', 'value' => '-1'), 'is_recursive' => array('type' => 'bool', 'value' => NULL));
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array(array('field' => 'pluginmonitoringsliders_id', 'name' => '', 'type' => 'INDEX'), array('field' => 'groups_id', 'name' => '', 'type' => 'INDEX'), array('field' => 'entities_id', 'name' => '', 'type' => 'INDEX'), array('field' => 'is_recursive', 'name' => '', 'type' => 'INDEX'));
    $a_table['oldkeys'] = array();
    migrateTablesMonitoring($migration, $a_table);
    /*
     * Table glpi_plugin_monitoring_sliders_users
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_monitoring_sliders_users';
    $a_table['oldname'] = array();
    $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => ''), 'pluginmonitoringsliders_id' => array('type' => 'integer', 'value' => NULL), 'users_id' => array('type' => 'integer', 'value' => NULL));
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array(array('field' => 'pluginmonitoringsliders_id', 'name' => '', 'type' => 'INDEX'), array('field' => 'users_id', 'name' => '', 'type' => 'INDEX'));
    $a_table['oldkeys'] = array();
    migrateTablesMonitoring($migration, $a_table);
    /*
     * Table glpi_plugin_monitoring_sliders_items
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_monitoring_sliders_items';
    $a_table['oldname'] = array();
    $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => ''), 'plugin_monitoring_sliders_id' => array('type' => 'integer', 'value' => NULL), 'items_id' => array('type' => 'integer', 'value' => NULL), 'itemtype' => array('type' => 'varchar(100) DEFAULT NULL', 'value' => NULL), 'extra_infos' => array('type' => 'string', 'value' => NULL), 'is_minemap' => array('type' => 'bool', 'value' => NULL));
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array(array('field' => 'plugin_monitoring_sliders_id', 'name' => '', 'type' => 'INDEX'));
    $a_table['oldkeys'] = array();
    migrateTablesMonitoring($migration, $a_table);
    /*
     * Table glpi_plugin_monitoring_unavaibilities
     */
    $newTable = "glpi_plugin_monitoring_unavailabilities";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
        $migration->addField($newTable, 'plugin_monitoring_services_id', "int(11) NOT NULL DEFAULT '0'");
        $migration->addField($newTable, 'begin_date', "datetime DEFAULT NULL");
        $migration->addField($newTable, 'end_date', "datetime DEFAULT NULL");
        $migration->addField($newTable, 'duration', "int(15) NOT NULL DEFAULT '0'");
        // Scheduled unavailability
        $migration->addField($newTable, 'scheduled', "tinyint(1) NOT NULL DEFAULT '0'");
        // Unavailability details
        $migration->addField($newTable, 'details', "text DEFAULT NULL COLLATE utf8_unicode_ci");
        $migration->addKey($newTable, "plugin_monitoring_services_id");
        $migration->migrationOneTable($newTable);
    }
    /*
             $migration->changeField($newTable,
                                     'id',
                                     'id',
                                     "int(11) NOT NULL AUTO_INCREMENT");
             if (!FieldExists($newTable, "plugin_monitoring_services_id")) {
                $migration->changeField($newTable,
                                        'items_id',
                                        'plugin_monitoring_services_id',
                                        "int(11) NOT NULL DEFAULT '0'");
             }
          $migration->migrationOneTable($newTable);
             $migration->changeField($newTable,
                                     'plugin_monitoring_services_id',
                                     'plugin_monitoring_services_id',
                                     "int(11) NOT NULL DEFAULT '0'");
             $migration->changeField($newTable,
                                     'begin_date',
                                     'begin_date',
                                     "datetime DEFAULT NULL");
             $migration->changeField($newTable,
                                     'end_date',
                                     'end_date',
                                     "datetime DEFAULT NULL");
             $migration->dropField($newTable,
                                     'itemtype');
          $migration->migrationOneTable($newTable);
    */
    /*
     * glpi_plugin_monitoring_unavailabilitystates
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_monitoring_unavailabilitystates';
    $a_table['oldname'] = array();
    $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => ''), 'plugin_monitoring_services_id' => array('type' => 'integer', 'value' => 0), 'plugin_monitoring_serviceevents_id' => array('type' => 'integer', 'value' => 0));
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesMonitoring($migration, $a_table);
    /*
     * Table glpi_plugin_monitoring_weathermaps
     */
    $newTable = "glpi_plugin_monitoring_weathermaps";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'width', 'width', "smallint(6) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'height', 'height', "smallint(6) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'background', 'background', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'name', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'width', "smallint(6) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'height', "smallint(6) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'background', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_weathermapnodes
     */
    $newTable = "glpi_plugin_monitoring_weathermapnodes";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'name', 'name', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'plugin_monitoring_weathermaps_id', 'plugin_monitoring_weathermaps_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'items_id', 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'itemtype', 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->changeField($newTable, 'x', 'x', "smallint(6) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'y', 'y', "smallint(6) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'name', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'plugin_monitoring_weathermaps_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'items_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'itemtype', "varchar(100) DEFAULT NULL");
    $migration->addField($newTable, 'x', "smallint(6) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'y', "smallint(6) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'position', "varchar(255) COLLATE utf8_unicode_ci DEFAULT 'middle'");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_weathermaplinks
     */
    $newTable = "glpi_plugin_monitoring_weathermaplinks";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->changeField($newTable, 'id', 'id', "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, 'plugin_monitoring_weathermapnodes_id_1', 'plugin_monitoring_weathermapnodes_id_1', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'plugin_monitoring_weathermapnodes_id_2', 'plugin_monitoring_weathermapnodes_id_2', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'plugin_monitoring_services_id', 'plugin_monitoring_services_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, 'bandwidth_in', 'bandwidth_in', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, 'bandwidth_out', 'bandwidth_out', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, 'plugin_monitoring_weathermapnodes_id_1', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'plugin_monitoring_weathermapnodes_id_2', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'plugin_monitoring_services_id', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'bandwidth_in', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'bandwidth_out', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_shinkenwebservices
     */
    $newTable = "glpi_plugin_monitoring_shinkenwebservices";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->addField($newTable, 'url', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'action', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'cnt', "tinyint(2) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'fields_string', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_tags
     */
    $newTable = "glpi_plugin_monitoring_tags";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                     ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query);
    }
    $migration->addField($newTable, 'tag', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'ip', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'iplock', "bool");
    $migration->addField($newTable, 'username', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'password', "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, 'port', "varchar(255) COLLATE utf8_unicode_ci DEFAULT '7760'");
    $migration->addField($newTable, 'comment', "text DEFAULT NULL COLLATE utf8_unicode_ci");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_downtimes
     */
    $newTable = "glpi_plugin_monitoring_downtimes";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `{$newTable}` (\n                    `id` int(11) NOT NULL AUTO_INCREMENT,\n                    `plugin_monitoring_hosts_id` int(11) NOT NULL DEFAULT '0',\n                    PRIMARY KEY (`id`),\n                    KEY `plugin_monitoring_hosts_id` (`plugin_monitoring_hosts_id`)\n                  ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
        $DB->query($query);
    }
    $migration->addField($newTable, 'start_time', "datetime NOT NULL DEFAULT '2014-01-01 00:00:00'");
    $migration->addField($newTable, 'end_time', "datetime NOT NULL DEFAULT '2014-01-01 00:00:00'");
    $migration->addField($newTable, 'flexible', "tinyint(1) DEFAULT '1'");
    $migration->addField($newTable, 'duration', "int(1) DEFAULT '24'");
    $migration->addField($newTable, 'duration_type', "varchar(64) DEFAULT 'days'");
    $migration->addField($newTable, 'comment', "varchar(1024) DEFAULT NULL");
    $migration->addField($newTable, 'users_id', "int(11) DEFAULT '-1'");
    $migration->addField($newTable, 'tickets_id', "int(11) DEFAULT '0'");
    $migration->addField($newTable, 'services', "tinyint(1) DEFAULT '0'");
    $migration->addField($newTable, 'notified', "tinyint(1) DEFAULT '0'");
    $migration->addField($newTable, 'expired', "tinyint(1) DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->changeField($newTable, 'flexible', 'flexible', "tinyint(1) DEFAULT '0'");
    $migration->changeField($newTable, 'notified', 'notified', "tinyint(1) DEFAULT '0'");
    $migration->changeField($newTable, 'expired', 'expired', "tinyint(1) DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_acknowledges
     */
    $newTable = "glpi_plugin_monitoring_acknowledges";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `{$newTable}` (\n                    `id` int(11) NOT NULL AUTO_INCREMENT,\n                    `itemtype` varchar(100) DEFAULT 'Host',\n                    `items_id` int(11) NOT NULL DEFAULT '0',\n                    PRIMARY KEY (`id`),\n                    KEY `itemtype` (`itemtype`,`items_id`)\n                  ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
        $DB->query($query);
    }
    $migration->addField($newTable, 'start_time', "datetime NOT NULL DEFAULT '2014-01-01 00:00:00'");
    $migration->addField($newTable, 'end_time', "datetime NOT NULL DEFAULT '2014-01-01 00:00:00'");
    $migration->addField($newTable, 'sticky', "tinyint(1) DEFAULT '1'");
    $migration->addField($newTable, 'persistent', "tinyint(1) DEFAULT '1'");
    $migration->addField($newTable, 'notify', "tinyint(1) DEFAULT '1'");
    $migration->addField($newTable, 'comment', "varchar(1024) DEFAULT NULL");
    $migration->addField($newTable, 'users_id', "int(11) DEFAULT '-1'");
    $migration->addField($newTable, 'notified', "tinyint(1) DEFAULT '0'");
    $migration->addField($newTable, 'expired', "tinyint(1) DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->changeField($newTable, 'expired', 'expired', "tinyint(1) DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_hostcounters
     */
    $newTable = "glpi_plugin_monitoring_hostcounters";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `{$newTable}` (\n                     `id` INT(11) NOT NULL AUTO_INCREMENT,\n                     `hostname` VARCHAR(255) DEFAULT NULL,\n                     PRIMARY KEY (`id`),\n                     KEY `hostname` (`hostname`)\n                  ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
        $DB->query($query);
    }
    $migration->addField($newTable, 'date', "datetime DEFAULT NULL");
    $migration->addField($newTable, 'counter', "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, 'value', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'updated', "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addKey($newTable, array('hostname', 'date', 'updated'), 'updated');
    $migration->migrationOneTable($newTable);
    /*
     * Table glpi_plugin_monitoring_hostdailycounters
     */
    $newTable = "glpi_plugin_monitoring_hostdailycounters";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `{$newTable}` (\n                    `id` INT(11) NOT NULL AUTO_INCREMENT,\n                    `hostname` VARCHAR(255) NOT NULL DEFAULT '',\n                    `day` DATE NOT NULL DEFAULT '2013-01-01',\n                    `dayname` varchar(16) NOT NULL DEFAULT '',\n                     PRIMARY KEY (`id`),\n                     KEY (`hostname`,`day`),\n                     KEY (`hostname`,`dayname`)\n                  ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
        $DB->query($query);
    }
    /*
             $migration->addField($newTable,
                                  'plugin_monitoring_services_id',
                                  "int(11) NOT NULL DEFAULT '0'");
             $migration->addField($newTable,
                                  'plugin_monitoring_services_id2',
                                  "int(11) NOT NULL DEFAULT '0'");
    */
    $migration->addField($newTable, 'counters', "varchar(4096) NOT NULL DEFAULT ''");
    $migration->dropField($newTable, 'plugin_monitoring_services_id');
    $migration->dropField($newTable, 'plugin_monitoring_services_id2');
    $migration->addField($newTable, 'dayname', "varchar(16) NOT NULL DEFAULT ''");
    $migration->addField($newTable, 'cPaperChanged', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'cPrinterChanged', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'cBinEmptied', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'cPagesInitial', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'cPagesTotal', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'cPagesToday', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'cPagesRemaining', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'cRetractedInitial', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'cRetractedTotal', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'cRetractedToday', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'cRetractedRemaining', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'cPaperLoad', "int(11) NOT NULL DEFAULT '0'");
    $migration->dropField($newTable, 'cCardsInsertedOk');
    $migration->dropField($newTable, 'cCardsInsertedKo');
    $migration->dropField($newTable, 'cCardsRemoved');
    $migration->addField($newTable, 'cCardsInsertedOkToday', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'cCardsInsertedOkTotal', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'cCardsInsertedKoToday', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'cCardsInsertedKoTotal', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'cCardsRemovedToday', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, 'cCardsRemovedTotal', "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    /*
     * Table Delete old table not used
     */
    if (TableExists("glpi_plugin_monitoring_servicesuggests")) {
        $DB->query("DROP TABLE `glpi_plugin_monitoring_servicesuggests`");
    }
    if (TableExists("glpi_plugin_monitoring_servicegraphs")) {
        $DB->query("DROP TABLE `glpi_plugin_monitoring_servicegraphs`");
    }
    if (TableExists("glpi_plugin_monitoring_securities")) {
        $DB->query("DROP TABLE `glpi_plugin_monitoring_securities`");
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/monitoring')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . "/monitoring");
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/monitoring/templates')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . "/monitoring/templates");
    }
    // Update calendars
    $query = "SELECT * FROM `glpi_calendars`\n      WHERE `name`='24x7'\n      LIMIT 1";
    $result = $DB->query($query);
    if ($DB->numrows($result) == 0) {
        $calendar = new Calendar();
        $input = array();
        $input['name'] = '24x7';
        $input['is_recursive'] = 1;
        $calendars_id = $calendar->add($input);
        $calendarSegment = new CalendarSegment();
        $input = array();
        $input['calendars_id'] = $calendars_id;
        $input['is_recursive'] = 1;
        $input['begin'] = '00:00:00';
        $input['end'] = '24:00:00';
        $input['day'] = '0';
        $calendarSegment->add($input);
        $input['day'] = '1';
        $calendarSegment->add($input);
        $input['day'] = '2';
        $calendarSegment->add($input);
        $input['day'] = '3';
        $calendarSegment->add($input);
        $input['day'] = '4';
        $calendarSegment->add($input);
        $input['day'] = '5';
        $calendarSegment->add($input);
        $input['day'] = '6';
        $calendarSegment->add($input);
    }
    // Update crontasks
    $crontask = new CronTask();
    if (!$crontask->getFromDBbyName('PluginMonitoringDowntime', 'DowntimesExpired')) {
        CronTask::Register('PluginMonitoringDowntime', 'DowntimesExpired', '3600', array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30));
    }
    if (!$crontask->getFromDBbyName('PluginMonitoringLog', 'cleanlogs')) {
        CronTask::Register('PluginMonitoringLog', 'cleanlogs', '96400', array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30));
    }
    if (!$crontask->getFromDBbyName('PluginMonitoringUnavailability', 'unavailability')) {
        CronTask::Register('PluginMonitoringUnavailability', 'Unavailability', '300', array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30));
    }
    if (!$crontask->getFromDBbyName('PluginMonitoringDisplayview_rule', 'replayallviewrules')) {
        CronTask::Register('PluginMonitoringDisplayview_rule', 'replayallviewrules', '1200', array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30));
    }
    if ($crontask->getFromDBbyName('PluginMonitoringUnavaibility', 'unavaibility')) {
        $crontask->getFromDBbyName('PluginMonitoringUnavaibility', 'unavaibility');
        $crontask->delete($crontask->fields);
    }
    if ($crontask->getFromDBbyName('PluginMonitoringServiceevent', 'updaterrd')) {
        $crontask->getFromDBbyName('PluginMonitoringServiceevent', 'updaterrd');
        $crontask->delete($crontask->fields);
    }
    if ($crontask->getFromDBbyName('PluginMonitoringHostdailycounter', 'DailyCounters')) {
        $crontask->getFromDBbyName('PluginMonitoringHostdailycounter', 'DailyCounters');
        $crontask->delete($crontask->fields);
    }
    include GLPI_ROOT . "/plugins/monitoring/inc/command.class.php";
    $pmCommand = new PluginMonitoringCommand();
    $a_list = $pmCommand->find();
    $check_dummy_found = false;
    $restart_shinken_found = false;
    $host_action_found = false;
    foreach ($a_list as $data) {
        if ($data['command_name'] == "check_dummy") {
            $check_dummy_found = true;
        }
        if ($data['command_name'] == "restart_shinken") {
            $restart_shinken_found = true;
        }
        if ($data['command_name'] == "host_action") {
            $host_action_found = true;
        }
    }
    if (!$host_action_found) {
        // Host action command
        $pmCommand = new PluginMonitoringCommand();
        $input = array();
        $input['name'] = "Host action";
        $input['command_name'] = "host_action";
        $input['command_line'] = $DB->escape("host_action");
        $pmCommand->add($input);
    }
    if (!$restart_shinken_found) {
        // Restart shinken command
        $pmCommand = new PluginMonitoringCommand();
        $input = array();
        $input['name'] = "Restart Shinken";
        $input['command_name'] = "restart_shinken";
        $input['command_line'] = $DB->escape("nohup sh -c '/usr/local/shinken/bin/stop_arbiter.sh && sleep 3 && /usr/local/shinken/bin/launch_arbiter.sh' > /dev/null 2>&1 &");
        $pmCommand->add($input);
    }
    if (!$check_dummy_found) {
        // Check dummy command
        $pmCommand = new PluginMonitoringCommand();
        $input = array();
        $input['name'] = "Dummy check";
        $input['command_name'] = "check_dummy";
        $input['command_line'] = $DB->escape("\$PLUGINSDIR\$/check_dummy \$ARG1\$ \"\$ARG2\$\"");
        $arg = array();
        $arg['ARG1'] = 'INTEGER: dummy status code';
        $arg['ARG2'] = 'TEXT: dummy status output text';
        $input['arguments'] = exportArrayToDB($arg);
        $pmCommand->add($input);
    }
    /*
     * Clean services not having hosts
     */
    $query = "SELECT `glpi_plugin_monitoring_services`.* FROM `glpi_plugin_monitoring_services`\n      LEFT JOIN `glpi_plugin_monitoring_componentscatalogs_hosts`\n         ON `glpi_plugin_monitoring_componentscatalogs_hosts`.`id` = `plugin_monitoring_componentscatalogs_hosts_id`\n   WHERE `is_static` IS NULL";
    $result = $DB->query($query);
    while ($data = $DB->fetch_array($result)) {
        $queryd = "DELETE FROM `glpi_plugin_monitoring_services`\n         WHERE `id`='" . $data['id'] . "'";
        $DB->query($queryd);
    }
    /*
     * Clean components catalog not having hosts
     */
    $query = "SELECT `glpi_plugin_monitoring_componentscatalogs_hosts`.`id`\n      FROM `glpi_plugin_monitoring_componentscatalogs_hosts`\n      LEFT JOIN `glpi_computers`\n         ON (`glpi_plugin_monitoring_componentscatalogs_hosts`.`items_id` = `glpi_computers`.`id`)\n      WHERE (`glpi_computers`.`name` IS NULL);";
    $result = $DB->query($query);
    while ($data = $DB->fetch_array($result)) {
        $queryd = "DELETE FROM `glpi_plugin_monitoring_componentscatalogs_hosts`\n         WHERE `id`='" . $data['id'] . "'";
        $DB->query($queryd);
    }
    /*
     * Clean services not having valide component
     */
    $query = "SELECT `glpi_plugin_monitoring_services`.`id`\n      FROM `glpi_plugin_monitoring_services`\n      LEFT JOIN `glpi_plugin_monitoring_components`\n         ON (`plugin_monitoring_components_id` = `glpi_plugin_monitoring_components`.`id`)\n      WHERE (`glpi_plugin_monitoring_components`.`id` IS NULL);";
    $result = $DB->query($query);
    include GLPI_ROOT . "/plugins/monitoring/inc/service.class.php";
    $pmService = new PluginMonitoringService();
    while ($data = $DB->fetch_array($result)) {
        $pmService->delete($data);
    }
    // Update hosts config
    include GLPI_ROOT . "/plugins/monitoring/inc/hostconfig.class.php";
    $pmHostconfig = new PluginMonitoringHostconfig();
    $pmHostconfig->initConfig();
    // Verify hosts
    include GLPI_ROOT . "/plugins/monitoring/inc/host.class.php";
    $pmHost = new PluginMonitoringHost();
    $pmHost->verifyHosts();
    if ($insertrealm == '1') {
        // Insert into hostconfigs
        $query = "UPDATE `glpi_plugin_monitoring_hostconfigs`\n         SET `plugin_monitoring_realms_id` = '1'\n         WHERE `items_id` = '0'\n            AND `itemtype` = 'Entity'";
        $DB->query($query);
    }
    include GLPI_ROOT . "/plugins/monitoring/inc/config.class.php";
    $pmConfig = new PluginMonitoringConfig();
    $pmConfig->initConfig();
    // Add user monitoring if not defined
    if (!countElementsInTable('glpi_users', "`name`='monitoring'")) {
        // Create
        $input = array('name' => 'monitoring');
        $user = new User();
        $user->add($input);
    }
    // Update items of views to be compatible with step of 10px instead 1 px
    $query = "SELECT *\n      FROM `glpi_plugin_monitoring_displayviews_items`";
    $result = $DB->query($query);
    while ($data = $DB->fetch_array($result)) {
        $x = 10 * round($data['x'] / 10);
        $y = 10 * round($data['y'] / 10);
        $DB->query("UPDATE `glpi_plugin_monitoring_displayviews_items` " . "SET `x`='" . $x . "', `y`='" . $y . "' " . "WHERE `id`='" . $data['id'] . "'");
    }
    // Udpate componentcatalog_rules with new search engine (0.85)
    $query = "SELECT *\n      FROM `glpi_plugin_monitoring_componentscatalogs_rules`";
    $result = $DB->query($query);
    while ($data = $DB->fetch_array($result)) {
        $data_array = importArrayFromDB($data['condition']);
        if (!isset($data_array['searchtype'])) {
            continue;
        }
        $criteria = array();
        foreach ($data_array['field'] as $num => $value) {
            $criteria[$num]['field'] = $value;
        }
        unset($data_array['field']);
        foreach ($data_array['searchtype'] as $num => $value) {
            $criteria[$num]['searchtype'] = $value;
        }
        unset($data_array['searchtype']);
        foreach ($data_array['contains'] as $num => $value) {
            $criteria[$num]['value'] = $value;
        }
        unset($data_array['contains']);
        if (isset($data_array['link'])) {
            foreach ($data_array['link'] as $num => $value) {
                $criteria[$num]['link'] = $value;
            }
            unset($data_array['link']);
        }
        $data_array['criteria'] = $criteria;
        unset($data_array['_glpi_csrf_token']);
        $DB->query("UPDATE `glpi_plugin_monitoring_componentscatalogs_rules` " . "SET `condition`='" . exportArrayToDB($data_array) . "' " . "WHERE `id`='" . $data['id'] . "'");
    }
    // * Update unavailability (with table glpi_plugin_monitoring_unavailabilitystates)
    //      include (GLPI_ROOT . "/plugins/monitoring/inc/unavailabilitystate.class.php");
    //      $pmUnavailabilityState = new PluginMonitoringUnavailabilityState();
    //      $query = "SELECT * FROM `glpi_plugin_monitoring_services`";
    //      $result = $DB->query($query);
    //      while ($data=$DB->fetch_array($result)) {
    //         if ($pmUnavailabilityState->getLastID($data['id']) == 0) {
    //            $query2 = "SELECT id FROM `glpi_plugin_monitoring_serviceevents`
    //               WHERE `plugin_monitoring_services_id`='".$data['id']."'
    //                  AND `unavailability`='1'
    //               ORDER BY id DESC
    //               LIMIT 1";
    //            $result2 = $DB->query($query2);
    //            while ($data2=$DB->fetch_array($result2)) {
    //               $pmUnavailabilityState->setLastID($data['id'], $data2['id']);
    //            }
    //         }
    //      }
    $query = "UPDATE `glpi_plugin_monitoring_configs`\n      SET `version`='" . PLUGIN_MONITORING_VERSION . "'\n         WHERE `id`='1'";
    $DB->query($query);
}
Ejemplo n.º 13
0
function plugin_additionalalerts_install()
{
    global $DB;
    include_once GLPI_ROOT . "/plugins/additionalalerts/inc/profile.class.php";
    $install = false;
    $update78 = false;
    $update80 = false;
    if (!TableExists("glpi_plugin_alerting_config") && !TableExists("glpi_plugin_additionalalerts_notificationstates")) {
        $install = true;
        $DB->runFile(GLPI_ROOT . "/plugins/additionalalerts/sql/empty-1.7.0.sql");
    } else {
        if (TableExists("glpi_plugin_alerting_profiles") && FieldExists("glpi_plugin_alerting_profiles", "interface")) {
            $update78 = true;
            $update80 = true;
            $DB->runFile(GLPI_ROOT . "/plugins/additionalalerts/sql/update-1.2.0.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/additionalalerts/sql/update-1.3.0.sql");
        } else {
            if (!TableExists("glpi_plugin_additionalalerts_notificationstates")) {
                $update78 = true;
                $update80 = true;
                $DB->runFile(GLPI_ROOT . "/plugins/additionalalerts/sql/update-1.3.0.sql");
            } else {
                if (TableExists("glpi_plugin_additionalalerts_reminderalerts")) {
                    $DB->runFile(GLPI_ROOT . "/plugins/additionalalerts/sql/update-1.5.0.sql");
                    $notif = new Notification();
                    $options = array('itemtype' => 'PluginAdditionalalertsReminderAlert', 'event' => 'reminder', 'FIELDS' => 'id');
                    foreach ($DB->request('glpi_notifications', $options) as $data) {
                        $notif->delete($data);
                    }
                    $template = new NotificationTemplate();
                    $translation = new NotificationTemplateTranslation();
                    $options = array('itemtype' => 'PluginAdditionalalertsReminderAlert', 'FIELDS' => 'id');
                    foreach ($DB->request('glpi_notificationtemplates', $options) as $data) {
                        $options_template = array('notificationtemplates_id' => $data['id'], 'FIELDS' => 'id');
                        foreach ($DB->request('glpi_notificationtemplatetranslations', $options_template) as $data_template) {
                            $translation->delete($data_template);
                        }
                        $template->delete($data);
                    }
                    $temp = new CronTask();
                    if ($temp->getFromDBbyName('PluginAdditionalalertsReminderAlert', 'AdditionalalertsReminder')) {
                        $temp->delete(array('id' => $temp->fields["id"]));
                    }
                }
            }
        }
    }
    if ($install || $update78) {
        //Do One time on 0.78
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginAdditionalalertsInfocomAlert' AND `name` = 'Alert infocoms'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##lang.notinfocom.title## : ##notinfocom.entity##',\n                        '##FOREACHnotinfocoms##\n   ##lang.notinfocom.name## : ##notinfocom.name##\n   ##lang.notinfocom.computertype## : ##notinfocom.computertype##\n   ##lang.notinfocom.operatingsystem## : ##notinfocom.operatingsystem##\n   ##lang.notinfocom.state## : ##notinfocom.state##\n   ##lang.notinfocom.location## : ##notinfocom.location##\n   ##lang.notinfocom.user## : ##notinfocom.user## / ##notinfocom.group## / ##notinfocom.contact##\n   ##ENDFOREACHnotinfocoms##',\n                        '&lt;table class=\"tab_cadre\" border=\"1\" cellspacing=\"2\" cellpadding=\"3\"&gt;\n   &lt;tbody&gt;\n   &lt;tr&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.notinfocom.name##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.notinfocom.computertype##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.notinfocom.operatingsystem##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.notinfocom.state##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.notinfocom.location##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.notinfocom.user##&lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   ##FOREACHnotinfocoms##            \n   &lt;tr&gt;\n   &lt;td&gt;&lt;a href=\"##notinfocom.urlname##\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##notinfocom.name##&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##notinfocom.computertype##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##notinfocom.operatingsystem##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##notinfocom.state##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##notinfocom.location##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;a href=\"##notinfocom.urluser##\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##notinfocom.user##&lt;/span&gt;&lt;/a&gt; / &lt;a href=\"##notinfocom.urlgroup##\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##notinfocom.group##&lt;/span&gt;&lt;/a&gt; / &lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##notinfocom.contact##&lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   ##ENDFOREACHnotinfocoms##\n   &lt;/tbody&gt;\n   &lt;/table&gt;');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Alert infocoms', 0, 'PluginAdditionalalertsInfocomAlert', 'notinfocom',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-03-13 10:36:46');";
        $result = $DB->query($query);
        ////////////////////
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginAdditionalalertsOcsAlert' AND `name` = 'Alert machines ocs'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##lang.ocsmachine.title## : ##ocsmachine.entity##',\n                        '##FOREACHocsmachines##\n   ##lang.ocsmachine.name## : ##ocsmachine.name##\n   ##lang.ocsmachine.operatingsystem## : ##ocsmachine.operatingsystem##\n   ##lang.ocsmachine.state## : ##ocsmachine.state##\n   ##lang.ocsmachine.location## : ##ocsmachine.location##\n   ##lang.ocsmachine.user## : ##ocsmachine.user## / ##lang.ocsmachine.group## : ##ocsmachine.group## / ##lang.ocsmachine.contact## : ##ocsmachine.contact##\n   ##lang.ocsmachine.lastocsupdate## : ##ocsmachine.lastocsupdate##\n   ##lang.ocsmachine.lastupdate## : ##ocsmachine.lastupdate##\n   ##lang.ocsmachine.ocsserver## : ##ocsmachine.ocsserver##\n   ##ENDFOREACHocsmachines##',\n                        '&lt;table class=\"tab_cadre\" border=\"1\" cellspacing=\"2\" cellpadding=\"3\"&gt;\n   &lt;tbody&gt;\n   &lt;tr&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.ocsmachine.name##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.ocsmachine.operatingsystem##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.ocsmachine.state##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.ocsmachine.location##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.ocsmachine.user##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.ocsmachine.lastocsupdate##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.ocsmachine.lastupdate##&lt;/span&gt;&lt;/td&gt;\n   &lt;td style=\"text-align: left;\" bgcolor=\"#cccccc\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##lang.ocsmachine.ocsserver##&lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   ##FOREACHocsmachines##                 \n   &lt;tr&gt;\n   &lt;td&gt;&lt;a href=\"##ocsmachine.urlname##\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##ocsmachine.name##&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##ocsmachine.operatingsystem##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##ocsmachine.state##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##ocsmachine.location##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;##IFocsmachine.user##&lt;a href=\"##ocsmachine.urluser##\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##ocsmachine.user##&lt;/span&gt;&lt;/a&gt; / ##ENDIFocsmachine.user####IFocsmachine.group##&lt;a href=\"##ocsmachine.urlgroup##\"&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##ocsmachine.group##&lt;/span&gt;&lt;/a&gt; / ##ENDIFocsmachine.group####IFocsmachine.contact##&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##ocsmachine.contact####ENDIFocsmachine.contact##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##ocsmachine.lastocsupdate##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##ocsmachine.lastupdate##&lt;/span&gt;&lt;/td&gt;\n   &lt;td&gt;&lt;span style=\"font-family: Verdana; font-size: 11px; text-align: left;\"&gt;##ocsmachine.ocsserver##&lt;/span&gt;&lt;/td&gt;\n   &lt;/tr&gt;\n   ##ENDFOREACHocsmachines##\n   &lt;/tbody&gt;\n   &lt;/table&gt;');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Alert new machines ocs', 0, 'PluginAdditionalalertsOcsAlert', 'newocs',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-03-20 10:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Alert ocs synchronization', 0, 'PluginAdditionalalertsOcsAlert', 'ocs',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-03-20 10:36:46');";
        $result = $DB->query($query);
    }
    if ($update78) {
        //Do One time on 0.78
        $query_ = "SELECT *\n            FROM `glpi_plugin_additionalalerts_profiles` ";
        $result_ = $DB->query($query_);
        if ($DB->numrows($result_) > 0) {
            while ($data = $DB->fetch_array($result_)) {
                $query = "UPDATE `glpi_plugin_additionalalerts_profiles`\n                  SET `profiles_id` = '" . $data["id"] . "'\n                  WHERE `id` = '" . $data["id"] . "';";
                $result = $DB->query($query);
            }
        }
        $query = "ALTER TABLE `glpi_plugin_additionalalerts_profiles`\n               DROP `name` ;";
        $result = $DB->query($query);
    }
    // To be called for each task the plugin manage
    CronTask::Register('PluginAdditionalalertsOcsAlert', 'AdditionalalertsOcs', DAY_TIMESTAMP);
    CronTask::Register('PluginAdditionalalertsOcsAlert', 'AdditionalalertsNewOcs', HOUR_TIMESTAMP);
    CronTask::Register('PluginAdditionalalertsInfocomAlert', 'AdditionalalertsNotInfocom', HOUR_TIMESTAMP);
    PluginAdditionalalertsProfile::initProfile();
    PluginAdditionalalertsProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
    $migration = new Migration("1.7.0");
    $migration->dropTable('glpi_plugin_accounts_profiles');
    return true;
}
Ejemplo n.º 14
0
function plugin_domains_install()
{
    global $DB;
    include_once GLPI_ROOT . "/plugins/domains/inc/profile.class.php";
    $install = false;
    $update78 = false;
    $update80 = false;
    if (!TableExists("glpi_plugin_domain") && !TableExists("glpi_plugin_domains_domains")) {
        $install = true;
        $DB->runFile(GLPI_ROOT . "/plugins/domains/sql/empty-1.4.0.sql");
    } else {
        if (TableExists("glpi_plugin_domain") && !FieldExists("glpi_plugin_domain", "recursive")) {
            $update78 = true;
            $update80 = true;
            $DB->runFile(GLPI_ROOT . "/plugins/domains/sql/update-1.1.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/domains/sql/update-1.2.0.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/domains/sql/update-1.2.1.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/domains/sql/update-1.3.0.sql");
        } else {
            if (TableExists("glpi_plugin_domain_profiles") && FieldExists("glpi_plugin_domain_profiles", "interface")) {
                $update78 = true;
                $update80 = true;
                $DB->runFile(GLPI_ROOT . "/plugins/domains/sql/update-1.2.0.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/domains/sql/update-1.2.1.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/domains/sql/update-1.3.0.sql");
            } else {
                if (TableExists("glpi_plugin_domain") && !FieldExists("glpi_plugin_domain", "helpdesk_visible")) {
                    $update78 = true;
                    $update80 = true;
                    $DB->runFile(GLPI_ROOT . "/plugins/domains/sql/update-1.2.1.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/domains/sql/update-1.3.0.sql");
                } else {
                    if (!TableExists("glpi_plugin_domains_domains")) {
                        $update78 = true;
                        $update80 = true;
                        $DB->runFile(GLPI_ROOT . "/plugins/domains/sql/update-1.3.0.sql");
                    }
                }
            }
        }
    }
    //from 1.3 version
    if (TableExists("glpi_plugin_domains_domains") && !FieldExists("glpi_plugin_domains_domains", "users_id_tech")) {
        $DB->runFile(GLPI_ROOT . "/plugins/domains/sql/update-1.5.0.sql");
    }
    if ($install || $update78) {
        //Do One time on 0.78
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginDomainsDomain' AND `name` = 'Alert Domains'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##domain.action## : ##domain.entity##',\n                        '##lang.domain.entity## :##domain.entity##\n   ##FOREACHdomains##\n   ##lang.domain.name## : ##domain.name## - ##lang.domain.dateexpiration## : ##domain.dateexpiration##\n   ##ENDFOREACHdomains##',\n                        '&lt;p&gt;##lang.domain.entity## :##domain.entity##&lt;br /&gt; &lt;br /&gt;\n                        ##FOREACHdomains##&lt;br /&gt;\n                        ##lang.domain.name##  : ##domain.name## - ##lang.domain.dateexpiration## :  ##domain.dateexpiration##&lt;br /&gt; \n                        ##ENDFOREACHdomains##&lt;/p&gt;');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Alert Expired Domains', 0, 'PluginDomainsDomain', 'ExpiredDomains',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-02-17 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Alert Domains Which Expire', 0, 'PluginDomainsDomain', 'DomainsWhichExpire',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-02-17 22:36:46');";
        $result = $DB->query($query);
    }
    if ($update78) {
        $query_ = "SELECT *\n            FROM `glpi_plugin_domains_profiles` ";
        $result_ = $DB->query($query_);
        if ($DB->numrows($result_) > 0) {
            while ($data = $DB->fetch_array($result_)) {
                $query = "UPDATE `glpi_plugin_domains_profiles`\n                  SET `profiles_id` = '" . $data["id"] . "'\n                  WHERE `id` = '" . $data["id"] . "';";
                $result = $DB->query($query);
            }
        }
        $query = "ALTER TABLE `glpi_plugin_domains_profiles`\n               DROP `name` ;";
        $result = $DB->query($query);
        Plugin::migrateItemType(array(4400 => 'PluginDomainsDomain'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_tickets"), array("glpi_plugin_domains_domains_items"));
        Plugin::migrateItemType(array(1200 => "PluginAppliancesAppliance", 1300 => "PluginWebapplicationsWebapplication"), array("glpi_plugin_domains_domains_items"));
    }
    CronTask::Register('PluginDomainsDomain', 'DomainsAlert', DAY_TIMESTAMP);
    PluginDomainsProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
    return true;
}
Ejemplo n.º 15
0
function pluginMonitoringInstall($version)
{
    global $DB, $CFG_GLPI;
    // ** Insert in DB
    $DB_file = GLPI_ROOT . "/plugins/monitoring/install/mysql/plugin_monitoring-" . $version . "-empty.sql";
    $DBf_handle = fopen($DB_file, "rt");
    $sql_query = fread($DBf_handle, filesize($DB_file));
    fclose($DBf_handle);
    foreach (explode(";\n", "{$sql_query}") as $sql_line) {
        if (get_magic_quotes_runtime()) {
            $sql_line = Toolbox::stripslashes_deep($sql_line);
        }
        if (!empty($sql_line)) {
            $DB->query($sql_line);
        }
    }
    include GLPI_ROOT . "/plugins/monitoring/inc/profile.class.php";
    $pmProfile = new PluginMonitoringProfile();
    $pmProfile->initProfile();
    include GLPI_ROOT . "/plugins/monitoring/inc/command.class.php";
    $pmCommand = new PluginMonitoringCommand();
    $pmCommand->initCommands();
    include GLPI_ROOT . "/plugins/monitoring/inc/notificationcommand.class.php";
    $pmNotificationcommand = new PluginMonitoringNotificationcommand();
    $pmNotificationcommand->initCommands();
    include GLPI_ROOT . "/plugins/monitoring/inc/check.class.php";
    $pmCheck = new PluginMonitoringCheck();
    $pmCheck->initChecks();
    include GLPI_ROOT . "/plugins/monitoring/inc/hostconfig.class.php";
    $pmHostconfig = new PluginMonitoringHostconfig();
    $pmHostconfig->initConfig();
    include GLPI_ROOT . "/plugins/monitoring/inc/config.class.php";
    $pmConfig = new PluginMonitoringConfig();
    $pmConfig->initConfig();
    $query = "UPDATE `glpi_plugin_monitoring_configs`\n      SET `version`='" . PLUGIN_MONITORING_VERSION . "'\n         WHERE `id`='1'";
    $DB->query($query);
    $query = "SELECT * FROM `glpi_calendars`\n      WHERE `name`='24x7'\n      LIMIT 1";
    $result = $DB->query($query);
    if ($DB->numrows($result) == 0) {
        $calendar = new Calendar();
        $input = array();
        $input['name'] = '24x7';
        $input['is_recursive'] = 1;
        $calendars_id = $calendar->add($input);
        $calendarSegment = new CalendarSegment();
        $input = array();
        $input['calendars_id'] = $calendars_id;
        $input['is_recursive'] = 1;
        $input['begin'] = '00:00:00';
        $input['end'] = '24:00:00';
        $input['day'] = '0';
        $calendarSegment->add($input);
        $input['day'] = '1';
        $calendarSegment->add($input);
        $input['day'] = '2';
        $calendarSegment->add($input);
        $input['day'] = '3';
        $calendarSegment->add($input);
        $input['day'] = '4';
        $calendarSegment->add($input);
        $input['day'] = '5';
        $calendarSegment->add($input);
        $input['day'] = '6';
        $calendarSegment->add($input);
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/monitoring')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . "/monitoring");
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/monitoring/templates')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . "/monitoring/templates");
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/monitoring/weathermapbg')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . "/monitoring/weathermapbg");
    }
    CronTask::Register('PluginMonitoringServiceevent', 'updaterrd', '300', array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30));
    CronTask::Register('PluginMonitoringLog', 'cleanlogs', '96400', array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30));
    CronTask::Register('PluginMonitoringUnavaibility', 'unavaibility', '300', array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30));
    CronTask::Register('PluginMonitoringDisplayview_rule', 'replayallviewrules', '1200', array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30));
}
Ejemplo n.º 16
0
function pluginMonitoringInstall($version)
{
    global $DB, $LANG, $CFG_GLPI;
    // ** Insert in DB
    $DB_file = GLPI_ROOT . "/plugins/monitoring/install/mysql/plugin_monitoring-" . $version . "-empty.sql";
    $DBf_handle = fopen($DB_file, "rt");
    $sql_query = fread($DBf_handle, filesize($DB_file));
    fclose($DBf_handle);
    foreach (explode(";\n", "{$sql_query}") as $sql_line) {
        if (get_magic_quotes_runtime()) {
            $sql_line = stripslashes_deep($sql_line);
        }
        if (!empty($sql_line)) {
            $DB->query($sql_line);
        }
    }
    include GLPI_ROOT . "/plugins/monitoring/inc/profile.class.php";
    $pmProfile = new PluginMonitoringProfile();
    $pmProfile->initProfile();
    include GLPI_ROOT . "/plugins/monitoring/inc/command.class.php";
    $pmCommand = new PluginMonitoringCommand();
    $pmCommand->initCommands();
    include GLPI_ROOT . "/plugins/monitoring/inc/notificationcommand.class.php";
    $pmNotificationcommand = new PluginMonitoringNotificationcommand();
    $pmNotificationcommand->initCommands();
    include GLPI_ROOT . "/plugins/monitoring/inc/check.class.php";
    $pmCheck = new PluginMonitoringCheck();
    $pmCheck->initChecks();
    include GLPI_ROOT . "/plugins/monitoring/inc/hostconfig.class.php";
    $pmHostconfig = new PluginMonitoringHostconfig();
    $pmHostconfig->initConfig();
    include GLPI_ROOT . "/plugins/monitoring/inc/config.class.php";
    $pmConfig = new PluginMonitoringConfig();
    $pmConfig->initConfig();
    $query = "UPDATE `glpi_plugin_monitoring_configs`\n      SET `version`='" . PLUGIN_MONITORING_VERSION . "'\n         WHERE `id`='1'";
    $DB->query($query);
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/monitoring')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . "/monitoring");
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/monitoring/templates')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . "/monitoring/templates");
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/monitoring/weathermapbg')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . "/monitoring/weathermapbg");
    }
    CronTask::Register('PluginMonitoringServiceevent', 'updaterrd', '300', array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30));
    CronTask::Register('PluginMonitoringLog', 'cleanlogs', '96400', array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30));
    CronTask::Register('PluginMonitoringUnavaibility', 'unavaibility', '300', array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30));
}
Ejemplo n.º 17
0
function plugin_accounts_install()
{
    global $DB, $CFG_GLPI;
    include_once GLPI_ROOT . "/plugins/accounts/inc/profile.class.php";
    $install = false;
    $update78 = false;
    $update80 = false;
    $update171 = false;
    if (!TableExists("glpi_plugin_compte") && !TableExists("glpi_plugin_comptes") && !TableExists("glpi_comptes") && !TableExists("glpi_plugin_accounts_accounts")) {
        $install = true;
        $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/empty-1.9.0.sql");
    } else {
        if (TableExists("glpi_comptes") && !FieldExists("glpi_comptes", "notes")) {
            $update78 = true;
            $update80 = true;
            $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.1.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.3.sql");
            plugin_accounts_updatev14();
            $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.0.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.1.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.3.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.6.0.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.0.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.1.sql");
            $_SESSION['plugin_acounts_upgrading'] = 1;
        } else {
            if (TableExists("glpi_plugin_comptes") && !FieldExists("glpi_plugin_comptes", "all_users")) {
                $update78 = true;
                $update80 = true;
                $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.3.sql");
                plugin_accounts_updatev14();
                $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.0.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.1.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.3.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.6.0.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.0.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.1.sql");
                $_SESSION['plugin_acounts_upgrading'] = 1;
            } else {
                if (TableExists("glpi_plugin_compte_profiles") && !FieldExists("glpi_plugin_compte_profiles", "my_groups")) {
                    $update78 = true;
                    $update80 = true;
                    plugin_accounts_updatev14();
                    $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.0.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.1.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.3.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.6.0.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.0.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.1.sql");
                    $_SESSION['plugin_acounts_upgrading'] = 1;
                } else {
                    if (TableExists("glpi_plugin_compte_profiles") && FieldExists("glpi_plugin_compte_profiles", "interface")) {
                        $update78 = true;
                        $update80 = true;
                        $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.0.sql");
                        $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.1.sql");
                        $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.3.sql");
                        $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.6.0.sql");
                        $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.0.sql");
                        $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.1.sql");
                        $_SESSION['plugin_acounts_upgrading'] = 1;
                    } else {
                        if (TableExists("glpi_plugin_compte") && !FieldExists("glpi_plugin_compte", "date_mod")) {
                            $update78 = true;
                            $update80 = true;
                            $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.1.sql");
                            $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.3.sql");
                            $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.6.0.sql");
                            $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.0.sql");
                            $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.1.sql");
                        } else {
                            if (TableExists("glpi_plugin_compte") && !TableExists("glpi_plugin_compte_aeskey")) {
                                $update78 = true;
                                $update80 = true;
                                $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.5.3.sql");
                                $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.6.0.sql");
                                $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.0.sql");
                                $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.1.sql");
                            } else {
                                if (TableExists("glpi_plugin_compte") && !TableExists("glpi_plugin_accounts_accounts")) {
                                    $update78 = true;
                                    $update80 = true;
                                    $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.6.0.sql");
                                    $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.0.sql");
                                    $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.1.sql");
                                } else {
                                    if (TableExists("glpi_plugin_accounts_accounts") && !FieldExists("glpi_plugin_accounts_accounts", "locations_id")) {
                                        $update80 = true;
                                        $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.0.sql");
                                        $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.1.sql");
                                    } else {
                                        if (TableExists("glpi_plugin_accounts_hashes") && !FieldExists("glpi_plugin_accounts_hashes", "entities_id")) {
                                            $update171 = true;
                                            $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.7.1.sql");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    //from 1.6 version
    if (TableExists("glpi_plugin_accounts_accounts") && !FieldExists("glpi_plugin_accounts_accounts", "users_id_tech")) {
        $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.8.0.sql");
    }
    //from 1.9 version
    if (TableExists("glpi_plugin_accounts_accounttypes") && !FieldExists("glpi_plugin_accounts_accounttypes", "is_recursive")) {
        $DB->runFile(GLPI_ROOT . "/plugins/accounts/sql/update-1.9.0.sql");
    }
    if ($install || $update78) {
        //Do One time on 0.78
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates`\n               WHERE `itemtype`='PluginAccountsAccount'\n               AND `name` = 'New Accounts'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n               VALUES(NULL, " . $itemtype . ", '','##lang.account.title##',\n                        '##lang.account.url## : ##account.url##\r\n\r\n\n                        ##lang.account.entity## : ##account.entity##\r\n\n                        ##IFaccount.name####lang.account.name## : ##account.name##\r\n##ENDIFaccount.name##\n                        ##IFaccount.type####lang.account.type## : ##account.type##\r\n##ENDIFaccount.type##\n                        ##IFaccount.state####lang.account.state## : ##account.state##\r\n##ENDIFaccount.state##\n                        ##IFaccount.login####lang.account.login## : ##account.login##\r\n##ENDIFaccount.login##\n                        ##IFaccount.users_id####lang.account.users_id## : ##account.users_id##\r\n##ENDIFaccount.users_id##\n                        ##IFaccount.groups_id####lang.account.groups_id## : ##account.groups_id##\r\n##ENDIFaccount.groups_id##\n                        ##IFaccount.others####lang.account.others## : ##account.others##\r\n##ENDIFaccount.others##\n                        ##IFaccount.datecreation####lang.account.datecreation## : ##account.datecreation##\r\n##ENDIFaccount.datecreation##\n                        ##IFaccount.dateexpiration####lang.account.dateexpiration## : ##account.dateexpiration##\r\n##ENDIFaccount.dateexpiration##\n                        ##IFaccount.comment####lang.account.comment## : ##account.comment##\r\n##ENDIFaccount.comment##',\n                        '&lt;p&gt;&lt;strong&gt;##lang.account.url##&lt;/strong&gt; : &lt;a href=\"##account.url##\"&gt;##account.url##&lt;/a&gt;&lt;/p&gt;\n                        &lt;p&gt;&lt;strong&gt;##lang.account.entity##&lt;/strong&gt; : ##account.entity##&lt;br /&gt; ##IFaccount.name##&lt;strong&gt;##lang.account.name##&lt;/strong&gt; : ##account.name##&lt;br /&gt;##ENDIFaccount.name##  ##IFaccount.type##&lt;strong&gt;##lang.account.type##&lt;/strong&gt; : ##account.type##&lt;br /&gt;##ENDIFaccount.type##  ##IFaccount.state##&lt;strong&gt;##lang.account.state##&lt;/strong&gt; : ##account.state##&lt;br /&gt;##ENDIFaccount.state##  ##IFaccount.login##&lt;strong&gt;##lang.account.login##&lt;/strong&gt; : ##account.login##&lt;br /&gt;##ENDIFaccount.login##  ##IFaccount.users##&lt;strong&gt;##lang.account.users##&lt;/strong&gt; : ##account.users##&lt;br /&gt;##ENDIFaccount.users##  ##IFaccount.groups##&lt;strong&gt;##lang.account.groups##&lt;/strong&gt; : ##account.groups##&lt;br /&gt;##ENDIFaccount.groups##  ##IFaccount.others##&lt;strong&gt;##lang.account.others##&lt;/strong&gt; : ##account.others##&lt;br /&gt;##ENDIFaccount.others##  ##IFaccount.datecreation##&lt;strong&gt;##lang.account.datecreation##&lt;/strong&gt; : ##account.datecreation##&lt;br /&gt;##ENDIFaccount.datecreation##  ##IFaccount.dateexpiration##&lt;strong&gt;##lang.account.dateexpiration##&lt;/strong&gt; : ##account.dateexpiration##&lt;br /&gt;##ENDIFaccount.dateexpiration##  ##IFaccount.comment##&lt;strong&gt;##lang.account.comment##&lt;/strong&gt; : ##account.comment####ENDIFaccount.comment##&lt;/p&gt;');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n               VALUES (NULL, 'New Accounts', 0, 'PluginAccountsAccount', 'new',\n               'mail'," . $itemtype . ",\n                        '', 1, 1, '2010-02-17 22:36:46');";
        $result = $DB->query($query);
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates`\n               WHERE `itemtype`='PluginAccountsAccount'\n               AND `name` = 'Alert Accounts'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n               VALUES(NULL, " . $itemtype . ", '','##account.action## : ##account.entity##',\n                        '##lang.account.entity## :##account.entity##\n                        ##FOREACHaccounts##\n                        ##lang.account.name## : ##account.name## - ##lang.account.dateexpiration## : ##account.dateexpiration##\n                        ##ENDFOREACHaccounts##',\n                        '&lt;p&gt;##lang.account.entity## :##account.entity##&lt;br /&gt; &lt;br /&gt;\n                        ##FOREACHaccounts##&lt;br /&gt;\n                        ##lang.account.name##  : ##account.name## - ##lang.account.dateexpiration## :  ##account.dateexpiration##&lt;br /&gt;\n                        ##ENDFOREACHaccounts##&lt;/p&gt;');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n               VALUES (NULL, 'Alert Expired Accounts', 0, 'PluginAccountsAccount', 'ExpiredAccounts',\n               'mail'," . $itemtype . ",\n                        '', 1, 1, '2010-02-17 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n               VALUES (NULL, 'Alert Accounts Which Expire', 0, 'PluginAccountsAccount', 'AccountsWhichExpire',\n               'mail'," . $itemtype . ",\n                        '', 1, 1, '2010-02-17 22:36:46');";
        $result = $DB->query($query);
    }
    if ($update78) {
        //Do One time on 0.78
        $query_ = "SELECT *\n               FROM `glpi_plugin_accounts_profiles` ";
        $result_ = $DB->query($query_);
        if ($DB->numrows($result_) > 0) {
            while ($data = $DB->fetch_array($result_)) {
                $query = "UPDATE `glpi_plugin_accounts_profiles`\n                     SET `profiles_id` = '" . $data["id"] . "'\n                              WHERE `id` = '" . $data["id"] . "';";
                $result = $DB->query($query);
            }
        }
        $query = "ALTER TABLE `glpi_plugin_accounts_profiles`\n               DROP `name` ;";
        $result = $DB->query($query);
        Plugin::migrateItemType(array(1900 => 'PluginAccountsAccount', 1901 => 'PluginAccountsHelpdesk', 1902 => 'PluginAccountsGroup'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_tickets"), array("glpi_plugin_accounts_accounts_items"));
        Plugin::migrateItemType(array(1200 => "PluginAppliancesAppliance", 1300 => "PluginWebapplicationsWebapplication", 1700 => "PluginCertificatesCertificate", 4400 => "PluginDomainsDomain", 2400 => "PluginDatabasesDatabase"), array("glpi_plugin_accounts_accounts_items"));
    }
    if ($update171) {
        $query = "UPDATE `glpi_plugin_accounts_hashes`\n               SET `is_recursive` = '1'\n               WHERE `id` = '1';";
        $result = $DB->query($query);
        $query = "UPDATE `glpi_plugin_accounts_aeskeys`\n               SET `plugin_accounts_hashes_id` = '1'\n               WHERE `id` = '1';";
        $result = $DB->query($query);
    }
    if (isset($_SESSION['plugin_acounts_upgrading'])) {
        $msg = __('After plugin installation, you must do upgrade of your passwords from here : ', 'accounts');
        $msg .= "<a href='" . $CFG_GLPI["root_doc"] . "/plugins/accounts/front/upgrade.form.php'>" . __('Upgrading page', 'accounts') . "</a>";
        Session::addMessageAfterRedirect($msg, ERROR);
    }
    CronTask::Register('PluginAccountsAccount', 'AccountsAlert', DAY_TIMESTAMP);
    PluginAccountsProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
    return true;
}
Ejemplo n.º 18
0
function pluginFusioninventoryInstall($version, $migrationname = 'Migration')
{
    global $DB;
    ini_set("memory_limit", "-1");
    ini_set("max_execution_time", "0");
    $migration = new $migrationname($version);
    /*
     * Load classes
     */
    foreach (glob(GLPI_ROOT . '/plugins/fusioninventory/inc/*.php') as $file) {
        require_once $file;
    }
    $migration->displayMessage("Installation of plugin FusionInventory");
    // Get informations of plugin
    /*
     * Clean if Fusion / Tracker has been installed and uninstalled (not clean correctly)
     */
    $migration->displayMessage("Clean data from old installation of the plugin");
    $sql = "DELETE FROM `glpi_displaypreferences`\n         WHERE `itemtype`='5150'";
    $DB->query($sql);
    $sql = "DELETE FROM `glpi_displaypreferences`\n         WHERE `itemtype`='5151'";
    $DB->query($sql);
    $sql = "DELETE FROM `glpi_displaypreferences`\n         WHERE `itemtype`='5152'";
    $DB->query($sql);
    $sql = "DELETE FROM `glpi_displaypreferences`\n         WHERE `itemtype`='5153'";
    $DB->query($sql);
    $sql = "DELETE FROM `glpi_displaypreferences`\n         WHERE `itemtype`='5156'";
    $DB->query($sql);
    $sql = "DELETE FROM `glpi_displaypreferences`\n         WHERE `itemtype`='5157'";
    $DB->query($sql);
    $sql = "DELETE FROM `glpi_displaypreferences`\n         WHERE `itemtype`='5158'";
    $DB->query($sql);
    $sql = "DELETE FROM `glpi_displaypreferences`\n         WHERE `itemtype`='5159'";
    $DB->query($sql);
    $sql = "DELETE FROM `glpi_displaypreferences`\n         WHERE `itemtype`='5161'";
    $DB->query($sql);
    $sql = "DELETE FROM `glpi_displaypreferences`\n         WHERE `itemtype`='5165'";
    $DB->query($sql);
    $sql = "DELETE FROM `glpi_displaypreferences`\n         WHERE `itemtype`='5166'";
    $DB->query($sql);
    $sql = "DELETE FROM `glpi_displaypreferences`\n         WHERE `itemtype`='5167'";
    $DB->query($sql);
    $sql = "DELETE FROM `glpi_displaypreferences`\n         WHERE `itemtype`='5168'";
    $DB->query($sql);
    $sql = "DELETE FROM `glpi_displaypreferences`\n         WHERE `itemtype` LIKE 'PluginFusioninventory%'";
    $DB->query($sql);
    $sql = "DELETE FROM `glpi_displaypreferences`\n         WHERE `itemtype` LIKE 'PluginFusinvinventory%'";
    $DB->query($sql);
    $sql = "DELETE FROM `glpi_displaypreferences`\n         WHERE `itemtype` LIKE 'PluginFusinvsnmp%'";
    $DB->query($sql);
    // Purge network ports have itemtype tp 5153
    $networkPort = new NetworkPort();
    $sql = "SELECT * FROM `glpi_networkports`\n            WHERE `itemtype`='5153'";
    $result = $DB->query($sql);
    while ($data = $DB->fetch_array($result)) {
        $networkPort->delete(array('id' => $data['id']), 1);
    }
    /*
     * Remove old rules
     */
    $migration->displayMessage("Clean rules from old installation of the plugin");
    $Rule = new Rule();
    $a_rules = $Rule->find("`sub_type`='PluginFusioninventoryInventoryRuleImport'");
    foreach ($a_rules as $data) {
        $Rule->delete($data);
    }
    $a_rules = $Rule->find("`sub_type`='PluginFusinvinventoryRuleEntity'");
    foreach ($a_rules as $data) {
        $Rule->delete($data);
    }
    $a_rules = $Rule->find("`sub_type`='PluginFusinvinventoryRuleLocation'");
    foreach ($a_rules as $data) {
        $Rule->delete($data);
    }
    /*
     * Create DB structure
     */
    $migration->displayMessage("Creation tables in database");
    $DB_file = GLPI_ROOT . "/plugins/fusioninventory/install/mysql/plugin_fusioninventory-empty.sql";
    if (!$DB->runFile($DB_file)) {
        $migration->displayMessage("Error on creation tables in database");
    }
    if (!$DB->runFile(GLPI_ROOT . "/plugins/fusioninventory/install/mysql/usbid.sql")) {
        $migration->displayMessage("Error on creation table usbid in database");
    }
    if (!$DB->runFile(GLPI_ROOT . "/plugins/fusioninventory/install/mysql/pciid.sql")) {
        $migration->displayMessage("Error on creation table pciid in database");
    }
    if (!$DB->runFile(GLPI_ROOT . "/plugins/fusioninventory/install/mysql/oui.sql")) {
        $migration->displayMessage("Error on creation table oui in database");
    }
    /*
     * Creation of folders
     */
    $migration->displayMessage("Creation of folders");
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/tmp')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/tmp');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml/computer')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml/computer');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml/printer')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml/printer');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml/networkequipment')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml/networkequipment');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/upload')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/upload');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/walks')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/walks');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/tmpmodels')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/tmpmodels');
    }
    /*
     * Deploy folders
     */
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/repository')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/repository');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/manifests')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/manifests');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/import')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/import');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/export')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/export');
    }
    /*
     * Manage profiles
     */
    $migration->displayMessage("Initialize profiles");
    PluginFusioninventoryProfile::initProfile();
    /*
     * bug of purge network port when purge unmanaged devices, so we clean
     */
    $sql = "SELECT `glpi_networkports`.`id` as nid FROM `glpi_networkports`\n         LEFT JOIN `glpi_plugin_fusioninventory_unmanageds`\n            ON `glpi_plugin_fusioninventory_unmanageds`.`id` = `glpi_networkports`.`items_id`\n         WHERE `itemtype`='PluginFusioninventoryUnmanaged'\n            AND `glpi_plugin_fusioninventory_unmanageds`.`id` IS NULL ";
    $result = $DB->query($sql);
    while ($data = $DB->fetch_array($result)) {
        $networkPort->delete(array('id' => $data['nid']), 1);
    }
    /*
     * Add config
     */
    $migration->displayMessage("Initialize configuration");
    $pfConfig = new PluginFusioninventoryConfig();
    $pfConfig->initConfigModule();
    $configLogField = new PluginFusioninventoryConfigLogField();
    $configLogField->initConfig();
    /*
     * Register Agent TASKS
     */
    $migration->displayMessage("Initialize agent TASKS");
    $pfAgentmodule = new PluginFusioninventoryAgentmodule();
    $input = array();
    $input['modulename'] = "WAKEONLAN";
    $input['is_active'] = 0;
    $input['exceptions'] = exportArrayToDB(array());
    $pfAgentmodule->add($input);
    $input = array();
    $input['modulename'] = "INVENTORY";
    $input['is_active'] = 1;
    $input['exceptions'] = exportArrayToDB(array());
    $pfAgentmodule->add($input);
    $input = array();
    $input['modulename'] = "InventoryComputerESX";
    $input['is_active'] = 0;
    $input['exceptions'] = exportArrayToDB(array());
    $pfAgentmodule->add($input);
    $input = array();
    $input['modulename'] = "NETWORKINVENTORY";
    $input['is_active'] = 0;
    $input['exceptions'] = exportArrayToDB(array());
    $pfAgentmodule->add($input);
    $input = array();
    $input['modulename'] = "NETWORKDISCOVERY";
    $input['is_active'] = 0;
    $input['exceptions'] = exportArrayToDB(array());
    $pfAgentmodule->add($input);
    $input = array();
    $input['modulename'] = "DEPLOY";
    $input['is_active'] = 0;
    $input['exceptions'] = exportArrayToDB(array());
    $pfAgentmodule->add($input);
    $input = array();
    $input['modulename'] = "Collect";
    $input['is_active'] = 1;
    $input['exceptions'] = exportArrayToDB(array());
    $pfAgentmodule->add($input);
    /*
     * Add cron task
     */
    $migration->displayMessage("Initialize cron task");
    CronTask::Register('PluginFusioninventoryTask', 'taskscheduler', '60', array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30));
    Crontask::Register('PluginFusioninventoryTaskjobstate', 'cleantaskjob', 3600 * 24, array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30));
    Crontask::Register('PluginFusioninventoryNetworkPortLog', 'cleannetworkportlogs', 3600 * 24, array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30));
    CronTask::Register('PluginFusioninventoryTaskjob', 'updatedynamictasks', '60', array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30, 'state' => 0));
    Crontask::Register('PluginFusioninventoryAgent', 'cleanoldagents', 3600 * 24, array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30, 'comment' => 'Clean agents not contacted since xxx days'));
    Crontask::Register('PluginFusioninventoryAgentWakeup', 'wakeupAgents', 120, array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30, 'comment' => 'Wake agents ups'));
    /*
     * Create rules
     */
    $migration->displayMessage("Create rules");
    $pfSetup = new PluginFusioninventorySetup();
    $pfSetup->initRules();
    /*
     * Add notification for configuration management
     */
    /*
     *  Import OCS locks
     */
    $migration->displayMessage("Import OCS locks if exists");
    $pfLock = new PluginFusioninventoryLock();
    $pfLock->importFromOcs();
    Crontask::Register('PluginFusioninventoryTaskjobstate', 'cleantaskjob', 3600 * 24, array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30));
    $pfNetworkporttype = new PluginFusioninventoryNetworkporttype();
    $pfNetworkporttype->init();
    require_once GLPI_ROOT . "/plugins/fusioninventory/inc/inventorycomputerstat.class.php";
    PluginFusioninventoryInventoryComputerStat::init();
    $mode_cli = basename($_SERVER['SCRIPT_NAME']) == "cli_install.php";
}
Ejemplo n.º 19
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;
}
Ejemplo n.º 20
0
function plugin_badges_install()
{
    global $DB;
    include_once GLPI_ROOT . "/plugins/badges/inc/profile.class.php";
    $install = false;
    $update78 = false;
    $update85 = false;
    $update201 = false;
    if (!TableExists("glpi_plugin_badges") && !TableExists("glpi_plugin_badges_badgetypes")) {
        $install = true;
        $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/empty-2.0.1.sql");
    } else {
        if (TableExists("glpi_plugin_badges_users") && !TableExists("glpi_plugin_badges_default")) {
            $update78 = true;
            $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/update-1.4.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/update-1.5.0.sql");
            plugin_badges_configure15();
            $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/update-1.5.1.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/update-1.6.0.sql");
        } else {
            if (TableExists("glpi_plugin_badges_profiles") && FieldExists("glpi_plugin_badges_profiles", "interface")) {
                $update78 = true;
                $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/update-1.5.0.sql");
                plugin_badges_configure15();
                $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/update-1.5.1.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/update-1.6.0.sql");
            } else {
                if (TableExists("glpi_plugin_badges") && !FieldExists("glpi_plugin_badges", "date_mod")) {
                    $update78 = true;
                    $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/update-1.5.1.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/update-1.6.0.sql");
                } else {
                    if (!TableExists("glpi_plugin_badges_badgetypes")) {
                        $update78 = true;
                        $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/update-1.6.0.sql");
                    } else {
                        if (TableExists("glpi_plugin_badges_profiles")) {
                            $update85 = true;
                        }
                    }
                }
            }
        }
    }
    if (!TableExists("glpi_plugin_badges_requests")) {
        $update201 = true;
        $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/update-2.0.1.sql");
    }
    if ($install || $update201) {
        // Badge request notification
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginBadgesBadge' AND `name` = 'Access Badges Request'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        if (empty($itemtype)) {
            $query_id = "INSERT INTO `glpi_notificationtemplates`(`id`, `name`, `itemtype`, `date_mod`, `comment`, `css`) VALUES ('','Access Badges Request','PluginBadgesBadge', NOW(),'','');";
            $result = $DB->query($query_id) or die($DB->error());
            $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginBadgesBadge' AND `name` = 'Access Badges Request'";
            $result = $DB->query($query_id) or die($DB->error());
            $itemtype = $DB->result($result, 0, 'id');
        }
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\r\n                                 VALUES(NULL, '" . $itemtype . "', '','##badge.action## : ##badge.entity##',\r\n                        '##lang.badge.entity## :##badge.entity##\r\n                        ##FOREACHbadgerequest## \r\n                        ##lang.badgerequest.arrivaldate## : ##badgerequest.arrivaldate##\t\r\n                        ##lang.badgerequest.requester## : ##badgerequest.requester##\t\r\n                        ##lang.badgerequest.visitorfirstname## : ##badgerequest.visitorfirstname##\t\r\n                        ##lang.badgerequest.visitorrealname## : ##badgerequest.visitorrealname##\r\n                        ##lang.badgerequest.visitorsociety## : ##badgerequest.visitorsociety##\r\n                        ##ENDFOREACHbadgerequest##',\r\n                        '&lt;p&gt;##lang.badge.entity## :##badge.entity##&lt;br /&gt; &lt;br /&gt;\r\n                        ##FOREACHbadgerequest##&lt;br /&gt;\r\n                        ##lang.badgerequest.arrivaldate## : ##badgerequest.arrivaldate##&lt;br /&gt;\t\r\n                        ##lang.badgerequest.requester## : ##badgerequest.requester##&lt;br /&gt;\r\n                        ##lang.badgerequest.visitorfirstname## : ##badgerequest.visitorfirstname##&lt;br /&gt;\r\n                        ##lang.badgerequest.visitorrealname## : ##badgerequest.visitorrealname##&lt;br /&gt;\r\n                        ##lang.badgerequest.visitorsociety## : ##badgerequest.visitorsociety##&lt;br /&gt;\r\n                        ##ENDFOREACHbadgerequest##&lt;/p&gt;');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\r\n                                   VALUES (NULL, 'Access badge request', 0, 'PluginBadgesBadge', 'AccessBadgeRequest',\r\n                                          'mail','" . $itemtype . "',\r\n                                          '', 1, 1, '" . date('Y-m-d H:i:s') . "');";
        $result = $DB->query($query);
    }
    // Badge expiration alert notification
    $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginBadgesBadge' AND `name` = 'Access Badges Return'";
    $result = $DB->query($query_id) or die($DB->error());
    $itemtype = $DB->result($result, 0, 'id');
    if (empty($itemtype)) {
        $query_id = "INSERT INTO `glpi_notificationtemplates`(`id`, `name`, `itemtype`, `date_mod`, `comment`, `css`) VALUES ('','Access Badges Return','PluginBadgesBadge', NOW(),'','');";
        $result = $DB->query($query_id) or die($DB->error());
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginBadgesBadge' AND `name` = 'Access Badges Return'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
    }
    $query = "INSERT INTO `glpi_notificationtemplatetranslations`\r\n                              VALUES(NULL, '" . $itemtype . "', '','##badge.action## : ##badge.entity##',\r\n                     '##lang.badge.entity## :##badge.entity##\r\n                     ##FOREACHbadgerequest## \r\n                     ##lang.badgerequest.arrivaldate## : ##badgerequest.arrivaldate##\t\r\n                     ##lang.badgerequest.requester## : ##badgerequest.requester##\t\r\n                     ##lang.badgerequest.visitorfirstname## : ##badgerequest.visitorfirstname##\t\r\n                     ##lang.badgerequest.visitorrealname## : ##badgerequest.visitorrealname##\r\n                     ##lang.badgerequest.visitorsociety## : ##badgerequest.visitorsociety##\r\n                     ##ENDFOREACHbadgerequest##',\r\n                     '&lt;p&gt;##lang.badge.entity## :##badge.entity##&lt;br /&gt; &lt;br /&gt;\r\n                     ##FOREACHbadgerequest##&lt;br /&gt;\r\n                     ##lang.badgerequest.arrivaldate## : ##badgerequest.arrivaldate##&lt;br /&gt;\t\r\n                     ##lang.badgerequest.requester## : ##badgerequest.requester##&lt;br /&gt;\r\n                     ##lang.badgerequest.visitorfirstname## : ##badgerequest.visitorfirstname##&lt;br /&gt;\r\n                     ##lang.badgerequest.visitorrealname## : ##badgerequest.visitorrealname##&lt;br /&gt;\r\n                     ##lang.badgerequest.visitorsociety## : ##badgerequest.visitorsociety##&lt;br /&gt;\r\n                     ##ENDFOREACHbadgerequest##&lt;/p&gt;');";
    $result = $DB->query($query);
    $query = "INSERT INTO `glpi_notifications`\r\n                                VALUES (NULL, 'Access badge return', 0, 'PluginBadgesBadge', 'BadgesReturn',\r\n                                       'mail','" . $itemtype . "',\r\n                                       '', 1, 1, '" . date('Y-m-d H:i:s') . "');";
    $result = $DB->query($query);
    if ($update78) {
        $query_ = "SELECT *\r\n            FROM `glpi_plugin_badges_profiles` ";
        $result_ = $DB->query($query_);
        if ($DB->numrows($result_) > 0) {
            while ($data = $DB->fetch_array($result_)) {
                $query = "UPDATE `glpi_plugin_badges_profiles`\r\n                  SET `profiles_id` = '" . $data["id"] . "'\r\n                  WHERE `id` = '" . $data["id"] . "';";
                $result = $DB->query($query);
            }
        }
        $query = "ALTER TABLE `glpi_plugin_badges_profiles`\r\n               DROP `name` ;";
        $result = $DB->query($query);
        Plugin::migrateItemType(array(1600 => 'PluginBadgesBadge'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_items_tickets"));
    }
    if ($update85) {
        $notepad_tables = array('glpi_plugin_badges_badges');
        foreach ($notepad_tables as $t) {
            // Migrate data
            if (FieldExists($t, 'notepad')) {
                $query = "SELECT id, notepad\r\n                      FROM `{$t}`\r\n                      WHERE notepad IS NOT NULL\r\n                            AND notepad <>'';";
                foreach ($DB->request($query) as $data) {
                    $iq = "INSERT INTO `glpi_notepads`\r\n                             (`itemtype`, `items_id`, `content`, `date`, `date_mod`)\r\n                      VALUES ('" . getItemTypeForTable($t) . "', '" . $data['id'] . "',\r\n                              '" . addslashes($data['notepad']) . "', NOW(), NOW())";
                    $DB->queryOrDie($iq, "0.85 migrate notepad data");
                }
                $query = "ALTER TABLE `glpi_plugin_badges_badges` DROP COLUMN `notepad`;";
                $DB->query($query);
            }
        }
    }
    CronTask::Register('PluginBadgesBadge', 'BadgesAlert', DAY_TIMESTAMP);
    CronTask::Register('PluginBadgesReturn', 'BadgesReturnAlert', DAY_TIMESTAMP);
    PluginBadgesProfile::initProfile();
    PluginBadgesProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
    $migration = new Migration("2.0.0");
    $migration->dropTable('glpi_plugin_badges_profiles');
    return true;
}
Ejemplo n.º 21
0
function plugin_badges_install()
{
    global $DB;
    include_once GLPI_ROOT . "/plugins/badges/inc/profile.class.php";
    $install = false;
    $update78 = false;
    $update80 = false;
    if (!TableExists("glpi_plugin_badges") && !TableExists("glpi_plugin_badges_badgetypes")) {
        $install = true;
        $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/empty-1.7.0.sql");
    } else {
        if (TableExists("glpi_plugin_badges_users") && !TableExists("glpi_plugin_badges_default")) {
            $update78 = true;
            $update80 = true;
            $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/update-1.4.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/update-1.5.0.sql");
            plugin_badges_configure15();
            $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/update-1.5.1.sql");
            $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/update-1.6.0.sql");
        } else {
            if (TableExists("glpi_plugin_badges_profiles") && FieldExists("glpi_plugin_badges_profiles", "interface")) {
                $update78 = true;
                $update80 = true;
                $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/update-1.5.0.sql");
                plugin_badges_configure15();
                $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/update-1.5.1.sql");
                $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/update-1.6.0.sql");
            } else {
                if (TableExists("glpi_plugin_badges") && !FieldExists("glpi_plugin_badges", "date_mod")) {
                    $update78 = true;
                    $update80 = true;
                    $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/update-1.5.1.sql");
                    $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/update-1.6.0.sql");
                } else {
                    if (!TableExists("glpi_plugin_badges_badgetypes")) {
                        $update78 = true;
                        $update80 = true;
                        $DB->runFile(GLPI_ROOT . "/plugins/badges/sql/update-1.6.0.sql");
                    }
                }
            }
        }
    }
    if ($install || $update78) {
        //Do One time on 0.78
        $query_id = "SELECT `id` FROM `glpi_notificationtemplates` WHERE `itemtype`='PluginBadgesBadge' AND `name` = 'Alert Badges'";
        $result = $DB->query($query_id) or die($DB->error());
        $itemtype = $DB->result($result, 0, 'id');
        $query = "INSERT INTO `glpi_notificationtemplatetranslations`\n                                 VALUES(NULL, " . $itemtype . ", '','##badge.action## : ##badge.entity##',\n                        '##lang.badge.entity## :##badge.entity##\n   ##FOREACHbadges##\n   ##lang.badge.name## : ##badge.name## - ##lang.badge.dateexpiration## : ##badge.dateexpiration####IFbadge.serial## - ##lang.badge.serial## : ##badge.serial####ENDIFbadge.serial####IFbadge.users## - ##lang.badge.users## : ##badge.users####ENDIFbadge.users##\n   ##ENDFOREACHbadges##',\n                        '&lt;p&gt;##lang.badge.entity## :##badge.entity##&lt;br /&gt; &lt;br /&gt;\n                        ##FOREACHbadges##&lt;br /&gt;\n                        ##lang.badge.name##  : ##badge.name## - ##lang.badge.dateexpiration## :  ##badge.dateexpiration####IFbadge.serial## - ##lang.badge.serial## :  ##badge.serial####ENDIFbadge.serial####IFbadge.users## - ##lang.badge.users## :  ##badge.users####ENDIFbadge.users##&lt;br /&gt; \n                        ##ENDFOREACHbadges##&lt;/p&gt;');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Alert Expired Badges', 0, 'PluginBadgesBadge', 'ExpiredBadges',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-02-17 22:36:46');";
        $result = $DB->query($query);
        $query = "INSERT INTO `glpi_notifications`\n                                   VALUES (NULL, 'Alert Badges Which Expire', 0, 'PluginBadgesBadge', 'BadgesWhichExpire',\n                                          'mail'," . $itemtype . ",\n                                          '', 1, 1, '2010-02-17 22:36:46');";
        $result = $DB->query($query);
    }
    if ($update78) {
        $query_ = "SELECT *\n            FROM `glpi_plugin_badges_profiles` ";
        $result_ = $DB->query($query_);
        if ($DB->numrows($result_) > 0) {
            while ($data = $DB->fetch_array($result_)) {
                $query = "UPDATE `glpi_plugin_badges_profiles`\n                  SET `profiles_id` = '" . $data["id"] . "'\n                  WHERE `id` = '" . $data["id"] . "';";
                $result = $DB->query($query);
            }
        }
        $query = "ALTER TABLE `glpi_plugin_badges_profiles`\n               DROP `name` ;";
        $result = $DB->query($query);
        Plugin::migrateItemType(array(1600 => 'PluginBadgesBadge'), array("glpi_bookmarks", "glpi_bookmarks_users", "glpi_displaypreferences", "glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_tickets"));
    }
    CronTask::Register('PluginBadgesBadge', 'BadgesAlert', DAY_TIMESTAMP);
    PluginBadgesProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
    return true;
}
Ejemplo n.º 22
0
function pluginFusioninventoryUpdate($current_version, $migrationname = 'Migration')
{
    global $DB;
    ini_set("max_execution_time", "0");
    ini_set("memory_limit", "-1");
    foreach (glob(GLPI_ROOT . '/plugins/fusioninventory/inc/*.php') as $file) {
        require_once $file;
    }
    $migration = new $migrationname($current_version);
    $prepare_task = array();
    $prepare_rangeip = array();
    $prepare_Config = array();
    $a_plugin = plugin_version_fusioninventory();
    $plugins_id = PluginFusioninventoryModule::getModuleId($a_plugin['shortname']);
    $migration->displayMessage("Migration Classname : " . $migrationname);
    $migration->displayMessage("Update of plugin FusionInventory");
    /*
     * Check if folders are correctly created
     */
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/tmp')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/tmp');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml/computer')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml/computer');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml/printer')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml/printer');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml/networkequipment')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/xml/networkequipment');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/walks')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/walks');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/tmpmodels')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/tmpmodels');
    }
    /*
     * Deploy folders
     */
    if (is_dir(GLPI_PLUGIN_DOC_DIR . '/fusinvdeploy/files')) {
        rename(GLPI_PLUGIN_DOC_DIR . '/fusinvdeploy/files', GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files');
    }
    if (is_dir(GLPI_PLUGIN_DOC_DIR . '/fusinvdeploy/repository')) {
        rename(GLPI_PLUGIN_DOC_DIR . '/fusinvdeploy/repository', GLPI_PLUGIN_DOC_DIR . '/fusioninventory/repository');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/repository')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/repository');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/manifests')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/manifests');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/import')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/import');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/export')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files/export');
    }
    if (is_dir(GLPI_PLUGIN_DOC_DIR . '/fusinvdeploy/upload')) {
        rename(GLPI_PLUGIN_DOC_DIR . '/fusinvdeploy/upload', GLPI_PLUGIN_DOC_DIR . '/fusioninventory/upload');
    }
    if (!is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/upload')) {
        mkdir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/upload');
    }
    /*
     * Rename fileparts without .gz extension (cf #1999)
     */
    if (is_dir(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files')) {
        $gzfiles = pluginFusioninventoryFindFiles(GLPI_PLUGIN_DOC_DIR . '/fusioninventory/files', '/\\.gz$/');
        foreach ($gzfiles as $file) {
            $fileWithoutExt = pathinfo($file, PATHINFO_DIRNAME) . '/' . pathinfo($file, PATHINFO_FILENAME);
            rename($file, $fileWithoutExt);
        }
    }
    unset($gzfiles);
    /*
     *  Rename tables from old version of FuionInventory (2.2.1 for example)
     */
    $migration->renameTable("glpi_plugin_fusioninventory_rangeip", "glpi_plugin_fusioninventory_ipranges");
    $migration->renameTable("glpi_plugin_fusioninventory_lock", "glpi_plugin_fusioninventory_locks");
    $migration->renameTable("glpi_plugin_fusioninventory_unknown_device", "glpi_plugin_fusioninventory_unknowndevices");
    $migration->renameTable("glpi_plugin_fusioninventory_config", "glpi_plugin_fusioninventory_configs");
    $migration->renameTable("glpi_plugin_fusioninventory_networking_ports", "glpi_plugin_fusinvsnmp_networkports");
    $migration->renameTable("glpi_plugin_fusioninventory_construct_device", "glpi_plugin_fusinvsnmp_constructdevices");
    $migration->renameTable("glpi_plugin_fusioninventory_construct_mibs", "glpi_plugin_fusioninventory_snmpmodelconstructdevice_miboids");
    $migration->renameTable("glpi_plugin_fusioninventory_networking", "glpi_plugin_fusioninventory_networkequipments");
    $migration->renameTable("glpi_plugin_fusioninventory_networking_ifaddr", "glpi_plugin_fusinvsnmp_networkequipmentips");
    $migration->renameTable("glpi_plugin_fusioninventory_printers", "glpi_plugin_fusinvsnmp_printers");
    $migration->renameTable("glpi_plugin_fusioninventory_printers_cartridges", "glpi_plugin_fusinvsnmp_printercartridges");
    $migration->renameTable("glpi_plugin_fusioninventory_printers_history", "glpi_plugin_fusinvsnmp_printerlogs");
    $migration->renameTable("glpi_plugin_fusioninventory_model_infos", "glpi_plugin_fusioninventory_snmpmodels");
    $migration->renameTable("glpi_plugin_fusioninventory_mib_networking", "glpi_plugin_fusinvsnmp_modelmibs");
    $migration->renameTable("glpi_plugin_fusioninventory_snmp_connection", "glpi_plugin_fusinvsnmp_configsecurities");
    $migration->renameTable("glpi_plugin_fusioninventory_snmp_history", "glpi_plugin_fusinvsnmp_networkportlogs");
    $migration->renameTable("glpi_plugin_fusioninventory_snmp_history_connections", "glpi_plugin_fusinvsnmp_networkportconnectionlogs");
    $a_droptable = array('glpi_plugin_fusioninventory_agents_inventory_state', 'glpi_plugin_fusioninventory_config_modules', 'glpi_plugin_fusioninventory_connection_stats', 'glpi_plugin_fusioninventory_discovery', 'glpi_plugin_fusioninventory_errors', 'glpi_plugin_fusioninventory_lockable', 'glpi_plugin_fusioninventory_connection_history', 'glpi_plugin_fusioninventory_walks', 'glpi_plugin_fusioninventory_config_snmp_history', 'glpi_plugin_fusioninventory_config_snmp_networking', 'glpi_plugin_fusioninventory_task', 'glpi_plugin_fusinvinventory_pcidevices', 'glpi_plugin_fusinvinventory_pcivendors', 'glpi_plugin_fusinvinventory_usbdevices', 'glpi_plugin_fusinvinventory_usbvendors', 'glpi_plugin_fusinvsnmp_constructdevicewalks', 'glpi_plugin_fusioninventory_snmpmodelmiblabels', 'glpi_plugin_fusioninventory_snmpmodelmibobjects', 'glpi_plugin_fusioninventory_snmpmodelmiboids', 'glpi_plugin_fusioninventory_snmpmodelconstructdevices', 'glpi_plugin_fusioninventory_snmpmodelconstructdevicewalks' . 'glpi_plugin_fusioninventory_snmpmodelconstructdevices_users', 'glpi_plugin_fusioninventory_snmpmodelconstructdevice_miboids', 'glpi_plugin_fusioninventory_snmpmodelmibs', 'glpi_plugin_fusioninventory_snmpmodels', 'glpi_plugin_fusioninventory_snmpmodeldevices', 'glpi_plugin_fusinvsnmp_constructdevice_miboids', 'glpi_plugin_fusinvsnmp_constructdevices', 'glpi_plugin_fusinvsnmp_constructdevices_users', 'glpi_plugin_fusinvsnmp_miblabels', 'glpi_plugin_fusinvsnmp_mibobjects', 'glpi_plugin_fusinvsnmp_miboids', 'glpi_plugin_fusinvsnmp_modeldevices', 'glpi_plugin_fusinvsnmp_modelmibs', 'glpi_plugin_fusinvsnmp_models', 'glpi_plugin_fusioninventory_construct_walks');
    foreach ($a_droptable as $newTable) {
        $migration->dropTable($newTable);
    }
    /*
       $a_table = array();
    
       //table name
       $a_table['name'] = '';
       $a_table['oldname'] = array(
       );
    
       // fields : fields that are new, have changed type or just stay the same
       //    array(
       //        <fieldname> = array(
       //            'type' => <type>, 'value' => <value>)
       //    );
       $a_table['fields'] = array(
    
       );
    
       // oldfields = fields that need to be removed
       //    array( 'field0', 'field1', ...);
       $a_table['oldfields'] = array(
       );
    
       // renamefields = fields that need to be renamed
       //    array('oldname' = 'newname', ...)
       $a_table['renamefields'] = array(
       );
    
       // keys : new, changed or not
       //    array( 'field' => <fields>, 'name' => <keyname> , 'type' => <keytype>)
       // <fields> : fieldnames needed by the key
       //            ex : array('field0' , 'field1' ...)
       //            ex : 'fieldname'
       // <keyname> : the name of the key (if blank, the fieldname is used)
       // <type> : the type of key (ex: INDEX, ...)
       $a_table['keys'] = array(
       );
    
       // oldkeys : keys that need to be removed
       //    array( 'key0', 'key1', ... )
       $a_table['oldkeys'] = array(
       );
    */
    //Push task functionnality
    $migration->addField('glpi_plugin_fusioninventory_tasks', 'last_agent_wakeup', 'datetime');
    $migration->addField('glpi_plugin_fusioninventory_tasks', 'wakeup_agent_counter', "int(11) NOT NULL DEFAULT '0'");
    $migration->addField('glpi_plugin_fusioninventory_tasks', 'wakeup_agent_time', "int(11) NOT NULL DEFAULT '0'");
    $migration->addKey('glpi_plugin_fusioninventory_tasks', 'wakeup_agent_counter');
    $migration->migrationOneTable('glpi_plugin_fusioninventory_tasks');
    /*
     *  Table glpi_plugin_fusioninventory_agents
     */
    $newTable = "glpi_plugin_fusioninventory_agents";
    $prepare_agentConfig = array();
    if (TableExists("glpi_plugin_tracker_agents") and FieldExists("glpi_plugin_tracker_agents", "ifaddr_start")) {
        $query = "SELECT * FROM `glpi_plugin_tracker_agents`";
        $result = $DB->query($query);
        while ($data = $DB->fetch_array($result)) {
            $prepare_rangeip[] = array("ip_start" => $data['ifaddr_start'], "ip_end" => $data['ifaddr_end'], "name" => $data['name']);
            $prepare_agentConfig[] = array("name" => $data["name"], "lock" => $data['lock'], "threads_networkinventory" => $data['nb_process_query'], "threads_networkdiscovery" => $data['nb_process_discovery']);
        }
    } else {
        if (TableExists("glpi_plugin_tracker_agents") and FieldExists("glpi_plugin_tracker_agents", "core_discovery")) {
            $query = "SELECT * FROM `glpi_plugin_tracker_agents`";
            $result = $DB->query($query);
            while ($data = $DB->fetch_array($result)) {
                $prepare_agentConfig[] = array("name" => $data["name"], "lock" => $data['lock'], "threads_networkinventory" => $data['threads_query'], "threads_networkdiscovery" => $data['threads_discovery']);
            }
        } else {
            if (TableExists("glpi_plugin_fusioninventory_agents")) {
                if (FieldExists($newTable, "module_snmpquery")) {
                    $query = "SELECT * FROM `glpi_plugin_fusioninventory_agents`";
                    $result = $DB->query($query);
                    while ($data = $DB->fetch_array($result)) {
                        $prepare_agentConfig[] = array("id" => $data["ID"], "threads_networkinventory" => $data['threads_query'], "threads_networkdiscovery" => $data['threads_discovery'], "NETORKINVENTORY" => $data['module_snmpquery'], "NETWORKDISCOVERY" => $data['module_netdiscovery'], "INVENTORY" => $data['module_inventory'], "WAKEONLAN" => $data['module_wakeonlan']);
                    }
                }
            }
        }
    }
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_agents';
    $a_table['oldname'] = array('glpi_plugin_tracker_agents');
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['entities_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['is_recursive'] = array('type' => 'bool', 'value' => '1');
    $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['last_contact'] = array('type' => 'datetime', 'value' => NULL);
    $a_table['fields']['version'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['lock'] = array('type' => 'bool', 'value' => NULL);
    $a_table['fields']['device_id'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['computers_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['token'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['useragent'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['tag'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['threads_networkdiscovery'] = array('type' => "int(4) NOT NULL DEFAULT '1' COMMENT 'array(xmltag=>value)'", 'value' => NULL);
    $a_table['fields']['threads_networkinventory'] = array('type' => "int(4) NOT NULL DEFAULT '1' COMMENT 'array(xmltag=>value)'", 'value' => NULL);
    $a_table['fields']['senddico'] = array('type' => 'bool', 'value' => NULL);
    $a_table['fields']['timeout_networkdiscovery'] = array('type' => "int(4) NOT NULL DEFAULT '0' COMMENT 'Network Discovery task timeout'", 'value' => NULL);
    $a_table['fields']['timeout_networkinventory'] = array('type' => "int(4) NOT NULL DEFAULT '0' COMMENT 'Network Inventory task timeout'", 'value' => NULL);
    $a_table['fields']['agent_port'] = array('type' => 'varchar(6)', 'value' => NULL);
    $a_table['oldfields'] = array('module_snmpquery', 'module_netdiscovery', 'module_inventory', 'module_wakeonlan', 'core_discovery', 'threads_discovery', 'core_query', 'threads_query', 'tracker_agent_version', 'logs', 'fragment', 'itemtype', 'device_type');
    $a_table['renamefields'] = array();
    $a_table['renamefields']['ID'] = 'id';
    $a_table['renamefields']['last_agent_update'] = 'last_contact';
    $a_table['renamefields']['fusioninventory_agent_version'] = 'version';
    $a_table['renamefields']['key'] = 'device_id';
    $a_table['renamefields']['on_device'] = 'computers_id';
    $a_table['renamefields']['items_id'] = 'computers_id';
    $a_table['keys'] = array();
    $a_table['keys'][] = array('field' => 'name', 'name' => '', 'type' => 'INDEX');
    $a_table['keys'][] = array('field' => 'device_id', 'name' => '', 'type' => 'INDEX');
    $a_table['keys'][] = array('field' => 'computers_id', 'name' => '', 'type' => 'INDEX');
    $a_table['oldkeys'] = array('key');
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_agentmodules
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_agentmodules';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['modulename'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['is_active'] = array('type' => 'bool', 'value' => NULL);
    $a_table['fields']['exceptions'] = array('type' => 'text', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['oldfields'][] = 'plugins_id';
    $a_table['oldfields'][] = 'entities_id';
    $a_table['oldfields'][] = 'url';
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['keys'][] = array('field' => 'modulename', 'name' => '', 'type' => 'UNIQUE');
    $a_table['oldkeys'] = array('unicity', 'entities_id');
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Add Deploy module
     */
    $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_agentmodules`\n      WHERE `modulename`='DEPLOY'";
    $result = $DB->query($query);
    if (!$DB->numrows($result)) {
        $query_ins = "INSERT INTO `glpi_plugin_fusioninventory_agentmodules`\n            (`modulename`, `is_active`, `exceptions`)\n         VALUES ('DEPLOY', '0', '" . exportArrayToDB(array()) . "')";
        $DB->query($query_ins);
    }
    /*
     * Add WakeOnLan module appear in version 2.3.0
     */
    $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_agentmodules`\n      WHERE `modulename`='WAKEONLAN'";
    $result = $DB->query($query);
    if (!$DB->numrows($result)) {
        $query_ins = "INSERT INTO `glpi_plugin_fusioninventory_agentmodules`\n            (`modulename`, `is_active`, `exceptions`)\n         VALUES ('WAKEONLAN', '0', '" . exportArrayToDB(array()) . "')";
        $DB->query($query_ins);
    }
    /*
     * Add SNMPQUERY module if not present
     */
    $query = "UPDATE `glpi_plugin_fusioninventory_agentmodules`\n      SET `modulename`='NETWORKINVENTORY'\n      WHERE `modulename`='SNMPQUERY'";
    $DB->query($query);
    $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_agentmodules`\n      WHERE `modulename`='NETWORKINVENTORY'";
    $result = $DB->query($query);
    if (!$DB->numrows($result)) {
        $agentmodule = new PluginFusioninventoryAgentmodule();
        $input = array();
        $input['modulename'] = "NETWORKINVENTORY";
        $input['is_active'] = 0;
        $input['exceptions'] = exportArrayToDB(array());
        $agentmodule->add($input);
    }
    /*
     * Add NETDISCOVERY module if not present
     */
    $query = "UPDATE `glpi_plugin_fusioninventory_agentmodules`\n      SET `modulename`='NETWORKDISCOVERY'\n      WHERE `modulename`='NETDISCOVERY'";
    $DB->query($query);
    $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_agentmodules`\n      WHERE `modulename`='NETWORKDISCOVERY'";
    $result = $DB->query($query);
    if (!$DB->numrows($result)) {
        $agentmodule = new PluginFusioninventoryAgentmodule();
        $input = array();
        $input['modulename'] = "NETWORKDISCOVERY";
        $input['is_active'] = 0;
        $input['exceptions'] = exportArrayToDB(array());
        $agentmodule->add($input);
    }
    /*
     * Add INVENTORY module if not present
     */
    $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_agentmodules`\n      WHERE `modulename`='INVENTORY'";
    $result = $DB->query($query);
    if (!$DB->numrows($result)) {
        $agentmodule = new PluginFusioninventoryAgentmodule();
        $input = array();
        $input['modulename'] = "INVENTORY";
        $input['is_active'] = 1;
        $input['exceptions'] = exportArrayToDB(array());
        $agentmodule->add($input);
    }
    /*
     * Table glpi_plugin_fusioninventory_configs
     */
    $newTable = "glpi_plugin_fusioninventory_configs";
    if (TableExists('glpi_plugin_tracker_config')) {
        if (FieldExists('glpi_plugin_tracker_config', 'ssl_only')) {
            $query = "SELECT * FROM `glpi_plugin_tracker_config`\n               LIMIT 1";
            $result = $DB->query($query);
            if ($DB->numrows($result) > 0) {
                $data = $DB->fetch_assoc($result);
                $prepare_Config['ssl_only'] = $data['ssl_only'];
            }
        }
        //         $query = "SELECT *  FROM `glpi_plugin_tracker_config`
        //            WHERE `type`='version'
        //            LIMIT 1, 10";
        //         $result=$DB->query($query);
        //         while ($data=$DB->fetch_array($result)) {
        //            $DB->query("DELETE FROM `glpi_plugin_tracker_config`
        //               WHERE `ID`='".$data['ID']."'");
        //         }
    }
    if (TableExists('glpi_plugin_fusioninventory_configs')) {
        $id = 'id';
        if (FieldExists('glpi_plugin_fusioninventory_configs', 'ID')) {
            $id = 'ID';
        }
        $query = "SELECT *  FROM `glpi_plugin_fusioninventory_configs`\n            WHERE `type`='version'\n            LIMIT 1, 10";
        $result = $DB->query($query);
        while ($data = $DB->fetch_array($result)) {
            $DB->query("DELETE FROM `glpi_plugin_fusioninventory_configs`\n               WHERE `" . $id . "`='" . $data[$id] . "'");
        }
    }
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_configs';
    $a_table['oldname'] = array('glpi_plugin_tracker_config');
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['type'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['value'] = array('type' => 'string', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['oldfields'][] = 'version';
    $a_table['oldfields'][] = 'URL_agent_conf';
    $a_table['oldfields'][] = 'ssl_only';
    $a_table['oldfields'][] = 'authsnmp';
    $a_table['oldfields'][] = 'inventory_frequence';
    $a_table['oldfields'][] = 'criteria1_ip';
    $a_table['oldfields'][] = 'criteria1_name';
    $a_table['oldfields'][] = 'criteria1_serial';
    $a_table['oldfields'][] = 'criteria1_macaddr';
    $a_table['oldfields'][] = 'criteria2_ip';
    $a_table['oldfields'][] = 'criteria2_name';
    $a_table['oldfields'][] = 'criteria2_serial';
    $a_table['oldfields'][] = 'criteria2_macaddr';
    $a_table['oldfields'][] = 'delete_agent_process';
    $a_table['oldfields'][] = 'activation_history';
    $a_table['oldfields'][] = 'activation_connection';
    $a_table['oldfields'][] = 'activation_snmp_computer';
    $a_table['oldfields'][] = 'activation_snmp_networking';
    $a_table['oldfields'][] = 'activation_snmp_peripheral';
    $a_table['oldfields'][] = 'activation_snmp_phone';
    $a_table['oldfields'][] = 'activation_snmp_printer';
    $a_table['oldfields'][] = 'plugins_id';
    $a_table['oldfields'][] = 'module';
    $a_table['renamefields'] = array();
    $a_table['renamefields']['ID'] = 'id';
    $a_table['keys'] = array();
    $a_table['keys'][] = array('field' => array("type"), 'name' => 'unicity', 'type' => 'UNIQUE');
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_entities
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_entities';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['entities_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['transfers_id_auto'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['agent_base_url'] = array('type' => 'string', 'value' => '');
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['keys'][] = array('field' => array('entities_id', 'transfers_id_auto'), 'name' => 'entities_id', 'type' => 'INDEX');
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    if (countElementsInTable($a_table['name']) == 0) {
        $a_configs = getAllDatasFromTable('glpi_plugin_fusioninventory_configs', "`type`='transfers_id_auto'");
        $transfers_id_auto = 0;
        if (count($a_configs) > 0) {
            $a_config = current($a_configs);
            $transfers_id_auto = $a_config['value'];
        }
        $a_configs = getAllDatasFromTable('glpi_plugin_fusioninventory_configs', "`type`='agent_base_url'");
        $agent_base_url = '';
        if (count($a_configs) > 0) {
            $a_config = current($a_configs);
            $agent_base_url = $a_config['value'];
        }
        $DB->query("INSERT INTO `glpi_plugin_fusioninventory_entities`\n               (`entities_id`, `transfers_id_auto`, `agent_base_url`)\n            VALUES ('0', '" . $transfers_id_auto . "', '" . $agent_base_url . "');");
    } else {
        if (countElementsInTable($a_table['name']) > 0) {
            $a_configs = getAllDatasFromTable('glpi_plugin_fusioninventory_configs', "`type`='agent_base_url'");
            $agent_base_url = '';
            if (count($a_configs) > 0) {
                $a_config = current($a_configs);
                $agent_base_url = $a_config['value'];
                $DB->query("UPDATE `glpi_plugin_fusioninventory_entities`\n                  SET `agent_base_url` = '" . $agent_base_url . "'\n                  ;");
            }
        }
    }
    /*
     * Table glpi_plugin_fusioninventory_credentials
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_credentials';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['entities_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['is_recursive'] = array('type' => 'bool', 'value' => NULL);
    $a_table['fields']['name'] = array('type' => 'string', 'value' => "");
    $a_table['fields']['username'] = array('type' => 'string', 'value' => "");
    $a_table['fields']['password'] = array('type' => 'string', 'value' => "");
    $a_table['fields']['comment'] = array('type' => 'text', 'value' => NULL);
    $a_table['fields']['date_mod'] = array('type' => 'datetime', 'value' => NULL);
    $a_table['fields']['itemtype'] = array('type' => 'string', 'value' => "");
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    // Fix itemtype changed in 0.84
    $DB->query("UPDATE `glpi_plugin_fusioninventory_credentials`\n         SET `itemtype`='PluginFusioninventoryInventoryComputerESX'\n         WHERE `itemtype`='PluginFusinvinventoryVmwareESX'");
    /*
     * Table glpi_plugin_fusioninventory_credentialips
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_credentialips';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['entities_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['plugin_fusioninventory_credentials_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['name'] = array('type' => 'string', 'value' => "");
    $a_table['fields']['comment'] = array('type' => 'text', 'value' => NULL);
    $a_table['fields']['ip'] = array('type' => 'string', 'value' => "");
    $a_table['fields']['date_mod'] = array('type' => 'datetime', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_ipranges
     */
    $newTable = "glpi_plugin_fusioninventory_ipranges";
    if (TableExists("glpi_plugin_tracker_rangeip")) {
        // Get all data to create task
        $query = "SELECT * FROM `glpi_plugin_tracker_rangeip`";
        $result = $DB->query($query);
        while ($data = $DB->fetch_array($result)) {
            if ($data['discover'] == '1') {
                $prepare_task[] = array("agents_id" => $data['FK_tracker_agents'], "ipranges_id" => $data['ID'], "netdiscovery" => "1");
            }
            if ($data['query'] == '1') {
                $prepare_task[] = array("agents_id" => $data['FK_tracker_agents'], "ipranges_id" => $data['ID'], "snmpquery" => "1");
            }
        }
    }
    if (TableExists("glpi_plugin_fusioninventory_rangeip") and FieldExists("glpi_plugin_fusioninventory_rangeip", "FK_fusioninventory_agents_discover")) {
        // Get all data to create task
        $query = "SELECT * FROM `glpi_plugin_fusioninventory_rangeip`";
        $result = $DB->query($query);
        while ($data = $DB->fetch_array($result)) {
            if ($data['discover'] == '1') {
                $prepare_task[] = array("agents_id" => $data['FK_fusioninventory_agents_discover'], "ipranges_id" => $data['ID'], "netdiscovery" => "1");
            }
            if ($data['query'] == '1') {
                $prepare_task[] = array("agents_id" => $data['FK_fusioninventory_agents_query'], "ipranges_id" => $data['ID'], "snmpquery" => "1");
            }
        }
    }
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_ipranges';
    $a_table['oldname'] = array('glpi_plugin_tracker_rangeip', 'glpi_plugin_fusinvsnmp_ipranges');
    $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => ''), 'name' => array('type' => 'string', 'value' => NULL), 'entities_id' => array('type' => 'integer', 'value' => NULL), 'ip_start' => array('type' => 'string', 'value' => NULL), 'ip_end' => array('type' => 'string', 'value' => NULL));
    $a_table['oldfields'] = array('FK_tracker_agents', 'discover', 'query', 'FK_fusioninventory_agents_discover', 'FK_fusioninventory_agents_query', 'construct_device_id', 'log', 'comment');
    $a_table['renamefields'] = array('ID' => 'id', 'ifaddr_start' => 'ip_start', 'ifaddr_end' => 'ip_end', 'FK_entities' => 'entities_id');
    $a_table['keys'] = array(array('field' => 'entities_id', 'name' => '', 'type' => 'INDEX'));
    $a_table['oldkeys'] = array('FK_tracker_agents', 'FK_tracker_agents_2');
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_locks
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_locks';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['tablename'] = array('type' => "varchar(64) COLLATE utf8_unicode_ci NOT NULL DEFAULT ''", 'value' => NULL);
    $a_table['fields']['items_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['tablefields'] = array('type' => 'text', 'value' => NULL);
    $a_table['oldfields'] = array('itemtype');
    $a_table['renamefields'] = array();
    $a_table['renamefields']['fields'] = 'tablefields';
    $a_table['keys'] = array();
    $a_table['keys'][] = array('field' => 'tablename', 'name' => '', 'type' => 'INDEX');
    $a_table['keys'][] = array('field' => 'items_id', 'name' => '', 'type' => 'INDEX');
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_ipranges_configsecurities
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_ipranges_configsecurities';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['plugin_fusioninventory_ipranges_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['plugin_fusioninventory_configsecurities_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['rank'] = array('type' => 'integer', 'value' => '1');
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_mappings
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_mappings';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['itemtype'] = array('type' => "varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL", 'value' => NULL);
    $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['table'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['tablefield'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['locale'] = array('type' => "int(4) NOT NULL DEFAULT '0'", 'value' => NULL);
    $a_table['fields']['shortlocale'] = array('type' => 'int(4) DEFAULT NULL', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['keys'][] = array('field' => 'name', 'name' => '', 'type' => 'INDEX');
    $a_table['keys'][] = array('field' => 'itemtype', 'name' => '', 'type' => 'INDEX');
    $a_table['keys'][] = array('field' => 'table', 'name' => '', 'type' => 'INDEX');
    $a_table['keys'][] = array('field' => 'tablefield', 'name' => '', 'type' => 'INDEX');
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    pluginFusioninventoryUpdatemapping();
    if (TableExists('glpi_plugin_fusioninventory_profiles')) {
        /*
         * Table glpi_plugin_fusioninventory_profiles
         */
        $a_table = array();
        $a_table['name'] = 'glpi_plugin_fusioninventory_profiles';
        $a_table['oldname'] = array();
        $a_table['fields'] = array();
        $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
        $a_table['fields']['type'] = array('type' => 'string', 'value' => '');
        $a_table['fields']['right'] = array('type' => 'char', 'value' => NULL);
        $a_table['fields']['plugins_id'] = array('type' => 'integer', 'value' => NULL);
        $a_table['fields']['profiles_id'] = array('type' => 'integer', 'value' => NULL);
        $a_table['oldfields'] = array('name', 'interface', 'is_default', 'snmp_networking', 'snmp_printers', 'snmp_models', 'snmp_authentification', 'rangeip', 'agents', 'remotecontrol', 'agentsprocesses', 'unknowndevices', 'reports', 'deviceinventory', 'netdiscovery', 'snmp_query', 'wol', 'configuration');
        $a_table['renamefields'] = array();
        $a_table['renamefields']['ID'] = 'id';
        $a_table['keys'] = array();
        $a_table['oldkeys'] = array();
        migrateTablesFusionInventory($migration, $a_table);
        // Remove multiple lines can have problem with unicity
        $query = "SELECT * , count(`id`) AS cnt\n               FROM `glpi_plugin_fusioninventory_profiles`\n               GROUP BY `type`,`plugins_id`,`profiles_id`\n               HAVING cnt >1\n               ORDER BY cnt";
        $result = $DB->query($query);
        while ($data = $DB->fetch_array($result)) {
            $queryd = "DELETE FROM `glpi_plugin_fusioninventory_profiles`\n                  WHERE `type`='" . $data['type'] . "'\n                     AND `plugins_id`='" . $data['plugins_id'] . "'\n                     AND `profiles_id`='" . $data['profiles_id'] . "'\n                  ORDER BY `id` DESC\n                  LIMIT " . ($data['cnt'] - 1) . " ";
            $DB->query($queryd);
        }
        $a_table = array();
        $a_table['name'] = 'glpi_plugin_fusioninventory_profiles';
        $a_table['oldname'] = array();
        $a_table['fields'] = array();
        $a_table['oldfields'] = array();
        $a_table['renamefields'] = array();
        $a_table['keys'] = array();
        $a_table['keys'][] = array('field' => array("type", "plugins_id", "profiles_id"), 'name' => 'unicity', 'type' => 'UNIQUE');
        $a_table['oldkeys'] = array();
        migrateTablesFusionInventory($migration, $a_table);
    }
    /*
     * Update tasks related database tables
     */
    pluginFusioninventoryUpdateTasks($migration, $plugins_id);
    /*
     * Table glpi_plugin_fusioninventory_timeslots
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_timeslots';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['entities_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['is_recursive'] = array('type' => 'bool', 'value' => '0');
    $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['comment'] = array('type' => 'text', 'value' => NULL);
    $a_table['fields']['date_mod'] = array('type' => 'datetime', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_timeslotentries
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_timeslotentries';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['plugin_fusioninventory_timeslots_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['entities_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['is_recursive'] = array('type' => 'bool', 'value' => '0');
    $a_table['fields']['day'] = array('type' => 'bool', 'value' => 1);
    $a_table['fields']['begin'] = array('type' => 'int(11) DEFAULT NULL', 'value' => NULL);
    $a_table['fields']['end'] = array('type' => 'int(11) DEFAULT NULL', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_unmanageds
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_unmanageds';
    $a_table['oldname'] = array('glpi_plugin_fusioninventory_unknowndevices', 'glpi_plugin_tracker_unknown_device');
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['date_mod'] = array('type' => 'datetime', 'value' => NULL);
    $a_table['fields']['entities_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['locations_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['is_deleted'] = array('type' => 'bool', 'value' => NULL);
    $a_table['fields']['users_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['serial'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['otherserial'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['contact'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['domain'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['comment'] = array('type' => 'text', 'value' => NULL);
    $a_table['fields']['item_type'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['accepted'] = array('type' => 'bool', 'value' => NULL);
    $a_table['fields']['plugin_fusioninventory_agents_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['ip'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['hub'] = array('type' => 'bool', 'value' => NULL);
    $a_table['fields']['states_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['sysdescr'] = array('type' => 'text', 'value' => NULL);
    $a_table['fields']['plugin_fusioninventory_configsecurities_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['is_dynamic'] = array('type' => 'bool', 'value' => NULL);
    $a_table['fields']['serialized_inventory'] = array('type' => 'longblob', 'value' => NULL);
    $a_table['oldfields'] = array('dnsname', 'snmp', 'FK_model_infos', 'FK_snmp_connection', 'FK_agent', 'mac', 'ifmac', 'plugin_fusinvsnmp_models_id', 'plugin_fusioninventory_snmpmodels_id', 'is_template');
    $a_table['renamefields'] = array('ID' => 'id', 'comments' => 'comment', 'type' => 'item_type', 'ifaddr' => 'ip', 'FK_entities' => 'entities_id', 'location' => 'locations_id', 'deleted' => 'is_deleted', 'plugin_fusinvsnmp_configsecurities_id' => 'plugin_fusioninventory_configsecurities_id');
    $a_table['keys'] = array(array('field' => 'entities_id', 'name' => '', 'type' => 'INDEX'), array('field' => 'plugin_fusioninventory_agents_id', 'name' => '', 'type' => 'INDEX'), array('field' => 'is_deleted', 'name' => '', 'type' => 'INDEX'), array('field' => 'date_mod', 'name' => '', 'type' => 'INDEX'));
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    if (TableExists('glpi_plugin_fusinvsnmp_unknowndevices')) {
        $query = "SELECT * FROM `glpi_plugin_fusinvsnmp_unknowndevices`";
        $result = $DB->query($query);
        while ($data = $DB->fetch_array($result)) {
            $DB->query("UPDATE `glpi_plugin_fusioninventory_unmanageds`\n               SET `sysdescr`='" . $data['sysdescr'] . "',\n                   `plugin_fusioninventory_configsecurities_id`='" . $data['plugin_fusinvsnmp_configsecurities_id'] . "'\n               WHERE `id`='" . $data['plugin_fusioninventory_unknowndevices_id'] . "'");
        }
        $migration->dropTable('glpi_plugin_fusinvsnmp_unknowndevices');
    }
    /*
     * Table glpi_plugin_fusioninventory_ignoredimportdevices
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_ignoredimportdevices';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['date'] = array('type' => 'datetime', 'value' => NULL);
    $a_table['fields']['itemtype'] = array('type' => "varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL", 'value' => NULL);
    $a_table['fields']['entities_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['ip'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['mac'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['rules_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['method'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['serial'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['uuid'] = array('type' => 'string', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_inventorycomputercriterias
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_inventorycomputercriterias';
    $a_table['oldname'] = array('glpi_plugin_fusinvinventory_criterias');
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['comment'] = array('type' => 'text', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['keys'][] = array('field' => 'name', 'name' => '', 'type' => 'INDEX');
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_rulematchedlogs
     */
    $newTable = "glpi_plugin_fusioninventory_rulematchedlogs";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                     `id` int(11) NOT NULL AUTO_INCREMENT,\n                      PRIMARY KEY (`id`)\n                  ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1";
        $DB->query($query);
    }
    $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, "date", "datetime DEFAULT NULL");
    $migration->addField($newTable, "items_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "itemtype", "varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "rules_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "plugin_fusioninventory_agents_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "method", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     * Table glpi_plugin_fusioninventory_inventorycomputerblacklists
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_inventorycomputerblacklists';
    $a_table['oldname'] = array('glpi_plugin_fusinvinventory_blacklists');
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['plugin_fusioninventory_criterium_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['value'] = array('type' => 'string', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['keys'][] = array('field' => 'plugin_fusioninventory_criterium_id', 'name' => '', 'type' => 'KEY');
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    $DB->list_fields($newTable, FALSE);
    pluginFusioninventorychangeDisplayPreference("5153", "PluginFusioninventoryUnknownDevice");
    pluginFusioninventorychangeDisplayPreference("5158", "PluginFusioninventoryAgent");
    /*
     *  Udpate criteria for blacklist
     */
    $a_criteria = array();
    $a_criteria['Serial number'] = 'ssn';
    $a_criteria['uuid'] = 'uuid';
    $a_criteria['Mac address'] = 'macAddress';
    $a_criteria['Windows product key'] = 'winProdKey';
    $a_criteria['Model'] = 'smodel';
    $a_criteria['storage serial'] = 'storagesSerial';
    $a_criteria['drives serial'] = 'drivesSerial';
    $a_criteria['Asset Tag'] = 'assetTag';
    $a_criteria['Computer name'] = 'name';
    $a_criteria['Manufacturer'] = 'manufacturer';
    foreach ($a_criteria as $name => $comment) {
        $query = "SELECT * FROM `glpi_plugin_fusioninventory_inventorycomputercriterias`\n            WHERE `name`='" . $name . "'";
        $result = $DB->query($query);
        if ($DB->numrows($result) == '0') {
            $query_ins = "INSERT INTO `glpi_plugin_fusioninventory_inventorycomputercriterias`\n               (`name`, `comment`)\n               VALUES ('" . $name . "', '" . $comment . "')";
            $DB->query($query_ins);
        }
    }
    $a_criteria = array();
    $query = "SELECT * FROM `glpi_plugin_fusioninventory_inventorycomputercriterias`";
    $result = $DB->query($query);
    while ($data = $DB->fetch_array($result)) {
        $a_criteria[$data['comment']] = $data['id'];
    }
    /*
     * Update blacklist
     */
    $newTable = "glpi_plugin_fusioninventory_inventorycomputerblacklists";
    // * ssn
    $a_input = array('N/A', '(null string)', 'INVALID', 'SYS-1234567890', 'SYS-9876543210', 'SN-12345', 'SN-1234567890', '1111111111', '1111111', '1', '0123456789', '12345', '123456', '1234567', '12345678', '123456789', '1234567890', '123456789000', '12345678901234567', '0000000000', '000000000', '00000000', '0000000', '0000000', 'NNNNNNN', 'xxxxxxxxxxx', 'EVAL', 'IATPASS', 'none', 'To Be Filled By O.E.M.', 'Tulip Computers', 'Serial Number xxxxxx', 'SN-123456fvgv3i0b8o5n6n7k', 'Unknow', 'System Serial Number', 'MB-1234567890', '0', 'empty', 'Not Specified');
    foreach ($a_input as $value) {
        $query = "SELECT * FROM `" . $newTable . "`\n               WHERE `plugin_fusioninventory_criterium_id`='" . $a_criteria['ssn'] . "'\n                AND `value`='" . $value . "'";
        $result = $DB->query($query);
        if ($DB->numrows($result) == '0') {
            $query = "INSERT INTO `" . $newTable . "`\n                     (`plugin_fusioninventory_criterium_id`, `value`)\n                  VALUES ( '" . $a_criteria['ssn'] . "', '" . $value . "')";
            $DB->query($query);
        }
    }
    // * uuid
    $a_input = array('FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF', '03000200-0400-0500-0006-000700080009', '6AB5B300-538D-1014-9FB5-B0684D007B53', '01010101-0101-0101-0101-010101010101');
    foreach ($a_input as $value) {
        $query = "SELECT * FROM `" . $newTable . "`\n               WHERE `plugin_fusioninventory_criterium_id`='" . $a_criteria['uuid'] . "'\n                AND `value`='" . $value . "'";
        $result = $DB->query($query);
        if ($DB->numrows($result) == '0') {
            $query = "INSERT INTO `" . $newTable . "`\n                     (`plugin_fusioninventory_criterium_id`, `value`)\n                  VALUES ( '" . $a_criteria['uuid'] . "', '" . $value . "')";
            $DB->query($query);
        }
    }
    // * macAddress
    $a_input = array('20:41:53:59:4e:ff', '02:00:4e:43:50:49', 'e2:e6:16:20:0a:35', 'd2:0a:2d:a0:04:be', '00:a0:c6:00:00:00', 'd2:6b:25:2f:2c:e7', '33:50:6f:45:30:30', '0a:00:27:00:00:00', '00:50:56:C0:00:01', '00:50:56:C0:00:08', '02:80:37:EC:02:00', '50:50:54:50:30:30', '24:b6:20:52:41:53');
    foreach ($a_input as $value) {
        $query = "SELECT * FROM `" . $newTable . "`\n               WHERE `plugin_fusioninventory_criterium_id`='" . $a_criteria['macAddress'] . "'\n                AND `value`='" . $value . "'";
        $result = $DB->query($query);
        if ($DB->numrows($result) == '0') {
            $query = "INSERT INTO `" . $newTable . "`\n                     (`plugin_fusioninventory_criterium_id`, `value`)\n                  VALUES ( '" . $a_criteria['macAddress'] . "', '" . $value . "')";
            $DB->query($query);
        }
    }
    // * smodel
    $a_input = array('Unknow', 'To Be Filled By O.E.M.', '*', 'System Product Name', 'Product Name', 'System Name');
    foreach ($a_input as $value) {
        $query = "SELECT * FROM `" . $newTable . "`\n               WHERE `plugin_fusioninventory_criterium_id`='" . $a_criteria['smodel'] . "'\n                AND `value`='" . $value . "'";
        $result = $DB->query($query);
        if ($DB->numrows($result) == '0') {
            $query = "INSERT INTO `" . $newTable . "`\n                     (`plugin_fusioninventory_criterium_id`, `value`)\n                  VALUES ( '" . $a_criteria['smodel'] . "', '" . $value . "')";
            $DB->query($query);
        }
    }
    // * manufacturer
    $a_input = array('System manufacturer');
    foreach ($a_input as $value) {
        $query = "SELECT * FROM `" . $newTable . "`\n               WHERE `plugin_fusioninventory_criterium_id`='" . $a_criteria['manufacturer'] . "'\n                AND `value`='" . $value . "'";
        $result = $DB->query($query);
        if ($DB->numrows($result) == '0') {
            $query = "INSERT INTO `" . $newTable . "`\n                     (`plugin_fusioninventory_criterium_id`, `value`)\n                  VALUES ( '" . $a_criteria['manufacturer'] . "', '" . $value . "')";
            $DB->query($query);
        }
    }
    // * ip
    $query = "SELECT * FROM `glpi_plugin_fusioninventory_inventorycomputercriterias`\n            WHERE `name`='IP'";
    $result = $DB->query($query);
    if ($DB->numrows($result) == 0) {
        $DB->query("INSERT INTO `glpi_plugin_fusioninventory_inventorycomputercriterias`\n               (`id`, `name`, `comment`) VALUES\n               (11, 'IP', 'IP')");
    }
    $a_criteria = array();
    $query = "SELECT * FROM `glpi_plugin_fusioninventory_inventorycomputercriterias`";
    $result = $DB->query($query);
    while ($data = $DB->fetch_array($result)) {
        $a_criteria[$data['comment']] = $data['id'];
    }
    $a_input = array('0.0.0.0');
    foreach ($a_input as $value) {
        $query = "SELECT * FROM `" . $newTable . "`\n               WHERE `plugin_fusioninventory_criterium_id`='" . $a_criteria['IP'] . "'\n                AND `value`='" . $value . "'";
        $result = $DB->query($query);
        if ($DB->numrows($result) == '0') {
            $query = "INSERT INTO `" . $newTable . "`\n                     (`plugin_fusioninventory_criterium_id`, `value`)\n                  VALUES ( '" . $a_criteria['IP'] . "', '" . $value . "')";
            $DB->query($query);
        }
    }
    /*
     * Table glpi_plugin_fusioninventory_inventorycomputerantiviruses
     */
    $newTable = "glpi_plugin_fusioninventory_inventorycomputerantiviruses";
    $migration->renameTable("glpi_plugin_fusinvinventory_antivirus", $newTable);
    if (!TableExists($newTable)) {
        $DB->query("CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                   ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1");
    }
    $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, "computers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "name", "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, "manufacturers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "version", "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, "is_active", "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "uptodate", "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addKey($newTable, "name");
    $migration->addKey($newTable, "version");
    $migration->addKey($newTable, "is_active");
    $migration->addKey($newTable, "uptodate");
    $migration->addKey($newTable, "computers_id");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     * Table glpi_plugin_fusioninventory_inventorycomputerbatteries
     */
    $newTable = "glpi_plugin_fusioninventory_inventorycomputerbatteries";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                     `id` int(11) NOT NULL AUTO_INCREMENT,\n                      PRIMARY KEY (`id`)\n                  ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1";
        $DB->query($query);
    }
    $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "computers_id", "computers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "name", "name", "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, "manufacturers_id", "manufacturers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "serial", "serial", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "capacity", "capacity", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "date", "date", "datetime DEFAULT NULL");
    $migration->changeField($newTable, "plugin_fusioninventory_inventorycomputerchemistries_id", "plugin_fusioninventory_inventorycomputerchemistries_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "voltage", "voltage", "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, "computers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "name", "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, "manufacturers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "serial", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "capacity", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "date", "datetime DEFAULT NULL");
    $migration->addField($newTable, "plugin_fusioninventory_inventorycomputerchemistries_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "voltage", "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addKey($newTable, "computers_id");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     * Table glpi_plugin_fusioninventory_inventorycomputerchemistries
     */
    $newTable = "glpi_plugin_fusioninventory_inventorycomputerchemistries";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                     `id` int(11) NOT NULL AUTO_INCREMENT,\n                      PRIMARY KEY (`id`)\n                  ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1";
        $DB->query($query);
    }
    $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "name", "name", "varchar(255) DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, "name", "varchar(255) DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->addKey($newTable, "name");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     * Table glpi_plugin_fusioninventory_inventorycomputercomputers
     */
    if (TableExists("glpi_plugin_fusinvinventory_computers") and FieldExists("glpi_plugin_fusinvinventory_computers", "uuid")) {
        $Computer = new Computer();
        $sql = "SELECT * FROM `glpi_plugin_fusinvinventory_computers`";
        $result = $DB->query($sql);
        while ($data = $DB->fetch_array($result)) {
            if ($Computer->getFromDB($data['items_id'])) {
                $input = array();
                $input['id'] = $data['items_id'];
                $input['uuid'] = $data['uuid'];
                $Computer->update($input);
            }
        }
        $sql = "DROP TABLE `glpi_plugin_fusinvinventory_computers`";
        $DB->query($sql);
    }
    if (TableExists("glpi_plugin_fusinvinventory_tmp_agents")) {
        $sql = "DROP TABLE `glpi_plugin_fusinvinventory_tmp_agents`";
        $DB->query($sql);
    }
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_inventorycomputercomputers';
    $a_table['oldname'] = array('glpi_plugin_fusinvinventory_computers');
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['computers_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['bios_date'] = array('type' => 'datetime', 'value' => NULL);
    $a_table['fields']['bios_version'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['bios_assettag'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['bios_manufacturers_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['operatingsystem_installationdate'] = array('type' => 'datetime', 'value' => NULL);
    $a_table['fields']['winowner'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['wincompany'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['last_fusioninventory_update'] = array('type' => 'datetime', 'value' => NULL);
    $a_table['fields']['remote_addr'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['plugin_fusioninventory_computerarchs_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['serialized_inventory'] = array('type' => 'longblob', 'value' => "");
    $a_table['fields']['is_entitylocked'] = array('type' => 'bool', 'value' => "0");
    $a_table['fields']['oscomment'] = array('type' => 'text', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['keys'][] = array('field' => 'computers_id', 'name' => '', 'type' => 'INDEX');
    $a_table['keys'][] = array('field' => 'last_fusioninventory_update', 'name' => '', 'type' => 'INDEX');
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    // Migrate libserialization
    require_once GLPI_ROOT . "/plugins/fusioninventory/inc/inventorycomputercomputer.class.php";
    $pfInventoryComputerComputer = new PluginFusioninventoryInventoryComputerComputer();
    if (TableExists('glpi_plugin_fusinvinventory_libserialization')) {
        $query = "SELECT * FROM `glpi_plugin_fusinvinventory_libserialization`";
        $result = $DB->query($query);
        while ($data = $DB->fetch_array($result)) {
            $a_pfcomputer = array();
            $a_pfcomputer = current($pfInventoryComputerComputer->find("`computers_id`='" . $data['computers_id'] . "'", "", 1));
            if (empty($a_pfcomputer)) {
                // Add
                if (countElementsInTable("glpi_computers", "`id`='" . $data['computers_id'] . "'") > 0) {
                    $input = array();
                    $input['computers_id'] = $data['computers_id'];
                    $input['last_fusioninventory_update'] = $data['last_fusioninventory_update'];
                    $pfInventoryComputerComputer->add($input);
                }
            } else {
                // Update
                $a_pfcomputer['last_fusioninventory_update'] = $data['last_fusioninventory_update'];
                $pfInventoryComputerComputer->update($a_pfcomputer);
            }
        }
    }
    $migration->dropTable('glpi_plugin_fusinvinventory_libserialization');
    /*
     * Table glpi_plugin_fusioninventory_inventorycomputerstats
     */
    if (!TableExists("glpi_plugin_fusioninventory_inventorycomputerstats")) {
        $a_table = array();
        $a_table['name'] = 'glpi_plugin_fusioninventory_inventorycomputerstats';
        $a_table['oldname'] = array();
        $a_table['fields'] = array();
        $a_table['fields']['id'] = array('type' => "smallint(3) NOT NULL AUTO_INCREMENT", 'value' => '');
        $a_table['fields']['day'] = array('type' => "smallint(3) NOT NULL DEFAULT '0'", 'value' => '');
        $a_table['fields']['hour'] = array('type' => "tinyint(2) NOT NULL DEFAULT '0'", 'value' => '');
        $a_table['fields']['counter'] = array('type' => 'integer', 'value' => NULL);
        $a_table['oldfields'] = array();
        $a_table['renamefields'] = array();
        $a_table['keys'] = array();
        $a_table['oldkeys'] = array();
        migrateTablesFusionInventory($migration, $a_table);
        require_once GLPI_ROOT . "/plugins/fusioninventory/inc/inventorycomputerstat.class.php";
        PluginFusioninventoryInventoryComputerStat::init();
    }
    /*
     * Table glpi_plugin_fusioninventory_inventorycomputerstorages
     */
    $newTable = "glpi_plugin_fusioninventory_inventorycomputerstorages";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                     `id` int(11) NOT NULL AUTO_INCREMENT,\n                      PRIMARY KEY (`id`)\n                  ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1";
        $DB->query($query);
    }
    $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "name", "name", "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, "uuid", "uuid", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "totalsize", "totalsize", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "freesize", "freesize", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "plugin_fusioninventory_inventorycomputerstoragetypes_id", "plugin_fusioninventory_inventorycomputerstoragetypes_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "computers_id", "computers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, "name", "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, "uuid", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "totalsize", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "freesize", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "plugin_fusioninventory_inventorycomputerstoragetypes_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "computers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addKey($newTable, "uuid");
    $migration->addKey($newTable, "computers_id");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     * Table glpi_plugin_fusioninventory_inventorycomputerstoragetypes
     */
    $newTable = "glpi_plugin_fusioninventory_inventorycomputerstoragetypes";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                     `id` int(11) NOT NULL AUTO_INCREMENT,\n                      PRIMARY KEY (`id`)\n                  ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1";
        $DB->query($query);
    }
    $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "name", "name", "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, "level", "level", "tinyint(2) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, "name", "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, "level", "tinyint(2) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addKey($newTable, "level");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     * Table glpi_plugin_fusioninventory_inventorycomputerstorages_storages
     */
    $newTable = "glpi_plugin_fusioninventory_inventorycomputerstorages_storages";
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                     `id` int(11) NOT NULL AUTO_INCREMENT,\n                      PRIMARY KEY (`id`)\n                  ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1";
        $DB->query($query);
    }
    $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "plugin_fusioninventory_inventorycomputerstorages_id_1", "plugin_fusioninventory_inventorycomputerstorages_id_1", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "plugin_fusioninventory_inventorycomputerstorages_id_2", "plugin_fusioninventory_inventorycomputerstorages_id_2", "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, "plugin_fusioninventory_inventorycomputerstorages_id_1", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "plugin_fusioninventory_inventorycomputerstorages_id_2", "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addKey($newTable, "plugin_fusioninventory_inventorycomputerstorages_id_1");
    $migration->addKey($newTable, "plugin_fusioninventory_inventorycomputerstorages_id_2");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     * glpi_plugin_fusioninventory_configlogfields
     */
    $newTable = "glpi_plugin_fusioninventory_configlogfields";
    $migration->renameTable("glpi_plugin_fusioninventory_config_snmp_history", $newTable);
    $migration->renameTable("glpi_plugin_fusinvsnmp_configlogfields", $newTable);
    if (TableExists($newTable)) {
        if (FieldExists($newTable, "field")) {
            $query = "SELECT * FROM `" . $newTable . "`";
            $result = $DB->query($query);
            while ($data = $DB->fetch_array($result)) {
                $pfMapping = new PluginFusioninventoryMapping();
                $mapping = 0;
                if ($mapping = $pfMapping->get("NetworkEquipment", $data['field'])) {
                    $queryu = "UPDATE `" . $newTable . "`\n                     SET `field`='" . $mapping['id'] . "'\n                     WHERE `field`='" . $data['field'] . "'";
                    $DB->query($queryu);
                }
            }
        }
    }
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                     `id` int(8) NOT NULL AUTO_INCREMENT,\n                      PRIMARY KEY (`id`)\n                  ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1";
        $DB->query($query);
    }
    $migration->changeField($newTable, "ID", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "id", "id", "int(8) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "plugin_fusioninventory_mappings_id", "plugin_fusioninventory_mappings_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "days", "days", "int(255) NOT NULL DEFAULT '-1'");
    $migration->migrationOneTable($newTable);
    $migration->changeField($newTable, "ID", "id", "int(8) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "field", "plugin_fusioninventory_mappings_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, "id", "int(8) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, "plugin_fusioninventory_mappings_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "days", "int(255) NOT NULL DEFAULT '-1'");
    $migration->addKey($newTable, "plugin_fusioninventory_mappings_id");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    $configLogField = new PluginFusioninventoryConfigLogField();
    $configLogField->initConfig();
    /*
     * Table glpi_plugin_fusioninventory_networkportconnectionlogs
     */
    $newTable = "glpi_plugin_fusioninventory_networkportconnectionlogs";
    $migration->renameTable("glpi_plugin_fusinvsnmp_networkportconnectionlogs", $newTable);
    if (!TableExists($newTable)) {
        $DB->query('CREATE TABLE `' . $newTable . '` (
                        `id` int(11) NOT NULL AUTO_INCREMENT,
                        PRIMARY KEY (`id`)
                   ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1');
    }
    $migration->changeField($newTable, "ID", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "date", "date_mod", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'");
    $migration->changeField($newTable, "date_mod", "date_mod", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'");
    $migration->changeField($newTable, "creation", "creation", "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "FK_port_source", "networkports_id_source", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "networkports_id_source", "networkports_id_source", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "FK_port_destination", "networkports_id_destination", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "networkports_id_destination", "networkports_id_destination", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "plugin_fusioninventory_agentprocesses_id", "plugin_fusioninventory_agentprocesses_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->dropField($newTable, "process_number");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, "date_mod", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'");
    $migration->addField($newTable, "creation", "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "networkports_id_source", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "networkports_id_destination", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "plugin_fusioninventory_agentprocesses_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addKey($newTable, array("networkports_id_source", "networkports_id_destination", "plugin_fusioninventory_agentprocesses_id"), "networkports_id_source");
    $migration->addKey($newTable, "date_mod");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     * Table glpi_plugin_fusioninventory_networkporttypes
     */
    $newTable = "glpi_plugin_fusioninventory_networkporttypes";
    $migration->renameTable("glpi_plugin_fusinvsnmp_networkporttypes", $newTable);
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                     `id` int(11) NOT NULL AUTO_INCREMENT,\n                      PRIMARY KEY (`id`)\n                  ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1";
        $DB->query($query);
    }
    $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "name", "name", "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, "number", "number", "int(4) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "othername", "othername", "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, "import", "import", "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, "name", "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, "number", "int(4) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "othername", "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, "import", "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     * Table glpi_plugin_fusioninventory_printers
     */
    $newTable = "glpi_plugin_fusioninventory_printers";
    $migration->renameTable("glpi_plugin_fusinvsnmp_printers", $newTable);
    $migration->renameTable("glpi_plugin_tracker_printers", $newTable);
    if (!TableExists($newTable)) {
        $DB->query('CREATE TABLE `' . $newTable . '` (
                        `id` int(11) NOT NULL AUTO_INCREMENT,
                        PRIMARY KEY (`id`)
                   ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1');
    }
    $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "printers_id", "printers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "sysdescr", "sysdescr", "text COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "plugin_fusinvsnmp_configsecurities_id", "plugin_fusioninventory_configsecurities_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "plugin_fusioninventory_configsecurities_id", "plugin_fusioninventory_configsecurities_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "frequence_days", "frequence_days", "int(5) NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, "last_fusioninventory_update", "last_fusioninventory_update", "datetime DEFAULT NULL");
    $migration->migrationOneTable($newTable);
    $migration->changeField($newTable, "ID", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "FK_printers", "printers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "FK_snmp_connection", "plugin_fusioninventory_configsecurities_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "last_tracker_update", "last_fusioninventory_update", "datetime DEFAULT NULL");
    $migration->dropKey($newTable, "FK_printers");
    $migration->dropKey($newTable, "FK_snmp_connection");
    $migration->dropKey($newTable, "plugin_fusioninventory_snmpmodels_id");
    $migration->migrationOneTable($newTable);
    $migration->dropField($newTable, "plugin_fusinvsnmp_models_id");
    $migration->dropField($newTable, "plugin_fusioninventory_snmpmodels_id");
    $migration->dropField($newTable, "FK_model_infos");
    $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, "printers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "sysdescr", "text COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "plugin_fusioninventory_configsecurities_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "frequence_days", "int(5) NOT NULL DEFAULT '1'");
    $migration->addField($newTable, "last_fusioninventory_update", "datetime DEFAULT NULL");
    $migration->addField($newTable, "serialized_inventory", "longblob");
    $migration->addKey($newTable, "plugin_fusioninventory_configsecurities_id");
    $migration->addKey($newTable, "printers_id");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     * Table glpi_plugin_fusioninventory_printerlogs
     */
    $newTable = "glpi_plugin_fusioninventory_printerlogs";
    $migration->renameTable("glpi_plugin_fusinvsnmp_printerlogs", $newTable);
    $migration->renameTable("glpi_plugin_tracker_printers_history", $newTable);
    if (!TableExists($newTable)) {
        $DB->query('CREATE TABLE `' . $newTable . '` (
                        `id` int(11) NOT NULL AUTO_INCREMENT,
                        PRIMARY KEY (`id`)
                   ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1');
    }
    $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "printers_id", "printers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "date", "date", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'");
    $migration->changeField($newTable, "pages_total", "pages_total", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "pages_n_b", "pages_n_b", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "pages_color", "pages_color", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "pages_recto_verso", "pages_recto_verso", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "scanned", "scanned", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "pages_total_print", "pages_total_print", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "pages_n_b_print", "pages_n_b_print", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "pages_color_print", "pages_color_print", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "pages_total_copy", "pages_total_copy", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "pages_n_b_copy", "pages_n_b_copy", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "pages_color_copy", "pages_color_copy", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "pages_total_fax", "pages_total_fax", "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->changeField($newTable, "ID", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "FK_printers", "printers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, "printers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "date", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'");
    $migration->addField($newTable, "pages_total", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "pages_n_b", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "pages_color", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "pages_recto_verso", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "scanned", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "pages_total_print", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "pages_n_b_print", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "pages_color_print", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "pages_total_copy", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "pages_n_b_copy", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "pages_color_copy", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "pages_total_fax", "int(11) NOT NULL DEFAULT '0'");
    $migration->addKey($newTable, array("printers_id", "date"), "printers_id");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     *  glpi_plugin_fusioninventory_printercartridges
     */
    $newTable = "glpi_plugin_fusioninventory_printercartridges";
    $migration->renameTable("glpi_plugin_fusinvsnmp_printercartridges", $newTable);
    $migration->renameTable("glpi_plugin_tracker_printers_cartridges", $newTable);
    if (!TableExists($newTable)) {
        $DB->query('CREATE TABLE `' . $newTable . '` (
                        `id` bigint(100) NOT NULL AUTO_INCREMENT,
                        PRIMARY KEY (`id`)
                   ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1');
    }
    $migration->changeField($newTable, "id", "id", "bigint(100) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "printers_id", "printers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "plugin_fusioninventory_mappings_id", "plugin_fusioninventory_mappings_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "cartridges_id", "cartridges_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "state", "state", "int(3) NOT NULL DEFAULT '100'");
    $migration->migrationOneTable($newTable);
    $migration->changeField($newTable, "ID", "id", "bigint(100) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "FK_printers", "printers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "FK_cartridges", "cartridges_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "plugin_fusioninventory_mappings_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    // Update with mapping
    if (FieldExists($newTable, "object_name")) {
        $query = "SELECT * FROM `" . $newTable . "`\n               GROUP BY `object_name`";
        $result = $DB->query($query);
        while ($data = $DB->fetch_array($result)) {
            $pfMapping = new PluginFusioninventoryMapping();
            $mapping = 0;
            if ($mapping = $pfMapping->get("Printer", $data['object_name'])) {
                $DB->query("UPDATE `" . $newTable . "`\n                     SET `plugin_fusioninventory_mappings_id`='" . $mapping['id'] . "'\n                        WHERE `object_name`='" . $data['object_name'] . "'");
            }
        }
    }
    $migration->dropField($newTable, "object_name");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, "id", "bigint(100) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, "printers_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "plugin_fusioninventory_mappings_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "cartridges_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "state", "int(3) NOT NULL DEFAULT '100'");
    $migration->addKey($newTable, "printers_id");
    $migration->addKey($newTable, "plugin_fusioninventory_mappings_id");
    $migration->addKey($newTable, "cartridges_id");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     * glpi_plugin_fusioninventory_networkports
     */
    $newTable = "glpi_plugin_fusioninventory_networkports";
    $migration->renameTable("glpi_plugin_fusinvsnmp_networkports", $newTable);
    $migration->renameTable("glpi_plugin_tracker_networking_ports", $newTable);
    if (!TableExists($newTable)) {
        $DB->query('CREATE TABLE `' . $newTable . '` (
                        `id` int(11) NOT NULL AUTO_INCREMENT,
                        PRIMARY KEY (`id`)
                   ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1');
    }
    $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "networkports_id", "networkports_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "ifmtu", "ifmtu", "int(8) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "ifspeed", "ifspeed", "bigint(50) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "ifinternalstatus", "ifinternalstatus", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "ifconnectionstatus", "ifconnectionstatus", "int(8) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "iflastchange", "iflastchange", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "ifinoctets", "ifinoctets", "bigint(50) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "ifinerrors", "ifinerrors", "bigint(50) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "ifoutoctets", "ifoutoctets", "bigint(50) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "ifouterrors", "ifouterrors", "bigint(50) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "ifstatus", "ifstatus", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "mac", "mac", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "ifdescr", "ifdescr", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "portduplex", "portduplex", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "trunk", "trunk", "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "lastup", "lastup", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'");
    $migration->migrationOneTable($newTable);
    $migration->changeField($newTable, "ID", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "FK_networking_ports", "networkports_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "ifmac", "mac", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->dropKey($newTable, "FK_networking_ports");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, "networkports_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "ifmtu", "int(8) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "ifspeed", "bigint(50) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "ifinternalstatus", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "ifconnectionstatus", "int(8) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "iflastchange", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "ifinoctets", "bigint(50) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "ifinerrors", "bigint(50) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "ifoutoctets", "bigint(50) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "ifouterrors", "bigint(50) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "ifstatus", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "mac", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "ifdescr", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "ifalias", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "portduplex", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "trunk", "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "lastup", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'");
    $migration->addKey($newTable, "networkports_id");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     * Table glpi_plugin_fusioninventory_networkequipments
     */
    $newTable = "glpi_plugin_fusioninventory_networkequipments";
    $migration->renameTable("glpi_plugin_fusinvsnmp_networkequipments", $newTable);
    $migration->renameTable("glpi_plugin_tracker_networking", $newTable);
    if (!TableExists($newTable)) {
        $DB->query('CREATE TABLE `' . $newTable . '` (
                        `id` int(11) NOT NULL AUTO_INCREMENT,
                        PRIMARY KEY (`id`)
                   ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1');
    }
    $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "networkequipments_id", "networkequipments_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "sysdescr", "sysdescr", "text COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "plugin_fusioninventory_configsecurities_id", "plugin_fusioninventory_configsecurities_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "uptime", "uptime", "varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "cpu", "cpu", "int(3) NOT NULL DEFAULT '0' COMMENT '%'");
    $migration->changeField($newTable, "memory", "memory", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "last_fusioninventory_update", "last_fusioninventory_update", "datetime DEFAULT NULL");
    $migration->changeField($newTable, "last_PID_update", "last_PID_update", "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->changeField($newTable, "ID", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "FK_networking", "networkequipments_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "FK_snmp_connection", "plugin_fusioninventory_configsecurities_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "last_tracker_update", "last_fusioninventory_update", "datetime DEFAULT NULL");
    $migration->changeField($newTable, "plugin_fusinvsnmp_configsecurities_id", "plugin_fusioninventory_configsecurities_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->dropKey($newTable, "FK_networking");
    $migration->dropKey($newTable, "FK_model_infos");
    $migration->dropKey($newTable, "plugin_fusioninventory_snmpmodels_id");
    $migration->migrationOneTable($newTable);
    $migration->dropField($newTable, "plugin_fusioninventory_snmpmodels_id");
    $migration->dropField($newTable, "plugin_fusinvsnmp_models_id");
    $migration->dropField($newTable, "FK_model_infos");
    $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, "networkequipments_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "sysdescr", "text COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "plugin_fusioninventory_configsecurities_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "uptime", "varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "cpu", "int(3) NOT NULL DEFAULT '0' COMMENT '%'");
    $migration->addField($newTable, "memory", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "last_fusioninventory_update", "datetime DEFAULT NULL");
    $migration->addField($newTable, "last_PID_update", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "serialized_inventory", "longblob");
    $migration->addKey($newTable, "networkequipments_id");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     * glpi_plugin_fusioninventory_networkequipmentips
     * Removed in 0.84, but required here for update, we drop in edn of this function
     */
    if (TableExists("glpi_plugin_fusioninventory_networkequipmentips") || TableExists("glpi_plugin_fusinvsnmp_networkequipmentips") || TableExists("glpi_plugin_tracker_networking_ifaddr")) {
        $newTable = "glpi_plugin_fusioninventory_networkequipmentips";
        $migration->renameTable("glpi_plugin_fusinvsnmp_networkequipmentips", $newTable);
        $migration->renameTable("glpi_plugin_tracker_networking_ifaddr", $newTable);
        if (!TableExists($newTable)) {
            $DB->query('CREATE TABLE `' . $newTable . '` (
                        `id` int(11) NOT NULL AUTO_INCREMENT,
                        PRIMARY KEY (`id`)
                   ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1');
        }
        $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT");
        $migration->changeField($newTable, "networkequipments_id", "networkequipments_id", "int(11) NOT NULL DEFAULT '0'");
        $migration->changeField($newTable, "ip", "ip", "varchar(255) DEFAULT NULL");
        $migration->migrationOneTable($newTable);
        $migration->changeField($newTable, "ID", "id", "int(11) NOT NULL AUTO_INCREMENT");
        $migration->changeField($newTable, "FK_networking", "networkequipments_id", "int(11) NOT NULL DEFAULT '0'");
        $migration->changeField($newTable, "ifaddr", "ip", "varchar(255) DEFAULT NULL");
        $migration->dropKey($newTable, "ifaddr");
        $migration->migrationOneTable($newTable);
        $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT");
        $migration->addField($newTable, "networkequipments_id", "int(11) NOT NULL DEFAULT '0'");
        $migration->addField($newTable, "ip", "varchar(255) DEFAULT NULL");
        $migration->addKey($newTable, "ip");
        $migration->addKey($newTable, "networkequipments_id");
        $migration->migrationOneTable($newTable);
        $DB->list_fields($newTable, FALSE);
    }
    /*
     * Table glpi_plugin_fusioninventory_networkportlogs
     */
    $newTable = "glpi_plugin_fusioninventory_networkportlogs";
    if (TableExists("glpi_plugin_tracker_snmp_history")) {
        // **** Update history
        update213to220_ConvertField($migration);
        // **** Migration network history connections
        $query = "SELECT count(ID) FROM `glpi_plugin_tracker_snmp_history`\n                              WHERE `Field`='0'";
        $result = $DB->query($query);
        $datas = $DB->fetch_assoc($result);
        $nb = $datas['count(ID)'];
        //echo "Move Connections history to another table...";
        for ($i = 0; $i < $nb; $i = $i + 500) {
            $migration->displayMessage("{$i} / {$nb}");
            $sql_connection = "SELECT * FROM `glpi_plugin_tracker_snmp_history`\n                                 WHERE `Field`='0'\n                                 ORDER BY `FK_process` DESC, `date_mod` DESC\n                                 LIMIT 500";
            $result_connection = $DB->query($sql_connection);
            while ($thread_connection = $DB->fetch_array($result_connection)) {
                $input = array();
                $input['process_number'] = $thread_connection['FK_process'];
                $input['date'] = $thread_connection['date_mod'];
                if ($thread_connection["old_device_ID"] != "0" or $thread_connection["new_device_ID"] != "0") {
                    if ($thread_connection["old_device_ID"] != "0") {
                        // disconnection
                        $input['creation'] = '0';
                    } else {
                        if ($thread_connection["new_device_ID"] != "0") {
                            // connection
                            $input['creation'] = '1';
                        }
                    }
                    $input['FK_port_source'] = $thread_connection["FK_ports"];
                    $dataPort = array();
                    if ($thread_connection["old_device_ID"] != "0") {
                        $queryPort = "SELECT *\n                                      FROM `glpi_networkports`\n                                      WHERE `mac`='" . $thread_connection['old_value'] . "'\n                                      LIMIT 1";
                        $resultPort = $DB->query($queryPort);
                        $dataPort = $DB->fetch_assoc($resultPort);
                    } else {
                        if ($thread_connection["new_device_ID"] != "0") {
                            $queryPort = "SELECT *\n                                      FROM `glpi_networkports`\n                                      WHERE `mac`='" . $thread_connection['new_value'] . "'\n                                      LIMIT 1";
                            $resultPort = $DB->query($queryPort);
                            $dataPort = $DB->fetch_assoc($resultPort);
                        }
                    }
                    if (isset($dataPort['id'])) {
                        $input['FK_port_destination'] = $dataPort['id'];
                    } else {
                        $input['FK_port_destination'] = 0;
                    }
                    $query_ins = "INSERT INTO `glpi_plugin_fusinvsnmp_networkportconnectionlogs`\n                        (`date_mod`, `creation`, `networkports_id_source`,\n                         `networkports_id_destination`)\n                        VALUES ('" . $input['date'] . "',\n                                '" . $input['creation'] . "',\n                                '" . $input['FK_port_source'] . "',\n                                '" . $input['FK_port_destination'] . "')";
                    $DB->query($query_ins);
                }
            }
        }
        $query_del = "DELETE FROM `glpi_plugin_tracker_snmp_history`\n               WHERE `Field`='0'\n               AND (`old_device_ID`!='0' OR `new_device_ID`!='0')";
        $DB->query($query_del);
        $migration->displayMessage("{$nb} / {$nb}");
    }
    $migration->renameTable("glpi_plugin_fusinvsnmp_networkportlogs", $newTable);
    $migration->renameTable("glpi_plugin_tracker_snmp_history", $newTable);
    if (!TableExists($newTable)) {
        $query = "CREATE TABLE `" . $newTable . "` (\n                     `id` int(11) NOT NULL AUTO_INCREMENT,\n                      PRIMARY KEY (`id`)\n                  ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1";
        $DB->query($query);
    }
    $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "networkports_id", "networkports_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "plugin_fusioninventory_mappings_id", "plugin_fusioninventory_mappings_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "date_mod", "date_mod", "datetime DEFAULT NULL");
    $migration->changeField($newTable, "value_old", "value_old", "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, "value_new", "value_new", "varchar(255) DEFAULT NULL");
    $migration->changeField($newTable, "plugin_fusioninventory_agentprocesses_id", "plugin_fusioninventory_agentprocesses_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->changeField($newTable, "ID", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "FK_ports", "networkports_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "plugin_fusioninventory_mappings_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    // Update with mapping
    if (FieldExists($newTable, "Field")) {
        //            $pfNetworkPortLog = new PluginFusioninventoryNetworkPortLog();
        $pfMapping = new PluginFusioninventoryMapping();
        $query = "SELECT * FROM `" . $newTable . "`\n               GROUP BY `Field`";
        $result = $DB->query($query);
        while ($data = $DB->fetch_array($result)) {
            $mapping = 0;
            if ($mapping = $pfMapping->get("NetworkEquipment", $data['Field'])) {
                $DB->query("UPDATE `" . $newTable . "`\n                     SET `plugin_fusioninventory_mappings_id`='" . $mapping['id'] . "'\n                     WHERE `Field`='" . $data['Field'] . "'\n                        AND `plugin_fusioninventory_mappings_id`!='" . $mapping['id'] . "'");
            }
        }
    }
    $migration->dropField($newTable, "Field");
    $migration->changeField($newTable, "old_value", "value_old", "varchar(255) DEFAULT NULL");
    $migration->dropField($newTable, "old_device_type");
    $migration->dropField($newTable, "old_device_ID");
    $migration->changeField($newTable, "new_value", "value_new", "varchar(255) DEFAULT NULL");
    $migration->dropField($newTable, "new_device_type");
    $migration->dropField($newTable, "new_device_ID");
    $migration->dropField($newTable, "FK_process");
    $migration->dropKey($newTable, "FK_process");
    $migration->dropKey($newTable, "FK_ports");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, "networkports_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "plugin_fusioninventory_mappings_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "date_mod", "datetime DEFAULT NULL");
    $migration->addField($newTable, "value_old", "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, "value_new", "varchar(255) DEFAULT NULL");
    $migration->addField($newTable, "plugin_fusioninventory_agentprocesses_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addKey($newTable, array("networkports_id", "date_mod"), "networkports_id");
    $migration->addKey($newTable, "plugin_fusioninventory_mappings_id");
    $migration->addKey($newTable, "plugin_fusioninventory_agentprocesses_id");
    $migration->addKey($newTable, "date_mod");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     * Table glpi_plugin_fusioninventory_configsecurities
     */
    // TODO get info to create SNMP authentification with old values of Tracker plugin
    $newTable = "glpi_plugin_fusioninventory_configsecurities";
    $migration->renameTable("glpi_plugin_fusinvsnmp_configsecurities", $newTable);
    $migration->renameTable("glpi_plugin_tracker_snmp_connection", $newTable);
    if (!TableExists($newTable)) {
        $DB->query('CREATE TABLE `' . $newTable . '` (
                        `id` int(11) NOT NULL AUTO_INCREMENT,
                        PRIMARY KEY (`id`)
                   ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1');
    }
    $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "name", "name", "varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "snmpversion", "snmpversion", "varchar(8) COLLATE utf8_unicode_ci NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, "community", "community", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "username", "username", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "authentication", "authentication", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "auth_passphrase", "auth_passphrase", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "encryption", "encryption", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "priv_passphrase", "priv_passphrase", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->changeField($newTable, "is_deleted", "is_deleted", "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->changeField($newTable, "ID", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "FK_snmp_version", "snmpversion", "varchar(8) COLLATE utf8_unicode_ci NOT NULL DEFAULT '1'");
    $migration->changeField($newTable, "sec_name", "username", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->dropField($newTable, "sec_level");
    $migration->dropField($newTable, "auth_protocol");
    $migration->dropField($newTable, "priv_protocol");
    $migration->dropField($newTable, "deleted");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, "name", "varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "snmpversion", "varchar(8) COLLATE utf8_unicode_ci NOT NULL DEFAULT '1'");
    $migration->addField($newTable, "community", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "username", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "authentication", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "auth_passphrase", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "encryption", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "priv_passphrase", "varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL");
    $migration->addField($newTable, "is_deleted", "tinyint(1) NOT NULL DEFAULT '0'");
    $migration->addKey($newTable, "snmpversion");
    $migration->addKey($newTable, "is_deleted");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     *  glpi_plugin_fusioninventory_statediscoveries
     */
    $newTable = "glpi_plugin_fusioninventory_statediscoveries";
    $migration->renameTable("glpi_plugin_fusinvsnmp_statediscoveries", $newTable);
    if (!TableExists($newTable)) {
        $DB->query("CREATE TABLE `" . $newTable . "` (\n                        `id` int(11) NOT NULL AUTO_INCREMENT,\n                        PRIMARY KEY (`id`)\n                   ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1");
    }
    $migration->changeField($newTable, "id", "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->changeField($newTable, "plugin_fusioninventory_taskjob_id", "plugin_fusioninventory_taskjob_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "plugin_fusioninventory_agents_id", "plugin_fusioninventory_agents_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "start_time", "start_time", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'");
    $migration->changeField($newTable, "end_time", "end_time", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'");
    $migration->changeField($newTable, "date_mod", "date_mod", "datetime DEFAULT NULL");
    $migration->changeField($newTable, "threads", "threads", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "nb_ip", "nb_ip", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "nb_found", "nb_found", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "nb_error", "nb_error", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "nb_exists", "nb_exists", "int(11) NOT NULL DEFAULT '0'");
    $migration->changeField($newTable, "nb_import", "nb_import", "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $migration->addField($newTable, "id", "int(11) NOT NULL AUTO_INCREMENT");
    $migration->addField($newTable, "plugin_fusioninventory_taskjob_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "plugin_fusioninventory_agents_id", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "start_time", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'");
    $migration->addField($newTable, "end_time", "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'");
    $migration->addField($newTable, "date_mod", "datetime DEFAULT NULL");
    $migration->addField($newTable, "threads", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "nb_ip", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "nb_found", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "nb_error", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "nb_exists", "int(11) NOT NULL DEFAULT '0'");
    $migration->addField($newTable, "nb_import", "int(11) NOT NULL DEFAULT '0'");
    $migration->migrationOneTable($newTable);
    $DB->list_fields($newTable, FALSE);
    /*
     * Table glpi_plugin_fusioninventory_computerlicenseinfos
     */
    if (TableExists("glpi_plugin_fusinvinventory_licenseinfos")) {
        $DB->query("UPDATE `glpi_plugin_fusinvinventory_licenseinfos`" . " SET `softwarelicenses_id`='0'" . " WHERE `softwarelicenses_id` IS NULL");
    }
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_computerlicenseinfos';
    $a_table['oldname'] = array('glpi_plugin_fusinvinventory_licenseinfos');
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['computers_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['softwarelicenses_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['fullname'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['serial'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['is_trial'] = array('type' => 'bool', 'value' => NULL);
    $a_table['fields']['is_update'] = array('type' => 'bool', 'value' => NULL);
    $a_table['fields']['is_oem'] = array('type' => 'bool', 'value' => NULL);
    $a_table['fields']['activation_date'] = array('type' => 'datetime', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['keys'][] = array('field' => 'name', 'name' => '', 'type' => 'INDEX');
    $a_table['keys'][] = array('field' => 'fullname', 'name' => '', 'type' => 'INDEX');
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_computerarchs
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_computerarchs';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => 'autoincrement', 'value' => '');
    $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['comment'] = array('type' => 'text', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['keys'][] = array('field' => 'name', 'name' => '', 'type' => 'INDEX');
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Deploy Update Begin
     */
    /*
     * glpi_plugin_fusioninventory_deployfiles
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_deployfiles';
    $a_table['oldname'] = array();
    $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => NULL), 'name' => array('type' => 'varchar(255) NOT NULL', 'value' => NULL), 'mimetype' => array('type' => 'varchar(255) NOT NULL', 'value' => NULL), 'filesize' => array('type' => 'bigint(20) NOT NULL', 'value' => NULL), 'comment' => array('type' => 'text DEFAULT NULL', 'value' => NULL), 'sha512' => array('type' => 'char(128) NOT NULL', 'value' => NULL), 'shortsha512' => array('type' => 'char(6) NOT NULL', 'value' => NULL), 'entities_id' => array('type' => 'int(11) NOT NULL', 'value' => NULL), 'is_recursive' => array('type' => 'tinyint(1) NOT NULL DEFAULT 0', 'value' => 0), 'date_mod' => array('type' => 'datetime DEFAULT NULL', 'value' => NULL));
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array(array('field' => 'id', 'name' => '', 'type' => 'KEY'), array('field' => 'shortsha512', 'name' => '', 'type' => 'KEY'), array('field' => 'entities_id', 'name' => '', 'type' => 'KEY'), array('field' => 'date_mod', 'name' => '', 'type' => 'KEY'));
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * glpi_plugin_fusioninventory_deployorders
     */
    $a_table = array();
    //table name
    $a_table['name'] = 'glpi_plugin_fusioninventory_deployorders';
    $a_table['oldname'] = array('glpi_plugin_fusinvdeploy_orders');
    $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => NULL), 'type' => array('type' => 'int(11) NOT NULL', 'value' => NULL), 'create_date' => array('type' => ' datetime NOT NULL', 'value' => NULL), 'plugin_fusioninventory_deploypackages_id' => array('type' => 'int(11) NOT NULL', 'value' => NULL), 'json' => array('type' => 'longtext DEFAULT NULL', 'value' => NULL));
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array('plugin_fusinvdeploy_packages_id' => 'plugin_fusioninventory_deploypackages_id');
    $a_table['keys'] = array(array('field' => 'type', 'name' => '', 'type' => 'KEY'), array('field' => 'create_date', 'name' => '', 'type' => 'KEY'), array('field' => 'plugin_fusioninventory_deploypackages_id', 'name' => '', 'type' => 'KEY'));
    $a_table['oldkeys'] = array('plugin_fusinvdeploy_packages_id');
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * glpi_plugin_fusioninventory_deploypackages
     */
    $a_table = array();
    //table name
    $a_table['name'] = 'glpi_plugin_fusioninventory_deploypackages';
    $a_table['oldname'] = array('glpi_plugin_fusinvdeploy_packages');
    $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => NULL), 'name' => array('type' => 'varchar(255) COLLATE utf8_unicode_ci NOT NULL', 'value' => NULL), 'comment' => array('type' => "text", 'value' => NULL), 'entities_id' => array('type' => 'int(11) NOT NULL', 'value' => NULL), 'is_recursive' => array('type' => 'tinyint(1) NOT NULL DEFAULT 0', 'value' => NULL), 'date_mod' => array('type' => 'datetime DEFAULT NULL', 'value' => NULL), 'uuid' => array('type' => 'string', 'value' => NULL));
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array(array('field' => 'entities_id', 'name' => '', 'type' => 'KEY'), array('field' => 'date_mod', 'name' => '', 'type' => 'KEY'));
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * glpi_plugin_fusioninventory_deploymirrors
     */
    $a_table = array();
    //table name
    $a_table['name'] = 'glpi_plugin_fusioninventory_deploymirrors';
    $a_table['oldname'] = array('glpi_plugin_fusinvdeploy_mirrors');
    $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => NULL), 'entities_id' => array('type' => 'int(11) NOT NULL', 'value' => NULL), 'is_recursive' => array('type' => 'tinyint(1) NOT NULL DEFAULT 0', 'value' => NULL), 'name' => array('type' => 'varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL', 'value' => NULL), 'url' => array('type' => "varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci" . " NOT NULL DEFAULT ''", 'value' => NULL), 'locations_id' => array('type' => 'int(11) NOT NULL', 'value' => 0), 'comment' => array('type' => "text", 'value' => NULL), 'date_mod' => array('type' => 'datetime DEFAULT NULL', 'value' => NULL));
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array(array('field' => 'entities_id', 'name' => '', 'type' => 'KEY'), array('field' => 'date_mod', 'name' => '', 'type' => 'KEY'));
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * glpi_plugin_fusioninventory_deploygroups
     */
    $a_table = array();
    //table name
    $a_table['name'] = 'glpi_plugin_fusioninventory_deploygroups';
    $a_table['oldname'] = array('glpi_plugin_fusinvdeploy_groups');
    $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => NULL), 'name' => array('type' => 'varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL', 'value' => NULL), 'comment' => array('type' => "text", 'value' => NULL), 'type' => array('type' => 'varchar(255) COLLATE utf8_unicode_ci NOT NULL', 'value' => NULL));
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * glpi_plugin_fusioninventory_deploygroups_staticdatas
     */
    $a_table = array();
    //table name
    $a_table['name'] = 'glpi_plugin_fusioninventory_deploygroups_staticdatas';
    $a_table['oldname'] = array('glpi_plugin_fusinvdeploy_groups_staticdatas');
    $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => NULL), 'groups_id' => array('type' => 'integer', 'value' => NULL), 'itemtype' => array('type' => 'varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL', 'value' => NULL), 'items_id' => array('type' => 'integer', 'value' => NULL));
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array(array('field' => 'groups_id', 'name' => '', 'type' => 'KEY'), array('field' => 'items_id', 'name' => '', 'type' => 'KEY'));
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * glpi_plugin_fusioninventory_deploygroups_dynamicdatas
     */
    $a_table = array();
    //table name
    $a_table['name'] = 'glpi_plugin_fusioninventory_deploygroups_dynamicdatas';
    $a_table['oldname'] = array('glpi_plugin_fusinvdeploy_groups_dynamicdatas');
    $a_table['fields'] = array('id' => array('type' => 'autoincrement', 'value' => NULL), 'groups_id' => array('type' => 'integer', 'value' => NULL), 'fields_array' => array('type' => 'text', 'value' => NULL));
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array(array('field' => 'groups_id', 'name' => '', 'type' => 'KEY'));
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * import old datas as json in order table before migrate this table
     */
    migrateTablesFromFusinvDeploy($migration);
    /*
     * Deploy Update End
     */
    /*
     * Table glpi_plugin_fusioninventory_collects
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_collects';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => "autoincrement", 'value' => '');
    $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['entities_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['is_recursive'] = array('type' => 'bool', 'value' => NULL);
    $a_table['fields']['type'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['is_active'] = array('type' => 'bool', 'value' => NULL);
    $a_table['fields']['comment'] = array('type' => 'text', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_collects_registries
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_collects_registries';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => "autoincrement", 'value' => '');
    $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['plugin_fusioninventory_collects_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['hive'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['path'] = array('type' => 'text', 'value' => NULL);
    $a_table['fields']['key'] = array('type' => 'string', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_collects_registries_contents
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_collects_registries_contents';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => "autoincrement", 'value' => '');
    $a_table['fields']['computers_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['plugin_fusioninventory_collects_registries_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['key'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['value'] = array('type' => 'string', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['keys'][] = array('field' => 'computers_id', 'name' => '', 'type' => 'INDEX');
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_collects_wmis
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_collects_wmis';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => "autoincrement", 'value' => '');
    $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['plugin_fusioninventory_collects_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['moniker'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['class'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['properties'] = array('type' => 'string', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_collects_wmis_contents
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_collects_wmis_contents';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => "autoincrement", 'value' => '');
    $a_table['fields']['computers_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['plugin_fusioninventory_collects_wmis_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['property'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['value'] = array('type' => 'string', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_collects_files
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_collects_files';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => "autoincrement", 'value' => '');
    $a_table['fields']['name'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['plugin_fusioninventory_collects_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['dir'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['limit'] = array('type' => "int(4) NOT NULL DEFAULT '50'", 'value' => NULL);
    $a_table['fields']['is_recursive'] = array('type' => 'bool', 'value' => NULL);
    $a_table['fields']['filter_regex'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['filter_sizeequals'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['filter_sizegreater'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['filter_sizelower'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['filter_checksumsha512'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['filter_checksumsha2'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['filter_name'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['filter_iname'] = array('type' => 'string', 'value' => NULL);
    $a_table['fields']['filter_is_file'] = array('type' => 'bool', 'value' => '1');
    $a_table['fields']['filter_is_dir'] = array('type' => 'bool', 'value' => '0');
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_collects_files_contents
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_collects_files_contents';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['id'] = array('type' => "autoincrement", 'value' => '');
    $a_table['fields']['computers_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['plugin_fusioninventory_collects_files_id'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['pathfile'] = array('type' => 'text', 'value' => NULL);
    $a_table['fields']['size'] = array('type' => 'integer', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_dblockinventorynames
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_dblockinventorynames';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['value'] = array('type' => "varchar(100) NOT NULL DEFAULT ''", 'value' => NULL);
    $a_table['fields']['date'] = array('type' => 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['keys'][] = array('field' => 'value', 'name' => '', 'type' => 'UNIQUE');
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_dblockinventories
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_dblockinventories';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['value'] = array('type' => 'integer', 'value' => NULL);
    $a_table['fields']['date'] = array('type' => 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['keys'][] = array('field' => 'value', 'name' => '', 'type' => 'UNIQUE');
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_dblocksoftwares
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_dblocksoftwares';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['value'] = array('type' => 'bool', 'value' => NULL);
    $a_table['fields']['date'] = array('type' => 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['keys'][] = array('field' => 'value', 'name' => '', 'type' => 'UNIQUE');
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Table glpi_plugin_fusioninventory_dblocksoftwareversions
     */
    $a_table = array();
    $a_table['name'] = 'glpi_plugin_fusioninventory_dblocksoftwareversions';
    $a_table['oldname'] = array();
    $a_table['fields'] = array();
    $a_table['fields']['value'] = array('type' => 'bool', 'value' => NULL);
    $a_table['fields']['date'] = array('type' => 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP', 'value' => NULL);
    $a_table['oldfields'] = array();
    $a_table['renamefields'] = array();
    $a_table['keys'] = array();
    $a_table['keys'][] = array('field' => 'value', 'name' => '', 'type' => 'UNIQUE');
    $a_table['oldkeys'] = array();
    migrateTablesFusionInventory($migration, $a_table);
    /*
     * Add ESX module appear in version 2.4.0(0.80+1.0)
     */
    $DB->query("UPDATE `glpi_plugin_fusioninventory_agentmodules`\n         SET `modulename`='InventoryComputerESX'\n         WHERE `modulename`='ESX'");
    $agentmodule = new PluginFusioninventoryAgentmodule();
    $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_agentmodules`\n         WHERE `modulename`='InventoryComputerESX'\n         LIMIT 1";
    $result = $DB->query($query);
    if ($DB->numrows($result) == '0') {
        $input = array();
        $input['modulename'] = "InventoryComputerESX";
        $input['is_active'] = 0;
        $input['exceptions'] = exportArrayToDB(array());
        $url = '';
        if (isset($_SERVER['HTTP_REFERER'])) {
            $url = $_SERVER['HTTP_REFERER'];
        }
        $agentmodule->add($input);
    }
    /*
     * Add Collect module appear in version 0.84+2.0
     */
    $agentmodule = new PluginFusioninventoryAgentmodule();
    $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_agentmodules`\n         WHERE `modulename`='Collect'\n         LIMIT 1";
    $result = $DB->query($query);
    if ($DB->numrows($result) == '0') {
        $input = array();
        $input['modulename'] = "Collect";
        $input['is_active'] = 1;
        $input['exceptions'] = exportArrayToDB(array());
        $agentmodule->add($input);
    }
    /*
     * Update pci and usb ids and oui
     */
    foreach (array('usbid.sql', 'pciid.sql', 'oui.sql') as $sql) {
        $DB_file = GLPI_ROOT . "/plugins/fusioninventory/install/mysql/{$sql}";
        $DBf_handle = fopen($DB_file, "rt");
        $sql_query = fread($DBf_handle, filesize($DB_file));
        fclose($DBf_handle);
        foreach (explode(";\n", "{$sql_query}") as $sql_line) {
            if (Toolbox::get_magic_quotes_runtime()) {
                $sql_line = Toolbox::stripslashes_deep($sql_line);
            }
            if (!empty($sql_line)) {
                $DB->query($sql_line);
            }
        }
    }
    /*
     * Migrate data of table glpi_plugin_fusinvsnmp_agentconfigs into
     * glpi_plugin_fusioninventory_agents
     */
    if (TableExists("glpi_plugin_fusinvsnmp_agentconfigs")) {
        $query = "SELECT * FROM `glpi_plugin_fusinvsnmp_agentconfigs`";
        $result = $DB->query($query);
        while ($data = $DB->fetch_array($result)) {
            $queryu = "UPDATE `glpi_plugin_fusioninventory_agents`\n            SET `threads_networkdiscovery`='" . $data['threads_netdiscovery'] . "',\n                `threads_networkinventory`='" . $data['threads_snmpquery'] . "',\n                `senddico`='" . $data['senddico'] . "'\n            WHERE `id`='" . $data['plugin_fusioninventory_agents_id'] . "'";
            $DB->query($queryu);
        }
    }
    // Update profiles
    if (TableExists("glpi_plugin_tracker_profiles")) {
        $profile = new Profile();
        $pfProfile = new PluginFusioninventoryProfile();
        $query = "SELECT * FROM `glpi_plugin_tracker_profiles`";
        $result = $DB->query($query);
        while ($data = $DB->fetch_array($result)) {
            $profiledata = current($profile->find("`name`='" . $data['name'] . "'", "", 1));
            if (!empty($profiledata)) {
                $newprofile = array();
                $newprofile['snmp_networking'] = "networkequipment";
                $newprofile['snmp_printers'] = "printer";
                $newprofile['snmp_models'] = "model";
                $newprofile['snmp_authentification'] = "configsecurity";
                $newprofile['general_config'] = "configuration";
                $newprofile['snmp_report'] = "reportprinter";
                foreach ($newprofile as $old => $new) {
                    if (isset($profiledata[$old])) {
                        //                  $pfProfile->addProfile($new,
                        //                                         $profiledata[$old],
                        //                                         $profiledata['id']);
                    }
                }
                if (isset($profiledata["snmp_report"])) {
                    //               $pfProfile->addProfile("reportnetworkequipment",
                    //                                      $profiledata["snmp_report"],
                    //                                      $profiledata['id']);
                }
            }
        }
        $DB->query("DROP TABLE `glpi_plugin_tracker_profiles`");
    }
    update213to220_ConvertField($migration);
    /*
     * Move networkequipment IPs to net system
     */
    if (TableExists("glpi_plugin_fusioninventory_networkequipmentips")) {
        $networkPort = new NetworkPort();
        $networkName = new NetworkName();
        $ipAddress = new IPAddress();
        $networkEquipment = new NetworkEquipment();
        $query = "SELECT * FROM `glpi_plugin_fusioninventory_networkequipments`";
        $result = $DB->query($query);
        while ($data = $DB->fetch_array($result)) {
            if ($networkEquipment->getFromDB($data['networkequipments_id'])) {
                $oldtableip = array();
                $queryIP = "SELECT * FROM `glpi_plugin_fusioninventory_networkequipmentips`\n               WHERE `networkequipments_id`='" . $data['networkequipments_id'] . "'";
                $resultIP = $DB->query($queryIP);
                while ($dataIP = $DB->fetch_array($resultIP)) {
                    $oldtableip[$dataIP['ip']] = $dataIP['ip'];
                }
                // Get actual IP defined
                $networknames_id = 0;
                $a_ports = $networkPort->find("`itemtype`='NetworkEquipment'\n                  AND `items_id`='" . $data['networkequipments_id'] . "'\n                  AND `instantiation_type`='NetworkPortAggregate'\n                  AND `name`='management'", "", 1);
                foreach ($a_ports as $a_port) {
                    $a_networknames = $networkName->find("`itemtype`='NetworkPort'\n                  AND `items_id`='" . $a_port['id'] . "'");
                    foreach ($a_networknames as $a_networkname) {
                        $networknames_id = $a_networkname['id'];
                        $a_ipaddresses = $ipAddress->find("`itemtype`='NetworkName'\n                     AND `items_id`='" . $a_networkname['id'] . "'");
                        foreach ($a_ipaddresses as $a_ipaddress) {
                            if (isset($oldtableip[$a_ipaddress['name']])) {
                                unset($oldtableip[$a_ipaddress['name']]);
                            } else {
                                $ipAddress->delete($a_ipaddress, 1);
                            }
                        }
                    }
                }
                // Update
                foreach ($oldtableip as $ip) {
                    $input = array();
                    $input['itemtype'] = "NetworkName";
                    $input['items_id'] = $networknames_id;
                    $input['name'] = $ip;
                    $input['is_dynamic'] = 1;
                    $ipAddress->add($input);
                }
            }
        }
    }
    /*
     * Table Delete old table not used
     */
    $a_drop = array();
    $a_drop[] = 'glpi_plugin_tracker_computers';
    $a_drop[] = 'glpi_plugin_tracker_connection_history';
    $a_drop[] = 'glpi_plugin_tracker_agents_processes';
    $a_drop[] = 'glpi_plugin_tracker_config_snmp_history';
    $a_drop[] = 'glpi_plugin_tracker_config_snmp_networking';
    $a_drop[] = 'glpi_plugin_tracker_config_snmp_printer';
    $a_drop[] = 'glpi_plugin_tracker_config_snmp_script';
    $a_drop[] = 'glpi_plugin_tracker_connection_stats';
    $a_drop[] = 'glpi_plugin_tracker_discovery';
    $a_drop[] = 'glpi_plugin_tracker_errors';
    $a_drop[] = 'glpi_plugin_tracker_model_infos';
    $a_drop[] = 'glpi_plugin_tracker_processes';
    $a_drop[] = 'glpi_plugin_tracker_processes_values';
    $a_drop[] = 'glpi_plugin_fusioninventory_agents_errors';
    $a_drop[] = 'glpi_plugin_fusioninventory_agents_processes';
    $a_drop[] = 'glpi_plugin_fusioninventory_computers';
    $a_drop[] = 'glpi_dropdown_plugin_tracker_snmp_auth_auth_protocol';
    $a_drop[] = 'glpi_dropdown_plugin_tracker_snmp_auth_priv_protocol';
    $a_drop[] = 'glpi_dropdown_plugin_tracker_snmp_auth_sec_level';
    $a_drop[] = 'glpi_dropdown_plugin_tracker_snmp_version';
    $a_drop[] = 'glpi_plugin_fusioninventory_config_snmp_networking';
    $a_drop[] = 'glpi_plugin_fusioninventory_config_snmp_history';
    $a_drop[] = 'glpi_plugin_fusinvsnmp_agentconfigs';
    $a_drop[] = 'glpi_plugin_tracker_computers';
    $a_drop[] = 'glpi_plugin_tracker_config';
    $a_drop[] = 'glpi_plugin_tracker_config_discovery';
    $a_drop[] = 'glpi_dropdown_plugin_fusioninventory_mib_label';
    $a_drop[] = 'glpi_dropdown_plugin_fusioninventory_mib_object';
    $a_drop[] = 'glpi_dropdown_plugin_fusioninventory_mib_oid';
    $a_drop[] = 'glpi_dropdown_plugin_fusioninventory_snmp_auth_auth_protocol';
    $a_drop[] = 'glpi_dropdown_plugin_fusioninventory_snmp_auth_priv_protocol';
    $a_drop[] = 'glpi_dropdown_plugin_fusioninventory_snmp_version';
    $a_drop[] = 'glpi_plugin_fusinvsnmp_temp_profiles';
    $a_drop[] = 'glpi_plugin_fusinvsnmp_tmp_agents';
    $a_drop[] = 'glpi_plugin_fusinvsnmp_tmp_configs';
    $a_drop[] = 'glpi_plugin_fusinvsnmp_tmp_tasks';
    $a_drop[] = 'glpi_plugin_tracker_tmp_connections';
    $a_drop[] = 'glpi_plugin_tracker_tmp_netports';
    $a_drop[] = 'glpi_plugin_tracker_walks';
    $a_drop[] = 'glpi_plugin_fusioninventory_networkequipmentips';
    foreach ($a_drop as $droptable) {
        if (TableExists($droptable)) {
            $DB->query("DROP TABLE `" . $droptable . "`");
        }
    }
    $migration->executeMigration();
    /*
     * Add WakeOnLan module appear in version 2.3.0
     */
    $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_agentmodules`\n      WHERE `modulename`='WAKEONLAN'";
    $result = $DB->query($query);
    if (!$DB->numrows($result)) {
        $agentmodule = new PluginFusioninventoryAgentmodule();
        $input = array();
        $input['plugins_id'] = $plugins_id;
        $input['modulename'] = "WAKEONLAN";
        $input['is_active'] = 0;
        $input['exceptions'] = exportArrayToDB(array());
        $agentmodule->add($input);
    }
    /*
     * Add storage type if not present
     */
    $a_storage = array();
    $a_storage['partition'] = 5;
    $a_storage['volume groups'] = 10;
    $a_storage['logical volumes'] = 20;
    $a_storage['hard disk'] = 1;
    $a_storage['mount'] = 25;
    foreach ($a_storage as $name => $level) {
        $query = "SELECT `id` FROM `glpi_plugin_fusioninventory_inventorycomputerstoragetypes`\n         WHERE `name`='" . $name . "'";
        $result = $DB->query($query);
        if (!$DB->numrows($result)) {
            $DB->query("INSERT INTO `glpi_plugin_fusioninventory_inventorycomputerstoragetypes`\n            (`name`, `level`) VALUES\n            ('" . $name . "', '" . $level . "')");
        }
    }
    /*
     * Clean for port orphelin
     */
    //networkports with item_type = 0
    $NetworkPort = new NetworkPort();
    $NetworkPort_Vlan = new NetworkPort_Vlan();
    $NetworkPort_NetworkPort = new NetworkPort_NetworkPort();
    $a_networkports = $NetworkPort->find("`itemtype`=''");
    foreach ($a_networkports as $data) {
        if ($NetworkPort_NetworkPort->getFromDBForNetworkPort($data['id'])) {
            $NetworkPort_NetworkPort->delete($NetworkPort_NetworkPort->fields);
        }
        $a_vlans = $NetworkPort_Vlan->find("`networkports_id`='" . $data['id'] . "'");
        foreach ($a_vlans as $a_vlan) {
            $NetworkPort_Vlan->delete($a_vlan);
        }
        $NetworkPort->delete($data, 1);
    }
    /*
     *  Clean old ports deleted but have some informations in SNMP tables
     */
    //echo "Clean ports purged\n";
    $query_select = "SELECT `glpi_plugin_fusioninventory_networkports`.`id`\n                    FROM `glpi_plugin_fusioninventory_networkports`\n                          LEFT JOIN `glpi_networkports`\n                                    ON `glpi_networkports`.`id` = `networkports_id`\n                          LEFT JOIN `glpi_networkequipments`\n                              ON `glpi_networkequipments`.`id` = `glpi_networkports`.`items_id`\n                    WHERE `glpi_networkequipments`.`id` IS NULL";
    $result = $DB->query($query_select);
    while ($data = $DB->fetch_array($result)) {
        $query_del = "DELETE FROM `glpi_plugin_fusioninventory_networkports`\n         WHERE `id`='" . $data["id"] . "'";
        $DB->query($query_del);
    }
    /*
     * Clean for switch more informations again in DB when switch is purged
     */
    //echo "Clean for switch more informations again in DB when switch is purged\n";
    $query_select = "SELECT `glpi_plugin_fusioninventory_networkequipments`.`id`\n                    FROM `glpi_plugin_fusioninventory_networkequipments`\n                    LEFT JOIN `glpi_networkequipments`\n                        ON `glpi_networkequipments`.`id` = `networkequipments_id`\n                    WHERE `glpi_networkequipments`.`id` IS NULL";
    $result = $DB->query($query_select);
    while ($data = $DB->fetch_array($result)) {
        $query_del = "DELETE FROM `glpi_plugin_fusioninventory_networkequipments`\n         WHERE `id`='" . $data["id"] . "'";
        $DB->query($query_del);
    }
    /*
     * Clean for printer more informations again in DB when printer is purged
     */
    //echo "Clean for printer more informations again in DB when printer is purged\n";
    $query_select = "SELECT `glpi_plugin_fusioninventory_printers`.`id`\n                    FROM `glpi_plugin_fusioninventory_printers`\n                          LEFT JOIN `glpi_printers` ON `glpi_printers`.`id` = `printers_id`\n                    WHERE `glpi_printers`.`id` IS NULL";
    $result = $DB->query($query_select);
    while ($data = $DB->fetch_array($result)) {
        $query_del = "DELETE FROM `glpi_plugin_fusioninventory_printers`\n         WHERE `id`='" . $data["id"] . "'";
        $DB->query($query_del);
    }
    /*
     *  Clean printer cartridge not deleted with the printer associated
     */
    //echo "Clean printer cartridge not deleted with the printer associated\n";
    $query_select = "SELECT `glpi_plugin_fusioninventory_printercartridges`.`id`\n                    FROM `glpi_plugin_fusioninventory_printercartridges`\n                          LEFT JOIN `glpi_printers` ON `glpi_printers`.`id` = `printers_id`\n                    WHERE `glpi_printers`.`id` IS NULL";
    $result = $DB->query($query_select);
    while ($data = $DB->fetch_array($result)) {
        $query_del = "DELETE FROM `glpi_plugin_fusioninventory_printercartridges`\n         WHERE `id`='" . $data["id"] . "'";
        $DB->query($query_del);
    }
    /*
     *  Clean printer history not deleted with printer associated
     */
    //echo "Clean printer history not deleted with printer associated\n";
    $query_select = "SELECT `glpi_plugin_fusioninventory_printerlogs`.`id`\n                    FROM `glpi_plugin_fusioninventory_printerlogs`\n                          LEFT JOIN `glpi_printers` ON `glpi_printers`.`id` = `printers_id`\n                    WHERE `glpi_printers`.`id` IS NULL";
    $result = $DB->query($query_select);
    while ($data = $DB->fetch_array($result)) {
        $query_del = "DELETE FROM `glpi_plugin_fusioninventory_printerlogs`\n         WHERE `id`='" . $data["id"] . "'";
        $DB->query($query_del);
    }
    /*
     * Fix problem with mapping with many entries with same mapping
     */
    $a_mapping = array();
    $a_mappingdouble = array();
    $query = "SELECT * FROM `glpi_plugin_fusioninventory_mappings`\n      ORDER BY `id`";
    $result = $DB->query($query);
    while ($data = $DB->fetch_array($result)) {
        if (!isset($a_mapping[$data['itemtype'] . "." . $data['name']])) {
            $a_mapping[$data['itemtype'] . "." . $data['name']] = $data['id'];
        } else {
            $a_mappingdouble[$data['id']] = $data['itemtype'] . "." . $data['name'];
        }
    }
    foreach ($a_mappingdouble as $mapping_id => $mappingkey) {
        $query = "UPDATE `glpi_plugin_fusioninventory_printercartridges`\n         SET plugin_fusioninventory_mappings_id='" . $a_mapping[$mappingkey] . "'\n         WHERE plugin_fusioninventory_mappings_id='" . $mapping_id . "'";
        $DB->query($query);
        $query = "UPDATE `glpi_plugin_fusioninventory_networkportlogs`\n         SET plugin_fusioninventory_mappings_id='" . $a_mapping[$mappingkey] . "'\n         WHERE plugin_fusioninventory_mappings_id='" . $mapping_id . "'";
        $DB->query($query);
        $query = "UPDATE `glpi_plugin_fusioninventory_configlogfields`\n         SET plugin_fusioninventory_mappings_id='" . $a_mapping[$mappingkey] . "'\n         WHERE plugin_fusioninventory_mappings_id='" . $mapping_id . "'";
        $DB->query($query);
        $query = "DELETE FROM `glpi_plugin_fusioninventory_mappings`\n         WHERE `id` = '" . $mapping_id . "'";
        $DB->query($query);
    }
    /*
     * Update networports to convert itemtype 5153 to PluginFusioninventoryUnknownDevice
     */
    $sql = "UPDATE `glpi_networkports`\n      SET `itemtype`='PluginFusioninventoryUnknownDevice'\n      WHERE `itemtype`='5153'";
    $DB->query($sql);
    $sql = "UPDATE `glpi_networkports`\n      SET `itemtype`='PluginFusioninventoryTask'\n      WHERE `itemtype`='5166'";
    $DB->query($sql);
    /*
     * Clean display preferences not used
     */
    $sql = "DELETE FROM `glpi_displaypreferences`\n      WHERE `itemtype`='5150' ";
    $DB->query($sql);
    $sql = "DELETE FROM `glpi_displaypreferences`\n      WHERE `itemtype`='5160' ";
    $DB->query($sql);
    $sql = "DELETE FROM `glpi_displaypreferences`\n      WHERE `itemtype`='5161' ";
    $DB->query($sql);
    $sql = "DELETE FROM `glpi_displaypreferences`\n      WHERE `itemtype`='5163' ";
    $DB->query($sql);
    $sql = "DELETE FROM `glpi_displaypreferences`\n      WHERE `itemtype`='5165' ";
    $DB->query($sql);
    $sql = "DELETE FROM `glpi_displaypreferences`\n      WHERE `itemtype`='5190' ";
    $DB->query($sql);
    /*
     * Update display preferences
     */
    changeDisplayPreference("5153", "PluginFusioninventoryUnknownDevice");
    changeDisplayPreference("5158", "PluginFusioninventoryAgent");
    changeDisplayPreference("PluginFusinvinventoryBlacklist", "PluginFusioninventoryInventoryComputerBlacklist");
    changeDisplayPreference("5151", "PluginFusinvsnmpModel");
    changeDisplayPreference("PluginFusinvsnmpModel", "PluginFusioninventorySnmpmodel");
    changeDisplayPreference("5152", "PluginFusinvsnmpConfigSecurity");
    changeDisplayPreference("5156", "PluginFusinvsnmpPrinterCartridge");
    changeDisplayPreference("5157", "PluginFusinvsnmpNetworkEquipment");
    changeDisplayPreference("PluginFusinvsnmpNetworkEquipment", "PluginFusioninventoryNetworkEquipment");
    changeDisplayPreference("5159", "PluginFusinvsnmpIPRange");
    changeDisplayPreference("5162", "PluginFusinvsnmpNetworkPortLog");
    changeDisplayPreference("5167", "PluginFusioninventorySnmpmodelConstructDevice");
    changeDisplayPreference("PluginFusinvsnmpConstructDevice", "PluginFusioninventorySnmpmodelConstructDevice");
    changeDisplayPreference("5168", "PluginFusinvsnmpPrinterLog");
    changeDisplayPreference("PluginFusinvsnmpPrinterLogReport", "PluginFusioninventoryPrinterLogReport");
    changeDisplayPreference("PluginFusioninventoryUnknownDevice", "PluginFusioninventoryUnmanaged");
    /*
     * Delete IP and MAC of PluginFusioninventoryUnknownDevice in displaypreference
     */
    $queryd = "DELETE FROM `glpi_displaypreferences`\n         WHERE `itemtype`='PluginFusioninventoryUnknownDevice'\n            AND (`num`='11' OR `num`='12' OR `num`='16')";
    $DB->query($queryd);
    /*
     * Clean in displaypreference
     */
    $queryd = "DELETE FROM `glpi_displaypreferences`\n         WHERE `itemtype`='PluginFusioninventorysnmpModel'";
    $DB->query($queryd);
    /*
     * Modify displaypreference for PluginFusioninventoryPrinterLog
     */
    $pfPrinterLogReport = new PluginFusioninventoryPrinterLog();
    $a_searchoptions = $pfPrinterLogReport->getSearchOptions();
    $query = "SELECT * FROM `glpi_displaypreferences`\n      WHERE `itemtype` = 'PluginFusioninventoryPrinterLogReport'\n         AND `users_id`='0'";
    $result = $DB->query($query);
    if ($DB->numrows($result) == '0') {
        $query = "INSERT INTO `glpi_displaypreferences` (`id`, `itemtype`, `num`, `rank`,\n                        `users_id`)\n                     VALUES (NULL, 'PluginFusioninventoryPrinterLogReport', '2', '1', '0'),\n             (NULL, 'PluginFusioninventoryPrinterLogReport', '18', '2', '0'),\n             (NULL, 'PluginFusioninventoryPrinterLogReport', '20', '3', '0'),\n             (NULL, 'PluginFusioninventoryPrinterLogReport', '5', '4', '0'),\n             (NULL, 'PluginFusioninventoryPrinterLogReport', '6', '5', '0')";
        $DB->query($query);
    } else {
        while ($data = $DB->fetch_array($result)) {
            if (!isset($a_searchoptions[$data['num']])) {
                $queryd = "DELETE FROM `glpi_displaypreferences`\n                  WHERE `id`='" . $data['id'] . "'";
                $DB->query($queryd);
            }
        }
    }
    /*
     * Modify displaypreference for PluginFusinvsnmpNetworkEquipment
     */
    $a_check = array();
    $a_check["2"] = 1;
    $a_check["3"] = 2;
    $a_check["4"] = 3;
    $a_check["5"] = 4;
    $a_check["6"] = 5;
    $a_check["7"] = 6;
    $a_check["8"] = 7;
    $a_check["9"] = 8;
    $a_check["10"] = 9;
    $a_check["11"] = 10;
    $a_check["14"] = 11;
    $a_check["12"] = 12;
    $a_check["13"] = 13;
    foreach ($a_check as $num => $rank) {
        $query = "SELECT * FROM `glpi_displaypreferences`\n         WHERE `itemtype` = 'PluginFusioninventoryNetworkEquipment'\n         AND `num`='" . $num . "'\n            AND `users_id`='0'";
        $result = $DB->query($query);
        if ($DB->numrows($result) == '0') {
            $query = "INSERT INTO `glpi_displaypreferences` (`id`, `itemtype`, `num`, `rank`,\n                           `users_id`)\n                        VALUES (NULL, 'PluginFusioninventoryNetworkEquipment', '" . $num . "',\n                           '" . $rank . "', '0')";
            $DB->query($query);
        }
    }
    $query = "SELECT * FROM `glpi_displaypreferences`\n      WHERE `itemtype` = 'PluginFusioninventoryNetworkEquipment'\n         AND `users_id`='0'";
    $result = $DB->query($query);
    while ($data = $DB->fetch_array($result)) {
        if (!isset($a_check[$data['num']])) {
            $queryd = "DELETE FROM `glpi_displaypreferences`\n               WHERE `id`='" . $data['id'] . "'";
            $DB->query($queryd);
        }
    }
    // If no PluginFusioninventoryTaskjoblog in preferences, add them
    $query = "SELECT * FROM `glpi_displaypreferences`\n      WHERE `itemtype` = 'PluginFusioninventoryTaskjoblog'\n         AND `users_id`='0'";
    $result = $DB->query($query);
    if ($DB->numrows($result) == 0) {
        $DB->query("INSERT INTO `glpi_displaypreferences`\n            (`id`, `itemtype`, `num`, `rank`, `users_id`)\n         VALUES (NULL,'PluginFusioninventoryTaskjoblog', '2', '1', '0'),\n                (NULL,'PluginFusioninventoryTaskjoblog', '3', '2', '0'),\n                (NULL,'PluginFusioninventoryTaskjoblog', '4', '3', '0'),\n                (NULL,'PluginFusioninventoryTaskjoblog', '5', '4', '0'),\n                (NULL,'PluginFusioninventoryTaskjoblog', '6', '5', '0'),\n                (NULL,'PluginFusioninventoryTaskjoblog', '7', '6', '0'),\n                (NULL,'PluginFusioninventoryTaskjoblog', '8', '7', '0')");
    }
    // If no PluginFusioninventoryNetworkPort in preferences, add them
    $query = "SELECT * FROM `glpi_displaypreferences`\n      WHERE `itemtype` = 'PluginFusioninventoryNetworkPort'\n         AND `users_id`='0'";
    $result = $DB->query($query);
    if ($DB->numrows($result) == 0) {
        $DB->query("INSERT INTO `glpi_displaypreferences`\n            (`id`, `itemtype`, `num`, `rank`, `users_id`)\n         VALUES (NULL,'PluginFusioninventoryNetworkPort', '3', '1', '0'),\n                (NULL,'PluginFusioninventoryNetworkPort', '5', '2', '0'),\n                (NULL,'PluginFusioninventoryNetworkPort', '6', '3', '0'),\n                (NULL,'PluginFusioninventoryNetworkPort', '7', '4', '0'),\n                (NULL,'PluginFusioninventoryNetworkPort', '8', '5', '0'),\n                (NULL,'PluginFusioninventoryNetworkPort', '9', '6', '0'),\n                (NULL,'PluginFusioninventoryNetworkPort', '10', '7', '0'),\n                (NULL,'PluginFusioninventoryNetworkPort', '11', '8', '0'),\n                (NULL,'PluginFusioninventoryNetworkPort', '12', '9', '0'),\n                (NULL,'PluginFusioninventoryNetworkPort', '13', '10', '0'),\n                (NULL,'PluginFusioninventoryNetworkPort', '14', '11', '0')");
    }
    /*
     * Convert taskjob definition from PluginFusinvsnmpIPRange to PluginFusioninventoryIPRange
     * onvert taskjob definition from PluginFusinvdeployPackage to PluginFusioninventoryDeployPackage
     */
    $query = "SELECT * FROM `glpi_plugin_fusioninventory_taskjobs`";
    $result = $DB->query($query);
    while ($data = $DB->fetch_array($result)) {
        $a_defs = importArrayFromDB($data['targets']);
        foreach ($a_defs as $num => $a_def) {
            if (key($a_def) == 'PluginFusinvsnmpIPRange') {
                $a_defs[$num] = array('PluginFusioninventoryIPRange' => current($a_def));
            } else {
                if (key($a_def) == 'PluginFusinvdeployPackage') {
                    $a_defs[$num] = array('PluginFusioninventoryDeployPackage' => current($a_def));
                }
            }
        }
        $queryu = "UPDATE `glpi_plugin_fusioninventory_taskjobs`\n         SET `targets`='" . exportArrayToDB($a_defs) . "'\n         WHERE `id`='" . $data['id'] . "'";
        $DB->query($queryu);
    }
    /*
     * Convert taskjoblogs itemtype from PluginFusinvdeployPackage to
     * PluginFusioninventoryDeployPackage
     */
    $query = "UPDATE `glpi_plugin_fusioninventory_taskjoblogs` " . "SET `itemtype`='PluginFusioninventoryDeployPackage'" . "WHERE `itemtype`='PluginFusinvdeployPackage'";
    $result = $DB->query($query);
    /*
     * Convert taskjobstates itemtype from PluginFusinvdeployPackage to
     * PluginFusioninventoryDeployPackage
     */
    $query = "UPDATE `glpi_plugin_fusioninventory_taskjobstates` " . "SET `itemtype`='PluginFusioninventoryDeployPackage'" . "WHERE `itemtype` = 'PluginFusinvdeployPackage'";
    $result = $DB->query($query);
    /*
     * Convert taskjob action from PluginFusinvdeployGroup to PluginFusioninventoryDeployGroup
     */
    $query = "SELECT * FROM `glpi_plugin_fusioninventory_taskjobs`";
    $result = $DB->query($query);
    while ($data = $DB->fetch_array($result)) {
        $a_defs = importArrayFromDB($data['actors']);
        foreach ($a_defs as $num => $a_def) {
            if (key($a_def) == 'PluginFusinvdeployGroup') {
                $a_defs[$num] = array('PluginFusioninventoryDeployGroup' => current($a_def));
            }
        }
        $queryu = "UPDATE `glpi_plugin_fusioninventory_taskjobs`\n         SET `actors`='" . exportArrayToDB($a_defs) . "'\n         WHERE `id`='" . $data['id'] . "'";
        $DB->query($queryu);
    }
    /*
     * Convert itemtype from glpi_plugin_fusioninventory_unknowndevices to
     * PluginFusioninventoryUnmanaged
     */
    $tables = array('glpi_networkports', 'glpi_logs', 'glpi_plugin_fusioninventory_ignoredimportdevices');
    foreach ($tables as $table) {
        $query = "UPDATE `" . $table . "` " . "SET `itemtype`='PluginFusioninventoryUnmanaged'" . "WHERE `itemtype` = 'PluginFusioninventoryUnknowndevice'";
        $DB->query($query);
    }
    $query = "UPDATE `glpi_ipaddresses` " . "SET `mainitemtype`='PluginFusioninventoryUnmanaged'" . "WHERE `mainitemtype` = 'PluginFusioninventoryUnknowndevice'";
    $DB->query($query);
    /*
     * Update rules
     */
    $query = "UPDATE glpi_rules SET `sub_type`='PluginFusioninventoryInventoryRuleImport'\n      WHERE `sub_type`='PluginFusioninventoryRuleImportEquipment'";
    $DB->query($query);
    $query = "SELECT * FROM `glpi_rules`\n               WHERE `sub_type`='PluginFusioninventoryInventoryRuleImport'";
    $result = $DB->query($query);
    while ($data = $DB->fetch_array($result)) {
        $querya = "UPDATE glpi_ruleactions SET `value`='1'\n         WHERE `rules_id`='" . $data['id'] . "'\n            AND `value`='0'\n            AND `field`='_fusion'";
        $DB->query($querya);
    }
    $query = "UPDATE glpi_rules SET `sub_type`='PluginFusioninventoryInventoryRuleEntity'\n      WHERE `sub_type`='PluginFusinvinventoryRuleEntity'";
    $DB->query($query);
    /*
     *  Add default rules
     */
    if (TableExists("glpi_plugin_tracker_config_discovery")) {
        $migration->displayMessage("Create rules");
        $pfSetup = new PluginFusioninventorySetup();
        $pfSetup->initRules();
    }
    // If no rules, add them
    if (countElementsInTable('glpi_rules', "`sub_type`='PluginFusioninventoryInventoryRuleImport'") == 0) {
        $migration->displayMessage("Create rules");
        $pfSetup = new PluginFusioninventorySetup();
        $pfSetup->initRules();
    }
    // Add peripheral rules (in first in rule list) when use it since 0.85
    $query = "DELETE FROM `glpi_plugin_fusioninventory_configs`" . " WHERE `type`='import_peripheral' ";
    $DB->query($query);
    $query = "UPDATE `glpi_rules` " . " SET `ranking` = `ranking`+3" . " WHERE `sub_type`='PluginFusioninventoryInventoryRuleImport' ";
    $ranking = 0;
    // Create rule for : Peripheral + serial
    $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection();
    $input = array();
    $input['is_active'] = 1;
    $input['name'] = 'Peripheral serial';
    $input['match'] = 'AND';
    $input['sub_type'] = 'PluginFusioninventoryInventoryRuleImport';
    $input['ranking'] = $ranking;
    $rule_id = $rulecollection->add($input);
    // Add criteria
    $rule = $rulecollection->getRuleClass();
    $rulecriteria = new RuleCriteria(get_class($rule));
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['criteria'] = "serial";
    $input['pattern'] = 1;
    $input['condition'] = 10;
    $rulecriteria->add($input);
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['criteria'] = "serial";
    $input['pattern'] = 1;
    $input['condition'] = 8;
    $rulecriteria->add($input);
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['criteria'] = "itemtype";
    $input['pattern'] = 'Peripheral';
    $input['condition'] = 0;
    $rulecriteria->add($input);
    // Add action
    $ruleaction = new RuleAction(get_class($rule));
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['action_type'] = 'assign';
    $input['field'] = '_fusion';
    $input['value'] = '1';
    $ruleaction->add($input);
    $ranking++;
    // Create rule for : Peripheral import
    $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection();
    $input = array();
    $input['is_active'] = 1;
    $input['name'] = 'Peripheral import';
    $input['match'] = 'AND';
    $input['sub_type'] = 'PluginFusioninventoryInventoryRuleImport';
    $input['ranking'] = $ranking;
    $rule_id = $rulecollection->add($input);
    // Add criteria
    $rule = $rulecollection->getRuleClass();
    $rulecriteria = new RuleCriteria(get_class($rule));
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['criteria'] = "itemtype";
    $input['pattern'] = 'Peripheral';
    $input['condition'] = 0;
    $rulecriteria->add($input);
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['criteria'] = "serial";
    $input['pattern'] = 1;
    $input['condition'] = 8;
    $rulecriteria->add($input);
    // Add action
    $ruleaction = new RuleAction(get_class($rule));
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['action_type'] = 'assign';
    $input['field'] = '_fusion';
    $input['value'] = '1';
    $ruleaction->add($input);
    $ranking++;
    // Create rule for : Peripheral ignore import
    $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection();
    $input = array();
    $input['is_active'] = 1;
    $input['name'] = 'Peripheral ignore import';
    $input['match'] = 'AND';
    $input['sub_type'] = 'PluginFusioninventoryInventoryRuleImport';
    $input['ranking'] = $ranking;
    $rule_id = $rulecollection->add($input);
    // Add criteria
    $rule = $rulecollection->getRuleClass();
    $rulecriteria = new RuleCriteria(get_class($rule));
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['criteria'] = "itemtype";
    $input['pattern'] = 'Peripheral';
    $input['condition'] = 0;
    $rulecriteria->add($input);
    // Add action
    $ruleaction = new RuleAction(get_class($rule));
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['action_type'] = 'assign';
    $input['field'] = '_ignore_import';
    $input['value'] = '1';
    $ruleaction->add($input);
    // Add monitor rules (in first in rule list) when use it since 0.85
    $query = "DELETE FROM `glpi_plugin_fusioninventory_configs`" . " WHERE `type`='import_monitor' ";
    $DB->query($query);
    $query = "UPDATE `glpi_rules` " . " SET `ranking` = `ranking`+3" . " WHERE `sub_type`='PluginFusioninventoryInventoryRuleImport' ";
    $ranking = 0;
    // Create rule for : Monitor + serial
    $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection();
    $input = array();
    $input['is_active'] = 1;
    $input['name'] = 'Monitor serial';
    $input['match'] = 'AND';
    $input['sub_type'] = 'PluginFusioninventoryInventoryRuleImport';
    $input['ranking'] = $ranking;
    $rule_id = $rulecollection->add($input);
    // Add criteria
    $rule = $rulecollection->getRuleClass();
    $rulecriteria = new RuleCriteria(get_class($rule));
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['criteria'] = "serial";
    $input['pattern'] = 1;
    $input['condition'] = 10;
    $rulecriteria->add($input);
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['criteria'] = "serial";
    $input['pattern'] = 1;
    $input['condition'] = 8;
    $rulecriteria->add($input);
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['criteria'] = "itemtype";
    $input['pattern'] = 'Monitor';
    $input['condition'] = 0;
    $rulecriteria->add($input);
    // Add action
    $ruleaction = new RuleAction(get_class($rule));
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['action_type'] = 'assign';
    $input['field'] = '_fusion';
    $input['value'] = '1';
    $ruleaction->add($input);
    $ranking++;
    // Create rule for : Monitor import
    $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection();
    $input = array();
    $input['is_active'] = 1;
    $input['name'] = 'Monitor import';
    $input['match'] = 'AND';
    $input['sub_type'] = 'PluginFusioninventoryInventoryRuleImport';
    $input['ranking'] = $ranking;
    $rule_id = $rulecollection->add($input);
    // Add criteria
    $rule = $rulecollection->getRuleClass();
    $rulecriteria = new RuleCriteria(get_class($rule));
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['criteria'] = "itemtype";
    $input['pattern'] = 'Monitor';
    $input['condition'] = 0;
    $rulecriteria->add($input);
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['criteria'] = "serial";
    $input['pattern'] = 1;
    $input['condition'] = 8;
    $rulecriteria->add($input);
    // Add action
    $ruleaction = new RuleAction(get_class($rule));
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['action_type'] = 'assign';
    $input['field'] = '_fusion';
    $input['value'] = '1';
    $ruleaction->add($input);
    $ranking++;
    // Create rule for : Monitor ignore import
    $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection();
    $input = array();
    $input['is_active'] = 1;
    $input['name'] = 'Monitor ignore import';
    $input['match'] = 'AND';
    $input['sub_type'] = 'PluginFusioninventoryInventoryRuleImport';
    $input['ranking'] = $ranking;
    $rule_id = $rulecollection->add($input);
    // Add criteria
    $rule = $rulecollection->getRuleClass();
    $rulecriteria = new RuleCriteria(get_class($rule));
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['criteria'] = "itemtype";
    $input['pattern'] = 'Monitor';
    $input['condition'] = 0;
    $rulecriteria->add($input);
    // Add action
    $ruleaction = new RuleAction(get_class($rule));
    $input = array();
    $input['rules_id'] = $rule_id;
    $input['action_type'] = 'assign';
    $input['field'] = '_ignore_import';
    $input['value'] = '1';
    $ruleaction->add($input);
    // Add printer rules (in first in rule list) when use it since 0.85
    $query = "DELETE FROM `glpi_plugin_fusioninventory_configs`" . " WHERE `type`='import_printer' ";
    /*
     *  Manage configuration of plugin
     */
    $config = new PluginFusioninventoryConfig();
    $pfSetup = new PluginFusioninventorySetup();
    $users_id = $pfSetup->createFusionInventoryUser();
    $a_input = array();
    $a_input['ssl_only'] = 0;
    $a_input['delete_task'] = 20;
    $a_input['inventory_frequence'] = 24;
    $a_input['agent_port'] = 62354;
    $a_input['extradebug'] = 0;
    $a_input['users_id'] = $users_id;
    $a_input['agents_old_days'] = 0;
    $config->addValues($a_input, FALSE);
    //      $DB->query("DELETE FROM `glpi_plugin_fusioninventory_configs`
    //        WHERE `plugins_id`='0'");
    //      $query = "SELECT * FROM `glpi_plugin_fusioninventory_configs`
    //           WHERE `type`='version'
    //           LIMIT 1, 10";
    //      $result = $DB->query($query);
    //      while ($data=$DB->fetch_array($result)) {
    //         $config->delete($data);
    //      }
    $a_input = array();
    $a_input['version'] = PLUGIN_FUSIONINVENTORY_VERSION;
    $config->addValues($a_input, TRUE);
    $a_input = array();
    $a_input['ssl_only'] = 0;
    if (isset($prepare_Config['ssl_only'])) {
        $a_input['ssl_only'] = $prepare_Config['ssl_only'];
    }
    $a_input['delete_task'] = 20;
    $a_input['inventory_frequence'] = 24;
    $a_input['agent_port'] = 62354;
    $a_input['extradebug'] = 0;
    $a_input['users_id'] = 0;
    //Deploy configuration options
    $a_input['server_upload_path'] = Toolbox::addslashes_deep(implode(DIRECTORY_SEPARATOR, array(GLPI_PLUGIN_DOC_DIR, 'fusioninventory', 'upload')));
    $a_input['alert_winpath'] = 1;
    $a_input['server_as_mirror'] = 1;
    $config->addValues($a_input, FALSE);
    $pfSetup = new PluginFusioninventorySetup();
    $users_id = $pfSetup->createFusionInventoryUser();
    $query = "UPDATE `glpi_plugin_fusioninventory_configs`\n                         SET `value`='" . $users_id . "'\n                  WHERE `type`='users_id'";
    $DB->query($query);
    // Update fusinvinventory _config values to this plugin
    $input = array();
    $input['import_software'] = 1;
    $input['import_volume'] = 1;
    $input['import_antivirus'] = 1;
    $input['import_registry'] = 1;
    $input['import_process'] = 1;
    $input['import_vm'] = 1;
    $input['component_processor'] = 1;
    $input['component_memory'] = 1;
    $input['component_harddrive'] = 1;
    $input['component_networkcard'] = 1;
    $input['component_graphiccard'] = 1;
    $input['component_soundcard'] = 1;
    $input['component_drive'] = 1;
    $input['component_networkdrive'] = 1;
    $input['component_control'] = 1;
    $input['states_id_default'] = 0;
    $input['location'] = 0;
    $input['group'] = 0;
    $input['component_networkcardvirtual'] = 1;
    $config->addValues($input, FALSE);
    // Add new config values if not added
    $input = $config->initConfigModule(TRUE);
    foreach ($input as $name => $value) {
        $a_conf = $config->find("`type`='" . $name . "'");
        if (count($a_conf) == 0) {
            $config->add(array('type' => $name, 'value' => $value));
        }
    }
    $migration->displayMessage("Clean printers");
    /*
     * Remove / at the end of printers (bugs in older versions of agents.
     */
    $printer = new Printer();
    $query = "SELECT * FROM `glpi_printers`\n         WHERE `serial` LIKE '%/' ";
    $result = $DB->query($query);
    while ($data = $DB->fetch_array($result)) {
        $cleanSerial = preg_replace('/\\/$/', '', $data['serial']);
        $querynb = "SELECT * FROM `glpi_printers`\n            WHERE `serial`='" . $cleanSerial . "'\n            LIMIT 1";
        $resultnb = $DB->query($querynb);
        if ($DB->numrows($resultnb) == '0') {
            $input = array();
            $input['id'] = $data['id'];
            $input["serial"] = $cleanSerial;
            $printer->update($input);
        }
    }
    /*
     * Update blacklist
     */
    $input = array();
    $input['03000200-0400-0500-0006-000700080009'] = '2';
    $input['6AB5B300-538D-1014-9FB5-B0684D007B53'] = '2';
    $input['01010101-0101-0101-0101-010101010101'] = '2';
    $input['20:41:53:59:4e:ff'] = '3';
    $input['02:00:4e:43:50:49'] = '3';
    $input['e2:e6:16:20:0a:35'] = '3';
    $input['d2:0a:2d:a0:04:be'] = '3';
    $input['00:a0:c6:00:00:00'] = '3';
    $input['d2:6b:25:2f:2c:e7'] = '3';
    $input['33:50:6f:45:30:30'] = '3';
    $input['0a:00:27:00:00:00'] = '3';
    $input['00:50:56:C0:00:01'] = '3';
    $input['00:50:56:C0:00:02'] = '3';
    $input['00:50:56:C0:00:03'] = '3';
    $input['00:50:56:C0:00:04'] = '3';
    $input['00:50:56:C0:00:08'] = '3';
    $input['FE:FF:FF:FF:FF:FF'] = '3';
    $input['00:00:00:00:00:00'] = '3';
    $input['00:0b:ca:fe:00:00'] = '3';
    $input['02:80:37:EC:02:00'] = '3';
    $input['MB-1234567890'] = '1';
    $input['Not Specified'] = '1';
    $input['OEM_Serial'] = '1';
    $input['SystemSerialNumb'] = '1';
    $input['Not'] = '2';
    foreach ($input as $value => $type) {
        $query = "SELECT * FROM `glpi_plugin_fusioninventory_inventorycomputerblacklists`\n         WHERE `plugin_fusioninventory_criterium_id`='" . $type . "'\n          AND `value`='" . $value . "'";
        $result = $DB->query($query);
        if ($DB->numrows($result) == '0') {
            $query = "INSERT INTO `glpi_plugin_fusioninventory_inventorycomputerblacklists`\n            (`plugin_fusioninventory_criterium_id`, `value`) VALUES\n            ( '" . $type . "', '" . $value . "')";
            $DB->query($query);
        }
    }
    $migration->displayMessage("Add Crontasks");
    /*
     * Add Crontask if not exist
     */
    $crontask = new CronTask();
    if ($crontask->getFromDBbyName('PluginFusioninventoryTaskjob', 'taskscheduler')) {
        $crontask->fields['itemtype'] = 'PluginFusioninventoryTask';
        $crontask->updateInDB(array('itemtype'));
    }
    if (!$crontask->getFromDBbyName('PluginFusioninventoryTask', 'taskscheduler')) {
        CronTask::Register('PluginFusioninventoryTask', 'taskscheduler', '60', array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30));
    }
    if ($crontask->getFromDBbyName('PluginFusioninventoryTaskjobstate', 'cleantaskjob') and $crontask->getFromDBbyName('PluginFusioninventoryTaskjobstatus', 'cleantaskjob')) {
        $crontask->getFromDBbyName('PluginFusioninventoryTaskjobstatus', 'cleantaskjob');
        $crontask->delete($crontask->fields);
    }
    if ($crontask->getFromDBbyName('PluginFusioninventoryTaskjobstatus', 'cleantaskjob')) {
        $query = "UPDATE `glpi_crontasks` SET `itemtype`='PluginFusioninventoryTaskjobstate'\n         WHERE `itemtype`='PluginFusioninventoryTaskjobstatus'";
        $DB->query($query);
    }
    if (!$crontask->getFromDBbyName('PluginFusioninventoryTaskjobstate', 'cleantaskjob')) {
        Crontask::Register('PluginFusioninventoryTaskjobstate', 'cleantaskjob', 3600 * 24, array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30));
    }
    if ($crontask->getFromDBbyName('PluginFusinvsnmpNetworkPortLog', 'cleannetworkportlogs')) {
        $crontask->delete($crontask->fields);
    }
    if (!$crontask->getFromDBbyName('PluginFusioninventoryNetworkPortLog', 'cleannetworkportlogs')) {
        Crontask::Register('PluginFusioninventoryNetworkPortLog', 'cleannetworkportlogs', 3600 * 24, array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30));
    }
    if ($crontask->getFromDBbyName('PluginFusioninventoryConfigurationManagement', 'checkdevices')) {
        $crontask->delete($crontask->fields);
    }
    if (!$crontask->getFromDBbyName('PluginFusioninventoryAgent', 'cleanoldagents')) {
        Crontask::Register('PluginFusioninventoryAgent', 'cleanoldagents', 86400, array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30, 'hourmin' => 22, 'hourmax' => 6, 'comment' => 'Clean agents not contacted since xxx days'));
    }
    /*
     * Update task's agents list from dynamic group periodically in order to automatically target new
     * computer.
     */
    if (!$crontask->getFromDBbyName('PluginFusioninventoryTaskjob', 'updatedynamictasks')) {
        CronTask::Register('PluginFusioninventoryTaskjob', 'updatedynamictasks', '60', array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30, 'state' => 0));
    }
    if (!$crontask->getFromDBbyName('PluginFusioninventoryAgentWakeup', 'wakeupAgents')) {
        Crontask::Register('PluginFusioninventoryAgentWakeup', 'wakeupAgents', 120, array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30, 'comment' => 'Wake agents ups'));
    }
    /**
     * Add field to manage which group can be refreshed by updatedynamictasks crontask
     */
    if (!FieldExists('glpi_plugin_fusioninventory_deploygroups_dynamicdatas', 'can_update_group')) {
        $migration->addField('glpi_plugin_fusioninventory_deploygroups_dynamicdatas', 'can_update_group', 'bool');
        $migration->addKey('glpi_plugin_fusioninventory_deploygroups_dynamicdatas', 'can_update_group');
        $migration->migrationOneTable('glpi_plugin_fusioninventory_deploygroups_dynamicdatas');
    }
    //   $pfIgnoredimportdevice = new PluginFusioninventoryIgnoredimportdevice();
    //   $pfIgnoredimportdevice->install();
    //Change static & dynamic structure to fit the GLPI framework
    $migration->changeField('glpi_plugin_fusioninventory_deploygroups_dynamicdatas', 'groups_id', 'plugin_fusioninventory_deploygroups_id', 'integer');
    $migration->migrationOneTable('glpi_plugin_fusioninventory_deploygroups_dynamicdatas');
    $migration->changeField('glpi_plugin_fusioninventory_deploygroups_staticdatas', 'groups_id', 'plugin_fusioninventory_deploygroups_id', 'integer');
    $migration->migrationOneTable('glpi_plugin_fusioninventory_deploygroups_staticdatas');
    // Delete data in glpi_logs(agent problem => ticket http://forge.fusioninventory.org/issues/1546)
    // ** Token
    $query = "DELETE FROM `glpi_logs`\n      WHERE `itemtype`='PluginFusioninventoryAgent'\n         AND `id_search_option`='9'";
    $DB->query($query);
    // ** Last contact
    $query = "DELETE FROM `glpi_logs`\n      WHERE `itemtype`='PluginFusioninventoryAgent'\n         AND `id_search_option`='4'";
    $DB->query($query);
    // ** Version
    $query = "DELETE FROM `glpi_logs`\n      WHERE `itemtype`='PluginFusioninventoryAgent'\n         AND `id_search_option`='8'\n         AND `old_value`=`new_value`";
    $DB->query($query);
    /*
     * Manage devices with is_dynamic
     */
    $query = "SELECT * FROM `glpi_plugin_fusioninventory_networkequipments`";
    $result = $DB->query($query);
    while ($data = $DB->fetch_array($result)) {
        $DB->query("UPDATE `glpi_networkequipments` SET `is_dynamic`='1'\n                        WHERE `id`='" . $data['networkequipments_id'] . "'");
    }
    $query = "SELECT * FROM `glpi_plugin_fusioninventory_inventorycomputercomputers`";
    $result = $DB->query($query);
    while ($data = $DB->fetch_array($result)) {
        $DB->query("UPDATE `glpi_computers` SET `is_dynamic`='1'\n                        WHERE `id`='" . $data['computers_id'] . "'");
    }
    $query = "SELECT * FROM `glpi_plugin_fusioninventory_printers`";
    $result = $DB->query($query);
    while ($data = $DB->fetch_array($result)) {
        $DB->query("UPDATE `glpi_printers` SET `is_dynamic`='1'\n                        WHERE `id`='" . $data['printers_id'] . "'");
    }
    // Update networkports types
    $pfNetworkporttype = new PluginFusioninventoryNetworkporttype();
    $pfNetworkporttype->init();
    if (TableExists('glpi_plugin_fusioninventory_profiles')) {
        //Migrate rights to the new system introduction in GLPI 0.85
        PluginFusioninventoryProfile::migrateProfiles();
        //Drop old table
        $migration->dropTable('glpi_plugin_fusioninventory_profiles');
    }
    //Create first access to the current profile is needed
    if (isset($_SESSION['glpiactiveprofile'])) {
        PluginFusioninventoryProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
    }
    // Define lastup field of fusion networkports
    $query = "SELECT * FROM `glpi_plugin_fusioninventory_mappings`\n      WHERE `name`='ifstatus'\n      LIMIT 1";
    $result = $DB->query($query);
    while ($data = $DB->fetch_array($result)) {
        $query_np = "SELECT * FROM `glpi_plugin_fusioninventory_networkports`";
        $result_np = $DB->query($query_np);
        while ($data_np = $DB->fetch_array($result_np)) {
            $query_nplog = "SELECT * FROM `glpi_plugin_fusioninventory_networkportlogs`\n            WHERE `networkports_id`='" . $data_np['networkports_id'] . "'\n               AND `plugin_fusioninventory_mappings_id`='" . $data['id'] . "'\n            ORDER BY `date_mod` DESC\n            LIMIT 1";
            $result_nplog = $DB->query($query_nplog);
            while ($data_nplog = $DB->fetch_array($result_nplog)) {
                $DB->query("UPDATE `glpi_plugin_fusioninventory_networkports`\n               SET `lastup`='" . $data_nplog['date_mod'] . "'\n               WHERE `id`='" . $data_np['id'] . "'");
            }
        }
    }
    //Migrate search params for dynamic groups
    doDynamicDataSearchParamsMigration();
}
Ejemplo n.º 23
0
function plugin_example_install()
{
    global $DB;
    $config = new Config();
    $config->setConfigurationValues('plugin:Example', array('configuration' => false));
    ProfileRight::addProfileRights(array('example:read'));
    if (!TableExists("glpi_plugin_example_examples")) {
        $query = "CREATE TABLE `glpi_plugin_example_examples` (\n                  `id` int(11) NOT NULL auto_increment,\n                  `name` varchar(255) collate utf8_unicode_ci default NULL,\n                  `serial` varchar(255) collate utf8_unicode_ci NOT NULL,\n                  `plugin_example_dropdowns_id` int(11) NOT NULL default '0',\n                  `is_deleted` tinyint(1) NOT NULL default '0',\n                  `is_template` tinyint(1) NOT NULL default '0',\n                  `template_name` varchar(255) collate utf8_unicode_ci default NULL,\n                PRIMARY KEY (`id`)\n               ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query) or die("error creating glpi_plugin_example_examples " . $DB->error());
        $query = "INSERT INTO `glpi_plugin_example_examples`\n                       (`id`, `name`, `serial`, `plugin_example_dropdowns_id`, `is_deleted`,\n                        `is_template`, `template_name`)\n                VALUES (1, 'example 1', 'serial 1', 1, 0, 0, NULL),\n                       (2, 'example 2', 'serial 2', 2, 0, 0, NULL),\n                       (3, 'example 3', 'serial 3', 1, 0, 0, NULL)";
        $DB->query($query) or die("error populate glpi_plugin_example " . $DB->error());
    }
    if (!TableExists("glpi_plugin_example_dropdowns")) {
        $query = "CREATE TABLE `glpi_plugin_example_dropdowns` (\n                  `id` int(11) NOT NULL auto_increment,\n                  `name` varchar(255) collate utf8_unicode_ci default NULL,\n                  `comment` text collate utf8_unicode_ci,\n                PRIMARY KEY  (`id`),\n                KEY `name` (`name`)\n               ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query) or die("error creating glpi_plugin_example_dropdowns" . $DB->error());
        $query = "INSERT INTO `glpi_plugin_example_dropdowns`\n                       (`id`, `name`, `comment`)\n                VALUES (1, 'dp 1', 'comment 1'),\n                       (2, 'dp2', 'comment 2')";
        $DB->query($query) or die("error populate glpi_plugin_example_dropdowns" . $DB->error());
    }
    if (!TableExists('glpi_plugin_example_devicecameras')) {
        $query = "CREATE TABLE `glpi_plugin_example_devicecameras` (\n                  `id` int(11) NOT NULL AUTO_INCREMENT,\n                  `designation` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,\n                  `comment` text COLLATE utf8_unicode_ci,\n                  `manufacturers_id` int(11) NOT NULL DEFAULT '0',\n                  PRIMARY KEY (`id`),\n                  KEY `designation` (`designation`),\n                  KEY `manufacturers_id` (`manufacturers_id`)\n                ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query) or die("error creating glpi_plugin_example_examples " . $DB->error());
    }
    if (!TableExists('glpi_plugin_example_items_devicecameras')) {
        $query = "CREATE TABLE `glpi_plugin_example_items_devicecameras` (\n                  `id` int(11) NOT NULL AUTO_INCREMENT,\n                  `items_id` int(11) NOT NULL DEFAULT '0',\n                  `itemtype` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,\n                  `plugin_example_devicecameras_id` int(11) NOT NULL DEFAULT '0',\n                  `is_deleted` tinyint(1) NOT NULL DEFAULT '0',\n                  `is_dynamic` tinyint(1) NOT NULL DEFAULT '0',\n                  PRIMARY KEY (`id`),\n                  KEY `computers_id` (`items_id`),\n                  KEY `plugin_example_devicecameras_id` (`plugin_example_devicecameras_id`),\n                  KEY `is_deleted` (`is_deleted`),\n                  KEY `is_dynamic` (`is_dynamic`)\n                ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->query($query) or die("error creating glpi_plugin_example_examples " . $DB->error());
    }
    // To be called for each task the plugin manage
    // task in class
    CronTask::Register('PluginExampleExample', 'Sample', DAY_TIMESTAMP, array('param' => 50));
    return true;
}