Merge branch 'master' into migration_unit_tests
This commit is contained in:
commit
a4b6d66703
|
@ -22,6 +22,7 @@ if (empty($_POST['dirToken'])) {
|
||||||
} else {
|
} else {
|
||||||
// return only read permissions for public upload
|
// return only read permissions for public upload
|
||||||
$allowedPermissions = OCP\PERMISSION_READ;
|
$allowedPermissions = OCP\PERMISSION_READ;
|
||||||
|
$public_directory = !empty($_POST['subdir']) ? $_POST['subdir'] : '/';
|
||||||
|
|
||||||
$linkItem = OCP\Share::getShareByToken($_POST['dirToken']);
|
$linkItem = OCP\Share::getShareByToken($_POST['dirToken']);
|
||||||
if ($linkItem === false) {
|
if ($linkItem === false) {
|
||||||
|
@ -45,7 +46,7 @@ if (empty($_POST['dirToken'])) {
|
||||||
$dir = sprintf(
|
$dir = sprintf(
|
||||||
"/%s/%s",
|
"/%s/%s",
|
||||||
$path,
|
$path,
|
||||||
isset($_POST['subdir']) ? $_POST['subdir'] : ''
|
$public_directory
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!$dir || empty($dir) || $dir === false) {
|
if (!$dir || empty($dir) || $dir === false) {
|
||||||
|
@ -113,6 +114,13 @@ if (strpos($dir, '..') === false) {
|
||||||
$target = \OC\Files\Filesystem::normalizePath(stripslashes($dir).'/'.$files['name'][$i]);
|
$target = \OC\Files\Filesystem::normalizePath(stripslashes($dir).'/'.$files['name'][$i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$directory = \OC\Files\Filesystem::normalizePath(stripslashes($dir));
|
||||||
|
if (isset($public_directory)) {
|
||||||
|
// If we are uploading from the public app,
|
||||||
|
// we want to send the relative path in the ajax request.
|
||||||
|
$directory = $public_directory;
|
||||||
|
}
|
||||||
|
|
||||||
if ( ! \OC\Files\Filesystem::file_exists($target)
|
if ( ! \OC\Files\Filesystem::file_exists($target)
|
||||||
|| (isset($_POST['resolution']) && $_POST['resolution']==='replace')
|
|| (isset($_POST['resolution']) && $_POST['resolution']==='replace')
|
||||||
) {
|
) {
|
||||||
|
@ -140,7 +148,7 @@ if (strpos($dir, '..') === false) {
|
||||||
'uploadMaxFilesize' => $maxUploadFileSize,
|
'uploadMaxFilesize' => $maxUploadFileSize,
|
||||||
'maxHumanFilesize' => $maxHumanFileSize,
|
'maxHumanFilesize' => $maxHumanFileSize,
|
||||||
'permissions' => $meta['permissions'] & $allowedPermissions,
|
'permissions' => $meta['permissions'] & $allowedPermissions,
|
||||||
'directory' => \OC\Files\Filesystem::normalizePath(stripslashes($dir)),
|
'directory' => $directory,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,7 +176,7 @@ if (strpos($dir, '..') === false) {
|
||||||
'uploadMaxFilesize' => $maxUploadFileSize,
|
'uploadMaxFilesize' => $maxUploadFileSize,
|
||||||
'maxHumanFilesize' => $maxHumanFileSize,
|
'maxHumanFilesize' => $maxHumanFileSize,
|
||||||
'permissions' => $meta['permissions'] & $allowedPermissions,
|
'permissions' => $meta['permissions'] & $allowedPermissions,
|
||||||
'directory' => \OC\Files\Filesystem::normalizePath(stripslashes($dir)),
|
'directory' => $directory,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,7 @@ class Scan extends Command {
|
||||||
|
|
||||||
protected function execute(InputInterface $input, OutputInterface $output) {
|
protected function execute(InputInterface $input, OutputInterface $output) {
|
||||||
if ($input->getOption('all')) {
|
if ($input->getOption('all')) {
|
||||||
|
\OC_App::loadApps('authentication');
|
||||||
$users = $this->userManager->search('');
|
$users = $this->userManager->search('');
|
||||||
} else {
|
} else {
|
||||||
$users = $input->getArgument('user_id');
|
$users = $input->getArgument('user_id');
|
||||||
|
|
|
@ -84,9 +84,26 @@
|
||||||
background-color: rgb(240,240,240);
|
background-color: rgb(240,240,240);
|
||||||
}
|
}
|
||||||
tbody a { color:#000; }
|
tbody a { color:#000; }
|
||||||
span.extension, span.uploading, td.date { color:#999; }
|
|
||||||
span.extension { text-transform:lowercase; -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=70)"; filter:alpha(opacity=70); opacity:.7; -webkit-transition:opacity 300ms; -moz-transition:opacity 300ms; -o-transition:opacity 300ms; transition:opacity 300ms; }
|
span.extension, span.uploading, td.date {
|
||||||
tr:hover span.extension { -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"; filter:alpha(opacity=100); opacity:1; color:#777; }
|
color: #999;
|
||||||
|
}
|
||||||
|
span.extension {
|
||||||
|
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=70)";
|
||||||
|
filter: alpha(opacity=70);
|
||||||
|
opacity: .7;
|
||||||
|
-webkit-transition: opacity 300ms;
|
||||||
|
-moz-transition: opacity 300ms;
|
||||||
|
-o-transition: opacity 300ms;
|
||||||
|
transition: opacity 300ms;
|
||||||
|
}
|
||||||
|
tr:hover span.extension {
|
||||||
|
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
|
||||||
|
filter: alpha(opacity=100);
|
||||||
|
opacity: 1;
|
||||||
|
color: #777;
|
||||||
|
}
|
||||||
|
|
||||||
table tr.mouseOver td { background-color:#eee; }
|
table tr.mouseOver td { background-color:#eee; }
|
||||||
table th { height:24px; padding:0 8px; color:#999; }
|
table th { height:24px; padding:0 8px; color:#999; }
|
||||||
table th .name {
|
table th .name {
|
||||||
|
|
|
@ -5,14 +5,14 @@ namespace OCA\Files;
|
||||||
class Helper
|
class Helper
|
||||||
{
|
{
|
||||||
public static function buildFileStorageStatistics($dir) {
|
public static function buildFileStorageStatistics($dir) {
|
||||||
$l = new \OC_L10N('files');
|
|
||||||
$maxUploadFilesize = \OCP\Util::maxUploadFilesize($dir);
|
|
||||||
$maxHumanFilesize = \OCP\Util::humanFileSize($maxUploadFilesize);
|
|
||||||
$maxHumanFilesize = $l->t('Upload') . ' max. ' . $maxHumanFilesize;
|
|
||||||
|
|
||||||
// information about storage capacities
|
// information about storage capacities
|
||||||
$storageInfo = \OC_Helper::getStorageInfo($dir);
|
$storageInfo = \OC_Helper::getStorageInfo($dir);
|
||||||
|
|
||||||
|
$l = new \OC_L10N('files');
|
||||||
|
$maxUploadFilesize = \OCP\Util::maxUploadFilesize($dir, $storageInfo['free']);
|
||||||
|
$maxHumanFilesize = \OCP\Util::humanFileSize($maxUploadFilesize);
|
||||||
|
$maxHumanFilesize = $l->t('Upload') . ' max. ' . $maxHumanFilesize;
|
||||||
|
|
||||||
return array('uploadMaxFilesize' => $maxUploadFilesize,
|
return array('uploadMaxFilesize' => $maxUploadFilesize,
|
||||||
'maxHumanFilesize' => $maxHumanFilesize,
|
'maxHumanFilesize' => $maxHumanFilesize,
|
||||||
'freeSpace' => $storageInfo['free'],
|
'freeSpace' => $storageInfo['free'],
|
||||||
|
|
|
@ -13,16 +13,14 @@ use OCA\Encryption\Util;
|
||||||
$loginname = isset($_POST['user']) ? $_POST['user'] : '';
|
$loginname = isset($_POST['user']) ? $_POST['user'] : '';
|
||||||
$password = isset($_POST['password']) ? $_POST['password'] : '';
|
$password = isset($_POST['password']) ? $_POST['password'] : '';
|
||||||
|
|
||||||
$migrationCompleted = true;
|
$migrationStatus = Util::MIGRATION_COMPLETED;
|
||||||
|
|
||||||
if ($loginname !== '' && $password !== '') {
|
if ($loginname !== '' && $password !== '') {
|
||||||
$username = \OCP\User::checkPassword($loginname, $password);
|
$username = \OCP\User::checkPassword($loginname, $password);
|
||||||
if ($username) {
|
if ($username) {
|
||||||
$util = new Util(new \OC_FilesystemView('/'), $username);
|
$util = new Util(new \OC_FilesystemView('/'), $username);
|
||||||
if ($util->getMigrationStatus() !== Util::MIGRATION_COMPLETED) {
|
$migrationStatus = $util->getMigrationStatus();
|
||||||
$migrationCompleted = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
\OCP\JSON::success(array('data' => array('migrationCompleted' => $migrationCompleted)));
|
\OCP\JSON::success(array('data' => array('migrationStatus' => $migrationStatus)));
|
||||||
|
|
|
@ -10,6 +10,7 @@ OC::$CLASSPATH['OCA\Encryption\Session'] = 'files_encryption/lib/session.php';
|
||||||
OC::$CLASSPATH['OCA\Encryption\Capabilities'] = 'files_encryption/lib/capabilities.php';
|
OC::$CLASSPATH['OCA\Encryption\Capabilities'] = 'files_encryption/lib/capabilities.php';
|
||||||
OC::$CLASSPATH['OCA\Encryption\Helper'] = 'files_encryption/lib/helper.php';
|
OC::$CLASSPATH['OCA\Encryption\Helper'] = 'files_encryption/lib/helper.php';
|
||||||
|
|
||||||
|
\OCP\Util::addscript('files_encryption', 'encryption');
|
||||||
\OCP\Util::addscript('files_encryption', 'detect-migration');
|
\OCP\Util::addscript('files_encryption', 'detect-migration');
|
||||||
|
|
||||||
if (!OC_Config::getValue('maintenance', false)) {
|
if (!OC_Config::getValue('maintenance', false)) {
|
||||||
|
|
|
@ -85,10 +85,9 @@ class Hooks {
|
||||||
$ready = $util->beginMigration();
|
$ready = $util->beginMigration();
|
||||||
} elseif ($migrationStatus === Util::MIGRATION_IN_PROGRESS) {
|
} elseif ($migrationStatus === Util::MIGRATION_IN_PROGRESS) {
|
||||||
// refuse login as long as the initial encryption is running
|
// refuse login as long as the initial encryption is running
|
||||||
while ($migrationStatus === Util::MIGRATION_IN_PROGRESS) {
|
sleep(5);
|
||||||
sleep(60);
|
\OCP\User::logout();
|
||||||
$migrationStatus = $util->getMigrationStatus();
|
return false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If migration not yet done
|
// If migration not yet done
|
||||||
|
@ -109,22 +108,28 @@ class Hooks {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encrypt existing user files:
|
// Encrypt existing user files
|
||||||
if (
|
try {
|
||||||
$util->encryptAll('/' . $params['uid'] . '/' . 'files', $session->getLegacyKey(), $params['password'])
|
$result = $util->encryptAll('/' . $params['uid'] . '/' . 'files', $session->getLegacyKey(), $params['password']);
|
||||||
) {
|
} catch (\Exception $ex) {
|
||||||
|
\OCP\Util::writeLog('Encryption library', 'Initial encryption failed! Error: ' . $ex->getMessage(), \OCP\Util::FATAL);
|
||||||
|
$util->resetMigrationStatus();
|
||||||
|
\OCP\User::logout();
|
||||||
|
$result = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($result) {
|
||||||
|
|
||||||
\OC_Log::write(
|
\OC_Log::write(
|
||||||
'Encryption library', 'Encryption of existing files belonging to "' . $params['uid'] . '" completed'
|
'Encryption library', 'Encryption of existing files belonging to "' . $params['uid'] . '" completed'
|
||||||
, \OC_Log::INFO
|
, \OC_Log::INFO
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register successful migration in DB
|
// Register successful migration in DB
|
||||||
$util->finishMigration();
|
$util->finishMigration();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
|
@ -17,10 +17,14 @@ $(document).ready(function(){
|
||||||
data: {user: user, password: password},
|
data: {user: user, password: password},
|
||||||
async: false,
|
async: false,
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
if (response.data.migrationCompleted === false) {
|
if (response.data.migrationStatus === OC.Encryption.MIGRATION_OPEN) {
|
||||||
var message = t('files_encryption', 'Initial encryption started... This can take some time. Please wait.');
|
var message = t('files_encryption', 'Initial encryption started... This can take some time. Please wait.');
|
||||||
$('#messageText').text(message);
|
$('#messageText').text(message);
|
||||||
$('#message').removeClass('hidden').addClass('update');
|
$('#message').removeClass('hidden').addClass('update');
|
||||||
|
} else if (response.data.migrationStatus === OC.Encryption.MIGRATION_IN_PROGRESS) {
|
||||||
|
var message = t('files_encryption', 'Initial encryption running... Please try again later.');
|
||||||
|
$('#messageText').text(message);
|
||||||
|
$('#message').removeClass('hidden').addClass('update');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -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,
|
||||||
|
};
|
|
@ -283,7 +283,7 @@ class Proxy extends \OC_FileProxy {
|
||||||
public function postGetFileInfo($path, $data) {
|
public function postGetFileInfo($path, $data) {
|
||||||
|
|
||||||
// if path is a folder do nothing
|
// if path is a folder do nothing
|
||||||
if (\OCP\App::isEnabled('files_encryption') && is_array($data) && array_key_exists('size', $data)) {
|
if (\OCP\App::isEnabled('files_encryption') && $data !== false && array_key_exists('size', $data)) {
|
||||||
|
|
||||||
// Disable encryption proxy to prevent recursive calls
|
// Disable encryption proxy to prevent recursive calls
|
||||||
$proxyStatus = \OC_FileProxy::$enabled;
|
$proxyStatus = \OC_FileProxy::$enabled;
|
||||||
|
@ -341,7 +341,7 @@ class Proxy extends \OC_FileProxy {
|
||||||
}
|
}
|
||||||
|
|
||||||
// if file is encrypted return real file size
|
// if file is encrypted return real file size
|
||||||
if (is_array($fileInfo) && $fileInfo['encrypted'] === true) {
|
if ($fileInfo && $fileInfo['encrypted'] === true) {
|
||||||
// try to fix unencrypted file size if it doesn't look plausible
|
// try to fix unencrypted file size if it doesn't look plausible
|
||||||
if ((int)$fileInfo['size'] > 0 && (int)$fileInfo['unencrypted_size'] === 0 ) {
|
if ((int)$fileInfo['size'] > 0 && (int)$fileInfo['unencrypted_size'] === 0 ) {
|
||||||
$fixSize = $util->getFileSize($path);
|
$fixSize = $util->getFileSize($path);
|
||||||
|
@ -354,7 +354,7 @@ class Proxy extends \OC_FileProxy {
|
||||||
$size = $fileInfo['unencrypted_size'];
|
$size = $fileInfo['unencrypted_size'];
|
||||||
} else {
|
} else {
|
||||||
// self healing if file was removed from file cache
|
// self healing if file was removed from file cache
|
||||||
if (!is_array($fileInfo)) {
|
if (!$fileInfo) {
|
||||||
$fileInfo = array();
|
$fileInfo = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -567,7 +567,7 @@ class Stream {
|
||||||
|
|
||||||
// get file info
|
// get file info
|
||||||
$fileInfo = $this->rootView->getFileInfo($path);
|
$fileInfo = $this->rootView->getFileInfo($path);
|
||||||
if (is_array($fileInfo)) {
|
if ($fileInfo) {
|
||||||
// set encryption data
|
// set encryption data
|
||||||
$fileInfo['encrypted'] = true;
|
$fileInfo['encrypted'] = true;
|
||||||
$fileInfo['size'] = $this->size;
|
$fileInfo['size'] = $this->size;
|
||||||
|
|
|
@ -316,7 +316,8 @@ class Util {
|
||||||
$found = array(
|
$found = array(
|
||||||
'plain' => array(),
|
'plain' => array(),
|
||||||
'encrypted' => array(),
|
'encrypted' => array(),
|
||||||
'legacy' => array()
|
'legacy' => array(),
|
||||||
|
'broken' => array(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,10 +328,7 @@ class Util {
|
||||||
if(is_resource($handle)) {
|
if(is_resource($handle)) {
|
||||||
while (false !== ($file = readdir($handle))) {
|
while (false !== ($file = readdir($handle))) {
|
||||||
|
|
||||||
if (
|
if ($file !== "." && $file !== "..") {
|
||||||
$file !== "."
|
|
||||||
&& $file !== ".."
|
|
||||||
) {
|
|
||||||
|
|
||||||
$filePath = $directory . '/' . $this->view->getRelativePath('/' . $file);
|
$filePath = $directory . '/' . $this->view->getRelativePath('/' . $file);
|
||||||
$relPath = \OCA\Encryption\Helper::stripUserFilesPath($filePath);
|
$relPath = \OCA\Encryption\Helper::stripUserFilesPath($filePath);
|
||||||
|
@ -357,15 +355,23 @@ class Util {
|
||||||
// NOTE: This is inefficient;
|
// NOTE: This is inefficient;
|
||||||
// scanning every file like this
|
// scanning every file like this
|
||||||
// will eat server resources :(
|
// will eat server resources :(
|
||||||
if (
|
if ($isEncryptedPath) {
|
||||||
Keymanager::getFileKey($this->view, $this, $relPath)
|
|
||||||
&& $isEncryptedPath
|
|
||||||
) {
|
|
||||||
|
|
||||||
|
$fileKey = Keymanager::getFileKey($this->view, $this, $relPath);
|
||||||
|
$shareKey = Keymanager::getShareKey($this->view, $this->userId, $this, $relPath);
|
||||||
|
// if file is encrypted but now file key is available, throw exception
|
||||||
|
if ($fileKey === false || $shareKey === false) {
|
||||||
|
\OCP\Util::writeLog('encryption library', 'No keys available to decrypt the file: ' . $filePath, \OCP\Util::ERROR);
|
||||||
|
$found['broken'][] = array(
|
||||||
|
'name' => $file,
|
||||||
|
'path' => $filePath,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
$found['encrypted'][] = array(
|
$found['encrypted'][] = array(
|
||||||
'name' => $file,
|
'name' => $file,
|
||||||
'path' => $filePath
|
'path' => $filePath,
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// If the file uses old
|
// If the file uses old
|
||||||
// encryption system
|
// encryption system
|
||||||
|
@ -771,6 +777,12 @@ class Util {
|
||||||
$successful = false;
|
$successful = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if there are broken encrypted files than the complete decryption
|
||||||
|
// was not successful
|
||||||
|
if (!empty($found['broken'])) {
|
||||||
|
$successful = false;
|
||||||
|
}
|
||||||
|
|
||||||
if ($successful) {
|
if ($successful) {
|
||||||
$this->view->deleteAll($this->keyfilesPath);
|
$this->view->deleteAll($this->keyfilesPath);
|
||||||
$this->view->deleteAll($this->shareKeysPath);
|
$this->view->deleteAll($this->shareKeysPath);
|
||||||
|
@ -1185,27 +1197,49 @@ class Util {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief set migration status
|
||||||
|
* @param int $status
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
private function setMigrationStatus($status) {
|
||||||
|
|
||||||
|
$sql = 'UPDATE `*PREFIX*encryption` SET `migration_status` = ? WHERE `uid` = ?';
|
||||||
|
$args = array($status, $this->userId);
|
||||||
|
$query = \OCP\DB::prepare($sql);
|
||||||
|
$manipulatedRows = $query->execute($args);
|
||||||
|
|
||||||
|
if ($manipulatedRows === 1) {
|
||||||
|
$result = true;
|
||||||
|
\OCP\Util::writeLog('Encryption library', "Migration status set to " . self::MIGRATION_OPEN, \OCP\Util::INFO);
|
||||||
|
} else {
|
||||||
|
$result = false;
|
||||||
|
\OCP\Util::writeLog('Encryption library', "Could not set migration status to " . self::MIGRATION_OPEN, \OCP\Util::WARN);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief start migration mode to initially encrypt users data
|
* @brief start migration mode to initially encrypt users data
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function beginMigration() {
|
public function beginMigration() {
|
||||||
|
|
||||||
$return = false;
|
$result = $this->setMigrationStatus(self::MIGRATION_IN_PROGRESS);
|
||||||
|
|
||||||
$sql = 'UPDATE `*PREFIX*encryption` SET `migration_status` = ? WHERE `uid` = ? and `migration_status` = ?';
|
if ($result) {
|
||||||
$args = array(self::MIGRATION_IN_PROGRESS, $this->userId, self::MIGRATION_OPEN);
|
|
||||||
$query = \OCP\DB::prepare($sql);
|
|
||||||
$manipulatedRows = $query->execute($args);
|
|
||||||
|
|
||||||
if ($manipulatedRows === 1) {
|
|
||||||
$return = true;
|
|
||||||
\OCP\Util::writeLog('Encryption library', "Start migration to encryption mode for " . $this->userId, \OCP\Util::INFO);
|
\OCP\Util::writeLog('Encryption library', "Start migration to encryption mode for " . $this->userId, \OCP\Util::INFO);
|
||||||
} else {
|
} else {
|
||||||
\OCP\Util::writeLog('Encryption library', "Could not activate migration mode for " . $this->userId . ". Probably another process already started the initial encryption", \OCP\Util::WARN);
|
\OCP\Util::writeLog('Encryption library', "Could not activate migration mode for " . $this->userId . ". Probably another process already started the initial encryption", \OCP\Util::WARN);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function resetMigrationStatus() {
|
||||||
|
return $this->setMigrationStatus(self::MIGRATION_OPEN);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1213,22 +1247,15 @@ class Util {
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function finishMigration() {
|
public function finishMigration() {
|
||||||
|
$result = $this->setMigrationStatus(self::MIGRATION_COMPLETED);
|
||||||
|
|
||||||
$return = false;
|
if ($result) {
|
||||||
|
|
||||||
$sql = 'UPDATE `*PREFIX*encryption` SET `migration_status` = ? WHERE `uid` = ? and `migration_status` = ?';
|
|
||||||
$args = array(self::MIGRATION_COMPLETED, $this->userId, self::MIGRATION_IN_PROGRESS);
|
|
||||||
$query = \OCP\DB::prepare($sql);
|
|
||||||
$manipulatedRows = $query->execute($args);
|
|
||||||
|
|
||||||
if ($manipulatedRows === 1) {
|
|
||||||
$return = true;
|
|
||||||
\OCP\Util::writeLog('Encryption library', "Finish migration successfully for " . $this->userId, \OCP\Util::INFO);
|
\OCP\Util::writeLog('Encryption library', "Finish migration successfully for " . $this->userId, \OCP\Util::INFO);
|
||||||
} else {
|
} else {
|
||||||
\OCP\Util::writeLog('Encryption library', "Could not deactivate migration mode for " . $this->userId, \OCP\Util::WARN);
|
\OCP\Util::writeLog('Encryption library', "Could not deactivate migration mode for " . $this->userId, \OCP\Util::WARN);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -203,7 +203,7 @@ class Test_Encryption_Hooks extends \PHPUnit_Framework_TestCase {
|
||||||
$fileInfo = $this->user1View->getFileInfo($this->filename);
|
$fileInfo = $this->user1View->getFileInfo($this->filename);
|
||||||
|
|
||||||
// check if we have a valid file info
|
// check if we have a valid file info
|
||||||
$this->assertTrue(is_array($fileInfo));
|
$this->assertTrue($fileInfo instanceof \OC\Files\FileInfo);
|
||||||
|
|
||||||
// share the file with user2
|
// share the file with user2
|
||||||
\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_HOOKS_USER2, OCP\PERMISSION_ALL);
|
\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_HOOKS_USER2, OCP\PERMISSION_ALL);
|
||||||
|
|
|
@ -150,7 +150,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
|
||||||
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
|
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
|
||||||
|
|
||||||
// check if we have a valid file info
|
// check if we have a valid file info
|
||||||
$this->assertTrue(is_array($fileInfo));
|
$this->assertTrue($fileInfo instanceof \OC\Files\FileInfo);
|
||||||
|
|
||||||
// check if the unencrypted file size is stored
|
// check if the unencrypted file size is stored
|
||||||
$this->assertGreaterThan(0, $fileInfo['unencrypted_size']);
|
$this->assertGreaterThan(0, $fileInfo['unencrypted_size']);
|
||||||
|
@ -310,7 +310,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
|
||||||
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1);
|
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1);
|
||||||
|
|
||||||
// check if we have a valid file info
|
// check if we have a valid file info
|
||||||
$this->assertTrue(is_array($fileInfo));
|
$this->assertTrue($fileInfo instanceof \OC\Files\FileInfo);
|
||||||
|
|
||||||
// re-enable the file proxy
|
// re-enable the file proxy
|
||||||
\OC_FileProxy::$enabled = $proxyStatus;
|
\OC_FileProxy::$enabled = $proxyStatus;
|
||||||
|
@ -388,7 +388,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
|
||||||
. $this->subfolder);
|
. $this->subfolder);
|
||||||
|
|
||||||
// check if we have a valid file info
|
// check if we have a valid file info
|
||||||
$this->assertTrue(is_array($fileInfoSubFolder));
|
$this->assertTrue($fileInfoSubFolder instanceof \OC\Files\FileInfo);
|
||||||
|
|
||||||
// re-enable the file proxy
|
// re-enable the file proxy
|
||||||
\OC_FileProxy::$enabled = $proxyStatus;
|
\OC_FileProxy::$enabled = $proxyStatus;
|
||||||
|
@ -422,7 +422,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
|
||||||
. $this->subsubfolder . '/' . $this->filename);
|
. $this->subsubfolder . '/' . $this->filename);
|
||||||
|
|
||||||
// check if we have fileInfos
|
// check if we have fileInfos
|
||||||
$this->assertTrue(is_array($fileInfo));
|
$this->assertTrue($fileInfo instanceof \OC\Files\FileInfo);
|
||||||
|
|
||||||
// share the file with user3
|
// share the file with user3
|
||||||
\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4, OCP\PERMISSION_ALL);
|
\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4, OCP\PERMISSION_ALL);
|
||||||
|
@ -517,7 +517,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
|
||||||
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
|
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
|
||||||
|
|
||||||
// check if we have a valid file info
|
// check if we have a valid file info
|
||||||
$this->assertTrue(is_array($fileInfo));
|
$this->assertTrue($fileInfo instanceof \OC\Files\FileInfo);
|
||||||
|
|
||||||
// check if the unencrypted file size is stored
|
// check if the unencrypted file size is stored
|
||||||
$this->assertGreaterThan(0, $fileInfo['unencrypted_size']);
|
$this->assertGreaterThan(0, $fileInfo['unencrypted_size']);
|
||||||
|
@ -595,7 +595,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
|
||||||
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
|
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
|
||||||
|
|
||||||
// check if we have a valid file info
|
// check if we have a valid file info
|
||||||
$this->assertTrue(is_array($fileInfo));
|
$this->assertTrue($fileInfo instanceof \OC\Files\FileInfo);
|
||||||
|
|
||||||
// check if the unencrypted file size is stored
|
// check if the unencrypted file size is stored
|
||||||
$this->assertGreaterThan(0, $fileInfo['unencrypted_size']);
|
$this->assertGreaterThan(0, $fileInfo['unencrypted_size']);
|
||||||
|
@ -888,7 +888,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
|
||||||
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
|
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
|
||||||
|
|
||||||
// check if we have a valid file info
|
// check if we have a valid file info
|
||||||
$this->assertTrue(is_array($fileInfo));
|
$this->assertTrue($fileInfo instanceof \OC\Files\FileInfo);
|
||||||
|
|
||||||
// check if the unencrypted file size is stored
|
// check if the unencrypted file size is stored
|
||||||
$this->assertGreaterThan(0, $fileInfo['unencrypted_size']);
|
$this->assertGreaterThan(0, $fileInfo['unencrypted_size']);
|
||||||
|
|
|
@ -64,6 +64,8 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
|
||||||
function setUp() {
|
function setUp() {
|
||||||
|
// login user
|
||||||
|
\Test_Encryption_Util::loginHelper(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1);
|
||||||
\OC_User::setUserId(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1);
|
\OC_User::setUserId(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1);
|
||||||
$this->userId = \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1;
|
$this->userId = \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1;
|
||||||
$this->pass = \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1;
|
$this->pass = \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1;
|
||||||
|
@ -328,7 +330,7 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
$fileInfoUnencrypted = $this->view->getFileInfo($this->userId . '/files/' . $filename);
|
$fileInfoUnencrypted = $this->view->getFileInfo($this->userId . '/files/' . $filename);
|
||||||
|
|
||||||
$this->assertTrue(is_array($fileInfoUnencrypted));
|
$this->assertTrue($fileInfoUnencrypted instanceof \OC\Files\FileInfo);
|
||||||
|
|
||||||
// enable file encryption again
|
// enable file encryption again
|
||||||
\OC_App::enable('files_encryption');
|
\OC_App::enable('files_encryption');
|
||||||
|
@ -338,7 +340,7 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
$fileInfoEncrypted = $this->view->getFileInfo($this->userId . '/files/' . $filename);
|
$fileInfoEncrypted = $this->view->getFileInfo($this->userId . '/files/' . $filename);
|
||||||
|
|
||||||
$this->assertTrue(is_array($fileInfoEncrypted));
|
$this->assertTrue($fileInfoEncrypted instanceof \OC\Files\FileInfo);
|
||||||
|
|
||||||
// check if mtime and etags unchanged
|
// check if mtime and etags unchanged
|
||||||
$this->assertEquals($fileInfoEncrypted['mtime'], $fileInfoUnencrypted['mtime']);
|
$this->assertEquals($fileInfoEncrypted['mtime'], $fileInfoUnencrypted['mtime']);
|
||||||
|
@ -357,23 +359,98 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
$fileInfoEncrypted = $this->view->getFileInfo($this->userId . '/files/' . $filename);
|
$fileInfoEncrypted = $this->view->getFileInfo($this->userId . '/files/' . $filename);
|
||||||
|
|
||||||
$this->assertTrue(is_array($fileInfoEncrypted));
|
$this->assertTrue($fileInfoEncrypted instanceof \OC\Files\FileInfo);
|
||||||
|
$this->assertEquals($fileInfoEncrypted['encrypted'], 1);
|
||||||
|
|
||||||
// encrypt all unencrypted files
|
// decrypt all encrypted files
|
||||||
$util->decryptAll('/' . $this->userId . '/' . 'files');
|
$result = $util->decryptAll('/' . $this->userId . '/' . 'files');
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
|
||||||
$fileInfoUnencrypted = $this->view->getFileInfo($this->userId . '/files/' . $filename);
|
$fileInfoUnencrypted = $this->view->getFileInfo($this->userId . '/files/' . $filename);
|
||||||
|
|
||||||
$this->assertTrue(is_array($fileInfoUnencrypted));
|
$this->assertTrue($fileInfoUnencrypted instanceof \OC\Files\FileInfo);
|
||||||
|
|
||||||
// check if mtime and etags unchanged
|
// check if mtime and etags unchanged
|
||||||
$this->assertEquals($fileInfoEncrypted['mtime'], $fileInfoUnencrypted['mtime']);
|
$this->assertEquals($fileInfoEncrypted['mtime'], $fileInfoUnencrypted['mtime']);
|
||||||
$this->assertEquals($fileInfoEncrypted['etag'], $fileInfoUnencrypted['etag']);
|
$this->assertEquals($fileInfoEncrypted['etag'], $fileInfoUnencrypted['etag']);
|
||||||
|
// file should no longer be encrypted
|
||||||
|
$this->assertEquals(0, $fileInfoUnencrypted['encrypted']);
|
||||||
|
|
||||||
$this->view->unlink($this->userId . '/files/' . $filename);
|
$this->view->unlink($this->userId . '/files/' . $filename);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testDescryptAllWithBrokenFiles() {
|
||||||
|
|
||||||
|
$file1 = "/decryptAll1" . uniqid() . ".txt";
|
||||||
|
$file2 = "/decryptAll2" . uniqid() . ".txt";
|
||||||
|
|
||||||
|
$util = new Encryption\Util($this->view, $this->userId);
|
||||||
|
|
||||||
|
$this->view->file_put_contents($this->userId . '/files/' . $file1, $this->dataShort);
|
||||||
|
$this->view->file_put_contents($this->userId . '/files/' . $file2, $this->dataShort);
|
||||||
|
|
||||||
|
$fileInfoEncrypted1 = $this->view->getFileInfo($this->userId . '/files/' . $file1);
|
||||||
|
$fileInfoEncrypted2 = $this->view->getFileInfo($this->userId . '/files/' . $file2);
|
||||||
|
|
||||||
|
$this->assertTrue($fileInfoEncrypted1 instanceof \OC\Files\FileInfo);
|
||||||
|
$this->assertTrue($fileInfoEncrypted2 instanceof \OC\Files\FileInfo);
|
||||||
|
$this->assertEquals($fileInfoEncrypted1['encrypted'], 1);
|
||||||
|
$this->assertEquals($fileInfoEncrypted2['encrypted'], 1);
|
||||||
|
|
||||||
|
// rename keyfile for file1 so that the decryption for file1 fails
|
||||||
|
// Expected behaviour: decryptAll() returns false, file2 gets decrypted anyway
|
||||||
|
$this->view->rename($this->userId . '/files_encryption/keyfiles/' . $file1 . '.key',
|
||||||
|
$this->userId . '/files_encryption/keyfiles/' . $file1 . '.key.moved');
|
||||||
|
|
||||||
|
// decrypt all encrypted files
|
||||||
|
$result = $util->decryptAll('/' . $this->userId . '/' . 'files');
|
||||||
|
|
||||||
|
$this->assertFalse($result);
|
||||||
|
|
||||||
|
$fileInfoUnencrypted1 = $this->view->getFileInfo($this->userId . '/files/' . $file1);
|
||||||
|
$fileInfoUnencrypted2 = $this->view->getFileInfo($this->userId . '/files/' . $file2);
|
||||||
|
|
||||||
|
$this->assertTrue($fileInfoUnencrypted1 instanceof \OC\Files\FileInfo);
|
||||||
|
$this->assertTrue($fileInfoUnencrypted2 instanceof \OC\Files\FileInfo);
|
||||||
|
|
||||||
|
// file1 should be still encrypted; file2 should be decrypted
|
||||||
|
$this->assertEquals(1, $fileInfoUnencrypted1['encrypted']);
|
||||||
|
$this->assertEquals(0, $fileInfoUnencrypted2['encrypted']);
|
||||||
|
|
||||||
|
// keyfiles and share keys should still exist
|
||||||
|
$this->assertTrue($this->view->is_dir($this->userId . '/files_encryption/keyfiles/'));
|
||||||
|
$this->assertTrue($this->view->is_dir($this->userId . '/files_encryption/share-keys/'));
|
||||||
|
|
||||||
|
// rename the keyfile for file1 back
|
||||||
|
$this->view->rename($this->userId . '/files_encryption/keyfiles/' . $file1 . '.key.moved',
|
||||||
|
$this->userId . '/files_encryption/keyfiles/' . $file1 . '.key');
|
||||||
|
|
||||||
|
// try again to decrypt all encrypted files
|
||||||
|
$result = $util->decryptAll('/' . $this->userId . '/' . 'files');
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
|
||||||
|
$fileInfoUnencrypted1 = $this->view->getFileInfo($this->userId . '/files/' . $file1);
|
||||||
|
$fileInfoUnencrypted2 = $this->view->getFileInfo($this->userId . '/files/' . $file2);
|
||||||
|
|
||||||
|
$this->assertTrue($fileInfoUnencrypted1 instanceof \OC\Files\FileInfo);
|
||||||
|
$this->assertTrue($fileInfoUnencrypted2 instanceof \OC\Files\FileInfo);
|
||||||
|
|
||||||
|
// now both files should be decrypted
|
||||||
|
$this->assertEquals(0, $fileInfoUnencrypted1['encrypted']);
|
||||||
|
$this->assertEquals(0, $fileInfoUnencrypted2['encrypted']);
|
||||||
|
|
||||||
|
// keyfiles and share keys should be deleted
|
||||||
|
$this->assertFalse($this->view->is_dir($this->userId . '/files_encryption/keyfiles/'));
|
||||||
|
$this->assertFalse($this->view->is_dir($this->userId . '/files_encryption/share-keys/'));
|
||||||
|
|
||||||
|
$this->view->unlink($this->userId . '/files/' . $file1);
|
||||||
|
$this->view->unlink($this->userId . '/files/' . $file2);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @large
|
* @large
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -69,7 +69,7 @@ class OC_Mount_Config {
|
||||||
if(OC_Mount_Config::checkphpftp()) $backends['\OC\Files\Storage\FTP']=array(
|
if(OC_Mount_Config::checkphpftp()) $backends['\OC\Files\Storage\FTP']=array(
|
||||||
'backend' => 'FTP',
|
'backend' => 'FTP',
|
||||||
'configuration' => array(
|
'configuration' => array(
|
||||||
'host' => 'URL',
|
'host' => 'Hostname',
|
||||||
'user' => 'Username',
|
'user' => 'Username',
|
||||||
'password' => '*Password',
|
'password' => '*Password',
|
||||||
'root' => '&Root',
|
'root' => '&Root',
|
||||||
|
|
|
@ -11,7 +11,7 @@ if(!\OC_App::isEnabled('files_sharing')){
|
||||||
|
|
||||||
\OC_User::setIncognitoMode(true);
|
\OC_User::setIncognitoMode(true);
|
||||||
|
|
||||||
$file = array_key_exists('file', $_GET) ? (string) urldecode($_GET['file']) : '';
|
$file = array_key_exists('file', $_GET) ? (string) $_GET['file'] : '';
|
||||||
$maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '36';
|
$maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '36';
|
||||||
$maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '36';
|
$maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '36';
|
||||||
$scalingUp = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true;
|
$scalingUp = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true;
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<div id="imgframe">
|
<div id="imgframe">
|
||||||
<?php $size = \OC\Preview::isMimeSupported($_['mimetype']) ? 500 : 128 ?>
|
<?php $size = \OC\Preview::isMimeSupported($_['mimetype']) ? 500 : 128 ?>
|
||||||
<img src="<?php p(OCP\Util::linkToRoute( 'core_ajax_public_preview', array('x' => $size, 'y' => $size, 'file' => urlencode($_['directory_path']), 't' => $_['dirToken']))); ?>" class="publicpreview"/>
|
<img src="<?php p(OCP\Util::linkToRoute( 'core_ajax_public_preview', array('x' => $size, 'y' => $size, 'file' => $_['directory_path'], 't' => $_['dirToken']))); ?>" class="publicpreview"/>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<div class="directDownload">
|
<div class="directDownload">
|
||||||
|
|
|
@ -11,7 +11,7 @@ if(!\OC_App::isEnabled('files_trashbin')){
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$file = array_key_exists('file', $_GET) ? (string) urldecode($_GET['file']) : '';
|
$file = array_key_exists('file', $_GET) ? (string) $_GET['file'] : '';
|
||||||
$maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '44';
|
$maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '44';
|
||||||
$maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '44';
|
$maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '44';
|
||||||
$scalingUp = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true;
|
$scalingUp = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true;
|
||||||
|
|
|
@ -996,6 +996,6 @@ class Trashbin {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function preview_icon($path) {
|
public static function preview_icon($path) {
|
||||||
return \OC_Helper::linkToRoute( 'core_ajax_trashbin_preview', array('x' => 36, 'y' => 36, 'file' => urlencode($path) ));
|
return \OC_Helper::linkToRoute( 'core_ajax_trashbin_preview', array('x' => 36, 'y' => 36, 'file' => $path ));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
*/
|
*/
|
||||||
\OC_Util::checkLoggedIn();
|
\OC_Util::checkLoggedIn();
|
||||||
|
|
||||||
$file = array_key_exists('file', $_GET) ? (string) urldecode($_GET['file']) : '';
|
$file = array_key_exists('file', $_GET) ? (string) $_GET['file'] : '';
|
||||||
$maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '36';
|
$maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '36';
|
||||||
$maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '36';
|
$maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '36';
|
||||||
$scalingUp = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true;
|
$scalingUp = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true;
|
||||||
|
|
|
@ -354,6 +354,10 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$sorter = new \OC\Share\SearchResultSorter($_GET['search'],
|
||||||
|
'label',
|
||||||
|
new \OC\Log());
|
||||||
|
usort($shareWith, array($sorter, 'sort'));
|
||||||
OC_JSON::success(array('data' => $shareWith));
|
OC_JSON::success(array('data' => $shareWith));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
4
cron.php
4
cron.php
|
@ -97,7 +97,7 @@ try {
|
||||||
touch(TemporaryCronClass::$lockfile);
|
touch(TemporaryCronClass::$lockfile);
|
||||||
|
|
||||||
// Work
|
// Work
|
||||||
$jobList = new \OC\BackgroundJob\JobList();
|
$jobList = \OC::$server->getJobList();
|
||||||
$jobs = $jobList->getAll();
|
$jobs = $jobList->getAll();
|
||||||
foreach ($jobs as $job) {
|
foreach ($jobs as $job) {
|
||||||
$job->execute($jobList, $logger);
|
$job->execute($jobList, $logger);
|
||||||
|
@ -109,7 +109,7 @@ try {
|
||||||
OC_JSON::error(array('data' => array('message' => 'Backgroundjobs are using system cron!')));
|
OC_JSON::error(array('data' => array('message' => 'Backgroundjobs are using system cron!')));
|
||||||
} else {
|
} else {
|
||||||
// Work and success :-)
|
// Work and success :-)
|
||||||
$jobList = new \OC\BackgroundJob\JobList();
|
$jobList = \OC::$server->getJobList();
|
||||||
$job = $jobList->getNext();
|
$job = $jobList->getNext();
|
||||||
$job->execute($jobList, $logger);
|
$job->execute($jobList, $logger);
|
||||||
$jobList->setLastJob($job);
|
$jobList->setLastJob($job);
|
||||||
|
|
|
@ -33,15 +33,56 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace OC;
|
||||||
|
|
||||||
|
use \OC\DB\Connection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides an easy way for apps to store config values in the
|
* This class provides an easy way for apps to store config values in the
|
||||||
* database.
|
* database.
|
||||||
*/
|
*/
|
||||||
class OC_Appconfig {
|
class AppConfig implements \OCP\IAppConfig {
|
||||||
|
/**
|
||||||
|
* @var \OC\DB\Connection $conn
|
||||||
|
*/
|
||||||
|
protected $conn;
|
||||||
|
|
||||||
private static $cache = array();
|
private $cache = array();
|
||||||
|
|
||||||
private static $appsLoaded = array();
|
private $appsLoaded = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \OC\DB\Connection $conn
|
||||||
|
*/
|
||||||
|
public function __construct(Connection $conn) {
|
||||||
|
$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
|
* @brief Get all apps using the config
|
||||||
|
@ -50,16 +91,14 @@ class OC_Appconfig {
|
||||||
* This function returns a list of all apps that have at least one
|
* This function returns a list of all apps that have at least one
|
||||||
* entry in the appconfig table.
|
* entry in the appconfig table.
|
||||||
*/
|
*/
|
||||||
public static function getApps() {
|
public function getApps() {
|
||||||
// No magic in here!
|
$query = 'SELECT DISTINCT `appid` FROM `*PREFIX*appconfig` ORDER BY `appid`';
|
||||||
$query = OC_DB::prepare('SELECT DISTINCT `appid` FROM `*PREFIX*appconfig` ORDER BY `appid`');
|
$result = $this->conn->executeQuery($query);
|
||||||
$result = $query->execute();
|
|
||||||
|
|
||||||
$apps = array();
|
$apps = array();
|
||||||
while ($row = $result->fetchRow()) {
|
while ($appid = $result->fetchColumn()) {
|
||||||
$apps[] = $row["appid"];
|
$apps[] = $appid;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $apps;
|
return $apps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,35 +110,13 @@ class OC_Appconfig {
|
||||||
* This function gets all keys of an app. Please note that the values are
|
* This function gets all keys of an app. Please note that the values are
|
||||||
* not returned.
|
* not returned.
|
||||||
*/
|
*/
|
||||||
public static function getKeys($app) {
|
public function getKeys($app) {
|
||||||
// No magic in here as well
|
$values = $this->getAppValues($app);
|
||||||
$query = OC_DB::prepare('SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?');
|
$keys = array_keys($values);
|
||||||
$result = $query->execute(array($app));
|
sort($keys);
|
||||||
|
|
||||||
$keys = array();
|
|
||||||
while ($row = $result->fetchRow()) {
|
|
||||||
$keys[] = $row["configkey"];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $keys;
|
return $keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function getAppValues($app) {
|
|
||||||
if (!isset(self::$cache[$app])) {
|
|
||||||
self::$cache[$app] = array();
|
|
||||||
}
|
|
||||||
if (array_search($app, self::$appsLoaded) === false) {
|
|
||||||
$query = OC_DB::prepare('SELECT `configvalue`, `configkey` FROM `*PREFIX*appconfig`'
|
|
||||||
. ' WHERE `appid` = ?');
|
|
||||||
$result = $query->execute(array($app));
|
|
||||||
while ($row = $result->fetchRow()) {
|
|
||||||
self::$cache[$app][$row['configkey']] = $row['configvalue'];
|
|
||||||
}
|
|
||||||
self::$appsLoaded[] = $app;
|
|
||||||
}
|
|
||||||
return self::$cache[$app];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Gets the config value
|
* @brief Gets the config value
|
||||||
* @param string $app app
|
* @param string $app app
|
||||||
|
@ -110,18 +127,11 @@ class OC_Appconfig {
|
||||||
* This function gets a value from the appconfig table. If the key does
|
* This function gets a value from the appconfig table. If the key does
|
||||||
* not exist the default value will be returned
|
* not exist the default value will be returned
|
||||||
*/
|
*/
|
||||||
public static function getValue($app, $key, $default = null) {
|
public function getValue($app, $key, $default = null) {
|
||||||
if (!isset(self::$cache[$app])) {
|
$values = $this->getAppValues($app);
|
||||||
self::$cache[$app] = array();
|
|
||||||
}
|
|
||||||
if (isset(self::$cache[$app][$key])) {
|
|
||||||
return self::$cache[$app][$key];
|
|
||||||
}
|
|
||||||
$values = self::getAppValues($app);
|
|
||||||
if (isset($values[$key])) {
|
if (isset($values[$key])) {
|
||||||
return $values[$key];
|
return $values[$key];
|
||||||
} else {
|
} else {
|
||||||
self::$cache[$app][$key] = $default;
|
|
||||||
return $default;
|
return $default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,12 +142,9 @@ class OC_Appconfig {
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function hasKey($app, $key) {
|
public function hasKey($app, $key) {
|
||||||
if (isset(self::$cache[$app]) and isset(self::$cache[$app][$key])) {
|
$values = $this->getAppValues($app);
|
||||||
return true;
|
return isset($values[$key]);
|
||||||
}
|
|
||||||
$exists = self::getKeys($app);
|
|
||||||
return in_array($key, $exists);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -145,31 +152,32 @@ class OC_Appconfig {
|
||||||
* @param string $app app
|
* @param string $app app
|
||||||
* @param string $key key
|
* @param string $key key
|
||||||
* @param string $value value
|
* @param string $value value
|
||||||
* @return bool
|
|
||||||
*
|
*
|
||||||
* Sets a value. If the key did not exist before it will be created.
|
* Sets a value. If the key did not exist before it will be created.
|
||||||
*/
|
*/
|
||||||
public static function setValue($app, $key, $value) {
|
public function setValue($app, $key, $value) {
|
||||||
// Does the key exist? yes: update. No: insert
|
// Does the key exist? no: insert, yes: update.
|
||||||
if (!self::hasKey($app, $key)) {
|
if (!$this->hasKey($app, $key)) {
|
||||||
$query = OC_DB::prepare('INSERT INTO `*PREFIX*appconfig` ( `appid`, `configkey`, `configvalue` )'
|
$data = array(
|
||||||
. ' VALUES( ?, ?, ? )');
|
'appid' => $app,
|
||||||
$query->execute(array($app, $key, $value));
|
'configkey' => $key,
|
||||||
|
'configvalue' => $value,
|
||||||
|
);
|
||||||
|
$this->conn->insert('*PREFIX*appconfig', $data);
|
||||||
} else {
|
} else {
|
||||||
$query = OC_DB::prepare('UPDATE `*PREFIX*appconfig` SET `configvalue` = ?'
|
$data = array(
|
||||||
. ' WHERE `appid` = ? AND `configkey` = ?');
|
'configvalue' => $value,
|
||||||
$query->execute(array($value, $app, $key));
|
);
|
||||||
|
$where = array(
|
||||||
|
'appid' => $app,
|
||||||
|
'configkey' => $key,
|
||||||
|
);
|
||||||
|
$this->conn->update('*PREFIX*appconfig', $data, $where);
|
||||||
}
|
}
|
||||||
// TODO where should this be documented?
|
if (!isset($this->cache[$app])) {
|
||||||
\OC_Hook::emit('OC_Appconfig', 'post_set_value', array(
|
$this->cache[$app] = array();
|
||||||
'app' => $app,
|
|
||||||
'key' => $key,
|
|
||||||
'value' => $value
|
|
||||||
));
|
|
||||||
if (!isset(self::$cache[$app])) {
|
|
||||||
self::$cache[$app] = array();
|
|
||||||
}
|
}
|
||||||
self::$cache[$app][$key] = $value;
|
$this->cache[$app][$key] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -180,15 +188,15 @@ class OC_Appconfig {
|
||||||
*
|
*
|
||||||
* Deletes a key.
|
* Deletes a key.
|
||||||
*/
|
*/
|
||||||
public static function deleteKey($app, $key) {
|
public function deleteKey($app, $key) {
|
||||||
// Boring!
|
$where = array(
|
||||||
$query = OC_DB::prepare('DELETE FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?');
|
'appid' => $app,
|
||||||
$query->execute(array($app, $key));
|
'configkey' => $key,
|
||||||
if (isset(self::$cache[$app]) and isset(self::$cache[$app][$key])) {
|
);
|
||||||
unset(self::$cache[$app][$key]);
|
$this->conn->delete('*PREFIX*appconfig', $where);
|
||||||
|
if (isset($this->cache[$app]) and isset($this->cache[$app][$key])) {
|
||||||
|
unset($this->cache[$app][$key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -198,13 +206,12 @@ class OC_Appconfig {
|
||||||
*
|
*
|
||||||
* Removes all keys in appconfig belonging to the app.
|
* Removes all keys in appconfig belonging to the app.
|
||||||
*/
|
*/
|
||||||
public static function deleteApp($app) {
|
public function deleteApp($app) {
|
||||||
// Nothing special
|
$where = array(
|
||||||
$query = OC_DB::prepare('DELETE FROM `*PREFIX*appconfig` WHERE `appid` = ?');
|
'appid' => $app,
|
||||||
$query->execute(array($app));
|
);
|
||||||
self::$cache[$app] = array();
|
$this->conn->delete('*PREFIX*appconfig', $where);
|
||||||
|
unset($this->cache[$app]);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -214,10 +221,11 @@ class OC_Appconfig {
|
||||||
* @param key
|
* @param key
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function getValues($app, $key) {
|
public function getValues($app, $key) {
|
||||||
if ($app !== false and $key !== false) {
|
if (($app !== false) == ($key !== false)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$fields = '`configvalue`';
|
$fields = '`configvalue`';
|
||||||
$where = 'WHERE';
|
$where = 'WHERE';
|
||||||
$params = array();
|
$params = array();
|
||||||
|
@ -232,13 +240,14 @@ class OC_Appconfig {
|
||||||
$params[] = $key;
|
$params[] = $key;
|
||||||
$key = 'appid';
|
$key = 'appid';
|
||||||
}
|
}
|
||||||
$queryString = 'SELECT ' . $fields . ' FROM `*PREFIX*appconfig` ' . $where;
|
$query = 'SELECT ' . $fields . ' FROM `*PREFIX*appconfig` ' . $where;
|
||||||
$query = OC_DB::prepare($queryString);
|
$result = $this->conn->executeQuery($query, $params);
|
||||||
$result = $query->execute($params);
|
|
||||||
$values = array();
|
$values = array();
|
||||||
while ($row = $result->fetchRow()) {
|
while ($row = $result->fetch((\PDO::FETCH_ASSOC))) {
|
||||||
$values[$row[$key]] = $row['configvalue'];
|
$values[$row[$key]] = $row['configvalue'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $values;
|
return $values;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,9 @@
|
||||||
|
|
||||||
namespace OC\BackgroundJob;
|
namespace OC\BackgroundJob;
|
||||||
|
|
||||||
abstract class Job {
|
use OCP\BackgroundJob\IJob;
|
||||||
|
|
||||||
|
abstract class Job implements IJob {
|
||||||
/**
|
/**
|
||||||
* @var int $id
|
* @var int $id
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
|
* Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
|
||||||
* This file is licensed under the Affero General Public License version 3 or
|
* This file is licensed under the Affero General Public License version 3 or
|
||||||
* later.
|
* later.
|
||||||
* See the COPYING-README file.
|
* See the COPYING-README file.
|
||||||
|
@ -8,14 +8,28 @@
|
||||||
|
|
||||||
namespace OC\BackgroundJob;
|
namespace OC\BackgroundJob;
|
||||||
|
|
||||||
|
use OCP\BackgroundJob\IJobList;
|
||||||
|
|
||||||
|
class JobList implements IJobList {
|
||||||
/**
|
/**
|
||||||
* Class QueuedJob
|
* @var \OCP\IDBConnection
|
||||||
*
|
|
||||||
* create a background job that is to be executed once
|
|
||||||
*
|
|
||||||
* @package OC\BackgroundJob
|
|
||||||
*/
|
*/
|
||||||
class JobList {
|
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 Job|string $job
|
||||||
* @param mixed $argument
|
* @param mixed $argument
|
||||||
|
@ -28,7 +42,7 @@ class JobList {
|
||||||
$class = $job;
|
$class = $job;
|
||||||
}
|
}
|
||||||
$argument = json_encode($argument);
|
$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));
|
$query->execute(array($class, $argument));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,10 +59,10 @@ class JobList {
|
||||||
}
|
}
|
||||||
if (!is_null($argument)) {
|
if (!is_null($argument)) {
|
||||||
$argument = json_encode($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));
|
$query->execute(array($class, $argument));
|
||||||
} else {
|
} 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));
|
$query->execute(array($class));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,9 +81,9 @@ class JobList {
|
||||||
$class = $job;
|
$class = $job;
|
||||||
}
|
}
|
||||||
$argument = json_encode($argument);
|
$argument = json_encode($argument);
|
||||||
$query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*jobs` WHERE `class` = ? AND `argument` = ?');
|
$query = $this->conn->prepare('SELECT `id` FROM `*PREFIX*jobs` WHERE `class` = ? AND `argument` = ?');
|
||||||
$result = $query->execute(array($class, $argument));
|
$query->execute(array($class, $argument));
|
||||||
return (bool)$result->fetchRow();
|
return (bool)$query->fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,10 +92,10 @@ class JobList {
|
||||||
* @return Job[]
|
* @return Job[]
|
||||||
*/
|
*/
|
||||||
public function getAll() {
|
public function getAll() {
|
||||||
$query = \OC_DB::prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs`');
|
$query = $this->conn->prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs`');
|
||||||
$result = $query->execute();
|
$query->execute();
|
||||||
$jobs = array();
|
$jobs = array();
|
||||||
while ($row = $result->fetchRow()) {
|
while ($row = $query->fetch()) {
|
||||||
$jobs[] = $this->buildJob($row);
|
$jobs[] = $this->buildJob($row);
|
||||||
}
|
}
|
||||||
return $jobs;
|
return $jobs;
|
||||||
|
@ -94,15 +108,15 @@ class JobList {
|
||||||
*/
|
*/
|
||||||
public function getNext() {
|
public function getNext() {
|
||||||
$lastId = $this->getLastJob();
|
$lastId = $this->getLastJob();
|
||||||
$query = \OC_DB::prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs` WHERE `id` > ? ORDER BY `id` ASC', 1);
|
$query = $this->conn->prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs` WHERE `id` > ? ORDER BY `id` ASC', 1);
|
||||||
$result = $query->execute(array($lastId));
|
$query->execute(array($lastId));
|
||||||
if ($row = $result->fetchRow()) {
|
if ($row = $query->fetch()) {
|
||||||
return $this->buildJob($row);
|
return $this->buildJob($row);
|
||||||
} else {
|
} else {
|
||||||
//begin at the start of the queue
|
//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);
|
$query = $this->conn->prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs` ORDER BY `id` ASC', 1);
|
||||||
$result = $query->execute();
|
$query->execute();
|
||||||
if ($row = $result->fetchRow()) {
|
if ($row = $query->fetch()) {
|
||||||
return $this->buildJob($row);
|
return $this->buildJob($row);
|
||||||
} else {
|
} else {
|
||||||
return null; //empty job list
|
return null; //empty job list
|
||||||
|
@ -115,9 +129,9 @@ class JobList {
|
||||||
* @return Job
|
* @return Job
|
||||||
*/
|
*/
|
||||||
public function getById($id) {
|
public function getById($id) {
|
||||||
$query = \OC_DB::prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs` WHERE `id` = ?');
|
$query = $this->conn->prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs` WHERE `id` = ?');
|
||||||
$result = $query->execute(array($id));
|
$query->execute(array($id));
|
||||||
if ($row = $result->fetchRow()) {
|
if ($row = $query->fetch()) {
|
||||||
return $this->buildJob($row);
|
return $this->buildJob($row);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
@ -148,7 +162,7 @@ class JobList {
|
||||||
* @param Job $job
|
* @param Job $job
|
||||||
*/
|
*/
|
||||||
public function setLastJob($job) {
|
public function setLastJob($job) {
|
||||||
\OC_Appconfig::setValue('backgroundjob', 'lastjob', $job->getId());
|
$this->config->setAppValue('backgroundjob', 'lastjob', $job->getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -157,7 +171,7 @@ class JobList {
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getLastJob() {
|
public function getLastJob() {
|
||||||
return \OC_Appconfig::getValue('backgroundjob', 'lastjob', 0);
|
return $this->config->getAppValue('backgroundjob', 'lastjob', 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -166,7 +180,7 @@ class JobList {
|
||||||
* @param Job $job
|
* @param Job $job
|
||||||
*/
|
*/
|
||||||
public function setLastRun($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()));
|
$query->execute(array(time(), $job->getId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,9 @@ class OC_DB_StatementWrapper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* make execute return the result instead of a bool
|
* make execute return the result instead of a bool
|
||||||
|
*
|
||||||
|
* @param array $input
|
||||||
|
* @return \OC_DB_StatementWrapper | int
|
||||||
*/
|
*/
|
||||||
public function execute($input=array()) {
|
public function execute($input=array()) {
|
||||||
if(OC_Config::getValue( "log_query", false)) {
|
if(OC_Config::getValue( "log_query", false)) {
|
||||||
|
|
|
@ -131,7 +131,7 @@ class OC_Files {
|
||||||
}
|
}
|
||||||
if ($xsendfile) {
|
if ($xsendfile) {
|
||||||
list($storage) = \OC\Files\Filesystem::resolvePath(\OC\Files\Filesystem::getView()->getAbsolutePath($filename));
|
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));
|
self::addSendfileHeader(\OC\Files\Filesystem::getLocalFile($filename));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -370,4 +370,13 @@ abstract class Common implements \OC\Files\Storage\Storage {
|
||||||
public function free_space($path) {
|
public function free_space($path) {
|
||||||
return \OC\Files\SPACE_UNKNOWN;
|
return \OC\Files\SPACE_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function isLocal() {
|
||||||
|
// the common implementation returns a temporary file by
|
||||||
|
// default, which is not local
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -298,5 +298,12 @@ if (\OC_Util::runningOnWindows()) {
|
||||||
public function hasUpdated($path, $time) {
|
public function hasUpdated($path, $time) {
|
||||||
return $this->filemtime($path) > $time;
|
return $this->filemtime($path) > $time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function isLocal() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -432,4 +432,12 @@ class Wrapper implements \OC\Files\Storage\Storage {
|
||||||
public function test() {
|
public function test() {
|
||||||
return $this->storage->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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -781,14 +781,7 @@ class View {
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @param boolean $includeMountPoints whether to add mountpoint sizes,
|
* @param boolean $includeMountPoints whether to add mountpoint sizes,
|
||||||
* defaults to true
|
* defaults to true
|
||||||
* @return array
|
* @return \OC\Files\FileInfo | false
|
||||||
*
|
|
||||||
* returns an associative array with the following keys:
|
|
||||||
* - size
|
|
||||||
* - mtime
|
|
||||||
* - mimetype
|
|
||||||
* - encrypted
|
|
||||||
* - versioned
|
|
||||||
*/
|
*/
|
||||||
public function getFileInfo($path, $includeMountPoints = true) {
|
public function getFileInfo($path, $includeMountPoints = true) {
|
||||||
$data = array();
|
$data = array();
|
||||||
|
@ -841,10 +834,13 @@ class View {
|
||||||
$data['permissions'] = $permissions;
|
$data['permissions'] = $permissions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!$data) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$data = \OC_FileProxy::runPostProxies('getFileInfo', $path, $data);
|
$data = \OC_FileProxy::runPostProxies('getFileInfo', $path, $data);
|
||||||
|
|
||||||
return $data;
|
return new FileInfo($path, $storage, $internalPath, $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -852,7 +848,7 @@ class View {
|
||||||
*
|
*
|
||||||
* @param string $directory path under datadirectory
|
* @param string $directory path under datadirectory
|
||||||
* @param string $mimetype_filter limit returned content to this mimetype or mimepart
|
* @param string $mimetype_filter limit returned content to this mimetype or mimepart
|
||||||
* @return array
|
* @return FileInfo[]
|
||||||
*/
|
*/
|
||||||
public function getDirectoryContent($directory, $mimetype_filter = '') {
|
public function getDirectoryContent($directory, $mimetype_filter = '') {
|
||||||
$result = array();
|
$result = array();
|
||||||
|
@ -878,7 +874,11 @@ class View {
|
||||||
$watcher->checkUpdate($internalPath);
|
$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);
|
$permissions = $permissionsCache->getDirectoryPermissions($cache->getId($internalPath), $user);
|
||||||
|
|
||||||
$ids = array();
|
$ids = array();
|
||||||
|
@ -936,7 +936,7 @@ class View {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$files[] = $rootEntry;
|
$files[] = new FileInfo($path . '/' . $rootEntry['name'], $subStorage, '', $rootEntry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -958,6 +958,7 @@ class View {
|
||||||
$result = $files;
|
$result = $files;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -965,12 +966,15 @@ class View {
|
||||||
* change file metadata
|
* change file metadata
|
||||||
*
|
*
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @param array $data
|
* @param array | \OCP\Files\FileInfo $data
|
||||||
* @return int
|
* @return int
|
||||||
*
|
*
|
||||||
* returns the fileid of the updated file
|
* returns the fileid of the updated file
|
||||||
*/
|
*/
|
||||||
public function putFileInfo($path, $data) {
|
public function putFileInfo($path, $data) {
|
||||||
|
if ($data instanceof FileInfo) {
|
||||||
|
$data = $data->getData();
|
||||||
|
}
|
||||||
$path = Filesystem::normalizePath($this->fakeRoot . '/' . $path);
|
$path = Filesystem::normalizePath($this->fakeRoot . '/' . $path);
|
||||||
/**
|
/**
|
||||||
* @var \OC\Files\Storage\Storage $storage
|
* @var \OC\Files\Storage\Storage $storage
|
||||||
|
@ -995,7 +999,7 @@ class View {
|
||||||
* search for files with the name matching $query
|
* search for files with the name matching $query
|
||||||
*
|
*
|
||||||
* @param string $query
|
* @param string $query
|
||||||
* @return array
|
* @return FileInfo[]
|
||||||
*/
|
*/
|
||||||
public function search($query) {
|
public function search($query) {
|
||||||
return $this->searchCommon('%' . $query . '%', 'search');
|
return $this->searchCommon('%' . $query . '%', 'search');
|
||||||
|
@ -1005,7 +1009,7 @@ class View {
|
||||||
* search for files by mimetype
|
* search for files by mimetype
|
||||||
*
|
*
|
||||||
* @param string $mimetype
|
* @param string $mimetype
|
||||||
* @return array
|
* @return FileInfo[]
|
||||||
*/
|
*/
|
||||||
public function searchByMime($mimetype) {
|
public function searchByMime($mimetype) {
|
||||||
return $this->searchCommon($mimetype, 'searchByMime');
|
return $this->searchCommon($mimetype, 'searchByMime');
|
||||||
|
@ -1014,7 +1018,7 @@ class View {
|
||||||
/**
|
/**
|
||||||
* @param string $query
|
* @param string $query
|
||||||
* @param string $method
|
* @param string $method
|
||||||
* @return array
|
* @return FileInfo[]
|
||||||
*/
|
*/
|
||||||
private function searchCommon($query, $method) {
|
private function searchCommon($query, $method) {
|
||||||
$files = array();
|
$files = array();
|
||||||
|
@ -1028,8 +1032,9 @@ class View {
|
||||||
$results = $cache->$method($query);
|
$results = $cache->$method($query);
|
||||||
foreach ($results as $result) {
|
foreach ($results as $result) {
|
||||||
if (substr($mountPoint . $result['path'], 0, $rootLength + 1) === $this->fakeRoot . '/') {
|
if (substr($mountPoint . $result['path'], 0, $rootLength + 1) === $this->fakeRoot . '/') {
|
||||||
|
$internalPath = $result['path'];
|
||||||
$result['path'] = substr($mountPoint . $result['path'], $rootLength);
|
$result['path'] = substr($mountPoint . $result['path'], $rootLength);
|
||||||
$files[] = $result;
|
$files[] = new FileInfo($mountPoint . $result['path'], $storage, $internalPath, $result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1043,8 +1048,9 @@ class View {
|
||||||
$results = $cache->$method($query);
|
$results = $cache->$method($query);
|
||||||
if ($results) {
|
if ($results) {
|
||||||
foreach ($results as $result) {
|
foreach ($results as $result) {
|
||||||
|
$internalPath = $result['path'];
|
||||||
$result['path'] = $relativeMountPoint . $result['path'];
|
$result['path'] = $relativeMountPoint . $result['path'];
|
||||||
$files[] = $result;
|
$files[] = new FileInfo($mountPoint . $result['path'], $storage, $internalPath, $result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,13 +76,8 @@ class Manager extends PublicEmitter {
|
||||||
if (isset($this->cachedGroups[$gid])) {
|
if (isset($this->cachedGroups[$gid])) {
|
||||||
return $this->cachedGroups[$gid];
|
return $this->cachedGroups[$gid];
|
||||||
}
|
}
|
||||||
foreach ($this->backends as $backend) {
|
|
||||||
if ($backend->groupExists($gid)) {
|
|
||||||
return $this->getGroupObject($gid);
|
return $this->getGroupObject($gid);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getGroupObject($gid) {
|
protected function getGroupObject($gid) {
|
||||||
$backends = array();
|
$backends = array();
|
||||||
|
@ -91,6 +86,9 @@ class Manager extends PublicEmitter {
|
||||||
$backends[] = $backend;
|
$backends[] = $backend;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (count($backends) === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
$this->cachedGroups[$gid] = new Group($gid, $backends, $this->userManager, $this);
|
$this->cachedGroups[$gid] = new Group($gid, $backends, $this->userManager, $this);
|
||||||
return $this->cachedGroups[$gid];
|
return $this->cachedGroups[$gid];
|
||||||
}
|
}
|
||||||
|
@ -110,8 +108,8 @@ class Manager extends PublicEmitter {
|
||||||
public function createGroup($gid) {
|
public function createGroup($gid) {
|
||||||
if (!$gid) {
|
if (!$gid) {
|
||||||
return false;
|
return false;
|
||||||
} else if ($this->groupExists($gid)) {
|
} else if ($group = $this->get($gid)) {
|
||||||
return $this->get($gid);
|
return $group;
|
||||||
} else {
|
} else {
|
||||||
$this->emit('\OC\Group', 'preCreate', array($gid));
|
$this->emit('\OC\Group', 'preCreate', array($gid));
|
||||||
foreach ($this->backends as $backend) {
|
foreach ($this->backends as $backend) {
|
||||||
|
|
|
@ -804,18 +804,22 @@ class OC_Helper {
|
||||||
/**
|
/**
|
||||||
* @brief calculates the maximum upload size respecting system settings, free space and user quota
|
* @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
|
||||||
* @return number of bytes representing
|
* @param int $freeSpace the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly
|
||||||
|
* @return int number of bytes representing
|
||||||
*/
|
*/
|
||||||
public static function maxUploadFilesize($dir) {
|
public static function maxUploadFilesize($dir, $freeSpace = null) {
|
||||||
return min(self::freeSpace($dir), self::uploadLimit());
|
if (is_null($freeSpace)){
|
||||||
|
$freeSpace = self::freeSpace($dir);
|
||||||
|
}
|
||||||
|
return min($freeSpace, self::uploadLimit());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate free space left within user quota
|
* Calculate free space left within user quota
|
||||||
*
|
*
|
||||||
* @param $dir the current folder where the user currently operates
|
* @param string $dir the current folder where the user currently operates
|
||||||
* @return number of bytes representing
|
* @return int number of bytes representing
|
||||||
*/
|
*/
|
||||||
public static function freeSpace($dir) {
|
public static function freeSpace($dir) {
|
||||||
$freeSpace = \OC\Files\Filesystem::free_space($dir);
|
$freeSpace = \OC\Files\Filesystem::free_space($dir);
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,7 +6,7 @@
|
||||||
* See the COPYING-README file.
|
* See the COPYING-README file.
|
||||||
*/
|
*/
|
||||||
//both, libreoffice backend and php fallback, need imagick
|
//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');
|
$isShellExecEnabled = \OC_Helper::is_function_enabled('shell_exec');
|
||||||
|
|
||||||
// LibreOffice preview is currently not supported on Windows
|
// LibreOffice preview is currently not supported on Windows
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
*/
|
*/
|
||||||
namespace OC\Preview;
|
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 {
|
class PDF extends Provider {
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
*/
|
*/
|
||||||
namespace OC\Preview;
|
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 {
|
class SVG extends Provider {
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ class Unknown extends Provider {
|
||||||
|
|
||||||
$svgPath = substr_replace($path, 'svg', -3);
|
$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
|
// http://www.php.net/manual/de/imagick.setresolution.php#85284
|
||||||
$svg = new \Imagick();
|
$svg = new \Imagick();
|
||||||
|
|
|
@ -124,6 +124,9 @@ class Server extends SimpleContainer implements IServerContainer {
|
||||||
$this->registerService('AllConfig', function($c) {
|
$this->registerService('AllConfig', function($c) {
|
||||||
return new \OC\AllConfig();
|
return new \OC\AllConfig();
|
||||||
});
|
});
|
||||||
|
$this->registerService('AppConfig', function ($c) {
|
||||||
|
return new \OC\AppConfig(\OC_DB::getConnection());
|
||||||
|
});
|
||||||
$this->registerService('L10NFactory', function($c) {
|
$this->registerService('L10NFactory', function($c) {
|
||||||
return new \OC\L10N\Factory();
|
return new \OC\L10N\Factory();
|
||||||
});
|
});
|
||||||
|
@ -148,6 +151,13 @@ class Server extends SimpleContainer implements IServerContainer {
|
||||||
$this->registerService('AvatarManager', function($c) {
|
$this->registerService('AvatarManager', function($c) {
|
||||||
return new AvatarManager();
|
return new AvatarManager();
|
||||||
});
|
});
|
||||||
|
$this->registerService('JobList', function ($c) {
|
||||||
|
/**
|
||||||
|
* @var Server $c
|
||||||
|
*/
|
||||||
|
$config = $c->getConfig();
|
||||||
|
return new \OC\BackgroundJob\JobList($c->getDatabaseConnection(), $config);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -269,6 +279,15 @@ class Server extends SimpleContainer implements IServerContainer {
|
||||||
return $this->query('AllConfig');
|
return $this->query('AllConfig');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the app config manager
|
||||||
|
*
|
||||||
|
* @return \OCP\IAppConfig
|
||||||
|
*/
|
||||||
|
function getAppConfig(){
|
||||||
|
return $this->query('AppConfig');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get an L10N instance
|
* get an L10N instance
|
||||||
* @param $app string appid
|
* @param $app string appid
|
||||||
|
@ -336,4 +355,13 @@ class Server extends SimpleContainer implements IServerContainer {
|
||||||
function getActivityManager() {
|
function getActivityManager() {
|
||||||
return $this->query('ActivityManager');
|
return $this->query('ActivityManager');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an job list for controlling background jobs
|
||||||
|
*
|
||||||
|
* @return \OCP\BackgroundJob\IJobList
|
||||||
|
*/
|
||||||
|
function getJobList(){
|
||||||
|
return $this->query('JobList');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ use \OC\BackgroundJob\JobList;
|
||||||
/**
|
/**
|
||||||
* This class provides functions to register backgroundjobs in ownCloud
|
* 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
|
* \OC\BackgroundJob\QueuedJob or \OC\BackgroundJob\TimedJob and register it using
|
||||||
* \OCP\BackgroundJob->registerJob($job, $argument), $argument will be passed to the run() function
|
* \OCP\BackgroundJob->registerJob($job, $argument), $argument will be passed to the run() function
|
||||||
* of the job when the job is executed.
|
* of the job when the job is executed.
|
||||||
|
@ -73,7 +73,7 @@ class BackgroundJob {
|
||||||
* @param mixed $argument
|
* @param mixed $argument
|
||||||
*/
|
*/
|
||||||
public static function registerJob($job, $argument = null) {
|
public static function registerJob($job, $argument = null) {
|
||||||
$jobList = new JobList();
|
$jobList = \OC::$server->getJobList();
|
||||||
$jobList->add($job, $argument);
|
$jobList->add($job, $argument);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ class BackgroundJob {
|
||||||
* key is string "$klass-$method", value is array( $klass, $method )
|
* key is string "$klass-$method", value is array( $klass, $method )
|
||||||
*/
|
*/
|
||||||
static public function allRegularTasks() {
|
static public function allRegularTasks() {
|
||||||
$jobList = new JobList();
|
$jobList = \OC::$server->getJobList();
|
||||||
$allJobs = $jobList->getAll();
|
$allJobs = $jobList->getAll();
|
||||||
$regularJobs = array();
|
$regularJobs = array();
|
||||||
foreach ($allJobs as $job) {
|
foreach ($allJobs as $job) {
|
||||||
|
@ -118,7 +118,7 @@ class BackgroundJob {
|
||||||
* @return associative array
|
* @return associative array
|
||||||
*/
|
*/
|
||||||
public static function findQueuedTask($id) {
|
public static function findQueuedTask($id) {
|
||||||
$jobList = new JobList();
|
$jobList = \OC::$server->getJobList();
|
||||||
return $jobList->getById($id);
|
return $jobList->getById($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ class BackgroundJob {
|
||||||
* @return array with associative arrays
|
* @return array with associative arrays
|
||||||
*/
|
*/
|
||||||
public static function allQueuedTasks() {
|
public static function allQueuedTasks() {
|
||||||
$jobList = new JobList();
|
$jobList = \OC::$server->getJobList();
|
||||||
$allJobs = $jobList->getAll();
|
$allJobs = $jobList->getAll();
|
||||||
$queuedJobs = array();
|
$queuedJobs = array();
|
||||||
foreach ($allJobs as $job) {
|
foreach ($allJobs as $job) {
|
||||||
|
@ -148,7 +148,7 @@ class BackgroundJob {
|
||||||
* @return array with associative arrays
|
* @return array with associative arrays
|
||||||
*/
|
*/
|
||||||
public static function queuedTaskWhereAppIs($app) {
|
public static function queuedTaskWhereAppIs($app) {
|
||||||
$jobList = new JobList();
|
$jobList = \OC::$server->getJobList();
|
||||||
$allJobs = $jobList->getAll();
|
$allJobs = $jobList->getAll();
|
||||||
$queuedJobs = array();
|
$queuedJobs = array();
|
||||||
foreach ($allJobs as $job) {
|
foreach ($allJobs as $job) {
|
||||||
|
@ -186,7 +186,7 @@ class BackgroundJob {
|
||||||
* Deletes a report
|
* Deletes a report
|
||||||
*/
|
*/
|
||||||
public static function deleteQueuedTask($id) {
|
public static function deleteQueuedTask($id) {
|
||||||
$jobList = new JobList();
|
$jobList = \OC::$server->getJobList();
|
||||||
$job = $jobList->getById($id);
|
$job = $jobList->getById($id);
|
||||||
if ($job) {
|
if ($job) {
|
||||||
$jobList->remove($job);
|
$jobList->remove($job);
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
|
@ -315,4 +315,15 @@ interface Storage {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getETag($path);
|
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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
|
@ -113,6 +113,13 @@ interface IServerContainer {
|
||||||
*/
|
*/
|
||||||
function getConfig();
|
function getConfig();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the app config manager
|
||||||
|
*
|
||||||
|
* @return \OCP\IAppConfig
|
||||||
|
*/
|
||||||
|
function getAppConfig();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get an L10N instance
|
* get an L10N instance
|
||||||
* @param $app string appid
|
* @param $app string appid
|
||||||
|
@ -176,4 +183,11 @@ interface IServerContainer {
|
||||||
*/
|
*/
|
||||||
function getAvatarManager();
|
function getAvatarManager();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an job list for controlling background jobs
|
||||||
|
*
|
||||||
|
* @return \OCP\BackgroundJob\IJobList
|
||||||
|
*/
|
||||||
|
function getJobList();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,7 +121,7 @@ class Util {
|
||||||
/**
|
/**
|
||||||
* get l10n object
|
* get l10n object
|
||||||
* @param string $application
|
* @param string $application
|
||||||
* @return OC_L10N
|
* @return \OC_L10N
|
||||||
*/
|
*/
|
||||||
public static function getL10N( $application ) {
|
public static function getL10N( $application ) {
|
||||||
return \OC_L10N::get( $application );
|
return \OC_L10N::get( $application );
|
||||||
|
@ -460,11 +460,12 @@ class Util {
|
||||||
/**
|
/**
|
||||||
* calculates the maximum upload size respecting system settings, free space and user quota
|
* 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
|
* @return number of bytes representing
|
||||||
*/
|
*/
|
||||||
public static function maxUploadFilesize($dir) {
|
public static function maxUploadFilesize($dir, $free = null) {
|
||||||
return \OC_Helper::maxUploadFilesize($dir);
|
return \OC_Helper::maxUploadFilesize($dir, $free);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -16,7 +16,14 @@ $util = new \OCA\Encryption\Util($view, \OCP\User::getUser());
|
||||||
$result = $util->initEncryption($params);
|
$result = $util->initEncryption($params);
|
||||||
|
|
||||||
if ($result !== false) {
|
if ($result !== false) {
|
||||||
|
|
||||||
|
try {
|
||||||
$successful = $util->decryptAll();
|
$successful = $util->decryptAll();
|
||||||
|
} catch (\Exception $ex) {
|
||||||
|
\OCP\Util::writeLog('encryption library', "Decryption finished unexpected: " . $ex->getMessage(), \OCP\Util::ERROR);
|
||||||
|
$successful = false;
|
||||||
|
}
|
||||||
|
|
||||||
if ($successful === true) {
|
if ($successful === true) {
|
||||||
\OCP\JSON::success(array('data' => array('message' => 'Files decrypted successfully')));
|
\OCP\JSON::success(array('data' => array('message' => 'Files decrypted successfully')));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Copyright (c) 2013 Christopher Schäpers <christopher@schaepers.it>
|
* Copyright (c) 2013 Christopher Schäpers <christopher@schaepers.it>
|
||||||
|
* Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl>
|
||||||
* This file is licensed under the Affero General Public License version 3 or
|
* This file is licensed under the Affero General Public License version 3 or
|
||||||
* later.
|
* later.
|
||||||
* See the COPYING-README file.
|
* See the COPYING-README file.
|
||||||
|
@ -41,6 +42,7 @@ class Test_Appconfig extends PHPUnit_Framework_TestCase {
|
||||||
while ($row = $result->fetchRow()) {
|
while ($row = $result->fetchRow()) {
|
||||||
$expected[] = $row['appid'];
|
$expected[] = $row['appid'];
|
||||||
}
|
}
|
||||||
|
sort($expected);
|
||||||
$apps = \OC_Appconfig::getApps();
|
$apps = \OC_Appconfig::getApps();
|
||||||
$this->assertEquals($expected, $apps);
|
$this->assertEquals($expected, $apps);
|
||||||
}
|
}
|
||||||
|
@ -52,6 +54,7 @@ class Test_Appconfig extends PHPUnit_Framework_TestCase {
|
||||||
while($row = $result->fetchRow()) {
|
while($row = $result->fetchRow()) {
|
||||||
$expected[] = $row["configkey"];
|
$expected[] = $row["configkey"];
|
||||||
}
|
}
|
||||||
|
sort($expected);
|
||||||
$keys = \OC_Appconfig::getKeys('testapp');
|
$keys = \OC_Appconfig::getKeys('testapp');
|
||||||
$this->assertEquals($expected, $keys);
|
$this->assertEquals($expected, $keys);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,8 @@ class DummyJobList extends \OC\BackgroundJob\JobList {
|
||||||
|
|
||||||
private $last = 0;
|
private $last = 0;
|
||||||
|
|
||||||
|
public function __construct(){}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \OC\BackgroundJob\Job|string $job
|
* @param \OC\BackgroundJob\Job|string $job
|
||||||
* @param mixed $argument
|
* @param mixed $argument
|
||||||
|
|
|
@ -8,31 +8,6 @@
|
||||||
|
|
||||||
namespace Test\BackgroundJob;
|
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 {
|
class Job extends \PHPUnit_Framework_TestCase {
|
||||||
private $run = false;
|
private $run = false;
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -116,16 +116,22 @@ class Manager extends \PHPUnit_Framework_TestCase {
|
||||||
/**
|
/**
|
||||||
* @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend
|
* @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend
|
||||||
*/
|
*/
|
||||||
|
$backendGroupCreated = false;
|
||||||
$backend = $this->getMock('\OC_Group_Database');
|
$backend = $this->getMock('\OC_Group_Database');
|
||||||
$backend->expects($this->any())
|
$backend->expects($this->any())
|
||||||
->method('groupExists')
|
->method('groupExists')
|
||||||
->with('group1')
|
->with('group1')
|
||||||
->will($this->returnValue(false));
|
->will($this->returnCallback(function () use (&$backendGroupCreated) {
|
||||||
|
return $backendGroupCreated;
|
||||||
|
}));
|
||||||
$backend->expects($this->once())
|
$backend->expects($this->once())
|
||||||
->method('implementsActions')
|
->method('implementsActions')
|
||||||
->will($this->returnValue(true));
|
->will($this->returnValue(true));
|
||||||
$backend->expects($this->once())
|
$backend->expects($this->once())
|
||||||
->method('createGroup');
|
->method('createGroup')
|
||||||
|
->will($this->returnCallback(function () use (&$backendGroupCreated) {
|
||||||
|
$backendGroupCreated = true;
|
||||||
|
}));;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \OC\User\Manager $userManager
|
* @var \OC\User\Manager $userManager
|
||||||
|
@ -170,6 +176,10 @@ class Manager extends \PHPUnit_Framework_TestCase {
|
||||||
->method('getGroups')
|
->method('getGroups')
|
||||||
->with('1')
|
->with('1')
|
||||||
->will($this->returnValue(array('group1')));
|
->will($this->returnValue(array('group1')));
|
||||||
|
$backend->expects($this->once())
|
||||||
|
->method('groupExists')
|
||||||
|
->with('group1')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \OC\User\Manager $userManager
|
* @var \OC\User\Manager $userManager
|
||||||
|
@ -193,6 +203,9 @@ class Manager extends \PHPUnit_Framework_TestCase {
|
||||||
->method('getGroups')
|
->method('getGroups')
|
||||||
->with('1')
|
->with('1')
|
||||||
->will($this->returnValue(array('group1')));
|
->will($this->returnValue(array('group1')));
|
||||||
|
$backend1->expects($this->any())
|
||||||
|
->method('groupExists')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2
|
* @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2
|
||||||
|
@ -202,6 +215,9 @@ class Manager extends \PHPUnit_Framework_TestCase {
|
||||||
->method('getGroups')
|
->method('getGroups')
|
||||||
->with('1')
|
->with('1')
|
||||||
->will($this->returnValue(array('group12', 'group1')));
|
->will($this->returnValue(array('group12', 'group1')));
|
||||||
|
$backend2->expects($this->any())
|
||||||
|
->method('groupExists')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \OC\User\Manager $userManager
|
* @var \OC\User\Manager $userManager
|
||||||
|
@ -228,6 +244,9 @@ class Manager extends \PHPUnit_Framework_TestCase {
|
||||||
->method('getGroups')
|
->method('getGroups')
|
||||||
->with('1', 2, 1)
|
->with('1', 2, 1)
|
||||||
->will($this->returnValue(array('group1')));
|
->will($this->returnValue(array('group1')));
|
||||||
|
$backend1->expects($this->any())
|
||||||
|
->method('groupExists')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2
|
* @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2
|
||||||
|
@ -237,6 +256,9 @@ class Manager extends \PHPUnit_Framework_TestCase {
|
||||||
->method('getGroups')
|
->method('getGroups')
|
||||||
->with('1', 1, 0)
|
->with('1', 1, 0)
|
||||||
->will($this->returnValue(array('group12')));
|
->will($this->returnValue(array('group12')));
|
||||||
|
$backend2->expects($this->any())
|
||||||
|
->method('groupExists')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \OC\User\Manager $userManager
|
* @var \OC\User\Manager $userManager
|
||||||
|
@ -263,6 +285,10 @@ class Manager extends \PHPUnit_Framework_TestCase {
|
||||||
->method('getUserGroups')
|
->method('getUserGroups')
|
||||||
->with('user1')
|
->with('user1')
|
||||||
->will($this->returnValue(array('group1')));
|
->will($this->returnValue(array('group1')));
|
||||||
|
$backend->expects($this->any())
|
||||||
|
->method('groupExists')
|
||||||
|
->with('group1')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \OC\User\Manager $userManager
|
* @var \OC\User\Manager $userManager
|
||||||
|
@ -286,6 +312,10 @@ class Manager extends \PHPUnit_Framework_TestCase {
|
||||||
->method('getUserGroups')
|
->method('getUserGroups')
|
||||||
->with('user1')
|
->with('user1')
|
||||||
->will($this->returnValue(array('group1')));
|
->will($this->returnValue(array('group1')));
|
||||||
|
$backend1->expects($this->any())
|
||||||
|
->method('groupExists')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2
|
* @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2
|
||||||
*/
|
*/
|
||||||
|
@ -294,6 +324,9 @@ class Manager extends \PHPUnit_Framework_TestCase {
|
||||||
->method('getUserGroups')
|
->method('getUserGroups')
|
||||||
->with('user1')
|
->with('user1')
|
||||||
->will($this->returnValue(array('group1', 'group2')));
|
->will($this->returnValue(array('group1', 'group2')));
|
||||||
|
$backend1->expects($this->any())
|
||||||
|
->method('groupExists')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \OC\User\Manager $userManager
|
* @var \OC\User\Manager $userManager
|
||||||
|
|
|
@ -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