From e51fec2f57ce92d7882509fb01f4621b353441d4 Mon Sep 17 00:00:00 2001 From: pc-10 Date: Fri, 26 Sep 2025 11:37:23 -0300 Subject: [PATCH 1/2] feat: add kernel schedule extraction with bulk import functionality - Add extractFromKernel method to extract schedules from Laravel Kernel - Create ImportService to handle schedule import logic with duplicate prevention - Add importFromKernel method with upsert functionality (create new or update existing) - Create extract.blade.php view with bulk selection interface --- resources/lang/en/schedule.php | 20 +++- resources/views/extract.blade.php | 120 +++++++++++++++++++ resources/views/index.blade.php | 4 + routes/web.php | 6 +- src/Http/Controllers/ScheduleController.php | 45 +++++++ src/Http/Services/ImportService.php | 23 ++++ src/Http/Services/KernelExtractorService.php | 106 ++++++++++++++++ 7 files changed, 319 insertions(+), 5 deletions(-) create mode 100644 resources/views/extract.blade.php create mode 100644 src/Http/Services/ImportService.php create mode 100644 src/Http/Services/KernelExtractorService.php diff --git a/resources/lang/en/schedule.php b/resources/lang/en/schedule.php index 6b04f2b..1079134 100644 --- a/resources/lang/en/schedule.php +++ b/resources/lang/en/schedule.php @@ -5,7 +5,8 @@ 'create' => 'Create new schedule', 'edit' => 'Edit schedule', 'show' => 'Show run history', - 'back_to_application' => 'Back to application' + 'back_to_application' => 'Back to application', + 'extract' => 'Extract Schedules from Kernel' ], 'fields' => [ 'command' => 'Command', @@ -33,7 +34,8 @@ 'updated_at' => 'Updated At', 'never' => 'Never', 'groups' => 'Groups', - 'environments' => 'Environments' + 'environments' => 'Environments', + 'settings' => 'Settings' ], 'messages' => [ 'no-records-found' => 'No records found.', @@ -48,7 +50,13 @@ 'help-type' => 'Multiple :type can be specified separated by commas', 'attention-type-function' => "ATTENTION: parameters of the type 'function' are executed before the execution of the scheduling and its return is passed as parameter. Use with care, it can break your job", 'delete_cronjob' => 'Delete cronjob', - 'delete_cronjob_confirm' => 'Do you really want to delete the cronjob ":cronjob"?' + 'delete_cronjob_confirm' => 'Do you really want to delete the cronjob ":cronjob"?', + 'import-success' => 'Schedules extracted successfully', + 'import-error' => 'Error extracting schedules', + 'no-schedules-found' => 'No schedules found in Kernel.', + 'all-environments' => 'All', + 'no-overlap' => 'No Overlap', + 'one-server' => 'One Server' ], 'status' => [ 'active' => 'Active', @@ -65,7 +73,11 @@ 'delete' => 'Delete', 'history' => 'History', 'cancel' => 'Cancel', - 'restore' => 'Restore' + 'restore' => 'Restore', + 'extract_kernel' => 'Extract from Kernel', + 'select_all' => 'Select All', + 'select_none' => 'Select None', + 'import_selected' => 'Import Selected' ], 'validation' => [ 'cron' => 'The field must be filled in the cron expression format.', diff --git a/resources/views/extract.blade.php b/resources/views/extract.blade.php new file mode 100644 index 0000000..be0be0b --- /dev/null +++ b/resources/views/extract.blade.php @@ -0,0 +1,120 @@ +@extends('schedule::layout.master') + +@section('content') +
+
+
+
+
+ {{ trans('schedule::schedule.titles.extract') }} + + {{ trans('schedule::schedule.buttons.back') }} + +
+ +
+ @include('schedule::messages') + + @if(count($extractedSchedules) > 0) +
+ @csrf + +
+ + + +
+ +
+ + + + + + + + + + + + @foreach($extractedSchedules as $index => $schedule) + + + + + + + + @endforeach + +
+ + {{ trans('schedule::schedule.fields.command') }}{{ trans('schedule::schedule.fields.expression') }}{{ trans('schedule::schedule.fields.environments') }}{{ trans('schedule::schedule.fields.settings') }}
+ + + {{ $schedule['command'] }} + @if(!empty($schedule['params'])) +
+ @foreach($schedule['params'] as $key => $param) + {{ $key }}: {{ $param }} + @endforeach + @endif +
{{ $schedule['expression'] }} + @if($schedule['environments']) + {{ $schedule['environments'] }} + @else + {{ trans('schedule::schedule.messages.all-environments') }} + @endif + + @if($schedule['without_overlapping']) + {{ trans('schedule::schedule.messages.no-overlap') }} + @endif + @if($schedule['on_one_server']) + {{ trans('schedule::schedule.messages.one-server') }} + @endif + @if($schedule['status']) + {{ trans('schedule::schedule.status.active') }} + @else + {{ trans('schedule::schedule.status.inactive') }} + @endif +
+
+
+ @else +
+ {{ trans('schedule::schedule.messages.no-schedules-found') }} +
+ @endif +
+
+
+
+
+ + +@endsection diff --git a/resources/views/index.blade.php b/resources/views/index.blade.php index e6618e0..0ce21e6 100644 --- a/resources/views/index.blade.php +++ b/resources/views/index.blade.php @@ -122,6 +122,10 @@ class="bi {{ ($schedule->status ? 'bi-pause' : 'bi-play') }}">