diff options
-rw-r--r-- | lib/base.php | 21 | ||||
-rw-r--r-- | lib/private/app.php | 8 | ||||
-rw-r--r-- | lib/private/backgroundjob/joblist.php | 152 | ||||
-rw-r--r-- | lib/private/helper.php | 56 | ||||
-rw-r--r-- | lib/private/legacy/config.php | 94 | ||||
-rw-r--r-- | lib/private/server.php | 7 | ||||
-rw-r--r-- | lib/private/systemconfig.php | 17 | ||||
-rw-r--r-- | lib/private/user.php | 4 | ||||
-rw-r--r-- | lib/private/util.php | 20 | ||||
-rw-r--r-- | lib/public/backgroundjob/ijoblist.php | 8 | ||||
-rw-r--r-- | lib/public/util.php | 11 | ||||
-rw-r--r-- | settings/help.php | 4 | ||||
-rw-r--r-- | tests/lib/allconfig.php | 16 | ||||
-rw-r--r-- | tests/lib/backgroundjob/joblist.php | 13 | ||||
-rw-r--r-- | tests/lib/helper.php | 120 | ||||
-rw-r--r-- | tests/lib/server.php | 3 |
16 files changed, 180 insertions, 374 deletions
diff --git a/lib/base.php b/lib/base.php index 8f1432d6fb9..c0db0454f6a 100644 --- a/lib/base.php +++ b/lib/base.php @@ -113,6 +113,11 @@ class OC { public static $server = null; /** + * @var \OC\Config + */ + private static $config = null; + + /** * @throws \RuntimeException when the 3rdparty directory is missing or * the app path list is empty or contains an invalid path */ @@ -124,7 +129,7 @@ class OC { } else { self::$configDir = OC::$SERVERROOT . '/config/'; } - OC_Config::$object = new \OC\Config(self::$configDir); + self::$config = new \OC\Config(self::$configDir); OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT))); /** @@ -137,7 +142,7 @@ class OC { 'SCRIPT_FILENAME' => $_SERVER['SCRIPT_FILENAME'], ], ]; - $fakeRequest = new \OC\AppFramework\Http\Request($params, null, new \OC\AllConfig(new \OC\SystemConfig())); + $fakeRequest = new \OC\AppFramework\Http\Request($params, null, new \OC\AllConfig(new \OC\SystemConfig(self::$config))); $scriptName = $fakeRequest->getScriptName(); if (substr($scriptName, -1) == '/') { $scriptName .= 'index.php'; @@ -152,7 +157,7 @@ class OC { if (OC::$CLI) { - OC::$WEBROOT = OC_Config::getValue('overwritewebroot', ''); + OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); } else { if (substr($scriptName, 0 - strlen(OC::$SUBURI)) === OC::$SUBURI) { OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); @@ -165,7 +170,7 @@ class OC { // This most likely means that we are calling from CLI. // However some cron jobs still need to generate // a web URL, so we use overwritewebroot as a fallback. - OC::$WEBROOT = OC_Config::getValue('overwritewebroot', ''); + OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); } // Resolve /owncloud to /owncloud/ to ensure to always have a trailing @@ -178,8 +183,8 @@ class OC { } // search the 3rdparty folder - OC::$THIRDPARTYROOT = OC_Config::getValue('3rdpartyroot', null); - OC::$THIRDPARTYWEBROOT = OC_Config::getValue('3rdpartyurl', null); + OC::$THIRDPARTYROOT = self::$config->getValue('3rdpartyroot', null); + OC::$THIRDPARTYWEBROOT = self::$config->getValue('3rdpartyurl', null); if (empty(OC::$THIRDPARTYROOT) && empty(OC::$THIRDPARTYWEBROOT)) { if (file_exists(OC::$SERVERROOT . '/3rdparty')) { @@ -197,7 +202,7 @@ class OC { } // search the apps folder - $config_paths = OC_Config::getValue('apps_paths', array()); + $config_paths = self::$config->getValue('apps_paths', array()); if (!empty($config_paths)) { foreach ($config_paths as $paths) { if (isset($paths['url']) && isset($paths['path'])) { @@ -517,7 +522,7 @@ class OC { } // setup the basic server - self::$server = new \OC\Server(\OC::$WEBROOT); + self::$server = new \OC\Server(\OC::$WEBROOT, self::$config); \OC::$server->getEventLogger()->log('autoloader', 'Autoloader', $loaderStart, $loaderEnd); \OC::$server->getEventLogger()->start('boot', 'Initialize'); diff --git a/lib/private/app.php b/lib/private/app.php index e8cc9219224..ff711e82424 100644 --- a/lib/private/app.php +++ b/lib/private/app.php @@ -96,7 +96,7 @@ class OC_App { * if $types is set, only apps of those types will be loaded */ public static function loadApps($types = null) { - if (OC_Config::getValue('maintenance', false)) { + if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) { return false; } // Load the enabled apps here @@ -239,7 +239,7 @@ class OC_App { * @return string[] */ public static function getEnabledApps($forceRefresh = false, $all = false) { - if (!OC_Config::getValue('installed', false)) { + if (!\OC::$server->getSystemConfig()->getValue('installed', false)) { return array(); } // in incognito mode or when logged out, $user will be false, @@ -374,7 +374,7 @@ class OC_App { $settings = array(); // by default, settings only contain the help menu if (OC_Util::getEditionString() === '' && - OC_Config::getValue('knowledgebaseenabled', true) == true + \OC::$server->getSystemConfig()->getValue('knowledgebaseenabled', true) == true ) { $settings = array( array( @@ -455,7 +455,7 @@ class OC_App { * @return string|false */ public static function getInstallPath() { - if (OC_Config::getValue('appstoreenabled', true) == false) { + if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) { return false; } diff --git a/lib/private/backgroundjob/joblist.php b/lib/private/backgroundjob/joblist.php index 03c9180ddb0..75c205833fe 100644 --- a/lib/private/backgroundjob/joblist.php +++ b/lib/private/backgroundjob/joblist.php @@ -24,134 +24,179 @@ namespace OC\BackgroundJob; +use OCP\BackgroundJob\IJob; use OCP\BackgroundJob\IJobList; use OCP\AutoloadNotAllowedException; class JobList implements IJobList { - /** - * @var \OCP\IDBConnection - */ - private $conn; + /** @var \OCP\IDBConnection */ + protected $connection; /** * @var \OCP\IConfig $config */ - private $config; + protected $config; /** - * @param \OCP\IDBConnection $conn + * @param \OCP\IDBConnection $connection * @param \OCP\IConfig $config */ - public function __construct($conn, $config) { - $this->conn = $conn; + public function __construct($connection, $config) { + $this->connection = $connection; $this->config = $config; } /** - * @param Job|string $job + * @param IJob|string $job * @param mixed $argument */ public function add($job, $argument = null) { if (!$this->has($job, $argument)) { - if ($job instanceof Job) { + if ($job instanceof IJob) { $class = get_class($job); } else { $class = $job; } + $argument = json_encode($argument); if (strlen($argument) > 4000) { throw new \InvalidArgumentException('Background job arguments can\'t exceed 4000 characters (json encoded)'); } - $query = $this->conn->prepare('INSERT INTO `*PREFIX*jobs`(`class`, `argument`, `last_run`) VALUES(?, ?, 0)'); - $query->execute(array($class, $argument)); + + $query = $this->connection->getQueryBuilder(); + $query->insert('jobs') + ->values([ + 'class' => $query->createNamedParameter($class), + 'argument' => $query->createNamedParameter($argument), + 'last_run' => $query->createNamedParameter(0, \PDO::PARAM_INT), + ]); + $query->execute(); } } /** - * @param Job|string $job + * @param IJob|string $job * @param mixed $argument */ public function remove($job, $argument = null) { - if ($job instanceof Job) { + if ($job instanceof IJob) { $class = get_class($job); } else { $class = $job; } + + $query = $this->connection->getQueryBuilder(); + $query->delete('jobs') + ->where($query->expr()->eq('class', $query->createNamedParameter($class))); if (!is_null($argument)) { $argument = json_encode($argument); - $query = $this->conn->prepare('DELETE FROM `*PREFIX*jobs` WHERE `class` = ? AND `argument` = ?'); - $query->execute(array($class, $argument)); - } else { - $query = $this->conn->prepare('DELETE FROM `*PREFIX*jobs` WHERE `class` = ?'); - $query->execute(array($class)); + $query->andWhere($query->expr()->eq('argument', $query->createNamedParameter($argument))); } + $query->execute(); } + /** + * @param int $id + */ protected function removeById($id) { - $query = $this->conn->prepare('DELETE FROM `*PREFIX*jobs` WHERE `id` = ?'); - $query->execute([$id]); + $query = $this->connection->getQueryBuilder(); + $query->delete('jobs') + ->where($query->expr()->eq('id', $query->createNamedParameter($id, \PDO::PARAM_INT))); + $query->execute(); } /** * check if a job is in the list * - * @param Job|string $job + * @param IJob|string $job * @param mixed $argument * @return bool */ public function has($job, $argument) { - if ($job instanceof Job) { + if ($job instanceof IJob) { $class = get_class($job); } else { $class = $job; } $argument = json_encode($argument); - $query = $this->conn->prepare('SELECT `id` FROM `*PREFIX*jobs` WHERE `class` = ? AND `argument` = ?'); - $query->execute(array($class, $argument)); - return (bool)$query->fetch(); + + $query = $this->connection->getQueryBuilder(); + $query->select('id') + ->from('jobs') + ->where($query->expr()->eq('class', $query->createNamedParameter($class))) + ->andWhere($query->expr()->eq('argument', $query->createNamedParameter($argument))) + ->setMaxResults(1); + + $result = $query->execute(); + $row = $result->fetch(); + $result->closeCursor(); + + return (bool) $row; } /** * get all jobs in the list * - * @return Job[] + * @return IJob[] */ public function getAll() { - $query = $this->conn->prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs`'); - $query->execute(); - $jobs = array(); - while ($row = $query->fetch()) { + $query = $this->connection->getQueryBuilder(); + $query->select('*') + ->from('jobs'); + $result = $query->execute(); + + $jobs = []; + while ($row = $result->fetch()) { $job = $this->buildJob($row); if ($job) { $jobs[] = $job; } } + $result->closeCursor(); + return $jobs; } /** * get the next job in the list * - * @return Job + * @return IJob|null */ public function getNext() { $lastId = $this->getLastJob(); - $query = $this->conn->prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs` WHERE `id` > ? ORDER BY `id` ASC', 1); - $query->execute(array($lastId)); - if ($row = $query->fetch()) { + + $query = $this->connection->getQueryBuilder(); + $query->select('*') + ->from('jobs') + ->where($query->expr()->gt('id', $query->createNamedParameter($lastId, \PDO::PARAM_INT))) + ->orderBy('id', 'ASC') + ->setMaxResults(1); + $result = $query->execute(); + $row = $result->fetch(); + $result->closeCursor(); + + if ($row) { $jobId = $row['id']; $job = $this->buildJob($row); } else { //begin at the start of the queue - $query = $this->conn->prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs` ORDER BY `id` ASC', 1); - $query->execute(); - if ($row = $query->fetch()) { + $query = $this->connection->getQueryBuilder(); + $query->select('*') + ->from('jobs') + ->orderBy('id', 'ASC') + ->setMaxResults(1); + $result = $query->execute(); + $row = $result->fetch(); + $result->closeCursor(); + + if ($row) { $jobId = $row['id']; $job = $this->buildJob($row); } else { return null; //empty job list } } + if (is_null($job)) { $this->removeById($jobId); return $this->getNext(); @@ -162,12 +207,18 @@ class JobList implements IJobList { /** * @param int $id - * @return Job|null + * @return IJob|null */ public function getById($id) { - $query = $this->conn->prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs` WHERE `id` = ?'); - $query->execute(array($id)); - if ($row = $query->fetch()) { + $query = $this->connection->getQueryBuilder(); + $query->select('*') + ->from('jobs') + ->where($query->expr()->eq('id', $query->createNamedParameter($id, \PDO::PARAM_INT))); + $result = $query->execute(); + $row = $result->fetch(); + $result->closeCursor(); + + if ($row) { return $this->buildJob($row); } else { return null; @@ -178,7 +229,7 @@ class JobList implements IJobList { * get the job object from a row in the db * * @param array $row - * @return Job + * @return IJob|null */ private function buildJob($row) { $class = $row['class']; @@ -204,7 +255,7 @@ class JobList implements IJobList { /** * set the job that was last ran * - * @param Job $job + * @param IJob $job */ public function setLastJob($job) { $this->config->setAppValue('backgroundjob', 'lastjob', $job->getId()); @@ -213,19 +264,22 @@ class JobList implements IJobList { /** * get the id of the last ran job * - * @return string + * @return int */ public function getLastJob() { - return $this->config->getAppValue('backgroundjob', 'lastjob', 0); + return (int) $this->config->getAppValue('backgroundjob', 'lastjob', 0); } /** * set the lastRun of $job to now * - * @param Job $job + * @param IJob $job */ public function setLastRun($job) { - $query = $this->conn->prepare('UPDATE `*PREFIX*jobs` SET `last_run` = ? WHERE `id` = ?'); - $query->execute(array(time(), $job->getId())); + $query = $this->connection->getQueryBuilder(); + $query->update('jobs') + ->set('last_run', $query->createNamedParameter(time(), \PDO::PARAM_INT)) + ->where($query->expr()->eq('id', $query->createNamedParameter($job->getId(), \PDO::PARAM_INT))); + $query->execute(); } } diff --git a/lib/private/helper.php b/lib/private/helper.php index 95f6be27ccf..64952903712 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -54,60 +54,6 @@ class OC_Helper { private static $templateManager; /** - * Creates an absolute url - * @param string $app app - * @param string $file file - * @param array $args array with param=>value, will be appended to the returned url - * The value of $args will be urlencoded - * @return string the url - * - * Returns a absolute url to the given app and file. - */ - public static function linkToAbsolute($app, $file, $args = array()) { - return OC::$server->getURLGenerator()->getAbsoluteURL( - OC::$server->getURLGenerator()->linkTo($app, $file, $args) - ); - } - - /** - * Makes an $url absolute - * @param string $url the url - * @return string the absolute url - * @deprecated Use \OC::$server->getURLGenerator()->getAbsoluteURL($url) - * - * Returns a absolute url to the given app and file. - */ - public static function makeURLAbsolute($url) { - return OC::$server->getURLGenerator()->getAbsoluteURL($url); - } - - /** - * Creates an url for remote use - * @param string $service id - * @return string the url - * - * Returns a url to the given service. - */ - public static function linkToRemoteBase($service) { - return OC::$server->getURLGenerator()->linkTo('', 'remote.php') . '/' . $service; - } - - /** - * Creates an absolute url for remote use - * @param string $service id - * @param bool $add_slash - * @return string the url - * - * Returns a absolute url to the given service. - */ - public static function linkToRemote($service, $add_slash = true) { - return OC::$server->getURLGenerator()->getAbsoluteURL( - self::linkToRemoteBase($service) - . (($add_slash && $service[strlen($service) - 1] != '/') ? '/' : '') - ); - } - - /** * Creates an absolute url for public use * @param string $service id * @param bool $add_slash @@ -666,7 +612,7 @@ class OC_Helper { */ public static function getStorageInfo($path, $rootInfo = null) { // return storage info without adding mount points - $includeExtStorage = \OC_Config::getValue('quota_include_external_storage', false); + $includeExtStorage = \OC::$server->getSystemConfig()->getValue('quota_include_external_storage', false); if (!$rootInfo) { $rootInfo = \OC\Files\Filesystem::getFileInfo($path, false); diff --git a/lib/private/legacy/config.php b/lib/private/legacy/config.php deleted file mode 100644 index 1835d4a4b1c..00000000000 --- a/lib/private/legacy/config.php +++ /dev/null @@ -1,94 +0,0 @@ -<?php -/** - * @author Bart Visscher <bartv@thisnet.nl> - * @author Joas Schilling <nickvergessen@owncloud.com> - * @author Jörn Friedrich Dreyer <jfd@butonic.de> - * @author Lukas Reschke <lukas@owncloud.com> - * @author Michael Gapczynski <GapczynskiM@gmail.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin McCorkell <rmccorkell@karoshi.org.uk> - * - * @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/> - * - */ - -/** - * This class is responsible for reading and writing config.php, the very basic - * configuration file of ownCloud. - * - * @deprecated use \OC::$server->getConfig() to get an \OCP\Config instance - */ -class OC_Config { - - /** @var \OC\Config */ - public static $object; - - /** - * Lists all available config keys - * @return array an array of key names - * - * This function returns all keys saved in config.php. Please note that it - * does not return the values. - */ - public static function getKeys() { - return self::$object->getKeys(); - } - - /** - * Gets a value from config.php - * @param string $key key - * @param mixed $default = null default value - * @return mixed the value or $default - * - * This function gets the value from config.php. If it does not exist, - * $default will be returned. - */ - public static function getValue($key, $default = null) { - return self::$object->getValue($key, $default); - } - - /** - * Sets a value - * @param string $key key - * @param mixed $value value - * - * This function sets the value and writes the config.php. - * - */ - public static function setValue($key, $value) { - self::$object->setValue($key, $value); - } - - /** - * Sets and deletes values and writes the config.php - * - * @param array $configs Associative array with `key => value` pairs - * If value is null, the config key will be deleted - */ - public static function setValues(array $configs) { - self::$object->setValues($configs); - } - - /** - * Removes a key from the config - * @param string $key key - * - * This function removes a key from the config.php. - */ - public static function deleteKey($key) { - self::$object->deleteKey($key); - } -} diff --git a/lib/private/server.php b/lib/private/server.php index 8439500706d..3e1af0310d1 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -84,8 +84,9 @@ class Server extends SimpleContainer implements IServerContainer { /** * @param string $webRoot + * @param \OC\Config $config */ - public function __construct($webRoot) { + public function __construct($webRoot, \OC\Config $config) { parent::__construct(); $this->webRoot = $webRoot; @@ -238,8 +239,8 @@ class Server extends SimpleContainer implements IServerContainer { $c->getSystemConfig() ); }); - $this->registerService('SystemConfig', function ($c) { - return new \OC\SystemConfig(); + $this->registerService('SystemConfig', function ($c) use ($config) { + return new \OC\SystemConfig($config); }); $this->registerService('AppConfig', function ($c) { return new \OC\AppConfig(\OC_DB::getConnection()); diff --git a/lib/private/systemconfig.php b/lib/private/systemconfig.php index 94b815aebd7..fb8c18123d7 100644 --- a/lib/private/systemconfig.php +++ b/lib/private/systemconfig.php @@ -44,12 +44,19 @@ class SystemConfig { 'objectstore' => ['arguments' => ['password' => true]], ]; + /** @var Config */ + private $config; + + public function __construct(Config $config) { + $this->config = $config; + } + /** * Lists all available config keys * @return array an array of key names */ public function getKeys() { - return \OC_Config::getKeys(); + return $this->config->getKeys(); } /** @@ -59,7 +66,7 @@ class SystemConfig { * @param mixed $value the value that should be stored */ public function setValue($key, $value) { - \OC_Config::setValue($key, $value); + $this->config->setValue($key, $value); } /** @@ -69,7 +76,7 @@ class SystemConfig { * If value is null, the config key will be deleted */ public function setValues(array $configs) { - \OC_Config::setValues($configs); + $this->config->setValues($configs); } /** @@ -80,7 +87,7 @@ class SystemConfig { * @return mixed the value or $default */ public function getValue($key, $default = '') { - return \OC_Config::getValue($key, $default); + return $this->config->getValue($key, $default); } /** @@ -106,7 +113,7 @@ class SystemConfig { * @param string $key the key of the value, under which it was saved */ public function deleteValue($key) { - \OC_Config::deleteKey($key); + $this->config->deleteKey($key); } /** diff --git a/lib/private/user.php b/lib/private/user.php index f806aa07251..cfa60d675fe 100644 --- a/lib/private/user.php +++ b/lib/private/user.php @@ -130,7 +130,7 @@ class OC_User { */ public static function setupBackends() { OC_App::loadApps(array('prelogin')); - $backends = OC_Config::getValue('user_backends', array()); + $backends = \OC::$server->getSystemConfig()->getValue('user_backends', array()); foreach ($backends as $i => $config) { $class = $config['class']; $arguments = $config['arguments']; @@ -498,7 +498,7 @@ class OC_User { if ($user) { return $user->getHome(); } else { - return OC_Config::getValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $uid; + return \OC::$server->getSystemConfig()->getValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $uid; } } diff --git a/lib/private/util.php b/lib/private/util.php index c63befb3f32..0e029d74b7d 100644 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -72,7 +72,7 @@ class OC_Util { private static function initLocalStorageRootFS() { // mount local file backend as root - $configDataDirectory = OC_Config::getValue("datadirectory", OC::$SERVERROOT . "/data"); + $configDataDirectory = \OC::$server->getSystemConfig()->getValue("datadirectory", OC::$SERVERROOT . "/data"); //first set up the local "root" storage \OC\Files\Filesystem::initMountManager(); if (!self::$rootMounted) { @@ -184,7 +184,7 @@ class OC_Util { OC_Hook::emit('OC_Filesystem', 'preSetup', array('user' => $user)); //check if we are using an object storage - $objectStore = OC_Config::getValue('objectstore'); + $objectStore = \OC::$server->getSystemConfig()->getValue('objectstore', null); if (isset($objectStore)) { self::initObjectStoreRootFS($objectStore); } else { @@ -848,7 +848,7 @@ class OC_Util { public static function checkDatabaseVersion() { $l = \OC::$server->getL10N('lib'); $errors = array(); - $dbType = \OC_Config::getValue('dbtype', 'sqlite'); + $dbType = \OC::$server->getSystemConfig()->getValue('dbtype', 'sqlite'); if ($dbType === 'pgsql') { // check PostgreSQL version try { @@ -974,7 +974,7 @@ class OC_Util { */ public static function checkAppEnabled($app) { if (!OC_App::isEnabled($app)) { - header('Location: ' . OC_Helper::linkToAbsolute('', 'index.php')); + header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); exit(); } } @@ -988,7 +988,7 @@ class OC_Util { public static function checkLoggedIn() { // Check if we are a user if (!OC_User::isLoggedIn()) { - header('Location: ' . OC_Helper::linkToAbsolute('', 'index.php', + header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php', [ 'redirect_url' => \OC::$server->getRequest()->getRequestUri() ] @@ -1006,7 +1006,7 @@ class OC_Util { public static function checkAdminUser() { OC_Util::checkLoggedIn(); if (!OC_User::isAdminUser(OC_User::getUser())) { - header('Location: ' . OC_Helper::linkToAbsolute('', 'index.php')); + header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); exit(); } } @@ -1046,7 +1046,7 @@ class OC_Util { } if (!$isSubAdmin) { - header('Location: ' . OC_Helper::linkToAbsolute('', 'index.php')); + header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); exit(); } return true; @@ -1108,11 +1108,11 @@ class OC_Util { * @return string */ public static function getInstanceId() { - $id = OC_Config::getValue('instanceid', null); + $id = \OC::$server->getSystemConfig()->getValue('instanceid', null); if (is_null($id)) { // We need to guarantee at least one letter in instanceid so it can be used as the session_name $id = 'oc' . \OC::$server->getSecureRandom()->getLowStrengthGenerator()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); - OC_Config::$object->setValue('instanceid', $id); + \OC::$server->getSystemConfig()->setValue('instanceid', $id); } return $id; } @@ -1364,7 +1364,7 @@ class OC_Util { * @return string the theme */ public static function getTheme() { - $theme = OC_Config::getValue("theme", ''); + $theme = \OC::$server->getSystemConfig()->getValue("theme", ''); if ($theme === '') { if (is_dir(OC::$SERVERROOT . '/themes/default')) { diff --git a/lib/public/backgroundjob/ijoblist.php b/lib/public/backgroundjob/ijoblist.php index 384f8b3d801..51431c42a67 100644 --- a/lib/public/backgroundjob/ijoblist.php +++ b/lib/public/backgroundjob/ijoblist.php @@ -36,7 +36,6 @@ interface IJobList { * * @param \OCP\BackgroundJob\IJob|string $job * @param mixed $argument The argument to be passed to $job->run() when the job is exectured - * @return void * @since 7.0.0 */ public function add($job, $argument = null); @@ -46,7 +45,6 @@ interface IJobList { * * @param \OCP\BackgroundJob\IJob|string $job * @param mixed $argument - * @return void * @since 7.0.0 */ public function remove($job, $argument = null); @@ -72,14 +70,14 @@ interface IJobList { /** * get the next job in the list * - * @return \OCP\BackgroundJob\IJob + * @return \OCP\BackgroundJob\IJob|null * @since 7.0.0 */ public function getNext(); /** * @param int $id - * @return \OCP\BackgroundJob\IJob + * @return \OCP\BackgroundJob\IJob|null * @since 7.0.0 */ public function getById($id); @@ -88,7 +86,6 @@ interface IJobList { * set the job that was last ran to the current time * * @param \OCP\BackgroundJob\IJob $job - * @return void * @since 7.0.0 */ public function setLastJob($job); @@ -105,7 +102,6 @@ interface IJobList { * set the lastRun of $job to now * * @param \OCP\BackgroundJob\IJob $job - * @return void * @since 7.0.0 */ public function setLastRun($job); diff --git a/lib/public/util.php b/lib/public/util.php index da4aa6e9deb..a9fe0e47de6 100644 --- a/lib/public/util.php +++ b/lib/public/util.php @@ -269,7 +269,10 @@ class Util { * @since 4.0.0 - parameter $args was added in 4.5.0 */ public static function linkToAbsolute( $app, $file, $args = array() ) { - return(\OC_Helper::linkToAbsolute( $app, $file, $args )); + $urlGenerator = \OC::$server->getURLGenerator(); + return $urlGenerator->getAbsoluteURL( + $urlGenerator->linkTo($app, $file, $args) + ); } /** @@ -279,7 +282,11 @@ class Util { * @since 4.0.0 */ public static function linkToRemote( $service ) { - return(\OC_Helper::linkToRemote( $service )); + $urlGenerator = \OC::$server->getURLGenerator(); + $remoteBase = $urlGenerator->linkTo('', 'remote.php') . '/' . $service; + return $urlGenerator->getAbsoluteURL( + $remoteBase . (($service[strlen($service) - 1] != '/') ? '/' : '') + ); } /** diff --git a/settings/help.php b/settings/help.php index 21b48242706..848ce06cf49 100644 --- a/settings/help.php +++ b/settings/help.php @@ -34,11 +34,11 @@ OC_Util::addStyle( "settings", "settings" ); if(isset($_GET['mode']) and $_GET['mode'] === 'admin') { - $url=OC_Helper::linkToAbsolute( 'core', 'doc/admin/index.html' ); + $url=\OCP\Util::linkToAbsolute( 'core', 'doc/admin/index.html' ); $style1=''; $style2=' active'; }else{ - $url=OC_Helper::linkToAbsolute( 'core', 'doc/user/index.html' ); + $url=\OCP\Util::linkToAbsolute( 'core', 'doc/user/index.html' ); $style1=' active'; $style2=''; } diff --git a/tests/lib/allconfig.php b/tests/lib/allconfig.php index ca3dce12eaf..0caf8163cfc 100644 --- a/tests/lib/allconfig.php +++ b/tests/lib/allconfig.php @@ -28,7 +28,9 @@ class TestAllConfig extends \Test\TestCase { $connection = $this->connection; } if($systemConfig === null) { - $systemConfig = $this->getMock('\OC\SystemConfig'); + $systemConfig = $this->getMockBuilder('\OC\SystemConfig') + ->disableOriginalConstructor() + ->getMock(); } return new \OC\AllConfig($systemConfig, $connection); } @@ -89,7 +91,9 @@ class TestAllConfig extends \Test\TestCase { public function testSetUserValueWithPreCondition() { // mock the check for the database to run the correct SQL statements for each database type - $systemConfig = $this->getMock('\OC\SystemConfig'); + $systemConfig = $this->getMockBuilder('\OC\SystemConfig') + ->disableOriginalConstructor() + ->getMock(); $systemConfig->expects($this->once()) ->method('getValue') ->with($this->equalTo('dbtype'), @@ -133,7 +137,9 @@ class TestAllConfig extends \Test\TestCase { */ public function testSetUserValueWithPreConditionFailure() { // mock the check for the database to run the correct SQL statements for each database type - $systemConfig = $this->getMock('\OC\SystemConfig'); + $systemConfig = $this->getMockBuilder('\OC\SystemConfig') + ->disableOriginalConstructor() + ->getMock(); $systemConfig->expects($this->once()) ->method('getValue') ->with($this->equalTo('dbtype'), @@ -394,7 +400,9 @@ class TestAllConfig extends \Test\TestCase { public function testGetUsersForUserValue() { // mock the check for the database to run the correct SQL statements for each database type - $systemConfig = $this->getMock('\OC\SystemConfig'); + $systemConfig = $this->getMockBuilder('\OC\SystemConfig') + ->disableOriginalConstructor() + ->getMock(); $systemConfig->expects($this->once()) ->method('getValue') ->with($this->equalTo('dbtype'), diff --git a/tests/lib/backgroundjob/joblist.php b/tests/lib/backgroundjob/joblist.php index 73b3255c079..c0796d8253a 100644 --- a/tests/lib/backgroundjob/joblist.php +++ b/tests/lib/backgroundjob/joblist.php @@ -15,26 +15,21 @@ use Test\TestCase; * Class JobList * * @group DB - * * @package Test\BackgroundJob */ class JobList extends TestCase { - /** - * @var \OC\BackgroundJob\JobList - */ + /** @var \OC\BackgroundJob\JobList */ protected $instance; - /** - * @var \OCP\IConfig | \PHPUnit_Framework_MockObject_MockObject $config - */ + /** @var \OCP\IConfig|\PHPUnit_Framework_MockObject_MockObject */ protected $config; protected function setUp() { parent::setUp(); - $conn = \OC::$server->getDatabaseConnection(); + $connection = \OC::$server->getDatabaseConnection(); $this->config = $this->getMock('\OCP\IConfig'); - $this->instance = new \OC\BackgroundJob\JobList($conn, $this->config); + $this->instance = new \OC\BackgroundJob\JobList($connection, $this->config); } protected function getAllSorted() { diff --git a/tests/lib/helper.php b/tests/lib/helper.php index 114354c7936..c2620896157 100644 --- a/tests/lib/helper.php +++ b/tests/lib/helper.php @@ -223,126 +223,6 @@ class Test_Helper extends \Test\TestCase { /** * @small - * test absolute URL construction - * @dataProvider provideDocRootURLs - */ - function testMakeAbsoluteURLDocRoot($url, $expectedResult) { - \OC::$WEBROOT = ''; - $result = \OC_Helper::makeURLAbsolute($url); - - $this->assertEquals($expectedResult, $result); - } - - /** - * @small - * test absolute URL construction - * @dataProvider provideSubDirURLs - */ - function testMakeAbsoluteURLSubDir($url, $expectedResult) { - \OC::$WEBROOT = '/owncloud'; - $result = \OC_Helper::makeURLAbsolute($url); - - $this->assertEquals($expectedResult, $result); - } - - public function provideDocRootURLs() { - return array( - array('index.php', 'http://localhost/index.php'), - array('/index.php', 'http://localhost/index.php'), - array('/apps/index.php', 'http://localhost/apps/index.php'), - array('apps/index.php', 'http://localhost/apps/index.php'), - ); - } - - public function provideSubDirURLs() { - return array( - array('index.php', 'http://localhost/owncloud/index.php'), - array('/index.php', 'http://localhost/owncloud/index.php'), - array('/apps/index.php', 'http://localhost/owncloud/apps/index.php'), - array('apps/index.php', 'http://localhost/owncloud/apps/index.php'), - ); - } - - /** - * @small - * test linkToAbsolute URL construction - * @dataProvider provideDocRootAppAbsoluteUrlParts - */ - public function testLinkToAbsoluteDocRoot($app, $file, $args, $expectedResult) { - \OC::$WEBROOT = ''; - $result = \OC_Helper::linkToAbsolute($app, $file, $args); - - $this->assertEquals($expectedResult, $result); - } - - /** - * @small - * test linkToAbsolute URL construction in sub directory - * @dataProvider provideSubDirAppAbsoluteUrlParts - */ - public function testLinkToAbsoluteSubDir($app, $file, $args, $expectedResult) { - \OC::$WEBROOT = '/owncloud'; - $result = \OC_Helper::linkToAbsolute($app, $file, $args); - - $this->assertEquals($expectedResult, $result); - } - - /** - * @return array - */ - public function provideDocRootAppAbsoluteUrlParts() { - return array( - array('files', 'ajax/list.php', array(), 'http://localhost/index.php/apps/files/ajax/list.php'), - array('files', 'ajax/list.php', array('trut' => 'trat', 'dut' => 'dat'), 'http://localhost/index.php/apps/files/ajax/list.php?trut=trat&dut=dat'), - array('', 'index.php', array('trut' => 'trat', 'dut' => 'dat'), 'http://localhost/index.php?trut=trat&dut=dat'), - ); - } - - /** - * @return array - */ - public function provideSubDirAppAbsoluteUrlParts() { - return array( - array('files', 'ajax/list.php', array(), 'http://localhost/owncloud/index.php/apps/files/ajax/list.php'), - array('files', 'ajax/list.php', array('trut' => 'trat', 'dut' => 'dat'), 'http://localhost/owncloud/index.php/apps/files/ajax/list.php?trut=trat&dut=dat'), - array('', 'index.php', array('trut' => 'trat', 'dut' => 'dat'), 'http://localhost/owncloud/index.php?trut=trat&dut=dat'), - ); - } - - /** - * @small - * test linkToRemoteBase URL construction - */ - public function testLinkToRemoteBase() { - \OC::$WEBROOT = ''; - $result = \OC_Helper::linkToRemoteBase('webdav'); - $this->assertEquals('/remote.php/webdav', $result); - - \OC::$WEBROOT = '/owncloud'; - $result = \OC_Helper::linkToRemoteBase('webdav'); - $this->assertEquals('/owncloud/remote.php/webdav', $result); - } - - /** - * @small - * test linkToRemote URL construction - */ - public function testLinkToRemote() { - \OC::$WEBROOT = ''; - $result = \OC_Helper::linkToRemote('webdav'); - $this->assertEquals('http://localhost/remote.php/webdav/', $result); - $result = \OC_Helper::linkToRemote('webdav', false); - $this->assertEquals('http://localhost/remote.php/webdav', $result); - - \OC::$WEBROOT = '/owncloud'; - $result = \OC_Helper::linkToRemote('webdav'); - $this->assertEquals('http://localhost/owncloud/remote.php/webdav/', $result); - $result = \OC_Helper::linkToRemote('webdav', false); - $this->assertEquals('http://localhost/owncloud/remote.php/webdav', $result); - } - - /** - * @small * test linkToPublic URL construction */ public function testLinkToPublic() { diff --git a/tests/lib/server.php b/tests/lib/server.php index 6b569e77dd9..e2670061e8d 100644 --- a/tests/lib/server.php +++ b/tests/lib/server.php @@ -38,7 +38,8 @@ class Server extends \Test\TestCase { public function setUp() { parent::setUp(); - $this->server = new \OC\Server(''); + $config = new \OC\Config(\OC::$configDir); + $this->server = new \OC\Server('', $config); } public function dataTestQuery() { |