-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
066ac38
commit e2f73ec
Showing
13 changed files
with
429 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Events\Install\UpdateFinished; | ||
use Illuminate\Console\Command; | ||
|
||
class FinishUpdate extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'update:finish {alias} {company_id} {new} {old}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Finish the update process through CLI'; | ||
|
||
/** | ||
* Create a new command instance. | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle() | ||
{ | ||
set_time_limit(900); // 15 minutes | ||
|
||
$this->info('Finishing update...'); | ||
|
||
session(['company_id' => $this->argument('company_id')]); | ||
|
||
$this->call('cache:clear'); | ||
|
||
event(new UpdateFinished($this->argument('alias'), $this->argument('new'), $this->argument('old'))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Utilities\Updater; | ||
use App\Utilities\Versions; | ||
use Illuminate\Console\Command; | ||
|
||
class Update extends Command | ||
{ | ||
const CMD_SUCCESS = 0; | ||
|
||
const CMD_ERROR = 1; | ||
|
||
public $alias; | ||
|
||
public $new; | ||
|
||
public $old; | ||
|
||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'update {alias} {company_id} {new=latest}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Allows to update Akaunting directly through CLI'; | ||
|
||
/** | ||
* Create a new command instance. | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle() | ||
{ | ||
set_time_limit(900); // 15 minutes | ||
|
||
$this->alias = $this->argument('alias'); | ||
|
||
$this->new = $this->getNewVersion(); | ||
|
||
$this->old = $this->getOldVersion(); | ||
|
||
session(['company_id' => $this->argument('company_id')]); | ||
|
||
if (!$path = $this->download()) { | ||
return self::CMD_ERROR; | ||
} | ||
|
||
if (!$this->unzip($path)) { | ||
return self::CMD_ERROR; | ||
} | ||
|
||
if (!$this->copyFiles($path)) { | ||
return self::CMD_ERROR; | ||
} | ||
|
||
if (!$this->finish()) { | ||
return self::CMD_ERROR; | ||
} | ||
|
||
return self::CMD_SUCCESS; | ||
} | ||
|
||
public function getNewVersion() | ||
{ | ||
$new = $this->argument('new'); | ||
|
||
if ($new == 'latest') { | ||
$modules = ($this->alias == 'core') ? [] : [$this->alias]; | ||
|
||
$new = Versions::latest($modules)[$this->alias]; | ||
} | ||
|
||
return $new; | ||
} | ||
|
||
public function getOldVersion() | ||
{ | ||
return ($this->alias == 'core') | ||
? version('short') | ||
: module($this->alias)->get('version'); | ||
} | ||
|
||
public function download() | ||
{ | ||
$this->info('Downloading update...'); | ||
|
||
try { | ||
$path = Updater::download($this->alias, $this->new, $this->old); | ||
} catch (\Exception $e) { | ||
$this->error($e->getMessage()); | ||
|
||
return false; | ||
} | ||
|
||
return $path; | ||
} | ||
|
||
public function unzip($path) | ||
{ | ||
$this->info('Unzipping update...'); | ||
|
||
try { | ||
Updater::unzip($path, $this->alias, $this->new, $this->old); | ||
} catch (\Exception $e) { | ||
$this->error($e->getMessage()); | ||
|
||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public function copyFiles($path) | ||
{ | ||
$this->info('Copying update files...'); | ||
|
||
try { | ||
Updater::copyFiles($path, $this->alias, $this->new, $this->old); | ||
} catch (\Exception $e) { | ||
$this->error($e->getMessage()); | ||
|
||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public function finish() | ||
{ | ||
$this->info('Finishing update...'); | ||
|
||
try { | ||
Updater::finish($this->alias, $this->new, $this->old); | ||
} catch (\Exception $e) { | ||
$this->error($e->getMessage()); | ||
|
||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.