ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilFSStorageGroup.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 /******************************************************************************
5  *
6  * This file is part of ILIAS, a powerful learning management system.
7  *
8  * ILIAS is licensed with the GPL-3.0, you should have received a copy
9  * of said license along with the source code.
10  *
11  * If this is not the case or you just want to try ILIAS, you'll find
12  * us at:
13  * https://www.ilias.de
14  * https://github.com/ILIAS-eLearning
15  *
16  *****************************************************************************/
26 {
27  protected const MEMBER_EXPORT_DIR = 'memberExport';
28 
29  private ilLogger $logger;
30 
31  public function __construct(int $a_container_id = 0)
32  {
33  global $DIC;
34 
35  $this->logger = $DIC->logger()->grp();
37  }
38 
42  public function initMemberExportDirectory(): void
43  {
45  }
46 
50  public function getMemberExportDirectory(): string
51  {
52  return $this->getAbsolutePath() . '/' . self::MEMBER_EXPORT_DIR;
53  }
54 
55  public function addMemberExportFile(string $a_data, string $a_rel_name): bool
56  {
58  if (!$this->writeToFile($a_data, $this->getMemberExportDirectory() . '/' . $a_rel_name)) {
59  $this->logger->warning('Cannot write to file: ' . $this->getMemberExportDirectory() . '/' . $a_rel_name);
60  return false;
61  }
62  return true;
63  }
64 
68  public function getMemberExportFiles(): array
69  {
70  if (!is_dir($this->getMemberExportDirectory())) {
71  return [];
72  }
73 
74  $dp = opendir($this->getMemberExportDirectory());
75  $files = [];
76  while ($file = readdir($dp)) {
77  if (is_dir($file)) {
78  continue;
79  }
80 
81  if (
82  preg_match("/^([0-9]{10})_[a-zA-Z]*_export_([a-z]+)_([0-9]+)\.[a-z]+$/", $file, $matches) &&
83  $matches[3] == $this->getContainerId()) {
84  $timest = $matches[1];
85  $file_info['name'] = $matches[0];
86  $file_info['timest'] = $matches[1];
87  $file_info['type'] = $matches[2];
88  $file_info['id'] = $matches[3];
89  $file_info['size'] = filesize($this->getMemberExportDirectory() . '/' . $file);
90 
91  $files[$timest] = $file_info;
92  }
93  }
94  closedir($dp);
95  return $files;
96  }
97 
98  public function getMemberExportFile(string $a_name): string
99  {
100  $file_name = $this->getMemberExportDirectory() . '/' . $a_name;
101  if (file_exists($file_name)) {
102  return file_get_contents($file_name);
103  }
104  return '';
105  }
106 
107  public function deleteMemberExportFile(string $a_export_name): bool
108  {
109  return $this->deleteFile($this->getMemberExportDirectory() . '/' . $a_export_name);
110  }
111 
112  public function hasMemberExportFile(string $a_export_name): bool
113  {
114  return $this->fileExists($this->getMemberExportDirectory() . '/' . $a_export_name);
115  }
116 
120  protected function getPathPostfix(): string
121  {
122  return 'grp';
123  }
124 
128  protected function getPathPrefix(): string
129  {
130  return 'ilGroup';
131  }
132 }
deleteMemberExportFile(string $a_export_name)
getMemberExportDirectory()
Get path of export directory.
initMemberExportDirectory()
Init export directory and create it if it does not exist.
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
global $DIC
Definition: feed.php:28
addMemberExportFile(string $a_data, string $a_rel_name)
getMemberExportFile(string $a_name)
__construct(VocabulariesInterface $vocabularies)
__construct(int $a_container_id=0)
hasMemberExportFile(string $a_export_name)
getAbsolutePath()
Calculates the full path on the filesystem.