Skip to content

Commit

Permalink
Detection is not responsible for extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
VicDeo committed Dec 15, 2015
1 parent 64074a5 commit 8e54fac
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 29 deletions.
7 changes: 6 additions & 1 deletion app/config/container.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use Owncloud\Updater\Utils\FilesystemHelper;
use Owncloud\Updater\Utils\Locator;
use Owncloud\Updater\Utils\OccRunner;
use Owncloud\Updater\Utils\Registry;
use Owncloud\Updater\Command\BackupDataCommand;
use Owncloud\Updater\Command\BackupDbCommand;
use Owncloud\Updater\Command\CheckpointCommand;
Expand Down Expand Up @@ -73,6 +74,10 @@
return new OccRunner($c['utils.locator']);
};

$c['utils.registry'] = function($c){
return new Registry();
};

$c['utils.appmanager'] = function($c){
return new AppManager($c['utils.occrunner']);
};
Expand Down Expand Up @@ -187,7 +192,7 @@
};

$c['application'] = function($c){
$application = new Application('ownCloud updater', '0.1');
$application = new Application('ownCloud updater', '1.0');
$application->setContainer($c);
$application->addCommands($c['commands']);
return $application;
Expand Down
30 changes: 8 additions & 22 deletions src/Command/DetectCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
use Owncloud\Updater\Utils\Fetcher;
use Owncloud\Updater\Utils\Feed;
use Owncloud\Updater\Utils\ConfigReader;
use Owncloud\Updater\Utils\ZipExtractor;

class DetectCommand extends Command {

Expand Down Expand Up @@ -71,6 +70,9 @@ protected function configure(){
}

protected function execute(InputInterface $input, OutputInterface $output){
$registry = $this->container['utils.registry'];
$registry->set('feed', false);

$locator = $this->container['utils.locator'];
$fsHelper = $this->container['utils.filesystemhelper'];
try{
Expand All @@ -96,7 +98,7 @@ protected function execute(InputInterface $input, OutputInterface $output){

if ($action === 'abort'){
$output->writeln('Abort has been choosed. Exiting.');
return 0;
return 128;
}

$path = $this->fetcher->getBaseDownloadPath($feed);
Expand All @@ -119,36 +121,20 @@ protected function execute(InputInterface $input, OutputInterface $output){
}
if ($action === 'download'){
$output->writeln('Downloading has been completed. Exiting.');
return 0;
return 64;
}
if ($fileExists){
$fullExtractionPath = $locator->getExtractionBaseDir() . '/' . $feed->getVersion();
if (!file_exists($fullExtractionPath)){
try {
$fsHelper->mkdir($fullExtractionPath, true);
} catch (\Exception $ex) {
$output->writeln('Unable create directory ' . $fullExtractionPath);
}
}
$output->writeln('Extracting source into ' . $fullExtractionPath);

$zipExtractor = new ZipExtractor($path, $fullExtractionPath);
try {
$zipExtractor->extract();
} catch (\Exception $ex) {
$output->writeln('Extraction has been failed');
$fsHelper->removeIfExists($locator->getExtractionBaseDir());
}
$registry->set('feed', $feed);
}
} else {
$output->writeln('No updates found online.');
if ($input->getOption('exit-if-none')){
exit(4);
return 4;
}
}
} catch (\Exception $e){
$this->getApplication()->getLogger()->error($e->getMessage());
exit(2);
return 2;
}
}

Expand Down
42 changes: 36 additions & 6 deletions src/Command/ExecuteCoreUpgradeScriptsCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @author Victor Dubiniuk <dubiniuk@owncloud.com>
*
Expand Down Expand Up @@ -26,6 +27,7 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Owncloud\Updater\Utils\OccRunner;
use Owncloud\Updater\Utils\ZipExtractor;

class ExecuteCoreUpgradeScriptsCommand extends Command {

Expand All @@ -42,17 +44,45 @@ public function __construct($occRunner){
protected function configure(){
$this
->setName('upgrade:executeCoreUpgradeScripts')
->setDescription('execute core upgrade scripts
[danger, might take long]')
;
->setDescription('execute core upgrade scripts [danger, might take long]');
}

protected function execute(InputInterface $input, OutputInterface $output){
$locator = $this->container['utils.locator'];
$fsHelper = $this->container['utils.filesystemhelper'];

$plain = $this->occRunner->run('upgrade');
$output->writeln($plain);
$registry = $this->container['utils.registry'];
$fetcher = $this->container['utils.fetcher'];

$feed = $registry->get('feed');

if ($feed){
$path = $fetcher->getBaseDownloadPath($feed);
$fullExtractionPath = $locator->getExtractionBaseDir() . '/' . $feed->getVersion();

if (!file_exists($fullExtractionPath)){
try{
$fsHelper->mkdir($fullExtractionPath, true);
} catch (\Exception $ex){

$output->writeln('Unable create directory ' . $fullExtractionPath);
}
}
$output->writeln('Extracting source into ' . $fullExtractionPath);

$zipExtractor = new ZipExtractor($path, $fullExtractionPath);
try{
$zipExtractor->extract();
} catch (\Exception $e){
$output->writeln('Extraction has been failed');
$fsHelper->removeIfExists($locator->getExtractionBaseDir());
throw $e;
}

$plain = $this->occRunner->run('upgrade');
$output->writeln($plain);

}

}

}
40 changes: 40 additions & 0 deletions src/Utils/Registry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/**
* @author Victor Dubiniuk <dubiniuk@owncloud.com>
*
* @copyright Copyright (c) 2015, ownCloud, Inc.
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

namespace Owncloud\Updater\Utils;

class Registry {

protected $objects = array();

function set($name, $object){
$this->objects[$name] = $object;
}

function get($name){
if (isset($this->objects[$name])){
return $this->objects[$name];
}
return null;
}

}

0 comments on commit 8e54fac

Please sign in to comment.