Changeset View
Changeset View
Standalone View
Standalone View
src/app/Jobs/User/CreateJob.php
- This file was added.
<?php | |||||
namespace App\Jobs\User; | |||||
use App\Jobs\UserJob; | |||||
/** | |||||
* Create the \App\User in LDAP. | |||||
* | |||||
* Throws exceptions for the following reasons: | |||||
* | |||||
* * The user is marked as deleted (`$user->isDeleted()`), or | |||||
* * the user is actually deleted (`$user->deleted_at`), or | |||||
* * the user is already marked as ready in LDAP (`$user->isLdapReady()`). | |||||
* | |||||
*/ | |||||
class CreateJob extends UserJob | |||||
{ | |||||
/** | |||||
* Execute the job. | |||||
* | |||||
* @return void | |||||
* | |||||
* @throws \Exception | |||||
*/ | |||||
public function handle() | |||||
{ | |||||
$user = $this->getUser(); | |||||
// sanity checks | |||||
if ($user->isDeleted()) { | |||||
$this->fail(new \Exception("User {$this->userId} is marked as deleted.")); | |||||
} | |||||
if ($user->deleted_at) { | |||||
$this->fail(new \Exception("User {$this->userId} is actually deleted.")); | |||||
} | |||||
if ($user->isLdapReady()) { | |||||
$this->fail(new \Exception("User {$this->userId} is already marked as ldap-ready.")); | |||||
} | |||||
\App\Backends\LDAP::createUser($user); | |||||
$user->status |= \App\User::STATUS_LDAP_READY; | |||||
$user->save(); | |||||
} | |||||
} |