ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilFileSystemStorageMailMigration.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2009 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
34{
35 const STORAGE_WEB = 1;
36 const STORAGE_DATA = 2;
37
38 const FACTOR = 100;
39 const MAX_EXPONENT = 3;
40
41
44 private $path_conversion = false;
45
46 private $path;
47
57 public function __construct($a_storage_type,$a_path_conversion,$a_container_id)
58 {
59 $this->storage_type = $a_storage_type;
60 $this->path_conversion = $a_path_conversion;
61 $this->container_id = $a_container_id;
62
63 // Get path info
64 $this->init();
65 }
66
67 public function getContainerId()
68 {
70 }
71
81 public static function _createPathFromId($a_container_id,$a_name)
82 {
83 $path = array();
84 $found = false;
85 $num = $a_container_id;
86 for($i = self::MAX_EXPONENT; $i > 0;$i--)
87 {
88 $factor = pow(self::FACTOR,$i);
89 if(($tmp = (int) ($num / $factor)) or $found)
90 {
91 $path[] = $tmp;
92 $num = $num % $factor;
93 $found = true;
94 }
95 }
96
97 if(count($path))
98 {
99 $path_string = (implode('/',$path).'/');
100 }
101 return $path_string.$a_name.'_'.$a_container_id;
102 }
103
113 abstract protected function getPathPrefix();
114
125 abstract protected function getPathPostfix();
126
133 public function create()
134 {
135 if(!file_exists($this->path))
136 {
138 }
139 return true;
140 }
141
142
149 public function getAbsolutePath()
150 {
151 return $this->path;
152 }
153
159 private function init()
160 {
161 switch($this->storage_type)
162 {
165 break;
166
169 break;
170 }
172 $this->path .= '/';
173
174 // Append path prefix
175 $this->path .= ($this->getPathPrefix().'/');
176
177 if($this->path_conversion)
178 {
179 $this->path .= self::_createPathFromId($this->container_id,$this->getPathPostfix());
180 }
181 else
182 {
183 $this->path .= ($this->getPathPostfix().'_'.$this->container_id);
184 }
185 return true;
186 }
187
195 public function writeToFile($a_data,$a_absolute_path)
196 {
197 if(!$fp = @fopen($a_absolute_path,'w+'))
198 {
199 return false;
200 }
201 if(@fwrite($fp,$a_data) === false)
202 {
203 @fclose($fp);
204 return false;
205 }
206 @fclose($fp);
207 return true;
208 }
209
217 public function deleteFile($a_abs_name)
218 {
219 if(@file_exists($a_abs_name))
220 {
221 @unlink($a_abs_name);
222 return true;
223 }
224 return false;
225 }
226
234 function deleteDirectory($a_abs_name)
235 {
236 if(@file_exists($a_abs_name))
237 {
239 return true;
240 }
241 return false;
242 }
243
244
252 public function delete()
253 {
255 }
256
257
266 public function copyFile($a_from,$a_to)
267 {
268 if(@file_exists($a_from))
269 {
270 @copy($a_from,$a_to);
271 return true;
272 }
273 return false;
274 }
275
285 public function _copyDirectory($a_source,$a_target)
286 {
287 return ilUpdateUtilsMailMigration::rCopy($a_source,$a_target);
288 }
289
290 public function appendToPath($a_appendix)
291 {
292 $this->path .= $a_appendix;
293 }
294
295 public function getStorageType()
296 {
297 return $this->storage_type;
298 }
299}
300
301?>
static _createPathFromId($a_container_id, $a_name)
Create a path from an id: e.g 12345 will be converted to 12/34/<name>_5.
writeToFile($a_data, $a_absolute_path)
Write data to file.
getPathPostfix()
Get directory name.
getPathPrefix()
Get path prefix.
_copyDirectory($a_source, $a_target)
Copy directory and all contents.
getAbsolutePath()
Get absolute path of storage directory.
__construct($a_storage_type, $a_path_conversion, $a_container_id)
Constructor.