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