Merge pull request #18408 from owncloud/ext-ocp
Use OCP classes as much as possible in files_external v2
This commit is contained in:
commit
d93bf35482
|
@ -37,8 +37,15 @@ if (isset($_GET['offset'])) {
|
|||
$offset = (int)$_GET['offset'];
|
||||
}
|
||||
|
||||
$groups = \OC_Group::getGroups($pattern, $limit, $offset);
|
||||
$users = \OCP\User::getDisplayNames($pattern, $limit, $offset);
|
||||
$groups = [];
|
||||
foreach (\OC::$server->getGroupManager()->search($pattern, $limit, $offset) as $group) {
|
||||
$groups[$group->getGID()] = $group->getGID();
|
||||
}
|
||||
|
||||
$users = [];
|
||||
foreach (\OC::$server->getUserManager()->searchDisplayName($pattern, $limit, $offset) as $user) {
|
||||
$users[$user->getUID()] = $user->getDisplayName();
|
||||
}
|
||||
|
||||
$results = array('groups' => $groups, 'users' => $users);
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
namespace OCA\Files_External\AppInfo;
|
||||
|
||||
/**
|
||||
* @var $this \OC\Route\Router
|
||||
* @var $this \OCP\Route\IRouter
|
||||
**/
|
||||
\OC_Mount_Config::$app->registerRoutes(
|
||||
$this,
|
||||
|
|
|
@ -372,7 +372,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
|
|||
switch ($mode) {
|
||||
case 'r':
|
||||
case 'rb':
|
||||
$tmpFile = \OC_Helper::tmpFile();
|
||||
$tmpFile = \OCP\Files::tmpFile();
|
||||
self::$tmpFiles[$tmpFile] = $path;
|
||||
|
||||
try {
|
||||
|
@ -404,7 +404,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
|
|||
} else {
|
||||
$ext = '';
|
||||
}
|
||||
$tmpFile = \OC_Helper::tmpFile($ext);
|
||||
$tmpFile = \OCP\Files::tmpFile($ext);
|
||||
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
|
||||
if ($this->file_exists($path)) {
|
||||
$source = $this->fopen($path, 'r');
|
||||
|
@ -464,7 +464,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
|
|||
]);
|
||||
$this->testTimeout();
|
||||
} else {
|
||||
$mimeType = \OC_Helper::getMimetypeDetector()->detectPath($path);
|
||||
$mimeType = \OC::$server->getMimeTypeDetector()->detectPath($path);
|
||||
$this->getConnection()->putObject([
|
||||
'Bucket' => $this->bucket,
|
||||
'Key' => $this->cleanKey($path),
|
||||
|
@ -629,7 +629,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
|
|||
'Bucket' => $this->bucket,
|
||||
'Key' => $this->cleanKey(self::$tmpFiles[$tmpFile]),
|
||||
'SourceFile' => $tmpFile,
|
||||
'ContentType' => \OC_Helper::getMimeType($tmpFile),
|
||||
'ContentType' => \OC::$server->getMimeTypeDetector()->detect($tmpFile),
|
||||
'ContentLength' => filesize($tmpFile)
|
||||
));
|
||||
$this->testTimeout();
|
||||
|
|
|
@ -71,7 +71,7 @@ class Api {
|
|||
*/
|
||||
public static function getUserMounts($params) {
|
||||
$entries = array();
|
||||
$user = \OC_User::getUser();
|
||||
$user = \OC::$server->getUserSession()->getUser()->getUID();
|
||||
|
||||
$mounts = \OC_Mount_Config::getAbsoluteMountPoints($user);
|
||||
foreach($mounts as $mountPoint => $mount) {
|
||||
|
|
|
@ -86,10 +86,9 @@ class OC_Mount_Config {
|
|||
self::addStorageIdToConfig($data['user']);
|
||||
$user = \OC::$server->getUserManager()->get($data['user']);
|
||||
if (!$user) {
|
||||
\OCP\Util::writeLog(
|
||||
'files_external',
|
||||
\OC::$server->getLogger()->warning(
|
||||
'Cannot init external mount points for non-existant user "' . $data['user'] . '".',
|
||||
\OCP\Util::WARN
|
||||
['app' => 'files_external']
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
@ -279,10 +278,11 @@ class OC_Mount_Config {
|
|||
*/
|
||||
public static function readData($user = null) {
|
||||
if (isset($user)) {
|
||||
$jsonFile = OC_User::getHome($user) . '/mount.json';
|
||||
$jsonFile = \OC::$server->getUserManager()->get($user)->getHome() . '/mount.json';
|
||||
} else {
|
||||
$datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data/');
|
||||
$jsonFile = \OC_Config::getValue('mount_file', $datadir . '/mount.json');
|
||||
$config = \OC::$server->getConfig();
|
||||
$datadir = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data/');
|
||||
$jsonFile = $config->getSystemValue('mount_file', $datadir . '/mount.json');
|
||||
}
|
||||
if (is_file($jsonFile)) {
|
||||
$mountPoints = json_decode(file_get_contents($jsonFile), true);
|
||||
|
@ -301,10 +301,11 @@ class OC_Mount_Config {
|
|||
*/
|
||||
public static function writeData($user, $data) {
|
||||
if (isset($user)) {
|
||||
$file = OC_User::getHome($user) . '/mount.json';
|
||||
$file = \OC::$server->getUserManager()->get($user)->getHome() . '/mount.json';
|
||||
} else {
|
||||
$datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data/');
|
||||
$file = \OC_Config::getValue('mount_file', $datadir . '/mount.json');
|
||||
$config = \OC::$server->getConfig();
|
||||
$datadir = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data/');
|
||||
$file = $config->getSystemValue('mount_file', $datadir . '/mount.json');
|
||||
}
|
||||
|
||||
foreach ($data as &$applicables) {
|
||||
|
@ -328,7 +329,7 @@ class OC_Mount_Config {
|
|||
* @return string
|
||||
*/
|
||||
public static function dependencyMessage($backends) {
|
||||
$l = new \OC_L10N('files_external');
|
||||
$l = \OC::$server->getL10N('files_external');
|
||||
$message = '';
|
||||
$dependencyGroups = [];
|
||||
|
||||
|
@ -355,12 +356,12 @@ class OC_Mount_Config {
|
|||
/**
|
||||
* Returns a dependency missing message
|
||||
*
|
||||
* @param OC_L10N $l
|
||||
* @param \OCP\IL10N $l
|
||||
* @param string $module
|
||||
* @param string $backend
|
||||
* @return string
|
||||
*/
|
||||
private static function getSingleDependencyMessage(OC_L10N $l, $module, $backend) {
|
||||
private static function getSingleDependencyMessage(\OCP\IL10N $l, $module, $backend) {
|
||||
switch (strtolower($module)) {
|
||||
case 'curl':
|
||||
return $l->t('<b>Note:</b> The cURL support in PHP is not enabled or installed. Mounting of %s is not possible. Please ask your system administrator to install it.', $backend);
|
||||
|
|
|
@ -244,7 +244,7 @@ class Dropbox extends \OC\Files\Storage\Common {
|
|||
switch ($mode) {
|
||||
case 'r':
|
||||
case 'rb':
|
||||
$tmpFile = \OC_Helper::tmpFile();
|
||||
$tmpFile = \OCP\Files::tmpFile();
|
||||
try {
|
||||
$data = $this->dropbox->getFile($path);
|
||||
file_put_contents($tmpFile, $data);
|
||||
|
@ -270,7 +270,7 @@ class Dropbox extends \OC\Files\Storage\Common {
|
|||
} else {
|
||||
$ext = '';
|
||||
}
|
||||
$tmpFile = \OC_Helper::tmpFile($ext);
|
||||
$tmpFile = \OCP\Files::tmpFile($ext);
|
||||
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
|
||||
if ($this->file_exists($path)) {
|
||||
$source = $this->fopen($path, 'r');
|
||||
|
|
|
@ -429,7 +429,7 @@ class Google extends \OC\Files\Storage\Common {
|
|||
$request = new \Google_Http_Request($downloadUrl, 'GET', null, null);
|
||||
$httpRequest = $this->client->getAuth()->authenticatedRequest($request);
|
||||
if ($httpRequest->getResponseHttpCode() == 200) {
|
||||
$tmpFile = \OC_Helper::tmpFile($ext);
|
||||
$tmpFile = \OCP\Files::tmpFile($ext);
|
||||
$data = $httpRequest->getResponseBody();
|
||||
file_put_contents($tmpFile, $data);
|
||||
return fopen($tmpFile, $mode);
|
||||
|
@ -449,7 +449,7 @@ class Google extends \OC\Files\Storage\Common {
|
|||
case 'x+':
|
||||
case 'c':
|
||||
case 'c+':
|
||||
$tmpFile = \OC_Helper::tmpFile($ext);
|
||||
$tmpFile = \OCP\Files::tmpFile($ext);
|
||||
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
|
||||
if ($this->file_exists($path)) {
|
||||
$source = $this->fopen($path, 'rb');
|
||||
|
@ -466,7 +466,7 @@ class Google extends \OC\Files\Storage\Common {
|
|||
$parentFolder = $this->getDriveFile(dirname($path));
|
||||
if ($parentFolder) {
|
||||
// TODO Research resumable upload
|
||||
$mimetype = \OC_Helper::getMimeType($tmpFile);
|
||||
$mimetype = \OC::$server->getMimeTypeDetector()->detect($tmpFile);
|
||||
$data = file_get_contents($tmpFile);
|
||||
$params = array(
|
||||
'data' => $data,
|
||||
|
|
|
@ -310,7 +310,7 @@ class Swift extends \OC\Files\Storage\Common {
|
|||
switch ($mode) {
|
||||
case 'r':
|
||||
case 'rb':
|
||||
$tmpFile = \OC_Helper::tmpFile();
|
||||
$tmpFile = \OCP\Files::tmpFile();
|
||||
self::$tmpFiles[$tmpFile] = $path;
|
||||
try {
|
||||
$object = $this->getContainer()->getObject($path);
|
||||
|
@ -348,7 +348,7 @@ class Swift extends \OC\Files\Storage\Common {
|
|||
} else {
|
||||
$ext = '';
|
||||
}
|
||||
$tmpFile = \OC_Helper::tmpFile($ext);
|
||||
$tmpFile = \OCP\Files::tmpFile($ext);
|
||||
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
|
||||
if ($this->file_exists($path)) {
|
||||
$source = $this->fopen($path, 'r');
|
||||
|
@ -387,7 +387,7 @@ class Swift extends \OC\Files\Storage\Common {
|
|||
$object->saveMetadata($metadata);
|
||||
return true;
|
||||
} else {
|
||||
$mimeType = \OC_Helper::getMimetypeDetector()->detectPath($path);
|
||||
$mimeType = \OC::$server->getMimeTypeDetector()->detectPath($path);
|
||||
$customHeaders = array('content-type' => $mimeType);
|
||||
$metadataHeaders = DataObject::stockHeaders($metadata);
|
||||
$allHeaders = $customHeaders + $metadataHeaders;
|
||||
|
|
|
@ -418,7 +418,7 @@ abstract class StoragesService {
|
|||
*/
|
||||
protected function triggerApplicableHooks($signal, $mountPoint, $mountType, $applicableArray) {
|
||||
foreach ($applicableArray as $applicable) {
|
||||
\OC_Hook::emit(
|
||||
\OCP\Util::emitHook(
|
||||
Filesystem::CLASSNAME,
|
||||
$signal,
|
||||
[
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
use \OCA\Files_External\Service\BackendService;
|
||||
|
||||
OC_Util::checkAdminUser();
|
||||
\OCP\User::checkAdminUser();
|
||||
|
||||
// we must use the same container
|
||||
$appContainer = \OC_Mount_Config::$app->getContainer();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php /** @var $l OC_L10N */ ?>
|
||||
<?php /** @var $l \OCP\IL10N */ ?>
|
||||
<div id="controls">
|
||||
<div id="file_action_panel"></div>
|
||||
</div>
|
||||
|
|
|
@ -31,9 +31,14 @@ class UserStoragesServiceTest extends StoragesServiceTest {
|
|||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->userId = $this->getUniqueID('user_');
|
||||
$userManager = \OC::$server->getUserManager();
|
||||
|
||||
$this->userId = $this->getUniqueID('user_');
|
||||
$this->user = $userManager->createUser(
|
||||
$this->userId,
|
||||
$this->userId
|
||||
);
|
||||
|
||||
$this->user = new \OC\User\User($this->userId, null);
|
||||
$userSession = $this->getMock('\OCP\IUserSession');
|
||||
$userSession
|
||||
->expects($this->any())
|
||||
|
@ -48,6 +53,7 @@ class UserStoragesServiceTest extends StoragesServiceTest {
|
|||
|
||||
public function tearDown() {
|
||||
@unlink($this->dataDir . '/' . $this->userId . '/mount.json');
|
||||
$this->user->delete();
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue