ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilFSStorageCourse.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 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
24include_once('Services/FileSystem/classes/class.ilFileSystemStorage.php');
25
35{
36 const MEMBER_EXPORT_DIR = 'memberExport';
37 const INFO_DIR = 'info';
38 const ARCHIVE_DIR = 'archives';
39
40 private $log;
47 public function __construct($a_container_id = 0)
48 {
49 global $DIC;
50
51 $log = $DIC['log'];
52
53 $this->log = $log;
55 }
56
66 public static function _clone($a_source_id, $a_target_id)
67 {
68 $source = new ilFSStorageCourse($a_source_id);
69 $target = new ilFSStorageCourse($a_target_id);
70
71 $target->create();
72 ilFileSystemStorage::_copyDirectory($source->getAbsolutePath(), $target->getAbsolutePath());
73
74 // Delete member export files
75 $target->deleteDirectory($target->getMemberExportDirectory());
76
77 unset($source);
78 unset($target);
79 return true;
80 }
81
82 // Info files
89 public function initInfoDirectory()
90 {
92 }
93
100 public function getInfoDirectory()
101 {
102 return $this->getAbsolutePath() . '/' . self::INFO_DIR;
103 }
104
105
113 {
115 }
116
123 public function getMemberExportDirectory()
124 {
125 return $this->getAbsolutePath() . '/' . self::MEMBER_EXPORT_DIR;
126 }
127
136 public function addMemberExportFile($a_data, $a_rel_name)
137 {
139 if (!$this->writeToFile($a_data, $this->getMemberExportDirectory() . '/' . $a_rel_name)) {
140 $this->log->write('Cannot write to file: ' . $this->getMemberExportDirectory() . '/' . $a_rel_name);
141 return false;
142 }
143
144 return true;
145 }
146
153 public function getMemberExportFiles()
154 {
155 if (!@is_dir($this->getMemberExportDirectory())) {
156 return array();
157 }
158
159 $files = array();
160 $dp = @opendir($this->getMemberExportDirectory());
161
162 while ($file = readdir($dp)) {
163 if (is_dir($file)) {
164 continue;
165 }
166
167 if (preg_match("/^([0-9]{10})_[a-zA-Z]*_export_([a-z]+)_([0-9]+)\.[a-z]+$/", $file, $matches) and $matches[3] == $this->getContainerId()) {
168 $timest = $matches[1];
169 $file_info['name'] = $matches[0];
170 $file_info['timest'] = $matches[1];
171 $file_info['type'] = $matches[2];
172 $file_info['id'] = $matches[3];
173 $file_info['size'] = filesize($this->getMemberExportDirectory() . '/' . $file);
174
175 $files[$timest] = $file_info;
176 }
177 }
178 closedir($dp);
179 return $files ? $files : array();
180 }
181
182 public function getMemberExportFile($a_name)
183 {
184 $file_name = $this->getMemberExportDirectory() . '/' . $a_name;
185
186 if (@file_exists($file_name)) {
187 return file_get_contents($file_name);
188 }
189 }
190
198 public function deleteMemberExportFile($a_export_name)
199 {
200 return $this->deleteFile($this->getMemberExportDirectory() . '/' . $a_export_name);
201 }
202
203 // ARCHIVE Methods
211 public function initArchiveDirectory()
212 {
214 }
215
222 public function getArchiveDirectory()
223 {
224 return $this->getAbsolutePath() . '/' . self::ARCHIVE_DIR;
225 }
226
234 public function addArchiveSubDirectory($a_name)
235 {
236 ilUtil::makeDirParents($this->getArchiveDirectory() . '/' . $a_name);
237 }
238
246 public function writeArchiveFile($a_data, $a_rel_name)
247 {
248 if (!$this->writeToFile($a_data, $this->getArchiveDirectory() . '/' . $a_rel_name)) {
249 $this->log->write('Cannot write to file: ' . $this->getArchiveDirectory() . '/' . $a_rel_name);
250 return false;
251 }
252 return true;
253 }
254
264 public function zipArchive($a_rel_name, $a_zip_name)
265 {
266 if (ilUtil::zip($this->getArchiveDirectory() . '/' . $a_rel_name, $this->getArchiveDirectory() . '/' . $a_zip_name)) {
267 return filesize($this->getArchiveDirectory() . '/' . $a_zip_name);
268 }
269 return 0;
270 }
271
279 public function deleteArchive($a_rel_name)
280 {
281 $this->deleteFile($this->getArchiveDirectory() . '/' . $a_rel_name . '.zip');
282 $this->deleteDirectory($this->getArchiveDirectory() . '/' . $a_rel_name);
283 }
284
285 public function createArchiveOnlineVersion($a_rel_name)
286 {
287 ilUtil::makeDirParents(CLIENT_WEB_DIR . '/courses/' . $a_rel_name);
288 ilUtil::rCopy($this->getArchiveDirectory() . '/' . $a_rel_name, CLIENT_WEB_DIR . '/courses/' . $a_rel_name);
289
290 return true;
291 }
292
293 public function getOnlineLink($a_rel_name)
294 {
295 return ilUtil::getWebspaceDir('filesystem') . '/courses/' . $a_rel_name . '/index.html';
296 }
297
298
305 protected function getPathPostfix()
306 {
307 return 'crs';
308 }
309
316 protected function getPathPrefix()
317 {
318 return 'ilCourse';
319 }
320}
An exception for terminatinating execution or to throw for unit testing.
addArchiveSubDirectory($a_name)
Add subdirectory for archives.
createArchiveOnlineVersion($a_rel_name)
writeArchiveFile($a_data, $a_rel_name)
Write archive string to file.
addMemberExportFile($a_data, $a_rel_name)
Add new export file.
getPathPrefix()
Implementation of abstract method.
getMemberExportFiles()
Get all member export files.
getMemberExportDirectory()
Get path of export directory.
initMemberExportDirectory()
Init export directory and create it if it does not exist.
getPathPostfix()
Implementation of abstract method.
static _clone($a_source_id, $a_target_id)
Clone course data directory.
deleteArchive($a_rel_name)
Delete one archive.
__construct($a_container_id=0)
Constructor.
zipArchive($a_rel_name, $a_zip_name)
Zip archive directory.
deleteMemberExportFile($a_export_name)
Delete Member Export File.
initInfoDirectory()
init info directory
getInfoDirectory()
Get course info directory.
getArchiveDirectory()
Get archive directory.
initArchiveDirectory()
init Archive Directory
deleteFile($a_abs_name)
Delete file.
getAbsolutePath()
Get absolute path of storage directory.
static _copyDirectory($a_source, $a_target)
Copy directory and all contents.
deleteDirectory($a_abs_name)
Delete directory.
writeToFile($a_data, $a_absolute_path)
Write data to file.
static getWebspaceDir($mode="filesystem")
get webspace directory
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
static makeDirParents($a_dir)
Create a new directory and all parent directories.
$source
Definition: metadata.php:76
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$DIC
Definition: xapitoken.php:46