Laravel Application Self-Updater
, (*1)
This package provides some basic methods to implement a self updating
functionality for your Laravel 5 application. Already bundled are some
methods to provide a self-update mechanism via Github., (*2)
Usually you need this when distributing a self-hosted Laravel application
that needs some updating mechanism, as you do not want to bother your
lovely users with Git and/or Composer commands ;-), (*3)
Install with Composer
There are currently two branches:
* master
: Compatible with PHP 7.x
* 5.x
: Compatible with PHP 5.5 + 5.6, (*4)
Please select the right branch for your PHP version accordingly., (*5)
To install the latest version from the master using Composer:, (*6)
$ composer require codedge/laravel-selfupdater
This adds the codedge/laravel-selfupdater package to your composer.json
and downloads the project., (*7)
You need to include the service provider in your config/app.php
[1]
and optionally the facade [2]
:, (*8)
// config/app.php
return [
//...
'providers' => [
// ...
Codedge\Updater\UpdaterServiceProvider::class, // [1]
],
// ...
'aliases' => [
// ...
'Updater' => Codedge\Updater\UpdaterManager::class, // [2]
]
Additionally add the listener to your app/Providers/EventServiceProvider.php
:, (*9)
// app/Providers/EventServiceProvider.php
/**
* The event handler mappings for the application.
*
* @var array
*/
protected $listen = [
// ...
\Codedge\Updater\Events\UpdateAvailable::class => [
\Codedge\Updater\Listeners\SendUpdateAvailableNotification::class
],
\Codedge\Updater\Events\UpdateSucceeded::class => [
\Codedge\Updater\Listeners\SendUpdateSucceededNotification::class
],
];
Configuration
After installing the package you need to publish the configuration file via
sh
$ php artisan vendor:publish --provider="Codedge\Updater\UpdaterServiceProvider"
, (*10)
Note: Please enter correct value for vendor and repository name in your config/self-updater.php
if you want to
use Github as source for your updates., (*11)
Running artisan commands
Artisan commands can be run before or after the update process and can be configured in config/self-updater.php
:, (*12)
Example:, (*13)
'artisan_commands' => [
'pre_update' => [
'updater:prepare' => [
'class' => \App\Console\Commands\PreUpdateTasks::class,
'params' => []
],
],
'post_update' => [
'postupdate:cleanup' => [
'class' => \App\Console\Commands\PostUpdateCleanup::class,
'params' => [
'log' => 1,
'reset' => false,
// etc.
]
]
]
]
Notifications via email
You need to specify a recipient email address and a recipient name to receive
update available notifications.
You can specify these values by adding SELF_UPDATER_MAILTO_NAME
and
SELF_UPDATER_MAILTO_ADDRESS
to your .env
file., (*14)
Config name |
Description |
SELF_UPDATER_MAILTO_NAME |
Name of email recipient |
SELF_UPDATER_MAILTO_ADDRESS |
Address of email recipient |
SELF_UPDATER_MAILTO_UPDATE_AVAILABLE_SUBJECT |
Subject of update available email |
SELF_UPDATER_MAILTO_UPDATE_SUCCEEDED_SUBJECT |
Subject of update succeeded email |
Usage
To start an update process, i. e. in a controller, just use:, (*15)
public function update()
{
// This downloads and install the latest version of your repo
Updater::update();
// Just download the source and do the actual update elsewhere
Updater::fetch();
// Check if a new version is available and pass current version
Updater::isNewVersionAvailable('1.2');
}
Of course you can inject the updater via method injection:, (*16)
public function update(UpdaterManager $updater)
{
$updater->update(); // Same as above
// .. and shorthand for this:
$updater->source()->update;
$updater->fetch() // Same as above...
}
Note: Currently the fetching of the source is a synchronous process.
It is not run in background., (*17)
Using Github
The package comes with a Github source repository type to fetch
releases from Github - basically use Github to pull the latest version
of your software., (*18)
Just make sure you set the proper repository in your config/self-updater.php
file., (*19)
Extending and adding new source repository types
You want to pull your new versions from elsewhere? Feel free to create
your own source repository type somewhere but keep in mind for the new
source repository type:, (*20)
- It needs to extend AbstractRepositoryType
- It needs to implement SourceRepositoryTypeContract
So the perfect class head looks like, (*21)
class BitbucketRepositoryType extends AbstractRepositoryType implements SourceRepositoryTypeContract
Afterwards you may create your own service provider,
i. e. BitbucketUpdaterServiceProvider, with your boot method like so:, (*22)
public function boot()
{
Updater::extend('bitbucket', function($app) {
return Updater::sourceRepository(new BitbucketRepositoryType);
});
}
Now you call your own update source with:, (*23)
public function update(UpdaterManager $updater)
{
$updater->source('bitbucket')->update();
}
Contributing
Please see the contributing guide., (*24)
Roadmap
Just a quickly sketched roadmap what still needs to be implemented., (*25)
Licence
The MIT License (MIT). Please see Licencse file for more information., (*26)