Skip to content

Commit

Permalink
Make automation conditions optional for rules to be triggered.
Browse files Browse the repository at this point in the history
  • Loading branch information
sampoyigi committed Aug 30, 2023
1 parent e43b242 commit 95f2f30
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 40 deletions.
37 changes: 0 additions & 37 deletions classes/BaseEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,45 +161,8 @@ public static function findEventObjects()
return $results;
}

public static function findEventGroups()
{
return self::findRulesValues('groups');
}

public static function findEventsByGroup($group)
{
$results = [];
foreach (self::findEvents() as $eventClass => [$eventCode, $eventObj]) {
if ($eventObj->getEventGroup() == $group)
$results[$eventClass] = $eventObj;
}

return $results;
}

public static function findEventByIdentifier($identifier)
{
foreach (self::findEvents() as [$eventCode, $eventObj]) {
if ($eventObj->getEventIdentifier() == $identifier)
return $eventObj;
}
}

public static function findEventPresets()
{
return self::findRulesValues('presets');
}

public static function findEventPresetsByClass($className)
{
$results = [];
foreach (self::findEventPresets() as $code => $definition) {
if (array_get($definition, 'event', false) != $className)
continue;

$results[$code] = $definition;
}

return $results;
}
}
2 changes: 1 addition & 1 deletion language/en/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@

'help_event' => 'This rule is triggered by the selected system event',
'help_actions' => 'Choose one or more actions to perform when this automation is triggered',
'help_conditions' => 'Choose one or more conditions that must be met for this automation to be triggered. You must choose at least one condition to enable this automation.',
'help_conditions' => 'Choose one or more conditions that must be met for this automation to be triggered. Leave blank to always trigger this automation.',
];
4 changes: 2 additions & 2 deletions models/AutomationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ class AutomationRule extends Model
public function triggerRule()
{
try {
if (!$this->conditions || !$this->actions)
if (!$this->actions)
return false;

$params = $this->getEventObject()->getEventParams();

if (!$this->checkConditions($params))
if ($this->conditions && !$this->checkConditions($params))
return false;

$this->actions->each(function ($action) use ($params) {
Expand Down

0 comments on commit 95f2f30

Please sign in to comment.