Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switching to web-executor #355

Merged
merged 3 commits into from
Jul 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
// symlinks are not resolved by PHP properly
// getcwd always reports source and not target
if(getcwd()){
define('CURRENT_DIR', getcwd());
define('CURRENT_DIR', trim(getcwd()));
} elseif (isset($_SERVER['PWD'])){
define('CURRENT_DIR', $_SERVER['PWD']);
} elseif (isset($_SERVER['SCRIPT_FILENAME'])){
Expand Down
17 changes: 7 additions & 10 deletions app/config/container.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
use Owncloud\Updater\Command\PreUpgradeRepairCommand;
use Owncloud\Updater\Command\RestartWebServerCommand;
use Owncloud\Updater\Command\UpdateConfigCommand;
use Owncloud\Updater\Command\UpgradeShippedAppsCommand;
use Owncloud\Updater\Command\StartCommand;

$c = new Container();
Expand All @@ -67,7 +66,9 @@
};

$c['utils.occrunner'] = function($c){
return new OccRunner($c['utils.locator']);
$disabled = explode(',', ini_get('disable_functions'));
$isProcOpenEnabled = function_exists('proc_open') && !in_array('proc_open', $disabled);
return new OccRunner($c['utils.locator'], $isProcOpenEnabled && IS_CLI);
};

$c['utils.registry'] = function($c){
Expand Down Expand Up @@ -123,7 +124,7 @@
$c['command.info'] = function($c){
return new InfoCommand();
};
$c['command.maintenaceMode'] = function($c){
$c['command.maintenanceMode'] = function($c){
return new MaintenanceModeCommand($c['utils.occrunner']);
};
$c['command.postUpgradeCleanup'] = function($c){
Expand All @@ -138,12 +139,9 @@
$c['command.restartWebServer'] = function($c){
return new RestartWebServerCommand();
};
$c['command.updateCoreCofig'] = function($c){
$c['command.updateCoreConfig'] = function($c){
return new UpdateConfigCommand();
};
$c['command.upgradeShippedApps'] = function($c){
return new UpgradeShippedAppsCommand($c['utils.occrunner']);
};
$c['command.start'] = function($c){
return new StartCommand();
};
Expand All @@ -161,13 +159,12 @@
$c['command.enableNotShippedApps'],
$c['command.executeCoreUpgradeScripts'],
$c['command.info'],
$c['command.maintenaceMode'],
$c['command.maintenanceMode'],
$c['command.postUpgradeCleanup'],
$c['command.postUpgradeRepair'],
$c['command.preUpgradeRepair'],
$c['command.restartWebServer'],
$c['command.updateCoreCofig'],
$c['command.upgradeShippedApps'],
$c['command.updateCoreConfig'],
$c['command.start'],
];
};
Expand Down
3 changes: 3 additions & 0 deletions application.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*
*/

define('IS_CLI', true);

$oldWorkingDir = getcwd();
if ($oldWorkingDir === false) {
echo "This script can be run from the ownCloud root directory only." . PHP_EOL;
Expand All @@ -29,6 +31,7 @@
echo "Can't change to ownCloud root directory." . PHP_EOL;
exit(1);
}

require __DIR__ . '/app/bootstrap.php';
/** @var \Owncloud\Updater\Console\Application $application */
$application = $container['application'];
Expand Down
1 change: 1 addition & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

use Owncloud\Updater\Controller\IndexController;

define ('IS_CLI', false);
require __DIR__ . '/app/bootstrap.php';

$controller = new IndexController($container);
Expand Down
7 changes: 0 additions & 7 deletions pub/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,6 @@ $(function () {
: $.Deferred()
;
})
.then(function (response) {
handleResponse(response, function () {}, '#step-coreupgrade');
return response.error_code === 0
? $.post($('#meta-information').data('endpoint'), {command: 'upgrade:upgradeShippedApps'})
: $.Deferred()
;
})
.then(function (response) {
if (response.error_code === 0){
accordion.setCurrent('#step-appupgrade');
Expand Down
18 changes: 14 additions & 4 deletions src/Command/ExecuteCoreUpgradeScriptsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,22 @@ protected function execute(InputInterface $input, OutputInterface $output){
}

$fsHelper->copyr($tmpDir . '/config/config.php', $oldSourcesDir . '/config/config.php');

//Remove old apps
$appDirectories = $fsHelper->scandirFiltered($oldSourcesDir . '/apps');
foreach ($appDirectories as $appDirectory){
$fsHelper->rmdirr($oldSourcesDir . '/apps/' . $appDirectory);
}

//Put new shipped apps
$newAppsDir = $fullExtractionPath . '/owncloud/apps';
$newAppsList = $fsHelper->scandirFiltered($newAppsDir);
foreach ($newAppsList as $appId){
$output->writeln('Copying the application ' . $appId);
$fsHelper->copyr($newAppsDir . '/' . $appId, $locator->getOwnCloudRootPath() . '/apps/' . $appId, false);
}

try {
$appDirectories = $fsHelper->scandirFiltered($oldSourcesDir . '/apps');
foreach ($appDirectories as $appDirectory){
$fsHelper->rmdirr($oldSourcesDir . '/apps/' . $appDirectory);
}
$plain = $this->occRunner->run('upgrade');
$output->writeln($plain);
} catch (ProcessFailedException $e){
Expand Down
13 changes: 4 additions & 9 deletions src/Command/MaintenanceModeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\ProcessUtils;
use Owncloud\Updater\Utils\OccRunner;

class MaintenanceModeCommand extends Command {
Expand Down Expand Up @@ -58,18 +57,14 @@ protected function configure(){
}

protected function execute(InputInterface $input, OutputInterface $output){
$mode = '';
$args = [];
if ($input->getOption('on')){
$mode = '--on';
$args = ['--on' => ''];
} elseif ($input->getOption('off')){
$mode = '--off';
$args = ['--off' => ''];
}

if ($mode !== ''){
$mode = ProcessUtils::escapeArgument($mode);
}

$response = $this->occRunner->run('maintenance:mode ' . $mode);
$response = $this->occRunner->run('maintenance:mode', $args);
$output->writeln($response);
}

Expand Down
1 change: 0 additions & 1 deletion src/Command/StartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class StartCommand extends Command {
[ 'command' => 'upgrade:dbUpgrade'],
[ 'command' => 'upgrade:disableNotShippedApps'],
[ 'command' => 'upgrade:executeCoreUpgradeScripts'],
[ 'command' => 'upgrade:upgradeShippedApps'],
[ 'command' => 'upgrade:enableNotShippedApps'],
[ 'command' => 'upgrade:cleanCache'],
[ 'command' => 'upgrade:postUpgradeRepair'],
Expand Down
75 changes: 0 additions & 75 deletions src/Command/UpgradeShippedAppsCommand.php

This file was deleted.

33 changes: 33 additions & 0 deletions src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ class Application extends \Symfony\Component\Console\Application {
/** @var ConsoleLogger */
protected $fallbackLogger;

/** @var string */
protected $endpoint;

/** @var string */
protected $authToken;

/** @var array */
protected $allowFailure = [
Expand Down Expand Up @@ -77,6 +82,34 @@ public function getContainer(){
return $this->diContainer;
}

/**
* @param string $endpoint
*/
public function setEndpoint($endpoint){
$this->endpoint = $endpoint;
}

/**
* @return string
*/
public function getEndpoint(){
return $this->endpoint;
}

/**
* @param $token
*/
public function setAuthToken($token){
$this->authToken = $token;
}

/**
* @return string
*/
public function getAuthToken(){
return $this->authToken;
}

/**
* Get logger instance
* @return \Psr\Log\LoggerInterface
Expand Down
20 changes: 15 additions & 5 deletions src/Controller/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,9 @@ public function dispatch() {

protected function isLoggedIn() {
/** @var ConfigReader $configReader */
$configReader = $this->container['utils.configReader'];
$configReader->init();
$storedSecret = isset($configReader->get(['system'])['updater.secret']) ? $configReader->get(['system'])['updater.secret'] : null;
if(is_null($storedSecret)) {
$locator = $this->container['utils.locator'];
$storedSecret = $locator->getSecretFromConfig();
if($storedSecret === '') {
die('updater.secret is undefined in config/config.php. Either browse the admin settings in your ownCloud and click "Open updater" or define a strong secret using <pre>php -r \'echo password_hash("MyStrongSecretDoUseYourOwn!", PASSWORD_DEFAULT)."\n";\'</pre> and set this in the config.php.');
}
$sentAuthHeader = ($this->request->header('X_Updater_Auth') !== null) ? $this->request->header('X_Updater_Auth') : '';
Expand Down Expand Up @@ -135,7 +134,18 @@ public function ajaxAction() {
$output->setFormatter(new HtmlOutputFormatter($formatter));

$application->setAutoExit(false);
// Some commands dump things out instead of returning a value

$endpoint = preg_replace('/(updater\/|updater\/index.php)$/', '', $this->request->getRequestUri());
$fullEndpoint = sprintf(
'%s://%s%sindex.php/occ/',
$this->request->getServerProtocol(),
$this->request->getHost(),
$endpoint !== '' ? $endpoint : '/'
);

$application->setEndpoint($fullEndpoint);
$application->setAuthToken($this->request->header('X_Updater_Auth'));
// Some commands dump things out instead of returning a value
ob_start();
$errorCode = $application->run($input, $output);
if (!$result = $output->fetch()){
Expand Down
Loading