From e1bd90de9ca4a5e6887b7d2701c8911478eee6ce Mon Sep 17 00:00:00 2001 From: kaioken Date: Tue, 21 Dec 2021 02:16:41 -0400 Subject: [PATCH] feat : add sync rules --- src/Traits/CanUseRules.php | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/Traits/CanUseRules.php b/src/Traits/CanUseRules.php index 8bf282d..15836f8 100644 --- a/src/Traits/CanUseRules.php +++ b/src/Traits/CanUseRules.php @@ -13,18 +13,24 @@ trait CanUseRules { protected array $rulesRelatedEntities = []; + protected bool $enableWorkflows = true; /** * fireRules. * * search rules for companies and systems_modules * - * @param mixed $event + * @param mixed $event + * @param bool $useAsync * * @return void */ - public function fireRules(string $event) : void + public function fireRules(string $event, bool $useAsync = true) : void { + if ($this->enableWorkflows === false) { + return; + } + $rulesTypes = RulesTypes::findFirstByName($event); if (!$rulesTypes) { return; @@ -38,7 +44,7 @@ public function fireRules(string $event) : void if ($rules->count()) { foreach ($rules as $rule) { - if ($rule->isAsync()) { + if ($rule->isAsync() && $useAsync) { RulesJob::dispatch($rule, $event, $this); } else { $rulesJobs = new RulesJob($rule, $event, $this); @@ -74,7 +80,7 @@ public function getRulesRelatedEntities() : array * Add rulesRelatedEntities to toArray allowing us to pass values to the queue * why? when serializing the object only db properties are unserialize based on toArray. * - * @param [type] $columns + * @param mixed $columns * * @return array */ @@ -85,4 +91,24 @@ public function toArray($columns = null) : array return $array; } + + /** + * Enable workflows. + * + * @return void + */ + public function enableWorkflows() : void + { + $this->enableWorkflows = true; + } + + /** + * Disable workflows. + * + * @return void + */ + public function disableWorkflows() : void + { + $this->enableWorkflows = false; + } }