recipes->keys() as $key ) { try { $existing = $this->automations->find_by_recipe_key( $key ); if ( null !== $existing ) { if ( ! $existing->is_enabled() && 0 === $existing->run_count() ) { $fresh = $this->recipes->materialise( $key, $this->clock ); if ( null !== $fresh ) { $existing->replace_definition( $fresh->name(), $fresh->description(), $fresh->trigger(), $fresh->conditions(), $fresh->actions(), $fresh->cancel_if(), $fresh->pause_period_hours(), $this->clock->now() ); $this->automations->save( $existing ); } } ++$saved; continue; } $automation = $this->recipes->materialise( $key, $this->clock ); if ( null === $automation ) { continue; } $this->automations->save( $automation ); ++$saved; } catch ( \Throwable ) { // Skip this key when the table or recipe_key column is missing. continue; } } return $saved; } }