Skip to content

Commit 2d43520

Browse files
author
micha
committed
bump code to php 8.1
remove dead code fix connection config optimize code
1 parent 6bf759c commit 2d43520

18 files changed

+203
-256
lines changed

composer.json

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,16 @@
1616
}
1717
],
1818
"require": {
19-
"php": "^7.4|^8.0",
19+
"php": "^8.1",
2020
"macropage/php-to-ascii-table" : "dev-master",
2121
"codedungeon/php-cli-colors" : "^1.0",
2222
"macropage/ansi-to-html" : "dev-master"
2323
},
24-
"require-dev": {
25-
"orchestra/testbench": "^4.0",
26-
"phpunit/phpunit": "^8.0"
27-
},
2824
"autoload": {
2925
"psr-4": {
3026
"macropage\\LaravelSchedulerWatcher\\": "src"
3127
}
3228
},
33-
"autoload-dev": {
34-
"psr-4": {
35-
"macropage\\LaravelSchedulerWatcher\\Tests\\": "tests"
36-
}
37-
},
38-
"scripts": {
39-
"test": "vendor/bin/phpunit",
40-
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
41-
42-
},
4329
"config": {
4430
"sort-packages": true
4531
},

migrations/2020_05_12_200432_create_scheduler_watcher_job_event_outputs_table.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
use Illuminate\Database\Migrations\Migration;
44
use Illuminate\Database\Schema\Blueprint;
55

6-
class CreateSchedulerWatcherJobEventOutputsTable extends Migration {
6+
class CreateSchedulerWatcherJobEventOutputsTable extends Migration
7+
{
78

89
/**
910
* Run the migrations.
1011
*
1112
* @return void
1213
*/
13-
public function up(): void {
14-
Schema::connection('mysql_scheduler')->create(config('scheduler-watcher.table_prefix') . 'job_event_outputs', function (Blueprint $table) {
14+
public function up(): void
15+
{
16+
Schema::connection(config('laravel-scheduler-watcher.mysql_connection'))->create(config('scheduler-watcher.table_prefix') . 'job_event_outputs', function (Blueprint $table) {
1517
$table->integer('jobo_id', true);
1618
$table->integer('jobo_jobe_id')->nullable()->index('FK_job_event_outputs_job_events_jobe_id');
1719
$table->text('jobo_output')->nullable();
@@ -24,8 +26,9 @@ public function up(): void {
2426
*
2527
* @return void
2628
*/
27-
public function down(): void {
28-
Schema::connection('mysql_scheduler')->drop(config('scheduler-watcher.table_prefix') . 'job_event_outputs');
29+
public function down(): void
30+
{
31+
Schema::connection(config('laravel-scheduler-watcher.mysql_connection'))->drop(config('scheduler-watcher.table_prefix') . 'job_event_outputs');
2932
}
3033

3134
}

migrations/2020_05_12_200432_create_scheduler_watcher_job_events_table.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
use Illuminate\Database\Migrations\Migration;
44
use Illuminate\Database\Schema\Blueprint;
55

6-
class CreateSchedulerWatcherJobEventsTable extends Migration {
6+
class CreateSchedulerWatcherJobEventsTable extends Migration
7+
{
78

89
/**
910
* Run the migrations.
1011
*
1112
* @return void
1213
*/
13-
public function up(): void {
14-
Schema::connection('mysql_scheduler')->create(config('scheduler-watcher.table_prefix') . 'job_events', function (Blueprint $table) {
14+
public function up(): void
15+
{
16+
Schema::connection(config('laravel-scheduler-watcher.mysql_connection'))->create(config('scheduler-watcher.table_prefix') . 'job_events', function (Blueprint $table) {
1517
$table->integer('jobe_id', true);
1618
$table->integer('jobe_job_id')->nullable()->index('FK_job_events_jobs_job_id');
1719
$table->dateTime('jobe_start')->nullable();
@@ -28,8 +30,9 @@ public function up(): void {
2830
*
2931
* @return void
3032
*/
31-
public function down(): void {
32-
Schema::connection('mysql_scheduler')->drop(config('scheduler-watcher.table_prefix') . 'job_events');
33+
public function down(): void
34+
{
35+
Schema::connection(config('laravel-scheduler-watcher.mysql_connection'))->drop(config('scheduler-watcher.table_prefix') . 'job_events');
3336
}
3437

3538
}

migrations/2020_05_12_200432_create_scheduler_watcher_jobs_table.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
use Illuminate\Database\Migrations\Migration;
44
use Illuminate\Database\Schema\Blueprint;
55

6-
class CreateSchedulerWatcherJobsTable extends Migration {
6+
class CreateSchedulerWatcherJobsTable extends Migration
7+
{
78

89
/**
910
* Run the migrations.
1011
*
1112
* @return void
1213
*/
13-
public function up(): void {
14-
Schema::connection('mysql_scheduler')->create(config('scheduler-watcher.table_prefix') . 'jobs', function (Blueprint $table) {
14+
public function up(): void
15+
{
16+
Schema::connection(config('laravel-scheduler-watcher.mysql_connection'))->create(config('scheduler-watcher.table_prefix') . 'jobs', function (Blueprint $table) {
1517
$table->integer('job_id', true);
1618
$table->char('job_md5', 32)->unique('UK_jobs_job_md5');
1719
$table->string('job_name');
@@ -26,8 +28,9 @@ public function up(): void {
2628
*
2729
* @return void
2830
*/
29-
public function down(): void {
30-
Schema::connection('mysql_scheduler')->drop(config('scheduler-watcher.table_prefix') . 'jobs');
31+
public function down(): void
32+
{
33+
Schema::connection(config('laravel-scheduler-watcher.mysql_connection'))->drop(config('scheduler-watcher.table_prefix') . 'jobs');
3134
}
3235

3336
}

migrations/2020_05_12_200435_add_foreign_keys_to_scheduler_watcher_job_event_outputs_table.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
use Illuminate\Database\Migrations\Migration;
44
use Illuminate\Database\Schema\Blueprint;
55

6-
class AddForeignKeysToSchedulerWatcherJobEventOutputsTable extends Migration {
6+
class AddForeignKeysToSchedulerWatcherJobEventOutputsTable extends Migration
7+
{
78

89
/**
910
* Run the migrations.
1011
*
1112
* @return void
1213
*/
13-
public function up(): void {
14-
Schema::connection('mysql_scheduler')->table(config('scheduler-watcher.table_prefix') . 'job_event_outputs', function (Blueprint $table) {
14+
public function up(): void
15+
{
16+
Schema::connection(config('laravel-scheduler-watcher.mysql_connection'))->table(config('scheduler-watcher.table_prefix') . 'job_event_outputs', function (Blueprint $table) {
1517
$table->foreign('jobo_jobe_id', 'FK_job_event_outputs_job_events_jobe_id')->references('jobe_id')->on(config('scheduler-watcher.table_prefix') . 'job_events')->onUpdate('RESTRICT')->onDelete('CASCADE');
1618
});
1719
}
@@ -22,8 +24,9 @@ public function up(): void {
2224
*
2325
* @return void
2426
*/
25-
public function down(): void {
26-
Schema::connection('mysql_scheduler')->table(config('scheduler-watcher.table_prefix') . 'job_event_outputs', function (Blueprint $table) {
27+
public function down(): void
28+
{
29+
Schema::connection(config('laravel-scheduler-watcher.mysql_connection'))->table(config('scheduler-watcher.table_prefix') . 'job_event_outputs', function (Blueprint $table) {
2730
$table->dropForeign('FK_job_event_outputs_job_events_jobe_id');
2831
});
2932
}

migrations/2020_05_12_200435_add_foreign_keys_to_scheduler_watcher_job_events_table.php

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,32 @@
33
use Illuminate\Database\Migrations\Migration;
44
use Illuminate\Database\Schema\Blueprint;
55

6-
class AddForeignKeysToSchedulerWatcherJobEventsTable extends Migration {
6+
class AddForeignKeysToSchedulerWatcherJobEventsTable extends Migration
7+
{
78

8-
/**
9-
* Run the migrations.
10-
*
11-
* @return void
12-
*/
13-
public function up(): void {
14-
Schema::connection('mysql_scheduler')->table(config('scheduler-watcher.table_prefix').'job_events', function(Blueprint $table)
15-
{
16-
$table->foreign('jobe_job_id', 'FK_job_events_jobs_job_id')->references('job_id')->on(config('scheduler-watcher.table_prefix').'jobs')->onUpdate('RESTRICT')->onDelete('NO ACTION');
17-
});
18-
}
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up(): void
15+
{
16+
Schema::connection(config('laravel-scheduler-watcher.mysql_connection'))->table(config('scheduler-watcher.table_prefix') . 'job_events', function (Blueprint $table) {
17+
$table->foreign('jobe_job_id', 'FK_job_events_jobs_job_id')->references('job_id')->on(config('scheduler-watcher.table_prefix') . 'jobs')->onUpdate('RESTRICT')->onDelete('NO ACTION');
18+
});
19+
}
1920

2021

21-
/**
22-
* Reverse the migrations.
23-
*
24-
* @return void
25-
*/
26-
public function down(): void {
27-
Schema::connection('mysql_scheduler')->table(config('scheduler-watcher.table_prefix').'job_events', function(Blueprint $table)
28-
{
29-
$table->dropForeign('FK_job_events_jobs_job_id');
30-
});
31-
}
22+
/**
23+
* Reverse the migrations.
24+
*
25+
* @return void
26+
*/
27+
public function down(): void
28+
{
29+
Schema::connection(config('laravel-scheduler-watcher.mysql_connection'))->table(config('scheduler-watcher.table_prefix') . 'job_events', function (Blueprint $table) {
30+
$table->dropForeign('FK_job_events_jobs_job_id');
31+
});
32+
}
3233

3334
}

src/Console/SchedulerWatcherCommandCheckLastRun.php

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,17 @@ class SchedulerWatcherCommandCheckLastRun extends Command {
2323
*/
2424
protected $description = 'Get common infos of Jobs';
2525

26-
/**
27-
* Create a new command instance.
28-
*
29-
* @return void
30-
*/
31-
public function __construct() {
32-
parent::__construct();
33-
}
34-
35-
/**
36-
* Execute the console command.
37-
*
38-
* @return mixed
39-
*/
40-
public function handle() {
26+
public function handle(): string|int|null
27+
{
4128
$job = jobs::whereJobMd5($this->argument('jobMD5'))->first();
4229
if (!$job) {
4330
$this->echo('unable to find any job with your md5','error');
44-
return 2;
31+
return self::INVALID;
4532
}
4633
$last_job_events = job_events::whereJobeJobId($job->job_id)->orderByDesc('jobe_id')->limit(1)->get()->first();
4734
if (!$last_job_events) {
4835
$this->echo('no events found for this job','warn');
49-
return 2;
36+
return self::INVALID;
5037
}
5138
$job_output = job_event_outputs::whereJoboJobeId($last_job_events->jobe_id)->first('jobo_output');
5239
$output = "Last exitcode from job: ".$job->job_name.': ['.$last_job_events->jobe_exitcode.'] - last output: ';
@@ -64,26 +51,15 @@ public function handle() {
6451
return $last_job_events->jobe_exitcode;
6552
}
6653

67-
/**
68-
* @param $str
69-
* @param null $type
70-
* @param int $exitcode
71-
*/
72-
private function echo($str, $type=null, $exitcode=0):void {
54+
private function echo($str, ?string $type=null, int $exitcode=0):void {
7355
if ($this->option('noansi')) {
7456
echo $str;
7557
} else {
76-
switch ($exitcode) {
77-
case 1:
78-
$type = 'warn';
79-
breaK;
80-
case 0:
81-
$type = 'info';
82-
break;
83-
default:
84-
$type = 'error';
85-
break;
86-
}
58+
$type = match ($exitcode) {
59+
1 => 'warn',
60+
0 => 'info',
61+
default => 'error',
62+
};
8763
$this->$type($str);
8864
}
8965
}

src/Console/SchedulerWatcherCommandCleanUp.php

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
use macropage\LaravelSchedulerWatcher\Models\jobs;
77
use Illuminate\Console\Command;
88

9-
class SchedulerWatcherCommandCleanUp extends Command {
9+
class SchedulerWatcherCommandCleanUp extends Command
10+
{
1011
/**
1112
* The name and signature of the console command.
1213
*
@@ -21,22 +22,9 @@ class SchedulerWatcherCommandCleanUp extends Command {
2122
*/
2223
protected $description = 'Clean table job_events and keep last X entries';
2324

24-
/**
25-
* Create a new command instance.
26-
*
27-
* @return void
28-
*/
29-
public function __construct() {
30-
parent::__construct();
31-
}
3225

33-
/**
34-
* Execute the console command.
35-
*
36-
* @return mixed
37-
* @throws \Exception
38-
*/
39-
public function handle() {
26+
public function handle(): int
27+
{
4028
$job = jobs::whereJobMd5($this->argument('jobMD5'))->first();
4129
if (!$job) {
4230
$this->alert('unable to find any job with your md5');
@@ -51,8 +39,8 @@ public function handle() {
5139
foreach ($last_job_events as $job_event) {
5240
$events_we_keep[] = $job_event->jobe_id;
5341
}
54-
$count_deleted = job_events::whereJobeJobId($job->job_id)->whereNotIn('jobe_id',$events_we_keep)->delete();
55-
$this->info('deleted '.$count_deleted.' old entries of: '.$job->job_name);
42+
$count_deleted = job_events::whereJobeJobId($job->job_id)->whereNotIn('jobe_id', $events_we_keep)->delete();
43+
$this->info('deleted ' . $count_deleted . ' old entries of: ' . $job->job_name);
5644
return 0;
5745
}
5846
}

src/Console/SchedulerWatcherCommandCleanUpAll.php

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
use macropage\LaravelSchedulerWatcher\Models\jobs;
77
use Illuminate\Console\Command;
88

9-
class SchedulerWatcherCommandCleanUpAll extends Command {
9+
class SchedulerWatcherCommandCleanUpAll extends Command
10+
{
1011
/**
1112
* The name and signature of the console command.
1213
*
@@ -21,23 +22,9 @@ class SchedulerWatcherCommandCleanUpAll extends Command {
2122
*/
2223
protected $description = 'Clean table job_events and keep last X entries of every existing job';
2324

24-
/**
25-
* Create a new command instance.
26-
*
27-
* @return void
28-
*/
29-
public function __construct() {
30-
parent::__construct();
31-
}
3225

33-
/**
34-
* Execute the console command.
35-
*
36-
* @return mixed
37-
* @throws \Exception
38-
* @noinspection DuplicatedCode
39-
*/
40-
public function handle() {
26+
public function handle(): int
27+
{
4128
$jobs = jobs::all();
4229
if ($jobs->isEmpty()) {
4330
$this->alert('no jobs found!');

0 commit comments

Comments
 (0)