ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilObjFile Class Reference

Class ilObjFile. More...

+ Inheritance diagram for ilObjFile:
+ Collaboration diagram for ilObjFile:

Public Member Functions

 __construct ($a_id=0, $a_call_by_reference=true)
 ilObjFile constructor. More...
 
 initType ()
 
 createProperties ($a_upload=false)
 The basic properties of a file object are stored in table object_data. More...
 
 setNoMetaDataCreation ($a_status)
 
 getDirectory ($a_version=0)
 
 createDirectory ()
 
 raiseUploadError ($a_raise=true)
 
 replaceFile ($a_upload_file, $a_filename)
 
 addFileVersion ($a_upload_file, $a_filename)
 
 copy ($a_source, $a_destination)
 copy file More...
 
 clearDataDirectory ()
 clear data directory More...
 
 deleteVersions ($a_hist_entry_ids=null)
 Deletes the specified history entries or all entries if no ids are specified. More...
 
 setFileName ($a_name)
 
 getFileName ()
 
 setFileType ($a_type)
 
 getFileType ()
 
 setFileSize ($a_size)
 
 getFileSize ()
 
 setAction ($a_action)
 
 getAction ()
 
 setRollbackVersion ($a_rollback_version)
 
 getRollbackVersion ()
 
 setRollbackUserId ($a_rollback_user_id)
 
 getRollbackUserId ()
 
 getDiskUsage ()
 Gets the disk usage of the object in bytes. More...
 
 getFile ($a_hist_entry_id=null)
 
 setVersion ($a_version)
 
 getVersion ()
 
 setMaxVersion ($a_max_version)
 
 getMaxVersion ()
 
 setMode ($a_mode)
 mode is object or filelist More...
 
 getMode ()
 mode is object or filelist More...
 
 determineFileSize ($a_hist_entry_id=null)
 Determine File Size. More...
 
 getFileExtension ()
 Returns the extension of the file name converted to lower-case. More...
 
 isInline ()
 Returns true, if this file should be displayed inline in a browser window. More...
 
 isHidden ()
 Returns true, if this file should be hidden in the repository view. More...
 
 guessFileType ($a_file="")
 Guesses the file type based on the current values returned by getFileType() and getFileExtension(). More...
 
 export ($a_target_dir)
 export files of object to target directory note: target directory must be the export target directory, "/objects/il_<inst>_file_<file_id>/..." will be appended to this directory More...
 
 getUsages ()
 get all usages of file object More...
 
 getXMLZip ()
 
 addNewsNotification ($a_lang_var)
 
 initFileStorage ()
 init file storage object More...
 
 storeUnzipedFile ($a_upload_file, $a_filename)
 storeUnzipedFile More...
 
 checkFileExtension ($new_filename, $new_title)
 Check if the file extension does still exist after an update of the title. More...
 
 getVersions ($version_ids=null)
 Gets the file versions for this object. More...
 
 getSpecificVersion ($version_id)
 Gets a specific file version. More...
 
 rollback ($version_id)
 Makes the specified version the current one and returns theSummary of rollbackVersion. More...
 
 compareVersions ($v1, $v2)
 Compares two file versions. More...
 
 setRating ($a_value)
 
 hasRating ()
 
 getPageCount ()
 
 setPageCount ($page_count)
 
- Public Member Functions inherited from ilObject2
 __construct ($a_id=0, $a_reference=true)
 Constructor public. More...
 
 withReferences ()
 
 read ()
 Read data from db. More...
 
 getId ()
 
 setId ($a_id)
 
 setRefId ($a_id)
 
 getRefId ()
 
 getType ()
 
 setType ($a_type)
 
 getPresentationTitle ()
 
 getTitle ()
 
 getUntranslatedTitle ()
 
 setTitle ($a_title)
 
 getDescription ()
 
 setDescription ($a_desc)
 
 getLongDescription ()
 
 getImportId ()
 
 setImportId ($a_import_id)
 
 getOwner ()
 
 getOwnerName ()
 
 setOwner ($a_owner)
 
 getCreateDate ()
 
 getLastUpdateDate ()
 
 create ($a_clone_mode=false)
 
 update ()
 
 MDUpdateListener ($a_element)
 
 createMetaData ()
 
 updateMetaData ()
 
 deleteMetaData ()
 
 updateOwner ()
 
 putInTree ($a_parent_ref)
 
 setPermissions ($a_parent_ref)
 
 createReference ()
 
 countReferences ()
 
 delete ()
 
 initDefaultRoles ()
 
 setRegisterMode ($a_bool)
 
 isUserRegistered ($a_user_id=0)
 
 requireRegistration ()
 
 appendCopyInfo ($a_target_id, $a_copy_id)
 
 cloneMetaData ($target_obj)
 
 cloneObject ($a_target_id, $a_copy_id=null, $a_omit_tree=false)
 
 cloneDependencies ($a_target_id, $a_copy_id)
 
- Public Member Functions inherited from ilObject
 __construct ($a_id=0, $a_reference=true)
 Constructor public. More...
 
 withReferences ()
 determines wehter objects are referenced or not (got ref ids or not) More...
 
 read ()
 read object data from db into object More...
 
 getId ()
 get object id public More...
 
 setId ($a_id)
 set object id public More...
 
 setRefId ($a_id)
 set reference id public More...
 
 getRefId ()
 get reference id public More...
 
 getType ()
 get object type public More...
 
 setType ($a_type)
 set object type public More...
 
 getPresentationTitle ()
 get presentation title Normally same as title Overwritten for sessions More...
 
 getTitle ()
 get object title public More...
 
 getUntranslatedTitle ()
 get untranslated object title public More...
 
 setTitle ($a_title)
 set object title More...
 
 getDescription ()
 get object description More...
 
 setDescription ($a_desc)
 set object description More...
 
 getLongDescription ()
 get object long description (stored in object_description) More...
 
 getImportId ()
 get import id More...
 
 setImportId ($a_import_id)
 set import id More...
 
 setOfflineStatus ($a_status)
 Set offline status. More...
 
 getOfflineStatus ()
 Get offline status. More...
 
 supportsOfflineHandling ()
 Check whether object supports offline handling. More...
 
 getOwner ()
 get object owner More...
 
 getOwnerName ()
 
 setOwner ($a_owner)
 set object owner More...
 
 getCreateDate ()
 get create date public More...
 
 getLastUpdateDate ()
 get last update date public More...
 
 getDiskUsage ()
 Gets the disk usage of the object in bytes. More...
 
 create ()
 create More...
 
 update ()
 update object in db More...
 
 MDUpdateListener ($a_element)
 Meta data update listener. More...
 
 createMetaData ()
 create meta data entry More...
 
 updateMetaData ()
 update meta data entry More...
 
 deleteMetaData ()
 delete meta data entry More...
 
 updateOwner ()
 update owner of object in db More...
 
 putInTree ($a_parent_ref)
 maybe this method should be in tree object!? More...
 
 setPermissions ($a_parent_ref)
 set permissions of object More...
 
 setParentRolePermissions ($a_parent_ref)
 Initialize the permissions of parent roles (local roles of categories, global roles...) This method is overwritten in e.g courses, groups for building permission intersections with non_member templates. More...
 
 createReference ()
 creates reference for object More...
 
 countReferences ()
 count references of object More...
 
 initDefaultRoles ()
 init default roles settings Purpose of this function is to create a local role folder and local roles, that are needed depending on the object type If you want to setup default local roles you MUST overwrite this method in derived object classes (see ilObjForum for an example) public More...
 
 applyDidacticTemplate ($a_tpl_id)
 Apply template. More...
 
 setRegisterMode ($a_bool)
 
 isUserRegistered ($a_user_id=0)
 
 requireRegistration ()
 
 getXMLZip ()
 
 getHTMLDirectory ()
 
 appendCopyInfo ($a_target_id, $a_copy_id)
 Prepend Copy info if object with same name exists in that container. More...
 
 cloneDependencies ($a_target_id, $a_copy_id)
 Clone object dependencies. More...
 
 cloneMetaData ($target_obj)
 Copy meta data. More...
 
 getPossibleSubObjects ($a_filter=true)
 get all possible subobjects of this type the object can decide which types of subobjects are possible jut in time overwrite if the decision distinguish from standard model More...
 

Static Public Member Functions

static _writeFileType ($a_id, $a_format)
 
static _lookupFileName ($a_id)
 
static _lookupFileSize ($a_id)
 Lookups the file size of the file in bytes. More...
 
static _lookupVersion ($a_id)
 lookup version More...
 
static _deleteAllUsages ($a_type, $a_id, $a_usage_hist_nr=0, $a_usage_lang="-")
 static delete all usages of More...
 
static _saveUsage ($a_file_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_usage_lang="-")
 save usage More...
 
static _getFilesOfObject ($a_type, $a_id, $a_usage_hist_nr=0, $a_usage_lang="-")
 get all files of an object More...
 
static _lookupAbsolutePath ($obj_id, $a_version=null)
 
- Static Public Member Functions inherited from ilObject2
static _lookupObjIdByImportId ($a_import_id)
 
static _lookupOwnerName ($a_owner_id)
 
static _getIdForImportId ($a_import_id)
 
static _getAllReferences ($a_id)
 
static _lookupTitle ($a_id)
 
static _lookupOwner ($a_id)
 
static _getIdsForTitle ($title, $type='', $partialmatch=false)
 
static _lookupDescription ($a_id)
 
static _lookupLastUpdate ($a_id, $a_as_string=false)
 
static _getLastUpdateOfObjects ($a_objs)
 
static _lookupObjId ($a_id)
 
static _setDeletedDate ($a_ref_id)
 
static _resetDeletedDate ($a_ref_id)
 
static _lookupDeletedDate ($a_ref_id)
 
static _writeTitle ($a_obj_id, $a_title)
 
static _writeDescription ($a_obj_id, $a_desc)
 
static _writeImportId ($a_obj_id, $a_import_id)
 
static _lookupType ($a_id, $a_reference=false)
 
static _isInTrash ($a_ref_id)
 
static _hasUntrashedReference ($a_obj_id)
 
static _lookupObjectId ($a_ref_id)
 
static _getObjectsDataForType ($a_type, $a_omit_trash=false)
 
static _exists ($a_id, $a_reference=false, $a_type=null)
 
static _getObjectsByType ($a_obj_type="", $a_owner="")
 
static _prepareCloneSelection ($a_ref_ids, $new_type, $a_show_path=true)
 
static _getIcon ($a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
 
- Static Public Member Functions inherited from ilObject
static _lookupObjIdByImportId ($a_import_id)
 
static _lookupImportId ($a_obj_id)
 
static _lookupOwnerName ($a_owner_id)
 lookup owner name for owner id More...
 
static _getIdForImportId ($a_import_id)
 get current object id for import id (static) More...
 
static _getAllReferences ($a_id)
 get all reference ids of object More...
 
static _lookupTitle ($a_id)
 lookup object title More...
 
static lookupOfflineStatus ($a_obj_id)
 Lookup offline status using objectDataCache. More...
 
static _lookupOwner ($a_id)
 lookup object owner More...
 
static _getIdsForTitle ($title, $type='', $partialmatch=false)
 
static _lookupDescription ($a_id)
 lookup object description More...
 
static _lookupLastUpdate ($a_id, $a_as_string=false)
 lookup last update More...
 
static _getLastUpdateOfObjects ($a_objs)
 Get last update for a set of media objects. More...
 
static _lookupObjId ($a_id)
 
static _setDeletedDate ($a_ref_id)
 only called in ilTree::saveSubTree More...
 
static setDeletedDates ($a_ref_ids)
 Set deleted date. More...
 
static _resetDeletedDate ($a_ref_id)
 only called in ilObjectGUI::insertSavedNodes More...
 
static _lookupDeletedDate ($a_ref_id)
 only called in ilObjectGUI::insertSavedNodes More...
 
static _writeTitle ($a_obj_id, $a_title)
 write title to db (static) More...
 
static _writeDescription ($a_obj_id, $a_desc)
 write description to db (static) More...
 
static _writeImportId ($a_obj_id, $a_import_id)
 write import id to db (static) More...
 
static _lookupType ($a_id, $a_reference=false)
 lookup object type More...
 
static _isInTrash ($a_ref_id)
 checks wether object is in trash More...
 
static _hasUntrashedReference ($a_obj_id)
 checks wether an object has at least one reference that is not in trash More...
 
static _lookupObjectId ($a_ref_id)
 lookup object id More...
 
static _getObjectsDataForType ($a_type, $a_omit_trash=false)
 get all objects of a certain type More...
 
static _exists ($a_id, $a_reference=false, $a_type=null)
 checks if an object exists in object_data More...
 
static _getObjectsByType ($a_obj_type="", $a_owner="")
 Get objects by type. More...
 
static _prepareCloneSelection ($a_ref_ids, $new_type, $show_path=true)
 Prepare copy wizard object selection. More...
 
static collectDeletionDependencies (&$deps, $a_ref_id, $a_obj_id, $a_type, $a_depth=0)
 Collect deletion dependencies. More...
 
static getDeletionDependencies ($a_obj_id)
 Get deletion dependencies. More...
 
static getLongDescriptions (array $a_obj_ids)
 Get long description data. More...
 
static getAllOwnedRepositoryObjects ($a_user_id)
 Get all ids of objects user owns. More...
 
static fixMissingTitles ($a_type, array &$a_obj_title_map)
 Try to fix missing object titles. More...
 
static _lookupCreationDate ($a_id)
 Lookup creation date. More...
 
static hasAutoRating ($a_type, $a_ref_id)
 Check if auto rating is active for parent group/course. More...
 

Data Fields

const MODE_FILELIST = "filelist"
 
const MODE_OBJECT = "object"
 
 $raise_upload_error
 
 $mode = self::MODE_OBJECT
 
- Data Fields inherited from ilObject
const TITLE_LENGTH = 255
 max length of object title More...
 
const DESC_LENGTH = 128
 
 $lng
 
 $id
 
 $ref_id
 
 $type
 
 $title
 
 $untranslatedTitle
 
 $desc
 
 $long_desc
 
 $owner
 
 $create_date
 
 $last_update
 
 $import_id
 
 $register = false
 
 $referenced
 
 $objectList
 
 $max_title
 
 $max_desc
 
 $add_dots
 

Protected Member Functions

 doCreate ($a_upload=false)
 create object More...
 
 beforeCreateMetaData ()
 
 beforeUpdateMetaData ()
 
 doCreateMetaData ()
 create file object meta data More...
 
 beforeMDUpdateListener ($a_element)
 
 doMDUpdateListener ($a_element)
 
 doRead ()
 
 beforeUpdate ()
 
 doUpdate ()
 
 doUpdateMetaData ()
 update meta data More...
 
 doCloneObject ($a_new_obj, $a_target_id, $a_copy_id=0)
 Clone. More...
 
 beforeDelete ()
 
 doDelete ()
 
 updateWithVersion ($version)
 Updates the file object with the specified file version. More...
 
 createPreview ($force=false)
 Creates a preview for the file object. More...
 
 deletePreview ()
 Deletes the preview of the file object. More...
 
- Protected Member Functions inherited from ilObject2
 initType ()
 
 doRead ()
 
 doCreate ()
 
 beforeCreate ()
 
 doUpdate ()
 
 beforeUpdate ()
 
 doMDUpdateListener ($a_element)
 
 beforeMDUpdateListener ($a_element)
 
 doCreateMetaData ()
 
 beforeCreateMetaData ()
 
 doUpdateMetaData ()
 
 beforeUpdateMetaData ()
 
 doDelete ()
 
 beforeDelete ()
 
 doCloneObject ($new_obj, $a_target_id, $a_copy_id=null)
 
 beforeCloneObject ()
 

Static Protected Member Functions

static handleQuotaUpdate (ilObjFile $a_file)
 

Protected Attributes

 $no_meta_data_creation
 
 $filename = ''
 
 $filetype = ''
 
 $filemaxsize = "20000000"
 
 $filesize
 
 $page_count = 0
 
 $rating = false
 
 $log = null
 
 $version = 1
 
 $max_version = 1
 
 $action = null
 
 $rollback_version = null
 
 $rollback_user_id = null
 
- Protected Attributes inherited from ilObject
 $objDefinition
 
 $db
 
 $log
 
 $error
 
 $tree
 
 $app_event_handler
 
 $rbacadmin
 
 $rbacreview
 

Private Member Functions

 parseInfoParams ($entry)
 Parses the info parameters ("info_params") of the specified history entry. More...
 
 getArrayForDatabase ($file_id=0)
 

Private Attributes

 $file_storage = null
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilObjFile::__construct (   $a_id = 0,
  $a_call_by_reference = true 
)

ilObjFile constructor.

Parameters
int$a_idID of the object, ref_id or obj_id possible
bool$a_call_by_referencedefines the $a_id a ref_id

Definition at line 97 of file class.ilObjFile.php.

References ilObject2\getId(), ilLoggerFactory\getLogger(), and initFileStorage().

98  {
99  $this->version = 0;
100  $this->max_version = 0;
101  $this->raise_upload_error = true;
102 
103  $this->log = ilLoggerFactory::getLogger('file');
104 
105  parent::__construct($a_id, $a_call_by_reference);
106 
107  if ($this->getId()) {
108  $this->initFileStorage();
109  }
110  }
initFileStorage()
init file storage object
static getLogger($a_component_id)
Get component logger.
+ Here is the call graph for this function:

Member Function Documentation

◆ _deleteAllUsages()

static ilObjFile::_deleteAllUsages (   $a_type,
  $a_id,
  $a_usage_hist_nr = 0,
  $a_usage_lang = "-" 
)
static

static delete all usages of

Definition at line 1070 of file class.ilObjFile.php.

References $a_type, $DIC, $ilDB, and $row.

Referenced by ilPCFileList\beforePageDelete(), and ilPCFileList\saveFileUsage().

1071  {
1072  global $DIC;
1073  $ilDB = $DIC['ilDB'];
1074 
1075  $and_hist = ($a_usage_hist_nr !== false) ? " AND usage_hist_nr = "
1076  . $ilDB->quote($a_usage_hist_nr, "integer") : "";
1077 
1078  $file_ids = array();
1079  $set = $ilDB->query("SELECT id FROM file_usage" . " WHERE usage_type = "
1080  . $ilDB->quote($a_type, "text") . " AND usage_id= "
1081  . $ilDB->quote($a_id, "integer") . " AND usage_lang= "
1082  . $ilDB->quote($a_usage_lang, "text") . $and_hist);
1083  while ($row = $ilDB->fetchAssoc($set)) {
1084  $file_ids[] = $row["id"];
1085  }
1086 
1087  $ilDB->manipulate("DELETE FROM file_usage WHERE usage_type = "
1088  . $ilDB->quote($a_type, "text") . " AND usage_id = "
1089  . $ilDB->quote((int) $a_id, "integer") . " AND usage_lang= "
1090  . $ilDB->quote($a_usage_lang, "text") . " AND usage_hist_nr = "
1091  . $ilDB->quote((int) $a_usage_hist_nr, "integer"));
1092 
1093  foreach ($file_ids as $file_id) {
1094  self::handleQuotaUpdate(new self($file_id, false));
1095  }
1096  }
global $DIC
Definition: saml.php:7
$a_type
Definition: workflow.php:92
$row
global $ilDB
+ Here is the caller graph for this function:

◆ _getFilesOfObject()

static ilObjFile::_getFilesOfObject (   $a_type,
  $a_id,
  $a_usage_hist_nr = 0,
  $a_usage_lang = "-" 
)
static

get all files of an object

Parameters
string$a_typeobject type (e.g. "lm:pg")
int$a_idobject id
Returns
array array of file ids

Definition at line 1157 of file class.ilObjFile.php.

References $a_type, $DIC, $ilDB, and $ret.

Referenced by ilPCFileList\afterPageUpdate(), ilCOPageHTMLExport\collectPageElements(), ilPageObjectGUI\downloadFile(), ilObjGlossary\exportHTMLGlossaryTerms(), ilObjContentObject\exportHTMLGlossaryTerms(), ilObjContentObject\exportHTMLPages(), ilPageObject\getLastUpdateOfIncludedElements(), and ilCOPageExporter\getXmlExportHeadDependencies().

1158  {
1159  global $DIC;
1160  $ilDB = $DIC['ilDB'];
1161 
1162  $lstr = "";
1163  if ($a_usage_lang != "") {
1164  $lstr = "usage_lang = " . $ilDB->quote((string) $a_usage_lang, "text") . " AND ";
1165  }
1166 
1167  // get usages in learning modules
1168  $q = "SELECT * FROM file_usage WHERE " . "usage_id = " . $ilDB->quote((int) $a_id, "integer")
1169  . " AND " . "usage_type = " . $ilDB->quote((string) $a_type, "text") . " AND " . $lstr
1170  . "usage_hist_nr = " . $ilDB->quote((int) $a_usage_hist_nr, "integer");
1171  $file_set = $ilDB->query($q);
1172  $ret = array();
1173  while ($file_rec = $ilDB->fetchAssoc($file_set)) {
1174  $ret[$file_rec["id"]] = $file_rec["id"];
1175  }
1176 
1177  return $ret;
1178  }
global $DIC
Definition: saml.php:7
$a_type
Definition: workflow.php:92
global $ilDB
$ret
Definition: parser.php:6
+ Here is the caller graph for this function:

◆ _lookupAbsolutePath()

static ilObjFile::_lookupAbsolutePath (   $obj_id,
  $a_version = null 
)
static
Parameters
$obj_id
null$a_version
Returns
bool|string
Exceptions

Definition at line 1273 of file class.ilObjFile.php.

References $s.

Referenced by ilFolderDownloadBackgroundTaskHandler\copyFile(), ilContainerGUI\copyFile(), and ilObjFolder\recurseFolder().

1274  {
1275  $file_object = new self($obj_id, false);
1276  $s = new FilePathSanitizer($file_object);
1277  $s->sanitizeIfNeeded();
1278 
1279  return $file_object->getFile($a_version);
1280  }
$s
Definition: pwgen.php:45
+ Here is the caller graph for this function:

◆ _lookupFileName()

static ilObjFile::_lookupFileName (   $a_id)
static
Parameters
$a_id
Returns
string
Deprecated:
Static methods will be removed in a future version of ILIAS

Definition at line 779 of file class.ilObjFile.php.

References $DIC, $ilDB, $r, $row, ilDBConstants\FETCHMODE_OBJECT, and ilUtil\stripSlashes().

Referenced by ilSCORM2004PageGUI\setDefaultLinkXml(), and ilFilePreviewRenderer\supports().

780  {
781  global $DIC;
782  $ilDB = $DIC['ilDB'];
783 
784  $q = "SELECT * FROM file_data WHERE file_id = " . $ilDB->quote($a_id, 'integer');
785  $r = $ilDB->query($q);
787 
788  $strip_slashes = ilUtil::stripSlashes($row->file_name);
789 
790  return $strip_slashes;
791  }
global $DIC
Definition: saml.php:7
$r
Definition: example_031.php:79
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
$row
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _lookupFileSize()

static ilObjFile::_lookupFileSize (   $a_id)
static

Lookups the file size of the file in bytes.

Definition at line 795 of file class.ilObjFile.php.

References ilObjFileAccess\_lookupFileSize().

Referenced by ilPageObject\addFileSizes(), and ilObjFileGUI\infoScreenForward().

796  {
797  require_once("./Modules/File/classes/class.ilObjFileAccess.php");
798 
799  return ilObjFileAccess::_lookupFileSize($a_id);
800  }
static _lookupFileSize($a_id)
Quickly looks up the file size from the database and returns the number of bytes. ...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _lookupVersion()

static ilObjFile::_lookupVersion (   $a_id)
static

lookup version

Definition at line 806 of file class.ilObjFile.php.

References ilObjFileAccess\_lookupVersion().

807  {
808  require_once("./Modules/File/classes/class.ilObjFileAccess.php");
809 
810  return ilObjFileAccess::_lookupVersion($a_id);
811  }
static _lookupVersion($a_id)
lookup version
+ Here is the call graph for this function:

◆ _saveUsage()

static ilObjFile::_saveUsage (   $a_file_id,
  $a_type,
  $a_id,
  $a_usage_hist_nr = 0,
  $a_usage_lang = "-" 
)
static

save usage

Definition at line 1102 of file class.ilObjFile.php.

References $a_type, $DIC, $ilDB, and ilObject\_lookupType().

Referenced by ilPCFileList\saveFileUsage().

1103  {
1104  global $DIC;
1105  $ilDB = $DIC['ilDB'];
1106 
1107  // check if file really exists
1108  if (ilObject::_lookupType($a_file_id) != "file") {
1109  return;
1110  }
1111  // #15143
1112  $ilDB->replace("file_usage", array(
1113  "id" => array("integer", (int) $a_file_id),
1114  "usage_type" => array("text", (string) $a_type),
1115  "usage_id" => array("integer", (int) $a_id),
1116  "usage_hist_nr" => array("integer", (int) $a_usage_hist_nr),
1117  "usage_lang" => array("text", $a_usage_lang),
1118  ), array());
1119 
1120  self::handleQuotaUpdate(new self($a_file_id, false));
1121  }
global $DIC
Definition: saml.php:7
$a_type
Definition: workflow.php:92
static _lookupType($a_id, $a_reference=false)
lookup object type
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _writeFileType()

static ilObjFile::_writeFileType (   $a_id,
  $a_format 
)
static

Definition at line 762 of file class.ilObjFile.php.

References $DIC, $ilDB, and $res.

Referenced by doMDUpdateListener().

763  {
764  global $DIC;
765  $ilDB = $DIC['ilDB'];
766 
767  $q = "UPDATE file_data SET " . " file_type = " . $ilDB->quote($a_format, 'text')
768  . " WHERE file_id = " . $ilDB->quote($a_id, 'integer');
769  $res = $ilDB->manipulate($q);
770  }
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB
+ Here is the caller graph for this function:

◆ addFileVersion()

ilObjFile::addFileVersion (   $a_upload_file,
  $a_filename 
)
Parameters
$a_upload_file
$a_filename
Returns
Exceptions

Definition at line 414 of file class.ilObjFile.php.

References $result, ilHistory\_createEntry(), addNewsNotification(), createPreview(), ilObject2\getId(), getMaxVersion(), and getVersion().

415  {
416  if ($result = $this->getUploadFile($a_upload_file, $a_filename, true)) {
417  ilHistory::_createEntry($this->getId(), "new_version", $result->getName() . "," . $this->getVersion() . "," . $this->getMaxVersion());
418  $this->addNewsNotification("file_updated");
419 
420  // create preview
421  $this->createPreview($this->getVersion() > 1);
422  }
423 
424  return $result;
425  }
$result
static _createEntry( $a_obj_id, $a_action, $a_info_params="", $a_obj_type="", $a_user_comment="", $a_update_last=false)
Creates a new history entry for an object.
createPreview($force=false)
Creates a preview for the file object.
addNewsNotification($a_lang_var)
+ Here is the call graph for this function:

◆ addNewsNotification()

ilObjFile::addNewsNotification (   $a_lang_var)

Definition at line 1196 of file class.ilObjFile.php.

References $DIC, $ilUser, ilObject2\getDescription(), ilObject2\getId(), ilObject2\getType(), isHidden(), NEWS_NOTICE, and NEWS_USERS.

Referenced by addFileVersion(), createProperties(), replaceFile(), and rollback().

1197  {
1198  // BEGIN WebDAV Suppress news notification for hidden files
1199  if ($this->isHidden()) {
1200  return;
1201  }
1202  // END WebDAV Suppress news notification for hidden files
1203 
1204  global $DIC;
1205  $ilUser = $DIC['ilUser'];
1206 
1207  // Add Notification to news
1208  include_once("./Services/News/classes/class.ilNewsItem.php");
1209  include_once("./Modules/File/classes/class.ilObjFileAccess.php");
1210  $news_item = new ilNewsItem();
1211  $news_item->setContext($this->getId(), $this->getType());
1212  $news_item->setPriority(NEWS_NOTICE);
1213  $news_item->setTitle($a_lang_var);
1214  $news_item->setContentIsLangVar(true);
1215  if ($this->getDescription() != "") {
1216  $news_item->setContent("<p>" . $this->getDescription() . "</p>");
1217  }
1218  $news_item->setUserId($ilUser->getId());
1219  $news_item->setVisibility(NEWS_USERS);
1220  $news_item->create();
1221  }
global $DIC
Definition: saml.php:7
const NEWS_NOTICE
$ilUser
Definition: imgupload.php:18
isHidden()
Returns true, if this file should be hidden in the repository view.
const NEWS_USERS
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ beforeCreateMetaData()

ilObjFile::beforeCreateMetaData ( )
protected

Definition at line 194 of file class.ilObjFile.php.

195  {
196  return !(bool) $this->no_meta_data_creation;
197  }

◆ beforeDelete()

ilObjFile::beforeDelete ( )
protected

Definition at line 1000 of file class.ilObjFile.php.

References $DIC, $ilDB, and getUsages().

1001  {
1002  global $DIC;
1003  $ilDB = $DIC['ilDB'];
1004 
1005  // check, if file is used somewhere
1006  $usages = $this->getUsages();
1007  if (count($usages) == 0) {
1008  return true;
1009  }
1010 
1011  return false;
1012  }
global $DIC
Definition: saml.php:7
getUsages()
get all usages of file object
global $ilDB
+ Here is the call graph for this function:

◆ beforeMDUpdateListener()

ilObjFile::beforeMDUpdateListener (   $a_element)
protected

Definition at line 223 of file class.ilObjFile.php.

References ilObject\$title, checkFileExtension(), getFileName(), ilObject2\getId(), and ilObject2\getType().

224  {
225  // Check file extension
226  // Removing the file extension is not allowed
227  include_once 'Services/MetaData/classes/class.ilMD.php';
228  $md = new ilMD($this->getId(), 0, $this->getType());
229  if (!is_object($md_gen = $md->getGeneral())) {
230  return false;
231  }
232  $title = $this->checkFileExtension($this->getFileName(), $md_gen->getTitle());
233  $md_gen->setTitle($title);
234  $md_gen->update();
235 
236  return true;
237  }
checkFileExtension($new_filename, $new_title)
Check if the file extension does still exist after an update of the title.
+ Here is the call graph for this function:

◆ beforeUpdate()

ilObjFile::beforeUpdate ( )
protected

Definition at line 527 of file class.ilObjFile.php.

References getMode(), and ilObject2\updateMetaData().

528  {
529  // no meta data handling for file list files
530  if ($this->getMode() != self::MODE_FILELIST) {
531  $this->updateMetaData();
532  }
533 
534  return true;
535  }
getMode()
mode is object or filelist
+ Here is the call graph for this function:

◆ beforeUpdateMetaData()

ilObjFile::beforeUpdateMetaData ( )
protected

Definition at line 200 of file class.ilObjFile.php.

201  {
202  return !(bool) $this->no_meta_data_creation;
203  }

◆ checkFileExtension()

ilObjFile::checkFileExtension (   $new_filename,
  $new_title 
)

Check if the file extension does still exist after an update of the title.

Returns

Definition at line 1288 of file class.ilObjFile.php.

References ilObjFileAccess\_getFileExtension(), and getFileName().

Referenced by beforeMDUpdateListener(), and updateWithVersion().

1289  {
1290  include_once './Modules/File/classes/class.ilObjFileAccess.php';
1291  $fileExtension = ilObjFileAccess::_getFileExtension($new_filename);
1292  $titleExtension = ilObjFileAccess::_getFileExtension($new_title);
1293  if ($titleExtension != $fileExtension && strlen($fileExtension) > 0) {
1294  // remove old extension
1295  $pi = pathinfo($this->getFileName());
1296  $suffix = $pi["extension"];
1297  if ($suffix != "") {
1298  if (substr($new_title, strlen($new_title) - strlen($suffix) - 1) == "." . $suffix) {
1299  $new_title = substr($new_title, 0, strlen($new_title) - strlen($suffix) - 1);
1300  }
1301  }
1302  $new_title .= '.' . $fileExtension;
1303  }
1304 
1305  return $new_title;
1306  }
static _getFileExtension($a_file_name)
Gets the file extension of the specified file name.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clearDataDirectory()

ilObjFile::clearDataDirectory ( )

clear data directory

Definition at line 440 of file class.ilObjFile.php.

References createDirectory(), ilUtil\delDir(), and getDirectory().

Referenced by deleteVersions().

441  {
442  ilUtil::delDir($this->getDirectory());
443  $this->createDirectory();
444  }
getDirectory($a_version=0)
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:

◆ compareVersions()

ilObjFile::compareVersions (   $v1,
  $v2 
)

Compares two file versions.

Parameters
array$v1First file version to compare.
array$v2Second file version to compare.
Returns
int Returns an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.

Definition at line 1485 of file class.ilObjFile.php.

1486  {
1487  // v2 - v1 because version should be descending
1488  return (int) $v2["version"] - (int) $v1["version"];
1489  }

◆ copy()

ilObjFile::copy (   $a_source,
  $a_destination 
)

copy file

Definition at line 431 of file class.ilObjFile.php.

References getDirectory().

Referenced by rollback().

432  {
433  return copy($a_source, $this->getDirectory() . "/" . $a_destination);
434  }
copy($a_source, $a_destination)
copy file
getDirectory($a_version=0)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createDirectory()

ilObjFile::createDirectory ( )

Definition at line 293 of file class.ilObjFile.php.

References getDirectory(), and ilUtil\makeDirParents().

Referenced by clearDataDirectory().

294  {
296  }
static makeDirParents($a_dir)
Create a new directory and all parent directories.
getDirectory($a_version=0)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createPreview()

ilObjFile::createPreview (   $force = false)
protected

Creates a preview for the file object.

Parameters
bool$forcetrue, to force the creation of the preview; false, to create the preview only if the file is newer.

Definition at line 1581 of file class.ilObjFile.php.

References ilPreview\createPreview(), and getMode().

Referenced by addFileVersion(), raiseUploadError(), replaceFile(), storeUnzipedFile(), and updateWithVersion().

1582  {
1583  // only normal files are supported
1584  if ($this->getMode() != self::MODE_OBJECT) {
1585  return;
1586  }
1587 
1588  require_once("./Services/Preview/classes/class.ilPreview.php");
1589  ilPreview::createPreview($this, $force);
1590  }
getMode()
mode is object or filelist
static createPreview($a_obj, $a_force=false)
Creates the preview for the object with the specified id.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createProperties()

ilObjFile::createProperties (   $a_upload = false)

The basic properties of a file object are stored in table object_data.

This is not sufficient for a file object. Therefore we create additional properties in table file_data. This method has been put into a separate operation, to allow a WebDAV Null resource (class.ilObjNull.php) to become a file object.

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

References $_GET, $DIC, $metadata, ilHistory\_createEntry(), ilNewsItem\_getDefaultVisibilityForRefId(), ilBlockSetting\_write(), addNewsNotification(), ilObject2\createMetaData(), ilLogLevel\DEBUG, getArrayForDatabase(), ilStr\getBytesForString(), getFileName(), getFileSize(), getFileType(), ilObject2\getId(), getMode(), getVersion(), and initFileStorage().

Referenced by doCreate().

138  {
139  global $DIC;
140 
141  // Create file directory
142  $this->initFileStorage();
143  $this->file_storage->create();
144 
145  if ($a_upload) {
146  return true;
147  }
148 
149  // not upload mode
150  ilHistory::_createEntry($this->getId(), "create", $this->getFileName() . ",1" . ",1");
151  $this->addNewsNotification("file_created");
152 
153  // New Item
154  $default_visibility = ilNewsItem::_getDefaultVisibilityForRefId($_GET['ref_id']);
155  if ($default_visibility == "public") {
156  ilBlockSetting::_write("news", "public_notifications", 1, 0, $this->getId());
157  }
158 
159  // log creation
160  $this->log->debug("ilObjFile::createProperties, ID: " . $this->getId() . ", Name: "
161  . $this->getFileName() . ", Type: " . $this->getFileType() . ", Size: "
162  . $this->getFileSize() . ", Mode: " . $this->getMode() . ", Name(Bytes): "
163  . implode(":", ilStr::getBytesForString($this->getFileName())));
164  $this->log->logStack(ilLogLevel::DEBUG);
165 
166  $DIC->database()->insert('file_data', $this->getArrayForDatabase());
167 
168  //add metadata to database
169  $metadata = [
170  'meta_lifecycle_id' => ['integer', $DIC->database()->nextId('il_meta_lifecycle')],
171  'rbac_id' => ['integer', $this->getId()],
172  'obj_id' => ['integer', $this->getId()],
173  'obj_type' => ['text', "file"],
174  'meta_version' => ['integer', (int) $this->getVersion()],
175  ];
176  $DIC->database()->insert('il_meta_lifecycle', $metadata);
177 
178  // no meta data handling for file list files
179  if ($this->getMode() != self::MODE_FILELIST) {
180  $this->createMetaData();
181  }
182  }
static _write($a_type, $a_setting, $a_value, $a_user=0, $a_block_id=0)
Write setting to database.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
getMode()
mode is object or filelist
$metadata['__DYNAMIC:1__']
static _createEntry( $a_obj_id, $a_action, $a_info_params="", $a_obj_type="", $a_user_comment="", $a_update_last=false)
Creates a new history entry for an object.
static getBytesForString($a_str)
Return string as byte array Note: Use this for debugging purposes only.
getArrayForDatabase($file_id=0)
addNewsNotification($a_lang_var)
initFileStorage()
init file storage object
static _getDefaultVisibilityForRefId($a_ref_id)
Get default visibility for reference id.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deletePreview()

ilObjFile::deletePreview ( )
protected

Deletes the preview of the file object.

Definition at line 1596 of file class.ilObjFile.php.

References ilPreview\deletePreview(), ilObject2\getId(), and getMode().

Referenced by doDelete().

1597  {
1598  // only normal files are supported
1599  if ($this->getMode() != self::MODE_OBJECT) {
1600  return;
1601  }
1602 
1603  require_once("./Services/Preview/classes/class.ilPreview.php");
1604  ilPreview::deletePreview($this->getId());
1605  }
getMode()
mode is object or filelist
static deletePreview($a_obj_id)
Deletes the preview for the object with the specified id.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deleteVersions()

ilObjFile::deleteVersions (   $a_hist_entry_ids = null)

Deletes the specified history entries or all entries if no ids are specified.

Parameters
array$a_hist_entry_idsThe ids of the entries to delete or null to delete all entries

Definition at line 452 of file class.ilObjFile.php.

References $index, $version, ilHistory\_removeEntriesForObject(), ilHistory\_removeEntryByHistoryID(), clearDataDirectory(), ilUtil\delDir(), getDirectory(), ilObject2\getId(), getMaxVersion(), getVersion(), getVersions(), and updateWithVersion().

453  {
454  if ($a_hist_entry_ids == null || count($a_hist_entry_ids) < 1) {
455  $this->clearDataDirectory();
456 
458 
459  self::handleQuotaUpdate($this);
460  } else {
461  $actualVersionDeleted = false;
462 
463  // get all versions
464  $versions = $this->getVersions();
465 
466  // delete each version
467  foreach ($a_hist_entry_ids as $hist_id) {
468  $entry = null;
469 
470  // get version
471  foreach ($versions as $index => $version) {
472  if ($version["hist_entry_id"] == $hist_id) {
473  // remove each history entry
475 
476  // delete directory
477  $version_dir = $this->getDirectory($version["version"]);
478  ilUtil::delDir($version_dir);
479 
480  // is actual version?
481  if ($version["version"] == $this->getVersion()) {
482  $actualVersionDeleted = true;
483  }
484 
485  // remove from array
486  unset($versions[$index]);
487  break;
488  }
489  }
490  }
491 
492  // update actual version if it was deleted before
493  if ($actualVersionDeleted) {
494  // get newest version (already sorted by getVersions)
495  $version = reset($versions);
496  $version['max_version'] = $this->getMaxVersion();
497  $this->updateWithVersion($version);
498  } else {
499  // updateWithVersion() will trigger quota, too
500  self::handleQuotaUpdate($this);
501  }
502  }
503  }
static _removeEntryByHistoryID($a_hist_entry_id)
Removes a single entry from the history.
clearDataDirectory()
clear data directory
getDirectory($a_version=0)
$index
Definition: metadata.php:60
static _removeEntriesForObject($a_obj_id)
remove all history entries for an object
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
getVersions($version_ids=null)
Gets the file versions for this object.
updateWithVersion($version)
Updates the file object with the specified file version.
+ Here is the call graph for this function:

◆ determineFileSize()

ilObjFile::determineFileSize (   $a_hist_entry_id = null)

Determine File Size.

Definition at line 817 of file class.ilObjFile.php.

References $data, $DIC, $s, ilHistory\_getEntryByHistoryID(), ilFileDelivery\DISP_ATTACHMENT, ilFileDelivery\DISP_INLINE, getDirectory(), getFileName(), ilObject2\getTitle(), ilFileUtils\getValidFilename(), getVersion(), guessFileType(), isInline(), parseInfoParams(), and setFileSize().

Referenced by updateWithVersion().

818  {
819  if (is_null($a_hist_entry_id)) {
820  $file = $this->getDirectory($this->getVersion()) . "/" . $this->getFileName();
821  } else {
822  require_once("./Services/History/classes/class.ilHistory.php");
823  $entry = ilHistory::_getEntryByHistoryID($a_hist_entry_id);
824 
825  if ($entry === false) {
826  return false;
827  }
828 
829  $data = $this->parseInfoParams($entry);
830  $file = $this->getDirectory($data["version"]) . "/" . $data["filename"];
831  }
832  if (is_file($file)) {
833  $this->setFileSize(filesize($file));
834  }
835  }
parseInfoParams($entry)
Parses the info parameters ("info_params") of the specified history entry.
getDirectory($a_version=0)
setFileSize($a_size)
static _getEntryByHistoryID($a_hist_entry_id)
returns a single history entry
$data
Definition: bench.php:6
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ doCloneObject()

ilObjFile::doCloneObject (   $a_new_obj,
  $a_target_id,
  $a_copy_id = 0 
)
protected

Clone.

public

Parameters
objectclone
inttarget id
intcopy id

Definition at line 964 of file class.ilObjFile.php.

References $DIC, $ilDB, ilHistory\_copyEntriesForObject(), ilObject2\cloneMetaData(), ilPreview\copyPreviews(), getArrayForDatabase(), getDirectory(), ilObject2\getId(), and ilUtil\rCopy().

965  {
966  global $DIC;
967  $ilDB = $DIC['ilDB'];
968 
969  $a_new_obj->createDirectory();
970  $this->cloneMetaData($a_new_obj);
971 
972  // Copy all file versions
973  ilUtil::rCopy($this->getDirectory(), $a_new_obj->getDirectory());
974 
975  // object created now copy other settings
976  // bugfix mantis 26131
977  $DIC->database()->insert('file_data', $this->getArrayForDatabase($a_new_obj->getId()));
978 
979  // copy all previews
980  require_once("./Services/Preview/classes/class.ilPreview.php");
981  ilPreview::copyPreviews($this->getId(), $a_new_obj->getId());
982 
983  // copy history entries
984  require_once("./Services/History/classes/class.ilHistory.php");
985  ilHistory::_copyEntriesForObject($this->getId(), $a_new_obj->getId());
986 
987  // Copy learning progress settings
988  include_once('Services/Tracking/classes/class.ilLPObjSettings.php');
989  $obj_settings = new ilLPObjSettings($this->getId());
990  $obj_settings->cloneSettings($a_new_obj->getId());
991  unset($obj_settings);
992 
993  // add news notification
994  $a_new_obj->addNewsNotification("file_created");
995 
996  return $a_new_obj;
997  }
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
global $DIC
Definition: saml.php:7
getDirectory($a_version=0)
static _copyEntriesForObject($a_src_id, $a_dst_id)
copy all history entries for an object
getArrayForDatabase($file_id=0)
static copyPreviews($a_src_id, $a_dest_id)
Copies the preview images from one preview to a new preview object.
global $ilDB
cloneMetaData($target_obj)
+ Here is the call graph for this function:

◆ doCreate()

ilObjFile::doCreate (   $a_upload = false)
protected

create object

Parameters
boolupload mode (if enabled no entries in file_data will be done)

Definition at line 124 of file class.ilObjFile.php.

References createProperties().

125  {
126  $this->createProperties($a_upload);
127  }
createProperties($a_upload=false)
The basic properties of a file object are stored in table object_data.
+ Here is the call graph for this function:

◆ doCreateMetaData()

ilObjFile::doCreateMetaData ( )
protected

create file object meta data

Definition at line 209 of file class.ilObjFile.php.

References $format, getFileSize(), getFileType(), ilObject2\getId(), and ilObject2\getType().

210  {
211  // add technical section with file size and format
212  $md_obj = new ilMD($this->getId(), 0, $this->getType());
213  $technical = $md_obj->addTechnical();
214  $technical->setSize($this->getFileSize());
215  $technical->save();
216  $format = $technical->addFormat();
217  $format->setFormat($this->getFileType());
218  $format->save();
219  $technical->update();
220  }
$format
Definition: metadata.php:141
+ Here is the call graph for this function:

◆ doDelete()

ilObjFile::doDelete ( )
protected

Definition at line 1015 of file class.ilObjFile.php.

References $DIC, $ilDB, ilHistory\_removeEntriesForObject(), ilUtil\delDir(), ilObject2\deleteMetaData(), deletePreview(), getDirectory(), ilObject2\getId(), and getMode().

1016  {
1017  global $DIC;
1018  $ilDB = $DIC['ilDB'];
1019 
1020  // delete file data entry
1021  $q = "DELETE FROM file_data WHERE file_id = " . $ilDB->quote($this->getId(), 'integer');
1022  $this->ilias->db->query($q);
1023 
1024  // delete history entries
1025  require_once("./Services/History/classes/class.ilHistory.php");
1027 
1028  self::handleQuotaUpdate($this);
1029 
1030  // delete entire directory and its content
1031  if (@is_dir($this->getDirectory())) {
1032  ilUtil::delDir($this->getDirectory());
1033  }
1034 
1035  // delete meta data
1036  if ($this->getMode() != self::MODE_FILELIST) {
1037  $this->deleteMetaData();
1038  }
1039 
1040  // delete preview
1041  $this->deletePreview();
1042  }
global $DIC
Definition: saml.php:7
getMode()
mode is object or filelist
getDirectory($a_version=0)
deletePreview()
Deletes the preview of the file object.
redirection script todo: (a better solution should control the processing via a xml file) ...
global $ilDB
static _removeEntriesForObject($a_obj_id)
remove all history entries for an object
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:

◆ doMDUpdateListener()

ilObjFile::doMDUpdateListener (   $a_element)
protected

Definition at line 240 of file class.ilObjFile.php.

References ilObject\$id, _writeFileType(), ilObject2\getId(), ilObject2\getType(), and setFileType().

241  {
242  // handling for technical section
243  include_once 'Services/MetaData/classes/class.ilMD.php';
244 
245  switch ($a_element) {
246  case 'Technical':
247 
248  // Update Format (size is not stored in db)
249  $md = new ilMD($this->getId(), 0, $this->getType());
250  if (!is_object($md_technical = $md->getTechnical())) {
251  return false;
252  }
253 
254  foreach ($md_technical->getFormatIds() as $id) {
255  $md_format = $md_technical->getFormat($id);
256  ilObjFile::_writeFileType($this->getId(), $md_format->getFormat());
257  $this->setFileType($md_format->getFormat());
258  break;
259  }
260 
261  break;
262  }
263 
264  return true;
265  }
static _writeFileType($a_id, $a_format)
setFileType($a_type)
+ Here is the call graph for this function:

◆ doRead()

ilObjFile::doRead ( )
protected

Definition at line 506 of file class.ilObjFile.php.

References $DIC, $r, $row, ilObject2\getId(), initFileStorage(), setFileName(), setFileSize(), setFileType(), setMaxVersion(), setMode(), setPageCount(), setRating(), and setVersion().

507  {
508  global $DIC;
509 
510  $q = "SELECT * FROM file_data WHERE file_id = %s";
511  $r = $DIC->database()->queryF($q, ['integer'], [$this->getId()]);
512  $row = $r->fetchObject();
513 
514  $this->setFileName($row->file_name);
515  $this->setFileType($row->file_type);
516  $this->setFileSize($row->file_size);
517  $this->setVersion($row->version ? $row->version : 1);
518  $this->setMaxVersion($row->max_version ? $row->max_version : 1);
519  $this->setMode($row->f_mode);
520  $this->setRating($row->rating);
521  $this->setPageCount($row->page_count);
522 
523  $this->initFileStorage();
524  }
setFileType($a_type)
setFileName($a_name)
setMode($a_mode)
mode is object or filelist
global $DIC
Definition: saml.php:7
setVersion($a_version)
setFileSize($a_size)
$r
Definition: example_031.php:79
$row
setMaxVersion($a_max_version)
initFileStorage()
init file storage object
setPageCount($page_count)
setRating($a_value)
+ Here is the call graph for this function:

◆ doUpdate()

ilObjFile::doUpdate ( )
protected

Definition at line 538 of file class.ilObjFile.php.

References $DIC, getArrayForDatabase(), ilObject2\getId(), and getVersion().

Referenced by raiseUploadError().

539  {
540  global $DIC;
541 
542  $a_columns = $this->getArrayForDatabase();
543  $DIC->database()->update('file_data', $a_columns, [
544  'file_id' => [
545  'integer',
546  $this->getId(),
547  ],
548  ]);
549 
550  // update metadata with the current file version
551  $meta_version_column = ['meta_version' => ['integer', (int) $this->getVersion()]];
552  $DIC->database()->update('il_meta_lifecycle', $meta_version_column, [
553  'obj_id' => [
554  'integer',
555  $this->getId(),
556  ],
557  ]);
558 
559  self::handleQuotaUpdate($this);
560 
561  return true;
562  }
global $DIC
Definition: saml.php:7
getArrayForDatabase($file_id=0)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ doUpdateMetaData()

ilObjFile::doUpdateMetaData ( )
protected

update meta data

Definition at line 568 of file class.ilObjFile.php.

References $format, getFileSize(), getFileType(), ilObject2\getId(), and ilObject2\getType().

569  {
570  // add technical section with file size and format
571  $md_obj = new ilMD($this->getId(), 0, $this->getType());
572  if (!is_object($technical = $md_obj->getTechnical())) {
573  $technical = $md_obj->addTechnical();
574  $technical->save();
575  }
576  $technical->setSize($this->getFileSize());
577 
578  $format_ids = $technical->getFormatIds();
579  if (count($format_ids) > 0) {
580  $format = $technical->getFormat($format_ids[0]);
581  $format->setFormat($this->getFileType());
582  $format->update();
583  } else {
584  $format = $technical->addFormat();
585  $format->setFormat($this->getFileType());
586  $format->save();
587  }
588  $technical->update();
589  }
$format
Definition: metadata.php:141
+ Here is the call graph for this function:

◆ export()

ilObjFile::export (   $a_target_dir)

export files of object to target directory note: target directory must be the export target directory, "/objects/il_<inst>_file_<file_id>/..." will be appended to this directory

Parameters
string$a_target_dirtarget directory

Definition at line 1052 of file class.ilObjFile.php.

References getDirectory(), ilObject2\getId(), getVersion(), ilUtil\makeDir(), and ilUtil\rCopy().

1053  {
1054  $subdir = "il_" . IL_INST_ID . "_file_" . $this->getId();
1055  ilUtil::makeDir($a_target_dir . "/objects/" . $subdir);
1056 
1057  $filedir = $this->getDirectory($this->getVersion());
1058 
1059  if (@!is_dir($filedir)) {
1060  $filedir = $this->getDirectory();
1061  }
1062 
1063  ilUtil::rCopy($filedir, $a_target_dir . "/objects/" . $subdir);
1064  }
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
getDirectory($a_version=0)
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
+ Here is the call graph for this function:

◆ getAction()

ilObjFile::getAction ( )

Definition at line 649 of file class.ilObjFile.php.

References $action.

650  {
651  return $this->action;
652  }

◆ getArrayForDatabase()

ilObjFile::getArrayForDatabase (   $file_id = 0)
private
Parameters
int$file_id(part of bugfix mantis 26131)
Returns
array

Definition at line 1649 of file class.ilObjFile.php.

References getFileName(), getFileSize(), getFileType(), ilObject2\getId(), getMaxVersion(), getMode(), getPageCount(), getVersion(), and hasRating().

Referenced by createProperties(), doCloneObject(), and doUpdate().

1650  {
1651  if ($file_id == 0) {
1652  $file_id = $this->getId();
1653  }
1654  return [
1655  'file_id' => ['integer', $file_id],
1656  'file_name' => ['text', $this->getFileName()],
1657  'file_type' => ['text', $this->getFileType()],
1658  'file_size' => ['integer', (int) $this->getFileSize()],
1659  'version' => ['integer', (int) $this->getVersion()],
1660  'max_version' => ['integer', (int) $this->getMaxVersion()],
1661  'f_mode' => ['text', $this->getMode()],
1662  'page_count' => ['text', $this->getPageCount()],
1663  'rating' => ['integer', $this->hasRating()],
1664  ];
1665  }
getMode()
mode is object or filelist
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDirectory()

ilObjFile::getDirectory (   $a_version = 0)
Parameters
int$a_version
Returns
string

Definition at line 273 of file class.ilObjFile.php.

References initFileStorage().

Referenced by clearDataDirectory(), copy(), createDirectory(), deleteVersions(), determineFileSize(), doCloneObject(), doDelete(), export(), getFile(), getXMLZip(), raiseUploadError(), rollback(), and storeUnzipedFile().

274  {
275  $version_subdir = "";
276 
277  if ($a_version) {
278  // BEGIN WebDAV Avoid double slash before version subdirectory
279  $version_subdir = sprintf("%03d", $a_version);
280  // END WebDAV Avoid double slash before version subdirectory
281  }
282 
283  if (!is_object($this->file_storage)) {
284  $this->initFileStorage();
285  }
286 
287  $str = $this->file_storage->getAbsolutePath() . '/' . $version_subdir;
288 
289  return $str;
290  }
initFileStorage()
init file storage object
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDiskUsage()

ilObjFile::getDiskUsage ( )

Gets the disk usage of the object in bytes.

public

Returns
integer the disk usage in bytes

Definition at line 685 of file class.ilObjFile.php.

References ilObjFileAccess\_lookupDiskUsage().

Referenced by handleQuotaUpdate().

686  {
687  require_once("./Modules/File/classes/class.ilObjFileAccess.php");
688 
689  return ilObjFileAccess::_lookupDiskUsage($this->id);
690  }
static _lookupDiskUsage($a_id)
Returns the number of bytes used on the harddisk by the file object with the specified object id...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFile()

ilObjFile::getFile (   $a_hist_entry_id = null)

Definition at line 694 of file class.ilObjFile.php.

References $data, ilHistory\_getEntryByHistoryID(), getDirectory(), getFileName(), getVersion(), and parseInfoParams().

695  {
696  if (is_null($a_hist_entry_id)) {
697  $file = $this->getDirectory($this->getVersion()) . "/" . $this->getFileName();
698  } else {
699  require_once("./Services/History/classes/class.ilHistory.php");
700  $entry = ilHistory::_getEntryByHistoryID($a_hist_entry_id);
701 
702  if ($entry === false) {
703  return false;
704  }
705 
706  $data = $this->parseInfoParams($entry);
707  $file = $this->getDirectory($data["version"]) . "/" . $data["filename"];
708  }
709 
710  return $file;
711  }
parseInfoParams($entry)
Parses the info parameters ("info_params") of the specified history entry.
getDirectory($a_version=0)
static _getEntryByHistoryID($a_hist_entry_id)
returns a single history entry
$data
Definition: bench.php:6
+ Here is the call graph for this function:

◆ getFileExtension()

ilObjFile::getFileExtension ( )

Returns the extension of the file name converted to lower-case.

e.g. returns 'pdf' for 'document.pdf'.

Definition at line 900 of file class.ilObjFile.php.

References ilObjFileAccess\_getFileExtension(), and ilObject2\getTitle().

Referenced by guessFileType().

901  {
902  require_once 'Modules/File/classes/class.ilObjFileAccess.php';
903 
905  }
static _getFileExtension($a_file_name)
Gets the file extension of the specified file name.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFileName()

ilObjFile::getFileName ( )
Returns
string

Definition at line 604 of file class.ilObjFile.php.

References $filename.

Referenced by beforeMDUpdateListener(), checkFileExtension(), createProperties(), determineFileSize(), getArrayForDatabase(), getFile(), and getXMLZip().

605  {
606  return $this->filename;
607  }
+ Here is the caller graph for this function:

◆ getFileSize()

ilObjFile::getFileSize ( )

Definition at line 637 of file class.ilObjFile.php.

References $filesize.

Referenced by createProperties(), doCreateMetaData(), doUpdateMetaData(), and getArrayForDatabase().

638  {
639  return $this->filesize;
640  }
+ Here is the caller graph for this function:

◆ getFileType()

ilObjFile::getFileType ( )
Returns
string

Definition at line 622 of file class.ilObjFile.php.

References $filetype.

Referenced by createProperties(), doCreateMetaData(), doUpdateMetaData(), getArrayForDatabase(), and guessFileType().

623  {
624  return $this->filetype;
625  }
+ Here is the caller graph for this function:

◆ getMaxVersion()

ilObjFile::getMaxVersion ( )

Definition at line 734 of file class.ilObjFile.php.

References $max_version.

Referenced by addFileVersion(), deleteVersions(), getArrayForDatabase(), raiseUploadError(), replaceFile(), and rollback().

735  {
736  return $this->max_version;
737  }
+ Here is the caller graph for this function:

◆ getMode()

ilObjFile::getMode ( )

mode is object or filelist

Returns
string mode

Definition at line 756 of file class.ilObjFile.php.

References $mode.

Referenced by beforeUpdate(), createPreview(), createProperties(), deletePreview(), doDelete(), and getArrayForDatabase().

757  {
758  return $this->mode;
759  }
+ Here is the caller graph for this function:

◆ getPageCount()

ilObjFile::getPageCount ( )
Returns
int

Definition at line 1629 of file class.ilObjFile.php.

References $page_count.

Referenced by getArrayForDatabase().

1630  {
1631  return $this->page_count;
1632  }
+ Here is the caller graph for this function:

◆ getRollbackUserId()

ilObjFile::getRollbackUserId ( )

Definition at line 673 of file class.ilObjFile.php.

References $rollback_user_id.

674  {
676  }

◆ getRollbackVersion()

ilObjFile::getRollbackVersion ( )

Definition at line 661 of file class.ilObjFile.php.

References $rollback_version.

662  {
664  }

◆ getSpecificVersion()

ilObjFile::getSpecificVersion (   $version_id)

Gets a specific file version.

Parameters
int$version_idThe version id to get.
Returns
array The specific version or false if the version was not found.

Definition at line 1361 of file class.ilObjFile.php.

References PHPMailer\PHPMailer\$params, $version, ilHistory\_getEntryByHistoryID(), and parseInfoParams().

Referenced by rollback().

1362  {
1363  include_once("./Services/History/classes/class.ilHistory.php");
1365  if ($version === false) {
1366  return false;
1367  }
1368 
1369  // ilHistory returns different keys in _getEntryByHistoryID and _getEntriesForObject
1370  // so this makes it the same
1371  $version["hist_entry_id"] = $version["id"];
1372  $version["user_id"] = $version["usr_id"];
1373  $version["date"] = $version["hdate"];
1374  unset($version["id"], $version["usr_id"], $version["hdate"]);
1375 
1376  // parse params
1377  $params = $this->parseInfoParams($version);
1378 
1379  return array_merge($version, $params);
1380  }
parseInfoParams($entry)
Parses the info parameters ("info_params") of the specified history entry.
static _getEntryByHistoryID($a_hist_entry_id)
returns a single history entry
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUsages()

ilObjFile::getUsages ( )

get all usages of file object

Definition at line 1127 of file class.ilObjFile.php.

References $DIC, $ilDB, $ret, and ilObject2\getId().

Referenced by beforeDelete(), and handleQuotaUpdate().

1128  {
1129  global $DIC;
1130  $ilDB = $DIC['ilDB'];
1131 
1132  // get usages in learning modules
1133  $q = "SELECT * FROM file_usage WHERE id = " . $ilDB->quote($this->getId(), "integer");
1134  $us_set = $ilDB->query($q);
1135  $ret = array();
1136  while ($us_rec = $ilDB->fetchAssoc($us_set)) {
1137  $ret[] = array(
1138  "type" => $us_rec["usage_type"],
1139  "id" => $us_rec["usage_id"],
1140  "lang" => $us_rec["usage_lang"],
1141  "hist_nr" => $us_rec["usage_hist_nr"],
1142  );
1143  }
1144 
1145  return $ret;
1146  }
global $DIC
Definition: saml.php:7
global $ilDB
$ret
Definition: parser.php:6
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getVersion()

ilObjFile::getVersion ( )

◆ getVersions()

ilObjFile::getVersions (   $version_ids = null)

Gets the file versions for this object.

Parameters
array$version_idsThe file versions to get. If not specified all versions are returned.
Returns
array The file versions.
          Example:  array (
'date' => '2019-07-25 11:19:51', 'user_id' => '6', 'obj_id' => '287', 'obj_type' => 'file', 'action' => 'create', 'info_params' => 'chicken_outlined.pdf,1,1', 'user_comment' => '', 'hist_entry_id' => '3', 'title' => NULL, )

Definition at line 1329 of file class.ilObjFile.php.

References $index, PHPMailer\PHPMailer\$params, $version, ilHistory\_getEntriesForObject(), ilObject2\getId(), ilObject2\getType(), and parseInfoParams().

Referenced by deleteVersions().

1329  : array
1330  {
1331  $versions = (array) ilHistory::_getEntriesForObject($this->getId(), $this->getType());
1332 
1333  if ($version_ids != null && count($version_ids) > 0) {
1334  foreach ($versions as $index => $version) {
1335  if (!in_array($version["hist_entry_id"], $version_ids, true)) {
1336  unset($versions[$index]);
1337  }
1338  }
1339  }
1340 
1341  // add custom entries
1342  foreach ($versions as $index => $version) {
1343  $params = $this->parseInfoParams($version);
1344  $versions[$index] = array_merge($version, $params);
1345  }
1346 
1347  // sort by version number (hist_entry_id will do for that)
1348  usort($versions, array($this, "compareVersions"));
1349 
1350  return $versions;
1351  }
parseInfoParams($entry)
Parses the info parameters ("info_params") of the specified history entry.
$index
Definition: metadata.php:60
static _getEntriesForObject($a_obj_id, $a_obj_type="")
get all history entries for an object
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getXMLZip()

ilObjFile::getXMLZip ( )

Definition at line 1182 of file class.ilObjFile.php.

References $DIC, ilUtil\escapeShellArg(), getDirectory(), and getFileName().

1183  {
1184  global $DIC;
1185  $ilias = $DIC['ilias'];
1186 
1187  $zip = PATH_TO_ZIP;
1188 
1189  exec($zip . ' ' . ilUtil::escapeShellArg($this->getDirectory() . '/' . $this->getFileName())
1190  . " " . ilUtil::escapeShellArg($this->getDirectory() . '/' . '1.zip'));
1191 
1192  return $this->getDirectory() . '/1.zip';
1193  }
global $DIC
Definition: saml.php:7
getDirectory($a_version=0)
static escapeShellArg($a_arg)
+ Here is the call graph for this function:

◆ guessFileType()

ilObjFile::guessFileType (   $a_file = "")

Guesses the file type based on the current values returned by getFileType() and getFileExtension().

If getFileType() returns 'application/octet-stream', the file extension is used to guess a more accurate file type.

Definition at line 939 of file class.ilObjFile.php.

References $filename, $path, getFileExtension(), getFileType(), and ilMimeTypeUtil\getMimeType().

Referenced by determineFileSize(), and updateWithVersion().

940  {
941  $path = pathinfo($a_file);
942  if ($path["extension"] != "") {
943  $filename = $path["basename"];
944  } else {
945  $filename = "dummy." . $this->getFileExtension();
946  }
947  include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
948  $mime = ilMimeTypeUtil::getMimeType($a_file, $filename, $this->getFileType());
949 
950  return $mime;
951  }
$path
Definition: aliased.php:25
static getMimeType($a_file='', $a_filename='', $a_mime='')
getFileExtension()
Returns the extension of the file name converted to lower-case.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleQuotaUpdate()

static ilObjFile::handleQuotaUpdate ( ilObjFile  $a_file)
staticprotected

Definition at line 1553 of file class.ilObjFile.php.

References getDiskUsage(), ilObject2\getId(), ilObject2\getType(), getUsages(), and ilDiskQuotaHandler\handleUpdatedSourceObject().

Referenced by raiseUploadError().

1554  {
1555  include_once "Services/MediaObjects/classes/class.ilObjMediaObject.php";
1556  $mob = new ilObjMediaObject();
1557 
1558  // file itself could be workspace item
1559  $parent_obj_ids = array($a_file->getId());
1560 
1561  foreach ($a_file->getUsages() as $item) {
1562  $parent_obj_id = $mob->getParentObjectIdForUsage($item);
1563  if ($parent_obj_id
1564  && !in_array($parent_obj_id, $parent_obj_ids)
1565  ) {
1566  $parent_obj_ids[] = $parent_obj_id;
1567  }
1568  }
1569 
1570  include_once "Services/DiskQuota/classes/class.ilDiskQuotaHandler.php";
1571  ilDiskQuotaHandler::handleUpdatedSourceObject($a_file->getType(), $a_file->getId(), $a_file->getDiskUsage(), $parent_obj_ids);
1572  }
Class ilObjMediaObject.
getUsages()
get all usages of file object
static handleUpdatedSourceObject($a_src_obj_type, $a_src_obj_id, $a_src_filesize, $a_owner_obj_ids=null, $a_is_prtf=false)
Find and update/create all related entries for source object.
getDiskUsage()
Gets the disk usage of the object in bytes.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasRating()

ilObjFile::hasRating ( )
Returns
bool

Definition at line 1620 of file class.ilObjFile.php.

References $rating.

Referenced by getArrayForDatabase().

1621  {
1622  return $this->rating;
1623  }
+ Here is the caller graph for this function:

◆ initFileStorage()

ilObjFile::initFileStorage ( )

init file storage object

public

Definition at line 1230 of file class.ilObjFile.php.

References ilObject2\getId().

Referenced by __construct(), createProperties(), doRead(), and getDirectory().

1231  {
1232  $this->file_storage = new ilFSStorageFile($this->getId());
1233 
1234  return true;
1235  }
Class ilFSStorageFile.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initType()

ilObjFile::initType ( )

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

114  {
115  $this->type = "file";
116  }

◆ isHidden()

ilObjFile::isHidden ( )

Returns true, if this file should be hidden in the repository view.

Definition at line 924 of file class.ilObjFile.php.

References ilObjFileAccess\_isFileHidden(), and ilObject2\getTitle().

Referenced by addNewsNotification().

925  {
926  require_once 'Modules/File/classes/class.ilObjFileAccess.php';
927 
928  return ilObjFileAccess::_isFileHidden($this->getTitle());
929  }
static _isFileHidden($a_file_name)
Returns true, if a file with the specified name, is usually hidden from the user. ...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isInline()

ilObjFile::isInline ( )

Returns true, if this file should be displayed inline in a browser window.

This is especially useful for PDF documents, HTML pages, and for images which are directly supported by the browser.

Definition at line 913 of file class.ilObjFile.php.

References ilObjFileAccess\_isFileInline(), and ilObject2\getTitle().

Referenced by determineFileSize().

914  {
915  require_once 'Modules/File/classes/class.ilObjFileAccess.php';
916 
917  return ilObjFileAccess::_isFileInline($this->getTitle());
918  }
static _isFileInline($a_file_name)
Returns true, if the specified file shall be displayed inline in the browser.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseInfoParams()

ilObjFile::parseInfoParams (   $entry)
private

Parses the info parameters ("info_params") of the specified history entry.

Parameters
array$entryThe history entry.
Returns
array Returns an array containing the "filename" and "version" contained within the "info_params".

Definition at line 1500 of file class.ilObjFile.php.

References $data, $n, and $result.

Referenced by determineFileSize(), getFile(), getSpecificVersion(), getVersions(), and raiseUploadError().

1501  {
1502  $data = explode(",", $entry["info_params"]);
1503 
1504  // bugfix: first created file had no version number
1505  // this is a workaround for all files created before the bug was fixed
1506  if (empty($data[1])) {
1507  $data[1] = "1";
1508  }
1509 
1510  if (empty($data[2])) {
1511  $data[2] = "1";
1512  }
1513 
1514 // BEGIN bugfix #27391
1515  if (sizeof($data) > 3)
1516  {
1517  $last = sizeof($data) - 1;
1518  for ($n = 1; $n < $last - 1; $n++)
1519  {
1520  $data[0] .= "," . $data[$n];
1521  }
1522  $data[1] = $data[$last - 1];
1523  $data[2] = $data[$last];
1524  }
1525 // END bugfix #27391
1526 
1527  $result = array(
1528  "filename" => $data[0],
1529  "version" => $data[1],
1530  "max_version" => $data[2],
1531  "rollback_version" => "",
1532  "rollback_user_id" => "",
1533  );
1534 
1535  // if rollback, the version contains the rollback version as well
1536  // bugfix mantis 26236: rollback info is read from version to ensure compatibility with older ilias versions
1537  if ($entry["action"] == "rollback") {
1538  $tokens = explode("|", $result["version"]);
1539  if (count($tokens) > 1) {
1540  $result["version"] = $tokens[0];
1541  $result["rollback_version"] = $tokens[1];
1542 
1543  if (count($tokens) > 2) {
1544  $result["rollback_user_id"] = $tokens[2];
1545  }
1546  }
1547  }
1548 
1549  return $result;
1550  }
$result
$n
Definition: RandomTest.php:85
$data
Definition: bench.php:6
+ Here is the caller graph for this function:

◆ raiseUploadError()

◆ replaceFile()

ilObjFile::replaceFile (   $a_upload_file,
  $a_filename 
)
Parameters
$a_upload_file
$a_filename
Returns
Exceptions

Definition at line 392 of file class.ilObjFile.php.

References $result, ilHistory\_createEntry(), addNewsNotification(), createPreview(), ilObject2\getId(), getMaxVersion(), and getVersion().

393  {
394  if ($result = $this->getUploadFile($a_upload_file, $a_filename, true)) {
395  ilHistory::_createEntry($this->getId(), "replace", $a_filename . "," . $this->getVersion() . "," . $this->getMaxVersion());
396  $this->addNewsNotification("file_updated");
397 
398  // create preview
399  $this->createPreview(true);
400  }
401 
402  return $result;
403  }
$result
static _createEntry( $a_obj_id, $a_action, $a_info_params="", $a_obj_type="", $a_user_comment="", $a_update_last=false)
Creates a new history entry for an object.
createPreview($force=false)
Creates a preview for the file object.
addNewsNotification($a_lang_var)
+ Here is the call graph for this function:

◆ rollback()

ilObjFile::rollback (   $version_id)

Makes the specified version the current one and returns theSummary of rollbackVersion.

Parameters
int$version_idThe id of the version to make the current one.
Returns
array The new actual version.

Definition at line 1390 of file class.ilObjFile.php.

References $DIC, $ilDB, $ilUser, $source, ilHistory\_changeUserId(), ilHistory\_createEntry(), ilHistory\_getEntriesForObject(), addNewsNotification(), copy(), getDirectory(), ilObject2\getId(), getMaxVersion(), getSpecificVersion(), ilUtil\makeDir(), setMaxVersion(), and updateWithVersion().

1391  {
1392  global $DIC;
1393  $ilDB = $DIC['ilDB'];
1394  $ilUser = $DIC['ilUser'];
1395 
1396  $source = $this->getSpecificVersion($version_id);
1397  if ($source === false) {
1398  $this->ilErr->raiseError($this->lng->txt("obj_not_found"), $this->ilErr->MESSAGE);
1399  }
1400 
1401  // get the new version number
1402  $new_version_nr = $this->getMaxVersion() + 1;
1403  $this->setMaxVersion($new_version_nr);
1404 
1405  // copy file
1406  $source_path = $this->getDirectory($source["version"]) . "/" . $source["filename"];
1407  $dest_dir = $this->getDirectory($new_version_nr);
1408  if (@!is_dir($dest_dir)) {
1409  ilUtil::makeDir($dest_dir);
1410  }
1411 
1412  copy($source_path, $dest_dir . "/" . $source["filename"]);
1413 
1414  // create new history entry based on the old one
1415  include_once("./Services/History/classes/class.ilHistory.php");
1416  // bugfix mantis 26236: added rollback info to version instead of max_version to ensure compatibility with older ilias versions
1417  ilHistory::_createEntry($this->getId(), "rollback", $source["filename"] . ","
1418  . $new_version_nr . "|"
1419  . $source["version"] . "|"
1420  . $ilUser->getId() . ","
1421  . $this->getMaxVersion());
1422 
1423  // get id of newest entry
1424  $entries = ilHistory::_getEntriesForObject($this->getId());
1425  $newest_entry_id = 0;
1426  foreach ($entries as $entry) {
1427  if ($entry["action"] == "rollback") {
1428  $newest_entry_id = $entry["hist_entry_id"];
1429  }
1430  }
1431  $new_version = $this->getSpecificVersion($newest_entry_id);
1432  $new_version['version'] = $new_version_nr;
1433  $new_version['max_version'] = $new_version_nr;
1434 
1435  // change user back to the original uploader
1436  ilHistory::_changeUserId($new_version["hist_entry_id"], $source["user_id"]);
1437 
1438  // update this file with the new version
1439  $this->updateWithVersion($new_version);
1440 
1441  $this->addNewsNotification("file_updated");
1442 
1443  return $new_version;
1444  }
static _changeUserId($a_hist_entry_id, $new_user_id)
Changes the user id of the specified history entry.
global $DIC
Definition: saml.php:7
copy($a_source, $a_destination)
copy file
getDirectory($a_version=0)
static _createEntry( $a_obj_id, $a_action, $a_info_params="", $a_obj_type="", $a_user_comment="", $a_update_last=false)
Creates a new history entry for an object.
$ilUser
Definition: imgupload.php:18
getSpecificVersion($version_id)
Gets a specific file version.
static _getEntriesForObject($a_obj_id, $a_obj_type="")
get all history entries for an object
addNewsNotification($a_lang_var)
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
setMaxVersion($a_max_version)
global $ilDB
$source
Definition: linkback.php:22
updateWithVersion($version)
Updates the file object with the specified file version.
+ Here is the call graph for this function:

◆ setAction()

ilObjFile::setAction (   $a_action)

Definition at line 643 of file class.ilObjFile.php.

644  {
645  $this->action = $a_action;
646  }

◆ setFileName()

ilObjFile::setFileName (   $a_name)
Parameters
string$a_name

Definition at line 595 of file class.ilObjFile.php.

Referenced by doRead(), raiseUploadError(), and updateWithVersion().

596  {
597  $this->filename = $a_name;
598  }
+ Here is the caller graph for this function:

◆ setFileSize()

ilObjFile::setFileSize (   $a_size)
Parameters
$a_size

Definition at line 631 of file class.ilObjFile.php.

Referenced by determineFileSize(), and doRead().

632  {
633  $this->filesize = $a_size;
634  }
+ Here is the caller graph for this function:

◆ setFileType()

ilObjFile::setFileType (   $a_type)
Parameters
string$a_type

Definition at line 613 of file class.ilObjFile.php.

References $a_type.

Referenced by doMDUpdateListener(), doRead(), and updateWithVersion().

614  {
615  $this->filetype = $a_type;
616  }
$a_type
Definition: workflow.php:92
+ Here is the caller graph for this function:

◆ setMaxVersion()

ilObjFile::setMaxVersion (   $a_max_version)

Definition at line 728 of file class.ilObjFile.php.

Referenced by doRead(), raiseUploadError(), rollback(), and updateWithVersion().

729  {
730  $this->max_version = $a_max_version;
731  }
+ Here is the caller graph for this function:

◆ setMode()

ilObjFile::setMode (   $a_mode)

mode is object or filelist

Parameters
string$a_modemode

Definition at line 745 of file class.ilObjFile.php.

Referenced by doRead().

746  {
747  $this->mode = $a_mode;
748  }
+ Here is the caller graph for this function:

◆ setNoMetaDataCreation()

ilObjFile::setNoMetaDataCreation (   $a_status)
Parameters
bool$a_status

Definition at line 188 of file class.ilObjFile.php.

189  {
190  $this->no_meta_data_creation = (bool) $a_status;
191  }

◆ setPageCount()

ilObjFile::setPageCount (   $page_count)
Parameters
int$page_count

Definition at line 1638 of file class.ilObjFile.php.

References $page_count.

Referenced by doRead(), and raiseUploadError().

1639  {
1640  $this->page_count = $page_count;
1641  }
+ Here is the caller graph for this function:

◆ setRating()

ilObjFile::setRating (   $a_value)
Parameters
bool$a_value

Definition at line 1611 of file class.ilObjFile.php.

Referenced by doRead().

1612  {
1613  $this->rating = (bool) $a_value;
1614  }
+ Here is the caller graph for this function:

◆ setRollbackUserId()

ilObjFile::setRollbackUserId (   $a_rollback_user_id)

Definition at line 667 of file class.ilObjFile.php.

668  {
669  $this->rollback_user_id = $a_rollback_user_id;
670  }

◆ setRollbackVersion()

ilObjFile::setRollbackVersion (   $a_rollback_version)

Definition at line 655 of file class.ilObjFile.php.

656  {
657  $this->rollback_version = $a_rollback_version;
658  }

◆ setVersion()

ilObjFile::setVersion (   $a_version)

Definition at line 716 of file class.ilObjFile.php.

Referenced by doRead(), raiseUploadError(), storeUnzipedFile(), and updateWithVersion().

717  {
718  $this->version = $a_version;
719  }
+ Here is the caller graph for this function:

◆ storeUnzipedFile()

ilObjFile::storeUnzipedFile (   $a_upload_file,
  $a_filename 
)

storeUnzipedFile

Stores Files unzipped from uploaded archive in filesystem

Parameters
string$a_upload_file
string$a_filename

Definition at line 1247 of file class.ilObjFile.php.

References createPreview(), getDirectory(), ilFileUtils\getValidFilename(), getVersion(), ilUtil\makeDir(), ilFileUtils\rename(), and setVersion().

1248  {
1249  $this->setVersion($this->getVersion() + 1);
1250 
1251  if (@!is_dir($this->getDirectory($this->getVersion()))) {
1252  ilUtil::makeDir($this->getDirectory($this->getVersion()));
1253  }
1254 
1255  $file = $this->getDirectory($this->getVersion()) . "/" . $a_filename;
1256 
1257  $file = ilFileUtils::getValidFilename($file);
1258 
1259  ilFileUtils::rename($a_upload_file, $file);
1260 
1261  // create preview
1262  $this->createPreview();
1263  }
setVersion($a_version)
getDirectory($a_version=0)
static rename($a_source, $a_target)
Rename a file.
createPreview($force=false)
Creates a preview for the file object.
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static getValidFilename($a_filename)
Get valid filename.
+ Here is the call graph for this function:

◆ updateWithVersion()

ilObjFile::updateWithVersion (   $version)
protected

Updates the file object with the specified file version.

Parameters
array$versionThe version to update the file object with.

Definition at line 1452 of file class.ilObjFile.php.

References $version, checkFileExtension(), createPreview(), determineFileSize(), ilObject2\getTitle(), guessFileType(), setFileName(), setFileType(), setMaxVersion(), ilObject2\setTitle(), setVersion(), and ilObject2\update().

Referenced by deleteVersions(), and rollback().

1453  {
1454  // update title (checkFileExtension must be called before setFileName!)
1455  $this->setTitle($this->checkFileExtension($version["filename"], $this->getTitle()));
1456 
1457  $this->setVersion($version["version"]);
1458  $this->setMaxVersion($version["max_version"]);
1459  $this->setFileName($version["filename"]);
1460 
1461  // evaluate mime type (reset file type before)
1462  $this->setFileType("");
1463  $this->setFileType($this->guessFileType($version["filename"]));
1464 
1465  // set filesize
1466  $this->determineFileSize();
1467 
1468  $this->update();
1469 
1470  // refresh preview
1471  $this->createPreview(true);
1472  }
setFileType($a_type)
setFileName($a_name)
setVersion($a_version)
checkFileExtension($new_filename, $new_title)
Check if the file extension does still exist after an update of the title.
setTitle($a_title)
createPreview($force=false)
Creates a preview for the file object.
setMaxVersion($a_max_version)
determineFileSize($a_hist_entry_id=null)
Determine File Size.
guessFileType($a_file="")
Guesses the file type based on the current values returned by getFileType() and getFileExtension().
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $action

ilObjFile::$action = null
protected

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

Referenced by getAction().

◆ $file_storage

ilObjFile::$file_storage = null
private

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

◆ $filemaxsize

ilObjFile::$filemaxsize = "20000000"
protected

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

◆ $filename

ilObjFile::$filename = ''
protected

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

Referenced by getFileName(), and guessFileType().

◆ $filesize

ilObjFile::$filesize
protected

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

Referenced by getFileSize().

◆ $filetype

ilObjFile::$filetype = ''
protected

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

Referenced by getFileType().

◆ $log

ilObjFile::$log = null
protected

Definition at line 68 of file class.ilObjFile.php.

◆ $max_version

ilObjFile::$max_version = 1
protected

Definition at line 76 of file class.ilObjFile.php.

Referenced by getMaxVersion().

◆ $mode

ilObjFile::$mode = self::MODE_OBJECT

Definition at line 52 of file class.ilObjFile.php.

Referenced by getMode().

◆ $no_meta_data_creation

ilObjFile::$no_meta_data_creation
protected

Definition at line 28 of file class.ilObjFile.php.

◆ $page_count

ilObjFile::$page_count = 0
protected

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

Referenced by getPageCount(), and setPageCount().

◆ $raise_upload_error

ilObjFile::$raise_upload_error

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

◆ $rating

ilObjFile::$rating = false
protected

Definition at line 60 of file class.ilObjFile.php.

Referenced by hasRating().

◆ $rollback_user_id

ilObjFile::$rollback_user_id = null
protected

Definition at line 88 of file class.ilObjFile.php.

Referenced by getRollbackUserId().

◆ $rollback_version

ilObjFile::$rollback_version = null
protected

Definition at line 84 of file class.ilObjFile.php.

Referenced by getRollbackVersion().

◆ $version

ilObjFile::$version = 1
protected

◆ MODE_FILELIST

const ilObjFile::MODE_FILELIST = "filelist"

Definition at line 23 of file class.ilObjFile.php.

◆ MODE_OBJECT

const ilObjFile::MODE_OBJECT = "object"

Definition at line 24 of file class.ilObjFile.php.


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