From b35b22977cfc9412278ae70b49c402a95efca19e Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Wed, 2 Oct 2013 09:15:31 +0200 Subject: Move legacy file to correct location --- lib/private/legacy/appconfig.php | 120 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 lib/private/legacy/appconfig.php (limited to 'lib/private') diff --git a/lib/private/legacy/appconfig.php b/lib/private/legacy/appconfig.php new file mode 100644 index 00000000000..0ca6d4150ef --- /dev/null +++ b/lib/private/legacy/appconfig.php @@ -0,0 +1,120 @@ +. + * + */ + +/** + * This class provides an easy way for apps to store config values in the + * database. + */ +OC_Appconfig::$object = new \OC\AppConfig(OC_DB::getConnection()); +class OC_Appconfig{ + public static $object; + /** + * @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::$object->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::$object->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::$object->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::$object->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::$object->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::$object->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::$object->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::$object->getValues($app, $key); + } +} -- cgit v1.2.3 From 617acbd6f9e93254c31987639cc4915dceb7c4c0 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 13 Jan 2014 14:28:49 +0100 Subject: Add a FileInfo class which holds all info of a file and return that from getFileInfo, getDirectoryContent and search --- lib/private/files/fileinfo.php | 149 +++++++++++++++++++++++++++++++++++++++++ lib/private/files/view.php | 37 +++++----- lib/public/files/fileinfo.php | 87 ++++++++++++++++++++++++ lib/public/util.php | 2 +- 4 files changed, 257 insertions(+), 18 deletions(-) create mode 100644 lib/private/files/fileinfo.php create mode 100644 lib/public/files/fileinfo.php (limited to 'lib/private') diff --git a/lib/private/files/fileinfo.php b/lib/private/files/fileinfo.php new file mode 100644 index 00000000000..24d99627aaf --- /dev/null +++ b/lib/private/files/fileinfo.php @@ -0,0 +1,149 @@ + + * 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 { + /** + * @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]; + } + + public function jsonSerialize() { + return $this->data; + } + + /** + * @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']; + } +} diff --git a/lib/private/files/view.php b/lib/private/files/view.php index 8893911ed5d..39c2ffed93d 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(); @@ -838,10 +831,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); } /** @@ -849,7 +845,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(); @@ -875,7 +871,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(); @@ -933,7 +933,7 @@ class View { break; } } - $files[] = $rootEntry; + $files[] = new FileInfo($path . '/' . $rootEntry['name'], $subStorage, '', $rootEntry); } } } @@ -955,6 +955,7 @@ class View { $result = $files; } } + return $result; } @@ -992,7 +993,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'); @@ -1002,7 +1003,7 @@ class View { * search for files by mimetype * * @param string $mimetype - * @return array + * @return FileInfo[] */ public function searchByMime($mimetype) { return $this->searchCommon($mimetype, 'searchByMime'); @@ -1011,7 +1012,7 @@ class View { /** * @param string $query * @param string $method - * @return array + * @return FileInfo[] */ private function searchCommon($query, $method) { $files = array(); @@ -1025,8 +1026,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); } } @@ -1040,8 +1042,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/public/files/fileinfo.php b/lib/public/files/fileinfo.php new file mode 100644 index 00000000000..a11378c2ee5 --- /dev/null +++ b/lib/public/files/fileinfo.php @@ -0,0 +1,87 @@ + Date: Mon, 13 Jan 2014 15:13:45 +0100 Subject: remove ArrayAccess, JsonSerializable from the public part of FileInfo --- lib/private/files/fileinfo.php | 4 ++-- lib/public/files/fileinfo.php | 20 +++++--------------- 2 files changed, 7 insertions(+), 17 deletions(-) (limited to 'lib/private') diff --git a/lib/private/files/fileinfo.php b/lib/private/files/fileinfo.php index 24d99627aaf..8e9b6a8b72c 100644 --- a/lib/private/files/fileinfo.php +++ b/lib/private/files/fileinfo.php @@ -1,6 +1,6 @@ + * Copyright (c) 2014 Robin Appelman * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. @@ -8,7 +8,7 @@ namespace OC\Files; -class FileInfo implements \OCP\Files\FileInfo { +class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess, \JsonSerializable { /** * @var array $data */ diff --git a/lib/public/files/fileinfo.php b/lib/public/files/fileinfo.php index 09c194fe96d..cbe216023da 100644 --- a/lib/public/files/fileinfo.php +++ b/lib/public/files/fileinfo.php @@ -1,26 +1,16 @@ + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. */ namespace OCP\Files; -interface FileInfo extends \ArrayAccess, \JsonSerializable { +interface FileInfo { const TYPE_FILE = 'file'; const TYPE_FOLDER = 'folder'; - public function offsetSet($offset, $value); - - public function offsetGet($offset); - - public function offsetUnset($offset); - - public function offsetExists($offset); - - public function jsonSerialize(); - /** * Get the Etag of the file or folder * -- cgit v1.2.3 From e706cf6c06a0111f9ec5db65e46f0fcc9261b456 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 13 Jan 2014 15:57:49 +0100 Subject: add Support for passing a FileInfo instance to View->putFileInfo --- lib/private/files/fileinfo.php | 4 ++++ lib/private/files/view.php | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'lib/private') diff --git a/lib/private/files/fileinfo.php b/lib/private/files/fileinfo.php index 8e9b6a8b72c..b80873d1d00 100644 --- a/lib/private/files/fileinfo.php +++ b/lib/private/files/fileinfo.php @@ -146,4 +146,8 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess, \JsonSerializable { public function getType() { return $this->data['type']; } + + public function getData(){ + return $this->data; + } } diff --git a/lib/private/files/view.php b/lib/private/files/view.php index 39c2ffed93d..b5870279664 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -963,12 +963,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 -- cgit v1.2.3 From fc5f20112efe03b203978c4b1045ed70c2ce5e74 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 24 Jan 2014 15:54:40 +0100 Subject: Add isReadable, isUpdateable, isDeletable, isShareable --- lib/private/files/fileinfo.php | 38 +++++++++++++++++++++++++++++++++++++- lib/public/files/fileinfo.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) (limited to 'lib/private') diff --git a/lib/private/files/fileinfo.php b/lib/private/files/fileinfo.php index b80873d1d00..7edea13df96 100644 --- a/lib/private/files/fileinfo.php +++ b/lib/private/files/fileinfo.php @@ -122,7 +122,7 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess, \JsonSerializable { /** * @return int */ - public function getMtime() { + public function getMTime() { return $this->data['mtime']; } @@ -150,4 +150,40 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess, \JsonSerializable { 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/public/files/fileinfo.php b/lib/public/files/fileinfo.php index cbe216023da..68ce45d3fa1 100644 --- a/lib/public/files/fileinfo.php +++ b/lib/public/files/fileinfo.php @@ -107,4 +107,32 @@ interface FileInfo { * @return \OCP\Files\FileInfo::TYPE_FILE | \OCP\Files\FileInfo::TYPE_FOLDER */ public function getType(); + + /** + * Check if the file or folder is readable + * + * @return bool + */ + public function isReadable(); + + /** + * Check if a file is writable + * + * @return bool + */ + public function isUpdateable(); + + /** + * Check if a file or folder can be deleted + * + * @return bool + */ + public function isDeletable(); + + /** + * Check if a file or folder can be shared + * + * @return bool + */ + public function isShareable(); } -- cgit v1.2.3 From 3c1ab66edac1ba2f1b398c859cd933c410ea3d8d Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 27 Jan 2014 15:56:57 +0100 Subject: Reuse the calculated free_space in buildFileStorageStatistics --- apps/files/lib/helper.php | 8 ++++---- lib/private/helper.php | 9 ++++++--- lib/public/util.php | 7 ++++--- 3 files changed, 14 insertions(+), 10 deletions(-) (limited to 'lib/private') diff --git a/apps/files/lib/helper.php b/apps/files/lib/helper.php index eaff28178ea..87939d26921 100644 --- a/apps/files/lib/helper.php +++ b/apps/files/lib/helper.php @@ -5,14 +5,14 @@ namespace OCA\Files; class Helper { public static function buildFileStorageStatistics($dir) { + // information about storage capacities + $storageInfo = \OC_Helper::getStorageInfo($dir); + $l = new \OC_L10N('files'); - $maxUploadFilesize = \OCP\Util::maxUploadFilesize($dir); + $maxUploadFilesize = \OCP\Util::maxUploadFilesize($dir, $storageInfo['free']); $maxHumanFilesize = \OCP\Util::humanFileSize($maxUploadFilesize); $maxHumanFilesize = $l->t('Upload') . ' max. ' . $maxHumanFilesize; - // information about storage capacities - $storageInfo = \OC_Helper::getStorageInfo($dir); - return array('uploadMaxFilesize' => $maxUploadFilesize, 'maxHumanFilesize' => $maxHumanFilesize, 'usedSpacePercent' => (int)$storageInfo['relative']); diff --git a/lib/private/helper.php b/lib/private/helper.php index 1c8d01c141f..12784c9a5eb 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -824,13 +824,16 @@ 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 + * @param string $dir the current folder where the user currently operates + * @param int $free the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly * @return number of bytes representing */ - public static function maxUploadFilesize($dir) { + public static function maxUploadFilesize($dir, $freeSpace = null) { $upload_max_filesize = OCP\Util::computerFileSize(ini_get('upload_max_filesize')); $post_max_size = OCP\Util::computerFileSize(ini_get('post_max_size')); - $freeSpace = \OC\Files\Filesystem::free_space($dir); + if (is_null($freeSpace)) { + $freeSpace = \OC\Files\Filesystem::free_space($dir); + } if ((int)$upload_max_filesize === 0 and (int)$post_max_size === 0) { $maxUploadFilesize = \OC\Files\SPACE_UNLIMITED; } elseif ((int)$upload_max_filesize === 0 or (int)$post_max_size === 0) { diff --git a/lib/public/util.php b/lib/public/util.php index 6317f10a66f..52874bcc954 100644 --- a/lib/public/util.php +++ b/lib/public/util.php @@ -456,10 +456,11 @@ class Util { /** * calculates the maximum upload size respecting system settings, free space and user quota * - * @param $dir the current folder where the user currently operates + * @param string $dir the current folder where the user currently operates + * @param int $free the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly * @return number of bytes representing */ - public static function maxUploadFilesize($dir) { - return \OC_Helper::maxUploadFilesize($dir); + public static function maxUploadFilesize($dir, $free = null) { + return \OC_Helper::maxUploadFilesize($dir, $free); } } -- cgit v1.2.3 From 788c8540aa6aac50795c37b088eeaa561d44b86c Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Tue, 4 Feb 2014 19:58:49 +0100 Subject: Added isLocal() method to storage, used for xsendfile Added isLocal() method to Storage to find out whether the storage is local or not. This method is used for the x-sendfile logic to find out whether to add the headers. --- lib/private/files.php | 2 +- lib/private/files/storage/common.php | 9 +++++++++ lib/private/files/storage/local.php | 7 +++++++ lib/private/files/storage/wrapper/wrapper.php | 8 ++++++++ lib/public/files/storage.php | 11 +++++++++++ 5 files changed, 36 insertions(+), 1 deletion(-) (limited to 'lib/private') 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/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/public/files/storage.php b/lib/public/files/storage.php index 194b42a6481..fe30f8f50af 100644 --- a/lib/public/files/storage.php +++ b/lib/public/files/storage.php @@ -315,4 +315,15 @@ interface Storage { * @return string */ public function getETag($path); + + /** + * Returns whether the storage is local, which means that files + * are stored on the local filesystem instead of remotely. + * Calling getLocalFile() for local storages should always + * return the local files, whereas for non-local storages + * it might return a temporary file. + * + * @return bool true if the files are stored locally, false otherwise + */ + public function isLocal(); } -- cgit v1.2.3 From cd3ef0bb9d6585dcc07e7ca62285032245283106 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 7 Feb 2014 14:03:39 +0100 Subject: Add caching to appconfig --- lib/private/appconfig.php | 61 +++++++++++++++++++++++++++---------- lib/private/db/statementwrapper.php | 3 ++ 2 files changed, 48 insertions(+), 16 deletions(-) (limited to 'lib/private') diff --git a/lib/private/appconfig.php b/lib/private/appconfig.php index ff47f08d485..71aa8307316 100644 --- a/lib/private/appconfig.php +++ b/lib/private/appconfig.php @@ -47,6 +47,10 @@ class AppConfig implements \OCP\IAppConfig { */ protected $conn; + private $cache = array(); + + private $appsLoaded = array(); + /** * @param \OC\DB\Connection $conn */ @@ -54,6 +58,32 @@ class AppConfig implements \OCP\IAppConfig { $this->conn = $conn; } + /** + * @param string $app + * @return string[] + */ + private function getAppCache($app) { + if (!isset($this->cache[$app])) { + $this->cache[$app] = array(); + } + return $this->cache[$app]; + } + + 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 * @return array with app ids @@ -81,15 +111,8 @@ class AppConfig implements \OCP\IAppConfig { * not returned. */ public function getKeys($app) { - $query = 'SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?'; - $result = $this->conn->executeQuery($query, array($app)); - - $keys = array(); - while ($key = $result->fetchColumn()) { - $keys[] = $key; - } - - return $keys; + $values = $this->getAppValues($app); + return array_keys($values); } /** @@ -103,11 +126,9 @@ class AppConfig implements \OCP\IAppConfig { * not exist the default value will be returned */ public function getValue($app, $key, $default = null) { - $query = 'SELECT `configvalue` FROM `*PREFIX*appconfig`' - . ' WHERE `appid` = ? AND `configkey` = ?'; - $row = $this->conn->fetchAssoc($query, array($app, $key)); - if ($row) { - return $row['configvalue']; + $values = $this->getAppValues($app); + if (isset($values[$key])) { + return $values[$key]; } else { return $default; } @@ -120,8 +141,8 @@ class AppConfig implements \OCP\IAppConfig { * @return bool */ public function hasKey($app, $key) { - $exists = $this->getKeys($app); - return in_array($key, $exists); + $values = $this->getAppValues($app); + return isset($values[$key]); } /** @@ -151,6 +172,10 @@ class AppConfig implements \OCP\IAppConfig { ); $this->conn->update('*PREFIX*appconfig', $data, $where); } + if (!isset($this->cache[$app])) { + $this->cache[$app] = array(); + } + $this->cache[$app][$key] = $value; } /** @@ -167,6 +192,9 @@ class AppConfig implements \OCP\IAppConfig { 'configkey' => $key, ); $this->conn->delete('*PREFIX*appconfig', $where); + if (isset($this->cache[$app]) and isset($this->cache[$app][$key])) { + unset($this->cache[$app][$key]); + } } /** @@ -181,6 +209,7 @@ class AppConfig implements \OCP\IAppConfig { 'appid' => $app, ); $this->conn->delete('*PREFIX*appconfig', $where); + unset($this->cache[$app]); } /** 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)) { -- cgit v1.2.3 From 41e8d44cf7261e05a40842ab56d4d4c3f61cf083 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 15 Jan 2014 17:55:05 +0100 Subject: move sorter into a class --- core/ajax/share.php | 27 ++-------------- lib/private/share/searchresultsorter.php | 53 ++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 24 deletions(-) create mode 100644 lib/private/share/searchresultsorter.php (limited to 'lib/private') diff --git a/core/ajax/share.php b/core/ajax/share.php index 5c2dbc6654d..21e320a4732 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -354,32 +354,11 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo break; } } - usort($shareWith, 'sortSearchFirst'); + $sorter = new \OC\Share\SearchResultSorter($_GET['search'], + 'label'); + usort($shareWith, array($sorter, 'sort')); OC_JSON::success(array('data' => $shareWith)); } break; } } - - -/** - * User and Group names matching the search term at the beginning shall appear - * on top of the share dialog. - * Callback function for usort. http://php.net/usort - */ -function sortSearchFirst($a, $b) { - $enc = 'UTF-8'; - $nameA = mb_strtolower($a['label'], $enc); - $nameB = mb_strtolower($b['label'], $enc); - $term = mb_strtolower($_GET['search'], $enc); - $i = mb_strpos($nameA, $term, 0, 'UTF-8'); - $j = mb_strpos($nameB, $term, 0, 'UTF-8'); - - if($i === $j) { - return 0; - } elseif ($i === 0) { - return -1; - } else { - return 1; - } -} diff --git a/lib/private/share/searchresultsorter.php b/lib/private/share/searchresultsorter.php new file mode 100644 index 00000000000..27f94a694ac --- /dev/null +++ b/lib/private/share/searchresultsorter.php @@ -0,0 +1,53 @@ + + * 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; + + /** + * @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 + */ + public function __construct($search, $key, $encoding = 'UTF-8') { + $this->encoding = $encoding; + $this->key = $key; + $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. + * Callback function for usort. http://php.net/usort + */ + public function sort($a, $b) { + if(!isset($a[$this->key]) || !isset($b[$this->key])) { + \OCP\Util::writeLog('core', 'Sharing: cannot sort due to missing'. + 'array key', \OC_Log::ERROR); + 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) { + return 0; + } elseif ($i === 0) { + return -1; + } else { + return 1; + } + } +} + -- cgit v1.2.3 From 82716ced48c256ef5e2f8ca9b7a4e3ab20e146cd Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 15 Jan 2014 18:19:20 +0100 Subject: sort following entries in alphabetical order --- lib/private/share/searchresultsorter.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib/private') diff --git a/lib/private/share/searchresultsorter.php b/lib/private/share/searchresultsorter.php index 27f94a694ac..f64a4766ade 100644 --- a/lib/private/share/searchresultsorter.php +++ b/lib/private/share/searchresultsorter.php @@ -27,7 +27,7 @@ class SearchResultSorter { /** * User and Group names matching the search term at the beginning shall appear - * on top of the share dialog. + * on top of the share dialog. Following entries in alphabetical order. * Callback function for usort. http://php.net/usort */ public function sort($a, $b) { @@ -41,8 +41,9 @@ class SearchResultSorter { $i = mb_strpos($nameA, $this->search, 0, $this->encoding); $j = mb_strpos($nameB, $this->search, 0, $this->encoding); - if($i === $j) { - return 0; + 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 { -- cgit v1.2.3 From 20bfbb0fd9316be0cbba9c2202a9b45ce7eea7f8 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 16 Jan 2014 10:30:18 +0100 Subject: wrong tld --- lib/private/share/searchresultsorter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/private') diff --git a/lib/private/share/searchresultsorter.php b/lib/private/share/searchresultsorter.php index f64a4766ade..4f8799494f5 100644 --- a/lib/private/share/searchresultsorter.php +++ b/lib/private/share/searchresultsorter.php @@ -1,6 +1,6 @@ + * Copyright (c) 2014 Arthur Schiwon * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. -- cgit v1.2.3 From 32afdcbefec5793fb28162c456919d2b0be5cfe9 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 16 Jan 2014 11:00:22 +0100 Subject: Inject logger --- lib/private/share/searchresultsorter.php | 9 ++++++--- tests/lib/share/searchresultsorter.php | 7 +++++++ 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'lib/private') diff --git a/lib/private/share/searchresultsorter.php b/lib/private/share/searchresultsorter.php index 4f8799494f5..f81a94c749d 100644 --- a/lib/private/share/searchresultsorter.php +++ b/lib/private/share/searchresultsorter.php @@ -12,16 +12,19 @@ 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, $encoding = 'UTF-8') { + public function __construct($search, $key, $encoding = 'UTF-8', \OC\Log $log = null) { $this->encoding = $encoding; $this->key = $key; + $this->log = is_null($log) ? new \OC\Log() : $log; $this->search = mb_strtolower($search, $this->encoding); } @@ -32,8 +35,8 @@ class SearchResultSorter { */ public function sort($a, $b) { if(!isset($a[$this->key]) || !isset($b[$this->key])) { - \OCP\Util::writeLog('core', 'Sharing: cannot sort due to missing'. - 'array key', \OC_Log::ERROR); + $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); diff --git a/tests/lib/share/searchresultsorter.php b/tests/lib/share/searchresultsorter.php index f24e40ea059..efc3e1b7aa3 100644 --- a/tests/lib/share/searchresultsorter.php +++ b/tests/lib/share/searchresultsorter.php @@ -37,4 +37,11 @@ class Test_Share_Search extends \PHPUnit_Framework_TestCase { $this->assertTrue($result[2]['foobar'] === 'Bicyclerepairwoman'); $this->assertTrue($result[3]['foobar'] === 'woot'); } + + /** + * @expectedException PHPUnit_Framework_Error + */ + public function testSortWrongLog() { + $sorter = new \OC\Share\SearchResultSorter('foo', 'bar', 'UTF-8', 'foobar'); + } } -- cgit v1.2.3 From af781bdea7509c3ecd9a7b4902fb7a266dc62c80 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 5 Feb 2014 17:05:56 +0100 Subject: fix DI --- core/ajax/share.php | 3 ++- lib/private/share/searchresultsorter.php | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'lib/private') diff --git a/core/ajax/share.php b/core/ajax/share.php index 21e320a4732..c251f8e7bae 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -355,7 +355,8 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo } } $sorter = new \OC\Share\SearchResultSorter($_GET['search'], - 'label'); + 'label', + new \OC\Log()); usort($shareWith, array($sorter, 'sort')); OC_JSON::success(array('data' => $shareWith)); } diff --git a/lib/private/share/searchresultsorter.php b/lib/private/share/searchresultsorter.php index f81a94c749d..fbf77179097 100644 --- a/lib/private/share/searchresultsorter.php +++ b/lib/private/share/searchresultsorter.php @@ -21,10 +21,10 @@ class SearchResultSorter { * @param $encoding optional, encoding to use, defaults to UTF-8 * @param $log optional, an \OC\Log instance */ - public function __construct($search, $key, $encoding = 'UTF-8', \OC\Log $log = null) { + public function __construct($search, $key, \OC\Log $log = null, $encoding = 'UTF-8') { $this->encoding = $encoding; $this->key = $key; - $this->log = is_null($log) ? new \OC\Log() : $log; + $this->log = $log; $this->search = mb_strtolower($search, $this->encoding); } @@ -35,8 +35,10 @@ class SearchResultSorter { */ public function sort($a, $b) { if(!isset($a[$this->key]) || !isset($b[$this->key])) { - $this->log->error('Sharing dialogue: cannot sort due to missing array key', - array('app' => 'core')); + 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); -- cgit v1.2.3 From a6399f9ceffcf9865b8a2be155dc4f98bd2ee5dc Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 11 Feb 2014 14:00:24 +0100 Subject: Add the background job list to the public server container --- cron.php | 4 +- lib/private/backgroundjob/job.php | 4 +- lib/private/backgroundjob/joblist.php | 68 +++++++++++++++++------------ lib/private/server.php | 16 +++++++ lib/public/backgroundjob.php | 14 +++--- lib/public/backgroundjob/ijob.php | 29 +++++++++++++ lib/public/backgroundjob/ijoblist.php | 73 ++++++++++++++++++++++++++++++++ lib/public/iservercontainer.php | 7 +++ tests/lib/backgroundjob/dummyjoblist.php | 2 + 9 files changed, 179 insertions(+), 38 deletions(-) create mode 100644 lib/public/backgroundjob/ijob.php create mode 100644 lib/public/backgroundjob/ijoblist.php (limited to 'lib/private') diff --git a/cron.php b/cron.php index 0d2c07b2d95..44ca421328b 100644 --- a/cron.php +++ b/cron.php @@ -97,7 +97,7 @@ try { touch(TemporaryCronClass::$lockfile); // Work - $jobList = new \OC\BackgroundJob\JobList(); + $jobList = \OC::$server->getJobList(); $jobs = $jobList->getAll(); foreach ($jobs as $job) { $job->execute($jobList, $logger); @@ -109,7 +109,7 @@ try { OC_JSON::error(array('data' => array('message' => 'Backgroundjobs are using system cron!'))); } else { // Work and success :-) - $jobList = new \OC\BackgroundJob\JobList(); + $jobList = \OC::$server->getJobList(); $job = $jobList->getNext(); $job->execute($jobList, $logger); $jobList->setLastJob($job); 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..6b0df9e0d63 100644 --- a/lib/private/backgroundjob/joblist.php +++ b/lib/private/backgroundjob/joblist.php @@ -8,14 +8,26 @@ namespace OC\BackgroundJob; -/** - * Class QueuedJob - * - * create a background job that is to be executed once - * - * @package OC\BackgroundJob - */ class JobList { + /** + * @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 +40,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 +57,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 +79,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 +90,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 +106,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 +127,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 +160,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 +169,7 @@ class JobList { * @return int */ public function getLastJob() { - return \OC_Appconfig::getValue('backgroundjob', 'lastjob', 0); + $this->config->getAppValue('backgroundjob', 'lastjob', 0); } /** @@ -166,7 +178,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/server.php b/lib/private/server.php index c9e593ec2ed..b5ffd08ce79 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -148,6 +148,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); + }); } /** @@ -336,4 +343,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/public/backgroundjob.php b/lib/public/backgroundjob.php index a7f54491dfa..bcaf6e35454 100644 --- a/lib/public/backgroundjob.php +++ b/lib/public/backgroundjob.php @@ -33,7 +33,7 @@ use \OC\BackgroundJob\JobList; /** * This class provides functions to register backgroundjobs in ownCloud * - * To create a new backgroundjob create a new class that inharits from either \OC\BackgroundJob\Job, + * To create a new backgroundjob create a new class that inherits from either \OC\BackgroundJob\Job, * \OC\BackgroundJob\QueuedJob or \OC\BackgroundJob\TimedJob and register it using * \OCP\BackgroundJob->registerJob($job, $argument), $argument will be passed to the run() function * of the job when the job is executed. @@ -73,7 +73,7 @@ class BackgroundJob { * @param mixed $argument */ public static function registerJob($job, $argument = null) { - $jobList = new JobList(); + $jobList = \OC::$server->getJobList(); $jobList->add($job, $argument); } @@ -99,7 +99,7 @@ class BackgroundJob { * key is string "$klass-$method", value is array( $klass, $method ) */ static public function allRegularTasks() { - $jobList = new JobList(); + $jobList = \OC::$server->getJobList(); $allJobs = $jobList->getAll(); $regularJobs = array(); foreach ($allJobs as $job) { @@ -118,7 +118,7 @@ class BackgroundJob { * @return associative array */ public static function findQueuedTask($id) { - $jobList = new JobList(); + $jobList = \OC::$server->getJobList(); return $jobList->getById($id); } @@ -128,7 +128,7 @@ class BackgroundJob { * @return array with associative arrays */ public static function allQueuedTasks() { - $jobList = new JobList(); + $jobList = \OC::$server->getJobList(); $allJobs = $jobList->getAll(); $queuedJobs = array(); foreach ($allJobs as $job) { @@ -148,7 +148,7 @@ class BackgroundJob { * @return array with associative arrays */ public static function queuedTaskWhereAppIs($app) { - $jobList = new JobList(); + $jobList = \OC::$server->getJobList(); $allJobs = $jobList->getAll(); $queuedJobs = array(); foreach ($allJobs as $job) { @@ -186,7 +186,7 @@ class BackgroundJob { * Deletes a report */ public static function deleteQueuedTask($id) { - $jobList = new JobList(); + $jobList = \OC::$server->getJobList(); $job = $jobList->getById($id); if ($job) { $jobList->remove($job); diff --git a/lib/public/backgroundjob/ijob.php b/lib/public/backgroundjob/ijob.php new file mode 100644 index 00000000000..c427b50401d --- /dev/null +++ b/lib/public/backgroundjob/ijob.php @@ -0,0 +1,29 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCP\BackgroundJob; + +interface IJob { + /** + * @param \OCP\BackgroundJob\IJobList $jobList + * @param \OC\Log $logger + */ + public function execute($jobList, $logger = null); + + public function setId($id); + + public function setLastRun($lastRun); + + public function setArgument($argument); + + public function getId(); + + public function getLastRun(); + + public function getArgument(); +} diff --git a/lib/public/backgroundjob/ijoblist.php b/lib/public/backgroundjob/ijoblist.php new file mode 100644 index 00000000000..7e80d51755b --- /dev/null +++ b/lib/public/backgroundjob/ijoblist.php @@ -0,0 +1,73 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCP\BackgroundJob; + +interface IJobList { + /** + * @param \OCP\BackgroundJob\IJob |string $job + * @param mixed $argument + */ + public function add($job, $argument = null); + + /** + * @param \OCP\BackgroundJob\IJob|string $job + * @param mixed $argument + */ + public function remove($job, $argument = null); + + /** + * check if a job is in the list + * + * @param $job + * @param mixed $argument + * @return bool + */ + public function has($job, $argument); + + /** + * get all jobs in the list + * + * @return \OCP\BackgroundJob\IJob[] + */ + public function getAll(); + + /** + * get the next job in the list + * + * @return \OCP\BackgroundJob\IJob + */ + public function getNext(); + + /** + * @param int $id + * @return \OCP\BackgroundJob\IJob + */ + public function getById($id); + + /** + * set the job that was last ran + * + * @param \OCP\BackgroundJob\IJob $job + */ + public function setLastJob($job); + + /** + * get the id of the last ran job + * + * @return int + */ + public function getLastJob(); + + /** + * set the lastRun of $job to now + * + * @param \OCP\BackgroundJob\IJob $job + */ + public function setLastRun($job); +} diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php index 5473f3ee334..0658bd0b022 100644 --- a/lib/public/iservercontainer.php +++ b/lib/public/iservercontainer.php @@ -176,4 +176,11 @@ interface IServerContainer { */ function getAvatarManager(); + /** + * Returns an job list for controlling background jobs + * + * @return \OCP\BackgroundJob\IJobList + */ + function getJobList(); + } diff --git a/tests/lib/backgroundjob/dummyjoblist.php b/tests/lib/backgroundjob/dummyjoblist.php index e1579c273bb..7801269b27e 100644 --- a/tests/lib/backgroundjob/dummyjoblist.php +++ b/tests/lib/backgroundjob/dummyjoblist.php @@ -21,6 +21,8 @@ class DummyJobList extends \OC\BackgroundJob\JobList { private $last = 0; + public function __construct(){} + /** * @param \OC\BackgroundJob\Job|string $job * @param mixed $argument -- cgit v1.2.3 From 50cc6a85e5d4c817235aee58e9d461e4034df27b Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 11 Feb 2014 14:26:40 +0100 Subject: Add explicit sorting --- lib/private/appconfig.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/private') diff --git a/lib/private/appconfig.php b/lib/private/appconfig.php index 71aa8307316..a47e1ad49e6 100644 --- a/lib/private/appconfig.php +++ b/lib/private/appconfig.php @@ -92,7 +92,7 @@ class AppConfig implements \OCP\IAppConfig { * entry in the appconfig table. */ public function getApps() { - $query = 'SELECT DISTINCT `appid` FROM `*PREFIX*appconfig`'; + $query = 'SELECT DISTINCT `appid` FROM `*PREFIX*appconfig` ORDER BY `appid`'; $result = $this->conn->executeQuery($query); $apps = array(); @@ -112,7 +112,9 @@ class AppConfig implements \OCP\IAppConfig { */ public function getKeys($app) { $values = $this->getAppValues($app); - return array_keys($values); + $keys = array_keys($values); + sort($keys); + return $keys; } /** -- cgit v1.2.3 From 62288971cacf9049ec4521d659a17857ac42d139 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 12 Feb 2014 13:32:16 +0100 Subject: Additional phpdoc --- lib/private/backgroundjob/joblist.php | 6 ++++-- lib/public/backgroundjob/ijob.php | 21 ++++++++++++++++++++- lib/public/backgroundjob/ijoblist.php | 10 +++++++--- 3 files changed, 31 insertions(+), 6 deletions(-) (limited to 'lib/private') diff --git a/lib/private/backgroundjob/joblist.php b/lib/private/backgroundjob/joblist.php index 6b0df9e0d63..5ec81dc3fc6 100644 --- a/lib/private/backgroundjob/joblist.php +++ b/lib/private/backgroundjob/joblist.php @@ -1,6 +1,6 @@ + * Copyright (c) 2014 Robin Appelman * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. @@ -8,7 +8,9 @@ namespace OC\BackgroundJob; -class JobList { +use OCP\BackgroundJob\IJobList; + +class JobList implements IJobList { /** * @var \OCP\IDBConnection */ diff --git a/lib/public/backgroundjob/ijob.php b/lib/public/backgroundjob/ijob.php index 5bf815ef8e0..5231e9537a9 100644 --- a/lib/public/backgroundjob/ijob.php +++ b/lib/public/backgroundjob/ijob.php @@ -10,14 +10,33 @@ namespace OCP\BackgroundJob; interface IJob { /** - * @param \OCP\BackgroundJob\IJobList $jobList + * Run the background job with the registered argument + * + * @param \OCP\BackgroundJob\IJobList $jobList The job list that manages the state of this job * @param \OC\Log $logger */ public function execute($jobList, $logger = null); + /** + * Get the id of the background job + * This id is determined by the job list when a job is added to the list + * + * @return int + */ public function getId(); + /** + * Get the last time this job was run as unix timestamp + * + * @return int + */ public function getLastRun(); + /** + * Get the argument associated with the background job + * This is the argument that will be passed to the background job + * + * @return mixed + */ public function getArgument(); } diff --git a/lib/public/backgroundjob/ijoblist.php b/lib/public/backgroundjob/ijoblist.php index 7e80d51755b..72f3fe863da 100644 --- a/lib/public/backgroundjob/ijoblist.php +++ b/lib/public/backgroundjob/ijoblist.php @@ -1,6 +1,6 @@ + * Copyright (c) 2014 Robin Appelman * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. @@ -10,12 +10,16 @@ namespace OCP\BackgroundJob; interface IJobList { /** + * Add a job to the list + * * @param \OCP\BackgroundJob\IJob |string $job - * @param mixed $argument + * @param mixed $argument The argument to be passed to $job->run() when the job is exectured */ public function add($job, $argument = null); /** + * Remove a job from the list + * * @param \OCP\BackgroundJob\IJob|string $job * @param mixed $argument */ @@ -51,7 +55,7 @@ interface IJobList { public function getById($id); /** - * set the job that was last ran + * set the job that was last ran to the current time * * @param \OCP\BackgroundJob\IJob $job */ -- cgit v1.2.3 From d6576c640c429d24a6329573c0dfaf99d82ac867 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 12 Feb 2014 13:52:13 +0100 Subject: Add unit tests for JobList --- lib/private/backgroundjob/joblist.php | 2 +- tests/lib/backgroundjob/job.php | 25 ----- tests/lib/backgroundjob/joblist.php | 203 ++++++++++++++++++++++++++++++++++ tests/lib/backgroundjob/testjob.php | 34 ++++++ 4 files changed, 238 insertions(+), 26 deletions(-) create mode 100644 tests/lib/backgroundjob/joblist.php create mode 100644 tests/lib/backgroundjob/testjob.php (limited to 'lib/private') diff --git a/lib/private/backgroundjob/joblist.php b/lib/private/backgroundjob/joblist.php index 5ec81dc3fc6..586e99a3cbc 100644 --- a/lib/private/backgroundjob/joblist.php +++ b/lib/private/backgroundjob/joblist.php @@ -171,7 +171,7 @@ class JobList implements IJobList { * @return int */ public function getLastJob() { - $this->config->getAppValue('backgroundjob', 'lastjob', 0); + return $this->config->getAppValue('backgroundjob', 'lastjob', 0); } /** diff --git a/tests/lib/backgroundjob/job.php b/tests/lib/backgroundjob/job.php index 7d66fa772d2..10a8f46462e 100644 --- a/tests/lib/backgroundjob/job.php +++ b/tests/lib/backgroundjob/job.php @@ -8,31 +8,6 @@ namespace Test\BackgroundJob; - -class TestJob extends \OC\BackgroundJob\Job { - private $testCase; - - /** - * @var callable $callback - */ - private $callback; - - /** - * @param Job $testCase - * @param callable $callback - */ - public function __construct($testCase, $callback) { - $this->testCase = $testCase; - $this->callback = $callback; - } - - public function run($argument) { - $this->testCase->markRun(); - $callback = $this->callback; - $callback($argument); - } -} - class Job extends \PHPUnit_Framework_TestCase { private $run = false; diff --git a/tests/lib/backgroundjob/joblist.php b/tests/lib/backgroundjob/joblist.php new file mode 100644 index 00000000000..c3318f80cb2 --- /dev/null +++ b/tests/lib/backgroundjob/joblist.php @@ -0,0 +1,203 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\BackgroundJob; + +class JobList extends \PHPUnit_Framework_TestCase { + /** + * @var \OC\BackgroundJob\JobList + */ + protected $instance; + + /** + * @var \OCP\IConfig | \PHPUnit_Framework_MockObject_MockObject $config + */ + protected $config; + + public function setUp() { + $conn = \OC::$server->getDatabaseConnection(); + $this->config = $this->getMock('\OCP\IConfig'); + $this->instance = new \OC\BackgroundJob\JobList($conn, $this->config); + } + + public function argumentProvider() { + return array( + array(null), + array(false), + array('foobar'), + array(12), + array(array( + 'asd' => 5, + 'foo' => 'bar' + )) + ); + } + + /** + * @dataProvider argumentProvider + * @param $argument + */ + public function testAddRemove($argument) { + $existingJobs = $this->instance->getAll(); + $job = new TestJob(); + $this->instance->add($job, $argument); + + $jobs = $this->instance->getAll(); + + $this->assertCount(count($existingJobs) + 1, $jobs); + $addedJob = $jobs[count($jobs) - 1]; + $this->assertInstanceOf('\Test\BackgroundJob\TestJob', $addedJob); + $this->assertEquals($argument, $addedJob->getArgument()); + + $this->instance->remove($job, $argument); + + $jobs = $this->instance->getAll(); + $this->assertEquals($existingJobs, $jobs); + } + + /** + * @dataProvider argumentProvider + * @param $argument + */ + public function testRemoveDifferentArgument($argument) { + $existingJobs = $this->instance->getAll(); + $job = new TestJob(); + $this->instance->add($job, $argument); + + $jobs = $this->instance->getAll(); + $this->instance->remove($job, 10); + $jobs2 = $this->instance->getAll(); + + $this->assertEquals($jobs, $jobs2); + + $this->instance->remove($job, $argument); + + $jobs = $this->instance->getAll(); + $this->assertEquals($existingJobs, $jobs); + } + + /** + * @dataProvider argumentProvider + * @param $argument + */ + public function testHas($argument) { + $job = new TestJob(); + $this->assertFalse($this->instance->has($job, $argument)); + $this->instance->add($job, $argument); + + $this->assertTrue($this->instance->has($job, $argument)); + + $this->instance->remove($job, $argument); + + $this->assertFalse($this->instance->has($job, $argument)); + } + + /** + * @dataProvider argumentProvider + * @param $argument + */ + public function testHasDifferentArgument($argument) { + $job = new TestJob(); + $this->instance->add($job, $argument); + + $this->assertFalse($this->instance->has($job, 10)); + + $this->instance->remove($job, $argument); + } + + public function testGetLastJob() { + $this->config->expects($this->once()) + ->method('getAppValue') + ->with('backgroundjob', 'lastjob', 0) + ->will($this->returnValue(15)); + + $this->assertEquals(15, $this->instance->getLastJob()); + } + + public function testGetNext() { + $job = new TestJob(); + $this->instance->add($job, 1); + $this->instance->add($job, 2); + + $jobs = $this->instance->getAll(); + + $savedJob1 = $jobs[count($jobs) - 2]; + $savedJob2 = $jobs[count($jobs) - 1]; + + $this->config->expects($this->once()) + ->method('getAppValue') + ->with('backgroundjob', 'lastjob', 0) + ->will($this->returnValue($savedJob1->getId())); + + $nextJob = $this->instance->getNext(); + + $this->assertEquals($savedJob2, $nextJob); + + $this->instance->remove($job, 1); + $this->instance->remove($job, 2); + } + + public function testGetNextWrapAround() { + $job = new TestJob(); + $this->instance->add($job, 1); + $this->instance->add($job, 2); + + $jobs = $this->instance->getAll(); + + $savedJob2 = $jobs[count($jobs) - 1]; + + $this->config->expects($this->once()) + ->method('getAppValue') + ->with('backgroundjob', 'lastjob', 0) + ->will($this->returnValue($savedJob2->getId())); + + $nextJob = $this->instance->getNext(); + + $this->assertEquals($jobs[0], $nextJob); + + $this->instance->remove($job, 1); + $this->instance->remove($job, 2); + } + + /** + * @dataProvider argumentProvider + * @param $argument + */ + public function testGetById($argument) { + $job = new TestJob(); + $this->instance->add($job, $argument); + + $jobs = $this->instance->getAll(); + + $addedJob = $jobs[count($jobs) - 1]; + + $this->assertEquals($addedJob, $this->instance->getById($addedJob->getId())); + + $this->instance->remove($job, $argument); + } + + public function testSetLastRun() { + $job = new TestJob(); + $this->instance->add($job); + + $jobs = $this->instance->getAll(); + + $addedJob = $jobs[count($jobs) - 1]; + + $timeStart = time(); + $this->instance->setLastRun($addedJob); + $timeEnd = time(); + + $addedJob = $this->instance->getById($addedJob->getId()); + + $this->assertGreaterThanOrEqual($timeStart, $addedJob->getLastRun()); + $this->assertLessThanOrEqual($timeEnd, $addedJob->getLastRun()); + + $this->instance->remove($job); + } +} diff --git a/tests/lib/backgroundjob/testjob.php b/tests/lib/backgroundjob/testjob.php new file mode 100644 index 00000000000..23fc4268d1a --- /dev/null +++ b/tests/lib/backgroundjob/testjob.php @@ -0,0 +1,34 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\BackgroundJob; + + +class TestJob extends \OC\BackgroundJob\Job { + private $testCase; + + /** + * @var callable $callback + */ + private $callback; + + /** + * @param Job $testCase + * @param callable $callback + */ + public function __construct($testCase = null, $callback = null) { + $this->testCase = $testCase; + $this->callback = $callback; + } + + public function run($argument) { + $this->testCase->markRun(); + $callback = $this->callback; + $callback($argument); + } +} -- cgit v1.2.3 From f62f1658ceba6ad02ada0823243d779a698f5f7f Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 14 Feb 2014 11:23:39 +0100 Subject: suppress error msg caused by php bug --- lib/private/preview/office.php | 2 +- lib/private/preview/pdf.php | 2 +- lib/private/preview/svg.php | 2 +- lib/private/preview/unknown.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/private') 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(); -- cgit v1.2.3 From 0ba0596341779100db37e25e59ac34f5a57bd2c3 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 14 Feb 2014 14:25:45 +0100 Subject: remove duplicate call to groupExists --- lib/private/group/manager.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'lib/private') diff --git a/lib/private/group/manager.php b/lib/private/group/manager.php index bf469d51d12..29453c5da14 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]; } -- cgit v1.2.3 From b35f679483f2b8f1dab56b903ca2e942ac4606ff Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 14 Feb 2014 15:07:08 +0100 Subject: Fix test cases for group manager --- lib/private/group/manager.php | 4 ++-- tests/lib/group/manager.php | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 4 deletions(-) (limited to 'lib/private') diff --git a/lib/private/group/manager.php b/lib/private/group/manager.php index 29453c5da14..9b433b64fd4 100644 --- a/lib/private/group/manager.php +++ b/lib/private/group/manager.php @@ -108,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/tests/lib/group/manager.php b/tests/lib/group/manager.php index 9d3adf51a0c..90f0e1b35e2 100644 --- a/tests/lib/group/manager.php +++ b/tests/lib/group/manager.php @@ -116,16 +116,22 @@ class Manager extends \PHPUnit_Framework_TestCase { /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend */ + $backendGroupCreated = false; $backend = $this->getMock('\OC_Group_Database'); $backend->expects($this->any()) ->method('groupExists') ->with('group1') - ->will($this->returnValue(false)); + ->will($this->returnCallback(function () use (&$backendGroupCreated) { + return $backendGroupCreated; + })); $backend->expects($this->once()) ->method('implementsActions') ->will($this->returnValue(true)); $backend->expects($this->once()) - ->method('createGroup'); + ->method('createGroup') + ->will($this->returnCallback(function () use (&$backendGroupCreated) { + $backendGroupCreated = true; + }));; /** * @var \OC\User\Manager $userManager @@ -170,6 +176,10 @@ class Manager extends \PHPUnit_Framework_TestCase { ->method('getGroups') ->with('1') ->will($this->returnValue(array('group1'))); + $backend->expects($this->once()) + ->method('groupExists') + ->with('group1') + ->will($this->returnValue(true)); /** * @var \OC\User\Manager $userManager @@ -193,6 +203,9 @@ class Manager extends \PHPUnit_Framework_TestCase { ->method('getGroups') ->with('1') ->will($this->returnValue(array('group1'))); + $backend1->expects($this->any()) + ->method('groupExists') + ->will($this->returnValue(true)); /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2 @@ -202,6 +215,9 @@ class Manager extends \PHPUnit_Framework_TestCase { ->method('getGroups') ->with('1') ->will($this->returnValue(array('group12', 'group1'))); + $backend2->expects($this->any()) + ->method('groupExists') + ->will($this->returnValue(true)); /** * @var \OC\User\Manager $userManager @@ -228,6 +244,9 @@ class Manager extends \PHPUnit_Framework_TestCase { ->method('getGroups') ->with('1', 2, 1) ->will($this->returnValue(array('group1'))); + $backend1->expects($this->any()) + ->method('groupExists') + ->will($this->returnValue(true)); /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2 @@ -237,6 +256,9 @@ class Manager extends \PHPUnit_Framework_TestCase { ->method('getGroups') ->with('1', 1, 0) ->will($this->returnValue(array('group12'))); + $backend2->expects($this->any()) + ->method('groupExists') + ->will($this->returnValue(true)); /** * @var \OC\User\Manager $userManager @@ -263,6 +285,10 @@ class Manager extends \PHPUnit_Framework_TestCase { ->method('getUserGroups') ->with('user1') ->will($this->returnValue(array('group1'))); + $backend->expects($this->any()) + ->method('groupExists') + ->with('group1') + ->will($this->returnValue(true)); /** * @var \OC\User\Manager $userManager @@ -286,6 +312,10 @@ class Manager extends \PHPUnit_Framework_TestCase { ->method('getUserGroups') ->with('user1') ->will($this->returnValue(array('group1'))); + $backend1->expects($this->any()) + ->method('groupExists') + ->will($this->returnValue(true)); + /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2 */ @@ -294,6 +324,9 @@ class Manager extends \PHPUnit_Framework_TestCase { ->method('getUserGroups') ->with('user1') ->will($this->returnValue(array('group1', 'group2'))); + $backend1->expects($this->any()) + ->method('groupExists') + ->will($this->returnValue(true)); /** * @var \OC\User\Manager $userManager -- cgit v1.2.3 From 09502fcb368c6b18a936b0b0aeb0e685829ad570 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 14 Feb 2014 19:24:12 +0100 Subject: remove the JsonSerializable interface from \OC\Files\FileInfo --- lib/private/files/fileinfo.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'lib/private') diff --git a/lib/private/files/fileinfo.php b/lib/private/files/fileinfo.php index 7edea13df96..c77571cd2a7 100644 --- a/lib/private/files/fileinfo.php +++ b/lib/private/files/fileinfo.php @@ -8,7 +8,7 @@ namespace OC\Files; -class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess, \JsonSerializable { +class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess { /** * @var array $data */ @@ -52,10 +52,6 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess, \JsonSerializable { return $this->data[$offset]; } - public function jsonSerialize() { - return $this->data; - } - /** * @return string */ -- cgit v1.2.3