Require package reinstall after industry change and wipe old queues.
Deploy Ladill Queue / deploy (push) Successful in 1m5s

Changing industry now flags a pending reinstall with an app banner; reinstall clears queues, tickets, and service points before applying the new template.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-17 20:10:25 +00:00
co-authored by Cursor
parent f1edf8a19e
commit a2d5a8affd
5 changed files with 276 additions and 29 deletions
+33 -20
View File
@@ -35,6 +35,8 @@ class SettingsController extends Controller
?? data_get($organization->settings, 'industry')
?? 'custom';
$activePackage = $packages->get($packageKey);
$selectedIndustry = data_get($organization->settings, 'industry', $packageKey);
$selectedPackage = $packages->get($selectedIndustry) ?? $activePackage;
return view('qms.settings.edit', [
'organization' => $organization,
@@ -43,7 +45,9 @@ class SettingsController extends Controller
'appointmentModes' => config('qms.appointment_modes'),
'industries' => $packages->labels(),
'activePackage' => $activePackage,
'selectedPackage' => $selectedPackage,
'packageMeta' => data_get($organization->settings, 'industry_package'),
'needsPackageReinstall' => IndustryPackageInstaller::needsReinstall($organization),
'hasPaidPlan' => $plans->hasPaidPlan($organization),
'isPro' => $plans->isPro($organization),
'isEnterprise' => $plans->isEnterprise($organization),
@@ -82,6 +86,7 @@ class SettingsController extends Controller
$settings['appointment_mode'] = $validated['appointment_mode'];
$previousIndustry = $settings['industry'] ?? null;
$installedPackage = data_get($settings, 'industry_package.key');
if ($industry !== null) {
$settings['industry'] = $industry;
}
@@ -95,6 +100,17 @@ class SettingsController extends Controller
}
$settings['integrations'] = $integrations;
$industryChanged = $industry !== null
&& $industry !== $previousIndustry;
$outOfSyncWithPackage = $industry !== null
&& is_string($installedPackage)
&& $installedPackage !== ''
&& $industry !== $installedPackage;
if ($industryChanged || $outOfSyncWithPackage) {
$settings['industry_package_needs_reinstall'] = true;
}
$logoPath = $organization->logo_path;
if ($request->boolean('remove_logo')) {
@@ -115,28 +131,21 @@ class SettingsController extends Controller
AuditLogger::record($owner, 'organization.updated', $organization->id, $owner, \App\Models\Organization::class, $organization->id);
$industryChanged = ($settings['industry'] ?? null) && ($settings['industry'] ?? null) !== $previousIndustry;
$packageNote = '';
if ($industryChanged) {
$branch = Branch::query()
->where('organization_id', $organization->id)
->where('is_active', true)
->orderBy('id')
->first();
if ($branch) {
try {
app(IndustryPackageInstaller::class)->install($organization->fresh(), $branch, $settings['industry'], [
'actor_ref' => $owner,
]);
$packageNote = ' Industry package re-provisioned.';
} catch (\Throwable $e) {
report($e);
$packageNote = ' Settings saved, but industry package re-provision failed — try Reinstall package.';
}
}
if ($industryChanged || $outOfSyncWithPackage) {
$label = $registry->get($industry)?->label() ?? $industry;
$packageNote = " Industry changed to {$label} — reinstall the industry package to replace queues and service points.";
}
return back()->with('success', 'Settings saved.'.$packageNote);
$redirect = back()->with('success', 'Settings saved.'.$packageNote);
if ($industryChanged || $outOfSyncWithPackage) {
$redirect->with(
'warning',
'Reinstall the industry package to apply the new template. This will clear existing queues, tickets, and service points.'
);
}
return $redirect;
}
public function reinstallPackage(Request $request, IndustryPackageInstaller $installer): RedirectResponse
@@ -159,9 +168,13 @@ class SettingsController extends Controller
$result = $installer->install($organization, $branch, $key, [
'actor_ref' => $owner,
'include_optional' => true,
'replace' => true,
]);
$message = 'Industry package synced.';
$message = ($result['replaced'] ?? false)
? 'Industry package reinstalled. Previous queues, tickets, and service points were cleared.'
: 'Industry package synced.';
if (($result['skipped_reason'] ?? null) === 'plan_queue_limit') {
$message .= ' Some stages were skipped because of your plan queue limit — upgrade to Pro for the full template.';
} elseif (($result['skipped_reason'] ?? null) === 'stages_managed_by_integration') {