registry = $registry; $this->automationStorage = $automationStorage; } public function initialize(Automation $automation): void { $this->cachedExistingAutomation = false; } public function visitNode(Automation $automation, AutomationNode $node): void { $step = $node->getStep(); $registryStep = $this->registry->getStep($step->getKey()); // step not registered (e.g. plugin was deactivated) - allow saving it only if it hasn't changed if (!$registryStep) { $currentAutomation = $this->getCurrentAutomation($automation); $currentStep = $currentAutomation ? ($currentAutomation->getSteps()[$step->getId()] ?? null) : null; if (!$currentStep || $step->toArray() !== $currentStep->toArray()) { throw Exceptions::automationStepModifiedWhenUnknown($step); } } } public function complete(Automation $automation): void { } private function getCurrentAutomation(Automation $automation): ?Automation { try { $id = $automation->getId(); if ($this->cachedExistingAutomation === false) { $this->cachedExistingAutomation = $this->automationStorage->getAutomation($id); } } catch (InvalidStateException $e) { // for new automations, no automation ID is set $this->cachedExistingAutomation = null; } return $this->cachedExistingAutomation; } }