Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
VaultManager.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 
7 namespace Dcp;
8 
10 {
11 
12  protected static $vault = null;
13  /**
14  * @return \VaultFile
15  */
16  protected static function getVault()
17  {
18 
19  if (self::$vault === null) {
20  self::$vault = new \VaultFile("", "FREEDOM");
21  }
22  return self::$vault;
23  }
24  /**
25  * return various informations for a file stored in VAULT
26  * @param int $idfile vault file identifier
27  * @param string $teng_name transformation engine name
28  * @return \vaultFileInfo
29  */
30  public static function getFileInfo($idfile, $teng_name = "")
31  {
32  self::getVault()->Show($idfile, $info, $teng_name);
33  if (!$info) {
34  return null;
35  }
36  return $info;
37  }
38  /**
39  * return various informations for a file stored in VAULT
40  * @param string $filepath
41  * @param string $ftitle
42  * @param bool $public_access set to true to store uncontrolled files like icons
43  * @return int
44  * @throws Exception
45  */
46  public static function storeFile($filepath, $ftitle = "", $public_access = false)
47  {
48 
49  $err = self::getVault()->store($filepath, $public_access, $vid);
50  if ($err) {
51  throw new Exception("VAULT0001", $err);
52  }
53  if ($ftitle != "") self::getVault()->rename($vid, $ftitle);
54  return $vid;
55  }
56  /**
57  * return various informations for a file stored in VAULT
58  * @param string $filepath
59  * @param string $ftitle
60  * @throws Exception
61  * @return int return vault identifier
62  */
63  public static function storeTemporaryFile($filepath, $ftitle = "")
64  {
66  throw new Exception("VAULT0003");
67  }
68  $err = self::getVault()->store($filepath, false, $vid, $fsname = '', $te = "", 0, $tmp = \AuthenticatorManager::$session->id);
69 
70  if ($err) {
71  throw new Exception("VAULT0002", $err);
72  }
73  if ($ftitle != "") self::getVault()->rename($vid, $ftitle);
74  return $vid;
75  }
76  /**
77  * Delete id_tmp propertty of identified files
78  * @param array $vids vault identifiers list
79  */
80  public static function setFilesPersitent(array $vids)
81  {
82  if (count($vids) > 0) {
83  $sql = sprintf("update vaultdiskstorage set id_tmp = null where id_tmp is not null and id_file in (%s)", implode(",", array_map(function ($x)
84  {
85  return intval($x);
86  }
87  , $vids)));
88  simpleQuery("", $sql);
89  }
90  }
91  /**
92  * Destroy file from vault
93  * The file is physicaly deleted
94  * @param int $vid vault file identifier
95  * @throws Exception
96  */
97  public static function destroyFile($vid)
98  {
99  $info = self::getFileInfo($vid);
100  if ($info === null) {
101  throw new Exception("VAULT0004", $vid);
102  }
103 
104  self::getVault()->destroy($vid);
105  }
106  /**
107  * Delete vault temporary files where create date is less than interval
108  * @param int $dayInterval number of day
109  */
110  public static function destroyTmpFiles($dayInterval = 2)
111  {
112  $sql = sprintf("select id_file from vaultdiskstorage where id_tmp is not null and id_tmp != '' and cdate < (now() - INTERVAL '%d day');", $dayInterval);
113 
114  simpleQuery("", $sql, $result, true);
115  foreach ($result as $vid) {
116  self::destroyFile($vid);
117  }
118  }
119  /**
120  * Set access date to now
121  * @param int $idfile vault file identifier
122  */
123  public static function updateAccessDate($idfile)
124  {
125  self::getVault()->updateAccessDate($idfile);
126  }
127 }
Exception class use exceptionCode to identifiy correctly exception.
Definition: exceptions.php:19
static destroyTmpFiles($dayInterval=2)
$fsname
Definition: vault_init.php:26
static storeTemporaryFile($filepath, $ftitle="")
static updateAccessDate($idfile)
static getFileInfo($idfile, $teng_name="")
static destroyFile($vid)
$info
Definition: geticon.php:30
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
Definition: Lib.Common.php:484
if($file) if($subject==""&&$file) if($subject=="") $err
static storeFile($filepath, $ftitle="", $public_access=false)
static setFilesPersitent(array $vids)
← centre documentaire © anakeen