ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilUpdateUtilsMailMigration.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
29{
30 public static function removeTrailingPathSeparators($path)
31 {
32 $path = preg_replace("/[\/\\\]+$/", "", $path);
33 return $path;
34 }
35
36 public static function getWebspaceDir($mode = "filesystem")
37 {
38 global $ilias;
39
40 if ($mode == "filesystem") {
41 return "./" . ILIAS_WEB_DIR . "/" . $ilias->client_id;
42 } else {
43 if (defined("ILIAS_MODULE")) {
44 return "../" . ILIAS_WEB_DIR . "/" . $ilias->client_id;
45 } else {
46 return "./" . ILIAS_WEB_DIR . "/" . $ilias->client_id;
47 }
48 }
49
50 //return $ilias->ini->readVariable("server","webspace_dir");
51 }
52
53 public static function getDataDir()
54 {
55 return CLIENT_DATA_DIR;
56 }
57
58 public static function makeDir($a_dir)
59 {
60 $a_dir = trim($a_dir);
61
62 // remove trailing slash (bugfix for php 4.2.x)
63 if (substr($a_dir, -1) == "/") {
64 $a_dir = substr($a_dir, 0, -1);
65 }
66
67 // check if a_dir comes with a path
68 if (!($path = substr($a_dir, 0, strrpos($a_dir, "/") - strlen($a_dir)))) {
69 $path = ".";
70 }
71
72 // create directory with file permissions of parent directory
73 umask(0000);
74 return @mkdir($a_dir, fileperms($path));
75 }
76
77 public static function makeDirParents($a_dir)
78 {
79 $dirs = array($a_dir);
80 $a_dir = dirname($a_dir);
81 $last_dirname = '';
82 while ($last_dirname != $a_dir) {
83 array_unshift($dirs, $a_dir);
84 $last_dirname = $a_dir;
85 $a_dir = dirname($a_dir);
86 }
87
88 // find the first existing dir
89 $reverse_paths = array_reverse($dirs, true);
90 $found_index = -1;
91 foreach ($reverse_paths as $key => $value) {
92 if ($found_index == -1) {
93 if (is_dir($value)) {
94 $found_index = $key;
95 }
96 }
97 }
98
99 umask(0000);
100 foreach ($dirs as $dirindex => $dir) {
101 // starting with the longest existing path
102 if ($dirindex >= $found_index) {
103 if (!file_exists($dir)) {
104 if (strcmp(substr($dir, strlen($dir) - 1, 1), "/") == 0) {
105 // on some systems there is an error when there is a slash
106 // at the end of a directory in mkdir, see Mantis #2554
107 $dir = substr($dir, 0, strlen($dir) - 1);
108 }
109 if (!mkdir($dir, $umask)) {
110 error_log("Can't make directory: $dir");
111 return false;
112 }
113 } elseif (!is_dir($dir)) {
114 error_log("$dir is not a directory");
115 return false;
116 } else {
117 // get umask of the last existing parent directory
118 $umask = fileperms($dir);
119 }
120 }
121 }
122 return true;
123 }
124
125 public static function delDir($a_dir)
126 {
127 if (!is_dir($a_dir) || is_int(strpos($a_dir, ".."))) {
128 return;
129 }
130
131 $current_dir = opendir($a_dir);
132
133 $files = array();
134
135 // this extra loop has been necessary because of a strange bug
136 // at least on MacOS X. A looped readdir() didn't work
137 // correctly with larger directories
138 // when an unlink happened inside the loop. Getting all files
139 // into the memory first solved the problem.
140 while ($entryname = readdir($current_dir)) {
141 $files[] = $entryname;
142 }
143
144 foreach ($files as $file) {
145 if (is_dir($a_dir . "/" . $file) and ($file != "." and $file != "..")) {
146 self::delDir(${a_dir} . "/" . ${file});
147 } elseif ($file != "." and $file != "..") {
148 unlink(${a_dir} . "/" . ${file});
149 }
150 }
151
152 closedir($current_dir);
153 @rmdir(${a_dir});
154 }
155
156 public static function getDir($a_dir)
157 {
158 $current_dir = opendir($a_dir);
159
160 $dirs = array();
161 $files = array();
162 while ($entry = readdir($current_dir)) {
163 if (is_dir($a_dir . "/" . $entry)) {
164 $dirs[$entry] = array("type" => "dir", "entry" => $entry);
165 } else {
166 if ($entry != "." && $entry != "..") {
167 $size = filesize($a_dir . "/" . $entry);
168 $files[$entry] = array("type" => "file", "entry" => $entry,
169 "size" => $size);
170 }
171 }
172 }
173 ksort($dirs);
174 ksort($files);
175
176 return array_merge($dirs, $files);
177 }
178
179 public static function ilTempnam()
180 {
181 $temp_path = self::getDataDir() . "/temp";
182 if (!is_dir($temp_path)) {
183 self::makeDir($temp_path);
184 }
185 $temp_name = tempnam($temp_path, "tmp");
186 // --->
187 // added the following line because tempnam creates a backslash on some
188 // Windows systems which leads to problems, because the "...\tmp..." can be
189 // interpreted as "...{TAB-CHARACTER}...". The normal slash works fine
190 // even under windows (Helmut Schottmüller, 2005-08-31)
191 $temp_name = str_replace("\\", "/", $temp_name);
192 // --->
193 unlink($temp_name);
194 return $temp_name;
195 }
196
197 public static function rename($source, $target)
198 {
199 return @rename($source, $target);
200 }
201}
$size
Definition: RandomTest.php:84
An exception for terminatinating execution or to throw for unit testing.
$source
Definition: metadata.php:76