PageRenderTime 44ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/files/cache/storage.php

https://github.com/sezuan/core
PHP | 60 lines | 37 code | 7 blank | 16 comment | 7 complexity | 0f3f56fd6e67e76df20b7b854a654ebd MD5 | raw file
Possible License(s): AGPL-3.0, AGPL-1.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace OC\Files\Cache;
  9. /**
  10. * Class Storage
  11. *
  12. * cache storage specific data
  13. *
  14. * @package OC\Files\Cache
  15. */
  16. class Storage {
  17. private $storageId;
  18. private $numericId;
  19. /**
  20. * @param \OC\Files\Storage\Storage|string $storage
  21. */
  22. public function __construct($storage) {
  23. if ($storage instanceof \OC\Files\Storage\Storage) {
  24. $this->storageId = $storage->getId();
  25. } else {
  26. $this->storageId = $storage;
  27. }
  28. if (strlen($this->storageId) > 64) {
  29. $this->storageId = md5($this->storageId);
  30. }
  31. $sql = 'SELECT `numeric_id` FROM `*PREFIX*storages` WHERE `id` = ?';
  32. $result = \OC_DB::executeAudited($sql, array($this->storageId));
  33. if ($row = $result->fetchRow()) {
  34. $this->numericId = $row['numeric_id'];
  35. } else {
  36. $sql = 'INSERT INTO `*PREFIX*storages` (`id`) VALUES(?)';
  37. \OC_DB::executeAudited($sql, array($this->storageId));
  38. $this->numericId = \OC_DB::insertid('*PREFIX*storages');
  39. }
  40. }
  41. public function getNumericId() {
  42. return $this->numericId;
  43. }
  44. public static function getStorageId($numericId) {
  45. $sql = 'SELECT `id` FROM `*PREFIX*storages` WHERE `numeric_id` = ?';
  46. $result = \OC_DB::executeAudited($sql, array($numericId));
  47. if ($row = $result->fetchRow()) {
  48. return $row['id'];
  49. } else {
  50. return null;
  51. }
  52. }
  53. }