Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathDatabaseObjectStorage.php
More file actions
Latest commit
136 lines (119 loc) · 2.99 KB
/
Copy pathDatabaseObjectStorage.php
File metadata and controls
136 lines (119 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
namespaceKanboard\Plugin\DatabaseStorage;
useKanboard\Core\ObjectStorage\ObjectStorageException;
useKanboard\Core\ObjectStorage\ObjectStorageInterface;
usePicoDb\Database;
/**
* Database Object Storage
*
* @package DatabaseStorage
* @author Frederic Guillot
*/
class DatabaseObjectStorage implements ObjectStorageInterface
{
constTABLE = 'object_storage';
/**
* @var Database
*/
protected$db;
/**
* Constructor
*
* @access public
* @param Database $db
*/
publicfunction__construct(Database$db)
{
$this->db = $db;
}
/**
* Fetch object contents
*
* @access public
* @throws ObjectStorageException
* @param string $key
* @return string
*/
publicfunctionget($key)
{
$contents = $this->db
->largeObject(self::TABLE)->eq('object_key', $key)
->findOneColumnAsString('object_data');
if ($contents === false) {
thrownewObjectStorageException('Object not found: '.$key);
}
return$contents;
}
/**
* Save object
*
* @access public
* @throws ObjectStorageException
* @param string $key
* @param string $blob
*/
publicfunctionput($key, &$blob)
{
$result = $this->db->largeObject(self::TABLE)
->insertFromString('object_data', $blob, array('object_key' => $key));
if ($result === false) {
thrownewObjectStorageException('Unable to save object: '.$key);
}
}
/**
* Output directly object content
*
* @access public
* @param string $key
*/
publicfunctionoutput($key)
{
$fd = $this->db->largeObject(self::TABLE)->eq('object_key', $key)->findOneColumnAsStream('object_data');
if (is_string($fd)) {
echo$fd;
} else {
fpassthru($fd);
}
}
/**
* Move local file to object storage
*
* @access public
* @throws ObjectStorageException
* @param string $src_filename
* @param string $key
* @return boolean
*/
publicfunctionmoveFile($src_filename, $key)
{
$result = $this->db->largeObject(self::TABLE)
->insertFromFile('object_data', $src_filename, array('object_key' => $key));
if ($result === false) {
thrownewObjectStorageException('Unable to move this file: '.$src_filename);
}
returntrue;
}
/**
* Move uploaded file to object storage
*
* @access public
* @param string $filename
* @param string $key
* @return boolean
*/
publicfunctionmoveUploadedFile($filename, $key)
{
return$this->moveFile($filename, $key);
}
/**
* Remove object
*
* @access public
* @param string $key
* @return boolean
*/
publicfunctionremove($key)
{
return$this->db->table(self::TABLE)->eq('object_key', $key)->remove();
}
}