Changeset View
Changeset View
Standalone View
Standalone View
src/app/Observers/ResourceSettingObserver.php
<?php | <?php | ||||
namespace App\Observers; | namespace App\Observers; | ||||
use App\Backends\LDAP; | |||||
use App\ResourceSetting; | use App\ResourceSetting; | ||||
class ResourceSettingObserver | class ResourceSettingObserver | ||||
{ | { | ||||
/** | /** | ||||
* Handle the resource setting "created" event. | * Handle the resource setting "created" event. | ||||
* | * | ||||
* @param \App\ResourceSetting $resourceSetting Settings object | * @param \App\ResourceSetting $resourceSetting Settings object | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function created(ResourceSetting $resourceSetting) | public function created(ResourceSetting $resourceSetting) | ||||
{ | { | ||||
if (in_array($resourceSetting->key, LDAP::RESOURCE_SETTINGS)) { | $this->dispatchUpdateJob($resourceSetting); | ||||
\App\Jobs\Resource\UpdateJob::dispatch($resourceSetting->resource_id); | |||||
} | |||||
} | } | ||||
/** | /** | ||||
* Handle the resource setting "updated" event. | * Handle the resource setting "updated" event. | ||||
* | * | ||||
* @param \App\ResourceSetting $resourceSetting Settings object | * @param \App\ResourceSetting $resourceSetting Settings object | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function updated(ResourceSetting $resourceSetting) | public function updated(ResourceSetting $resourceSetting) | ||||
{ | { | ||||
if (in_array($resourceSetting->key, LDAP::RESOURCE_SETTINGS)) { | $this->dispatchUpdateJob($resourceSetting); | ||||
\App\Jobs\Resource\UpdateJob::dispatch($resourceSetting->resource_id); | |||||
} | |||||
} | } | ||||
/** | /** | ||||
* Handle the resource setting "deleted" event. | * Handle the resource setting "deleted" event. | ||||
* | * | ||||
* @param \App\ResourceSetting $resourceSetting Settings object | * @param \App\ResourceSetting $resourceSetting Settings object | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function deleted(ResourceSetting $resourceSetting) | public function deleted(ResourceSetting $resourceSetting) | ||||
{ | { | ||||
if (in_array($resourceSetting->key, LDAP::RESOURCE_SETTINGS)) { | $this->dispatchUpdateJob($resourceSetting); | ||||
\App\Jobs\Resource\UpdateJob::dispatch($resourceSetting->resource_id); | } | ||||
/** | |||||
* Dispatch resource update job (if needed) | |||||
* | |||||
* @param \App\ResourceSetting $resourceSetting Settings object | |||||
*/ | |||||
private function dispatchUpdateJob(ResourceSetting $resourceSetting): void | |||||
{ | |||||
if ((\config('app.with_ldap') && in_array($resourceSetting->key, \App\Backends\LDAP::RESOURCE_SETTINGS)) | |||||
|| in_array($resourceSetting->key, \App\Backends\IMAP::RESOURCE_SETTINGS) | |||||
) { | |||||
$props = [$resourceSetting->key => $resourceSetting->getOriginal('value')]; | |||||
\App\Jobs\Resource\UpdateJob::dispatch($resourceSetting->resource_id, $props); | |||||
} | } | ||||
} | } | ||||
} | } |