ILIAS  release_8 Revision v8.24
ilFileSystemHelper Class Reference

File System Helper, to reduce deps. More...

+ Collaboration diagram for ilFileSystemHelper:

Public Member Functions

 __construct (ilLanguage $lng, ilSystemStyleMessageStack $message_stack)
 
 move (string $from, string $to)
 Used to move a complete directory of a skin. More...
 
 delete (string $file_path)
 
 saveDeleteFile (string $file_path)
 Deletes a given file in the container. More...
 
 recursiveRemoveDir (string $dir)
 Recursive delete of a folder. More...
 
 removeResourceDirectory (string $skin_dir, string $dir, bool $is_linked)
 Deletes a resource directory. More...
 
 createResourceDirectory (string $source, string $target)
 Creates a resource directory (sound, images or fonts) by copying from the source (mostly delos) More...
 
 changeResourceDirectory (string $skin_dir, string $new_dir, string $old_dir, bool $has_references)
 Alters the name/path of a resource directory. More...
 
 recursiveCopy (string $src, string $dest)
 Recursive copy of a folder. More...
 
 getMessageStack ()
 
 setMessageStack (ilSystemStyleMessageStack $message_stack)
 

Protected Attributes

ilSystemStyleMessageStack $message_stack
 Used to stack messages to be displayed to the user (mostly reports for failed actions) More...
 
ilLanguage $lng
 

Detailed Description

File System Helper, to reduce deps.

to ilUtil or wrap them properly. Should be replaced by src/Filesystem as soon as templates/default is accessible by src/Filesystem

Definition at line 25 of file class.ilFileSystemHelper.php.

Constructor & Destructor Documentation

◆ __construct()

ilFileSystemHelper::__construct ( ilLanguage  $lng,
ilSystemStyleMessageStack  $message_stack 
)

Definition at line 33 of file class.ilFileSystemHelper.php.

34 {
35 $this->setMessageStack($message_stack);
36 $this->lng = $lng;
37 }
setMessageStack(ilSystemStyleMessageStack $message_stack)

References $lng, ILIAS\Repository\lng(), and setMessageStack().

+ Here is the call graph for this function:

Member Function Documentation

◆ changeResourceDirectory()

ilFileSystemHelper::changeResourceDirectory ( string  $skin_dir,
string  $new_dir,
string  $old_dir,
bool  $has_references 
)

Alters the name/path of a resource directory.

Exceptions
ilSystemStyleException

Definition at line 138 of file class.ilFileSystemHelper.php.

138 : void
139 {
140 $absolut_new_dir = $skin_dir . $new_dir;
141 $absolut_old_dir = $skin_dir . $old_dir;
142
143 if (file_exists($absolut_new_dir)) {
144 $this->getMessageStack()->addMessage(
146 $this->lng->txt('dir_changed_to') . ' ' . $absolut_new_dir,
148 )
149 );
150 $this->getMessageStack()->addMessage(
152 $this->lng->txt('dir_preserved_backup') . ' ' . $absolut_old_dir,
154 )
155 );
156 } else {
157 mkdir($absolut_new_dir, 0775, true);
158 $this->recursiveCopy($absolut_old_dir, $absolut_new_dir);
159 $this->getMessageStack()->addMessage(
161 $this->lng->txt('dir_copied_from') . ' ' . $absolut_old_dir . ' ' . $this->lng->txt('sty_copy_to') . ' ' . $absolut_new_dir,
163 )
164 );
165 if (!$has_references) {
166 $this->recursiveRemoveDir($skin_dir . $old_dir);
167 $this->getMessageStack()->addMessage(
169 $this->lng->txt('dir_deleted') . ' ' . $absolut_old_dir,
171 )
172 );
173 } else {
174 $this->getMessageStack()->addMessage(
176 $this->lng->txt('dir_preserved_linked') . ' ' . $absolut_old_dir,
178 )
179 );
180 }
181 }
182 }
recursiveRemoveDir(string $dir)
Recursive delete of a folder.
recursiveCopy(string $src, string $dest)
Recursive copy of a folder.

References getMessageStack(), ILIAS\Repository\lng(), recursiveCopy(), recursiveRemoveDir(), and ilSystemStyleMessage\TYPE_SUCCESS.

+ Here is the call graph for this function:

◆ createResourceDirectory()

ilFileSystemHelper::createResourceDirectory ( string  $source,
string  $target 
)

Creates a resource directory (sound, images or fonts) by copying from the source (mostly delos)

Exceptions
ilSystemStyleException

Definition at line 119 of file class.ilFileSystemHelper.php.

119 : void
120 {
121 mkdir($target, 0775, true);
122
123 if ($source != '') {
124 $this->recursiveCopy($source, $target);
125 $this->getMessageStack()->addMessage(
127 $this->lng->txt('dir_created') . $target,
129 )
130 );
131 }
132 }
$source
Definition: metadata.php:93

References $source, getMessageStack(), ILIAS\Repository\lng(), recursiveCopy(), and ilSystemStyleMessage\TYPE_SUCCESS.

+ Here is the call graph for this function:

◆ delete()

ilFileSystemHelper::delete ( string  $file_path)

Definition at line 47 of file class.ilFileSystemHelper.php.

47 : void
48 {
49 unlink($file_path);
50 }

◆ getMessageStack()

ilFileSystemHelper::getMessageStack ( )

Definition at line 225 of file class.ilFileSystemHelper.php.

226 {
228 }
ilSystemStyleMessageStack $message_stack
Used to stack messages to be displayed to the user (mostly reports for failed actions)
Used to stack messages to be shown to the user.

References $message_stack.

Referenced by changeResourceDirectory(), createResourceDirectory(), removeResourceDirectory(), and saveDeleteFile().

+ Here is the caller graph for this function:

◆ move()

ilFileSystemHelper::move ( string  $from,
string  $to 
)

Used to move a complete directory of a skin.

Definition at line 42 of file class.ilFileSystemHelper.php.

42 : void
43 {
44 rename($from, $to);
45 }

◆ recursiveCopy()

ilFileSystemHelper::recursiveCopy ( string  $src,
string  $dest 
)

Recursive copy of a folder.

Exceptions
ilSystemStyleException

Definition at line 188 of file class.ilFileSystemHelper.php.

188 : void
189 {
190 foreach (scandir($src) as $file) {
191 $src_file = rtrim($src, '/') . '/' . $file;
192 $dest_file = rtrim($dest, '/') . '/' . $file;
193 if (!is_readable($src_file)) {
195 }
196 if (substr($file, 0, 1) != '.') {
197 if (is_dir($src_file)) {
198 if (!file_exists($dest_file)) {
199 try {
200 mkdir($dest_file);
201 } catch (Exception $e) {
202 throw new ilSystemStyleException(
204 'Copy ' . $src_file . ' to ' . $dest_file . ' Error: ' . $e
205 );
206 }
207 }
208 $this->recursiveCopy($src_file, $dest_file);
209 } else {
210 try {
211 copy($src_file, $dest_file);
212 } catch (Exception $e) {
213 throw new ilSystemStyleException(
215 'Copy ' . $src_file . ' to ' . $dest_file . ' Error: ' . $e
216 );
217 }
218 }
219 }
220 }
221 }
Class for advanced editing exception handling in ILIAS.

References Vendor\Package\$e, ilSystemStyleException\FILE_CREATION_FAILED, ilSystemStyleException\FILE_OPENING_FAILED, ilSystemStyleException\FOLDER_CREATION_FAILED, and recursiveCopy().

Referenced by changeResourceDirectory(), createResourceDirectory(), and recursiveCopy().

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

◆ recursiveRemoveDir()

ilFileSystemHelper::recursiveRemoveDir ( string  $dir)

Recursive delete of a folder.

Definition at line 71 of file class.ilFileSystemHelper.php.

71 : void
72 {
73 if (is_dir($dir)) {
74 $objects = scandir($dir);
75 foreach ($objects as $object) {
76 if ($object != '.' && $object != '..') {
77 if (is_dir($dir . '/' . $object)) {
78 $this->recursiveRemoveDir($dir . '/' . $object);
79 } else {
80 unlink($dir . '/' . $object);
81 }
82 }
83 }
84 rmdir($dir);
85 }
86 }

References recursiveRemoveDir().

Referenced by changeResourceDirectory(), recursiveRemoveDir(), and removeResourceDirectory().

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

◆ removeResourceDirectory()

ilFileSystemHelper::removeResourceDirectory ( string  $skin_dir,
string  $dir,
bool  $is_linked 
)

Deletes a resource directory.

Definition at line 91 of file class.ilFileSystemHelper.php.

92 {
93 $absolut_dir = $skin_dir . $dir;
94
95 if (file_exists($absolut_dir)) {
96 if (!$is_linked) {
97 self::recursiveRemoveDir($skin_dir . $dir);
98 $this->getMessageStack()->addMessage(
100 $this->lng->txt('dir_deleted') . ' ' . $dir,
102 )
103 );
104 } else {
105 $this->getMessageStack()->addMessage(
107 $this->lng->txt('dir_preserved_linked') . ' ' . $dir,
109 )
110 );
111 }
112 }
113 }

References getMessageStack(), ILIAS\Repository\lng(), recursiveRemoveDir(), and ilSystemStyleMessage\TYPE_SUCCESS.

+ Here is the call graph for this function:

◆ saveDeleteFile()

ilFileSystemHelper::saveDeleteFile ( string  $file_path)

Deletes a given file in the container.

Definition at line 55 of file class.ilFileSystemHelper.php.

55 : void
56 {
57 if (file_exists($file_path)) {
58 unlink($file_path);
59 $this->getMessageStack()->addMessage(
61 $this->lng->txt('file_deleted') . ' ' . $file_path,
63 )
64 );
65 }
66 }

References getMessageStack(), ILIAS\Repository\lng(), and ilSystemStyleMessage\TYPE_SUCCESS.

+ Here is the call graph for this function:

◆ setMessageStack()

ilFileSystemHelper::setMessageStack ( ilSystemStyleMessageStack  $message_stack)

Definition at line 230 of file class.ilFileSystemHelper.php.

230 : void
231 {
232 $this->message_stack = $message_stack;
233 }

References $message_stack.

Referenced by __construct().

+ Here is the caller graph for this function:

Field Documentation

◆ $lng

ilLanguage ilFileSystemHelper::$lng
protected

Definition at line 31 of file class.ilFileSystemHelper.php.

Referenced by __construct().

◆ $message_stack

ilSystemStyleMessageStack ilFileSystemHelper::$message_stack
protected

Used to stack messages to be displayed to the user (mostly reports for failed actions)

Definition at line 30 of file class.ilFileSystemHelper.php.

Referenced by getMessageStack(), and setMessageStack().


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