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