Merge pull request #1274 from denisdulici/master
Added update::all command
This commit is contained in:
commit
dd93e59e7e
@ -25,14 +25,6 @@ class BillReminder extends Command
|
||||
*/
|
||||
protected $description = 'Send reminders for bills';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
|
@ -22,14 +22,6 @@ class FinishUpdate extends Command
|
||||
*/
|
||||
protected $description = 'Finish the update process through CLI';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
|
@ -25,14 +25,6 @@ class InvoiceReminder extends Command
|
||||
*/
|
||||
protected $description = 'Send reminders for invoices';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
|
@ -38,14 +38,6 @@ class RecurringCheck extends Command
|
||||
*/
|
||||
protected $today;
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
|
@ -21,16 +21,6 @@ class SampleData extends Command
|
||||
*/
|
||||
protected $description = 'Seed for sample data';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
|
@ -32,14 +32,6 @@ class Update extends Command
|
||||
*/
|
||||
protected $description = 'Allows to update Akaunting and modules directly through CLI';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
@ -51,7 +43,11 @@ class Update extends Command
|
||||
|
||||
$this->alias = $this->argument('alias');
|
||||
|
||||
$this->new = $this->getNewVersion();
|
||||
if (false === $this->new = $this->getNewVersion()) {
|
||||
$this->error('Not able to get the latest version of ' . $this->alias . '!');
|
||||
|
||||
return self::CMD_ERROR;
|
||||
}
|
||||
|
||||
$this->old = $this->getOldVersion();
|
||||
|
||||
@ -79,15 +75,7 @@ class Update extends Command
|
||||
|
||||
public function getNewVersion()
|
||||
{
|
||||
$new = $this->argument('new');
|
||||
|
||||
if ($new == 'latest') {
|
||||
$modules = ($this->alias == 'core') ? [] : [$this->alias];
|
||||
|
||||
$new = Versions::latest($modules)[$this->alias]->data->latest;
|
||||
}
|
||||
|
||||
return $new;
|
||||
return ($this->argument('new') == 'latest') ? Versions::latest($this->alias) : $this->argument('new');
|
||||
}
|
||||
|
||||
public function getOldVersion()
|
||||
|
74
app/Console/Commands/UpdateAll.php
Normal file
74
app/Console/Commands/UpdateAll.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Utilities\Console;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class UpdateAll extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'update:all {company=1}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Allows to update Akaunting and all modules at once';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
set_time_limit(0); // unlimited
|
||||
|
||||
$this->info('Starting update...');
|
||||
|
||||
// Update core
|
||||
if ($this->runUpdate('core') !== true) {
|
||||
$this->error('Not able to update core!');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Update modules
|
||||
$modules = module()->all();
|
||||
|
||||
foreach ($modules as $module) {
|
||||
$alias = $module->get('alias');
|
||||
|
||||
if ($this->runUpdate($alias) !== true) {
|
||||
$this->error('Not able to update ' . $alias . '!');
|
||||
}
|
||||
}
|
||||
|
||||
$this->info('Update finished.');
|
||||
}
|
||||
|
||||
protected function runUpdate($alias)
|
||||
{
|
||||
$this->info('Updating ' . $alias . '...');
|
||||
|
||||
$company_id = $this->argument('company');
|
||||
|
||||
$command = "php artisan update {$alias} {$company_id}";
|
||||
|
||||
if (true !== $result = Console::run($command, true)) {
|
||||
$message = !empty($result) ? $result : trans('modules.errors.finish', ['module' => $alias]);
|
||||
|
||||
$this->error($message);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -20,16 +20,6 @@ class UserSeed extends Command
|
||||
*/
|
||||
protected $description = 'Seed for specific user';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
|
@ -158,7 +158,7 @@ class Updater
|
||||
|
||||
$modules = module()->all();
|
||||
|
||||
$versions = Versions::latest($modules);
|
||||
$versions = Versions::all($modules);
|
||||
|
||||
foreach ($versions as $alias => $latest_version) {
|
||||
$installed_version = ($alias == 'core') ? version('short') : module($alias)->get('version');
|
||||
|
@ -2,9 +2,11 @@
|
||||
|
||||
namespace App\Utilities;
|
||||
|
||||
use Akaunting\Module\Module;
|
||||
use App\Traits\SiteApi;
|
||||
use Cache;
|
||||
use Date;
|
||||
use Illuminate\Support\Arr;
|
||||
use Parsedown;
|
||||
|
||||
class Versions
|
||||
@ -52,7 +54,18 @@ class Versions
|
||||
return $output;
|
||||
}
|
||||
|
||||
public static function latest($modules = [])
|
||||
public static function latest($alias)
|
||||
{
|
||||
$versions = static::all($alias);
|
||||
|
||||
if (empty($versions[$alias]) || empty($versions[$alias]->data)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $versions[$alias]->data->latest;
|
||||
}
|
||||
|
||||
public static function all($modules = null)
|
||||
{
|
||||
// Get data from cache
|
||||
$versions = Cache::get('versions');
|
||||
@ -70,8 +83,18 @@ class Versions
|
||||
|
||||
$versions['core'] = static::getLatestVersion($url, $info['akaunting']);
|
||||
|
||||
$modules = Arr::wrap($modules);
|
||||
|
||||
// Then modules
|
||||
foreach ($modules as $module) {
|
||||
if (is_string($module)) {
|
||||
$module = module($module);
|
||||
}
|
||||
|
||||
if (!$module instanceof Module) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$alias = $module->get('alias');
|
||||
$version = $module->get('version');
|
||||
|
||||
@ -85,7 +108,7 @@ class Versions
|
||||
return $versions;
|
||||
}
|
||||
|
||||
public static function getLatestVersion($url, $latest)
|
||||
protected static function getLatestVersion($url, $latest)
|
||||
{
|
||||
if (!$data = static::getResponseData('GET', $url, ['timeout' => 10])) {
|
||||
return $latest;
|
||||
|
Loading…
x
Reference in New Issue
Block a user