ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilFSStorageGroup.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
30 {
31  protected const MEMBER_EXPORT_DIR = 'memberExport';
32 
33  private ilLogger $logger;
34 
35  public function __construct(int $a_container_id = 0)
36  {
37  global $DIC;
38 
39  $this->logger = $DIC->logger()->grp();
41  }
42 
46  public function initMemberExportDirectory(): void
47  {
49  }
50 
54  public function getMemberExportDirectory(): string
55  {
56  return $this->getAbsolutePath() . '/' . self::MEMBER_EXPORT_DIR;
57  }
58 
59  public function addMemberExportFile(string $a_data, string $a_rel_name): bool
60  {
62  if (!$this->writeToFile($a_data, $this->getMemberExportDirectory() . '/' . $a_rel_name)) {
63  $this->logger->warning('Cannot write to file: ' . $this->getMemberExportDirectory() . '/' . $a_rel_name);
64  return false;
65  }
66  return true;
67  }
68 
72  public function getMemberExportFiles(): array
73  {
74  if (!is_dir($this->getMemberExportDirectory())) {
75  return [];
76  }
77 
78  $dp = opendir($this->getMemberExportDirectory());
79  $files = [];
80  while ($file = readdir($dp)) {
81  if (is_dir($file)) {
82  continue;
83  }
84 
85  if (
86  preg_match("/^([0-9]{10})_[a-zA-Z]*_export_([a-z]+)_([0-9]+)\.[a-z]+$/", $file, $matches) &&
87  $matches[3] == $this->getContainerId()) {
88  $timest = $matches[1];
89  $file_info['name'] = $matches[0];
90  $file_info['timest'] = $matches[1];
91  $file_info['type'] = $matches[2];
92  $file_info['id'] = $matches[3];
93  $file_info['size'] = filesize($this->getMemberExportDirectory() . '/' . $file);
94 
95  $files[$timest] = $file_info;
96  }
97  }
98  closedir($dp);
99  return $files;
100  }
101 
102  public function getMemberExportFile(string $a_name): string
103  {
104  $file_name = $this->getMemberExportDirectory() . '/' . $a_name;
105  if (file_exists($file_name)) {
106  return file_get_contents($file_name);
107  }
108  return '';
109  }
110 
111  public function deleteMemberExportFile(string $a_export_name): bool
112  {
113  return $this->deleteFile($this->getMemberExportDirectory() . '/' . $a_export_name);
114  }
115 
116  public function hasMemberExportFile(string $a_export_name): bool
117  {
118  return $this->fileExists($this->getMemberExportDirectory() . '/' . $a_export_name);
119  }
120 
124  protected function getPathPostfix(): string
125  {
126  return 'grp';
127  }
128 
132  protected function getPathPrefix(): string
133  {
134  return 'ilGroup';
135  }
136 }
deleteMemberExportFile(string $a_export_name)
getMemberExportDirectory()
Get path of export directory.
initMemberExportDirectory()
Init export directory and create it if it does not exist.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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(int $a_container_id=0)
hasMemberExportFile(string $a_export_name)
getAbsolutePath()
Calculates the full path on the filesystem.
__construct(Container $dic, ilPlugin $plugin)