From 079e9cecbaa3c6f68db6f8b685ec41e078c94ff7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Thu, 2 Jul 2015 13:00:21 +0200 Subject: [PATCH] Revert "Use OCP classes as much as possible in files_external" --- apps/files_external/lib/amazons3.php | 4 +- apps/files_external/lib/api.php | 2 +- apps/files_external/lib/config.php | 32 ++++----- apps/files_external/lib/dropbox.php | 4 +- apps/files_external/lib/google.php | 4 +- apps/files_external/lib/swift.php | 4 +- .../service/storagesservice.php | 2 +- apps/files_external/templates/settings.php | 2 +- apps/files_external/tests/mountconfig.php | 65 +++++++------------ 9 files changed, 49 insertions(+), 70 deletions(-) diff --git a/apps/files_external/lib/amazons3.php b/apps/files_external/lib/amazons3.php index 77918c5507..02a02710a1 100644 --- a/apps/files_external/lib/amazons3.php +++ b/apps/files_external/lib/amazons3.php @@ -373,7 +373,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { switch ($mode) { case 'r': case 'rb': - $tmpFile = \OCP\Files::tmpFile(); + $tmpFile = \OC_Helper::tmpFile(); self::$tmpFiles[$tmpFile] = $path; try { @@ -405,7 +405,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { } else { $ext = ''; } - $tmpFile = \OCP\Files::tmpFile($ext); + $tmpFile = \OC_Helper::tmpFile($ext); \OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack')); if ($this->file_exists($path)) { $source = $this->fopen($path, 'r'); diff --git a/apps/files_external/lib/api.php b/apps/files_external/lib/api.php index 015c15c41f..b9435e3310 100644 --- a/apps/files_external/lib/api.php +++ b/apps/files_external/lib/api.php @@ -71,7 +71,7 @@ class Api { */ public static function getUserMounts($params) { $entries = array(); - $user = \OC::$server->getUserSession()->getUser()->getUID(); + $user = \OC_User::getUser(); $mounts = \OC_Mount_Config::getAbsoluteMountPoints($user); foreach($mounts as $mountPoint => $mount) { diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index 9d8b312e77..5dc6d06ae0 100644 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -124,9 +124,10 @@ class OC_Mount_Config { self::addStorageIdToConfig($data['user']); $user = \OC::$server->getUserManager()->get($data['user']); if (!$user) { - \OC::$server->getLogger()->warning( + \OCP\Util::writeLog( + 'files_external', 'Cannot init external mount points for non-existant user "' . $data['user'] . '".', - ['app' => 'files_external'] + \OCP\Util::WARN ); return; } @@ -160,9 +161,6 @@ class OC_Mount_Config { // Load system mount points $mountConfig = self::readData(); - $userObject = \OC::$server->getUserManager()->get($user); - $groupManager = \OC::$server->getGroupManager(); - // Global mount points (is this redundant?) if (isset($mountConfig[self::MOUNT_TYPE_GLOBAL])) { foreach ($mountConfig[self::MOUNT_TYPE_GLOBAL] as $mountPoint => $options) { @@ -209,7 +207,7 @@ class OC_Mount_Config { // Group mount points if (isset($mountConfig[self::MOUNT_TYPE_GROUP])) { foreach ($mountConfig[self::MOUNT_TYPE_GROUP] as $group => $mounts) { - if ($groupManager->get($group)->inGroup($userObject)) { + if (\OC_Group::inGroup($user, $group)) { foreach ($mounts as $mountPoint => $options) { $mountPoint = self::setUserVars($user, $mountPoint); foreach ($options as &$option) { @@ -583,7 +581,7 @@ class OC_Mount_Config { $result = self::getBackendStatus($class, $classOptions, $isPersonal); if ($result === self::STATUS_SUCCESS && $isNew) { - \OCP\Util::emitHook( + \OC_Hook::emit( \OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_create_mount, array( @@ -629,7 +627,7 @@ class OC_Mount_Config { } } self::writeData($isPersonal ? OCP\User::getUser() : null, $mountPoints); - \OCP\Util::emitHook( + \OC_Hook::emit( \OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_delete_mount, array( @@ -671,11 +669,10 @@ class OC_Mount_Config { */ public static function readData($user = null) { if (isset($user)) { - $jsonFile = \OC::$server->getUserManager()->get($user)->getHome() . '/mount.json'; + $jsonFile = OC_User::getHome($user) . '/mount.json'; } else { - $config = \OC::$server->getConfig(); - $datadir = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data/'); - $jsonFile = $config->getSystemValue('mount_file', $datadir . '/mount.json'); + $datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data/'); + $jsonFile = \OC_Config::getValue('mount_file', $datadir . '/mount.json'); } if (is_file($jsonFile)) { $mountPoints = json_decode(file_get_contents($jsonFile), true); @@ -694,11 +691,10 @@ class OC_Mount_Config { */ public static function writeData($user, $data) { if (isset($user)) { - $file = \OC::$server->getUserManager()->get($user)->getHome() . '/mount.json'; + $file = OC_User::getHome($user) . '/mount.json'; } else { - $config = \OC::$server->getConfig(); - $datadir = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data/'); - $file = $config->getSystemValue('mount_file', $datadir . '/mount.json'); + $datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data/'); + $file = \OC_Config::getValue('mount_file', $datadir . '/mount.json'); } foreach ($data as &$applicables) { @@ -756,7 +752,7 @@ class OC_Mount_Config { } private static function generateDependencyMessage($dependencies) { - $l = \OC::$server->getL10N('files_external'); + $l = new \OC_L10N('files_external'); $dependencyMessage = ''; foreach ($dependencies as $module => $backends) { $dependencyGroup = array(); @@ -793,7 +789,7 @@ class OC_Mount_Config { * @param string $backend * @return string */ - private static function getSingleDependencyMessage(\OCP\IL10N $l, $module, $backend) { + private static function getSingleDependencyMessage(OC_L10N $l, $module, $backend) { switch (strtolower($module)) { case 'curl': return $l->t('Note: 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); diff --git a/apps/files_external/lib/dropbox.php b/apps/files_external/lib/dropbox.php index afdf09a676..78219f8f06 100644 --- a/apps/files_external/lib/dropbox.php +++ b/apps/files_external/lib/dropbox.php @@ -243,7 +243,7 @@ class Dropbox extends \OC\Files\Storage\Common { switch ($mode) { case 'r': case 'rb': - $tmpFile = \OCP\Files::tmpFile(); + $tmpFile = \OC_Helper::tmpFile(); try { $data = $this->dropbox->getFile($path); file_put_contents($tmpFile, $data); @@ -269,7 +269,7 @@ class Dropbox extends \OC\Files\Storage\Common { } else { $ext = ''; } - $tmpFile = \OCP\Files::tmpFile($ext); + $tmpFile = \OC_Helper::tmpFile($ext); \OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack')); if ($this->file_exists($path)) { $source = $this->fopen($path, 'r'); diff --git a/apps/files_external/lib/google.php b/apps/files_external/lib/google.php index b4cc9bb0ea..8199d97eac 100644 --- a/apps/files_external/lib/google.php +++ b/apps/files_external/lib/google.php @@ -428,7 +428,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 = \OCP\Files::tmpFile($ext); + $tmpFile = \OC_Helper::tmpFile($ext); $data = $httpRequest->getResponseBody(); file_put_contents($tmpFile, $data); return fopen($tmpFile, $mode); @@ -448,7 +448,7 @@ class Google extends \OC\Files\Storage\Common { case 'x+': case 'c': case 'c+': - $tmpFile = \OCP\Files::tmpFile($ext); + $tmpFile = \OC_Helper::tmpFile($ext); \OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack')); if ($this->file_exists($path)) { $source = $this->fopen($path, 'rb'); diff --git a/apps/files_external/lib/swift.php b/apps/files_external/lib/swift.php index 4104e97fbe..50f0d40805 100644 --- a/apps/files_external/lib/swift.php +++ b/apps/files_external/lib/swift.php @@ -310,7 +310,7 @@ class Swift extends \OC\Files\Storage\Common { switch ($mode) { case 'r': case 'rb': - $tmpFile = \OCP\Files::tmpFile(); + $tmpFile = \OC_Helper::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 = \OCP\Files::tmpFile($ext); + $tmpFile = \OC_Helper::tmpFile($ext); \OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack')); if ($this->file_exists($path)) { $source = $this->fopen($path, 'r'); diff --git a/apps/files_external/service/storagesservice.php b/apps/files_external/service/storagesservice.php index 84ca8a4524..930f994455 100644 --- a/apps/files_external/service/storagesservice.php +++ b/apps/files_external/service/storagesservice.php @@ -306,7 +306,7 @@ abstract class StoragesService { */ protected function triggerApplicableHooks($signal, $mountPoint, $mountType, $applicableArray) { foreach ($applicableArray as $applicable) { - \OCP\Util::emitHook( + \OC_Hook::emit( Filesystem::CLASSNAME, $signal, [ diff --git a/apps/files_external/templates/settings.php b/apps/files_external/templates/settings.php index d5aba6fc80..b886c2e1b1 100644 --- a/apps/files_external/templates/settings.php +++ b/apps/files_external/templates/settings.php @@ -16,7 +16,7 @@ array('id' => ''))); ?> - data-id=""> + data-id=""> diff --git a/apps/files_external/tests/mountconfig.php b/apps/files_external/tests/mountconfig.php index f198b09c08..b76ba0a39a 100644 --- a/apps/files_external/tests/mountconfig.php +++ b/apps/files_external/tests/mountconfig.php @@ -131,9 +131,6 @@ class Test_Mount_Config extends \Test\TestCase { const TEST_GROUP2 = 'group2'; const TEST_GROUP2B = 'group2b'; - private $users = []; - private $groups = []; - protected function setUp() { parent::setUp(); @@ -150,43 +147,32 @@ class Test_Mount_Config extends \Test\TestCase { ) ); - $userManager = \OC::$server->getUserManager(); - $groupManager = \OC::$server->getGroupManager(); + \OC_User::createUser(self::TEST_USER1, self::TEST_USER1); + \OC_User::createUser(self::TEST_USER2, self::TEST_USER2); - $this->users[self::TEST_USER1] = $userManager->createUser( - self::TEST_USER1, - self::TEST_USER1 - ); - $this->users[self::TEST_USER2] = $userManager->createUser( - self::TEST_USER2, - self::TEST_USER2 - ); + \OC_Group::createGroup(self::TEST_GROUP1); + \OC_Group::createGroup(self::TEST_GROUP1B); + \OC_Group::addToGroup(self::TEST_USER1, self::TEST_GROUP1); + \OC_Group::addToGroup(self::TEST_USER1, self::TEST_GROUP1B); + \OC_Group::createGroup(self::TEST_GROUP2); + \OC_Group::createGroup(self::TEST_GROUP2B); + \OC_Group::addToGroup(self::TEST_USER2, self::TEST_GROUP2); + \OC_Group::addToGroup(self::TEST_USER2, self::TEST_GROUP2B); - $this->groups[self::TEST_GROUP1] = $groupManager->createGroup(self::TEST_GROUP1); - $this->groups[self::TEST_GROUP1B] = $groupManager->createGroup(self::TEST_GROUP1B); - $this->groups[self::TEST_GROUP2] = $groupManager->createGroup(self::TEST_GROUP2); - $this->groups[self::TEST_GROUP2B] = $groupManager->createGroup(self::TEST_GROUP2B); - - $this->groups[self::TEST_GROUP1]->addUser($this->users[self::TEST_USER1]); - $this->groups[self::TEST_GROUP1B]->addUser($this->users[self::TEST_USER1]); - $this->groups[self::TEST_GROUP2]->addUser($this->users[self::TEST_USER2]); - $this->groups[self::TEST_GROUP2B]->addUser($this->users[self::TEST_USER2]); - - \OC::$server->getUserSession()->setUser($this->users[self::TEST_USER1]); - $this->userHome = $this->users[self::TEST_USER1]->getHome(); + \OC_User::setUserId(self::TEST_USER1); + $this->userHome = \OC_User::getHome(self::TEST_USER1); @mkdir($this->userHome); - $config = \OC::$server->getConfig(); - $this->dataDir = $config->getSystemValue( + $this->dataDir = \OC_Config::getValue( 'datadirectory', \OC::$SERVERROOT . '/data/' ); - $this->oldAllowedBackends = $config->getAppValue( + $this->oldAllowedBackends = OCP\Config::getAppValue( 'files_external', 'user_mounting_backends', '' ); - $config->setAppValue( + OCP\Config::setAppValue( 'files_external', 'user_mounting_backends', 'Test_Mount_Config_Dummy_Storage' @@ -200,19 +186,16 @@ class Test_Mount_Config extends \Test\TestCase { Test_Mount_Config_Hook_Test::clear(); OC_Mount_Config::$skipTest = false; - foreach ($this->users as $user) { - $user->delete(); - } - foreach ($this->groups as $group) { - $group->delete(); - } - $this->users = []; - $this->groups = []; + \OC_User::deleteUser(self::TEST_USER2); + \OC_User::deleteUser(self::TEST_USER1); + \OC_Group::deleteGroup(self::TEST_GROUP1); + \OC_Group::deleteGroup(self::TEST_GROUP1B); + \OC_Group::deleteGroup(self::TEST_GROUP2); + \OC_Group::deleteGroup(self::TEST_GROUP2B); @unlink($this->dataDir . '/mount.json'); - $config = \OC::$server->getConfig(); - $config->setAppValue( + OCP\Config::setAppValue( 'files_external', 'user_mounting_backends', $this->oldAllowedBackends @@ -795,7 +778,7 @@ class Test_Mount_Config extends \Test\TestCase { ); // check mount points in the perspective of user $testUser - \OC::$server->getUserSession()->setUser($this->users[$testUser]); + \OC_User::setUserId($testUser); $mountPoints = OC_Mount_Config::getAbsoluteMountPoints($testUser); if ($expectVisible) { @@ -1133,7 +1116,7 @@ class Test_Mount_Config extends \Test\TestCase { ); // Ensure other user can read mount points - \OC::$server->getUserSession()->setUser($this->users[self::TEST_USER2]); + \OC_User::setUserId(self::TEST_USER2); $mountPointsMe = OC_Mount_Config::getAbsoluteMountPoints(self::TEST_USER2); $mountPointsOther = OC_Mount_Config::getAbsoluteMountPoints(self::TEST_USER1);