diff --git a/bin/doctum b/bin/doctum index fda44876..569d076b 100755 --- a/bin/doctum +++ b/bin/doctum @@ -1,12 +1,15 @@ #!/bin/bash cwd=$(dirname $0) pushd ${cwd}/../src/ +rm -rf cache/store/ + php -dmemory_limit=-1 \ vendor/bin/doctum.php \ update \ - doctum.config.php + doctum.config.php \ + -v popd diff --git a/src/app/Jobs/User/CreateJob.php b/src/app/Jobs/User/CreateJob.php new file mode 100644 index 00000000..cb613c3b --- /dev/null +++ b/src/app/Jobs/User/CreateJob.php @@ -0,0 +1,48 @@ +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(); + } +} diff --git a/src/app/Jobs/User/DeleteJob.php b/src/app/Jobs/User/DeleteJob.php new file mode 100644 index 00000000..19b834a2 --- /dev/null +++ b/src/app/Jobs/User/DeleteJob.php @@ -0,0 +1,28 @@ +getUser(); + + // sanity checks + if ($user->isDeleted()) { + $this->fail(new \Exception("User {$this->userId} is already marked as deleted.")); + } + + LDAP::deleteUser($user); + + $user->status |= User::STATUS_DELETED; + $user->save(); + } +} diff --git a/src/app/Jobs/User/UpdateJob.php b/src/app/Jobs/User/UpdateJob.php new file mode 100644 index 00000000..c05357a9 --- /dev/null +++ b/src/app/Jobs/User/UpdateJob.php @@ -0,0 +1,25 @@ +getUser(); + + if (!$user->isLdapReady()) { + $this->delete(); + return; + } + + LDAP::updateUser($user); + } +} diff --git a/src/app/Jobs/User/Verify.php b/src/app/Jobs/User/Verify.php new file mode 100644 index 00000000..58ac373e --- /dev/null +++ b/src/app/Jobs/User/Verify.php @@ -0,0 +1,34 @@ +getUser(); + + // sanity checks + if (!$user->hasSku('mailbox')) { + $this->fail(new \Exception("User {$this->userId} has no mailbox SKU.")); + } + + // the user has a mailbox (or is marked as such) + if ($user->isImapReady()) { + $this->fail(new \Exception("User {$this->userId} is already verified.")); + } + + if (IMAP::verifyAccount($user->email)) { + $user->status |= User::STATUS_IMAP_READY; + $user->status |= User::STATUS_ACTIVE; + $user->save(); + } + } +} diff --git a/src/app/Jobs/UserCreate.php b/src/app/Jobs/UserCreate.php deleted file mode 100644 index da34a45d..00000000 --- a/src/app/Jobs/UserCreate.php +++ /dev/null @@ -1,54 +0,0 @@ -user = $user; - } - - /** - * Execute the job. - * - * @return void - */ - public function handle() - { - if (!$this->user->isLdapReady()) { - LDAP::createUser($this->user); - - $this->user->status |= User::STATUS_LDAP_READY; - $this->user->save(); - } - } -} diff --git a/src/app/Jobs/UserDelete.php b/src/app/Jobs/UserDelete.php deleted file mode 100644 index 7cd9ac9f..00000000 --- a/src/app/Jobs/UserDelete.php +++ /dev/null @@ -1,53 +0,0 @@ -user = User::withTrashed()->find($user_id); - } - - /** - * Execute the job. - * - * @return void - */ - public function handle() - { - if (!$this->user->isDeleted()) { - LDAP::deleteUser($this->user); - - $this->user->status |= User::STATUS_DELETED; - $this->user->save(); - } - } -} diff --git a/src/app/Jobs/UserJob.php b/src/app/Jobs/UserJob.php new file mode 100644 index 00000000..2bdf6008 --- /dev/null +++ b/src/app/Jobs/UserJob.php @@ -0,0 +1,87 @@ +handle(); + * ``` + */ +abstract class UserJob implements ShouldQueue +{ + use Dispatchable; + use InteractsWithQueue; + use Queueable; + + /** + * The ID for the \App\User. This is the shortest globally unique identifier and saves Redis space + * compared to a serialized version of the complete \App\User object. + * + * @var int + */ + protected $userId; + + /** + * The \App\User email property, for legibility in the queue management. + * + * @var string + */ + protected $userEmail; + + /** + * The number of tries for this Job. + * + * @var int + */ + public $tries = 5; + + /** + * Create a new job instance. + * + * @param int $userId The ID for the user to create. + * + * @return void + */ + public function __construct(int $userId) + { + $this->userId = $userId; + + $user = $this->getUser($userId); + + $this->userEmail = $user->email; + } + + /** + * Execute the job. + * + * @return void + */ + abstract public function handle(); + + /** + * Get the \App\User entry associated with this job. + * + * @return \App\User|null + * + * @throws \Exception + */ + protected function getUser() + { + $user = \App\User::withTrashed()->find($this->userId); + + if (!$user) { + $this->fail(new \Exception("User {$this->userId} could not be found in the database.")); + } + + return $user; + } +} diff --git a/src/app/Jobs/UserUpdate.php b/src/app/Jobs/UserUpdate.php deleted file mode 100644 index a1d6a7cc..00000000 --- a/src/app/Jobs/UserUpdate.php +++ /dev/null @@ -1,47 +0,0 @@ -user = $user; - } - - /** - * Execute the job. - * - * @return void - */ - public function handle() - { - LDAP::updateUser($this->user); - } -} diff --git a/src/app/Jobs/UserVerify.php b/src/app/Jobs/UserVerify.php deleted file mode 100644 index 8fec9add..00000000 --- a/src/app/Jobs/UserVerify.php +++ /dev/null @@ -1,60 +0,0 @@ -user = $user; - } - - /** - * Execute the job. - * - * @return void - */ - public function handle() - { - if (!$this->user->hasSku('mailbox')) { - return; - } - - // The user has a mailbox - if (!$this->user->isImapReady()) { - if (IMAP::verifyAccount($this->user->email)) { - $this->user->status |= User::STATUS_IMAP_READY; - $this->user->status |= User::STATUS_ACTIVE; - $this->user->save(); - } - } - } -} diff --git a/src/doctum.config.php b/src/doctum.config.php index f52ab9f4..56365a6d 100644 --- a/src/doctum.config.php +++ b/src/doctum.config.php @@ -1,17 +1,26 @@ files() ->name('*.php') ->exclude('bootstrap') ->exclude('cache') ->exclude('database') + ->exclude('include') ->exclude('node_modules') ->exclude('tests') ->exclude('vendor') ->in(__DIR__); -return new Doctum($iterator); +return new Doctum( + $iterator, + [ + 'build_dir' => __DIR__ . '/../docs/build/%version%/', + 'cache_dir' => __DIR__ . '/cache/', + 'default_opened_level' => 1, + //'include_parent_data' => false, + ] +);