3 * @file src/Model/Storage/Filesystem.php
4 * @brief Storage backend system
7 namespace Friendica\Model\Storage;
9 use Friendica\Core\Logger;
10 use Friendica\Core\L10n;
11 use Friendica\Core\System;
12 use Friendica\Database\DBA;
15 * @brief Database based storage system
17 * This class manage data stored in database table.
19 class Database implements IStorage
21 public static function get($ref)
23 $r = DBA::selectFirst('storage', ['data'], ['id' => $ref]);
24 if (!DBA::isResult($r)) {
31 public static function put($data, $ref = '')
34 $r = DBA::update('storage', ['data' => $data], ['id' => $ref]);
36 Logger::log('Failed to update data with id ' . $ref . ': ' . DBA::errorNo() . ' : ' . DBA::errorMessage());
37 throw new StorageException(L10n::t('Database storage failed to update %s', $ref));
41 $r = DBA::insert('storage', ['data' => $data]);
43 Logger::log('Failed to insert data: ' . DBA::errorNo() . ' : ' . DBA::errorMessage());
44 throw new StorageException(L10n::t('Database storage failed to insert data'));
46 return DBA::lastInsertId();
50 public static function delete($ref)
52 return DBA::delete('storage', ['id' => $ref]);