ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 277 of file class.ilFileSystemStorage.php.

References ilUtil\rCopy().

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

278  {
279  return ilUtil::rCopy($a_source, $a_target);
280  }
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 $i, $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  $factor = pow(self::FACTOR, $i);
76  if (($tmp = (int) ($num / $factor)) or $found) {
77  $path[] = $tmp;
78  $num = $num % $factor;
79  $found = true;
80  }
81  }
82 
83  if (count($path)) {
84  $path_string = (implode('/', $path));
85  }
86  return $path_string;
87  }
Create styles array
The data for the language used.
$i
Definition: disco.tpl.php:19
+ 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 $i, $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  $factor = pow(self::FACTOR, $i);
90  if (($tmp = (int) ($num / $factor)) or $found) {
91  $path[] = $tmp;
92  $num = $num % $factor;
93  $found = true;
94  }
95  }
96 
97  if (count($path)) {
98  $path_string = (implode('/', $path) . '/');
99  }
100  return $path_string . $a_name . '_' . $a_container_id;
101  }
Create styles array
The data for the language used.
$i
Definition: disco.tpl.php:19
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ appendToPath()

ilFileSystemStorage::appendToPath (   $a_appendix)

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

Referenced by ilFSStorageMail\__construct().

283  {
284  $this->path .= $a_appendix;
285  }
+ 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 262 of file class.ilFileSystemStorage.php.

263  {
264  if (@file_exists($a_from)) {
265  @copy($a_from, $a_to);
266  return true;
267  }
268  return false;
269  }

◆ create() [1/2]

ilFileSystemStorage::create ( )

Create directory.

public

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

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

119  {
120  if (!file_exists($this->short_path)) {
122  }
123  return true;
124  }
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 132 of file class.ilFileSystemStorage.php.

References ilUtil\makeDirParents().

Referenced by ilRestFileStorage\init().

133  {
134  if (!file_exists($this->path)) {
135  ilUtil::makeDirParents($this->path);
136  }
137  return true;
138  }
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 248 of file class.ilFileSystemStorage.php.

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

249  {
250  return ilUtil::delDir($this->getAbsolutePath());
251  }
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 231 of file class.ilFileSystemStorage.php.

References ilUtil\delDir().

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

232  {
233  if (@file_exists($a_abs_name)) {
234  ilUtil::delDir($a_abs_name);
235  return true;
236  }
237  return false;
238  }
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 215 of file class.ilFileSystemStorage.php.

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

216  {
217  if (@file_exists($a_abs_name)) {
218  @unlink($a_abs_name);
219  return true;
220  }
221  return false;
222  }
+ Here is the caller graph for this function:

◆ getAbsolutePath() [1/2]

ilFileSystemStorage::getAbsolutePath ( )

Get absolute path of storage directory.

public

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

References $path.

134  {
135  return $this->path;
136  }

◆ 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 138 of file class.ilFileSystemStorage.php.

References $short_path.

139  {
140  return $this->short_path;
141  }

◆ getStorageType()

ilFileSystemStorage::getStorageType ( )

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

References $storage_type.

Referenced by ilFSStorageMail\getRelativePathExMailDirectory().

288  {
289  return $this->storage_type;
290  }
+ Here is the caller graph for this function:

◆ init() [1/2]

ilFileSystemStorage::init ( )
private

Read path info.

private

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

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

154  {
155  switch ($this->storage_type) {
156  case self::STORAGE_DATA:
157  $this->path = ilUpdateUtils::getDataDir();
158  break;
159 
160  case self::STORAGE_WEB:
161  $this->path = ilUpdateUtils::getWebspaceDir();
162  break;
163  }
164  $this->path = ilUpdateUtils::removeTrailingPathSeparators($this->path);
165  $this->path .= '/';
166 
167  // Append path prefix
168  $this->path .= ($this->getPathPrefix() . '/');
169 
170  if ($this->path_conversion) {
171  if ($path_id = self::_createPathFromId($this->container_id, $this->getPathPostfix())) {
172  $this->path = $this->path . '/' . $path_id;
173  $this->path .= '/';
174  $this->short_path = $this->path;
175  } else {
176  $this->short_path = $this->path;
177  }
178  $this->path .= ($this->getPathPostfix() . '_' . $this->container_id);
179  } else {
180  $this->short_path = $this->path;
181  $this->path .= ($this->getPathPostfix() . '_' . $this->container_id);
182  }
183  return true;
184  }
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 157 of file class.ilFileSystemStorage.php.

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

Referenced by __construct().

158  {
159  switch ($this->storage_type) {
160  case self::STORAGE_DATA:
161  $this->path = ilUtil::getDataDir();
162  break;
163 
164  case self::STORAGE_WEB:
165  $this->path = ilUtil::getWebspaceDir();
166  break;
167 
168  case self::STORAGE_SECURED:
169  $this->path = ilUtil::getWebspaceDir();
170  $this->path = ilUtil::removeTrailingPathSeparators($this->path);
171  $this->path .= '/' . self::SECURED_DIRECTORY;
172  break;
173  }
174  $this->path = ilUtil::removeTrailingPathSeparators($this->path);
175  $this->path .= '/';
176 
177  // Append path prefix
178  $this->path .= ($this->getPathPrefix() . '/');
179 
180  if ($this->path_conversion) {
181  $this->path .= self::_createPathFromId($this->container_id, $this->getPathPostfix());
182  } else {
183  $this->path .= ($this->getPathPostfix() . '_' . $this->container_id);
184  }
185  return true;
186  }
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 143 of file class.ilFileSystemStorage.php.

References $from.

Referenced by ilFSStorageExercise\uploadFile().

144  {
145  return @rename($from, $to);
146  }
$from
+ 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 195 of file class.ilFileSystemStorage.php.

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

196  {
197  if (!$fp = @fopen($a_absolute_path, 'w+')) {
198  return false;
199  }
200  if (@fwrite($fp, $a_data) === false) {
201  @fclose($fp);
202  return false;
203  }
204  @fclose($fp);
205  return true;
206  }
+ 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: