Skip to content

Commit

Permalink
Merge pull request #219 from TYPO3/hotfix/issue-218-surf-phar-read-only
Browse files Browse the repository at this point in the history
[HOTFIX] Move instantiation of Updater to execute method
  • Loading branch information
sabbelasichon authored Oct 31, 2018
2 parents 09e3a06 + 46a121d commit 48121f8
Showing 1 changed file with 14 additions and 29 deletions.
43 changes: 14 additions & 29 deletions src/Command/SelfUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,6 @@
class SelfUpdateCommand extends Command
{

/**
* @var Updater
*/
private $updater;

/**
* SelfUpdateCommand constructor.
*
* @param null $name
*/
public function __construct($name = null)
{
parent::__construct($name);

$this->updater = new Updater(null, false, Updater::STRATEGY_GITHUB);
/** @var GithubStrategy $strategy */
$strategy = $this->updater->getStrategy();
$strategy->setPackageName('TYPO3/Surf');
$strategy->setPharName('surf.phar');
}

/**
* @return bool
*/
Expand Down Expand Up @@ -85,6 +64,12 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$updater = new Updater(null, false, Updater::STRATEGY_GITHUB);
/** @var GithubStrategy $strategy */
$strategy = $updater->getStrategy();
$strategy->setPackageName('TYPO3/Surf');
$strategy->setPharName('surf.phar');

$io = new SymfonyStyle($input, $output);

$stability = $input->getOption('stability');
Expand All @@ -93,36 +78,36 @@ protected function execute(InputInterface $input, OutputInterface $output)
$stability = GithubStrategy::UNSTABLE;
}
/** @var GithubStrategy $strategy */
$strategy = $this->updater->getStrategy();
$strategy = $updater->getStrategy();
$strategy->setCurrentLocalVersion($this->getApplication()->getVersion());
$strategy->setStability($stability);

if ($input->getOption('check')) {
$result = $this->updater->hasUpdate();
$result = $updater->hasUpdate();
if ($result) {
$output->writeln(sprintf(
'The %s build available remotely is: %s',
$strategy->getStability() === GithubStrategy::ANY ? 'latest' : 'current ' . $strategy->getStability(),
$this->updater->getNewVersion()
$updater->getNewVersion()
));
} elseif (false === $this->updater->getNewVersion()) {
} elseif (false === $updater->getNewVersion()) {
$output->writeln('There are no new builds available.');
} else {
$output->writeln(sprintf('You have the current %s build installed.', $strategy->getStability()));
}
} elseif ($input->getOption('rollback')) {
$result = $this->updater->rollback();
$result = $updater->rollback();
$result ? $output->writeln('Success!') : $output->writeln('Failure!');
} else {
$result = $this->updater->update();
$result = $updater->update();

if ($result) {
$io->success(
sprintf(
'Your %s has been updated from "%s" to "%s".',
$this->getLocalPharName(),
$this->updater->getOldVersion(),
$this->updater->getNewVersion()
$updater->getOldVersion(),
$updater->getNewVersion()
)
);
} else {
Expand Down

0 comments on commit 48121f8

Please sign in to comment.