*/ class UserPreferenceListener implements IEventListener { public function __construct( protected IJobList $jobList, ) { } public function handle(Event $event): void { if ($event instanceof BeforePreferenceSetEvent) { if ($event->getAppId() === 'dav' && $event->getConfigKey() === 'user_status_automation' && $event->getConfigValue() === 'yes') { $event->setValid(true); // Not the cleanest way, but we just add the job in the before event. // If something ever turns wrong the first execution will remove the job again. // We also first delete the current job, so the next run time is reset. $this->jobList->remove(UserStatusAutomation::class, ['userId' => $event->getUserId()]); $this->jobList->add(UserStatusAutomation::class, ['userId' => $event->getUserId()]); } } elseif ($event instanceof BeforePreferenceDeletedEvent) { if ($event->getAppId() === 'dav' && $event->getConfigKey() === 'user_status_automation') { $event->setValid(true); } } } }