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