ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilUpdateUtils Class Reference

util class various functions, usage as namespace More...

+ Collaboration diagram for ilUpdateUtils:

Public Member Functions

 removeTrailingPathSeparators ($path)
 
 getWebspaceDir ($mode="filesystem")
 get webspace directory More...
 
 getDataDir ()
 get data directory (outside webspace) More...
 
 makeDir ($a_dir)
 creates a new directory and inherits all filesystem permissions of the parent directory You may pass only the name of your new directory or with the entire path or relative path information. More...
 
 makeDirParents ($a_dir)
 Create a new directory and all parent directories. More...
 
 delDir ($a_dir)
 removes a dir and all its content (subdirs and files) recursively More...
 
 getDir ($a_dir)
 get directory More...
 

Detailed Description

util class various functions, usage as namespace

Author
Sascha Hofmann sasch.nosp@m.ahof.nosp@m.mann@.nosp@m.gmx..nosp@m.de
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
Id
class.ilUtil.php 13126 2007-01-29 15:51:03 +0000 (Mo, 29 Jan 2007) smeyer

Definition at line 37 of file class.ilUpdateUtils.php.

Member Function Documentation

◆ delDir()

ilUpdateUtils::delDir (   $a_dir)

removes a dir and all its content (subdirs and files) recursively

@access public

Parameters
stringdir to delete
Author
Unknown flexe.nosp@m.r@cu.nosp@m.tephp.nosp@m..com (source: http://www.php.net/rmdir)

Definition at line 184 of file class.ilUpdateUtils.php.

185 {
186 if (!is_dir($a_dir) || is_int(strpos($a_dir, ".."))) {
187 return;
188 }
189
190 $current_dir = opendir($a_dir);
191
192 $files = array();
193
194 // this extra loop has been necessary because of a strange bug
195 // at least on MacOS X. A looped readdir() didn't work
196 // correctly with larger directories
197 // when an unlink happened inside the loop. Getting all files
198 // into the memory first solved the problem.
199 while ($entryname = readdir($current_dir)) {
200 $files[] = $entryname;
201 }
202
203 foreach ($files as $file) {
204 if (is_dir($a_dir . "/" . $file) and ($file != "." and $file!="..")) {
205 ilUtil::delDir(${a_dir} . "/" . ${file});
206 } elseif ($file != "." and $file != "..") {
207 unlink(${a_dir} . "/" . ${file});
208 }
209 }
210
211 closedir($current_dir);
212 rmdir(${a_dir});
213 }
$files
Definition: add-vimline.php:18
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file

References $file, $files, and ilUtil\delDir().

+ Here is the call graph for this function:

◆ getDataDir()

ilUpdateUtils::getDataDir ( )

get data directory (outside webspace)

Definition at line 74 of file class.ilUpdateUtils.php.

75 {
76 return CLIENT_DATA_DIR;
77 //global $ilias;
78
79 //return $ilias->ini->readVariable("server", "data_dir");
80 }

Referenced by ilFileSystemStorage\init().

+ Here is the caller graph for this function:

◆ getDir()

ilUpdateUtils::getDir (   $a_dir)

get directory

Definition at line 219 of file class.ilUpdateUtils.php.

220 {
221 $current_dir = opendir($a_dir);
222
223 $dirs = array();
224 $files = array();
225 while ($entry = readdir($current_dir)) {
226 if (is_dir($a_dir . "/" . $entry)) {
227 $dirs[$entry] = array("type" => "dir", "entry" => $entry);
228 } else {
229 $size = filesize($a_dir . "/" . $entry);
230 $files[$entry] = array("type" => "file", "entry" => $entry,
231 "size" => $size);
232 }
233 }
234 ksort($dirs);
235 ksort($files);
236
237 return array_merge($dirs, $files);
238 }
$size
Definition: RandomTest.php:84

References $files, and $size.

◆ getWebspaceDir()

ilUpdateUtils::getWebspaceDir (   $mode = "filesystem")

get webspace directory

Parameters
string$modeuse "filesystem" for filesystem operations and "output" for output operations, e.g. images

Definition at line 54 of file class.ilUpdateUtils.php.

55 {
56 global $ilias;
57
58 if ($mode == "filesystem") {
59 return "./" . ILIAS_WEB_DIR . "/" . $ilias->client_id;
60 } else {
61 if (defined("ILIAS_MODULE")) {
62 return "../" . ILIAS_WEB_DIR . "/" . $ilias->client_id;
63 } else {
64 return "./" . ILIAS_WEB_DIR . "/" . $ilias->client_id;
65 }
66 }
67
68 //return $ilias->ini->readVariable("server","webspace_dir");
69 }
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27

References defined.

Referenced by ilFileSystemStorage\init().

+ Here is the caller graph for this function:

◆ makeDir()

ilUpdateUtils::makeDir (   $a_dir)

creates a new directory and inherits all filesystem permissions of the parent directory You may pass only the name of your new directory or with the entire path or relative path information.

examples: a_dir = /tmp/test/your_dir a_dir = ../test/your_dir a_dir = your_dir (--> creates your_dir in current directory)

@access public

Parameters
string[path] + directory name
Returns
boolean

Definition at line 96 of file class.ilUpdateUtils.php.

97 {
98 $a_dir = trim($a_dir);
99
100 // remove trailing slash (bugfix for php 4.2.x)
101 if (substr($a_dir, -1) == "/") {
102 $a_dir = substr($a_dir, 0, -1);
103 }
104
105 // check if a_dir comes with a path
106 if (!($path = substr($a_dir, 0, strrpos($a_dir, "/") - strlen($a_dir)))) {
107 $path = ".";
108 }
109
110 // create directory with file permissions of parent directory
111 umask(0000);
112 return @mkdir($a_dir, fileperms($path));
113 }

References $path.

◆ makeDirParents()

ilUpdateUtils::makeDirParents (   $a_dir)

Create a new directory and all parent directories.

Creates a new directory and inherits all filesystem permissions of the parent directory If the parent directories doesn't exist, they will be created recursively. The directory name NEEDS TO BE an absolute path, because it seems that relative paths are not working with PHP's file_exists function.

Author
Helmut Schottmüller hscho.nosp@m.ttm@.nosp@m.tzi.d.nosp@m.e
Parameters
string$a_dirThe directory name to be created @access public

Definition at line 128 of file class.ilUpdateUtils.php.

129 {
130 $dirs = array($a_dir);
131 $a_dir = dirname($a_dir);
132 $last_dirname = '';
133 while ($last_dirname != $a_dir) {
134 array_unshift($dirs, $a_dir);
135 $last_dirname = $a_dir;
136 $a_dir = dirname($a_dir);
137 }
138
139 // find the first existing dir
140 $reverse_paths = array_reverse($dirs, true);
141 $found_index = -1;
142 foreach ($reverse_paths as $key => $value) {
143 if ($found_index == -1) {
144 if (is_dir($value)) {
145 $found_index = $key;
146 }
147 }
148 }
149
150 umask(0000);
151 foreach ($dirs as $dirindex => $dir) {
152 // starting with the longest existing path
153 if ($dirindex >= $found_index) {
154 if (!file_exists($dir)) {
155 if (strcmp(substr($dir, strlen($dir)-1, 1), "/") == 0) {
156 // on some systems there is an error when there is a slash
157 // at the end of a directory in mkdir, see Mantis #2554
158 $dir = substr($dir, 0, strlen($dir)-1);
159 }
160
161 if (!mkdir($dir, $umask)) {
162 error_log("Can't make directory: $dir");
163 return false;
164 }
165 } elseif (!is_dir($dir)) {
166 error_log("$dir is not a directory");
167 return false;
168 } else {
169 // get umask of the last existing parent directory
170 $umask = fileperms($dir);
171 }
172 }
173 }
174 return true;
175 }
$key
Definition: croninfo.php:18

References $key, and Monolog\Handler\error_log().

Referenced by ilFileSystemStorage\create().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeTrailingPathSeparators()

ilUpdateUtils::removeTrailingPathSeparators (   $path)

Definition at line 39 of file class.ilUpdateUtils.php.

40 {
41 $path = preg_replace("/[\/\\\]+$/", "", $path);
42 return $path;
43 }

References $path.

Referenced by ilFileSystemStorage\create(), ilFSStorageEvent\createDirectory(), and ilFileSystemStorage\init().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: