mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-07 21:44:51 +00:00
* Convert string references to `::class` PHP 5.5.9 adds the new static `class` property which provides the fully qualified class name. This is preferred over using strings for class names since the `class` property references are checked by PHP. * Use Faker methods Accessing Faker properties was deprecated in Faker 1.14. * Convert route options to fluent methods Laravel 8 adopts the tuple syntax for controller actions. Since the old options array is incompatible with this syntax, Shift converted them to use modern, fluent methods. * Adopt class based routes * Remove default `app` files * Shift core files * Streamline config files * Set new `ENV` variables * Default new `bootstrap/app.php` * Re-register HTTP middleware * Consolidate service providers * Re-register service providers * Re-register routes * Re-register scheduled commands * Bump Composer dependencies * Use `<env>` tags for configuration `<env>` tags have a lower precedence than system environment variables making it easier to overwrite PHPUnit configuration values in additional environments, such a CI. Review this blog post for more details on configuration precedence when testing Laravel: https://jasonmccreary.me/articles/laravel-testing-configuration-precedence/ * Adopt anonymous migrations * Rename `password_resets` table * Convert `$casts` property to method * Adopt Laravel type hints * Mark base controller as `abstract` * Remove `CreatesApplication` testing trait * Shift cleanup * Fix shift first issues * Updating Rules for laravel 11, sanctum config and pint * Fix Carbon issue on dashboard * Temporary fix for tests while migration is issue fixed on laravel side * Carbon needs numerical values, not strings * Minimum php version * Fix domain installation step not fetching the correct company_id * Fix Role Policy wasn't properly registered ---------
242 lines
5.3 KiB
PHP
242 lines
5.3 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\Setting;
|
|
use App\Space\Updater;
|
|
use Illuminate\Console\Command;
|
|
|
|
// Implementation taken from Akaunting - https://github.com/akaunting/akaunting
|
|
class UpdateCommand extends Command
|
|
{
|
|
public $installed;
|
|
|
|
public $version;
|
|
|
|
public $response;
|
|
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'core:update';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Automatically update your InvoiceShelf Core App';
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*/
|
|
public function handle(): void
|
|
{
|
|
set_time_limit(3600); // 1 hour
|
|
|
|
$this->installed = $this->getInstalledVersion();
|
|
$this->response = $this->getLatestVersionResponse();
|
|
$this->version = ($this->response) ? $this->response->version : false;
|
|
|
|
if ($this->response == 'extension_required') {
|
|
$this->info('Sorry! Your system does not meet the minimum requirements for this update.');
|
|
$this->info('Please retry after installing the required version/extensions.');
|
|
|
|
return;
|
|
}
|
|
|
|
if (! $this->version) {
|
|
$this->info('No Update Available! You are already on the latest version.');
|
|
|
|
return;
|
|
}
|
|
|
|
if (! $this->confirm("Do you wish to update to {$this->version}?")) {
|
|
return;
|
|
}
|
|
|
|
if (! $path = $this->download()) {
|
|
return;
|
|
}
|
|
|
|
if (! $path = $this->unzip($path)) {
|
|
return;
|
|
}
|
|
|
|
if (! $this->copyFiles($path)) {
|
|
return;
|
|
}
|
|
|
|
if (isset($this->response->deleted_files) && ! empty($this->response->deleted_files)) {
|
|
if (! $this->deleteFiles($this->response->deleted_files)) {
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (! $this->migrateUpdate()) {
|
|
return;
|
|
}
|
|
|
|
if (! $this->finish()) {
|
|
return;
|
|
}
|
|
|
|
$this->info('Successfully updated to '.$this->version);
|
|
}
|
|
|
|
public function getInstalledVersion()
|
|
{
|
|
return Setting::getSetting('version');
|
|
}
|
|
|
|
public function getLatestVersionResponse()
|
|
{
|
|
$this->info('Your currently installed version is '.$this->installed);
|
|
$this->line('');
|
|
$this->info('Checking for update...');
|
|
|
|
try {
|
|
$response = Updater::checkForUpdate($this->installed);
|
|
|
|
if ($response->success) {
|
|
$extensions = $response->version->extensions;
|
|
|
|
$is_required = false;
|
|
|
|
foreach ($extensions as $key => $extension) {
|
|
if (! $extension) {
|
|
$is_required = true;
|
|
$this->info('❌ '.$key);
|
|
}
|
|
|
|
$this->info('✅ '.$key);
|
|
}
|
|
|
|
if ($is_required) {
|
|
return 'extension_required';
|
|
}
|
|
|
|
return $response->version;
|
|
}
|
|
|
|
return false;
|
|
} catch (\Exception $e) {
|
|
$this->error($e->getMessage());
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function download()
|
|
{
|
|
$this->info('Downloading update...');
|
|
|
|
try {
|
|
$path = Updater::download($this->version, 1);
|
|
if (! is_string($path)) {
|
|
$this->error('Download exception');
|
|
|
|
return false;
|
|
}
|
|
} catch (\Exception $e) {
|
|
$this->error($e->getMessage());
|
|
|
|
return false;
|
|
}
|
|
|
|
return $path;
|
|
}
|
|
|
|
public function unzip($path)
|
|
{
|
|
$this->info('Unzipping update package...');
|
|
|
|
try {
|
|
$path = Updater::unzip($path);
|
|
if (! is_string($path)) {
|
|
$this->error('Unzipping exception');
|
|
|
|
return false;
|
|
}
|
|
} catch (\Exception $e) {
|
|
$this->error($e->getMessage());
|
|
|
|
return false;
|
|
}
|
|
|
|
return $path;
|
|
}
|
|
|
|
public function copyFiles($path)
|
|
{
|
|
$this->info('Copying update files...');
|
|
|
|
try {
|
|
Updater::copyFiles($path);
|
|
} catch (\Exception $e) {
|
|
$this->error($e->getMessage());
|
|
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public function deleteFiles($files)
|
|
{
|
|
$this->info('Deleting unused old files...');
|
|
|
|
try {
|
|
Updater::deleteFiles($files);
|
|
} catch (\Exception $e) {
|
|
$this->error($e->getMessage());
|
|
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public function migrateUpdate()
|
|
{
|
|
$this->info('Running Migrations...');
|
|
|
|
try {
|
|
Updater::migrateUpdate();
|
|
} catch (\Exception $e) {
|
|
$this->error($e->getMessage());
|
|
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public function finish()
|
|
{
|
|
$this->info('Finishing update...');
|
|
|
|
try {
|
|
Updater::finishUpdate($this->installed, $this->version);
|
|
} catch (\Exception $e) {
|
|
$this->error($e->getMessage());
|
|
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|