commit
a4b6d66703
@ -0,0 +1,12 @@ |
|||||||
|
/** |
||||||
|
* Copyright (c) 2014 |
||||||
|
* Bjoern Schiessle <schiessle@owncloud.com> |
||||||
|
* This file is licensed under the Affero General Public License version 3 or later. |
||||||
|
* See the COPYING-README file. |
||||||
|
*/ |
||||||
|
|
||||||
|
OC.Encryption={ |
||||||
|
MIGRATION_OPEN:0, |
||||||
|
MIGRATION_COMPLETED:1, |
||||||
|
MIGRATION_IN_PROGRESS:-1, |
||||||
|
}; |
@ -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); |
||||||
|
} |
||||||
|
} |
@ -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); |
||||||
|
} |
||||||
|
} |
@ -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; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
@ -0,0 +1,42 @@ |
|||||||
|
<?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 OCP\BackgroundJob; |
||||||
|
|
||||||
|
interface IJob { |
||||||
|
/** |
||||||
|
* 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(); |
||||||
|
} |
@ -0,0 +1,77 @@ |
|||||||
|
<?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 OCP\BackgroundJob; |
||||||
|
|
||||||
|
interface IJobList { |
||||||
|
/** |
||||||
|
* Add a job to the list |
||||||
|
* |
||||||
|
* @param \OCP\BackgroundJob\IJob |string $job |
||||||
|
* @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 |
||||||
|
*/ |
||||||
|
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 to the current time |
||||||
|
* |
||||||
|
* @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); |
||||||
|
} |
@ -0,0 +1,138 @@ |
|||||||
|
<?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 OCP\Files; |
||||||
|
|
||||||
|
interface FileInfo { |
||||||
|
const TYPE_FILE = 'file'; |
||||||
|
const TYPE_FOLDER = 'folder'; |
||||||
|
|
||||||
|
/** |
||||||
|
* Get the Etag of the file or folder |
||||||
|
* |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
public function getEtag(); |
||||||
|
|
||||||
|
/** |
||||||
|
* Get the size in bytes for the file or folder |
||||||
|
* |
||||||
|
* @return int |
||||||
|
*/ |
||||||
|
public function getSize(); |
||||||
|
|
||||||
|
/** |
||||||
|
* Get the last modified date as timestamp for the file or folder |
||||||
|
* |
||||||
|
* @return int |
||||||
|
*/ |
||||||
|
public function getMtime(); |
||||||
|
|
||||||
|
/** |
||||||
|
* Get the name of the file or folder |
||||||
|
* |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
public function getName(); |
||||||
|
|
||||||
|
/** |
||||||
|
* Get the path relative to the storage |
||||||
|
* |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
public function getInternalPath(); |
||||||
|
|
||||||
|
/** |
||||||
|
* Get the absolute path |
||||||
|
* |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
public function getPath(); |
||||||
|
|
||||||
|
/** |
||||||
|
* Get the full mimetype of the file or folder i.e. 'image/png' |
||||||
|
* |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
public function getMimetype(); |
||||||
|
|
||||||
|
/** |
||||||
|
* Get the first part of the mimetype of the file or folder i.e. 'image' |
||||||
|
* |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
public function getMimePart(); |
||||||
|
|
||||||
|
/** |
||||||
|
* Get the storage the file or folder is storage on |
||||||
|
* |
||||||
|
* @return \OCP\Files\Storage |
||||||
|
*/ |
||||||
|
public function getStorage(); |
||||||
|
|
||||||
|
/** |
||||||
|
* Get the file id of the file or folder |
||||||
|
* |
||||||
|
* @return int |
||||||
|
*/ |
||||||
|
public function getId(); |
||||||
|
|
||||||
|
/** |
||||||
|
* Check whether the file is encrypted |
||||||
|
* |
||||||
|
* @return bool |
||||||
|
*/ |
||||||
|
public function isEncrypted(); |
||||||
|
|
||||||
|
/** |
||||||
|
* Get the permissions of the file or folder as bitmasked combination of the following constants |
||||||
|
* \OCP\PERMISSION_CREATE |
||||||
|
* \OCP\PERMISSION_READ |
||||||
|
* \OCP\PERMISSION_UPDATE |
||||||
|
* \OCP\PERMISSION_DELETE |
||||||
|
* \OCP\PERMISSION_SHARE |
||||||
|
* \OCP\PERMISSION_ALL |
||||||
|
* |
||||||
|
* @return int |
||||||
|
*/ |
||||||
|
public function getPermissions(); |
||||||
|
|
||||||
|
/** |
||||||
|
* Check whether this is a file or a folder |
||||||
|
* |
||||||
|
* @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(); |
||||||
|
} |
@ -0,0 +1,91 @@ |
|||||||
|
<?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 OCP; |
||||||
|
|
||||||
|
/** |
||||||
|
* This class provides an easy way for apps to store config values in the |
||||||
|
* database. |
||||||
|
*/ |
||||||
|
interface IAppConfig { |
||||||
|
/** |
||||||
|
* @brief check if a key is set in the appconfig |
||||||
|
* @param string $app |
||||||
|
* @param string $key |
||||||
|
* @return bool |
||||||
|
*/ |
||||||
|
public function hasKey($app, $key); |
||||||
|
|
||||||
|
/** |
||||||
|
* @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 function getValue($app, $key, $default = null); |
||||||
|
|
||||||
|
/** |
||||||
|
* @brief Deletes a key |
||||||
|
* @param string $app app |
||||||
|
* @param string $key key |
||||||
|
* @return bool |
||||||
|
* |
||||||
|
* Deletes a key. |
||||||
|
*/ |
||||||
|
public function deleteKey($app, $key); |
||||||
|
|
||||||
|
/** |
||||||
|
* @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 function getKeys($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 function getValues($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 function setValue($app, $key, $value); |
||||||
|
|
||||||
|
/** |
||||||
|
* @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 function getApps(); |
||||||
|
|
||||||
|
/** |
||||||
|
* @brief Remove app from appconfig |
||||||
|
* @param string $app app |
||||||
|
* @return bool |
||||||
|
* |
||||||
|
* Removes all keys in appconfig belonging to the app. |
||||||
|
*/ |
||||||
|
public function deleteApp($app); |
||||||
|
} |
@ -0,0 +1,203 @@ |
|||||||
|
<?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 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); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,34 @@ |
|||||||
|
<?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 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); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,47 @@ |
|||||||
|
<?php |
||||||
|
/** |
||||||
|
* ownCloud |
||||||
|
* |
||||||
|
* @author Arthur Schiwon |
||||||
|
* @copyright 2014 Arthur Schiwon <blizzz@owncloud.com> |
||||||
|
* |
||||||
|
* 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/>. |
||||||
|
*/ |
||||||
|
|
||||||
|
class Test_Share_Search extends \PHPUnit_Framework_TestCase { |
||||||
|
public function testSort() { |
||||||
|
$search = 'lin'; |
||||||
|
$sorter = new \OC\Share\SearchResultSorter($search, 'foobar'); |
||||||
|
|
||||||
|
$result = array( |
||||||
|
array('foobar' => 'woot'), |
||||||
|
array('foobar' => 'linux'), |
||||||
|
array('foobar' => 'Linus'), |
||||||
|
array('foobar' => 'Bicyclerepairwoman'), |
||||||
|
); |
||||||
|
|
||||||
|
usort($result, array($sorter, 'sort')); |
||||||
|
$this->assertTrue($result[0]['foobar'] === 'Linus'); |
||||||
|
$this->assertTrue($result[1]['foobar'] === 'linux'); |
||||||
|
$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'); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue