Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.4 KiB

  1. <?php
  2. /**
  3. * @file src/Model/Storage/Filesystem.php
  4. * @brief Storage backend system
  5. */
  6. namespace Friendica\Model\Storage;
  7. use Friendica\Core\Logger;
  8. use Friendica\Core\L10n;
  9. use Friendica\Database\DBA;
  10. /**
  11. * @brief Database based storage system
  12. *
  13. * This class manage data stored in database table.
  14. */
  15. class Database implements IStorage
  16. {
  17. public static function get($ref)
  18. {
  19. $r = DBA::selectFirst('storage', ['data'], ['id' => $ref]);
  20. if (!DBA::isResult($r)) {
  21. return '';
  22. }
  23. return $r['data'];
  24. }
  25. public static function put($data, $ref = '')
  26. {
  27. if ($ref !== '') {
  28. $r = DBA::update('storage', ['data' => $data], ['id' => $ref]);
  29. if ($r === false) {
  30. Logger::log('Failed to update data with id ' . $ref . ': ' . DBA::errorNo() . ' : ' . DBA::errorMessage());
  31. throw new StorageException(L10n::t('Database storage failed to update %s', $ref));
  32. }
  33. return $ref;
  34. } else {
  35. $r = DBA::insert('storage', ['data' => $data]);
  36. if ($r === false) {
  37. Logger::log('Failed to insert data: ' . DBA::errorNo() . ' : ' . DBA::errorMessage());
  38. throw new StorageException(L10n::t('Database storage failed to insert data'));
  39. }
  40. return DBA::lastInsertId();
  41. }
  42. }
  43. public static function delete($ref)
  44. {
  45. return DBA::delete('storage', ['id' => $ref]);
  46. }
  47. public static function getOptions()
  48. {
  49. return [];
  50. }
  51. public static function saveOptions($data)
  52. {
  53. return [];
  54. }
  55. }