Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.VaultFile.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Retrieve and store file in Vault
8  *
9  * @author Anakeen
10  * @version $Id: Class.VaultFile.php,v 1.23 2008/05/27 12:46:06 marc Exp $
11  * @package FDL
12  */
13 /**
14  */
15 
16 include_once ("VAULT/Class.VaultDiskStorage.php");
17 include_once ("Class.Log.php");
18 define("VAULT_FMODE", 0600);
19 define("VAULT_DMODE", 0700);
20 
21 class VaultFile
22 {
23  /**
24  * @var int file ideentificator
25  */
26  public $idf;
27  public $f_mode = 0600;
28  public $d_mode = 0700;
29  public $type = "fs";
30 
32  /**
33  * @var VaultDiskStorage
34  */
35  public $storage;
36  function __construct($access, $vaultname = "Sample", $idf = - 1)
37  {
38 
39  if (!isset($chrono)) $this->chrono = FALSE;
40  else $this->chrono = $chrono;
41  $this->idf = $idf;
42  $this->name = $vaultname;
43  $this->logger = new Log("", "vault", $this->name);
44  if ($this->chrono) $this->logger->warning("Running with chrono !!!!");
45  $this->dbaccess = $access;
46 
47  $this->f_mode = 0600;
48  $this->d_mode = 0700;
49  $this->type = "fs";
50  switch ($this->type) {
51  case "fs":
52  $this->logger->debug("Set Storage Type to FS");
53  $this->storage = new VaultDiskStorage($access);
54  break;
55 
56  default:
57  // Not implemented yet
58 
59  }
60 }
61 // ---------------------------------------------------------
62 
63 /**
64  * @param int $id_file vault file identifier
65  * @param vaultFileInfo $infos file properties
66  * @param string $teng_lname engine name
67  * @return string error message
68  */
69 function show($id_file, &$infos, $teng_lname = "")
70 {
71  // ---------------------------------------------------------
72  if ($this->chrono) $this->logger->start("Show");
73  $msg = $this->storage->Show($id_file, $infos, $teng_lname);
74  if ($msg != '') {
75  $this->logger->error(sprintf("File #%s : %s", $id_file, $msg));
76  }
77  if ($this->chrono) $this->logger->end("Show");
78  return ($msg);
79 }
80 /**
81  * Set access date to now
82  * @param int $id_file vault file identifier
83  * @return void
84  */
85 function updateAccessDate($id_file)
86 {
87  $this->storage->updateAccessDate($id_file);
88 }
89 /**
90  * retrieve information from vault id
91  * @param int $id_file
92  * @param VaultFileInfo $infos
93  * @return string error message
94  */
95 function retrieve($id_file, &$infos)
96 {
97  // ---------------------------------------------------------
98  if ($this->chrono) $this->logger->start("Retrieve");
99  if (isset($info)) unset($infos);
100 
101  $msg = $this->storage->Show($id_file, $infos);
102 
103  if ($msg != '') $this->logger->error($msg);
104  if ($this->chrono) $this->logger->end("Retrieve");
105  return ($msg);
106 }
107 // ---------------------------------------------------------
108 function store($infile, $public_access, &$id, $fsname = "", $te_name = "", $te_id_file = 0, $tmp = null)
109 {
110  // ---------------------------------------------------------
111  if ($this->chrono) $this->logger->start("Store");
112  $id = - 1;
113  if (!file_exists($infile) || !is_readable($infile) || !is_file($infile)) {
114  $this->logger->error("Can't access file [" . $infile . "].");
115  $msg = _("can't access file");
116  } else {
117  if (!is_bool($public_access)) {
118  $public_access = FALSE;
119  $this->logger->warning("Access mode forced to RESTRICTED for " . $infile . "].");
120  }
121  $this->storage->id_tmp = $tmp;
122  $msg = $this->storage->Store($infile, $public_access, $id, $fsname, $te_name, $te_id_file);
123  if ($msg) $this->logger->error($msg);
124  }
125  if ($this->chrono) $this->logger->end("Store");
126  return ($msg);
127 }
128 // ---------------------------------------------------------
129 function save($infile, $public_access, $id)
130 {
131  // ---------------------------------------------------------
132  if ($this->chrono) $this->logger->start("Save");
133 
134  if (!is_bool($public_access)) {
135  $public_access = FALSE;
136  $this->logger->warning("Access mode forced to RESTRICTED for " . $infile . "].");
137  }
138 
139  $msg = $this->storage->Save($infile, $public_access, $id);
140  if ($msg) $this->logger->error($msg);
141 
142  $this->storage->mime_t = getTextMimeFile($infile);
143  $this->storage->mime_s = getSysMimeFile($infile, $this->storage->name);
144  $msg = $this->storage->Modify();
145  if ($this->chrono) $this->logger->end("Save");
146  return ($msg);
147 }
148 /**
149  * Modification of properties if file
150  * @param int $id_file vault id
151  * @param string $newname new file name
152  * @return string error message (empty if no error)
153  */
154 function rename($id_file, $newname)
155 {
156  // ---------------------------------------------------------
157  if ($this->chrono) $this->logger->start("Rename");
158  $msg = '';
159  if ($newname != "") {
160  $nn = str_replace(array(
161  '/',
162  '\\',
163  '?',
164  '*',
165  ':'
166  ) , '-', $newname);
167  if ($nn != $newname) {
168  addWarningMsg(sprintf(_("Some characters are not authorized for file name %s. They are replaced by -") , $nn));
169  $newname = $nn;
170  }
171 
172  include_once ("WHAT/Lib.FileMime.php");
173  $infile = $this->storage->getPath();
174  $oldname = $this->storage->name;
175  $this->storage->Show($id_file, $infos);
176  $this->storage->name = $newname;
177  $this->storage->mime_t = getTextMimeFile($infile, $this->storage->name);
178  $this->storage->mime_s = getSysMimeFile($infile, $this->storage->name);
179  $msg = $this->storage->Modify();
180  if ($msg == "") {
181  $pio = pathinfo($oldname);
182  $pin = pathinfo($newname);
183  $epio = isset($pio['extension']) ? $pio['extension'] : "";
184  if ($epio == "") $epio = "nop";
185  $epin = isset($pin['extension']) ? $pin['extension'] : "";
186  if ($epin == "") $epin = "nop";
187  if ($epio != $epin) {
188  // need rename physically file
189  if (preg_match("|(.*)/([0-9]+)\\.[^\\.]*|", $infos->path, $reg)) {
190  $newpath = $reg[1] . "/" . $reg[2] . "." . $epin;
191  rename($infos->path, $newpath);
192  }
193  }
194  }
195  if ($msg) $this->logger->error($msg);
196  }
197 
198  if ($this->chrono) $this->logger->end("Rename");
199  return ($msg);
200 }
201 // ---------------------------------------------------------
202 function listFiles(&$s)
203 {
204  // ---------------------------------------------------------
205  if ($this->chrono) $this->logger->start("ListFiles");
206  $this->storage->ListFiles($s);
207  if ($this->chrono) $this->logger->end("ListFiles");
208  return '';
209 }
210 // ---------------------------------------------------------
211 function destroy($id)
212 {
213  // ---------------------------------------------------------
214  if ($this->chrono) $this->logger->start("Destroy");
215 
216  $msg = $this->storage->Destroy($id);
217  if ($msg != '') $this->logger->error($msg);
218  if ($this->chrono) $this->logger->end("Destroy");
219  return $msg;
220 }
221 }
$s type
Definition: dav.php:73
getTextMimeFile($f, $fn= '')
const VAULT_DMODE
print $fam getTitle() $fam name
retrieve($id_file, &$infos)
updateAccessDate($id_file)
addWarningMsg($msg)
Definition: Lib.Common.php:95
getSysMimeFile($f, $fn="")
if($famId) $s
$fsname
Definition: vault_init.php:26
store($infile, $public_access, &$id, $fsname="", $te_name="", $te_id_file=0, $tmp=null)
save($infile, $public_access, $id)
show($id_file, &$infos, $teng_lname="")
rename($id_file, $newname)
__construct($access, $vaultname="Sample", $idf=-1)
$info
Definition: geticon.php:30
$vaultname
Definition: checkVault.php:28
← centre documentaire © anakeen