示例#1
0
function plugin_typology_uninstall()
{
    global $DB;
    // Plugin tables deletion
    $tables = array("glpi_plugin_typology_profiles", "glpi_plugin_typology_typologies", "glpi_plugin_typology_typologycriterias", "glpi_plugin_typology_typologycriteriadefinitions", "glpi_plugin_typology_typologies_items");
    foreach ($tables as $table) {
        $DB->query("DROP TABLE IF EXISTS `{$table}`;");
    }
    // Plugin adding information on general table deletion
    $tables_glpi = array("glpi_displaypreferences", "glpi_documents_items", "glpi_bookmarks", "glpi_logs");
    foreach ($tables_glpi as $table_glpi) {
        $DB->query("DELETE FROM `{$table_glpi}` WHERE `itemtype` = 'PluginTypologyTypology';");
    }
    //drop rules
    $Rule = new Rule();
    $a_rules = $Rule->find("`sub_type`='PluginTypologyRuleTypology'");
    foreach ($a_rules as $data) {
        $Rule->delete($data);
    }
    $notif = new Notification();
    $options = array('itemtype' => 'PluginTypologyTypology', 'event' => 'AlertNotValidatedTypology', 'FIELDS' => 'id');
    foreach ($DB->request('glpi_notifications', $options) as $data) {
        $notif->delete($data);
    }
    return true;
}
 protected function doExecute()
 {
     $params = array('url' => $this->url);
     if ($this->group !== '') {
         $params['group'] = $this->group;
     } else {
         $params['group'] = null;
     }
     $rules = Rule::find(array($params));
     if ($rules) {
         $contextMap = array(RuleConditionExpressionOperand::CONTEXT_TYPE_REQUEST => $_REQUEST, RuleConditionExpressionOperand::CONTEXT_TYPE_GET => $_GET, RuleConditionExpressionOperand::CONTEXT_TYPE_POST => $_POST, RuleConditionExpressionOperand::CONTEXT_TYPE_HEADER => HttpUtils::getHttpHeaders(), RuleConditionExpressionOperand::CONTEXT_TYPE_COOKIE => $_COOKIE);
         $matcher = new RuleResponseMatcher();
         foreach ($rules as $rule) {
             $res = $matcher->match($rule, $contextMap);
             if (isset($res)) {
                 if (is_array($res) || is_object($res)) {
                     $this->setReturnType(self::RETURN_TYPE_JSON);
                     return $this->success($rule->res);
                 } else {
                     return $res;
                 }
             }
         }
     }
     $this->setReturnType(self::RETURN_TYPE_JSON);
     return $this->error(1, 'can\'t match any url for [' . $this->url . ']');
 }
 protected function doExecute()
 {
     $params = array();
     foreach ($this->get() as $key => $val) {
         if (!empty($val) && in_array($key, array('url', '_id', 'tag', 'group', 'page', 'pageSize'))) {
             $params[$key] = $val;
         }
     }
     if (!empty($params['_id'])) {
         $id = new MongoId($params['_id']);
         $params['_id'] = (object) $id;
     }
     $pageSize = $params['pageSize'];
     $page = $params['page'];
     if (isset($pageSize)) {
         unset($params['pageSize']);
         $page += 0;
         if ($pageSize < self::MIN_PAGE_SIZE) {
             $pageSize = 1;
         } else {
             if ($pageSize > self::MAX_PAGE_SIZE) {
                 $pageSize = self::MAX_PAGE_SIZE;
             }
         }
     }
     if (isset($page)) {
         if (!isset($pageSize)) {
             $pageSize = self::DEFAULT_PAGE_SIZE;
         }
         unset($params['page']);
         $page += 0;
         if ($page <= 0) {
             $page = 1;
         }
         $queryParams = array('conditions' => $params, 'sort' => array('url' => 1), 'limit' => $pageSize, 'skip' => $pageSize * ($page - 1));
     } else {
         $queryParams = array('conditions' => $params, 'sort' => array('url' => 1));
     }
     $result = array('count' => Rule::count(array('conditions' => $params)), 'list' => Rule::find($queryParams));
     if (isset($page)) {
         $result['page'] = $page;
         $result['pageSize'] = $pageSize;
         if ($result['count'] > 0) {
             $result['totalPage'] = ceil($result['count'] / $pageSize);
         } else {
             $result['totalPage'] = 0;
         }
     }
     return $this->success($result);
 }
 public function beforeSave($rule)
 {
     if (empty($rule->url)) {
         throw new MockApiException('url is not set', ErrorInfo::ERROR_NO_INVALID_PARAM);
     }
     if (empty($rule->res)) {
         throw new MockApiException('res is not set', ErrorInfo::ERROR_NO_INVALID_PARAM);
     }
     $condition = array('url' => $rule->url);
     if ($rule->group !== '') {
         $condition['group'] = $rule->group;
     } else {
         $condition['group'] = $rule->null;
     }
     $list = Rule::find(array($condition));
     if (!empty($list)) {
         throw new MockApiException('rule has been existed' . ($rule->group ? ' in group [' . $rule->group . ']' : ''), ErrorInfo::ERROR_NO_INVALID_PARAM);
     }
 }
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";
}
 /**
  * Create rules (initialisation)
  */
 function initRules($reset = 0)
 {
     if ($reset == 1) {
         $grule = new Rule();
         $a_rules = $grule->find("`sub_type`='PluginFusioninventoryInventoryRuleImport'");
         foreach ($a_rules as $data) {
             $grule->delete($data);
         }
     }
     $rules = array();
     $rules[] = array('name' => 'Computer constraint (name)', 'match' => 'AND', 'is_active' => 1, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'Computer'), array('criteria' => 'name', 'condition' => 9, 'pattern' => 1)), 'action' => '_fusion2');
     $rules[] = array('name' => 'Computer update (by serial + uuid)', 'match' => 'AND', 'is_active' => 1, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'Computer'), array('criteria' => 'serial', 'condition' => 10, 'pattern' => 1), array('criteria' => 'serial', 'condition' => 8, 'pattern' => 1), array('criteria' => 'uuid', 'condition' => 10, 'pattern' => 1), array('criteria' => 'uuid', 'condition' => 8, 'pattern' => 1)), 'action' => '_fusion1');
     $rules[] = array('name' => 'Computer update (by serial)', 'match' => 'AND', 'is_active' => 1, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'Computer'), array('criteria' => 'serial', 'condition' => 10, 'pattern' => 1), array('criteria' => 'serial', 'condition' => 8, 'pattern' => 1)), 'action' => '_fusion1');
     $rules[] = array('name' => 'Computer update (by uuid)', 'match' => 'AND', 'is_active' => 0, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'Computer'), array('criteria' => 'uuid', 'condition' => 10, 'pattern' => 1), array('criteria' => 'uuid', 'condition' => 8, 'pattern' => 1)), 'action' => '_fusion1');
     $rules[] = array('name' => 'Computer update (by mac)', 'match' => 'AND', 'is_active' => 0, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'Computer'), array('criteria' => 'mac', 'condition' => 10, 'pattern' => 1), array('criteria' => 'mac', 'condition' => 8, 'pattern' => 1)), 'action' => '_fusion1');
     $rules[] = array('name' => 'Computer update (by name)', 'match' => 'AND', 'is_active' => 0, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'Computer'), array('criteria' => 'name', 'condition' => 10, 'pattern' => 1), array('criteria' => 'name', 'condition' => 8, 'pattern' => 1)), 'action' => '_fusion1');
     $rules[] = array('name' => 'Computer import (by serial + uuid)', 'match' => 'AND', 'is_active' => 1, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'Computer'), array('criteria' => 'uuid', 'condition' => 8, 'pattern' => 1), array('criteria' => 'serial', 'condition' => 8, 'pattern' => 1)), 'action' => '_fusion1');
     $rules[] = array('name' => 'Computer import (by serial)', 'match' => 'AND', 'is_active' => 1, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'Computer'), array('criteria' => 'serial', 'condition' => 8, 'pattern' => 1)), 'action' => '_fusion1');
     $rules[] = array('name' => 'Computer import (by uuid)', 'match' => 'AND', 'is_active' => 0, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'Computer'), array('criteria' => 'uuid', 'condition' => 8, 'pattern' => 1)), 'action' => '_fusion1');
     $rules[] = array('name' => 'Computer import (by mac)', 'match' => 'AND', 'is_active' => 0, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'Computer'), array('criteria' => 'mac', 'condition' => 8, 'pattern' => 1)), 'action' => '_fusion1');
     $rules[] = array('name' => 'Computer import (by name)', 'match' => 'AND', 'is_active' => 1, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'Computer'), array('criteria' => 'name', 'condition' => 8, 'pattern' => 1)), 'action' => '_fusion1');
     $rules[] = array('name' => 'Computer import denied', 'match' => 'AND', 'is_active' => 1, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'Computer')), 'action' => '_fusion2');
     $rules[] = array('name' => 'Printer constraint (name)', 'match' => 'AND', 'is_active' => 1, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'Printer'), array('criteria' => 'name', 'condition' => 9, 'pattern' => 1)), 'action' => '_fusion2');
     $rules[] = array('name' => 'Printer update (by serial)', 'match' => 'AND', 'is_active' => 1, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'Printer'), array('criteria' => 'serial', 'condition' => 8, 'pattern' => 1), array('criteria' => 'serial', 'condition' => 10, 'pattern' => 1)), 'action' => '_fusion1');
     $rules[] = array('name' => 'Printer update (by mac)', 'match' => 'AND', 'is_active' => 0, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'Printer'), array('criteria' => 'mac', 'condition' => 8, 'pattern' => 1), array('criteria' => 'mac', 'condition' => 10, 'pattern' => 1)), 'action' => '_fusion1');
     $rules[] = array('name' => 'Printer import (by serial)', 'match' => 'AND', 'is_active' => 1, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'Printer'), array('criteria' => 'serial', 'condition' => 8, 'pattern' => 1)), 'action' => '_fusion1');
     $rules[] = array('name' => 'Printer import (by mac)', 'match' => 'AND', 'is_active' => 0, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'Printer'), array('criteria' => 'mac', 'condition' => 8, 'pattern' => 1)), 'action' => '_fusion1');
     $rules[] = array('name' => 'Printer import denied', 'match' => 'AND', 'is_active' => 1, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'Printer')), 'action' => '_fusion2');
     $rules[] = array('name' => 'NetworkEquipment constraint (name)', 'match' => 'AND', 'is_active' => 1, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'NetworkEquipment'), array('criteria' => 'name', 'condition' => 9, 'pattern' => 1)), 'action' => '_fusion2');
     $rules[] = array('name' => 'NetworkEquipment import (by serial)', 'match' => 'AND', 'is_active' => 1, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'NetworkEquipment'), array('criteria' => 'serial', 'condition' => 8, 'pattern' => 1), array('criteria' => 'serial', 'condition' => 10, 'pattern' => 1)), 'action' => '_fusion1');
     $rules[] = array('name' => 'NetworkEquipment update (by mac)', 'match' => 'AND', 'is_active' => 0, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'NetworkEquipment'), array('criteria' => 'mac', 'condition' => 8, 'pattern' => 1), array('criteria' => 'mac', 'condition' => 10, 'pattern' => 1)), 'action' => '_fusion1');
     $rules[] = array('name' => 'NetworkEquipment import (by serial)', 'match' => 'AND', 'is_active' => 1, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'NetworkEquipment'), array('criteria' => 'serial', 'condition' => 8, 'pattern' => 1)), 'action' => '_fusion1');
     $rules[] = array('name' => 'NetworkEquipment import (by mac)', 'match' => 'AND', 'is_active' => 0, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'NetworkEquipment'), array('criteria' => 'mac', 'condition' => 8, 'pattern' => 1)), 'action' => '_fusion1');
     $rules[] = array('name' => 'NetworkEquipment import denied', 'match' => 'AND', 'is_active' => 1, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'NetworkEquipment')), 'action' => '_fusion2');
     $rules[] = array('name' => 'Peripheral update (by serial)', 'match' => 'AND', 'is_active' => 1, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'Peripheral'), array('criteria' => 'serial', 'condition' => 8, 'pattern' => 1), array('criteria' => 'serial', 'condition' => 10, 'pattern' => 1)), 'action' => '_fusion1');
     $rules[] = array('name' => 'Peripheral import (by serial)', 'match' => 'AND', 'is_active' => 1, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'Peripheral'), array('criteria' => 'serial', 'condition' => 8, 'pattern' => 1)), 'action' => '_fusion1');
     $rules[] = array('name' => 'Peripheral import denied', 'match' => 'AND', 'is_active' => 1, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'Peripheral')), 'action' => '_fusion2');
     $rules[] = array('name' => 'Monitor update (by serial)', 'match' => 'AND', 'is_active' => 1, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'Monitor'), array('criteria' => 'serial', 'condition' => 8, 'pattern' => 1), array('criteria' => 'serial', 'condition' => 10, 'pattern' => 1)), 'action' => '_fusion1');
     $rules[] = array('name' => 'Monitor import (by serial)', 'match' => 'AND', 'is_active' => 1, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'Monitor'), array('criteria' => 'serial', 'condition' => 8, 'pattern' => 1)), 'action' => '_fusion1');
     $rules[] = array('name' => 'Monitor import denied', 'match' => 'AND', 'is_active' => 1, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'Monitor')), 'action' => '_fusion2');
     $rules[] = array('name' => 'Phone constraint (name)', 'match' => 'AND', 'is_active' => 0, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'Phone'), array('criteria' => 'name', 'condition' => 9, 'pattern' => 1)), 'action' => '_fusion2');
     $rules[] = array('name' => 'Phone update (by mac)', 'match' => 'AND', 'is_active' => 0, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'Phone'), array('criteria' => 'mac', 'condition' => 10, 'pattern' => 1), array('criteria' => 'mac', 'condition' => 8, 'pattern' => 1)), 'action' => '_fusion1');
     $rules[] = array('name' => 'Phone import (by mac)', 'match' => 'AND', 'is_active' => 0, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'Phone'), array('criteria' => 'mac', 'condition' => 8, 'pattern' => 1)), 'action' => '_fusion1');
     $rules[] = array('name' => 'Phone import denied', 'match' => 'AND', 'is_active' => 0, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => 'Phone')), 'action' => '_fusion2');
     $rules[] = array('name' => 'Global constraint (name)', 'match' => 'AND', 'is_active' => 1, 'criteria' => array(array('criteria' => 'name', 'condition' => 9, 'pattern' => 1)), 'action' => '_fusion2');
     $rules[] = array('name' => 'Global update (by serial)', 'match' => 'AND', 'is_active' => 1, 'criteria' => array(array('criteria' => 'serial', 'condition' => 8, 'pattern' => 1), array('criteria' => 'serial', 'condition' => 10, 'pattern' => 1)), 'action' => '_fusion1');
     $rules[] = array('name' => 'Global update (by mac)', 'match' => 'AND', 'is_active' => 0, 'criteria' => array(array('criteria' => 'mac', 'condition' => 8, 'pattern' => 1), array('criteria' => 'mac', 'condition' => 10, 'pattern' => 1)), 'action' => '_fusion1');
     $rules[] = array('name' => 'Global import (by serial)', 'match' => 'AND', 'is_active' => 1, 'criteria' => array(array('criteria' => 'serial', 'condition' => 8, 'pattern' => 1)), 'action' => '_fusion1');
     $rules[] = array('name' => 'Global import (by mac)', 'match' => 'AND', 'is_active' => 0, 'criteria' => array(array('criteria' => 'mac', 'condition' => 8, 'pattern' => 1)), 'action' => '_fusion1');
     $rules[] = array('name' => 'Global import denied', 'match' => 'AND', 'is_active' => 1, 'criteria' => array(array('criteria' => 'itemtype', 'condition' => 0, 'pattern' => '')), 'action' => '_fusion2');
     $ranking = 0;
     foreach ($rules as $rule) {
         $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection();
         $input = array();
         $input['is_active'] = $rule['is_active'];
         $input['name'] = $rule['name'];
         $input['match'] = $rule['match'];
         $input['sub_type'] = 'PluginFusioninventoryInventoryRuleImport';
         $input['ranking'] = $ranking;
         $rule_id = $rulecollection->add($input);
         // Add criteria
         $rulefi = $rulecollection->getRuleClass();
         foreach ($rule['criteria'] as $criteria) {
             $rulecriteria = new RuleCriteria(get_class($rulefi));
             $criteria['rules_id'] = $rule_id;
             $rulecriteria->add($criteria);
         }
         // Add action
         $ruleaction = new RuleAction(get_class($rulefi));
         $input = array();
         $input['rules_id'] = $rule_id;
         $input['action_type'] = 'assign';
         if ($rule['action'] == '_fusion1') {
             $input['field'] = '_fusion';
             $input['value'] = '1';
         } else {
             if ($rule['action'] == '_fusion2') {
                 $input['field'] = '_fusion';
                 $input['value'] = '2';
             } else {
                 if ($rule['action'] == '_ignore_import') {
                     $input['field'] = '_ignore_import';
                     $input['value'] = '1';
                 }
             }
         }
         $ruleaction->add($input);
         $ranking++;
     }
     return true;
     // Old rules
     $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);
     $ranking++;
     // 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);
     $ranking++;
     // Create rule for : Computer + serial + uuid
     $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection();
     $input = array();
     $input['is_active'] = 1;
     $input['name'] = 'Computer serial + uuid';
     $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'] = "uuid";
     $input['pattern'] = 1;
     $input['condition'] = 10;
     $rulecriteria->add($input);
     $input = array();
     $input['rules_id'] = $rule_id;
     $input['criteria'] = "uuid";
     $input['pattern'] = 1;
     $input['condition'] = 8;
     $rulecriteria->add($input);
     $input = array();
     $input['rules_id'] = $rule_id;
     $input['criteria'] = "itemtype";
     $input['pattern'] = 'Computer';
     $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 : Computer + serial
     $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection();
     $input = array();
     $input['is_active'] = 1;
     $input['name'] = 'Computer 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'] = 'Computer';
     $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++;
     $ranking++;
     // Create rule for : Computer + mac
     $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection();
     $input = array();
     $input['is_active'] = 0;
     $input['name'] = 'Computer mac';
     $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'] = "mac";
     $input['pattern'] = 1;
     $input['condition'] = 10;
     $rulecriteria->add($input);
     $input = array();
     $input['rules_id'] = $rule_id;
     $input['criteria'] = "mac";
     $input['pattern'] = 1;
     $input['condition'] = 8;
     $rulecriteria->add($input);
     $input = array();
     $input['rules_id'] = $rule_id;
     $input['criteria'] = "itemtype";
     $input['pattern'] = 'Computer';
     $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 : Computer + name
     $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection();
     $input = array();
     $input['is_active'] = 1;
     $input['name'] = 'Computer name';
     $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'] = "name";
     $input['pattern'] = 1;
     $input['condition'] = 10;
     $rulecriteria->add($input);
     $input = array();
     $input['rules_id'] = $rule_id;
     $input['criteria'] = "name";
     $input['pattern'] = 1;
     $input['condition'] = 8;
     $rulecriteria->add($input);
     $input = array();
     $input['rules_id'] = $rule_id;
     $input['criteria'] = "itemtype";
     $input['pattern'] = 'Computer';
     $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 : Computer import
     $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection();
     $input = array();
     $input['is_active'] = 1;
     $input['name'] = 'Computer 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'] = 'Computer';
     $input['condition'] = 0;
     $rulecriteria->add($input);
     //         $input = array();
     //         $input['rules_id'] = $rule_id;
     //         $input['criteria'] = "name";
     //         $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 : Printer + serial
     $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection();
     $input = array();
     $input['is_active'] = 1;
     $input['name'] = 'Printer 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'] = 'Printer';
     $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 : Printer + mac
     $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection();
     $input = array();
     $input['is_active'] = 1;
     $input['name'] = 'Printer mac';
     $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'] = "mac";
     $input['pattern'] = 1;
     $input['condition'] = 10;
     $rulecriteria->add($input);
     $input = array();
     $input['rules_id'] = $rule_id;
     $input['criteria'] = "mac";
     $input['pattern'] = 1;
     $input['condition'] = 8;
     $rulecriteria->add($input);
     $input = array();
     $input['rules_id'] = $rule_id;
     $input['criteria'] = "itemtype";
     $input['pattern'] = 'Printer';
     $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 : Printer + name
     $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection();
     $input = array();
     $input['is_active'] = 1;
     $input['name'] = 'Printer name';
     $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'] = "name";
     $input['pattern'] = 1;
     $input['condition'] = 10;
     $rulecriteria->add($input);
     $input = array();
     $input['rules_id'] = $rule_id;
     $input['criteria'] = "name";
     $input['pattern'] = 1;
     $input['condition'] = 8;
     $rulecriteria->add($input);
     $input = array();
     $input['rules_id'] = $rule_id;
     $input['criteria'] = "itemtype";
     $input['pattern'] = 'Printer';
     $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 : Printer import
     $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection();
     $input = array();
     $input['is_active'] = 1;
     $input['name'] = 'Printer 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'] = 'Printer';
     $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 : NetworkEquipment + serial
     $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection();
     $input = array();
     $input['is_active'] = 1;
     $input['name'] = 'NetworkEquipment 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'] = 'NetworkEquipment';
     $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 : NetworkEquipment + mac
     $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection();
     $input = array();
     $input['is_active'] = 1;
     $input['name'] = 'NetworkEquipment mac';
     $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'] = "mac";
     $input['pattern'] = 1;
     $input['condition'] = 10;
     $rulecriteria->add($input);
     $input = array();
     $input['rules_id'] = $rule_id;
     $input['criteria'] = "mac";
     $input['pattern'] = 1;
     $input['condition'] = 8;
     $rulecriteria->add($input);
     $input = array();
     $input['rules_id'] = $rule_id;
     $input['criteria'] = "itemtype";
     $input['pattern'] = 'NetworkEquipment';
     $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 : NetworkEquipment import
     $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection();
     $input = array();
     $input['is_active'] = 1;
     $input['name'] = 'NetworkEquipment 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'] = 'NetworkEquipment';
     $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 search serial in all DB
     $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection();
     $input = array();
     $input['is_active'] = 1;
     $input['name'] = 'Find serial in all GLPI';
     $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);
     // 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 search mac in all DB
     $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection();
     $input = array();
     $input['is_active'] = 1;
     $input['name'] = 'Find mac in all GLPI';
     $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'] = "mac";
     $input['pattern'] = 1;
     $input['condition'] = 10;
     $rulecriteria->add($input);
     $input = array();
     $input['rules_id'] = $rule_id;
     $input['criteria'] = "mac";
     $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 search name in all DB
     $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection();
     $input = array();
     $input['is_active'] = 1;
     $input['name'] = 'Find name in all GLPI';
     $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'] = "name";
     $input['pattern'] = 1;
     $input['condition'] = 10;
     $rulecriteria->add($input);
     $input = array();
     $input['rules_id'] = $rule_id;
     $input['criteria'] = "name";
     $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 import into unmanaged devices
     $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection();
     $input = array();
     $input['is_active'] = 1;
     $input['name'] = 'Unmanaged device 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'] = "name";
     $input['pattern'] = '*';
     $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);
 }
示例#7
0
switch ($action) {
    case "preview_import":
        $rulecollection->checkGlobal(CREATE);
        if (RuleCollection::previewImportRules()) {
            break;
        }
    case "import":
        $rulecollection->checkGlobal(CREATE);
        RuleCollection::displayImportRulesForm();
        break;
    case "export":
        $rule = new Rule();
        if (isset($_SESSION['exportitems'])) {
            $rules_key = array_keys($_SESSION['exportitems']);
        } else {
            $rules_key = array_keys($rule->find());
        }
        $rulecollection->exportRulesToXML($rules_key);
        unset($_SESSION['exportitems']);
        break;
    case "download":
        echo "<div class='center'>";
        echo "<a href='" . Toolbox::getItemTypeSearchURL($_REQUEST['itemtype']) . "'>" . __('Back') . "</a>";
        echo "</div>";
        Html::redirect("rule.backup.php?action=export&itemtype=" . $_REQUEST['itemtype']);
        break;
    case "process_import":
        $rulecollection->checkGlobal(CREATE);
        RuleCollection::processImportRules();
        Html::back();
        break;
示例#8
0
 /**
  * Delete rule, also remove and update groups.
  *
  * @param null $id
  * @return bool
  * @throws Sentry\SentryException
  */
 public function delete_base_rules($id = null)
 {
     try {
         if (!empty($id)) {
             $rules = array(Rule::find($id));
         } else {
             $rules = Rule::all();
         }
         $groups = $this->get_base_groups();
         foreach ($groups as $group) {
             $permissions = array();
             if (!empty($group['permissions'])) {
                 $permissions = json_decode($group['permissions'], true);
                 foreach ($rules as $rule) {
                     if (!isset($permissions[$rule->rule])) {
                         continue;
                     }
                     $permissions[$rule->rule] = 0;
                 }
                 $this->update_base_group_rules($group['id'], $permissions);
             }
         }
         foreach ($rules as $rule) {
             $rule->delete();
         }
         return true;
     } catch (Sentry\SentryException $e) {
         throw new Sentry\SentryException($e->getMessage());
     }
 }
示例#9
0
function plugin_resources_uninstall()
{
    global $DB;
    $tables = array("glpi_plugin_resources_resources", "glpi_plugin_resources_resources_items", "glpi_plugin_resources_employees", "glpi_plugin_resources_employers", "glpi_plugin_resources_clients", "glpi_plugin_resources_choices", "glpi_plugin_resources_choiceitems", "glpi_plugin_resources_departments", "glpi_plugin_resources_contracttypes", "glpi_plugin_resources_resourcestates", "glpi_plugin_resources_tasktypes", "glpi_plugin_resources_profiles", "glpi_plugin_resources_tasks", "glpi_plugin_resources_taskplannings", "glpi_plugin_resources_tasks_items", "glpi_plugin_resources_checklists", "glpi_plugin_resources_checklistconfigs", "glpi_plugin_resources_reportconfigs", "glpi_plugin_resources_resourcerestings", "glpi_plugin_resources_resourceholidays", "glpi_plugin_resources_ticketcategories", "glpi_plugin_resources_resourcesituations", "glpi_plugin_resources_contractnatures", "glpi_plugin_resources_ranks", "glpi_plugin_resources_resourcespecialities", "glpi_plugin_resources_leavingreasons", "glpi_plugin_resources_professions", "glpi_plugin_resources_professionlines", "glpi_plugin_resources_professioncategories", "glpi_plugin_resources_employments", "glpi_plugin_resources_employmentstates", "glpi_plugin_resources_budgets", "glpi_plugin_resources_costs", "glpi_plugin_resources_budgettypes", "glpi_plugin_resources_budgetvolumes");
    foreach ($tables as $table) {
        $DB->query("DROP TABLE IF EXISTS `{$table}`;");
    }
    //old versions
    $tables = array("glpi_plugin_resources", "glpi_plugin_resources_device", "glpi_plugin_resources_needs", "glpi_plugin_resources_employee", "glpi_dropdown_plugin_resources_employer", "glpi_dropdown_plugin_resources_client", "glpi_dropdown_plugin_resources_type", "glpi_dropdown_plugin_resources_department", "glpi_dropdown_plugin_resources_tasks_type", "glpi_plugin_resources_mailingsettings", "glpi_plugin_resources_mailing");
    foreach ($tables as $table) {
        $DB->query("DROP TABLE IF EXISTS `{$table}`;");
    }
    $in = "IN (" . implode(',', array("'PluginResourcesResource'", "'PluginResourcesTask'", "'PluginResourcesHelpdesk'", "'PluginResourcesDirectory'", "'PluginResourcesChecklistconfig'", "'PluginResourcesResourceResting'", "'PluginResourcesResourceHoliday'", "'PluginResourcesBudget'", "'PluginResourcesEmployment'", "'PluginResourcesRecap'")) . ")";
    $tables = array("glpi_displaypreferences", "glpi_documents_items", "glpi_bookmarks", "glpi_logs", "glpi_tickets");
    foreach ($tables as $table) {
        $query = "DELETE FROM `{$table}` WHERE (`itemtype` " . $in . " ) ";
        $DB->query($query);
    }
    //drop rules
    $Rule = new Rule();
    $a_rules = $Rule->find("`sub_type`='PluginResourcesRuleChecklist'\n                              OR `sub_type`='PluginResourcesRuleContracttype'");
    foreach ($a_rules as $data) {
        $Rule->delete($data);
    }
    $notif = new Notification();
    $options = array('itemtype' => 'PluginResourcesResource', 'event' => 'new', 'FIELDS' => 'id');
    foreach ($DB->request('glpi_notifications', $options) as $data) {
        $notif->delete($data);
    }
    $options = array('itemtype' => 'PluginResourcesResource', 'event' => 'update', 'FIELDS' => 'id');
    foreach ($DB->request('glpi_notifications', $options) as $data) {
        $notif->delete($data);
    }
    $options = array('itemtype' => 'PluginResourcesResource', 'event' => 'delete', 'FIELDS' => 'id');
    foreach ($DB->request('glpi_notifications', $options) as $data) {
        $notif->delete($data);
    }
    $options = array('itemtype' => 'PluginResourcesResource', 'event' => 'newtask', 'FIELDS' => 'id');
    foreach ($DB->request('glpi_notifications', $options) as $data) {
        $notif->delete($data);
    }
    $options = array('itemtype' => 'PluginResourcesResource', 'event' => 'updatetask', 'FIELDS' => 'id');
    foreach ($DB->request('glpi_notifications', $options) as $data) {
        $notif->delete($data);
    }
    $options = array('itemtype' => 'PluginResourcesResource', 'event' => 'deletetask', 'FIELDS' => 'id');
    foreach ($DB->request('glpi_notifications', $options) as $data) {
        $notif->delete($data);
    }
    $options = array('itemtype' => 'PluginResourcesResource', 'event' => 'AlertExpiredTasks', 'FIELDS' => 'id');
    foreach ($DB->request('glpi_notifications', $options) as $data) {
        $notif->delete($data);
    }
    $options = array('itemtype' => 'PluginResourcesResource', 'event' => 'AlertLeavingResources', 'FIELDS' => 'id');
    foreach ($DB->request('glpi_notifications', $options) as $data) {
        $notif->delete($data);
    }
    $options = array('itemtype' => 'PluginResourcesResource', 'event' => 'AlertArrivalChecklists', 'FIELDS' => 'id');
    foreach ($DB->request('glpi_notifications', $options) as $data) {
        $notif->delete($data);
    }
    $options = array('itemtype' => 'PluginResourcesResource', 'event' => 'AlertLeavingChecklists', 'FIELDS' => 'id');
    foreach ($DB->request('glpi_notifications', $options) as $data) {
        $notif->delete($data);
    }
    $options = array('itemtype' => 'PluginResourcesResource', 'event' => 'LeavingResource', 'FIELDS' => 'id');
    foreach ($DB->request('glpi_notifications', $options) as $data) {
        $notif->delete($data);
    }
    $options = array('itemtype' => 'PluginResourcesResource', 'event' => 'report', 'FIELDS' => 'id');
    foreach ($DB->request('glpi_notifications', $options) as $data) {
        $notif->delete($data);
    }
    $options = array('itemtype' => 'PluginResourcesResource', 'event' => 'newresting', 'FIELDS' => 'id');
    foreach ($DB->request('glpi_notifications', $options) as $data) {
        $notif->delete($data);
    }
    $options = array('itemtype' => 'PluginResourcesResource', 'event' => 'updateresting', 'FIELDS' => 'id');
    foreach ($DB->request('glpi_notifications', $options) as $data) {
        $notif->delete($data);
    }
    $options = array('itemtype' => 'PluginResourcesResource', 'event' => 'deleteresting', 'FIELDS' => 'id');
    foreach ($DB->request('glpi_notifications', $options) as $data) {
        $notif->delete($data);
    }
    $options = array('itemtype' => 'PluginResourcesResource', 'event' => 'newholiday', 'FIELDS' => 'id');
    foreach ($DB->request('glpi_notifications', $options) as $data) {
        $notif->delete($data);
    }
    $options = array('itemtype' => 'PluginResourcesResource', 'event' => 'updateholiday', 'FIELDS' => 'id');
    foreach ($DB->request('glpi_notifications', $options) as $data) {
        $notif->delete($data);
    }
    $options = array('itemtype' => 'PluginResourcesResource', 'event' => 'deleteholiday', 'FIELDS' => 'id');
    foreach ($DB->request('glpi_notifications', $options) as $data) {
        $notif->delete($data);
    }
    //templates
    $template = new NotificationTemplate();
    $translation = new NotificationTemplateTranslation();
    $options = array('itemtype' => 'PluginResourcesResource', '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);
    }
    if (class_exists('PluginDatainjectionModel')) {
        PluginDatainjectionModel::clean(array('itemtype' => 'PluginResourcesResource'));
        PluginDatainjectionModel::clean(array('itemtype' => 'PluginResourcesClient'));
    }
    $rep_files_resources = GLPI_PLUGIN_DOC_DIR . "/resources";
    Toolbox::deleteDir($rep_files_resources);
    return true;
}