Skip to content

Commit

Permalink
events
Browse files Browse the repository at this point in the history
  • Loading branch information
salahhusa9 committed Oct 22, 2023
1 parent 0ddda67 commit 3614267
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Commands/CheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Salahhusa9\Updater\Commands;

use Illuminate\Console\Command;
use Salahhusa9\Updater\Events\NewVersionAvailable;
use Salahhusa9\Updater\Facades\Updater;

class UpdaterCommand extends Command
Expand All @@ -22,6 +23,8 @@ public function handle(): int

$this->info('New version available: '.$newVersionAvailable['new_version']);

event(new NewVersionAvailable($newVersionAvailable['current_version'],$newVersionAvailable['new_version']));

return self::SUCCESS;
}
}
20 changes: 20 additions & 0 deletions src/Events/NewVersionAvailable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Salahhusa9\Updater\Events;

use Illuminate\Queue\SerializesModels;
use Illuminate\Foundation\Events\Dispatchable;

class NewVersionAvailable
{
use Dispatchable, SerializesModels;

public $currentVersion;
public $newVersion;

public function __construct($currentVersion, $newVersion)
{
$this->currentVersion = $currentVersion;
$this->newVersion = $newVersion;
}
}
23 changes: 23 additions & 0 deletions src/Events/UpdateFailed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Salahhusa9\Updater\Events;

use Illuminate\Queue\SerializesModels;
use Illuminate\Foundation\Events\Dispatchable;

class UpdateFailed
{
use Dispatchable, SerializesModels;

public $pastVersion;
public $newVersion;
public $exception;

public function __construct($pastVersion, $newVersion, $exception)
{
$this->pastVersion = $pastVersion;
$this->newVersion = $newVersion;
$this->exception = $exception;
}
}

23 changes: 23 additions & 0 deletions src/Events/UpdatedSuccessfully.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Salahhusa9\Updater\Events;

use Illuminate\Queue\SerializesModels;
use Illuminate\Foundation\Events\Dispatchable;

class UpdatedSuccessfully
{
use Dispatchable, SerializesModels;

public $pastVersion;
public $newVersion;

public function __construct($pastVersion, $newVersion)
{
$this->pastVersion = $pastVersion;
$this->newVersion = $newVersion;
}
}



5 changes: 5 additions & 0 deletions src/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ private function updateTo($version): string
{
if (is_array($this->newVersionAvailable()) && $this->newVersionAvailable()['current_version'] != $version) {
try {
$current_version_in_past = $this->newVersionAvailable()['current_version'];

if (config('updater.maintenance_mode', false)) {
Artisan::call(
Expand Down Expand Up @@ -99,12 +100,16 @@ function ($content) {
Artisan::call('up');
}

event(new Events\UpdatedSuccessfully($current_version_in_past, $version));

return 'Updated to version '.$version;
} catch (\Throwable $th) {
if (config('updater.maintenance_mode', false)) {
Artisan::call('up');
}

event(new Events\UpdateFailed($current_version_in_past, $version, $th->getMessage()));

Check failure on line 111 in src/Updater.php

View workflow job for this annotation

GitHub Actions / phpstan

Variable $current_version_in_past might not be defined.

return throw $th;
}
} else {
Expand Down

0 comments on commit 3614267

Please sign in to comment.