ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $factor = pow(self::FACTOR, $i);
88 if (($tmp = (int) ($num / $factor)) or $found) {
89 $path[] = $tmp;
90 $num = $num % $factor;
91 $found = true;
92 }
93 }
94
95 if (count($path)) {
96 $path_string = (implode('/', $path) . '/');
97 }
98 return $path_string . $a_name . '_' . $a_container_id;
99 }
100
110 abstract protected function getPathPrefix();
111
122 abstract protected function getPathPostfix();
123
130 public function create()
131 {
132 if (!file_exists($this->path)) {
134 }
135 return true;
136 }
137
138
145 public function getAbsolutePath()
146 {
147 return $this->path;
148 }
149
155 private function init()
156 {
157 switch ($this->storage_type) {
160 break;
161
164 break;
165 }
167 $this->path .= '/';
168
169 // Append path prefix
170 $this->path .= ($this->getPathPrefix() . '/');
171
172 if ($this->path_conversion) {
173 $this->path .= self::_createPathFromId($this->container_id, $this->getPathPostfix());
174 } else {
175 $this->path .= ($this->getPathPostfix() . '_' . $this->container_id);
176 }
177 return true;
178 }
179
187 public function writeToFile($a_data, $a_absolute_path)
188 {
189 if (!$fp = @fopen($a_absolute_path, 'w+')) {
190 return false;
191 }
192 if (@fwrite($fp, $a_data) === false) {
193 @fclose($fp);
194 return false;
195 }
196 @fclose($fp);
197 return true;
198 }
199
207 public function deleteFile($a_abs_name)
208 {
209 if (@file_exists($a_abs_name)) {
210 @unlink($a_abs_name);
211 return true;
212 }
213 return false;
214 }
215
223 public function deleteDirectory($a_abs_name)
224 {
225 if (@file_exists($a_abs_name)) {
227 return true;
228 }
229 return false;
230 }
231
232
240 public function delete()
241 {
243 }
244
245
254 public function copyFile($a_from, $a_to)
255 {
256 if (@file_exists($a_from)) {
257 @copy($a_from, $a_to);
258 return true;
259 }
260 return false;
261 }
262
272 public function _copyDirectory($a_source, $a_target)
273 {
274 return ilUpdateUtilsMailMigration::rCopy($a_source, $a_target);
275 }
276
277 public function appendToPath($a_appendix)
278 {
279 $this->path .= $a_appendix;
280 }
281
282 public function getStorageType()
283 {
284 return $this->storage_type;
285 }
286}
An exception for terminatinating execution or to throw for unit testing.
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.
$i
Definition: disco.tpl.php:19