ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
class.ilFSStorageCourse.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=0);
4
26{
27 public const MEMBER_EXPORT_DIR = 'memberExport';
28 public const INFO_DIR = 'info';
29 public const ARCHIVE_DIR = 'archives';
30
32
33 public function __construct(int $a_container_id = 0)
34 {
35 global $DIC;
36
38 $this->logger = $DIC->logger()->crs();
40 }
41
42 public static function _clone(int $a_source_id, int $a_target_id): bool
43 {
44 $source = new ilFSStorageCourse($a_source_id);
45 $target = new ilFSStorageCourse($a_target_id);
46 $target->create();
47 ilFileSystemAbstractionStorage::_copyDirectory($source->getAbsolutePath(), $target->getAbsolutePath());
48
49 // Delete member export files
50 $target->deleteDirectory($target->getMemberExportDirectory());
51
52 unset($source);
53 unset($target);
54 return true;
55 }
56
57 public function initInfoDirectory(): void
58 {
60 }
61
62 public function getInfoDirectory(): string
63 {
64 return $this->getAbsolutePath() . '/' . self::INFO_DIR;
65 }
66
67 public function initMemberExportDirectory(): void
68 {
70 }
71
72 public function getMemberExportDirectory(): string
73 {
74 return $this->getAbsolutePath() . '/' . self::MEMBER_EXPORT_DIR;
75 }
76
77 public function addMemberExportFile($a_data, $a_rel_name): bool
78 {
80 if (!$this->writeToFile($a_data, $this->getMemberExportDirectory() . '/' . $a_rel_name)) {
81 $this->logger->write('Cannot write to file: ' . $this->getMemberExportDirectory() . '/' . $a_rel_name);
82 return false;
83 }
84
85 return true;
86 }
87
88 public function getMemberExportFiles(): array
89 {
90 if (!is_dir($this->getMemberExportDirectory())) {
91 return array();
92 }
93 $dp = opendir($this->getMemberExportDirectory());
94
95 $files = [];
96 while ($file = readdir($dp)) {
97 if (is_dir($file)) {
98 continue;
99 }
100
101 if (preg_match(
102 "/^([0-9]{10})_[a-zA-Z]*_export_([a-z]+)_([0-9]+)\.[a-z]+$/",
103 $file,
104 $matches
105 ) && $matches[3] == $this->getContainerId()) {
106 $timest = $matches[1];
107 $file_info['name'] = $matches[0];
108 $file_info['timest'] = $matches[1];
109 $file_info['type'] = $matches[2];
110 $file_info['id'] = $matches[3];
111 $file_info['size'] = filesize($this->getMemberExportDirectory() . '/' . $file);
112
113 $files[$timest] = $file_info;
114 }
115 }
116 closedir($dp);
117 return $files;
118 }
119
120 public function getMemberExportFile(string $a_name): string
121 {
122 $file_name = $this->getMemberExportDirectory() . '/' . $a_name;
123
124 if (file_exists($file_name)) {
125 return file_get_contents($file_name);
126 }
127 return '';
128 }
129
130 public function deleteMemberExportFile(string $a_export_name): bool
131 {
132 return $this->deleteFile($this->getMemberExportDirectory() . '/' . $a_export_name);
133 }
134
135 public function hasMemberExportFile(string $a_export_name): bool
136 {
137 return $this->fileExists($this->getMemberExportDirectory() . '/' . $a_export_name);
138 }
139
144 protected function getPathPostfix(): string
145 {
146 return 'crs';
147 }
148
153 protected function getPathPrefix(): string
154 {
155 return 'ilCourse';
156 }
157}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addMemberExportFile($a_data, $a_rel_name)
getPathPrefix()
Implementation of abstract method @access protected.
getPathPostfix()
Implementation of abstract method @access protected.
__construct(int $a_container_id=0)
deleteMemberExportFile(string $a_export_name)
static _clone(int $a_source_id, int $a_target_id)
hasMemberExportFile(string $a_export_name)
getMemberExportFile(string $a_name)
static _copyDirectory(string $a_sdir, string $a_tdir)
getAbsolutePath()
Calculates the full path on the filesystem.
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
Component logger with individual log levels by component id.
global $DIC
Definition: feed.php:28
$source
Definition: metadata.php:93
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc