ILIAS  release_7 Revision v7.30-3-g800a261c036
ilRestFileStorage Class Reference

File storage handling. More...

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

Public Member Functions

 __construct ()
 Constructor. More...
 
 getFile (\Slim\Http\Request $request, \Slim\Http\Response $response)
 
 createFile (\Slim\Http\Request $request, \Slim\Http\Response $response)
 Create new file from post. More...
 
 storeFileForRest ($content)
 
 getStoredFilePath ($tmpname)
 
 deleteDeprecated ()
 Delete deprecated files. More...
 
- Public Member Functions inherited from ilFileSystemStorage
 __construct ($a_storage_type, $a_path_conversion, $a_container_id)
 Constructor. More...
 
 getContainerId ()
 
 create ()
 Create directory. More...
 
 getAbsolutePath ()
 Get absolute path of storage directory. More...
 
 writeToFile ($a_data, $a_absolute_path)
 Write data to file. More...
 
 deleteFile ($a_abs_name)
 Delete file. More...
 
 deleteDirectory ($a_abs_name)
 Delete directory. More...
 
 delete ()
 Delete complete directory. More...
 
 copyFile ($a_from, $a_to)
 Copy files. More...
 
 appendToPath ($a_appendix)
 
 getStorageType ()
 
 getPath ()
 Get path. More...
 
 __construct ($a_storage_type, $a_path_conversion, $a_container_id)
 Constructor. More...
 
 create ()
 Create directory. More...
 
 getAbsolutePath ()
 Get absolute path of storage directory. More...
 
 getShortPath ()
 
 rename ($from, $to)
 

Data Fields

const AVAILABILITY_IN_DAYS = 1
 
- Data Fields inherited from ilFileSystemStorage
const STORAGE_WEB = 1
 
const STORAGE_DATA = 2
 
const STORAGE_SECURED = 3
 
const FACTOR = 100
 
const MAX_EXPONENT = 3
 
const SECURED_DIRECTORY = "sec"
 

Protected Member Functions

 checkWebserviceActivation (\Slim\Http\Request $request, \Slim\Http\Response $response)
 
 getPathPrefix ()
 Get path prefix. More...
 
 getPathPostfix ()
 Get path prefix. More...
 
 init ()
 init and create directory More...
 
 responeNotFound (\Slim\Http\Response $response)
 Send 403. More...
 
 getPathPrefix ()
 Get path prefix. More...
 
 getPathPostfix ()
 Get directory name. More...
 
 init ()
 Read path info. More...
 
 getPathPrefix ()
 Get path prefix. More...
 
 getPathPostfix ()
 Get directory name. More...
 

Private Attributes

 $logger = null
 

Additional Inherited Members

- Static Public Member Functions inherited from ilFileSystemStorage
static _createPathFromId ($a_container_id, $a_name)
 Create a path from an id: e.g 12345 will be converted to 12/34/<name>_5. More...
 
static _copyDirectory ($a_source, $a_target)
 Copy directory and all contents. More...
 
static _createPathFromId ($a_container_id, $a_name)
 Create a path from an id: e.g 12345 will be converted to 12/34/<name>_5. More...
 
- Protected Attributes inherited from ilFileSystemStorage
 $path
 

Detailed Description

File storage handling.

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

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

Constructor & Destructor Documentation

◆ __construct()

ilRestFileStorage::__construct ( )

Constructor.

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

26 {
27 global $DIC;
28
29 $this->logger = $DIC->logger()->wsrv();
30 $this->logger->logStack();
31
34 false,
35 0
36 );
37 }
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References $DIC, ILIAS\GlobalScreen\Provider\__construct(), and ilFileSystemStorage\STORAGE_DATA.

+ Here is the call graph for this function:

Member Function Documentation

◆ checkWebserviceActivation()

ilRestFileStorage::checkWebserviceActivation ( \Slim\Http\Request  $request,
\Slim\Http\Response  $response 
)
protected
Parameters
\Slim\Http\Request$request
\Slim\Http\Response$response
Returns
\Slim\Http\Response | null $response

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

45 {
46 global $DIC;
47
48 $settings = $DIC->settings();
49 if (!$settings->get('soap_user_administration', 0)) {
50 $this->logger->warning('Webservices disabled in administration.');
51
53 ->withHeader('Content-Type', 'text/html')
54 ->withStatus(\Slim\Http\StatusCode::HTTP_FORBIDDEN)
55 ->write('Webservice not enabled.');
56 return $response;
57 }
58 return null;
59 }
$response

References $DIC, and $response.

Referenced by createFile(), and getFile().

+ Here is the caller graph for this function:

◆ createFile()

ilRestFileStorage::createFile ( \Slim\Http\Request  $request,
\Slim\Http\Response  $response 
)

Create new file from post.

Parameters
\Slim\Http\Request$request
\Slim\Http\Response$response

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

151 {
152 $failure = $this->checkWebserviceActivation($request, $response);
153 if ($failure instanceof \Slim\Http\Response) {
154 return $failure;
155 }
156
157 $request_body = $request->getParam('content');
158
159 $tmpname = ilUtil::ilTempnam();
160 $path = $this->getPath() . '/' . basename($tmpname);
161
162 $this->writeToFile($request_body, $path);
163 $return = basename($tmpname);
164
166 ->withHeader('ContentType', 'application/json')
167 ->write($return);
168
169 return $response;
170 }
$failure
writeToFile($a_data, $a_absolute_path)
Write data to file.
checkWebserviceActivation(\Slim\Http\Request $request, \Slim\Http\Response $response)
static ilTempnam($a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.

References $failure, ilFileSystemStorage\$path, $response, checkWebserviceActivation(), ilFileSystemStorage\getPath(), ilUtil\ilTempnam(), and ilFileSystemStorage\writeToFile().

+ Here is the call graph for this function:

◆ deleteDeprecated()

ilRestFileStorage::deleteDeprecated ( )

Delete deprecated files.

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

194 {
195 $max_age = time() - self::AVAILABILITY_IN_DAYS * 24 * 60 * 60;
196 $ite = new DirectoryIterator($this->getPath());
197 foreach ($ite as $file) {
198 if ($file->getCTime() <= $max_age) {
199 try {
200 @unlink($file->getPathname());
201 } catch (Exception $e) {
202 $this->logger->warning($e->getMessage());
203 }
204 }
205 }
206 }

References Vendor\Package\$e, and ilFileSystemStorage\getPath().

+ Here is the call graph for this function:

◆ getFile()

ilRestFileStorage::getFile ( \Slim\Http\Request  $request,
\Slim\Http\Response  $response 
)
Parameters
\Slim\Http\Request$request
\Slim\Http\Response$response

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

91 {
93 if ($failure instanceof \Slim\Http\Response) {
94 return $failure;
95 }
96
97
98 $file_id = $request->getParam('name');
99
100 $this->logger->debug('Original file name: ' . $file_id);
101
102 $real_path = realpath($this->getPath() . '/' . $file_id);
103 if (!$real_path) {
104 $this->logger->warning('No realpath found for ' . $this->getPath() . '/' . $file_id);
105 return $this->responeNotFound($response);
106 }
107 $file_name = basename($real_path);
108 $this->logger->debug('Translated name: ' . $this->getPath() . '/' . $file_name);
109 if (
110 $file_name &&
111 is_file($this->getPath() . '/' . $file_name) &&
112 file_exists($this->getPath() . '/' . $file_name)
113 ) {
114 $this->logger->info('Delivering file: ' . $this->getPath() . '/' . $file_name);
115 $return = file_get_contents($this->getPath() . '/' . $file_name);
116
117 $this->logger->dump($return);
118
120 ->withStatus(\Slim\Http\StatusCode::HTTP_OK)
121 ->withHeader('Content-Type', 'application/json')
122 ->write($return);
123 return $response;
124 }
126 }
responeNotFound(\Slim\Http\Response $response)
Send 403.

References $failure, $response, checkWebserviceActivation(), ilFileSystemStorage\getPath(), and responeNotFound().

+ Here is the call graph for this function:

◆ getPathPostfix()

ilRestFileStorage::getPathPostfix ( )
protected

Get path prefix.

Reimplemented from ilFileSystemStorage.

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

73 {
74 return 'files';
75 }

◆ getPathPrefix()

ilRestFileStorage::getPathPrefix ( )
protected

Get path prefix.

Reimplemented from ilFileSystemStorage.

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

65 {
66 return 'ilRestFileStorage';
67 }

◆ getStoredFilePath()

ilRestFileStorage::getStoredFilePath (   $tmpname)
Parameters
$tmpname
Returns
string

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

186 {
187 return $this->getPath() . '/' . $tmpname;
188 }

References ilFileSystemStorage\getPath().

+ Here is the call graph for this function:

◆ init()

ilRestFileStorage::init ( )
protected

init and create directory

Reimplemented from ilFileSystemStorage.

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

81 {
82 parent::init();
83 $this->create();
84 }

References ilFileSystemStorage\create().

+ Here is the call graph for this function:

◆ responeNotFound()

ilRestFileStorage::responeNotFound ( \Slim\Http\Response  $response)
protected

Send 403.

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

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

135 {
136 return $response
137 ->withHeader('Content-Type', 'text/html')
138 ->withStatus(\Slim\Http\StatusCode::HTTP_NOT_FOUND)
139 ->write('File not found');
140 }

References $response.

Referenced by getFile().

+ Here is the caller graph for this function:

◆ storeFileForRest()

ilRestFileStorage::storeFileForRest (   $content)

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

173 {
174 $tmpname = ilUtil::ilTempnam();
175 $path = $this->getPath() . '/' . basename($tmpname);
176
177 $this->writeToFile($content, $path);
178 return basename($tmpname);
179 }

References ilFileSystemStorage\$path, ilFileSystemStorage\getPath(), ilUtil\ilTempnam(), and ilFileSystemStorage\writeToFile().

+ Here is the call graph for this function:

Field Documentation

◆ $logger

ilRestFileStorage::$logger = null
private

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

◆ AVAILABILITY_IN_DAYS

const ilRestFileStorage::AVAILABILITY_IN_DAYS = 1

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


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