ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilFileSystemStorage Class Reference
+ Inheritance diagram for ilFileSystemStorage:
+ Collaboration diagram for ilFileSystemStorage:

Public Member Functions

 __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)
 

Static Public Member Functions

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...
 

Data Fields

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

 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...
 

Protected Attributes

 $path
 

Private Member Functions

 init ()
 Read path info. More...
 

Private Attributes

 $container_id
 
 $storage_type
 
 $path_conversion = false
 
 $short_path
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct() [1/2]

ilFileSystemStorage::__construct (   $a_storage_type,
  $a_path_conversion,
  $a_container_id 
)

Constructor.

public

Parameters
intstorage type
boolEn/Disable automatic path conversion. If enabled files with id 123 will be stored in directory files/1/file_123
intobject id of container (e.g file_id or mob_id)

Definition at line 59 of file class.ilFileSystemStorage.php.

References init().

60  {
61  $this->storage_type = $a_storage_type;
62  $this->path_conversion = $a_path_conversion;
63  $this->container_id = $a_container_id;
64 
65  // Get path info
66  $this->init();
67  }
+ Here is the call graph for this function:

◆ __construct() [2/2]

ilFileSystemStorage::__construct (   $a_storage_type,
  $a_path_conversion,
  $a_container_id 
)

Constructor.

public

Parameters
intstorage type
boolEn/Disable automatic path conversion. If enabled files with id 123 will be stored in directory files/1/file_123
intobject id of container (e.g file_id or mob_id)

Definition at line 50 of file class.ilFileSystemStorage.php.

References init().

51  {
52  $this->storage_type = $a_storage_type;
53  $this->path_conversion = $a_path_conversion;
54  $this->container_id = $a_container_id;
55 
56  // Get path info
57  $this->init();
58  }
+ Here is the call graph for this function:

Member Function Documentation

◆ _copyDirectory()

static ilFileSystemStorage::_copyDirectory (   $a_source,
  $a_target 
)
static

Copy directory and all contents.

Parameters
string$a_sourceabsolute source path
string$a_targetabsolute target path

Definition at line 290 of file class.ilFileSystemStorage.php.

References ilUtil\rCopy().

Referenced by ilFSStorageCourse\_clone(), and ilObjPortfolioBase\cloneBasics().

291  {
292  return ilUtil::rCopy($a_source,$a_target);
293  }
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _createPathFromId() [1/2]

static ilFileSystemStorage::_createPathFromId (   $a_container_id,
  $a_name 
)
static

Create a path from an id: e.g 12345 will be converted to 12/34/<name>_5.

public

Parameters
intcontainer id
stringname

Definition at line 69 of file class.ilFileSystemStorage.php.

References $path, array, getPathPostfix(), and getPathPrefix().

70  {
71  $path = array();
72  $found = false;
73  $num = $a_container_id;
74  for($i = self::MAX_EXPONENT; $i > 0;$i--)
75  {
76  $factor = pow(self::FACTOR,$i);
77  if(($tmp = (int) ($num / $factor)) or $found)
78  {
79  $path[] = $tmp;
80  $num = $num % $factor;
81  $found = true;
82  }
83  }
84 
85  if(count($path))
86  {
87  $path_string = (implode('/',$path));
88  }
89  return $path_string;
90  }
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ _createPathFromId() [2/2]

static ilFileSystemStorage::_createPathFromId (   $a_container_id,
  $a_name 
)
static

Create a path from an id: e.g 12345 will be converted to 12/34/<name>_5.

public

Parameters
intcontainer id
stringname

Definition at line 83 of file class.ilFileSystemStorage.php.

References $path, array, getPathPostfix(), and getPathPrefix().

Referenced by ilExport\_getExportDirectory().

84  {
85  $path = array();
86  $found = false;
87  $num = $a_container_id;
88  for($i = self::MAX_EXPONENT; $i > 0;$i--)
89  {
90  $factor = pow(self::FACTOR,$i);
91  if(($tmp = (int) ($num / $factor)) or $found)
92  {
93  $path[] = $tmp;
94  $num = $num % $factor;
95  $found = true;
96  }
97  }
98 
99  if(count($path))
100  {
101  $path_string = (implode('/',$path).'/');
102  }
103  return $path_string.$a_name.'_'.$a_container_id;
104  }
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ appendToPath()

ilFileSystemStorage::appendToPath (   $a_appendix)

Definition at line 295 of file class.ilFileSystemStorage.php.

Referenced by ilFSStorageMail\__construct().

296  {
297  $this->path .= $a_appendix;
298  }
+ Here is the caller graph for this function:

◆ copyFile()

ilFileSystemStorage::copyFile (   $a_from,
  $a_to 
)

Copy files.

public

Parameters
stringabsolute source
stringabsolute target

Definition at line 274 of file class.ilFileSystemStorage.php.

275  {
276  if(@file_exists($a_from))
277  {
278  @copy($a_from,$a_to);
279  return true;
280  }
281  return false;
282  }

◆ create() [1/2]

ilFileSystemStorage::create ( )

Create directory.

public

Definition at line 121 of file class.ilFileSystemStorage.php.

References ilUpdateUtils\makeDirParents(), and ilUpdateUtils\removeTrailingPathSeparators().

122  {
123  if(!file_exists($this->short_path))
124  {
126  }
127  return true;
128  }
makeDirParents($a_dir)
Create a new directory and all parent directories.
removeTrailingPathSeparators($path)
+ Here is the call graph for this function:

◆ create() [2/2]

ilFileSystemStorage::create ( )

Create directory.

public

Definition at line 135 of file class.ilFileSystemStorage.php.

References ilUtil\makeDirParents().

Referenced by ilRestFileStorage\init().

136  {
137  if(!file_exists($this->path))
138  {
139  ilUtil::makeDirParents($this->path);
140  }
141  return true;
142  }
static makeDirParents($a_dir)
Create a new directory and all parent directories.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ delete()

ilFileSystemStorage::delete ( )

Delete complete directory.

public

Parameters

Definition at line 260 of file class.ilFileSystemStorage.php.

References ilUtil\delDir(), and getAbsolutePath().

261  {
262  return ilUtil::delDir($this->getAbsolutePath());
263  }
getAbsolutePath()
Get absolute path of storage directory.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
+ Here is the call graph for this function:

◆ deleteDirectory()

ilFileSystemStorage::deleteDirectory (   $a_abs_name)

Delete directory.

public

Parameters
stringabsolute name

Definition at line 242 of file class.ilFileSystemStorage.php.

References ilUtil\delDir().

Referenced by ilFSStorageCourse\deleteArchive(), and ilExcCriteriaFile\resetReview().

243  {
244  if(@file_exists($a_abs_name))
245  {
246  ilUtil::delDir($a_abs_name);
247  return true;
248  }
249  return false;
250  }
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deleteFile()

ilFileSystemStorage::deleteFile (   $a_abs_name)

Delete file.

public

Parameters
stringabsolute name

Definition at line 225 of file class.ilFileSystemStorage.php.

Referenced by ilFSStorageCourse\deleteArchive(), ilFSStorageGroup\deleteMemberExportFile(), and ilFSStorageCourse\deleteMemberExportFile().

226  {
227  if(@file_exists($a_abs_name))
228  {
229  @unlink($a_abs_name);
230  return true;
231  }
232  return false;
233  }
+ Here is the caller graph for this function:

◆ getAbsolutePath() [1/2]

ilFileSystemStorage::getAbsolutePath ( )

Get absolute path of storage directory.

public

Definition at line 137 of file class.ilFileSystemStorage.php.

References $path.

138  {
139  return $this->path;
140  }

◆ getAbsolutePath() [2/2]

◆ getContainerId()

ilFileSystemStorage::getContainerId ( )

Definition at line 69 of file class.ilFileSystemStorage.php.

References $container_id.

Referenced by ilFSStorageGroup\getMemberExportFiles(), and ilFSStorageCourse\getMemberExportFiles().

+ Here is the caller graph for this function:

◆ getPath()

◆ getPathPostfix() [1/2]

ilFileSystemStorage::getPathPostfix ( )
abstractprotected

Get directory name.

E.g for files => file Only relative path, no trailing slash '_<obj_id>' will be appended automatically

protected

Returns
string directory name

◆ getPathPostfix() [2/2]

ilFileSystemStorage::getPathPostfix ( )
abstractprotected

Get directory name.

E.g for files => file Only relative path, no trailing slash '_<obj_id>' will be appended automatically

protected

Returns
string directory name

Referenced by _createPathFromId(), and init().

+ Here is the caller graph for this function:

◆ getPathPrefix() [1/2]

ilFileSystemStorage::getPathPrefix ( )
abstractprotected

Get path prefix.

Prefix that will be prepended to the path No trailing slash. E.g ilFiles for files

protected

Returns
string path prefix e.g files

◆ getPathPrefix() [2/2]

ilFileSystemStorage::getPathPrefix ( )
abstractprotected

Get path prefix.

Prefix that will be prepended to the path No trailing slash. E.g ilFiles for files

protected

Returns
string path prefix e.g files

Referenced by _createPathFromId(), and init().

+ Here is the caller graph for this function:

◆ getShortPath()

ilFileSystemStorage::getShortPath ( )

Definition at line 142 of file class.ilFileSystemStorage.php.

References $short_path.

143  {
144  return $this->short_path;
145  }

◆ getStorageType()

ilFileSystemStorage::getStorageType ( )

Definition at line 300 of file class.ilFileSystemStorage.php.

References $storage_type.

Referenced by ilFSStorageMail\getRelativePathExMailDirectory().

301  {
302  return $this->storage_type;
303  }
+ Here is the caller graph for this function:

◆ init() [1/2]

ilFileSystemStorage::init ( )
private

Read path info.

private

Definition at line 157 of file class.ilFileSystemStorage.php.

References $container_id, $path, ilUpdateUtils\getDataDir(), getPathPostfix(), getPathPrefix(), ilUpdateUtils\getWebspaceDir(), and ilUpdateUtils\removeTrailingPathSeparators().

158  {
159  switch($this->storage_type)
160  {
161  case self::STORAGE_DATA:
162  $this->path = ilUpdateUtils::getDataDir();
163  break;
164 
165  case self::STORAGE_WEB:
166  $this->path = ilUpdateUtils::getWebspaceDir();
167  break;
168  }
169  $this->path = ilUpdateUtils::removeTrailingPathSeparators($this->path);
170  $this->path .= '/';
171 
172  // Append path prefix
173  $this->path .= ($this->getPathPrefix().'/');
174 
175  if($this->path_conversion)
176  {
177  if($path_id = self::_createPathFromId($this->container_id,$this->getPathPostfix()))
178  {
179  $this->path = $this->path.'/'.$path_id;
180  $this->path .= '/';
181  $this->short_path = $this->path;
182  }
183  else
184  {
185  $this->short_path = $this->path;
186  }
187  $this->path .= ($this->getPathPostfix().'_'.$this->container_id);
188  }
189  else
190  {
191  $this->short_path = $this->path;
192  $this->path .= ($this->getPathPostfix().'_'.$this->container_id);
193  }
194  return true;
195  }
getWebspaceDir($mode="filesystem")
get webspace directory
removeTrailingPathSeparators($path)
getPathPrefix()
Get path prefix.
getDataDir()
get data directory (outside webspace)
getPathPostfix()
Get directory name.
+ Here is the call graph for this function:

◆ init() [2/2]

ilFileSystemStorage::init ( )
protected

Read path info.

private

Definition at line 161 of file class.ilFileSystemStorage.php.

References $container_id, ilUtil\getDataDir(), getPathPostfix(), getPathPrefix(), ilUtil\getWebspaceDir(), and ilUtil\removeTrailingPathSeparators().

Referenced by __construct().

162  {
163  switch($this->storage_type)
164  {
165  case self::STORAGE_DATA:
166  $this->path = ilUtil::getDataDir();
167  break;
168 
169  case self::STORAGE_WEB:
170  $this->path = ilUtil::getWebspaceDir();
171  break;
172 
173  case self::STORAGE_SECURED:
174  $this->path = ilUtil::getWebspaceDir();
175  $this->path = ilUtil::removeTrailingPathSeparators($this->path);
176  $this->path .= '/'.self::SECURED_DIRECTORY;
177  break;
178  }
179  $this->path = ilUtil::removeTrailingPathSeparators($this->path);
180  $this->path .= '/';
181 
182  // Append path prefix
183  $this->path .= ($this->getPathPrefix().'/');
184 
185  if($this->path_conversion)
186  {
187  $this->path .= self::_createPathFromId($this->container_id,$this->getPathPostfix());
188  }
189  else
190  {
191  $this->path .= ($this->getPathPostfix().'_'.$this->container_id);
192  }
193  return true;
194  }
getPathPrefix()
Get path prefix.
static removeTrailingPathSeparators($path)
static getDataDir()
get data directory (outside webspace)
getPathPostfix()
Get directory name.
static getWebspaceDir($mode="filesystem")
get webspace directory
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rename()

ilFileSystemStorage::rename (   $from,
  $to 
)

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

Referenced by ilFSStorageExercise\uploadFile().

148  {
149  return @rename($from,$to);
150  }
+ Here is the caller graph for this function:

◆ writeToFile()

ilFileSystemStorage::writeToFile (   $a_data,
  $a_absolute_path 
)

Write data to file.

public

Parameters

Definition at line 203 of file class.ilFileSystemStorage.php.

Referenced by ilFSStorageGroup\addMemberExportFile(), ilFSStorageCourse\addMemberExportFile(), ilRestFileStorage\createFile(), ilRestFileStorage\storeFileForRest(), and ilFSStorageCourse\writeArchiveFile().

204  {
205  if(!$fp = @fopen($a_absolute_path,'w+'))
206  {
207  return false;
208  }
209  if(@fwrite($fp,$a_data) === false)
210  {
211  @fclose($fp);
212  return false;
213  }
214  @fclose($fp);
215  return true;
216  }
+ Here is the caller graph for this function:

Field Documentation

◆ $container_id

ilFileSystemStorage::$container_id
private

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

Referenced by getContainerId(), and init().

◆ $path

◆ $path_conversion

ilFileSystemStorage::$path_conversion = false
private

Definition at line 46 of file class.ilFileSystemStorage.php.

◆ $short_path

ilFileSystemStorage::$short_path
private

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

Referenced by getShortPath().

◆ $storage_type

ilFileSystemStorage::$storage_type
private

Definition at line 45 of file class.ilFileSystemStorage.php.

Referenced by getStorageType().

◆ FACTOR

const ilFileSystemStorage::FACTOR = 100

Definition at line 40 of file class.ilFileSystemStorage.php.

◆ MAX_EXPONENT

const ilFileSystemStorage::MAX_EXPONENT = 3

Definition at line 41 of file class.ilFileSystemStorage.php.

◆ SECURED_DIRECTORY

const ilFileSystemStorage::SECURED_DIRECTORY = "sec"

Definition at line 42 of file class.ilFileSystemStorage.php.

◆ STORAGE_DATA

◆ STORAGE_SECURED

const ilFileSystemStorage::STORAGE_SECURED = 3

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

◆ STORAGE_WEB

const ilFileSystemStorage::STORAGE_WEB = 1

Definition at line 36 of file class.ilFileSystemStorage.php.


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