diff options
author | tomneedham <tom@owncloud.com> | 2014-02-17 11:03:57 +0000 |
---|---|---|
committer | tomneedham <tom@owncloud.com> | 2014-02-17 11:03:57 +0000 |
commit | a4b6d667038be9ca82c51fd0e22e7f3e51cb1e17 (patch) | |
tree | 1b456e75e10dde0f5a65af47420daa0abfd0fdf5 /lib/private | |
parent | 049e03c2b92e10ef94d1f7bc900e74f078a56a9b (diff) | |
parent | 5a8d37023a84d933eaa5113400014805048a689b (diff) | |
download | nextcloud-server-a4b6d667038be9ca82c51fd0e22e7f3e51cb1e17.tar.gz nextcloud-server-a4b6d667038be9ca82c51fd0e22e7f3e51cb1e17.zip |
Merge branch 'master' into migration_unit_tests
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/appconfig.php | 191 | ||||
-rw-r--r-- | lib/private/backgroundjob/job.php | 4 | ||||
-rw-r--r-- | lib/private/backgroundjob/joblist.php | 74 | ||||
-rw-r--r-- | lib/private/db/statementwrapper.php | 3 | ||||
-rw-r--r-- | lib/private/files.php | 2 | ||||
-rw-r--r-- | lib/private/files/fileinfo.php | 185 | ||||
-rw-r--r-- | lib/private/files/storage/common.php | 9 | ||||
-rw-r--r-- | lib/private/files/storage/local.php | 7 | ||||
-rw-r--r-- | lib/private/files/storage/wrapper/wrapper.php | 8 | ||||
-rw-r--r-- | lib/private/files/view.php | 42 | ||||
-rw-r--r-- | lib/private/group/manager.php | 14 | ||||
-rw-r--r-- | lib/private/helper.php | 16 | ||||
-rw-r--r-- | lib/private/legacy/appconfig.php | 126 | ||||
-rw-r--r-- | lib/private/preview/office.php | 2 | ||||
-rw-r--r-- | lib/private/preview/pdf.php | 2 | ||||
-rw-r--r-- | lib/private/preview/svg.php | 2 | ||||
-rw-r--r-- | lib/private/preview/unknown.php | 2 | ||||
-rw-r--r-- | lib/private/server.php | 28 | ||||
-rw-r--r-- | lib/private/share/searchresultsorter.php | 59 |
19 files changed, 617 insertions, 159 deletions
diff --git a/lib/private/appconfig.php b/lib/private/appconfig.php index da0b2ff8604..a47e1ad49e6 100644 --- a/lib/private/appconfig.php +++ b/lib/private/appconfig.php @@ -33,15 +33,56 @@ * */ +namespace OC; + +use \OC\DB\Connection; + /** * This class provides an easy way for apps to store config values in the * database. */ -class OC_Appconfig { +class AppConfig implements \OCP\IAppConfig { + /** + * @var \OC\DB\Connection $conn + */ + protected $conn; + + private $cache = array(); + + private $appsLoaded = array(); + + /** + * @param \OC\DB\Connection $conn + */ + public function __construct(Connection $conn) { + $this->conn = $conn; + } - private static $cache = array(); + /** + * @param string $app + * @return string[] + */ + private function getAppCache($app) { + if (!isset($this->cache[$app])) { + $this->cache[$app] = array(); + } + return $this->cache[$app]; + } - private static $appsLoaded = array(); + private function getAppValues($app) { + $appCache = $this->getAppCache($app); + if (array_search($app, $this->appsLoaded) === false) { + $query = 'SELECT `configvalue`, `configkey` FROM `*PREFIX*appconfig`' + . ' WHERE `appid` = ?'; + $result = $this->conn->executeQuery($query, array($app)); + while ($row = $result->fetch()) { + $appCache[$row['configkey']] = $row['configvalue']; + } + $this->appsLoaded[] = $app; + } + $this->cache[$app] = $appCache; + return $appCache; + } /** * @brief Get all apps using the config @@ -50,16 +91,14 @@ class OC_Appconfig { * This function returns a list of all apps that have at least one * entry in the appconfig table. */ - public static function getApps() { - // No magic in here! - $query = OC_DB::prepare('SELECT DISTINCT `appid` FROM `*PREFIX*appconfig` ORDER BY `appid`'); - $result = $query->execute(); + public function getApps() { + $query = 'SELECT DISTINCT `appid` FROM `*PREFIX*appconfig` ORDER BY `appid`'; + $result = $this->conn->executeQuery($query); $apps = array(); - while ($row = $result->fetchRow()) { - $apps[] = $row["appid"]; + while ($appid = $result->fetchColumn()) { + $apps[] = $appid; } - return $apps; } @@ -71,35 +110,13 @@ class OC_Appconfig { * This function gets all keys of an app. Please note that the values are * not returned. */ - public static function getKeys($app) { - // No magic in here as well - $query = OC_DB::prepare('SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?'); - $result = $query->execute(array($app)); - - $keys = array(); - while ($row = $result->fetchRow()) { - $keys[] = $row["configkey"]; - } - + public function getKeys($app) { + $values = $this->getAppValues($app); + $keys = array_keys($values); + sort($keys); return $keys; } - private static function getAppValues($app) { - if (!isset(self::$cache[$app])) { - self::$cache[$app] = array(); - } - if (array_search($app, self::$appsLoaded) === false) { - $query = OC_DB::prepare('SELECT `configvalue`, `configkey` FROM `*PREFIX*appconfig`' - . ' WHERE `appid` = ?'); - $result = $query->execute(array($app)); - while ($row = $result->fetchRow()) { - self::$cache[$app][$row['configkey']] = $row['configvalue']; - } - self::$appsLoaded[] = $app; - } - return self::$cache[$app]; - } - /** * @brief Gets the config value * @param string $app app @@ -110,18 +127,11 @@ class OC_Appconfig { * This function gets a value from the appconfig table. If the key does * not exist the default value will be returned */ - public static function getValue($app, $key, $default = null) { - if (!isset(self::$cache[$app])) { - self::$cache[$app] = array(); - } - if (isset(self::$cache[$app][$key])) { - return self::$cache[$app][$key]; - } - $values = self::getAppValues($app); + public function getValue($app, $key, $default = null) { + $values = $this->getAppValues($app); if (isset($values[$key])) { return $values[$key]; } else { - self::$cache[$app][$key] = $default; return $default; } } @@ -132,12 +142,9 @@ class OC_Appconfig { * @param string $key * @return bool */ - public static function hasKey($app, $key) { - if (isset(self::$cache[$app]) and isset(self::$cache[$app][$key])) { - return true; - } - $exists = self::getKeys($app); - return in_array($key, $exists); + public function hasKey($app, $key) { + $values = $this->getAppValues($app); + return isset($values[$key]); } /** @@ -145,31 +152,32 @@ class OC_Appconfig { * @param string $app app * @param string $key key * @param string $value value - * @return bool * * Sets a value. If the key did not exist before it will be created. */ - public static function setValue($app, $key, $value) { - // Does the key exist? yes: update. No: insert - if (!self::hasKey($app, $key)) { - $query = OC_DB::prepare('INSERT INTO `*PREFIX*appconfig` ( `appid`, `configkey`, `configvalue` )' - . ' VALUES( ?, ?, ? )'); - $query->execute(array($app, $key, $value)); + public function setValue($app, $key, $value) { + // Does the key exist? no: insert, yes: update. + if (!$this->hasKey($app, $key)) { + $data = array( + 'appid' => $app, + 'configkey' => $key, + 'configvalue' => $value, + ); + $this->conn->insert('*PREFIX*appconfig', $data); } else { - $query = OC_DB::prepare('UPDATE `*PREFIX*appconfig` SET `configvalue` = ?' - . ' WHERE `appid` = ? AND `configkey` = ?'); - $query->execute(array($value, $app, $key)); + $data = array( + 'configvalue' => $value, + ); + $where = array( + 'appid' => $app, + 'configkey' => $key, + ); + $this->conn->update('*PREFIX*appconfig', $data, $where); } - // TODO where should this be documented? - \OC_Hook::emit('OC_Appconfig', 'post_set_value', array( - 'app' => $app, - 'key' => $key, - 'value' => $value - )); - if (!isset(self::$cache[$app])) { - self::$cache[$app] = array(); + if (!isset($this->cache[$app])) { + $this->cache[$app] = array(); } - self::$cache[$app][$key] = $value; + $this->cache[$app][$key] = $value; } /** @@ -180,15 +188,15 @@ class OC_Appconfig { * * Deletes a key. */ - public static function deleteKey($app, $key) { - // Boring! - $query = OC_DB::prepare('DELETE FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?'); - $query->execute(array($app, $key)); - if (isset(self::$cache[$app]) and isset(self::$cache[$app][$key])) { - unset(self::$cache[$app][$key]); + public function deleteKey($app, $key) { + $where = array( + 'appid' => $app, + 'configkey' => $key, + ); + $this->conn->delete('*PREFIX*appconfig', $where); + if (isset($this->cache[$app]) and isset($this->cache[$app][$key])) { + unset($this->cache[$app][$key]); } - - return true; } /** @@ -198,13 +206,12 @@ class OC_Appconfig { * * Removes all keys in appconfig belonging to the app. */ - public static function deleteApp($app) { - // Nothing special - $query = OC_DB::prepare('DELETE FROM `*PREFIX*appconfig` WHERE `appid` = ?'); - $query->execute(array($app)); - self::$cache[$app] = array(); - - return true; + public function deleteApp($app) { + $where = array( + 'appid' => $app, + ); + $this->conn->delete('*PREFIX*appconfig', $where); + unset($this->cache[$app]); } /** @@ -214,10 +221,11 @@ class OC_Appconfig { * @param key * @return array */ - public static function getValues($app, $key) { - if ($app !== false and $key !== false) { + public function getValues($app, $key) { + if (($app !== false) == ($key !== false)) { return false; } + $fields = '`configvalue`'; $where = 'WHERE'; $params = array(); @@ -232,13 +240,14 @@ class OC_Appconfig { $params[] = $key; $key = 'appid'; } - $queryString = 'SELECT ' . $fields . ' FROM `*PREFIX*appconfig` ' . $where; - $query = OC_DB::prepare($queryString); - $result = $query->execute($params); + $query = 'SELECT ' . $fields . ' FROM `*PREFIX*appconfig` ' . $where; + $result = $this->conn->executeQuery($query, $params); + $values = array(); - while ($row = $result->fetchRow()) { + while ($row = $result->fetch((\PDO::FETCH_ASSOC))) { $values[$row[$key]] = $row['configvalue']; } + return $values; } } diff --git a/lib/private/backgroundjob/job.php b/lib/private/backgroundjob/job.php index 92bd0f8fdbd..0cef401bc24 100644 --- a/lib/private/backgroundjob/job.php +++ b/lib/private/backgroundjob/job.php @@ -8,7 +8,9 @@ namespace OC\BackgroundJob; -abstract class Job { +use OCP\BackgroundJob\IJob; + +abstract class Job implements IJob { /** * @var int $id */ diff --git a/lib/private/backgroundjob/joblist.php b/lib/private/backgroundjob/joblist.php index 99743a70c77..586e99a3cbc 100644 --- a/lib/private/backgroundjob/joblist.php +++ b/lib/private/backgroundjob/joblist.php @@ -1,6 +1,6 @@ <?php /** - * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com> + * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. @@ -8,14 +8,28 @@ namespace OC\BackgroundJob; -/** - * Class QueuedJob - * - * create a background job that is to be executed once - * - * @package OC\BackgroundJob - */ -class JobList { +use OCP\BackgroundJob\IJobList; + +class JobList implements IJobList { + /** + * @var \OCP\IDBConnection + */ + private $conn; + + /** + * @var \OCP\IConfig $config + */ + private $config; + + /** + * @param \OCP\IDBConnection $conn + * @param \OCP\IConfig $config + */ + public function __construct($conn, $config) { + $this->conn = $conn; + $this->config = $config; + } + /** * @param Job|string $job * @param mixed $argument @@ -28,7 +42,7 @@ class JobList { $class = $job; } $argument = json_encode($argument); - $query = \OC_DB::prepare('INSERT INTO `*PREFIX*jobs`(`class`, `argument`, `last_run`) VALUES(?, ?, 0)'); + $query = $this->conn->prepare('INSERT INTO `*PREFIX*jobs`(`class`, `argument`, `last_run`) VALUES(?, ?, 0)'); $query->execute(array($class, $argument)); } } @@ -45,10 +59,10 @@ class JobList { } if (!is_null($argument)) { $argument = json_encode($argument); - $query = \OC_DB::prepare('DELETE FROM `*PREFIX*jobs` WHERE `class` = ? AND `argument` = ?'); + $query = $this->conn->prepare('DELETE FROM `*PREFIX*jobs` WHERE `class` = ? AND `argument` = ?'); $query->execute(array($class, $argument)); } else { - $query = \OC_DB::prepare('DELETE FROM `*PREFIX*jobs` WHERE `class` = ?'); + $query = $this->conn->prepare('DELETE FROM `*PREFIX*jobs` WHERE `class` = ?'); $query->execute(array($class)); } } @@ -67,9 +81,9 @@ class JobList { $class = $job; } $argument = json_encode($argument); - $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*jobs` WHERE `class` = ? AND `argument` = ?'); - $result = $query->execute(array($class, $argument)); - return (bool)$result->fetchRow(); + $query = $this->conn->prepare('SELECT `id` FROM `*PREFIX*jobs` WHERE `class` = ? AND `argument` = ?'); + $query->execute(array($class, $argument)); + return (bool)$query->fetch(); } /** @@ -78,10 +92,10 @@ class JobList { * @return Job[] */ public function getAll() { - $query = \OC_DB::prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs`'); - $result = $query->execute(); + $query = $this->conn->prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs`'); + $query->execute(); $jobs = array(); - while ($row = $result->fetchRow()) { + while ($row = $query->fetch()) { $jobs[] = $this->buildJob($row); } return $jobs; @@ -94,15 +108,15 @@ class JobList { */ public function getNext() { $lastId = $this->getLastJob(); - $query = \OC_DB::prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs` WHERE `id` > ? ORDER BY `id` ASC', 1); - $result = $query->execute(array($lastId)); - if ($row = $result->fetchRow()) { + $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()) { return $this->buildJob($row); } else { //begin at the start of the queue - $query = \OC_DB::prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs` ORDER BY `id` ASC', 1); - $result = $query->execute(); - if ($row = $result->fetchRow()) { + $query = $this->conn->prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs` ORDER BY `id` ASC', 1); + $query->execute(); + if ($row = $query->fetch()) { return $this->buildJob($row); } else { return null; //empty job list @@ -115,9 +129,9 @@ class JobList { * @return Job */ public function getById($id) { - $query = \OC_DB::prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs` WHERE `id` = ?'); - $result = $query->execute(array($id)); - if ($row = $result->fetchRow()) { + $query = $this->conn->prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs` WHERE `id` = ?'); + $query->execute(array($id)); + if ($row = $query->fetch()) { return $this->buildJob($row); } else { return null; @@ -148,7 +162,7 @@ class JobList { * @param Job $job */ public function setLastJob($job) { - \OC_Appconfig::setValue('backgroundjob', 'lastjob', $job->getId()); + $this->config->setAppValue('backgroundjob', 'lastjob', $job->getId()); } /** @@ -157,7 +171,7 @@ class JobList { * @return int */ public function getLastJob() { - return \OC_Appconfig::getValue('backgroundjob', 'lastjob', 0); + return $this->config->getAppValue('backgroundjob', 'lastjob', 0); } /** @@ -166,7 +180,7 @@ class JobList { * @param Job $job */ public function setLastRun($job) { - $query = \OC_DB::prepare('UPDATE `*PREFIX*jobs` SET `last_run` = ? WHERE `id` = ?'); + $query = $this->conn->prepare('UPDATE `*PREFIX*jobs` SET `last_run` = ? WHERE `id` = ?'); $query->execute(array(time(), $job->getId())); } } diff --git a/lib/private/db/statementwrapper.php b/lib/private/db/statementwrapper.php index 5e89261d936..a71df315e2f 100644 --- a/lib/private/db/statementwrapper.php +++ b/lib/private/db/statementwrapper.php @@ -31,6 +31,9 @@ class OC_DB_StatementWrapper { /** * make execute return the result instead of a bool + * + * @param array $input + * @return \OC_DB_StatementWrapper | int */ public function execute($input=array()) { if(OC_Config::getValue( "log_query", false)) { diff --git a/lib/private/files.php b/lib/private/files.php index 8ce632013cf..24fca4a5df3 100644 --- a/lib/private/files.php +++ b/lib/private/files.php @@ -131,7 +131,7 @@ class OC_Files { } if ($xsendfile) { list($storage) = \OC\Files\Filesystem::resolvePath(\OC\Files\Filesystem::getView()->getAbsolutePath($filename)); - if ($storage instanceof \OC\Files\Storage\Local) { + if ($storage->isLocal()) { self::addSendfileHeader(\OC\Files\Filesystem::getLocalFile($filename)); } } diff --git a/lib/private/files/fileinfo.php b/lib/private/files/fileinfo.php new file mode 100644 index 00000000000..c77571cd2a7 --- /dev/null +++ b/lib/private/files/fileinfo.php @@ -0,0 +1,185 @@ +<?php +/** + * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Files; + +class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess { + /** + * @var array $data + */ + private $data; + + /** + * @var string $path + */ + private $path; + + /** + * @var \OC\Files\Storage\Storage $storage + */ + private $storage; + + /** + * @var string $internalPath + */ + private $internalPath; + + public function __construct($path, $storage, $internalPath, $data) { + $this->path = $path; + $this->storage = $storage; + $this->internalPath = $internalPath; + $this->data = $data; + } + + public function offsetSet($offset, $value) { + $this->data[$offset] = $value; + } + + public function offsetExists($offset) { + return isset($this->data[$offset]); + } + + public function offsetUnset($offset) { + unset($this->data[$offset]); + } + + public function offsetGet($offset) { + return $this->data[$offset]; + } + + /** + * @return string + */ + public function getPath() { + return $this->path; + } + + /** + * @return \OCP\Files\Storage + */ + public function getStorage() { + return $this->storage; + } + + /** + * @return string + */ + public function getInternalPath() { + return $this->internalPath; + } + + /** + * @return int + */ + public function getId() { + return $this->data['fileid']; + } + + /** + * @return string + */ + public function getMimetype() { + return $this->data['mimetype']; + } + + /** + * @return string + */ + public function getMimePart() { + return $this->data['mimepart']; + } + + /** + * @return string + */ + public function getName() { + return $this->data['name']; + } + + /** + * @return string + */ + public function getEtag() { + return $this->data['etag']; + } + + /** + * @return int + */ + public function getSize() { + return $this->data['size']; + } + + /** + * @return int + */ + public function getMTime() { + return $this->data['mtime']; + } + + /** + * @return bool + */ + public function isEncrypted() { + return $this->data['encrypted']; + } + + /** + * @return int + */ + public function getPermissions() { + return $this->data['permissions']; + } + + /** + * @return \OCP\Files\FileInfo::TYPE_FILE | \OCP\Files\FileInfo::TYPE_FOLDER + */ + public function getType() { + return $this->data['type']; + } + + public function getData(){ + return $this->data; + } + + /** + * @param int $permissions + * @return bool + */ + protected function checkPermissions($permissions) { + return ($this->getPermissions() & $permissions) === $permissions; + } + + /** + * @return bool + */ + public function isReadable() { + return $this->checkPermissions(\OCP\PERMISSION_READ); + } + + /** + * @return bool + */ + public function isUpdateable() { + return $this->checkPermissions(\OCP\PERMISSION_UPDATE); + } + + /** + * @return bool + */ + public function isDeletable() { + return $this->checkPermissions(\OCP\PERMISSION_DELETE); + } + + /** + * @return bool + */ + public function isShareable() { + return $this->checkPermissions(\OCP\PERMISSION_SHARE); + } +} diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php index 678bf419023..55b1471593d 100644 --- a/lib/private/files/storage/common.php +++ b/lib/private/files/storage/common.php @@ -370,4 +370,13 @@ abstract class Common implements \OC\Files\Storage\Storage { public function free_space($path) { return \OC\Files\SPACE_UNKNOWN; } + + /** + * {@inheritdoc} + */ + public function isLocal() { + // the common implementation returns a temporary file by + // default, which is not local + return false; + } } diff --git a/lib/private/files/storage/local.php b/lib/private/files/storage/local.php index db3c6bfca3a..fa0788f2377 100644 --- a/lib/private/files/storage/local.php +++ b/lib/private/files/storage/local.php @@ -298,5 +298,12 @@ if (\OC_Util::runningOnWindows()) { public function hasUpdated($path, $time) { return $this->filemtime($path) > $time; } + + /** + * {@inheritdoc} + */ + public function isLocal() { + return true; + } } } diff --git a/lib/private/files/storage/wrapper/wrapper.php b/lib/private/files/storage/wrapper/wrapper.php index f9adda80314..11ea9f71da7 100644 --- a/lib/private/files/storage/wrapper/wrapper.php +++ b/lib/private/files/storage/wrapper/wrapper.php @@ -432,4 +432,12 @@ class Wrapper implements \OC\Files\Storage\Storage { public function test() { return $this->storage->test(); } + + /** + * Returns the wrapped storage's value for isLocal() + * @return bool wrapped storage's isLocal() value + */ + public function isLocal() { + return $this->storage->isLocal(); + } } diff --git a/lib/private/files/view.php b/lib/private/files/view.php index d97544b865e..6fc534757b2 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -781,14 +781,7 @@ class View { * @param string $path * @param boolean $includeMountPoints whether to add mountpoint sizes, * defaults to true - * @return array - * - * returns an associative array with the following keys: - * - size - * - mtime - * - mimetype - * - encrypted - * - versioned + * @return \OC\Files\FileInfo | false */ public function getFileInfo($path, $includeMountPoints = true) { $data = array(); @@ -841,10 +834,13 @@ class View { $data['permissions'] = $permissions; } } + if (!$data) { + return false; + } $data = \OC_FileProxy::runPostProxies('getFileInfo', $path, $data); - return $data; + return new FileInfo($path, $storage, $internalPath, $data); } /** @@ -852,7 +848,7 @@ class View { * * @param string $directory path under datadirectory * @param string $mimetype_filter limit returned content to this mimetype or mimepart - * @return array + * @return FileInfo[] */ public function getDirectoryContent($directory, $mimetype_filter = '') { $result = array(); @@ -878,7 +874,11 @@ class View { $watcher->checkUpdate($internalPath); } - $files = $cache->getFolderContents($internalPath); //TODO: mimetype_filter + $files = array(); + $contents = $cache->getFolderContents($internalPath); //TODO: mimetype_filter + foreach ($contents as $content) { + $files[] = new FileInfo($path . '/' . $content['name'], $storage, $content['path'], $content); + } $permissions = $permissionsCache->getDirectoryPermissions($cache->getId($internalPath), $user); $ids = array(); @@ -936,7 +936,7 @@ class View { break; } } - $files[] = $rootEntry; + $files[] = new FileInfo($path . '/' . $rootEntry['name'], $subStorage, '', $rootEntry); } } } @@ -958,6 +958,7 @@ class View { $result = $files; } } + return $result; } @@ -965,12 +966,15 @@ class View { * change file metadata * * @param string $path - * @param array $data + * @param array | \OCP\Files\FileInfo $data * @return int * * returns the fileid of the updated file */ public function putFileInfo($path, $data) { + if ($data instanceof FileInfo) { + $data = $data->getData(); + } $path = Filesystem::normalizePath($this->fakeRoot . '/' . $path); /** * @var \OC\Files\Storage\Storage $storage @@ -995,7 +999,7 @@ class View { * search for files with the name matching $query * * @param string $query - * @return array + * @return FileInfo[] */ public function search($query) { return $this->searchCommon('%' . $query . '%', 'search'); @@ -1005,7 +1009,7 @@ class View { * search for files by mimetype * * @param string $mimetype - * @return array + * @return FileInfo[] */ public function searchByMime($mimetype) { return $this->searchCommon($mimetype, 'searchByMime'); @@ -1014,7 +1018,7 @@ class View { /** * @param string $query * @param string $method - * @return array + * @return FileInfo[] */ private function searchCommon($query, $method) { $files = array(); @@ -1028,8 +1032,9 @@ class View { $results = $cache->$method($query); foreach ($results as $result) { if (substr($mountPoint . $result['path'], 0, $rootLength + 1) === $this->fakeRoot . '/') { + $internalPath = $result['path']; $result['path'] = substr($mountPoint . $result['path'], $rootLength); - $files[] = $result; + $files[] = new FileInfo($mountPoint . $result['path'], $storage, $internalPath, $result); } } @@ -1043,8 +1048,9 @@ class View { $results = $cache->$method($query); if ($results) { foreach ($results as $result) { + $internalPath = $result['path']; $result['path'] = $relativeMountPoint . $result['path']; - $files[] = $result; + $files[] = new FileInfo($mountPoint . $result['path'], $storage, $internalPath, $result); } } } diff --git a/lib/private/group/manager.php b/lib/private/group/manager.php index bf469d51d12..9b433b64fd4 100644 --- a/lib/private/group/manager.php +++ b/lib/private/group/manager.php @@ -76,12 +76,7 @@ class Manager extends PublicEmitter { if (isset($this->cachedGroups[$gid])) { return $this->cachedGroups[$gid]; } - foreach ($this->backends as $backend) { - if ($backend->groupExists($gid)) { - return $this->getGroupObject($gid); - } - } - return null; + return $this->getGroupObject($gid); } protected function getGroupObject($gid) { @@ -91,6 +86,9 @@ class Manager extends PublicEmitter { $backends[] = $backend; } } + if (count($backends) === 0) { + return null; + } $this->cachedGroups[$gid] = new Group($gid, $backends, $this->userManager, $this); return $this->cachedGroups[$gid]; } @@ -110,8 +108,8 @@ class Manager extends PublicEmitter { public function createGroup($gid) { if (!$gid) { return false; - } else if ($this->groupExists($gid)) { - return $this->get($gid); + } else if ($group = $this->get($gid)) { + return $group; } else { $this->emit('\OC\Group', 'preCreate', array($gid)); foreach ($this->backends as $backend) { diff --git a/lib/private/helper.php b/lib/private/helper.php index 580f81acc62..58cb1b88d66 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -804,18 +804,22 @@ class OC_Helper { /** * @brief calculates the maximum upload size respecting system settings, free space and user quota * - * @param $dir the current folder where the user currently operates - * @return number of bytes representing + * @param string $dir the current folder where the user currently operates + * @param int $freeSpace the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly + * @return int number of bytes representing */ - public static function maxUploadFilesize($dir) { - return min(self::freeSpace($dir), self::uploadLimit()); + public static function maxUploadFilesize($dir, $freeSpace = null) { + if (is_null($freeSpace)){ + $freeSpace = self::freeSpace($dir); + } + return min($freeSpace, self::uploadLimit()); } /** * Calculate free space left within user quota * - * @param $dir the current folder where the user currently operates - * @return number of bytes representing + * @param string $dir the current folder where the user currently operates + * @return int number of bytes representing */ public static function freeSpace($dir) { $freeSpace = \OC\Files\Filesystem::free_space($dir); diff --git a/lib/private/legacy/appconfig.php b/lib/private/legacy/appconfig.php new file mode 100644 index 00000000000..46a8068c3b4 --- /dev/null +++ b/lib/private/legacy/appconfig.php @@ -0,0 +1,126 @@ +<?php +/** + * ownCloud + * + * @author Frank Karlitschek + * @author Jakob Sack + * @copyright 2012 Frank Karlitschek frank@owncloud.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library 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 along with this library. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/** + * This class provides an easy way for apps to store config values in the + * database. + */ +class OC_Appconfig { + /** + * @return \OCP\IAppConfig + */ + private static function getAppConfig() { + return \OC::$server->getAppConfig(); + } + + /** + * @brief Get all apps using the config + * @return array with app ids + * + * This function returns a list of all apps that have at least one + * entry in the appconfig table. + */ + public static function getApps() { + return self::getAppConfig()->getApps(); + } + + /** + * @brief Get the available keys for an app + * @param string $app the app we are looking for + * @return array with key names + * + * This function gets all keys of an app. Please note that the values are + * not returned. + */ + public static function getKeys($app) { + return self::getAppConfig()->getKeys($app); + } + + /** + * @brief Gets the config value + * @param string $app app + * @param string $key key + * @param string $default = null, default value if the key does not exist + * @return string the value or $default + * + * This function gets a value from the appconfig table. If the key does + * not exist the default value will be returned + */ + public static function getValue($app, $key, $default = null) { + return self::getAppConfig()->getValue($app, $key, $default); + } + + /** + * @brief check if a key is set in the appconfig + * @param string $app + * @param string $key + * @return bool + */ + public static function hasKey($app, $key) { + return self::getAppConfig()->hasKey($app, $key); + } + + /** + * @brief sets a value in the appconfig + * @param string $app app + * @param string $key key + * @param string $value value + * + * Sets a value. If the key did not exist before it will be created. + */ + public static function setValue($app, $key, $value) { + self::getAppConfig()->setValue($app, $key, $value); + } + + /** + * @brief Deletes a key + * @param string $app app + * @param string $key key + * + * Deletes a key. + */ + public static function deleteKey($app, $key) { + self::getAppConfig()->deleteKey($app, $key); + } + + /** + * @brief Remove app from appconfig + * @param string $app app + * + * Removes all keys in appconfig belonging to the app. + */ + public static function deleteApp($app) { + self::getAppConfig()->deleteApp($app); + } + + /** + * get multiply values, either the app or key can be used as wildcard by setting it to false + * + * @param app + * @param key + * @return array + */ + public static function getValues($app, $key) { + return self::getAppConfig()->getValues($app, $key); + } +} diff --git a/lib/private/preview/office.php b/lib/private/preview/office.php index 884b6e7dc9b..02bb22e9b94 100644 --- a/lib/private/preview/office.php +++ b/lib/private/preview/office.php @@ -6,7 +6,7 @@ * See the COPYING-README file. */ //both, libreoffice backend and php fallback, need imagick -if (extension_loaded('imagick') && count(\Imagick::queryFormats("PDF")) === 1) { +if (extension_loaded('imagick') && count(@\Imagick::queryFormats("PDF")) === 1) { $isShellExecEnabled = \OC_Helper::is_function_enabled('shell_exec'); // LibreOffice preview is currently not supported on Windows diff --git a/lib/private/preview/pdf.php b/lib/private/preview/pdf.php index 572b8788ac9..d390b4fc677 100644 --- a/lib/private/preview/pdf.php +++ b/lib/private/preview/pdf.php @@ -7,7 +7,7 @@ */ namespace OC\Preview; -if (extension_loaded('imagick') && count(\Imagick::queryFormats("PDF")) === 1) { +if (extension_loaded('imagick') && count(@\Imagick::queryFormats("PDF")) === 1) { class PDF extends Provider { diff --git a/lib/private/preview/svg.php b/lib/private/preview/svg.php index 07a37e8f8c1..9a73fff9467 100644 --- a/lib/private/preview/svg.php +++ b/lib/private/preview/svg.php @@ -7,7 +7,7 @@ */ namespace OC\Preview; -if (extension_loaded('imagick') && count(\Imagick::queryFormats("SVG")) === 1) { +if (extension_loaded('imagick') && count(@\Imagick::queryFormats("SVG")) === 1) { class SVG extends Provider { diff --git a/lib/private/preview/unknown.php b/lib/private/preview/unknown.php index 8145c826149..2d3b5c5655e 100644 --- a/lib/private/preview/unknown.php +++ b/lib/private/preview/unknown.php @@ -22,7 +22,7 @@ class Unknown extends Provider { $svgPath = substr_replace($path, 'svg', -3); - if (extension_loaded('imagick') && file_exists($svgPath) && count(\Imagick::queryFormats("SVG")) === 1) { + if (extension_loaded('imagick') && file_exists($svgPath) && count(@\Imagick::queryFormats("SVG")) === 1) { // http://www.php.net/manual/de/imagick.setresolution.php#85284 $svg = new \Imagick(); diff --git a/lib/private/server.php b/lib/private/server.php index c9e593ec2ed..7696fc207fd 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -124,6 +124,9 @@ class Server extends SimpleContainer implements IServerContainer { $this->registerService('AllConfig', function($c) { return new \OC\AllConfig(); }); + $this->registerService('AppConfig', function ($c) { + return new \OC\AppConfig(\OC_DB::getConnection()); + }); $this->registerService('L10NFactory', function($c) { return new \OC\L10N\Factory(); }); @@ -148,6 +151,13 @@ class Server extends SimpleContainer implements IServerContainer { $this->registerService('AvatarManager', function($c) { return new AvatarManager(); }); + $this->registerService('JobList', function ($c) { + /** + * @var Server $c + */ + $config = $c->getConfig(); + return new \OC\BackgroundJob\JobList($c->getDatabaseConnection(), $config); + }); } /** @@ -270,6 +280,15 @@ class Server extends SimpleContainer implements IServerContainer { } /** + * Returns the app config manager + * + * @return \OCP\IAppConfig + */ + function getAppConfig(){ + return $this->query('AppConfig'); + } + + /** * get an L10N instance * @param $app string appid * @return \OC_L10N @@ -336,4 +355,13 @@ class Server extends SimpleContainer implements IServerContainer { function getActivityManager() { return $this->query('ActivityManager'); } + + /** + * Returns an job list for controlling background jobs + * + * @return \OCP\BackgroundJob\IJobList + */ + function getJobList(){ + return $this->query('JobList'); + } } diff --git a/lib/private/share/searchresultsorter.php b/lib/private/share/searchresultsorter.php new file mode 100644 index 00000000000..fbf77179097 --- /dev/null +++ b/lib/private/share/searchresultsorter.php @@ -0,0 +1,59 @@ +<?php +/** + * Copyright (c) 2014 Arthur Schiwon <blizzz@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + * + */ +namespace OC\Share; + +class SearchResultSorter { + private $search; + private $encoding; + private $key; + private $log; + + /** + * @param $search the search term as was given by the user + * @param $key the array key containing the value that should be compared + * against + * @param $encoding optional, encoding to use, defaults to UTF-8 + * @param $log optional, an \OC\Log instance + */ + public function __construct($search, $key, \OC\Log $log = null, $encoding = 'UTF-8') { + $this->encoding = $encoding; + $this->key = $key; + $this->log = $log; + $this->search = mb_strtolower($search, $this->encoding); + } + + /** + * User and Group names matching the search term at the beginning shall appear + * on top of the share dialog. Following entries in alphabetical order. + * Callback function for usort. http://php.net/usort + */ + public function sort($a, $b) { + if(!isset($a[$this->key]) || !isset($b[$this->key])) { + if(!is_null($this->log)) { + $this->log->error('Sharing dialogue: cannot sort due to ' . + 'missing array key', array('app' => 'core')); + } + return 0; + } + $nameA = mb_strtolower($a[$this->key], $this->encoding); + $nameB = mb_strtolower($b[$this->key], $this->encoding); + $i = mb_strpos($nameA, $this->search, 0, $this->encoding); + $j = mb_strpos($nameB, $this->search, 0, $this->encoding); + + if($i === $j || $i > 0 && $j > 0) { + return strcmp(mb_strtolower($nameA, $this->encoding), + mb_strtolower($nameB, $this->encoding)); + } elseif ($i === 0) { + return -1; + } else { + return 1; + } + } +} + |