commit
be69b6ec41
26
app/Events/UpdateFinished.php
Normal file
26
app/Events/UpdateFinished.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
class UpdateFinished
|
||||
{
|
||||
public $alias;
|
||||
|
||||
public $old;
|
||||
|
||||
public $new;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param $alias
|
||||
* @param $old
|
||||
* @param $new
|
||||
*/
|
||||
public function __construct($alias, $old, $new)
|
||||
{
|
||||
$this->alias = $alias;
|
||||
$this->old = $old;
|
||||
$this->new = $new;
|
||||
}
|
||||
}
|
@ -3,9 +3,10 @@
|
||||
namespace App\Http\Controllers\Install;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Module\Module as Model;
|
||||
use App\Events\UpdateFinished;
|
||||
use App\Utilities\Updater;
|
||||
use App\Utilities\Versions;
|
||||
use Artisan;
|
||||
use Module;
|
||||
|
||||
class Updates extends Controller
|
||||
@ -73,17 +74,50 @@ class Updates extends Controller
|
||||
/**
|
||||
* Update the core or modules.
|
||||
*
|
||||
* @param $alias
|
||||
* @param $version
|
||||
* @return Response
|
||||
*/
|
||||
public function update($alias, $version)
|
||||
{
|
||||
set_time_limit(600); // 10 minutes
|
||||
|
||||
$status = Updater::update($alias, $version);
|
||||
if (Updater::update($alias, $version)) {
|
||||
return redirect('install/updates/post/' . $alias . '/' . version('short') . '/' . $version);
|
||||
}
|
||||
|
||||
// Clear cache in order to check for updates again
|
||||
Updater::clear();
|
||||
flash(trans('updates.error'))->error();
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Final actions post update.
|
||||
*
|
||||
* @param $alias
|
||||
* @param $old
|
||||
* @param $new
|
||||
* @return Response
|
||||
*/
|
||||
public function post($alias, $old, $new)
|
||||
{
|
||||
// Check if the file mirror was successful
|
||||
if (($alias == 'core') && (version('short') != $new)) {
|
||||
flash(trans('updates.error'))->error();
|
||||
|
||||
return redirect('install/updates');
|
||||
}
|
||||
|
||||
// Clear cache after update
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
// Update database
|
||||
Artisan::call('migrate', ['--force' => true]);
|
||||
|
||||
event(new UpdateFinished($alias, $old, $new));
|
||||
|
||||
flash(trans('updates.success'))->success();
|
||||
|
||||
return redirect('install/updates');
|
||||
}
|
||||
}
|
||||
|
@ -7,20 +7,11 @@ use Illuminate\Auth\Events\Login as ILogin;
|
||||
|
||||
class Login
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param Logout $event
|
||||
* @param ILogin $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(ILogin $event)
|
||||
|
@ -7,20 +7,11 @@ use Illuminate\Auth\Events\Logout as ILogout;
|
||||
|
||||
class Logout
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param Logout $event
|
||||
* @param ILogout $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(ILogout $event)
|
||||
|
31
app/Listeners/Updates/Listener.php
Normal file
31
app/Listeners/Updates/Listener.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Updates;
|
||||
|
||||
class Listener
|
||||
{
|
||||
const ALIAS = '';
|
||||
|
||||
const VERSION = '';
|
||||
|
||||
/**
|
||||
* Check if should listen.
|
||||
*
|
||||
* @param $event
|
||||
* @return boolean
|
||||
*/
|
||||
protected function check($event)
|
||||
{
|
||||
// Apply only to the specified alias
|
||||
if ($event->alias != static::ALIAS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Do not apply to the same or newer versions
|
||||
if ($event->old >= static::VERSION) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
33
app/Listeners/Updates/Version104.php
Normal file
33
app/Listeners/Updates/Version104.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Updates;
|
||||
|
||||
//use App\Models\Auth\Permission;
|
||||
use App\Events\UpdateFinished;
|
||||
|
||||
class Version104 extends Listener
|
||||
{
|
||||
const ALIAS = 'core';
|
||||
|
||||
const VERSION = '1.0.4';
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(UpdateFinished $event)
|
||||
{
|
||||
// Check if should listen
|
||||
if (!$this->check($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*Permission::create([
|
||||
'name' => 'john-doe',
|
||||
'display_name' => 'John Doe',
|
||||
'description' => 'John Doe',
|
||||
]);*/
|
||||
}
|
||||
}
|
@ -13,8 +13,8 @@ class EventServiceProvider extends ServiceProvider
|
||||
* @var array
|
||||
*/
|
||||
protected $listen = [
|
||||
'App\Events\Event' => [
|
||||
'App\Listeners\EventListener',
|
||||
'App\Events\UpdateFinished' => [
|
||||
'App\Listeners\Updates\Version104',
|
||||
],
|
||||
'Illuminate\Auth\Events\Login' => [
|
||||
'App\Listeners\Auth\Login',
|
||||
|
@ -5,7 +5,6 @@ namespace App\Utilities;
|
||||
use App\Models\Module\Module as Model;
|
||||
use App\Models\Module\ModuleHistory as ModelHistory;
|
||||
use App\Traits\SiteApi;
|
||||
use Artisan;
|
||||
use Cache;
|
||||
use Date;
|
||||
use File;
|
||||
@ -28,20 +27,21 @@ class Updater
|
||||
// Update
|
||||
public static function update($alias, $version)
|
||||
{
|
||||
// Download file
|
||||
if (!$data = static::download($alias, $version)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create temp directory
|
||||
$path = 'temp-' . md5(mt_rand());
|
||||
$temp_path = storage_path('app/temp') . '/' . $path;
|
||||
|
||||
$file = $temp_path . '/upload.zip';
|
||||
|
||||
// Create tmp directory
|
||||
if (!File::isDirectory($temp_path)) {
|
||||
File::makeDirectory($temp_path);
|
||||
}
|
||||
|
||||
$file = $temp_path . '/upload.zip';
|
||||
|
||||
// Add content to the Zip file
|
||||
$uploaded = is_int(file_put_contents($file, $data)) ? true : false;
|
||||
|
||||
@ -58,37 +58,20 @@ class Updater
|
||||
|
||||
$zip->close();
|
||||
|
||||
// Remove Zip
|
||||
File::delete($file);
|
||||
|
||||
if ($alias == 'core') {
|
||||
// Move all files/folders from temp path then delete it
|
||||
File::copyDirectory($temp_path, base_path());
|
||||
File::deleteDirectory($temp_path);
|
||||
|
||||
// Clear cache after update
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
// Update database
|
||||
Artisan::call('migrate', ['--force' => true]);
|
||||
|
||||
// Check if the file mirror was successful
|
||||
/*if (version('short') != $version) {
|
||||
// Move all files/folders from temp path
|
||||
if (!File::copyDirectory($temp_path, base_path())) {
|
||||
return false;
|
||||
}*/
|
||||
}
|
||||
} else {
|
||||
// Get module instance
|
||||
$module = Module::get($alias);
|
||||
$model = Model::where('alias', $alias)->first();
|
||||
|
||||
// Move all files/folders from temp path then delete it
|
||||
File::copyDirectory($temp_path, module_path($module->get('name')));
|
||||
File::deleteDirectory($temp_path);
|
||||
|
||||
// Clear cache after update
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
// Update database
|
||||
Artisan::call('migrate', ['--force' => true]);
|
||||
// Move all files/folders from temp path
|
||||
if (!File::copyDirectory($temp_path, module_path($module->get('name')))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Add history
|
||||
ModelHistory::create([
|
||||
@ -100,6 +83,9 @@ class Updater
|
||||
]);
|
||||
}
|
||||
|
||||
// Delete temp directory
|
||||
File::deleteDirectory($temp_path);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -9,5 +9,7 @@ return [
|
||||
'check' => 'Check',
|
||||
'new_core' => 'An updated version of Akaunting is available.',
|
||||
'latest_core' => 'Congratulations! You have the latest version of Akaunting. Future security updates will be applied automatically.',
|
||||
'success' => 'Update process has been completed successfully.',
|
||||
'error' => 'Update process has failed, please, try again.',
|
||||
|
||||
];
|
||||
|
@ -138,8 +138,11 @@
|
||||
@permission('read-install-updates')
|
||||
<!-- Updates: style can be found in dropdown.less -->
|
||||
<li>
|
||||
<a href="{{ url('install/updates') }}" title="{{ $updates }} Updates Available">
|
||||
<a href="{{ url('install/updates') }}" data-toggle="tooltip" data-placement="bottom" title="{{ $updates }} Updates Available">
|
||||
<i class="fa fa-refresh"></i>
|
||||
@if ($updates)
|
||||
<span class="label label-danger">{{ $updates }}</span>
|
||||
@endif
|
||||
</a>
|
||||
</li>
|
||||
@endpermission
|
||||
|
@ -104,7 +104,8 @@ Route::group(['middleware' => ['auth', 'language', 'adminmenu', 'permission:read
|
||||
Route::group(['prefix' => 'install'], function () {
|
||||
Route::get('updates/changelog', 'Install\Updates@changelog');
|
||||
Route::get('updates/check', 'Install\Updates@check');
|
||||
Route::get('updates/update/{id}/{version}', 'Install\Updates@update');
|
||||
Route::get('updates/update/{alias}/{version}', 'Install\Updates@update');
|
||||
Route::get('updates/post/{alias}/{old}/{new}', 'Install\Updates@post');
|
||||
Route::resource('updates', 'Install\Updates');
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user