Changeset View
Changeset View
Standalone View
Standalone View
src/app/Jobs/Group/UpdateJob.php
<?php | <?php | ||||
namespace App\Jobs\Group; | namespace App\Jobs\Group; | ||||
use App\Backends\LDAP; | |||||
use App\Jobs\GroupJob; | use App\Jobs\GroupJob; | ||||
class UpdateJob extends GroupJob | class UpdateJob extends GroupJob | ||||
{ | { | ||||
/** | /** | ||||
* Execute the job. | * Execute the job. | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function handle() | public function handle() | ||||
{ | { | ||||
$group = $this->getGroup(); | $group = $this->getGroup(); | ||||
if (!$group) { | if (!$group) { | ||||
return; | return; | ||||
} | } | ||||
if (!$group->isLdapReady()) { | // Cancel the update if the group is deleted or not yet in LDAP | ||||
if (!$group->isLdapReady() || $group->isDeleted()) { | |||||
$this->delete(); | $this->delete(); | ||||
return; | return; | ||||
} | } | ||||
\App\Backends\LDAP::updateGroup($group); | LDAP::connect(); | ||||
// Groups does not have an attribute for the status, therefore | |||||
// we remove suspended groups from LDAP. | |||||
// We do not remove STATUS_LDAP_READY flag because it is part of the | |||||
// setup process. | |||||
$inLdap = !empty(LDAP::getGroup($group->email)); | |||||
if ($group->isSuspended() && $inLdap) { | |||||
LDAP::deleteGroup($group); | |||||
} elseif (!$group->isSuspended() && !$inLdap) { | |||||
LDAP::createGroup($group); | |||||
} else { | |||||
LDAP::updateGroup($group); | |||||
} | |||||
LDAP::disconnect(); | |||||
} | } | ||||
} | } |