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


PHP RuleAction::deleteByCriteria方法代码示例

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


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

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


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