From d2d64d2a6390bf929bd93c6a7ecff7c720863a3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20Lo=CC=88sken?= Date: Thu, 18 Aug 2016 21:52:59 +0200 Subject: [PATCH] Use self-updater package, initial commit --- app/Console/Kernel.php | 5 ++ app/Http/Controllers/SelfUpdateController.php | 63 ++++++++++++++++ app/Http/routes.php | 3 + app/Providers/EventServiceProvider.php | 5 ++ composer.json | 3 +- composer.lock | 72 ++++++++++++++++-- config/app.php | 3 +- config/self-update.php | 73 +++++++++++++++++++ resources/lang/en/texts.php | 11 ++- resources/views/header.blade.php | 12 +++ .../mails/update-available.blade.php | 5 ++ .../vendor/self-update/self-update.blade.php | 58 +++++++++++++++ 12 files changed, 305 insertions(+), 8 deletions(-) create mode 100644 app/Http/Controllers/SelfUpdateController.php create mode 100644 config/self-update.php create mode 100644 resources/views/vendor/self-update/mails/update-available.blade.php create mode 100644 resources/views/vendor/self-update/self-update.blade.php diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 0cda6a4c86..665d592532 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -52,5 +52,10 @@ class Kernel extends ConsoleKernel ->sendOutputTo($logFile) ->daily(); } + + $schedule + ->command('updater:check-for-update --prefixVersionWith=v') + ->sendOutputTo($logFile) + ->daily(); } } diff --git a/app/Http/Controllers/SelfUpdateController.php b/app/Http/Controllers/SelfUpdateController.php new file mode 100644 index 0000000000..1f362da3eb --- /dev/null +++ b/app/Http/Controllers/SelfUpdateController.php @@ -0,0 +1,63 @@ +updater = $updater; + } + + /** + * Show default update page + * + * @return mixed + */ + public function index() + { + $versionInstalled = $this->updater->source()->getVersionInstalled('v'); + $updateAvailable = $this->updater->source()->isNewVersionAvailable($versionInstalled); + + return view( + 'vendor.self-update.self-update', + [ + 'versionInstalled' => $versionInstalled, + 'versionAvailable' => $this->updater->source()->getVersionAvailable(), + 'updateAvailable' => $updateAvailable + ] + ); + } + + /** + * Run the actual update + * + * @return \Illuminate\Http\RedirectResponse + */ + public function update() + { + $this->updater->source()->update(); + + return Redirect::to('/'); + } + + public function download() + { + $this->updater->source()->fetch(); + } +} diff --git a/app/Http/routes.php b/app/Http/routes.php index c540c68139..a730ffec5f 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -265,6 +265,9 @@ Route::group([ Route::post('bank_accounts/bulk', 'BankAccountController@bulk'); Route::post('bank_accounts/validate', 'BankAccountController@validateAccount'); Route::post('bank_accounts/import_expenses/{bank_id}', 'BankAccountController@importExpenses'); + Route::get('self-update', 'SelfUpdateController@index'); + Route::post('self-update', 'SelfUpdateController@update'); + Route::get('self-update/download', 'SelfUpdateController@download'); }); // Route groups for API diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 0e847484ad..7bbbf92afd 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -159,6 +159,11 @@ class EventServiceProvider extends ServiceProvider { 'App\Events\TaskWasUpdated' => [ 'App\Listeners\ActivityListener@updatedTask', ], + + // Update events + \Codedge\Updater\Events\UpdateAvailable::class => [ + \Codedge\Updater\Listeners\SendUpdateAvailableNotification::class + ], ]; /** diff --git a/composer.json b/composer.json index fa1744a8a1..860b54e9e9 100644 --- a/composer.json +++ b/composer.json @@ -81,7 +81,8 @@ "barryvdh/laravel-ide-helper": "~2.2", "barryvdh/laravel-debugbar": "~2.2", "fzaninotto/faker": "^1.5", - "jaybizzle/laravel-crawler-detect": "1.*" + "jaybizzle/laravel-crawler-detect": "1.*", + "codedge/laravel-selfupdater": "5.x-dev" }, "require-dev": { "phpunit/phpunit": "~4.0", diff --git a/composer.lock b/composer.lock index 9644c8319d..bb46be6a5b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "58fb4c4de809dbd2c62e2701e4c31b12", - "content-hash": "308faa59f58a34174062714c7c9c5c48", + "hash": "09fda381adad88df20782277ade92809", + "content-hash": "77223af5b09a5e08bf323379fe8e3f24", "packages": [ { "name": "agmscode/omnipay-agms", @@ -1023,6 +1023,62 @@ ], "time": "2015-01-08 10:05:58" }, + { + "name": "codedge/laravel-selfupdater", + "version": "5.x-dev", + "source": { + "type": "git", + "url": "https://github.com/codedge/laravel-selfupdater.git", + "reference": "bc1272686ecaf11dd140400a072c1c98b845e44d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/codedge/laravel-selfupdater/zipball/bc1272686ecaf11dd140400a072c1c98b845e44d", + "reference": "bc1272686ecaf11dd140400a072c1c98b845e44d", + "shasum": "" + }, + "require": { + "ext-zip": "*", + "guzzlehttp/guzzle": "6.*", + "illuminate/support": "5.*", + "php": ">=5.5" + }, + "require-dev": { + "mockery/mockery": "^0.9.5", + "orchestra/testbench": "3.2.*", + "phpunit/phpunit": "^4.8" + }, + "type": "library", + "autoload": { + "psr-4": { + "Codedge\\Updater\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Holger Lösken", + "email": "holger.loesken@codedge.de", + "homepage": "http://codedge.de", + "role": "Developer" + } + ], + "description": "Providing an auto-updating functionality for your self-hosted Laravel application.", + "keywords": [ + "auto update", + "auto-update", + "laravel", + "laravel application", + "self update", + "self-hosted laravel application", + "self-update", + "update" + ], + "time": "2016-08-19 12:47:15" + }, { "name": "collizo4sky/omnipay-wepay", "version": "dev-additional-calls", @@ -2121,8 +2177,13 @@ "url": "https://github.com/gatepay/FedACHdir.git", "reference": "origin/master" }, - "type": "library", - "time": "2016-06-03 12:00:26" + "dist": { + "type": "zip", + "url": "https://github.com/gatepay/FedACHdir/archive/master.zip", + "reference": "origin/master", + "shasum": null + }, + "type": "library" }, { "name": "google/apiclient", @@ -10537,7 +10598,8 @@ "jlapp/swaggervel": 20, "omnipay/braintree": 20, "gatepay/fedachdir": 20, - "collizo4sky/omnipay-wepay": 20 + "collizo4sky/omnipay-wepay": 20, + "codedge/laravel-selfupdater": 20 }, "prefer-stable": false, "prefer-lowest": false, diff --git a/config/app.php b/config/app.php index 7ef56f68f0..985fdcc6d4 100644 --- a/config/app.php +++ b/config/app.php @@ -155,6 +155,7 @@ return [ 'Maatwebsite\Excel\ExcelServiceProvider', Websight\GcsProvider\CloudStorageServiceProvider::class, 'Jaybizzle\LaravelCrawlerDetect\LaravelCrawlerDetectServiceProvider', + Codedge\Updater\UpdaterServiceProvider::class, /* * Application Service Providers... @@ -257,7 +258,7 @@ return [ 'Excel' => 'Maatwebsite\Excel\Facades\Excel', 'PushNotification' => 'Davibennun\LaravelPushNotification\Facades\PushNotification', 'Crawler' => 'Jaybizzle\LaravelCrawlerDetect\Facades\LaravelCrawlerDetect', - + 'Updater' => Codedge\Updater\UpdaterFacade::class, ], ]; diff --git a/config/self-update.php b/config/self-update.php new file mode 100644 index 0000000000..53d4ac8f0f --- /dev/null +++ b/config/self-update.php @@ -0,0 +1,73 @@ + env('SELF_UPDATER_SOURCE', 'github'), + + /* + |-------------------------------------------------------------------------- + | Version installed + |-------------------------------------------------------------------------- + | + | Set this to the version of your software installed on your system. + | + */ + + 'version_installed' => env('SELF_UPDATER_VERSION_INSTALLED', '2.6.9'), + + /* + |-------------------------------------------------------------------------- + | Repository types + |-------------------------------------------------------------------------- + | + | A repository can be of different types, which can be specified here. + | Current options: + | - github + | + */ + + 'repository_types' => [ + 'github' => [ + 'type' => 'github', + 'repository_vendor' => env('SELF_UPDATER_REPO_VENDOR', 'invoiceninja'), + 'repository_name' => env('SELF_UPDATER_REPO_NAME', 'invoiceninja'), + 'repository_url' => '', + 'download_path' => env('SELF_UPDATER_DOWNLOAD_PATH', '/tmp'), + ], + ], + + /* + |-------------------------------------------------------------------------- + | Event Logging + |-------------------------------------------------------------------------- + | + | Configure if fired events should be logged + | + */ + + 'log_events' => env('SELF_UPDATER_LOG_EVENTS', false), + + /* + |-------------------------------------------------------------------------- + | Mail To Settings + |-------------------------------------------------------------------------- + | + | Configure if fired events should be logged + | + */ + + 'mail_to' => [ + 'address' => env('SELF_UPDATER_MAILTO_ADDRESS', ''), + 'name' => env('SELF_UPDATER_MAILTO_NAME', ''), + ], + +]; diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 8ebf0a545d..c355f861c5 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2075,7 +2075,16 @@ $LANG = array( 'include_item_taxes_inline' => 'Include line item taxes in line total', 'created_quotes' => 'Successfully created :count quotes(s)', - + + 'warning' => 'Warning', + 'self-update' => 'Update Invoice Ninja', + 'update_invoiceninja_title' => 'Update Invoice Ninja', + 'update_invoiceninja_warning' => 'Before start upgrading Invoice Ninja create a backup of your database and files!', + 'update_invoiceninja_available' => 'A new version of Invoice Ninja is available.', + 'update_invoiceninja_unavailable' => 'No new version of Invoice Ninja available.', + 'update_invoiceninja_decide_update_download' => 'You can decide to update directly to :version or to just download the new relase and update later.', + 'update_invoiceninja_update_start' => 'Update now', + 'update_invoiceninja_download_start' => 'Download :version', ); return $LANG; diff --git a/resources/views/header.blade.php b/resources/views/header.blade.php index 9d298c205b..026f29bcab 100644 --- a/resources/views/header.blade.php +++ b/resources/views/header.blade.php @@ -469,6 +469,18 @@ + @if (Utils::isAdmin()) + + @endif +