ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilRestFileStorage Class Reference

File storage handling. More...

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

Public Member Functions

 __construct ()
 Constructor. More...
 
 getFile ($name)
 Get file by md5 hash. More...
 
 createFile ()
 Get file by md5 hash. 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 ()
 Check if soap administration is enabled. More...
 
 getPathPrefix ()
 Get path prefix. More...
 
 getPathPostfix ()
 Get path prefix. More...
 
 init ()
 init and create directory More...
 
 responeNotFound ()
 Send not found response. More...
 
- Protected Member Functions inherited from ilFileSystemStorage
 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...
 

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...
 
 _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 20 of file class.ilRestFileStorage.php.

References ilFileSystemStorage\STORAGE_DATA.

21  {
22  parent::__construct(
24  false,
25  0
26  );
27  }

Member Function Documentation

◆ checkWebserviceActivation()

ilRestFileStorage::checkWebserviceActivation ( )
protected

Check if soap administration is enabled.

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

References $GLOBALS, and Slim\getInstance().

Referenced by createFile(), and getFile().

33  {
34  $settings = $GLOBALS['ilSetting'];
35  if(!$settings->get('soap_user_administration',0))
36  {
37  Slim::getInstance()->response()->header('Content-Type','text/html');
38  Slim::getInstance()->response()->status(403);
39  Slim::getInstance()->response()->body('Webservices not enabled.');
40  return false;
41  }
42  return true;
43  }
static getInstance( $name='default')
Get Slim application with name.
Definition: Slim.php:254
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createFile()

ilRestFileStorage::createFile ( )

Get file by md5 hash.

Parameters
<type>$name

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

References $GLOBALS, ilFileSystemStorage\$path, checkWebserviceActivation(), Slim\getInstance(), ilFileSystemStorage\getPath(), ilUtil\ilTempnam(), and ilFileSystemStorage\writeToFile().

126  {
127  if(!$this->checkWebserviceActivation())
128  {
129  return false;
130  }
131 
132  $request = Slim::getInstance()->request();
133  $body = $request->post("content");
134 
135  $tmpname = ilUtil::ilTempnam();
136  $path = $this->getPath().'/'.basename($tmpname);
137 
138  $this->writeToFile($body, $path);
139  $return = basename($tmpname);
140 
141  $GLOBALS['ilLog']->write(__METHOD__.' Writing to path '.$path);
142 
143  Slim::getInstance()->response()->header('Content-Type', 'application/json');
144  Slim::getInstance()->response()->body($return);
145  }
static getInstance( $name='default')
Get Slim application with name.
Definition: Slim.php:254
writeToFile($a_data, $a_absolute_path)
Write data to file.
static ilTempnam($a_temp_path=null)
Create a temporary file in an ILIAS writable directory.
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
checkWebserviceActivation()
Check if soap administration is enabled.
+ Here is the call graph for this function:

◆ deleteDeprecated()

ilRestFileStorage::deleteDeprecated ( )

Delete deprecated files.

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

References $file, $GLOBALS, and ilFileSystemStorage\getPath().

165  {
166  $max_age = time() - self::AVAILABILITY_IN_DAYS * 24 * 60 * 60;
167  $ite = new DirectoryIterator($this->getPath());
168  foreach($ite as $file)
169  {
170  if($file->getCTime() <= $max_age)
171  {
172  try {
173  @unlink($file->getPathname());
174  }
175  catch(Exception $e) {
176  $GLOBALS['ilLog']->write(__METHOD__.' '. $e->getMessage());
177  }
178  }
179  }
180  }
print $file
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
+ Here is the call graph for this function:

◆ getFile()

ilRestFileStorage::getFile (   $name)

Get file by md5 hash.

Parameters
<type>$name

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

References $GLOBALS, checkWebserviceActivation(), Slim\getInstance(), ilFileSystemStorage\getPath(), and responeNotFound().

75  {
76  if(!$this->checkWebserviceActivation())
77  {
78  return false;
79  }
80 
81  $GLOBALS['ilLog']->write(__METHOD__.' original name: '.$this->getPath().'/'.$name);
82 
83  $real_path = realpath($this->getPath().'/'.$name);
84  if(!$real_path)
85  {
86  $GLOBALS['ilLog']->write(__METHOD__.' no realpath found for: '.$this->getPath().'/'.$name);
87  $this->responeNotFound();
88  return;
89  }
90  $file_name = basename($real_path);
91  $GLOBALS['ilLog']->write(__METHOD__.' translated name: '.$this->getPath().'/'.$file_name);
92  if(
93  $file_name &&
94  is_file($this->getPath().'/'.$file_name) &&
95  file_exists($this->getPath().'/'.$file_name)
96  )
97  {
98  $GLOBALS['ilLog']->write(__METHOD__.' delivering file: ' . $this->getPath().'/'.$file_name);
99  $return = file_get_contents($this->getPath().'/'.$file_name);
100  // Response header
101  Slim::getInstance()->response()->header('Content-Type', 'application/json');
102  Slim::getInstance()->response()->body($return);
103  return;
104  }
105 
106  $this->responeNotFound();
107  }
static getInstance( $name='default')
Get Slim application with name.
Definition: Slim.php:254
responeNotFound()
Send not found response.
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
checkWebserviceActivation()
Check if soap administration is enabled.
+ Here is the call graph for this function:

◆ getPathPostfix()

ilRestFileStorage::getPathPostfix ( )
protected

Get path prefix.

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

57  {
58  return 'files';
59  }

◆ getPathPrefix()

ilRestFileStorage::getPathPrefix ( )
protected

Get path prefix.

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

49  {
50  return 'ilRestFileStorage';
51  }

◆ getStoredFilePath()

ilRestFileStorage::getStoredFilePath (   $tmpname)

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

References ilFileSystemStorage\getPath().

157  {
158  return $this->getPath().'/'.$tmpname;
159  }
+ 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 ilFileSystemStorage\create().

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

◆ responeNotFound()

ilRestFileStorage::responeNotFound ( )
protected

Send not found response.

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

References $GLOBALS, and Slim\getInstance().

Referenced by getFile().

114  {
115  $GLOBALS['ilLog']->write(__METHOD__.' file not found.');
116  Slim::getInstance()->response()->header('Content-Type','text/html');
117  Slim::getInstance()->response()->status(404);
118  Slim::getInstance()->response()->body('Not found');
119  }
static getInstance( $name='default')
Get Slim application with name.
Definition: Slim.php:254
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ storeFileForRest()

ilRestFileStorage::storeFileForRest (   $content)

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

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

148  {
149  $tmpname = ilUtil::ilTempnam();
150  $path = $this->getPath().'/'.basename($tmpname);
151 
152  $this->writeToFile($content, $path);
153  return basename($tmpname);
154  }
writeToFile($a_data, $a_absolute_path)
Write data to file.
static ilTempnam($a_temp_path=null)
Create a temporary file in an ILIAS writable directory.
+ Here is the call graph for this function:

Field Documentation

◆ 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: