当前位置: 首页>>代码示例>>PHP>>正文


PHP RuleAction::add方法代码示例

本文整理汇总了PHP中RuleAction::add方法的典型用法代码示例。如果您正苦于以下问题:PHP RuleAction::add方法的具体用法?PHP RuleAction::add怎么用?PHP RuleAction::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RuleAction的用法示例。


在下文中一共展示了RuleAction::add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: prepareDB

 /**
  * @test
  */
 public function prepareDB()
 {
     global $DB;
     $DB->connect();
     $_SESSION['glpiactive_entity'] = 0;
     $_SESSION["plugin_fusioninventory_entity"] = 0;
     $_SESSION["glpiname"] = 'Plugin_FusionInventory';
     $rule = new Rule();
     $ruleCriteria = new RuleCriteria();
     $ruleAction = new RuleAction();
     // * computer model assign
     $input = array('entities_id' => 0, 'sub_type' => 'PluginFusioninventoryCollectRule', 'name' => 'computer model', 'match' => 'AND');
     $rules_id = $rule->add($input);
     $input = array('rules_id' => $rules_id, 'criteria' => 'filename', 'condition' => 6, 'pattern' => "/latitude(.*)/");
     $ruleCriteria->add($input);
     $input = array('rules_id' => $rules_id, 'action_type' => 'assign', 'field' => 'computermodels_id', 'value' => 1);
     $this->ruleactions_id = $ruleAction->add($input);
     // * computer model regex
     $input = array('entities_id' => 0, 'sub_type' => 'PluginFusioninventoryCollectRule', 'name' => 'computer model 2', 'match' => 'AND');
     $rules_id = $rule->add($input);
     $input = array('rules_id' => $rules_id, 'criteria' => 'filename', 'condition' => 6, 'pattern' => "/longitude(.*)/");
     $ruleCriteria->add($input);
     $input = array('rules_id' => $rules_id, 'action_type' => 'regex_result', 'field' => 'computermodels_id', 'value' => '#0');
     $this->ruleactions_id = $ruleAction->add($input);
     // * user regex
     $input = array('entities_id' => 0, 'sub_type' => 'PluginFusioninventoryCollectRule', 'name' => 'user', 'match' => 'AND');
     $rules_id = $rule->add($input);
     $input = array('rules_id' => $rules_id, 'criteria' => 'filename', 'condition' => 6, 'pattern' => "/user (.*)/");
     $ruleCriteria->add($input);
     $input = array('rules_id' => $rules_id, 'action_type' => 'regex_result', 'field' => 'user', 'value' => '#0');
     $this->ruleactions_id = $ruleAction->add($input);
     // * softwareversion regex
     $input = array('entities_id' => 0, 'sub_type' => 'PluginFusioninventoryCollectRule', 'name' => 'softwareversion 3.0', 'match' => 'AND');
     $rules_id = $rule->add($input);
     $input = array('rules_id' => $rules_id, 'criteria' => 'filename', 'condition' => 6, 'pattern' => "/version (.*)/");
     $ruleCriteria->add($input);
     $input = array('rules_id' => $rules_id, 'action_type' => 'regex_result', 'field' => 'softwareversion', 'value' => '#0');
     $this->ruleactions_id = $ruleAction->add($input);
     // * otherserial regex
     $input = array('entities_id' => 0, 'sub_type' => 'PluginFusioninventoryCollectRule', 'name' => 'otherserial', 'match' => 'AND');
     $rules_id = $rule->add($input);
     $input = array('rules_id' => $rules_id, 'criteria' => 'filename', 'condition' => 6, 'pattern' => "/other (.*)/");
     $ruleCriteria->add($input);
     $input = array('rules_id' => $rules_id, 'action_type' => 'regex_result', 'field' => 'otherserial', 'value' => '#0');
     $this->ruleactions_id = $ruleAction->add($input);
     // * otherserial regex
     $input = array('entities_id' => 0, 'sub_type' => 'PluginFusioninventoryCollectRule', 'name' => 'otherserial assign', 'match' => 'AND');
     $rules_id = $rule->add($input);
     $input = array('rules_id' => $rules_id, 'criteria' => 'filename', 'condition' => 6, 'pattern' => "/serial (.*)/");
     $ruleCriteria->add($input);
     $input = array('rules_id' => $rules_id, 'action_type' => 'assign', 'field' => 'otherserial', 'value' => 'ttuujj');
     $this->ruleactions_id = $ruleAction->add($input);
     // * create items
     $computerModel = new ComputerModel();
     $input = array('name' => '6430u');
     $computerModel->add($input);
 }
开发者ID:C-Duv,项目名称:fusioninventory-for-glpi,代码行数:60,代码来源:CollectRuleTest.php

示例2: setUp

 protected function setUp()
 {
     global $DB;
     parent::setUp();
     $DB->connect();
     self::restore_database();
     $DB->query("UPDATE `glpi_rules`\n         SET `is_active`='0'\n         WHERE `sub_type`='PluginFusioninventoryInventoryRuleImport'");
     // Add a rule to ignore import
     // Create rule for import into unknown devices
     $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection();
     $input = array();
     $input['is_active'] = 1;
     $input['name'] = 'Ignore import';
     $input['match'] = 'AND';
     $input['sub_type'] = 'PluginFusioninventoryInventoryRuleImport';
     $input['ranking'] = 200;
     $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'] = '_ignore_import';
     $input['value'] = '1';
     $ruleaction->add($input);
 }
开发者ID:C-Duv,项目名称:fusioninventory-for-glpi,代码行数:35,代码来源:RuleIgnoredImportTest.php

示例3: TwoRegexpEntitiesTest

 /**
  * @test
  */
 public function TwoRegexpEntitiesTest()
 {
     global $DB;
     $DB->connect();
     $DB->query('DELETE FROM glpi_entities where id>0');
     $DB->query("INSERT INTO `glpi_entities`\n         (`id`, `name`, `entities_id`, `completename`, `level`, `tag`)\n         VALUES (1, 'entity A', 0, 'Entité racine > entity A', 2, 'entA')");
     $DB->query("INSERT INTO `glpi_entities`\n         (`id`, `name`, `entities_id`, `completename`, `level`, `tag`)\n         VALUES (2, 'entity B', 0, 'Entité racine > entity B', 2, 'entB')");
     $DB->query("INSERT INTO `glpi_entities`\n         (`id`, `name`, `entities_id`, `completename`, `level`, `tag`)\n         VALUES (3, 'entity C', 0, 'Entité racine > entity C', 2, 'entC')");
     // Add a rule for get entity tag (1)
     $rule = new Rule();
     $input = array('is_active' => 1, 'name' => 'entity rule 1', 'match' => 'AND', 'sub_type' => 'PluginFusioninventoryInventoryRuleEntity', 'ranking' => 1);
     $rule1_id = $rule->add($input);
     // Add criteria
     $rulecriteria = new RuleCriteria();
     $input = array('rules_id' => $rule1_id, 'criteria' => "name", 'pattern' => "/^([A-Za-z0-9]*) - ([A-Za-z0-9]*) - (.*)\$/", 'condition' => PluginFusioninventoryInventoryRuleEntity::REGEX_MATCH);
     $rulecriteria->add($input);
     // Add action
     $ruleaction = new RuleAction();
     $input = array('rules_id' => $rule1_id, 'action_type' => 'regex_result', 'field' => '_affect_entity_by_tag', 'value' => '#2');
     $ruleaction->add($input);
     // Add a rule for get entity tag (2)
     $rule = new Rule();
     $input = array('is_active' => 1, 'name' => 'entity rule 2', 'match' => 'AND', 'sub_type' => 'PluginFusioninventoryInventoryRuleEntity', 'ranking' => 2);
     $rule2_id = $rule->add($input);
     // Add criteria
     $rulecriteria = new RuleCriteria();
     $input = array('rules_id' => $rule2_id, 'criteria' => "name", 'pattern' => "/^([A-Za-z0-9]*) - (.*)\$/", 'condition' => PluginFusioninventoryInventoryRuleEntity::REGEX_MATCH);
     $rulecriteria->add($input);
     // Add action
     $ruleaction = new RuleAction();
     $input = array('rules_id' => $rule2_id, 'action_type' => 'regex_result', 'field' => '_affect_entity_by_tag', 'value' => '#1');
     $ruleaction->add($input);
     $input = array('name' => 'computer01 - entC');
     $ruleEntity = new PluginFusioninventoryInventoryRuleEntityCollection();
     $ruleEntity->getCollectionPart();
     $ent = $ruleEntity->processAllRules($input, array());
     $a_references = array('entities_id' => 3, '_ruleid' => $rule2_id);
     $this->assertEquals($a_references, $ent, 'Entity C');
     $input = array('name' => 'computer01 - blabla - entB');
     $ruleEntity = new PluginFusioninventoryInventoryRuleEntityCollection();
     $ruleEntity->getCollectionPart();
     $ent = $ruleEntity->processAllRules($input, array());
     $a_references = array('entities_id' => 2, '_ruleid' => $rule1_id);
     $this->assertEquals($a_references, $ent, 'Entity B');
 }
开发者ID:korial29,项目名称:fusioninventory-for-glpi,代码行数:48,代码来源:RuleEntityTest.php

示例4: postClone

 static function postClone(Rule $clone, $oldid)
 {
     global $DB;
     $fkey = getForeignKeyFieldForTable($clone->getTable());
     $crit = array($fkey => $oldid);
     $criteria = new RuleCriteria();
     foreach ($DB->request($criteria->getTable(), $crit) as $data) {
         unset($data['id']);
         $data[$fkey] = $clone->getID();
         $criteria->add(Toolbox::addslashes_deep($data));
     }
     $action = new RuleAction();
     foreach ($DB->request($action->getTable(), $crit) as $data) {
         unset($data['id']);
         $data[$fkey] = $clone->getID();
         $action->add(Toolbox::addslashes_deep($data));
     }
 }
开发者ID:geldarr,项目名称:hack-space,代码行数:18,代码来源:rule.class.php

示例5: die

/** @file
* @brief
*/
if (!defined('GLPI_ROOT')) {
    die("Sorry. You can't access directly to this file");
}
$rule = $rulecollection->getRuleClass();
$rulecollection->checkGlobal(READ);
if (!isset($_GET["id"])) {
    $_GET["id"] = "";
}
$rulecriteria = new RuleCriteria(get_class($rule));
$ruleaction = new RuleAction(get_class($rule));
if (isset($_POST["add_action"])) {
    $rulecollection->checkGlobal(CREATE);
    $ruleaction->add($_POST);
    Html::back();
} else {
    if (isset($_POST["update"])) {
        $rulecollection->checkGlobal(UPDATE);
        $rule->update($_POST);
        Event::log($_POST['id'], "rules", 4, "setup", sprintf(__('%s updates an item'), $_SESSION["glpiname"]));
        Html::back();
    } else {
        if (isset($_POST["add"])) {
            $rulecollection->checkGlobal(CREATE);
            $newID = $rule->add($_POST);
            Event::log($newID, "rules", 4, "setup", sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $newID));
            Html::redirect($_SERVER['HTTP_REFERER'] . "?id={$newID}");
        } else {
            if (isset($_POST["purge"])) {
开发者ID:paisdelconocimiento,项目名称:glpi-smartcities,代码行数:31,代码来源:rule.common.form.php

示例6: AddComputerStep2

 /**
  * @test
  */
 public function AddComputerStep2()
 {
     global $DB;
     $this->mark_incomplete();
     return;
     // TODO: recode this test
     $DB->connect();
     self::restore_database();
     $DB->query("INSERT INTO `glpi_entities`\n         (`id`, `name`, `entities_id`, `completename`, `level`, `entities_id_software`)\n         VALUES (1, 'entity1', 0, 'Entité racine > entity1', 2, 0)");
     $DB->query("UPDATE `glpi_entities`\n         SET `entities_id_software` = '0'\n         WHERE `id`='1'");
     $_SESSION['glpiactive_entity'] = 0;
     $_SESSION['glpiactiveentities_string'] = 0;
     $_SESSION['glpishowallentities'] = 1;
     $_SESSION['glpiname'] = 'glpi';
     $pfiComputerInv = new PluginFusioninventoryInventoryComputerInventory();
     $computer = new Computer();
     $software = new Software();
     $a_inventory = array();
     $a_inventory['CONTENT']['HARDWARE'] = array('NAME' => 'pc1');
     $a_inventory['CONTENT']['SOFTWARES'][] = array('COMMENTS' => "Non-interactive tool to get files from FTP, GOPHER, HTTP(S)", 'NAME' => "curl", 'VERSION' => "7.24.0_1");
     // * Add rule to entity 1
     $rule = new Rule();
     $ruleCriteria = new RuleCriteria();
     $ruleAction = new RuleAction();
     $input = array();
     $input['sub_type'] = 'PluginFusioninventoryInventoryRuleEntity';
     $input['name'] = 'pc1';
     $input['match'] = 'AND';
     $input['is_active'] = 1;
     $rules_id = $rule->add($input);
     $input = array();
     $input['rules_id'] = $rules_id;
     $input['criteria'] = 'name';
     $input['condition'] = 0;
     $input['pattern'] = 'pc1';
     $ruleCriteria->add($input);
     $input = array();
     $input['rules_id'] = $rules_id;
     $input['action_type'] = 'assign';
     $input['field'] = 'entities_id';
     $input['value'] = 1;
     $ruleAction->add($input);
     // ** Add agent
     $pfAgent = new PluginFusioninventoryAgent();
     $a_agents_id = $pfAgent->add(array('name' => 'pc-2013-02-13', 'device_id' => 'pc-2013-02-13'));
     $_SESSION['plugin_fusioninventory_agents_id'] = $a_agents_id;
     // ** Add
     $pfiComputerInv->import("pc-2013-02-13", "", $a_inventory);
     // creation
     $computer->getFromDB(1);
     $this->assertEquals(1, $computer->fields['entities_id'], 'Add computer');
     $software->getFromDB(1);
     $this->assertEquals(0, $software->fields['entities_id'], 'Software entity on add computer');
     // Software not in same entity as computer, may be recursive
     $this->assertEquals(1, $software->fields['is_recursive'], 'Software may have recursive = 1');
 }
开发者ID:korial29,项目名称:fusioninventory-for-glpi,代码行数:59,代码来源:SoftwareEntityCreationTest.php

示例7: testPrinterDicoIgnoreImport

 public function testPrinterDicoIgnoreImport()
 {
     global $DB;
     $DB->connect();
     self::restore_database();
     $_SESSION['glpiactive_entity'] = 0;
     $_SESSION["plugin_fusioninventory_entity"] = 0;
     $_SESSION["glpiname"] = 'Plugin_FusionInventory';
     $pfConfig = new PluginFusioninventoryConfig();
     $computer = new Computer();
     /*
      * TODO: maybe we could use some dataProvider here ?
      */
     // Add dictionnary rule for ignore import for printer p2
     $rulecollection = new RuleDictionnaryPrinterCollection();
     $rule = $rulecollection->getRuleClass();
     $input = array();
     $input['is_active'] = 1;
     $input['name'] = 'Ignore import';
     $input['match'] = 'AND';
     $input['sub_type'] = 'RuleDictionnaryPrinter';
     $input['ranking'] = 1;
     $rule_id = $rule->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'] = 'p2';
     $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 dictionnary rule for ignore import for printer p3
     $rulecollection = new RuleDictionnaryPrinterCollection();
     $rule = $rulecollection->getRuleClass();
     $input = array();
     $input['is_active'] = 1;
     $input['name'] = 'rename';
     $input['match'] = 'AND';
     $input['sub_type'] = 'RuleDictionnaryPrinter';
     $input['ranking'] = 2;
     $rule_id = $rule->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'] = 'p3';
     $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'] = 'name';
     $input['value'] = 'p3bis';
     $ruleaction->add($input);
     // Add action
     $ruleaction = new RuleAction(get_class($rule));
     $input = array();
     $input['rules_id'] = $rule_id;
     $input['action_type'] = 'assign';
     $input['field'] = 'manufacturer';
     $input['value'] = '1';
     $ruleaction->add($input);
     // Add action
     $ruleaction = new RuleAction(get_class($rule));
     $input = array();
     $input['rules_id'] = $rule_id;
     $input['action_type'] = 'assign';
     $input['field'] = 'is_global';
     $input['value'] = '0';
     $ruleaction->add($input);
     $pfici = new PluginFusioninventoryInventoryComputerInventory();
     $_SESSION['plugin_fusioninventory_agents_id'] = 1;
     $pfici->sendCriteria("toto", $this->a_computer1_beforeformat);
     $computer->getFromDB(1);
     $this->assertEquals('ggheb7ne7', $computer->fields['serial'], 'Computer not updated correctly');
     $a_printers = getAllDatasFromTable("glpi_printers");
     $this->assertEquals(0, countElementsInTable('glpi_printers'), 'Printer p2 may be ignored (' . print_r($a_printers, TRUE) . ')');
     $printer = new Printer();
     $printer->delete(array('id' => 1), 1);
     $DB->query("TRUNCATE TABLE `glpi_printers`");
 }
开发者ID:korial29,项目名称:fusioninventory-for-glpi,代码行数:94,代码来源:ComputerPrinterTest.php

示例8: addRulesFromChecklists

 function addRulesFromChecklists($data)
 {
     $rulecollection = new PluginResourcesRuleChecklistCollection();
     $rulecollection->checkGlobal('w');
     foreach ($data["item"] as $key => $val) {
         if ($val == 1) {
             $this->getFromDB($key);
             $rule = new PluginResourcesRuleChecklist();
             $values["name"] = addslashes($this->fields["name"]);
             $values["match"] = "AND";
             $values["is_active"] = 1;
             $values["is_recursive"] = 1;
             $values["entities_id"] = $this->fields["entities_id"];
             $values["sub_type"] = "PluginResourcesRuleChecklist";
             $newID = $rule->add($values);
             if (isset($data["checklist_type"]) && $data["checklist_type"] > 0) {
                 $criteria = new RuleCriteria();
                 $values["rules_id"] = $newID;
                 $values["criteria"] = "checklist_type";
                 $values["condition"] = 0;
                 $values["pattern"] = $data["checklist_type"];
                 $criteria->add($values);
             }
             if (isset($data["plugin_resources_contracttypes_id"])) {
                 $criteria = new RuleCriteria();
                 $values["rules_id"] = $newID;
                 $values["criteria"] = "plugin_resources_contracttypes_id";
                 $values["condition"] = $data["condition"];
                 $values["pattern"] = $data["plugin_resources_contracttypes_id"];
                 $criteria->add($values);
             }
             $action = new RuleAction();
             $values["rules_id"] = $newID;
             $values["action_type"] = "assign";
             $values["field"] = "checklists_id";
             $values["value"] = $key;
             $action->add($values);
         }
     }
 }
开发者ID:geldarr,项目名称:hack-space,代码行数:40,代码来源:checklistconfig.class.php

示例9: testSoftwareCategory

 /**
  * Test software category Rule and putInTrash / removeFromTrash
  */
 public function testSoftwareCategory()
 {
     global $CFG_GLPI;
     $ent0 = $this->sharedFixture['entity'][0];
     // Clean preload rules
     $tmp = SingletonRuleList::getInstance('RuleSoftwareCategory');
     $tmp->load = 0;
     $this->assertArrayHasKey('softwarecategories_id_ondelete', $CFG_GLPI, "Fail: no softwarecategories_id_ondelete");
     $idcat[0] = Dropdown::import('SoftwareCategory', array('name' => 'Trashed'));
     $this->assertGreaterThan(0, $idcat[0], "Fail: can't create SoftwareCategory");
     $idcat[1] = Dropdown::import('SoftwareCategory', array('name' => 'OpenSource'));
     $this->assertGreaterThan(0, $idcat[1], "Fail: can't create SoftwareCategory");
     $rule = new RuleSoftwareCategory();
     $crit = new RuleCriteria();
     $acte = new RuleAction();
     $idr[0] = $rule->add(array('name' => 'OSS', 'sub_type' => 'RuleSoftwareCategory', 'match' => 'AND', 'is_active' => 1));
     $this->assertGreaterThan(0, $idr[0], "Fail: can't create rule 1");
     $this->assertTrue($rule->getFromDB($idr[0]));
     $this->assertEquals(1, $rule->fields['ranking'], "Fail: ranking not set");
     $idc[0] = $crit->add(array('rules_id' => $idr[0], 'criteria' => 'manufacturer', 'condition' => Rule::PATTERN_IS, 'pattern' => 'Indepnet'));
     $this->assertGreaterThan(0, $idc[0], "Fail: can't create rule 1 criteria");
     $ida[0] = $acte->add(array('rules_id' => $idr[0], 'action_type' => 'assign', 'field' => 'softwarecategories_id', 'value' => $idcat[1]));
     $this->assertGreaterThan(0, $ida[0], "Fail: can't create rule 1 action");
     // Createthe software
     $soft = new Software();
     $id[0] = $soft->addOrRestoreFromTrash('GLPI', 'Indepnet', $ent0);
     $this->assertGreaterThan(0, $id[0], "Fail: can't create software 1");
     // Check name
     $this->assertTrue($soft->getFromDB($id[0]), "Fail: can't read new soft");
     $this->assertEquals('GLPI', $soft->getField('name'), "Fail: name not set");
     // Check category
     $catid = $soft->getField('softwarecategories_id');
     $this->assertEquals($idcat[1], $catid, "Fail: category not set");
     // Change configuration
     $CFG_GLPI["softwarecategories_id_ondelete"] = $idcat[0];
     // Delete
     $this->assertTrue($soft->putInTrash($id[0]), "Fail: can't put soft in trash");
     $this->assertTrue($soft->getFromDB($id[0]), "Fail: can't read new soft");
     $catid = $soft->getField('softwarecategories_id');
     $this->assertEquals($idcat[0], $catid, "Fail: category not set");
     $this->assertEquals(1, $soft->getField('is_deleted'), "Fail: soft not deleted");
     // Restore
     $this->assertTrue($soft->removeFromTrash($id[0]), "Fail: can't put soft in trash");
     $this->assertTrue($soft->getFromDB($id[0]), "Fail: can't read new soft");
     $catid = $soft->getField('softwarecategories_id');
     $this->assertEquals($idcat[1], $catid, "Fail: category not set");
     $this->assertEquals(0, $soft->getField('is_deleted'), "Fail: soft not restored");
     // Clean
     $this->assertTrue($soft->delete(array('id' => $id[0]), true), "Fail: can't delete software 1)");
 }
开发者ID:btry,项目名称:glpi,代码行数:53,代码来源:Import.php

示例10: processImportRules

 /**
  * import rules in glpi after user validation
  *
  * @since version 0.85
  *
  * @return true if all ok
  **/
 static function processImportRules()
 {
     global $DB;
     $ruleCriteria = new RuleCriteria();
     $ruleAction = new RuleAction();
     $entity = new Entity();
     //get session vars
     $rules = $_SESSION['glpi_import_rules'];
     $rules_refused = $_SESSION['glpi_import_rules_refused'];
     $rr_keys = array_keys($rules_refused);
     unset($_SESSION['glpi_import_rules']);
     unset($_SESSION['glpi_import_rules_refused']);
     // unset all refused rules
     foreach ($rules['rule'] as $k_rule => &$rule) {
         if (in_array($k_rule, $rr_keys)) {
             //Do not process rule with actions or criterias refused
             if (isset($rules_refused[$k_rule]['criterias']) || isset($rules_refused[$k_rule]['actions'])) {
                 unset($rules['rule'][$k_rule]);
             } else {
                 // accept rule with only entity not found (change entity)
                 $rule['entities_id'] = $_REQUEST['new_entities'][$rule['uuid']];
             }
         }
     }
     //import all right rules
     while (!empty($rules['rule'])) {
         $current_rule = array_shift($rules['rule']);
         $add_criteria_and_actions = false;
         $params = array();
         $itemtype = $current_rule['sub_type'];
         $item = new $itemtype();
         //Find a rule by it's uuid
         $found = $item->find("`uuid`='" . $current_rule['uuid'] . "'");
         $params = Toolbox::addslashes_deep($current_rule);
         unset($params['rulecriteria']);
         unset($params['ruleaction']);
         if (!$item->isEntityAssign()) {
             $params['entities_id'] = 0;
         } else {
             $entities_found = $entity->find("completename = '" . $rule['entities_id'] . "'");
             if (!empty($entities_found)) {
                 $entity_found = array_shift($entities_found);
                 $params['entities_id'] = $entity_found['id'];
             } else {
                 $params['entities_id'] = 0;
             }
         }
         foreach (array('is_recursive', 'is_active') as $field) {
             //Should not be necessary but without it there's an sql error...
             if (!isset($params[$field]) || $params[$field] == '') {
                 $params[$field] = 0;
             }
         }
         //if uuid not exist, create rule
         if (empty($found)) {
             //Manage entity
             $params['_add'] = true;
             $rules_id = $item->add($params);
             if ($rules_id) {
                 Event::log($rules_id, "rules", 4, "setup", sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $rules_id));
                 $add_criteria_and_actions = true;
             }
         } else {
             //if uuid exists, then update the rule
             $tmp = array_shift($found);
             $params['id'] = $tmp['id'];
             $params['_update'] = true;
             $rules_id = $tmp['id'];
             if ($item->update($params)) {
                 Event::log($rules_id, "rules", 4, "setup", sprintf(__('%s updates an item'), $_SESSION["glpiname"]));
                 //remove all dependent criterias and action
                 $ruleCriteria->deleteByCriteria(array("rules_id" => $rules_id));
                 $ruleAction->deleteByCriteria(array("rules_id" => $rules_id));
                 $add_criteria_and_actions = true;
             }
         }
         if ($add_criteria_and_actions) {
             //Add criteria
             if (isset($current_rule['rulecriteria'])) {
                 foreach ($current_rule['rulecriteria'] as $criteria) {
                     $criteria['rules_id'] = $rules_id;
                     //fix array in value key
                     //(simplexml bug, empty xml node are converted in empty array instead of null)
                     if (is_array($criteria['pattern'])) {
                         $criteria['pattern'] = null;
                     }
                     $criteria = Toolbox::addslashes_deep($criteria);
                     $ruleCriteria->add($criteria);
                 }
             }
             //Add actions
             if (isset($current_rule['ruleaction'])) {
                 foreach ($current_rule['ruleaction'] as $action) {
//.........这里部分代码省略.........
开发者ID:paisdelconocimiento,项目名称:glpi-smartcities,代码行数:101,代码来源:rulecollection.class.php

示例11: updateaddComputerRestrictEntity

 /**
  * Update computer with restrict entity (in this case computer added)
  *
  * @test
  */
 public function updateaddComputerRestrictEntity()
 {
     global $DB;
     $DB->connect();
     $computer = new Computer();
     $pfiComputerInv = new PluginFusioninventoryInventoryComputerInventory();
     // Disable all rules
     $DB->query("UPDATE `glpi_rules`\n         SET `is_active`='0'\n         WHERE `sub_type`='PluginFusioninventoryInventoryRuleImport'");
     // Add rule name + restrict entity search
     $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection();
     $input = array();
     $input['is_active'] = 1;
     $input['name'] = 'Computer name + restrict';
     $input['match'] = 'AND';
     $input['sub_type'] = 'PluginFusioninventoryInventoryRuleImport';
     $input['ranking'] = 1;
     $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'] = "entityrestrict";
     $input['pattern'] = '';
     $input['condition'] = 202;
     $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);
     $a_inventory = array();
     $a_inventory['CONTENT']['HARDWARE'] = array('NAME' => 'pc1');
     $a_inventory['CONTENT']['BIOS'] = array('SSN' => 'xxyyzz');
     $pfiComputerInv->import("pc-2013-02-13", "", $a_inventory);
     // Update
     $this->assertEquals(2, countElementsInTable('glpi_computers'), 'Must have only 2 computer');
     $computer->getFromDB(2);
     $this->assertEquals(1, $computer->fields['entities_id'], 'Second computer added');
 }
开发者ID:korial29,项目名称:fusioninventory-for-glpi,代码行数:66,代码来源:ComputerEntityTest.php

示例12: AddAllRules

 /**
  * @test
  */
 public function AddAllRules()
 {
     global $DB;
     $DB->connect();
     // * Add rule ignore
     $rule = new Rule();
     $ruleCriteria = new RuleCriteria();
     $ruleAction = new RuleAction();
     $input = array();
     $input['sub_type'] = 'RuleDictionnarySoftware';
     $input['name'] = 'glpi';
     $input['match'] = 'AND';
     $input['is_active'] = 1;
     $rules_id = $rule->add($input);
     $input = array();
     $input['rules_id'] = $rules_id;
     $input['criteria'] = 'name';
     $input['condition'] = 0;
     $input['pattern'] = 'glpi';
     $ruleCriteria->add($input);
     $input = array();
     $input['rules_id'] = $rules_id;
     $input['action_type'] = 'assign';
     $input['field'] = '_ignore_import';
     $input['value'] = 1;
     $ruleAction->add($input);
     // * Add rule rename software
     $input = array();
     $input['sub_type'] = 'RuleDictionnarySoftware';
     $input['name'] = 'glpi0.85';
     $input['match'] = 'AND';
     $input['is_active'] = 1;
     $rules_id = $rule->add($input);
     $input = array();
     $input['rules_id'] = $rules_id;
     $input['criteria'] = 'name';
     $input['condition'] = 0;
     $input['pattern'] = 'glpi0.85';
     $ruleCriteria->add($input);
     $input = array();
     $input['rules_id'] = $rules_id;
     $input['action_type'] = 'assign';
     $input['field'] = 'name';
     $input['value'] = 'glpi';
     $ruleAction->add($input);
     // * Add rule rename manufacturer
     $input = array();
     $input['sub_type'] = 'RuleDictionnaryManufacturer';
     $input['name'] = 'indepnet';
     $input['match'] = 'AND';
     $input['is_active'] = 1;
     $rules_id = $rule->add($input);
     $input = array();
     $input['rules_id'] = $rules_id;
     $input['criteria'] = 'name';
     $input['condition'] = 0;
     $input['pattern'] = 'indepnet assoce';
     $ruleCriteria->add($input);
     $input = array();
     $input['rules_id'] = $rules_id;
     $input['action_type'] = 'assign';
     $input['field'] = 'name';
     $input['value'] = 'indepnet';
     $ruleAction->add($input);
     // * Add rule Modify version
     $input = array();
     $input['sub_type'] = 'RuleDictionnarySoftware';
     $input['name'] = 'glpi0.85';
     $input['match'] = 'AND';
     $input['is_active'] = 1;
     $rules_id = $rule->add($input);
     $input = array();
     $input['rules_id'] = $rules_id;
     $input['criteria'] = 'name';
     $input['condition'] = 0;
     $input['pattern'] = 'glpi0.85';
     $ruleCriteria->add($input);
     $input = array();
     $input['rules_id'] = $rules_id;
     $input['action_type'] = 'assign';
     $input['field'] = 'version';
     $input['value'] = '0.85';
     $ruleAction->add($input);
 }
开发者ID:korial29,项目名称:fusioninventory-for-glpi,代码行数:87,代码来源:SoftwareUpdateTest.php

示例13: RegexpRuleResultRegexpTest

 /**
  * @test
  */
 public function RegexpRuleResultRegexpTest()
 {
     global $DB, $PF_CONFIG;
     $DB->connect();
     $rule = new Rule();
     $input = array('is_active' => 1, 'name' => 'Location regexp pc', 'match' => 'AND', 'sub_type' => 'PluginFusioninventoryInventoryRuleLocation', 'ranking' => 1);
     $rules_id = $rule->add($input);
     // Add criteria
     $rulecriteria = new RuleCriteria();
     $input = array('rules_id' => $rules_id, 'criteria' => "name", 'pattern' => "/pc (.*)/", 'condition' => PluginFusioninventoryInventoryRuleLocation::REGEX_MATCH);
     $rulecriteria->add($input);
     // Add action
     $ruleaction = new RuleAction();
     $input = array('rules_id' => $rules_id, 'action_type' => 'regex_result', 'field' => 'locations_id', 'value' => '#0');
     $ruleaction->add($input);
     $input = array('name' => 'pc Monsols04');
     $_SESSION["plugin_fusioninventory_entity"] = 0;
     $ruleLocation = new PluginFusioninventoryInventoryRuleLocationCollection();
     $ruleLocation->getCollectionPart();
     $loc = $ruleLocation->processAllRules($input, array());
     $a_references = array('locations_id' => 1, '_ruleid' => 51);
     $this->assertEquals($a_references, $loc, 'Location result regexp_result');
 }
开发者ID:korial29,项目名称:fusioninventory-for-glpi,代码行数:26,代码来源:RuleLocationTest.php

示例14: Rule

GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
* @since version 0.85
*/
include '../inc/includes.php';
$rule = new Rule();
$rule->getFromDB(intval($_POST['rules_id']));
$action = new RuleAction($rule->fields['sub_type']);
if (isset($_POST["add"])) {
    $action->check(-1, CREATE, $_POST);
    $action->add($_POST);
    Html::back();
} else {
    if (isset($_POST["update"])) {
        $action->check($_POST['id'], UPDATE);
        $action->update($_POST);
        Html::back();
    } else {
        if (isset($_POST["purge"])) {
            $action->check($_POST['id'], PURGE);
            $action->delete($_POST, 1);
            Html::back();
        }
    }
}
开发者ID:jose-martins,项目名称:glpi,代码行数:31,代码来源:ruleaction.form.php

示例15: initRules

 /**
  * 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';
//.........这里部分代码省略.........
开发者ID:korial29,项目名称:fusioninventory-for-glpi,代码行数:101,代码来源:setup.class.php


注:本文中的RuleAction::add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。