本文整理汇总了PHP中RuleAction类的典型用法代码示例。如果您正苦于以下问题:PHP RuleAction类的具体用法?PHP RuleAction怎么用?PHP RuleAction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RuleAction类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: 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
示例2: 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
示例3: executeActions
function executeActions($output, $params)
{
if (count($this->actions)) {
foreach ($this->actions as $action) {
switch ($action->fields["action_type"]) {
case "assign":
$output[$action->fields["field"]] = $action->fields["value"];
break;
case "regex_result":
//Regex result : assign value from the regex
$res = "";
if (isset($this->regex_results[0])) {
$res .= RuleAction::getRegexResultById($action->fields["value"], $this->regex_results[0]);
} else {
$res .= $action->fields["value"];
}
if ($res != '' && ($action->fields["field"] != 'user' && $action->fields["field"] != 'otherserial' && $action->fields["field"] != 'software' && $action->fields["field"] != 'softwareversion')) {
$res = Dropdown::importExternal(getItemTypeForTable(getTableNameForForeignKeyField($action->fields['field'])), $res);
}
$output[$action->fields["field"]] = $res;
break;
default:
//plugins actions
$executeaction = clone $this;
$ouput = $executeaction->executePluginsActions($action, $output, $params);
break;
}
}
}
return $output;
}
开发者ID:paisdelconocimiento,项目名称:glpi-smartcities,代码行数:31,代码来源:collectrule.class.php
示例4: executeActions
function executeActions($output, $params)
{
PluginFusioninventoryToolbox::logIfExtradebug("pluginFusioninventory-locationrules", "execute action\n");
if (count($this->actions)) {
foreach ($this->actions as $action) {
switch ($action->fields["action_type"]) {
case "assign":
PluginFusioninventoryToolbox::logIfExtradebug("pluginFusioninventory-locationrules", "value " . $action->fields["value"] . "\n");
$output[$action->fields["field"]] = $action->fields["value"];
break;
case "regex_result":
$res = '';
if (isset($this->regex_results[0])) {
$res .= RuleAction::getRegexResultById($action->fields["value"], $this->regex_results[0]);
} else {
$res .= $action->fields["value"];
}
if ($res != '') {
$entities_id = 0;
if (isset($_SESSION["plugin_fusioninventory_entity"]) && $_SESSION["plugin_fusioninventory_entity"] > 0) {
$entities_id = $_SESSION["plugin_fusioninventory_entity"];
}
$res = Dropdown::importExternal(getItemTypeForTable(getTableNameForForeignKeyField($action->fields['field'])), $res, $entities_id);
}
$output[$action->fields["field"]] = $res;
break;
}
}
}
return $output;
}
开发者ID:paisdelconocimiento,项目名称:glpi-smartcities,代码行数:31,代码来源:inventoryrulelocation.class.php
示例5: executeActions
function executeActions($output, $params)
{
PluginFusioninventoryToolbox::logIfExtradebug("pluginFusioninventory-entityrules", "execute action\n");
if (count($this->actions)) {
foreach ($this->actions as $action) {
switch ($action->fields["action_type"]) {
case "assign":
PluginFusioninventoryToolbox::logIfExtradebug("pluginFusioninventory-entityrules", "value " . $action->fields["value"] . "\n");
$output[$action->fields["field"]] = $action->fields["value"];
break;
case "regex_result":
//Assign entity using the regex's result
if ($action->fields["field"] == "_affect_entity_by_tag") {
PluginFusioninventoryToolbox::logIfExtradebug("pluginFusioninventory-entityrules", "value " . $action->fields["value"] . "\n");
//Get the TAG from the regex's results
$res = RuleAction::getRegexResultById($action->fields["value"], $this->regex_results[0]);
if (!is_null($res)) {
//Get the entity associated with the TAG
$target_entity = Entity::getEntityIDByTag($res);
if ($target_entity != '') {
$output["entities_id"] = $target_entity;
} else {
$output['pass_rule'] = True;
}
}
}
break;
}
}
}
return $output;
}
开发者ID:paisdelconocimiento,项目名称:glpi-smartcities,代码行数:32,代码来源:inventoryruleentity.class.php
示例6: executeActions
/**
* @see Rule::executeActions()
**/
function executeActions($output, $params)
{
if (count($this->actions)) {
foreach ($this->actions as $action) {
switch ($action->fields["action_type"]) {
case "assign":
$output[$action->fields["field"]] = $action->fields["value"];
break;
case "regex_result":
//Assign entity using the regex's result
if ($action->fields["field"] == "_affect_entity_by_tag") {
//Get the TAG from the regex's results
if (isset($this->regex_results[0])) {
$res = RuleAction::getRegexResultById($action->fields["value"], $this->regex_results[0]);
} else {
$res = $action->fields["value"];
}
if ($res != null) {
//Get the entity associated with the TAG
$target_entity = Entity::getEntityIDByTag($res);
if ($target_entity != '') {
$output["entities_id"] = $target_entity;
}
}
}
break;
}
}
}
return $output;
}
开发者ID:gaforeror,项目名称:glpi,代码行数:34,代码来源:ruleimportentity.class.php
示例7: 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
示例8: 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
示例9: plugin_reports_rulelist
function plugin_reports_rulelist($rulecollection, $title)
{
Session::checkRight($rulecollection::$rightname, READ);
$rulecollection->getCollectionDatas(true, true);
echo "<div class='center'>";
echo "<table class='tab_cadre' cellpadding='5'>\n";
echo "<tr><th colspan='6'><a href='" . $_SERVER["PHP_SELF"] . "'>" . __('rules_report_title', 'reports') . "</a> - " . $title . "</th></tr>";
echo "<tr><th>" . __('Name') . "</th>";
echo "<th>" . __('Description') . "</th>";
echo "<th colspan='2'>" . _n('Criterion', 'Criteria', 2) . "</th>";
echo "<th>" . _n('Action', 'Actions', 2) . "</th>";
echo "<th>" . __('Active') . "</th></tr>\n";
foreach ($rulecollection->RuleList->list as $rule) {
echo "<tr class='tab_bg_1'>";
echo "<td>" . $rule->fields["name"] . "</td>";
echo "<td>" . $rule->fields["description"] . "</td>";
if ($rule->fields["match"] == Rule::AND_MATCHING) {
echo "<td>" . __('and') . "</td>";
} else {
echo "<td>" . __('or') . "</td>";
}
echo "<td>";
foreach ($rule->criterias as $criteria) {
echo $rule->getCriteriaName($criteria->fields["criteria"]) . " " . RuleCriteria::getConditionByID($criteria->fields["condition"], get_class($rule)) . " " . $rule->getCriteriaDisplayPattern($criteria->fields["criteria"], $criteria->fields["condition"], $criteria->fields["pattern"]) . "<br>";
}
echo "</td>";
echo "<td>";
foreach ($rule->actions as $action) {
echo $rule->getActionName($action->fields["field"]) . " " . RuleAction::getActionByID($action->fields["action_type"]) . " " . stripslashes($rule->getActionValue($action->fields["field"], $action->fields["action_type"], $action->fields["value"])) . "<br>";
}
echo "</td>";
if ($rule->fields["is_active"]) {
echo "<td>" . __('Yes') . "</td>";
} else {
echo "<td>" . __('No') . "</td>";
}
echo "</tr>\n";
}
echo "</table></div>\n";
}
开发者ID:paisdelconocimiento,项目名称:glpi-smartcities,代码行数:40,代码来源:rules.php
示例10: executeActions
/**
* Execute the actions as defined in the rule
*
* @see Rule::executeActions()
*
* @param $output the result of the actions
* @param $params the parameters
*
* @return the fields modified
**/
function executeActions($output, $params)
{
global $CFG_GLPI;
$entity = '';
$right = '';
$is_recursive = 0;
$continue = true;
$output_src = $output;
if (count($this->actions)) {
$entity = array();
foreach ($this->actions as $action) {
switch ($action->fields["action_type"]) {
case "assign":
switch ($action->fields["field"]) {
case "entities_id":
$entity[] = $action->fields["value"];
break;
case "profiles_id":
$right = $action->fields["value"];
break;
case "is_recursive":
$is_recursive = $action->fields["value"];
break;
case "is_active":
$output["is_active"] = $action->fields["value"];
break;
case "_ignore_user_import":
$continue = false;
$output_src["_stop_import"] = true;
break;
}
// switch (field)
break;
case "regex_result":
switch ($action->fields["field"]) {
case "_affect_entity_by_dn":
case "_affect_entity_by_tag":
case "_affect_entity_by_domain":
case "_affect_entity_by_completename":
foreach ($this->regex_results as $regex_result) {
$res = RuleAction::getRegexResultById($action->fields["value"], $regex_result);
if ($res != null) {
switch ($action->fields["field"]) {
case "_affect_entity_by_dn":
$entity_found = Entity::getEntityIDByDN(addslashes($res));
break;
case "_affect_entity_by_tag":
$entity_found = Entity::getEntityIDByTag(addslashes($res));
break;
case "_affect_entity_by_domain":
$entity_found = Entity::getEntityIDByDomain(addslashes($res));
break;
case "_affect_entity_by_completename":
$res = Toolbox::unclean_cross_side_scripting_deep($res);
$entity_found = Entity::getEntityIDByCompletename(addslashes($res));
break;
default:
$entity_found = -1;
break;
}
//If an entity was found
if ($entity_found > -1) {
$entity[] = $entity_found;
}
}
}
if (!count($entity)) {
//Not entity assigned : action processing must be stopped for this rule
$continue = false;
}
break;
}
// switch (field)
break;
}
// switch (action_type)
}
// foreach (action)
}
// count (actions)
if ($continue) {
//Nothing to be returned by the function :
//Store in session the entity and/or right
if (count($entity)) {
if ($right != '') {
foreach ($entity as $entID) {
$output["_ldap_rules"]["rules_entities_rights"][] = array($entID, $right, $is_recursive);
}
} else {
foreach ($entity as $entID) {
//.........这里部分代码省略.........
开发者ID:stweil,项目名称:glpi,代码行数:101,代码来源:ruleright.class.php
示例11: 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
示例12: executeActions
/**
* @see Rule::executeActions()
**/
function executeActions($output, $params)
{
if (count($this->actions)) {
foreach ($this->actions as $action) {
switch ($action->fields["action_type"]) {
case "assign":
switch ($action->fields["field"]) {
default:
$output[$action->fields["field"]] = $action->fields["value"];
break;
case "_affect_entity_by_user_entity":
//3 cases :
//1 - rule contains a criteria like : Profil is XXXX
// -> in this case, profiles_id is stored in
// $this->criterias_results['PROFILES'] (one value possible)
//2- rule contains criteria "User has only one profile"
// -> in this case, profiles_id is stored in
// $this->criterias_results['PROFILES'] (one value possible) (same as 1)
//3 -> rule contains only one profile
$profile = 0;
//Case 2:
if (isset($this->criterias_results['ONE_PROFILE'])) {
$profile = $this->criterias_results['ONE_PROFILE'];
//Case 3
} else {
if (isset($this->criterias_results['UNIQUE_PROFILE'])) {
$profile = $this->criterias_results['UNIQUE_PROFILE'];
//Case 1
} else {
if (isset($this->criterias_results['PROFILES'])) {
$profile = $this->criterias_results['PROFILES'];
}
}
}
if ($profile) {
$entities = array();
if (isset($params['_users_id_requester'])) {
// Not set when testing
$entities = Profile_User::getEntitiesForProfileByUser($params['_users_id_requester'], $profile);
}
//Case 2 : check if there's only one profile for this user
if (isset($this->criterias_results['ONE_PROFILE']) && count($entities) == 1 || !isset($this->criterias_results['ONE_PROFILE'])) {
if (count($entities) == 1) {
//User has right on only one entity
$output['entities_id'] = array_pop($entities);
} else {
if (isset($this->criterias_results['UNIQUE_PROFILE'])) {
$output['entities_id'] = array_pop($entities);
} else {
//Rights on more than one entity : get the user's prefered entity
if (isset($params['_users_id_requester'])) {
// Not set when testing
$user = new User();
$user->getFromDB($params['_users_id_requester']);
$tmpid = $user->getField('entities_id');
// Retrieve all the entities (pref could be set on a child)
$entities = Profile_User::getEntitiesForProfileByUser($params['_users_id_requester'], $profile, true);
// If an entity is defined in user's preferences,
// and this entity allowed for this profile, use this one
// else do not set the rule as matched
if (in_array($tmpid, $entities)) {
$output['entities_id'] = $user->fields['entities_id'];
}
}
}
}
}
}
}
break;
case "regex_result":
foreach ($this->regex_results as $regex_result) {
$entity_found = -1;
$res = RuleAction::getRegexResultById($action->fields["value"], $regex_result);
if ($res != null) {
switch ($action->fields["field"]) {
case "_affect_entity_by_domain":
$entity_found = Entity::getEntityIDByDomain(addslashes($res));
break;
case "_affect_entity_by_tag":
$entity_found = Entity::getEntityIDByTag(addslashes($res));
break;
}
//If an entity was found
if ($entity_found > -1) {
$output['entities_id'] = $entity_found;
break;
}
}
}
// switch (field)
break;
}
}
}
return $output;
}
开发者ID:kipman,项目名称:glpi,代码行数:100,代码来源:rulemailcollector.class.php
示例13: executeAddRule
/**
* @since version 0.83 (before addRule)
*
* @param $input array of values
**/
function executeAddRule($input)
{
$this->check($_POST["affectentity"], UPDATE);
$collection = RuleCollection::getClassByType($_POST['sub_type']);
$rule = $collection->getRuleClass($_POST['sub_type']);
$ruleid = $rule->add($_POST);
if ($ruleid) {
//Add an action associated to the rule
$ruleAction = new RuleAction();
//Action is : affect computer to this entity
$ruleAction->addActionByAttributes("assign", $ruleid, "entities_id", $_POST["affectentity"]);
switch ($_POST['sub_type']) {
case 'RuleRight':
if ($_POST["profiles_id"]) {
$ruleAction->addActionByAttributes("assign", $ruleid, "profiles_id", $_POST["profiles_id"]);
}
$ruleAction->addActionByAttributes("assign", $ruleid, "is_recursive", $_POST["is_recursive"]);
}
}
Event::log($ruleid, "rules", 4, "setup", sprintf(__('%s adds the item'), $_SESSION["glpiname"]));
Html::back();
}
开发者ID:korial29,项目名称:glpi,代码行数:27,代码来源:entity.class.php
示例14: 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
示例15: 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
示例16: executeActions
/**
* @param $output
* @param $params
**/
function executeActions($output, $params)
{
if (count($this->actions)) {
foreach ($this->actions as $action) {
switch ($action->fields["action_type"]) {
case "send":
$ticket = new Ticket();
if ($ticket->getFromDB($output['id'])) {
NotificationEvent::raiseEvent('recall', $ticket);
}
break;
case "add_validation":
if (isset($output['_add_validation']) && !is_array($output['_add_validation'])) {
$output['_add_validation'] = array($output['_add_validation']);
}
switch ($action->fields['field']) {
case 'users_id_validate_requester_supervisor':
$output['_add_validation'][] = 'requester_supervisor';
break;
case 'users_id_validate_assign_supervisor':
$output['_add_validation'][] = 'assign_supervisor';
break;
case 'groups_id_validate':
$output[
|
请发表评论