Skip to content

Commit 176c689

Browse files
author
Holger Lösken
committed
Resolve codedge#39, add configuration to run artisan commands before and after update
1 parent 2a0f339 commit 176c689

File tree

4 files changed

+80
-5
lines changed

4 files changed

+80
-5
lines changed

README.md

+28-4
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,34 @@ After installing the package you need to publish the configuration file via
8383
$ php artisan vendor:publish --provider="Codedge\Updater\UpdaterServiceProvider"
8484
```
8585

86-
**Note:** Please enter correct value for vendor and repository name in
87-
your `config/self-updater.php` if you want to use Github as source for
88-
your updates.
89-
86+
**Note:** Please enter correct value for vendor and repository name in your `config/self-updater.php` if you want to
87+
use Github as source for your updates.
88+
89+
### Running artisan commands
90+
Artisan commands can be run before or after the update process and can be configured in `config/self-updater.php`:
91+
92+
__Example:__
93+
```php
94+
'artisan_commands' => [
95+
'pre_update' => [
96+
'updater:prepare' => [
97+
'class' => \App\Console\Commands\PreUpdateTasks::class,
98+
'params' => []
99+
],
100+
],
101+
'post_update' => [
102+
'postupdate:cleanup' => [
103+
'class' => \App\Console\Commands\PostUpdateCleanup::class,
104+
'params' => [
105+
'log' => 1,
106+
'reset' => false,
107+
// etc.
108+
]
109+
]
110+
]
111+
]
112+
```
113+
90114
### Notifications via email
91115
You need to specify a recipient email address and a recipient name to receive
92116
update available notifications.

config/self-update.php

+18
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,22 @@
9595
'subject_update_succeeded' => env('SELF_UPDATER_MAILTO_UPDATE_SUCCEEDED_SUBJECT', 'Update succeeded'),
9696
],
9797

98+
/*
99+
|---------------------------------------------------------------------------
100+
| Register custom artisan commands
101+
|---------------------------------------------------------------------------
102+
*/
103+
104+
'artisan_commands' => [
105+
'pre_update' => [
106+
//'command:signature' => [
107+
// 'class' => Command class
108+
// 'params' => []
109+
//]
110+
],
111+
'post_update' => [
112+
113+
]
114+
]
115+
98116
];

src/SourceRepository.php

+26-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Codedge\Updater;
44

55
use Codedge\Updater\Contracts\SourceRepositoryTypeContract;
6+
use Illuminate\Support\Facades\Artisan;
67

78
/**
89
* SourceRepository.
@@ -57,7 +58,11 @@ public function update($version = '', $forceFetching = true) : bool
5758
$this->fetch($version);
5859
}
5960

60-
return $this->sourceRepository->update($version);
61+
$this->preUpdateArtisanCommands();
62+
$updateStatus = $this->sourceRepository->update($version);
63+
$this->postUpdateArtisanCommands();
64+
65+
return $updateStatus;
6166
}
6267

6368
/**
@@ -99,4 +104,24 @@ public function getVersionAvailable($prepend = '', $append = '') : string
99104
{
100105
return $this->sourceRepository->getVersionAvailable($prepend, $append);
101106
}
107+
108+
/**
109+
* Run pre update artisan commands from config.
110+
*/
111+
protected function preUpdateArtisanCommands()
112+
{
113+
collect(config('self-update.artisan_commands.pre_update'))->every(function ($commandParams, $commandKey) {
114+
Artisan::call($commandKey, $commandParams['params']);
115+
});
116+
}
117+
118+
/**
119+
* Run post update artisan commands from config.
120+
*/
121+
protected function postUpdateArtisanCommands()
122+
{
123+
collect(config('self-update.artisan_commands.post_update'))->every(function ($commandParams, $commandKey) {
124+
Artisan::call($commandKey, $commandParams['params']);
125+
});
126+
}
102127
}

src/UpdaterServiceProvider.php

+8
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ protected function registerCommands()
6363
$this->commands([
6464
CheckForUpdate::class,
6565
]);
66+
67+
// Register custom commands from config
68+
collect(config('self-update.artisan_commands.pre_update'))->each(function ($command) {
69+
$this->commands([$command['class']]);
70+
});
71+
collect(config('self-update.artisan_commands.post_update'))->each(function ($command) {
72+
$this->commands([$command['class']]);
73+
});
6674
}
6775

6876
/**

0 commit comments

Comments
 (0)