Fix 500 when exiting hosting panel for existing accounts.
Deploy Ladill Hosting / deploy (push) Successful in 20s
Deploy Ladill Hosting / deploy (push) Successful in 20s
The account overview queried a local mailboxes table that the extracted hosting app does not have; guard those lookups and skip email-addon upsells when mailboxes are managed on Ladill Email. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -26,11 +26,12 @@ class HostingMailboxService
|
||||
*/
|
||||
public function usageSummary(HostingAccount $account): array
|
||||
{
|
||||
$account->loadMissing(['product', 'mailboxes']);
|
||||
$account->loadMissing(['product']);
|
||||
|
||||
$mailboxes = $account->loadedMailboxes();
|
||||
$freeAllowance = $account->freeEmailAllowance();
|
||||
$mailboxCount = $account->mailboxes->count();
|
||||
$paidCount = $account->mailboxes->where('is_paid', true)->count();
|
||||
$mailboxCount = $mailboxes->count();
|
||||
$paidCount = $mailboxes->where('is_paid', true)->count();
|
||||
$freeUsed = $freeAllowance === null ? $mailboxCount : min($mailboxCount, $freeAllowance);
|
||||
$extraCount = max($mailboxCount - ($freeAllowance ?? $mailboxCount), 0);
|
||||
|
||||
@@ -53,7 +54,15 @@ class HostingMailboxService
|
||||
|
||||
public function createMailbox(HostingAccount $account, array $input): array
|
||||
{
|
||||
$account->loadMissing(['product', 'mailboxes', 'sites']);
|
||||
$account->loadMissing(['product', 'sites']);
|
||||
|
||||
if (! HostingAccount::tracksLocalMailboxes()) {
|
||||
throw ValidationException::withMessages([
|
||||
'local_part' => 'Mailbox creation is managed in Ladill Email.',
|
||||
]);
|
||||
}
|
||||
|
||||
$account->loadMissing(['mailboxes']);
|
||||
|
||||
$domain = Domain::query()
|
||||
->whereKey((int) ($input['domain_id'] ?? 0))
|
||||
@@ -113,11 +122,11 @@ class HostingMailboxService
|
||||
|
||||
ProvisionMailboxJob::dispatch($mailbox->id, encrypt((string) $input['password']));
|
||||
|
||||
$invoice = $this->syncAddonInvoice($account->fresh(['mailboxes']));
|
||||
$invoice = $this->syncAddonInvoice($account->fresh());
|
||||
|
||||
return [
|
||||
'mailbox' => $mailbox->fresh(['domain']),
|
||||
'usage' => $this->usageSummary($account->fresh(['product', 'mailboxes'])),
|
||||
'usage' => $this->usageSummary($account->fresh(['product'])),
|
||||
'invoice' => $invoice,
|
||||
];
|
||||
}
|
||||
@@ -133,12 +142,12 @@ class HostingMailboxService
|
||||
$mailbox->update(['status' => 'deleting']);
|
||||
DeactivateMailboxJob::dispatch($mailbox->id);
|
||||
|
||||
return $this->syncAddonInvoice($account->fresh(['mailboxes']));
|
||||
return $this->syncAddonInvoice($account->fresh());
|
||||
}
|
||||
|
||||
public function syncAddonInvoice(HostingAccount $account): ?HostingBillingInvoice
|
||||
{
|
||||
$account->loadMissing(['product', 'mailboxes']);
|
||||
$account->loadMissing(['product']);
|
||||
$summary = $this->usageSummary($account);
|
||||
if ($summary['extra_count'] === 0) {
|
||||
HostingBillingInvoice::query()
|
||||
|
||||
@@ -20,11 +20,16 @@ class UpsellRecommendationService
|
||||
*/
|
||||
public function recommendationsForUser(User $user): Collection
|
||||
{
|
||||
$accounts = HostingAccount::query()
|
||||
$accountsQuery = HostingAccount::query()
|
||||
->where('user_id', $user->id)
|
||||
->where('status', HostingAccount::STATUS_ACTIVE)
|
||||
->with(['product', 'mailboxes:id,hosting_account_id,is_paid'])
|
||||
->get();
|
||||
->with(['product']);
|
||||
|
||||
if (HostingAccount::tracksLocalMailboxes()) {
|
||||
$accountsQuery->with(['mailboxes:id,hosting_account_id,is_paid']);
|
||||
}
|
||||
|
||||
$accounts = $accountsQuery->get();
|
||||
|
||||
return $accounts
|
||||
->flatMap(fn (HostingAccount $account): array => $this->recommendationsForAccount($account))
|
||||
@@ -37,7 +42,7 @@ class UpsellRecommendationService
|
||||
*/
|
||||
public function recommendationsForAccount(HostingAccount $account): array
|
||||
{
|
||||
$account->loadMissing(['product', 'mailboxes']);
|
||||
$account->loadMissing(['product']);
|
||||
|
||||
$recommendations = [];
|
||||
$upgradeProduct = $this->nextUpgradeProduct($account);
|
||||
@@ -75,8 +80,8 @@ class UpsellRecommendationService
|
||||
}
|
||||
|
||||
$freeAllowance = $account->freeEmailAllowance();
|
||||
$mailboxCount = $account->mailboxes->count();
|
||||
if ($freeAllowance !== null && $mailboxCount > $freeAllowance) {
|
||||
$mailboxCount = $account->loadedMailboxes()->count();
|
||||
if (HostingAccount::tracksLocalMailboxes() && $freeAllowance !== null && $mailboxCount > $freeAllowance) {
|
||||
$extraMailboxes = $mailboxCount - $freeAllowance;
|
||||
$addonAmount = self::EMAIL_ADDON_QUANTITY * self::EMAIL_ADDON_UNIT_PRICE;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user