16 include_once (
"VAULT/Class.VaultDiskFsStorage.php");
17 include_once (
"VAULT/Class.VaultDiskFsCache.php");
18 include_once (
"VAULT/Class.VaultDiskDirStorage.php");
19 include_once (
"VAULT/Lib.VaultCommon.php");
48 id_file bigint not null, primary key (id_file),
55 mime_t text DEFAULT '',
56 mime_s text DEFAULT '',
58 cdate timestamp DEFAULT null,
59 mdate timestamp DEFAULT null,
60 adate timestamp DEFAULT null,
62 teng_state int DEFAULT 0,
63 teng_lname text DEFAULT '',
64 teng_id_file bigint DEFAULT -1,
65 teng_comment text DEFAULT ''
68 CREATE INDEX vault_iddir on vaultdiskstorage (id_dir);
69 CREATE INDEX vault_teng on vaultdiskstorage (teng_state);
70 CREATE INDEX vault_tengid on vaultdiskstorage (teng_id_file);";
104 $this->logger =
new Log(
"",
"vault", $this->
name);
112 if ($this->storage == 1) {
116 $this->fs->Select($this->id_fs);
142 while (empty($newId)) {
143 $bytes = openssl_random_pseudo_bytes(PHP_INT_SIZE);
144 if ($bytes ===
false) {
145 throw new \Dcp\Exception(sprintf(
"Unable to get cryptographically strong random bytes from openssl: your system might be broken or too old."));
151 if (strlen($bytes) !== PHP_INT_SIZE) {
152 throw new \Dcp\Exception(sprintf(
"Unable to get cryptographically strong random bytes from openssl: your system might be broken or too old."));
157 if (PHP_INT_SIZE == 4) {
158 $bytes = ($bytes &
"\x7f\xff\xff\xff");
159 $int = unpack(
"Nint4", $bytes);
161 } elseif (PHP_INT_SIZE == 8) {
162 $bytes = ($bytes &
"\x7f\xff\xff\xff" .
"\xff\xff\xff\xff");
168 $upper_int = unpack(
"Nint4", substr($bytes, 0, 4));
169 $lower_int = unpack(
"Nint4", substr($bytes, 4, 4));
170 $int = ($upper_int[
'int4'] << 32) + $lower_int[
'int4'];
172 throw new \Dcp\Exception(sprintf(
"Unsupported PHP_INT_SIZE '%d'.", PHP_INT_SIZE));
179 throw new \Dcp\Exception(sprintf(
"Unexpected negative integer value with PHP_INT_SIZE '%d' and binary data '0x%s'.", PHP_INT_SIZE, bin2hex($bytes)));
185 SELECT id_file FROM %s WHERE id_file = %d LIMIT 1
190 throw new \Dcp\Db\Exception(
"DB0104",
$err);
213 return preg_match(
'!!u', $Str);
228 include_once (
"WHAT/Lib.FileMime.php");
230 if (!is_file($infile)) {
233 if (!is_readable($infile)) {
236 $this->size = filesize($infile);
239 $this->logger->error(
"Can't find free entry in vault. [reason $msg]");
251 $this->cdate = $this->mdate = $this->adate = date(
"c", time());
253 $this->teng_state =
'';
254 $this->teng_lname = $te_lname;
255 $this->teng_id_file = $te_id_file;
258 if ($msg !=
'')
return ($msg);
260 $this->fs->closeCurrentDir();
264 if (!@copy($infile, $f)) {
266 $this->logger->error(sprintf(_(
"Failed to copy %s to %s") , $infile, $f));
267 return (sprintf(_(
"Failed to copy %s to vault") , $infile));
270 $this->logger->debug(
"File $infile stored in $f");
285 if (!$this->
isAffected())
return _(
"vault file is not initialized");
287 $q =
new QueryDb($this->dbaccess,
"VaultDiskStorage");
288 $q->AddQuery(
"teng_id_file=" . $this->id_file);
289 $q->AddQuery(
"teng_lname='" . pg_escape_string($te_name) .
"'");
294 $ngf->teng_lname = $te_name;
297 $ngf->cdate = $ngf->mdate = $ngf->adate = date(
"c", time());
317 $this->id_file = - 1;
320 $query->AddQuery(sprintf(
"teng_id_file = E'%s'::bigint", pg_escape_string(
$id_file)));
323 $t =
$query->Query(0, 0,
"TABLE");
330 if (($this->id_file == - 1) && (
$teng_lname ==
"")) {
334 if ($this->id_file != - 1) {
335 $this->fs->Show($this->id_fs, $this->id_dir, $f_path);
355 return (_(
"file does not exist in vault"));
366 $this->adate = date(
"c", time());
379 $this->fs->Show($this->id_fs, $this->id_dir, $f_path);
386 $msg = $this->Show($id, $inf);
389 $msg = $this->fs->DelEntry($this->id_fs, $this->id_dir, $inf->size);
407 $this->size = filesize($infile);
408 $newsize = $this->size -
$size;
412 $this->mdate = date(
"c", time());
415 if ($msg !=
'')
return ($msg);
417 if (!copy($infile,
$path)) {
418 $err = sprintf(_(
"Cannot copy file %s to %s") , $infile,
$path);
420 $this->fs->select($this->id_fs);
421 $this->logger->debug(
"File $infile saved in $path");
426 $err = sprintf(
"cannot save file : invalid vault descriptor %s", $idf);
435 if (\Dcp\Autoloader::classExists(
'Dcp\TransformationEngine\Client')) {
437 UPDATE %s SET teng_state = %d WHERE teng_id_file = %s
440 $up = sprintf(
$sql, pg_escape_identifier($this->dbtable) , pg_escape_literal(\Dcp\TransformationEngine\Client::status_inprogress) , pg_escape_literal($this->id_file));
updateAccessDate($id_file)
getTextMimeFile($f, $fn= '')
exec_query($sql, $lvl=0, $prepare=false)
print $fam getTitle() $fam name
Add($nopost=false, $nopre=false)
vaultfilename($fspath, $name, $id)
getSysMimeFile($f, $fn="")
static getError($code, $args=null)
__construct($dbaccess= '', $id= '', $res= '', $dbid=0)
modify($nopost=false, $sfields="", $nopre=false)
Store($infile, $public_access, &$idf, $fsname="", $te_lname="", $te_id_file=0)
show($id_file, &$f_infos, $teng_lname="")
if(($docid!==0)&&(!is_numeric($docid))) $query
if($file) if($subject==""&&$file) if($subject=="") $err
GetEngineObject($te_name, &$ngf)
__construct($dbaccess= '', $id= '', $res= '', $dbid=0)
save($infile, $public_access, $idf)