ILIAS  trunk Revision v11.0_alpha-1744-gb0451eebef4
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator 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 (private int $storage_type, private bool $path_conversion, private int $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
 
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 28 of file class.ilRestFileStorage.php.

Constructor & Destructor Documentation

◆ __construct()

ilRestFileStorage::__construct ( )

Constructor.

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

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

40  {
41  global $DIC;
42 
43  $this->settings = $DIC->settings();
44  $this->logger = $DIC->logger()->wsrv();
47  false,
48  0
49  );
50  }
global $DIC
Definition: shib_login.php:22
__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 52 of file class.ilRestFileStorage.php.

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

Referenced by createFile(), and getFile().

52  : ?Response
53  {
54  if (!$this->settings->get('soap_user_administration', '0')) {
55  $this->logger->warning('Webservices disabled in administration.');
56 
57  return $response
58  ->withHeader('Content-Type', 'text/html')
59  ->withStatus(\Slim\Http\StatusCode::HTTP_FORBIDDEN)
60  ->write('Webservice not enabled.');
61  }
62  return null;
63  }
$response
Definition: xapitoken.php:93
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ 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 139 of file class.ilRestFileStorage.php.

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

139  : Response
140  {
141  $failure = $this->checkWebserviceActivation($request, $response);
142  if ($failure instanceof \Slim\Http\Response) {
143  return $failure;
144  }
145 
146  $request_body = $request->getParam('content');
147 
148  $tmpname = ilFileUtils::ilTempnam();
149  $path = $this->getPath() . '/' . basename($tmpname);
150 
151  $this->writeToFile($request_body, $path);
152  $return = basename($tmpname);
153 
154  return $response
155  ->withHeader('ContentType', 'application/json')
156  ->write($return);
157  }
writeToFile($a_data, $a_absolute_path)
checkWebserviceActivation(Request $request, Response $response)
$response
Definition: xapitoken.php:93
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:

◆ deleteDeprecated()

ilRestFileStorage::deleteDeprecated ( )

Delete deprecated files.

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

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

176  : void
177  {
178  $max_age = time() - self::AVAILABILITY_IN_DAYS * 24 * 60 * 60;
179  $ite = new DirectoryIterator($this->getPath());
180  foreach ($ite as $file) {
181  if ($file->getCTime() <= $max_age) {
182  try {
183  unlink($file->getPathname());
184  } catch (Exception $e) {
185  $this->logger->warning($e->getMessage());
186  }
187  }
188  }
189  }
+ Here is the call graph for this function:

◆ getFile()

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

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

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

85  : Response
86  {
87  $failure = $this->checkWebserviceActivation($request, $response);
88  if ($failure instanceof \Slim\Http\Response) {
89  return $failure;
90  }
91 
92  $file_id = $request->getParam('name');
93 
94  $this->logger->debug('Original file name: ' . $file_id);
95 
96  $real_path = realpath($this->getPath() . '/' . $file_id);
97  if (!$real_path) {
98  $this->logger->warning('No realpath found for ' . $this->getPath() . '/' . $file_id);
99  return $this->responeNotFound($response);
100  }
101  $file_name = basename($real_path);
102  $this->logger->debug('Translated name: ' . $this->getPath() . '/' . $file_name);
103  if (
104  $file_name &&
105  is_file($this->getPath() . '/' . $file_name) &&
106  file_exists($this->getPath() . '/' . $file_name)
107  ) {
108  $this->logger->info('Delivering file: ' . $this->getPath() . '/' . $file_name);
109  $return = file_get_contents($this->getPath() . '/' . $file_name);
110 
111  $this->logger->dump($return);
112 
113  return $response
114  ->withStatus(\Slim\Http\StatusCode::HTTP_OK)
115  ->withHeader('Content-Type', 'application/json')
116  ->write($return);
117  }
118  return $this->responeNotFound($response);
119  }
checkWebserviceActivation(Request $request, Response $response)
responeNotFound(Response $response)
Send 403.
$response
Definition: xapitoken.php:93
+ Here is the call graph for this function:

◆ getPathPostfix()

ilRestFileStorage::getPathPostfix ( )
protected

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

70  : string
71  {
72  return 'files';
73  }

◆ getPathPrefix()

ilRestFileStorage::getPathPrefix ( )
protected

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

65  : string
66  {
67  return 'ilRestFileStorage';
68  }

◆ getStoredFilePath()

ilRestFileStorage::getStoredFilePath ( string  $tmpname)

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

References ilFileSystemAbstractionStorage\getPath().

168  : string
169  {
170  return $this->getPath() . '/' . $tmpname;
171  }
+ Here is the call graph for this function:

◆ init()

ilRestFileStorage::init ( )
protected

init and create directory

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

References ilFileSystemAbstractionStorage\create(), and init().

78  : bool
79  {
80  parent::init();
81  $this->create();
82  return true;
83  }
+ 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 127 of file class.ilRestFileStorage.php.

Referenced by getFile().

127  : Response
128  {
129  return $response
130  ->withHeader('Content-Type', 'text/html')
131  ->withStatus(\Slim\Http\StatusCode::HTTP_NOT_FOUND)
132  ->write('File not found');
133  }
$response
Definition: xapitoken.php:93
+ Here is the caller graph for this function:

◆ storeFileForRest()

ilRestFileStorage::storeFileForRest ( string  $content)

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

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

159  : string
160  {
161  $tmpname = ilFileUtils::ilTempnam();
162  $path = $this->getPath() . '/' . basename($tmpname);
163 
164  $this->writeToFile($content, $path);
165  return basename($tmpname);
166  }
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 191 of file class.ilRestFileStorage.php.

Referenced by createFile(), and storeFileForRest().

191  : bool
192  {
193  if (!$fp = fopen($a_absolute_path, 'wb+')) {
194  return false;
195  }
196  if (fwrite($fp, $a_data) === false) {
197  fclose($fp);
198  return false;
199  }
200  fclose($fp);
201  return true;
202  }
+ Here is the caller graph for this function:

Field Documentation

◆ $logger

ilRestFileStorage::$logger
private

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

◆ $settings

ilSetting ilRestFileStorage::$settings
protected

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

◆ AVAILABILITY_IN_DAYS

const ilRestFileStorage::AVAILABILITY_IN_DAYS = 1
private

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


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