InvalidBackend.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud GmbH.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Robin Appelman <robin@icewind.nl>
  8. * @author Vincent Petry <vincent@nextcloud.com>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OCA\Files_External\Lib\Backend;
  26. use OCA\Files_External\Lib\StorageConfig;
  27. use OCP\Files\StorageNotAvailableException;
  28. use OCP\IUser;
  29. /**
  30. * Invalid storage backend representing a backend
  31. * that could not be resolved
  32. */
  33. class InvalidBackend extends Backend {
  34. /** @var string Invalid backend id */
  35. private $invalidId;
  36. /**
  37. * Constructs a new InvalidBackend with the id of the invalid backend
  38. * for display purposes
  39. *
  40. * @param string $invalidId id of the backend that did not exist
  41. */
  42. public function __construct($invalidId) {
  43. $this->invalidId = $invalidId;
  44. $this
  45. ->setIdentifier($invalidId)
  46. ->setStorageClass('\OC\Files\Storage\FailedStorage')
  47. ->setText('Unknown storage backend ' . $invalidId);
  48. }
  49. /**
  50. * Returns the invalid backend id
  51. *
  52. * @return string invalid backend id
  53. */
  54. public function getInvalidId() {
  55. return $this->invalidId;
  56. }
  57. /**
  58. * @return void
  59. */
  60. public function manipulateStorageConfig(StorageConfig &$storage, ?IUser $user = null) {
  61. $storage->setBackendOption('exception', new \Exception('Unknown storage backend "' . $this->invalidId . '"', StorageNotAvailableException::STATUS_ERROR));
  62. }
  63. }