3 * @file src/Model/Storage/Filesystem.php
4 * Storage backend system
7 namespace Friendica\Model\Storage;
9 use Friendica\Core\L10n;
10 use Psr\Log\LoggerInterface;
11 use Friendica\Database\Database as DBA;
14 * Database based storage system
16 * This class manage data stored in database table.
18 class Database extends AbstractStorage
20 const NAME = 'Database';
27 * @param LoggerInterface $logger
30 public function __construct(DBA $dba, LoggerInterface $logger, L10n $l10n)
32 parent::__construct($l10n, $logger);
40 public function get(string $reference)
42 $result = $this->dba->selectFirst('storage', ['data'], ['id' => $reference]);
43 if (!$this->dba->isResult($result)) {
47 return $result['data'];
53 public function put(string $data, string $reference = '')
55 if ($reference !== '') {
56 $result = $this->dba->update('storage', ['data' => $data], ['id' => $reference]);
57 if ($result === false) {
58 $this->logger->warning('Failed to update data.', ['id' => $reference, 'errorCode' => $this->dba->errorNo(), 'errorMessage' => $this->dba->errorMessage()]);
59 throw new StorageException($this->l10n->t('Database storage failed to update %s', $reference));
64 $result = $this->dba->insert('storage', ['data' => $data]);
65 if ($result === false) {
66 $this->logger->warning('Failed to insert data.', ['errorCode' => $this->dba->errorNo(), 'errorMessage' => $this->dba->errorMessage()]);
67 throw new StorageException($this->l10n->t('Database storage failed to insert data'));
70 return $this->dba->lastInsertId();
77 public function delete(string $reference)
79 return $this->dba->delete('storage', ['id' => $reference]);
85 public function getOptions()
93 public function saveOptions(array $data)
101 public static function getName()