ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $log;
50
51 $this->log = $log;
52 parent::__construct(ilFileSystemStorage::STORAGE_DATA, true, $a_container_id);
53 }
54
64 public static function _clone($a_source_id, $a_target_id)
65 {
66 $source = new ilFSStorageCourse($a_source_id);
67 $target = new ilFSStorageCourse($a_target_id);
68
69 $target->create();
70 ilFileSystemStorage::_copyDirectory($source->getAbsolutePath(), $target->getAbsolutePath());
71
72 // Delete member export files
73 $target->deleteDirectory($target->getMemberExportDirectory());
74
75 unset($source);
76 unset($target);
77 return true;
78 }
79
80 // Info files
87 public function initInfoDirectory()
88 {
90 }
91
98 public function getInfoDirectory()
99 {
100 return $this->getAbsolutePath() . '/' . self::INFO_DIR;
101 }
102
103
111 {
113 }
114
121 public function getMemberExportDirectory()
122 {
123 return $this->getAbsolutePath() . '/' . self::MEMBER_EXPORT_DIR;
124 }
125
134 public function addMemberExportFile($a_data, $a_rel_name)
135 {
137 if (!$this->writeToFile($a_data, $this->getMemberExportDirectory() . '/' . $a_rel_name)) {
138 $this->log->write('Cannot write to file: ' . $this->getMemberExportDirectory() . '/' . $a_rel_name);
139 return false;
140 }
141
142 return true;
143 }
144
151 public function getMemberExportFiles()
152 {
153 if (!@is_dir($this->getMemberExportDirectory())) {
154 return array();
155 }
156
157 $files = array();
158 $dp = @opendir($this->getMemberExportDirectory());
159
160 while ($file = readdir($dp)) {
161 if (is_dir($file)) {
162 continue;
163 }
164
165 if (preg_match("/^([0-9]{10})_[a-zA-Z]*_export_([a-z]+)_([0-9]+)\.[a-z]+$/", $file, $matches) and $matches[3] == $this->getContainerId()) {
166 $timest = $matches[1];
167 $file_info['name'] = $matches[0];
168 $file_info['timest'] = $matches[1];
169 $file_info['type'] = $matches[2];
170 $file_info['id'] = $matches[3];
171 $file_info['size'] = filesize($this->getMemberExportDirectory() . '/' . $file);
172
173 $files[$timest] = $file_info;
174 }
175 }
176 closedir($dp);
177 return $files ? $files : array();
178 }
179
180 public function getMemberExportFile($a_name)
181 {
182 $file_name = $this->getMemberExportDirectory() . '/' . $a_name;
183
184 if (@file_exists($file_name)) {
185 return file_get_contents($file_name);
186 }
187 }
188
196 public function deleteMemberExportFile($a_export_name)
197 {
198 return $this->deleteFile($this->getMemberExportDirectory() . '/' . $a_export_name);
199 }
200
201 // ARCHIVE Methods
209 public function initArchiveDirectory()
210 {
212 }
213
220 public function getArchiveDirectory()
221 {
222 return $this->getAbsolutePath() . '/' . self::ARCHIVE_DIR;
223 }
224
232 public function addArchiveSubDirectory($a_name)
233 {
234 ilUtil::makeDirParents($this->getArchiveDirectory() . '/' . $a_name);
235 }
236
244 public function writeArchiveFile($a_data, $a_rel_name)
245 {
246 if (!$this->writeToFile($a_data, $this->getArchiveDirectory() . '/' . $a_rel_name)) {
247 $this->log->write('Cannot write to file: ' . $this->getArchiveDirectory() . '/' . $a_rel_name);
248 return false;
249 }
250 return true;
251 }
252
262 public function zipArchive($a_rel_name, $a_zip_name)
263 {
264 if (ilUtil::zip($this->getArchiveDirectory() . '/' . $a_rel_name, $this->getArchiveDirectory() . '/' . $a_zip_name)) {
265 return filesize($this->getArchiveDirectory() . '/' . $a_zip_name);
266 }
267 return 0;
268 }
269
277 public function deleteArchive($a_rel_name)
278 {
279 $this->deleteFile($this->getArchiveDirectory() . '/' . $a_rel_name . '.zip');
280 $this->deleteDirectory($this->getArchiveDirectory() . '/' . $a_rel_name);
281 }
282
283 public function createArchiveOnlineVersion($a_rel_name)
284 {
285 ilUtil::makeDirParents(CLIENT_WEB_DIR . '/courses/' . $a_rel_name);
286 ilUtil::rCopy($this->getArchiveDirectory() . '/' . $a_rel_name, CLIENT_WEB_DIR . '/courses/' . $a_rel_name);
287
288 return true;
289 }
290
291 public function getOnlineLink($a_rel_name)
292 {
293 return ilUtil::getWebspaceDir('filesystem') . '/courses/' . $a_rel_name . '/index.html';
294 }
295
296
303 protected function getPathPostfix()
304 {
305 return 'crs';
306 }
307
314 protected function getPathPrefix()
315 {
316 return 'ilCourse';
317 }
318}
$files
Definition: add-vimline.php:18
$source
Definition: linkback.php:22
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.
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file