2017-09-14 04:46:43 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use Illuminate\Database\Migrations\Migration;
|
|
|
|
|
|
|
|
class UpdateOldPermissionsToPointToNewScheduleSystem extends Migration
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Run the migrations.
|
|
|
|
*/
|
2022-11-25 21:29:04 +01:00
|
|
|
public function up(): void
|
2017-09-14 04:46:43 +02:00
|
|
|
{
|
|
|
|
$permissions = DB::table('permissions')->where('permission', 'like', '%-task%')->get();
|
|
|
|
foreach ($permissions as $record) {
|
|
|
|
$parts = explode('-', $record->permission);
|
2021-01-23 21:33:34 +01:00
|
|
|
if (!in_array(array_get($parts, 1), ['tasks', 'task']) || count($parts) !== 2) {
|
2017-09-14 04:46:43 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$newPermission = $parts[0] . '-' . str_replace('task', 'schedule', $parts[1]);
|
|
|
|
|
|
|
|
DB::table('permissions')->where('id', '=', $record->id)->update(['permission' => $newPermission]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reverse the migrations.
|
|
|
|
*/
|
2022-11-25 21:29:04 +01:00
|
|
|
public function down(): void
|
2017-09-14 04:46:43 +02:00
|
|
|
{
|
|
|
|
$permissions = DB::table('permissions')->where('permission', 'like', '%-schedule%')->get();
|
|
|
|
foreach ($permissions as $record) {
|
|
|
|
$parts = explode('-', $record->permission);
|
2021-01-23 21:33:34 +01:00
|
|
|
if (!in_array(array_get($parts, 1), ['schedules', 'schedule']) || count($parts) !== 2) {
|
2017-09-14 04:46:43 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$newPermission = $parts[0] . '-' . str_replace('schedule', 'task', $parts[1]);
|
|
|
|
|
|
|
|
DB::table('permissions')->where('id', '=', $record->id)->update(['permission' => $newPermission]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|