Refactor menu codes to remove 'onticket' prefix

- Updated route middleware and menu codes across various files to replace 'onticket.adminapp' with 'adminapp'.
- Adjusted API routes for Ticketing, FiestaFutbolInfantil, and Desfile to reflect the new menu structure.
- Modified database migrations to remove the 'onticket' prefix from existing menu codes.
- Updated tests to align with the new menu code structure, ensuring compatibility and correctness.
This commit is contained in:
2026-10-02 10:04:55 -03:00
parent 007ba9d572
commit 09827e55aa
20 changed files with 270 additions and 98 deletions

View File

@@ -0,0 +1,63 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
public function up(): void
{
DB::transaction(function (): void {
$menus = DB::table('menues')->where('code', 'like', 'onticket.%')->get();
// Create every destination before updating foreign keys, including parents.
foreach ($menus as $menu) {
$data = (array) $menu;
unset($data['id']);
$data['code'] = substr($menu->code, strlen('onticket.'));
if (! DB::table('menues')->where('code', $data['code'])->exists()) {
DB::table('menues')->insert($data);
}
}
foreach ($menus as $menu) {
$code = substr($menu->code, strlen('onticket.'));
DB::table('menues')->where('parent_menu_code', $menu->code)
->update(['parent_menu_code' => $code]);
$this->moveAssignments('tenants_menues', 'menu_code', 'tenant_code', $menu->code, $code);
$this->moveAssignments('roles_menues', 'menu_codigo', 'rol_codigo', $menu->code, $code);
}
DB::table('menues')->whereIn('code', $menus->pluck('code'))->delete();
});
}
private function moveAssignments(
string $table,
string $menuColumn,
string $ownerColumn,
string $sourceCode,
string $targetCode,
): void {
foreach (DB::table($table)->where($menuColumn, $sourceCode)->get() as $assignment) {
$data = (array) $assignment;
unset($data['id']);
$data[$menuColumn] = $targetCode;
DB::table($table)->updateOrInsert([
$ownerColumn => $data[$ownerColumn],
$menuColumn => $targetCode,
], $data);
}
DB::table($table)->where($menuColumn, $sourceCode)->delete();
}
public function down(): void
{
// Keep compatible identifiers: merged assignments cannot be split reliably.
}
};