From 4d7130ad315637b7b7b925efce4032472f4530f8 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Tue, 2 Feb 2016 14:07:11 +0100 Subject: [PATCH] [Share 2.0] Add exceptions to OCP --- apps/files_sharing/api/share20ocs.php | 6 ++-- .../lib/controllers/sharecontroller.php | 5 ++-- .../tests/api/share20ocstest.php | 2 +- .../tests/controller/sharecontroller.php | 4 +-- lib/private/share20/defaultshareprovider.php | 2 +- lib/private/share20/manager.php | 2 +- .../exceptions/genericshareexception.php | 28 +++++++++++++++++++ .../share/exceptions}/sharenotfound.php | 11 ++++++-- .../lib/share20/defaultshareprovidertest.php | 4 +-- tests/lib/share20/managertest.php | 2 +- 10 files changed, 51 insertions(+), 15 deletions(-) create mode 100644 lib/public/share/exceptions/genericshareexception.php rename lib/{private/share20/exception => public/share/exceptions}/sharenotfound.php (81%) diff --git a/apps/files_sharing/api/share20ocs.php b/apps/files_sharing/api/share20ocs.php index 8fe8991f9c..a9f3214377 100644 --- a/apps/files_sharing/api/share20ocs.php +++ b/apps/files_sharing/api/share20ocs.php @@ -148,7 +148,7 @@ class Share20OCS { // First check if it is an internal share. try { $share = $this->shareManager->getShareById('ocinternal:'.$id); - } catch (\OC\Share20\Exception\ShareNotFound $e) { + } catch (\OCP\Share\Exceptions\ShareNotFound $e) { // Ignore for now //return new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.'); } @@ -178,7 +178,7 @@ class Share20OCS { try { $share = $this->shareManager->getShareById('ocinternal:' . $id); - } catch (\OC\Share20\Exception\ShareNotFound $e) { + } catch (\OCP\Share\Exceptions\ShareNotFound $e) { //Ignore for now //return new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.'); } @@ -443,7 +443,7 @@ class Share20OCS { try { $share = $this->shareManager->getShareById('ocinternal:' . $id); - } catch (\OC\Share20\Exception\ShareNotFound $e) { + } catch (\OCP\Share\Exceptions\ShareNotFound $e) { //Ignore for now //return new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.'); } diff --git a/apps/files_sharing/lib/controllers/sharecontroller.php b/apps/files_sharing/lib/controllers/sharecontroller.php index 9fec57edbd..6ac585e275 100644 --- a/apps/files_sharing/lib/controllers/sharecontroller.php +++ b/apps/files_sharing/lib/controllers/sharecontroller.php @@ -52,6 +52,7 @@ use OCP\Util; use OCA\Files_Sharing\Activity; use \OCP\Files\NotFoundException; use OCP\Files\IRootFolder; +use OCP\Share\Exceptions\ShareNotFound; /** * Class ShareController @@ -147,7 +148,7 @@ class ShareController extends Controller { // Check whether share exists try { $share = $this->shareManager->getShareByToken($token); - } catch (\OC\Share20\Exception\ShareNotFound $e) { + } catch (ShareNotFound $e) { return new NotFoundResponse(); } @@ -203,7 +204,7 @@ class ShareController extends Controller { // Check whether share exists try { $share = $this->shareManager->getShareByToken($token); - } catch (\OC\Share20\Exception\ShareNotFound $e) { + } catch (ShareNotFound $e) { return new NotFoundResponse(); } diff --git a/apps/files_sharing/tests/api/share20ocstest.php b/apps/files_sharing/tests/api/share20ocstest.php index 111fad0236..77331fada5 100644 --- a/apps/files_sharing/tests/api/share20ocstest.php +++ b/apps/files_sharing/tests/api/share20ocstest.php @@ -96,7 +96,7 @@ class Share20OCSTest extends \Test\TestCase { ->expects($this->once()) ->method('getShareById') ->with('ocinternal:42') - ->will($this->throwException(new \OC\Share20\Exception\ShareNotFound())); + ->will($this->throwException(new \OCP\Share\Exceptions\ShareNotFound())); $expected = new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.'); $this->assertEquals($expected, $this->ocs->deleteShare(42)); diff --git a/apps/files_sharing/tests/controller/sharecontroller.php b/apps/files_sharing/tests/controller/sharecontroller.php index 9f1d38f9f2..e36ee9e491 100644 --- a/apps/files_sharing/tests/controller/sharecontroller.php +++ b/apps/files_sharing/tests/controller/sharecontroller.php @@ -30,7 +30,7 @@ namespace OCA\Files_Sharing\Controllers; use OC\Files\Filesystem; -use OC\Share20\Exception\ShareNotFound; +use OCP\Share\Exceptions\ShareNotFound; use OCP\AppFramework\Http\NotFoundResponse; use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Http\TemplateResponse; @@ -175,7 +175,7 @@ class ShareControllerTest extends \Test\TestCase { ->expects($this->once()) ->method('getShareByToken') ->with('token') - ->will($this->throwException(new \OC\Share20\Exception\ShareNotFound())); + ->will($this->throwException(new \OCP\Share\Exceptions\ShareNotFound())); $response = $this->shareController->authenticate('token'); $expectedResponse = new NotFoundResponse(); diff --git a/lib/private/share20/defaultshareprovider.php b/lib/private/share20/defaultshareprovider.php index 224dddf401..7b78be2b61 100644 --- a/lib/private/share20/defaultshareprovider.php +++ b/lib/private/share20/defaultshareprovider.php @@ -24,7 +24,7 @@ use OCP\Files\File; use OCP\Share\IShareProvider; use OC\Share20\Exception\InvalidShare; use OC\Share20\Exception\ProviderException; -use OC\Share20\Exception\ShareNotFound; +use OCP\Share\Exceptions\ShareNotFound; use OC\Share20\Exception\BackendError; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\Files\NotFoundException; diff --git a/lib/private/share20/manager.php b/lib/private/share20/manager.php index b22b81bb40..8ea9d10c1c 100644 --- a/lib/private/share20/manager.php +++ b/lib/private/share20/manager.php @@ -36,7 +36,7 @@ use OCP\Files\File; use OCP\Files\Folder; use OCP\IUser; -use OC\Share20\Exception\ShareNotFound; +use OCP\Share\Exceptions\ShareNotFound; use OC\HintException; /** diff --git a/lib/public/share/exceptions/genericshareexception.php b/lib/public/share/exceptions/genericshareexception.php new file mode 100644 index 0000000000..83dfa12dbf --- /dev/null +++ b/lib/public/share/exceptions/genericshareexception.php @@ -0,0 +1,28 @@ + * */ -namespace OC\Share20\Exception; -class ShareNotFound extends \Exception { +namespace OCP\Share\Exceptions; + +/** + * Class ShareNotFound + * + * @package OCP\Share\Exceptions + * @since 9.0.0 + */ +class ShareNotFound extends GenericShareException { } diff --git a/tests/lib/share20/defaultshareprovidertest.php b/tests/lib/share20/defaultshareprovidertest.php index 504bd77603..32c0b342c4 100644 --- a/tests/lib/share20/defaultshareprovidertest.php +++ b/tests/lib/share20/defaultshareprovidertest.php @@ -110,7 +110,7 @@ class DefaultShareProviderTest extends \Test\TestCase { /** - * @expectedException \OC\Share20\Exception\ShareNotFound + * @expectedException \OCP\Share\Exceptions\ShareNotFound */ public function testGetShareByIdNotExist() { $this->provider->getShareById(1); @@ -809,7 +809,7 @@ class DefaultShareProviderTest extends \Test\TestCase { } /** - * @expectedException \OC\Share20\Exception\ShareNotFound + * @expectedException \OCP\Share\Exceptions\ShareNotFound */ public function testGetShareByTokenNotFound() { $this->provider->getShareByToken('invalidtoken'); diff --git a/tests/lib/share20/managertest.php b/tests/lib/share20/managertest.php index 6043d30a0b..5dcf8f0760 100644 --- a/tests/lib/share20/managertest.php +++ b/tests/lib/share20/managertest.php @@ -129,7 +129,7 @@ class ManagerTest extends \Test\TestCase { } /** - * @expectedException \OC\Share20\Exception\ShareNotFound + * @expectedException \OCP\Share\Exceptions\ShareNotFound */ public function testDeleteNoShareId() { $share = $this->getMock('\OCP\Share\IShare');