ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilRestFileStorage Class Reference

File storage handling. More...

+ Inheritance diagram for ilRestFileStorage:
+ Collaboration diagram for ilRestFileStorage:

Public Member Functions

 __construct ()
 Constructor. More...
 
 getFile (Request $request, Response $response)
 
 createFile (Request $request, Response $response)
 Create new file from post. More...
 
 storeFileForRest (string $content)
 
 getStoredFilePath (string $tmpname)
 
 deleteDeprecated ()
 Delete deprecated files. More...
 
 writeToFile ($a_data, $a_absolute_path)
 
- Public Member Functions inherited from ilFileSystemAbstractionStorage
 __construct (int $a_storage_type, bool $a_path_conversion, int $a_container_id)
 Constructor. More...
 
 fileExists (string $a_absolute_path)
 
 getContainerId ()
 
 writeToFile (string $a_data, $a_absolute_path)
 
 copyFile (string $a_from, string $a_to)
 
 create ()
 
 getAbsolutePath ()
 Calculates the full path on the filesystem. More...
 
 delete ()
 
 deleteDirectory (string $a_abs_name)
 
 deleteFile (string $a_abs_name)
 
 appendToPath (string $a_appendix)
 
 getStorageType ()
 
 getPath ()
 

Protected Member Functions

 checkWebserviceActivation (Request $request, Response $response)
 
 getPathPrefix ()
 
 getPathPostfix ()
 
 init ()
 init and create directory More...
 
 responeNotFound (Response $response)
 Send 403. More...
 
- Protected Member Functions inherited from ilFileSystemAbstractionStorage
 getLegacyFullAbsolutePath (string $relative_path)
 
 getFileSystemService ()
 
 getPathPrefix ()
 Get path prefix. More...
 
 getPathPostfix ()
 Get directory name. More...
 
 getLegacyAbsolutePath ()
 Calculates the absolute filesystem storage location. More...
 
 init ()
 

Protected Attributes

ilSetting $settings
 
- Protected Attributes inherited from ilFileSystemAbstractionStorage
string $path = null
 
ILIAS Filesystem Filesystems $file_system_service
 

Private Attributes

const AVAILABILITY_IN_DAYS = 1
 
 $logger
 

Additional Inherited Members

- Static Public Member Functions inherited from ilFileSystemAbstractionStorage
static createPathFromId (int $a_container_id, string $a_name)
 
static _copyDirectory (string $a_sdir, string $a_tdir)
 
- Data Fields inherited from ilFileSystemAbstractionStorage
const STORAGE_WEB = 1
 
const STORAGE_DATA = 2
 
const STORAGE_SECURED = 3
 

Detailed Description

File storage handling.

Author
Stefan Meyer smeye.nosp@m.r.il.nosp@m.ias@g.nosp@m.mx.d.nosp@m.e

Definition at line 14 of file class.ilRestFileStorage.php.

Constructor & Destructor Documentation

◆ __construct()

ilRestFileStorage::__construct ( )

Constructor.

Definition at line 25 of file class.ilRestFileStorage.php.

References $DIC, ILIAS\GlobalScreen\Provider\__construct(), ILIAS\Repository\logger(), ILIAS\Repository\settings(), and ilFileSystemAbstractionStorage\STORAGE_DATA.

26  {
27  global $DIC;
28 
29  $this->settings = $DIC->settings();
30  $this->logger = $DIC->logger()->wsrv();
33  false,
34  0
35  );
36  }
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
+ Here is the call graph for this function:

Member Function Documentation

◆ checkWebserviceActivation()

ilRestFileStorage::checkWebserviceActivation ( Request  $request,
Response  $response 
)
protected

Definition at line 38 of file class.ilRestFileStorage.php.

References ILIAS\Repository\logger(), and ILIAS\Repository\settings().

Referenced by createFile(), and getFile().

38  : ?Response
39  {
40  if (!$this->settings->get('soap_user_administration', '0')) {
41  $this->logger->warning('Webservices disabled in administration.');
42 
43  return $response
44  ->withHeader('Content-Type', 'text/html')
45  ->withStatus(\Slim\Http\StatusCode::HTTP_FORBIDDEN)
46  ->write('Webservice not enabled.');
47  }
48  return null;
49  }
$response
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createFile()

ilRestFileStorage::createFile ( Request  $request,
Response  $response 
)

Create new file from post.

Definition at line 125 of file class.ilRestFileStorage.php.

References ilFileSystemAbstractionStorage\$path, checkWebserviceActivation(), ilFileSystemAbstractionStorage\getPath(), ilFileUtils\ilTempnam(), and writeToFile().

125  : Response
126  {
127  $failure = $this->checkWebserviceActivation($request, $response);
128  if ($failure instanceof \Slim\Http\Response) {
129  return $failure;
130  }
131 
132  $request_body = $request->getParam('content');
133 
134  $tmpname = ilFileUtils::ilTempnam();
135  $path = $this->getPath() . '/' . basename($tmpname);
136 
137  $this->writeToFile($request_body, $path);
138  $return = basename($tmpname);
139 
140  return $response
141  ->withHeader('ContentType', 'application/json')
142  ->write($return);
143  }
writeToFile($a_data, $a_absolute_path)
checkWebserviceActivation(Request $request, Response $response)
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
$response
+ Here is the call graph for this function:

◆ deleteDeprecated()

ilRestFileStorage::deleteDeprecated ( )

Delete deprecated files.

Definition at line 162 of file class.ilRestFileStorage.php.

References Vendor\Package\$e, ilFileSystemAbstractionStorage\getPath(), and ILIAS\Repository\logger().

162  : void
163  {
164  $max_age = time() - self::AVAILABILITY_IN_DAYS * 24 * 60 * 60;
165  $ite = new DirectoryIterator($this->getPath());
166  foreach ($ite as $file) {
167  if ($file->getCTime() <= $max_age) {
168  try {
169  unlink($file->getPathname());
170  } catch (Exception $e) {
171  $this->logger->warning($e->getMessage());
172  }
173  }
174  }
175  }
+ Here is the call graph for this function:

◆ getFile()

ilRestFileStorage::getFile ( Request  $request,
Response  $response 
)

Definition at line 71 of file class.ilRestFileStorage.php.

References checkWebserviceActivation(), ilFileSystemAbstractionStorage\getPath(), ILIAS\Repository\logger(), and responeNotFound().

71  : Response
72  {
73  $failure = $this->checkWebserviceActivation($request, $response);
74  if ($failure instanceof \Slim\Http\Response) {
75  return $failure;
76  }
77 
78  $file_id = $request->getParam('name');
79 
80  $this->logger->debug('Original file name: ' . $file_id);
81 
82  $real_path = realpath($this->getPath() . '/' . $file_id);
83  if (!$real_path) {
84  $this->logger->warning('No realpath found for ' . $this->getPath() . '/' . $file_id);
85  return $this->responeNotFound($response);
86  }
87  $file_name = basename($real_path);
88  $this->logger->debug('Translated name: ' . $this->getPath() . '/' . $file_name);
89  if (
90  $file_name &&
91  is_file($this->getPath() . '/' . $file_name) &&
92  file_exists($this->getPath() . '/' . $file_name)
93  ) {
94  $this->logger->info('Delivering file: ' . $this->getPath() . '/' . $file_name);
95  $return = file_get_contents($this->getPath() . '/' . $file_name);
96 
97  $this->logger->dump($return);
98 
99  return $response
100  ->withStatus(\Slim\Http\StatusCode::HTTP_OK)
101  ->withHeader('Content-Type', 'application/json')
102  ->write($return);
103  }
104  return $this->responeNotFound($response);
105  }
checkWebserviceActivation(Request $request, Response $response)
responeNotFound(Response $response)
Send 403.
$response
+ Here is the call graph for this function:

◆ getPathPostfix()

ilRestFileStorage::getPathPostfix ( )
protected

Definition at line 56 of file class.ilRestFileStorage.php.

56  : string
57  {
58  return 'files';
59  }

◆ getPathPrefix()

ilRestFileStorage::getPathPrefix ( )
protected

Definition at line 51 of file class.ilRestFileStorage.php.

51  : string
52  {
53  return 'ilRestFileStorage';
54  }

◆ getStoredFilePath()

ilRestFileStorage::getStoredFilePath ( string  $tmpname)

Definition at line 154 of file class.ilRestFileStorage.php.

References ilFileSystemAbstractionStorage\getPath().

154  : string
155  {
156  return $this->getPath() . '/' . $tmpname;
157  }
+ Here is the call graph for this function:

◆ init()

ilRestFileStorage::init ( )
protected

init and create directory

Definition at line 64 of file class.ilRestFileStorage.php.

References ilFileSystemAbstractionStorage\create().

64  : bool
65  {
66  parent::init();
67  $this->create();
68  return true;
69  }
+ Here is the call graph for this function:

◆ responeNotFound()

ilRestFileStorage::responeNotFound ( Response  $response)
protected

Send 403.

Parameters
\Slim\Http\Response$response
Returns
$response

Definition at line 113 of file class.ilRestFileStorage.php.

Referenced by getFile().

113  : Response
114  {
115  return $response
116  ->withHeader('Content-Type', 'text/html')
117  ->withStatus(\Slim\Http\StatusCode::HTTP_NOT_FOUND)
118  ->write('File not found');
119  }
$response
+ Here is the caller graph for this function:

◆ storeFileForRest()

ilRestFileStorage::storeFileForRest ( string  $content)

Definition at line 145 of file class.ilRestFileStorage.php.

References ilFileSystemAbstractionStorage\$path, ilFileSystemAbstractionStorage\getPath(), ilFileUtils\ilTempnam(), and writeToFile().

145  : string
146  {
147  $tmpname = ilFileUtils::ilTempnam();
148  $path = $this->getPath() . '/' . basename($tmpname);
149 
150  $this->writeToFile($content, $path);
151  return basename($tmpname);
152  }
writeToFile($a_data, $a_absolute_path)
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
+ Here is the call graph for this function:

◆ writeToFile()

ilRestFileStorage::writeToFile (   $a_data,
  $a_absolute_path 
)

Definition at line 177 of file class.ilRestFileStorage.php.

Referenced by createFile(), and storeFileForRest().

177  : bool
178  {
179  if (!$fp = fopen($a_absolute_path, 'wb+')) {
180  return false;
181  }
182  if (fwrite($fp, $a_data) === false) {
183  fclose($fp);
184  return false;
185  }
186  fclose($fp);
187  return true;
188  }
+ Here is the caller graph for this function:

Field Documentation

◆ $logger

ilRestFileStorage::$logger
private

Definition at line 18 of file class.ilRestFileStorage.php.

◆ $settings

ilSetting ilRestFileStorage::$settings
protected

Definition at line 20 of file class.ilRestFileStorage.php.

◆ AVAILABILITY_IN_DAYS

const ilRestFileStorage::AVAILABILITY_IN_DAYS = 1
private

Definition at line 16 of file class.ilRestFileStorage.php.


The documentation for this class was generated from the following file: