-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added self update/rollback/check commands to manage application easier
- Loading branch information
1 parent
e1d8172
commit 55c3766
Showing
8 changed files
with
349 additions
and
9 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,29 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Kimai 2 - Remote Console. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace KimaiConsole\Command; | ||
|
||
use Humbug\SelfUpdate\Updater; | ||
use KimaiConsole\Constants; | ||
|
||
abstract class AbstractSelfCommand extends BaseCommand | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getUpdater(): Updater | ||
{ | ||
$updater = new Updater(null, false, Updater::STRATEGY_GITHUB); | ||
$updater->getStrategy()->setPackageName('kevinpapst/kimai2-console'); | ||
$updater->getStrategy()->setPharName('kimai.phar'); | ||
$updater->getStrategy()->setCurrentLocalVersion(Constants::VERSION); | ||
|
||
return $updater; | ||
} | ||
} |
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,60 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Kimai 2 - Remote Console. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace KimaiConsole\Command; | ||
|
||
use KimaiConsole\Constants; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
class SelfCheckCommand extends AbstractSelfCommand | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('self:check') | ||
->setDescription('Checks for available updates') | ||
->setHelp('This command checks if there is a new version available') | ||
; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$io = new SymfonyStyle($input, $output); | ||
|
||
$updater = $this->getUpdater(); | ||
|
||
try { | ||
$result = $updater->hasUpdate(); | ||
|
||
if ($result) { | ||
// this is also triggered, if the current local version is higher then the remote version | ||
// it does not trigger a version_compare, but only compare if the two versions are equal | ||
$io->success(sprintf('There is a new release available in version: %s', $updater->getNewVersion())); | ||
} elseif (false === $updater->getNewVersion()) { | ||
$io->success('There are no stable builds available.'); | ||
} else { | ||
$io->success(sprintf('You are running the latest version: %s', Constants::VERSION)); | ||
} | ||
} catch (\Exception $ex) { | ||
$io->error('Failed to check for updates: ' . $ex->getMessage()); | ||
|
||
return 1; | ||
} | ||
|
||
return 0; | ||
} | ||
} |
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,54 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Kimai 2 - Remote Console. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace KimaiConsole\Command; | ||
|
||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
class SelfRollbackCommand extends AbstractSelfCommand | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('self:rollback') | ||
->setDescription('Rollback to the latest available version') | ||
->setHelp('This command lets you rollback an updated application to the previous version') | ||
; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$io = new SymfonyStyle($input, $output); | ||
|
||
$updater = $this->getUpdater(); | ||
|
||
try { | ||
$result = $updater->rollback(); | ||
if ($result) { | ||
$io->success(sprintf('Rollback from version %s to %s', $updater->getOldVersion(), $updater->getNewVersion())); | ||
} else { | ||
$io->success('Cannot rollback'); | ||
} | ||
} catch (\Exception $ex) { | ||
$io->error('Failed to rollback! ' . $ex->getMessage()); | ||
|
||
return 1; | ||
} | ||
|
||
return 0; | ||
} | ||
} |
Oops, something went wrong.