Skip to content

Commit

Permalink
update updater
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelfolaron committed Nov 16, 2024
1 parent be7a20c commit 332bfdb
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 951 deletions.
2 changes: 0 additions & 2 deletions .idea/leantime-oss.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/Command/BackupDbCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
'mysqldump --column-statistics=0 --user=%s --password=%s --host=%s %s --port=%s --result-file=%s 2>&1',
$config->dbUser,
$config->dbPassword,
$config->dbHost,
$config->dbHost == 'localhost' ? '127.0.0.1' : $config->dbHost,
$config->dbDatabase,
$config->dbPort,
$backupPath
Expand All @@ -74,7 +74,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
case 2:
case 1:
$io->error('There was an issue backing up the database');

$io->listing($output);
return Command::FAILURE;
}

Expand Down
77 changes: 63 additions & 14 deletions app/Command/UpdateLeantime.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

use Illuminate\Console\Command;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Support\Facades\Http;
use Leantime\Core\Configuration\AppSettings;
use Leantime\Domain\Plugins\Services\Plugins;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -44,9 +46,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$currentVersion = $appSettings->appVersion;
$io->text('Starting the updater');
$io->text('Your current version is: v'.$currentVersion);

// Get Latest Version
//Check Versions + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
$io->section('Version Check');
$io->text('Your current version is: v'.$currentVersion);
$url = 'https://github.com/leantime/leantime/releases/latest';
$io->text('Checking latest version on Github...');

Expand All @@ -66,13 +69,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$jsonResponse = json_decode($result, true);
$latestVersion = $jsonResponse['tag_name'] ?? null;

$io->text('The current Leantime version is: '.$latestVersion);
$io->text('The latest Leantime version is: '.$latestVersion);

// Build download URL
if ('v'.$currentVersion == $latestVersion) {
$io->text('You are on the most up to date version');
if (version_compare($currentVersion, ltrim($latestVersion, 'v'), '>=')) {
$io->success('You are on the most up to date version');

return self::SUCCESS;
}

//Backup DB + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
$io->section('Database Backup');
$skipBackup = $input->getOption('skipDbBackup');

if ($skipBackup === false) {
Expand All @@ -84,26 +91,68 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->getApplication()->doRun($backUp, $output);
}

// Build download URL
//Download and extract + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
$io->section('Download & Extract');

$io->text('Downloading latest version...');
$downloadUrl = 'https://github.com/leantime/leantime/releases/download/'.$latestVersion.'/Leantime-'.$latestVersion.'.zip';
$file = file_get_contents($downloadUrl);

$zipFile = APP_ROOT.'/cache/latest.zip';
file_put_contents($zipFile, $file);
$zipFile = storage_path('/framework/cache/latest.zip');
Http::sink($zipFile)->get($downloadUrl);

$io->text('Extracting Archive...');

$zip = new \ZipArchive;
$zip->open($zipFile);
$zip->extractTo(APP_ROOT.'/cache/');
$zip->extractTo(storage_path('/framework/cache'));
$zip->close();

exec('cp -r '.APP_ROOT.'/cache/leantime/* '.APP_ROOT.'/');
//Disable Plugins + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
//If we got here everything is ready to go and we just need to move the files.
//Let's disable plugins
$io->section('Disabling Plugins');

/** @var Plugins $plugins */
$plugins = app()->make(Plugins::class);
$enabledPlugins = $plugins->getAllPlugins(enabledOnly: true);
foreach ($enabledPlugins as $plugin) {
if ($plugin->type != 'system' && isset($plugin->id)) {
$plugins->disablePlugin($plugin->id);
$io->text($plugin->name.': Disabled');
}
}

$io->success('Plugins disabled successfully');

//Apllying Update + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
$io->section('Applying Update');
exec('cp -r '.storage_path('/framework/cache/leantime').'/* '.APP_ROOT.'/');
$io->success('Files were updated');

//Clear Cache + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
$io->section('Clearing Cache');

exec('rm -rf "'.APP_ROOT.'/bootstrap/cache/*.php"');
exec('rm -rf "'.APP_ROOT.'/storage/framework/cache/leantime"');
exec('rm -rf "'.APP_ROOT.'/storage/framework/cache/latest.zip"');
exec('rm -rf "'.APP_ROOT.'/storage/framework/composerPaths.php"');
exec('rm -rf "'.APP_ROOT.'/storage/framework/viewPaths.php"');
exec('rm -rf "'.APP_ROOT.'/storage/framework/cache/*.php"');
exec('rm -rf "'.APP_ROOT.'/storage/framework/views/*.php"');

$io->success('Clearing Cache Complete');

//Enable Plugins + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
$io->section('Re-enabling Plugins');
foreach ($enabledPlugins as $plugin) {
if ($plugin->type != 'system' && isset($plugin->id)) {
$plugins->enablePlugin($plugin->id);
$io->text($plugin->name.': Enabled');
}
}

$io->text('Clean Up');
rmdir(APP_ROOT.'/cache/leantime');
$io->success('Plugins were enabled');

$io->section('Summary');
$io->success('Update applied Successfully');

return Command::SUCCESS;
Expand Down
2 changes: 1 addition & 1 deletion app/Core/Configuration/laravelConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
\Leantime\Core\Providers\AppServiceProvider::class,


\Leantime\Core\Providers\Cache::class, //\Illuminate\Cache\CacheServiceProvider::class,
\Leantime\Core\Providers\Redis::class,

Expand Down Expand Up @@ -48,7 +49,6 @@
\Leantime\Core\Providers\Frontcontroller::class,
\Leantime\Core\Providers\Views::class,
\Leantime\Core\Providers\TemplateServiceProvider::class,

],
'name' => env('LEAN_SITENAME', 'Leantime'),
'locale' => env('LEAN_LANGUAGE', 'en-US'),
Expand Down
2 changes: 1 addition & 1 deletion app/Core/Providers/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public function register()
$this->app->singleton(\Leantime\Core\Language::class, function () {
return new \Leantime\Core\Language;
});
$this->app->alias(\Leantime\Core\Language::class, 'translator');
//$this->app->alias(\Leantime\Core\Language::class, 'translator');
}
}
Loading

0 comments on commit 332bfdb

Please sign in to comment.