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


PHP Rule::add方法代码示例

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


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

 /**
  * Add computer in entity `ent1` (with rules)
  *
  * @test
  */
 public function AddComputer()
 {
     global $DB;
     $DB->connect();
     plugin_init_fusioninventory();
     $DB->query("INSERT INTO `glpi_entities`\n         (`id`, `name`, `entities_id`, `completename`, `level`)\n         VALUES (1, 'ent1', 0, 'Entité racine > ent1', 2)");
     $DB->query("INSERT INTO `glpi_entities`\n         (`id`, `name`, `entities_id`, `completename`, `level`)\n         VALUES (2, 'ent2', 0, 'Entité racine > ent2', 2)");
     $_SESSION['glpiactive_entity'] = 0;
     $pfiComputerInv = new PluginFusioninventoryInventoryComputerInventory();
     $computer = new Computer();
     $pfEntity = new PluginFusioninventoryEntity();
     $pfEntity->update(array('id' => 1, 'entities_id' => 0, 'transfers_id_auto' => 1));
     $a_inventory = array();
     $a_inventory['CONTENT']['HARDWARE'] = array('NAME' => 'pc1');
     $a_inventory['CONTENT']['BIOS'] = array('SSN' => 'xxyyzz');
     // * Add rule ignore
     $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');
     $this->AgentEntity(1, 1, 'Add computer on entity 1');
     // ** Update
     $pfiComputerInv->import("pc-2013-02-13", "", $a_inventory);
     // update
     $nbComputers = countElementsInTable("glpi_computers");
     $this->assertEquals(1, $nbComputers, 'Nb computer for update computer');
     $computer->getFromDB(1);
     $this->assertEquals(1, $computer->fields['entities_id'], 'Update computer');
     $this->AgentEntity(1, 1, 'Update computer on entity 1 (not changed)');
 }
开发者ID:korial29,项目名称:fusioninventory-for-glpi,代码行数:61,代码来源:ComputerEntityTest.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: 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

示例5: 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

示例6: 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

示例7: 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
     $rule = new Rule();
     $input = array();
     $input['is_active'] = 1;
     $input['name'] = 'Import pinter';
     $input['match'] = 'AND';
     $input['sub_type'] = 'PluginFusioninventoryInventoryRuleImport';
     $input['ranking'] = 198;
     $rule_id = $rule->add($input);
     // Add criteria
     $rulecriteria = new RuleCriteria();
     $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'] = "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();
     $input = array();
     $input['rules_id'] = $rule_id;
     $input['action_type'] = 'assign';
     $input['field'] = '_fusion';
     $input['value'] = '1';
     $ruleaction->add($input);
     // Denied import
     $input = array();
     $input['is_active'] = 1;
     $input['name'] = 'Import pinter';
     $input['match'] = 'AND';
     $input['sub_type'] = 'PluginFusioninventoryInventoryRuleImport';
     $input['ranking'] = 199;
     $rule_id = $rule->add($input);
     // Add criteria
     $input = array();
     $input['rules_id'] = $rule_id;
     $input['criteria'] = "name";
     $input['pattern'] = '1';
     $input['condition'] = 8;
     $rulecriteria->add($input);
     // Add action
     $input = array();
     $input['rules_id'] = $rule_id;
     $input['action_type'] = 'assign';
     $input['field'] = '_fusion';
     $input['value'] = '2';
     $ruleaction->add($input);
 }
开发者ID:C-Duv,项目名称:fusioninventory-for-glpi,代码行数:74,代码来源:RuleImportTest.php

示例8: update

 /**
  * Update current object to database
  *
  * @param bool $null_values
  * @return boolean Update result
  */
 public function update()
 {
     $fields = $this->validation();
     if (count($this->_errors) > 1 and is_array($this->_errors)) {
         return false;
     }
     // Automatically fill dates
     if (array_key_exists('upd_date', $fields) and empty($fields['upd_date']) || $fields['upd_date'] == null) {
         $this->upd_date = date('Y-m-d H:i:s');
         $fields['upd_date'] = $this->upd_date;
     }
     $result = Db::getInstance()->update(DB_PREFIX . $this->table, $fields, '`' . pSQL($this->identifier) . '` = ' . (int) $this->id);
     if ($result === false) {
         return false;
     }
     if (array_key_exists('rewrite', $fields)) {
         $rule = Rule::loadRule(array('entity' => pSQL(get_class($this)), 'id_entity' => (int) $this->id));
         if (Validate::isLoadedObject($rule)) {
             $rule->rule_link = strtolower(pSQL($this->rewrite));
             $rule->view_name = Tools::getRequest('view_name') ? Tools::getRequest('view_name') : pSQL(get_class($this) . 'View');
             $rule->update();
         } else {
             $rule = new Rule();
             $rule->entity = pSQL(get_class($this));
             $rule->view_name = Tools::getRequest('view_name') ? Tools::getRequest('view_name') : pSQL(get_class($this) . 'View');
             $rule->id_entity = (int) $this->id;
             $rule->rule_link = strtolower(pSQL($this->rewrite));
             $rule->add();
         }
     }
     return true;
 }
开发者ID:yiuked,项目名称:tmcart,代码行数:38,代码来源:ObjectBase.php


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