Changeset View
Changeset View
Standalone View
Standalone View
src/app/Jobs/Resource/CreateJob.php
Show All 24 Lines | public function handle() | ||||
return; | return; | ||||
} | } | ||||
if ($resource->trashed()) { | if ($resource->trashed()) { | ||||
$this->fail(new \Exception("Resource {$this->resourceId} is actually deleted.")); | $this->fail(new \Exception("Resource {$this->resourceId} is actually deleted.")); | ||||
return; | return; | ||||
} | } | ||||
if ($resource->isLdapReady()) { | $withLdap = \config('app.with_ldap'); | ||||
$this->fail(new \Exception("Resource {$this->resourceId} is already marked as ldap-ready.")); | |||||
return; | |||||
} | |||||
// see if the domain is ready | // see if the domain is ready | ||||
$domain = $resource->domain(); | $domain = $resource->domain(); | ||||
if (!$domain) { | if (!$domain) { | ||||
$this->fail(new \Exception("The domain for resource {$this->resourceId} does not exist.")); | $this->fail(new \Exception("The domain for resource {$this->resourceId} does not exist.")); | ||||
return; | return; | ||||
} | } | ||||
if ($domain->isDeleted()) { | if ($domain->isDeleted()) { | ||||
$this->fail(new \Exception("The domain for resource {$this->resourceId} is marked as deleted.")); | $this->fail(new \Exception("The domain for resource {$this->resourceId} is marked as deleted.")); | ||||
return; | return; | ||||
} | } | ||||
if (!$domain->isLdapReady()) { | if ($withLdap && !$domain->isLdapReady()) { | ||||
$this->release(60); | $this->release(60); | ||||
return; | return; | ||||
} | } | ||||
if ($withLdap && !$resource->isLdapReady()) { | |||||
\App\Backends\LDAP::createResource($resource); | \App\Backends\LDAP::createResource($resource); | ||||
$resource->status |= \App\Resource::STATUS_LDAP_READY; | $resource->status |= \App\Resource::STATUS_LDAP_READY; | ||||
$resource->save(); | $resource->save(); | ||||
} | } | ||||
if (!$resource->isImapReady()) { | |||||
if (!\App\Backends\IMAP::createResource($resource)) { | |||||
throw new \Exception("Failed to create mailbox for resource {$this->resourceId}."); | |||||
} | |||||
$resource->status |= \App\Resource::STATUS_IMAP_READY; | |||||
} | |||||
$resource->status |= \App\Resource::STATUS_ACTIVE; | |||||
$resource->save(); | |||||
} | |||||
} | } |