Fixed various bugs.

This commit is contained in:
James Cole
2016-01-15 09:25:32 +01:00
parent f80bc214f9
commit 209258b507
8 changed files with 160 additions and 49 deletions

View File

@@ -409,4 +409,47 @@ class RuleRepository implements RuleRepositoryInterface
return $ruleAction;
}
/**
* @param Rule $rule
* @param array $data
* @return Rule
*/
public function updateRule(Rule $rule, array $data)
{
// update rule:
$rule->active = $data['active'];
$rule->stop_processing = $data['stop_processing'];
$rule->title = $data['title'];
$rule->description = $data['description'];
$rule->save();
// delete triggers:
$rule->ruleTriggers()->delete();
// delete actions:
$rule->ruleActions()->delete();
// recreate triggers:
$order = 1;
$stopProcessing = false;
$this->storeTrigger($rule, 'user_action', $data['trigger'], $stopProcessing, $order);
foreach ($data['rule-triggers'] as $index => $trigger) {
$value = $data['rule-trigger-values'][$index];
$stopProcessing = isset($data['rule-trigger-stop'][$index]) ? true : false;
$this->storeTrigger($rule, $trigger, $value, $stopProcessing, $order);
$order++;
}
// recreate actions:
$order = 1;
foreach ($data['rule-actions'] as $index => $action) {
$value = $data['rule-action-values'][$index];
$stopProcessing = isset($data['rule-action-stop'][$index]) ? true : false;
$this->storeAction($rule, $action, $value, $stopProcessing, $order);
}
return $rule;
}
}

View File

@@ -60,14 +60,14 @@ interface RuleRepositoryInterface
public function destroyRule(Rule $rule);
/**
* @param Rule $rule
* @param Rule $rule
* @param array $ids
* @return bool
*/
public function reorderRuleTriggers(Rule $rule, array $ids);
/**
* @param Rule $rule
* @param Rule $rule
* @param array $ids
* @return bool
*/
@@ -89,6 +89,13 @@ interface RuleRepositoryInterface
*/
public function moveRuleUp(Rule $rule);
/**
* @param Rule $rule
* @param array $data
* @return Rule
*/
public function updateRule(Rule $rule, array $data);
/**
* @param Rule $rule
* @return bool
@@ -128,22 +135,22 @@ interface RuleRepositoryInterface
/**
* @param Rule $rule
* @param Rule $rule
* @param string $action
* @param string $value
* @param bool $stopProcessing
* @param int $order
* @param bool $stopProcessing
* @param int $order
*
* @return RuleTrigger
*/
public function storeTrigger(Rule $rule, $action, $value, $stopProcessing, $order);
/**
* @param Rule $rule
* @param Rule $rule
* @param string $action
* @param string $value
* @param bool $stopProcessing
* @param int $order
* @param bool $stopProcessing
* @param int $order
*
* @return RuleAction
*/