ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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...
 
 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, $a_deleted_by)
 
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, $a_deleted_by)
 
static setDeletedDates ($a_ref_ids, $a_user_id)
 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 ()
 

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 98 of file class.ilObjFile.php.

References ILIAS\GlobalScreen\Provider\__construct(), ilObject\getId(), ilLoggerFactory\getLogger(), and initFileStorage().

99  {
100  $this->version = 0;
101  $this->max_version = 0;
102  $this->raise_upload_error = true;
103 
104  $this->log = ilLoggerFactory::getLogger('file');
105 
106  parent::__construct($a_id, $a_call_by_reference);
107 
108  if ($this->getId()) {
109  $this->initFileStorage();
110  }
111  }
getId()
get object id public
initFileStorage()
init file storage object
__construct(Container $dic, ilPlugin $plugin)
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 1059 of file class.ilObjFile.php.

References $a_type, $DIC, and $ilDB.

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

1060  {
1061  global $DIC;
1062  $ilDB = $DIC['ilDB'];
1063 
1064  $and_hist = ($a_usage_hist_nr !== false) ? " AND usage_hist_nr = "
1065  . $ilDB->quote($a_usage_hist_nr, "integer") : "";
1066 
1067  $file_ids = array();
1068  $set = $ilDB->query("SELECT id FROM file_usage" . " WHERE usage_type = "
1069  . $ilDB->quote($a_type, "text") . " AND usage_id= "
1070  . $ilDB->quote($a_id, "integer") . " AND usage_lang= "
1071  . $ilDB->quote($a_usage_lang, "text") . $and_hist);
1072  while ($row = $ilDB->fetchAssoc($set)) {
1073  $file_ids[] = $row["id"];
1074  }
1075 
1076  $ilDB->manipulate("DELETE FROM file_usage WHERE usage_type = "
1077  . $ilDB->quote($a_type, "text") . " AND usage_id = "
1078  . $ilDB->quote((int) $a_id, "integer") . " AND usage_lang= "
1079  . $ilDB->quote($a_usage_lang, "text") . " AND usage_hist_nr = "
1080  . $ilDB->quote((int) $a_usage_hist_nr, "integer"));
1081 
1082  foreach ($file_ids as $file_id) {
1083  self::handleQuotaUpdate(new self($file_id, false));
1084  }
1085  }
$a_type
Definition: workflow.php:92
global $ilDB
$DIC
Definition: xapitoken.php:46
+ 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 1146 of file class.ilObjFile.php.

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

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

1147  {
1148  global $DIC;
1149  $ilDB = $DIC['ilDB'];
1150 
1151  $lstr = "";
1152  if ($a_usage_lang != "") {
1153  $lstr = "usage_lang = " . $ilDB->quote((string) $a_usage_lang, "text") . " AND ";
1154  }
1155 
1156  // get usages in learning modules
1157  $q = "SELECT * FROM file_usage WHERE " . "usage_id = " . $ilDB->quote((int) $a_id, "integer")
1158  . " AND " . "usage_type = " . $ilDB->quote((string) $a_type, "text") . " AND " . $lstr
1159  . "usage_hist_nr = " . $ilDB->quote((int) $a_usage_hist_nr, "integer");
1160  $file_set = $ilDB->query($q);
1161  $ret = array();
1162  while ($file_rec = $ilDB->fetchAssoc($file_set)) {
1163  $ret[$file_rec["id"]] = $file_rec["id"];
1164  }
1165 
1166  return $ret;
1167  }
$a_type
Definition: workflow.php:92
global $ilDB
$ret
Definition: parser.php:6
$DIC
Definition: xapitoken.php:46
+ 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 1262 of file class.ilObjFile.php.

1263  {
1264  $file_object = new self($obj_id, false);
1265  $s = new FilePathSanitizer($file_object);
1266  $s->sanitizeIfNeeded();
1267 
1268  return $file_object->getFile($a_version);
1269  }

◆ _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 762 of file class.ilObjFile.php.

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

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

763  {
764  global $DIC;
765  $ilDB = $DIC['ilDB'];
766 
767  $q = "SELECT * FROM file_data WHERE file_id = " . $ilDB->quote($a_id, 'integer');
768  $r = $ilDB->query($q);
769  $row = $r->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
770 
771  $strip_slashes = ilUtil::stripSlashes($row->file_name);
772 
773  return $strip_slashes;
774  }
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
global $ilDB
$DIC
Definition: xapitoken.php:46
+ 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 778 of file class.ilObjFile.php.

References ilObjFileAccess\_lookupFileSize().

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

779  {
780  require_once("./Modules/File/classes/class.ilObjFileAccess.php");
781 
782  return ilObjFileAccess::_lookupFileSize($a_id);
783  }
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 789 of file class.ilObjFile.php.

References ilObjFileAccess\_lookupVersion().

790  {
791  require_once("./Modules/File/classes/class.ilObjFileAccess.php");
792 
793  return ilObjFileAccess::_lookupVersion($a_id);
794  }
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 1091 of file class.ilObjFile.php.

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

Referenced by ilPCFileList\saveFileUsage().

1092  {
1093  global $DIC;
1094  $ilDB = $DIC['ilDB'];
1095 
1096  // check if file really exists
1097  if (ilObject::_lookupType($a_file_id) != "file") {
1098  return;
1099  }
1100  // #15143
1101  $ilDB->replace("file_usage", array(
1102  "id" => array("integer", (int) $a_file_id),
1103  "usage_type" => array("text", (string) $a_type),
1104  "usage_id" => array("integer", (int) $a_id),
1105  "usage_hist_nr" => array("integer", (int) $a_usage_hist_nr),
1106  "usage_lang" => array("text", $a_usage_lang),
1107  ), array());
1108 
1109  self::handleQuotaUpdate(new self($a_file_id, false));
1110  }
$a_type
Definition: workflow.php:92
static _lookupType($a_id, $a_reference=false)
lookup object type
global $ilDB
$DIC
Definition: xapitoken.php:46
+ 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 745 of file class.ilObjFile.php.

References $DIC, $ilDB, and $res.

Referenced by doMDUpdateListener().

746  {
747  global $DIC;
748  $ilDB = $DIC['ilDB'];
749 
750  $q = "UPDATE file_data SET " . " file_type = " . $ilDB->quote($a_format, 'text')
751  . " WHERE file_id = " . $ilDB->quote($a_id, 'integer');
752  $res = $ilDB->manipulate($q);
753  }
foreach($_POST as $key=> $value) $res
global $ilDB
$DIC
Definition: xapitoken.php:46
+ 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 397 of file class.ilObjFile.php.

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

398  {
399  if ($result = $this->getUploadFile($a_upload_file, $a_filename, true)) {
400  ilHistory::_createEntry($this->getId(), "new_version", $result->getName() . "," . $this->getVersion() . "," . $this->getMaxVersion());
401  $this->addNewsNotification("file_updated");
402 
403  // create preview
404  $this->createPreview($this->getVersion() > 1);
405  }
406 
407  return $result;
408  }
$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.
getId()
get object id public
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 1185 of file class.ilObjFile.php.

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

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

1186  {
1187  // BEGIN WebDAV Suppress news notification for hidden files
1188  if ($this->isHidden()) {
1189  return;
1190  }
1191  // END WebDAV Suppress news notification for hidden files
1192 
1193  global $DIC;
1194  $ilUser = $DIC['ilUser'];
1195 
1196  // Add Notification to news
1197  include_once("./Services/News/classes/class.ilNewsItem.php");
1198  include_once("./Modules/File/classes/class.ilObjFileAccess.php");
1199  $news_item = new ilNewsItem();
1200  $news_item->setContext($this->getId(), $this->getType());
1201  $news_item->setPriority(NEWS_NOTICE);
1202  $news_item->setTitle($a_lang_var);
1203  $news_item->setContentIsLangVar(true);
1204  if ($this->getDescription() != "") {
1205  $news_item->setContent("<p>" . $this->getDescription() . "</p>");
1206  }
1207  $news_item->setUserId($ilUser->getId());
1208  $news_item->setVisibility(NEWS_USERS);
1209  $news_item->create();
1210  }
getId()
get object id public
const NEWS_NOTICE
$ilUser
Definition: imgupload.php:18
isHidden()
Returns true, if this file should be hidden in the repository view.
$DIC
Definition: xapitoken.php:46
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 195 of file class.ilObjFile.php.

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

◆ beforeDelete()

ilObjFile::beforeDelete ( )
protected

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

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

990  {
991  global $DIC;
992  $ilDB = $DIC['ilDB'];
993 
994  // check, if file is used somewhere
995  $usages = $this->getUsages();
996  if (count($usages) == 0) {
997  return true;
998  }
999 
1000  return false;
1001  }
getUsages()
get all usages of file object
global $ilDB
$DIC
Definition: xapitoken.php:46
+ Here is the call graph for this function:

◆ beforeMDUpdateListener()

ilObjFile::beforeMDUpdateListener (   $a_element)
protected

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

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

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

◆ beforeUpdate()

ilObjFile::beforeUpdate ( )
protected

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

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

511  {
512  // no meta data handling for file list files
513  if ($this->getMode() != self::MODE_FILELIST) {
514  $this->updateMetaData();
515  }
516 
517  return true;
518  }
getMode()
mode is object or filelist
+ Here is the call graph for this function:

◆ beforeUpdateMetaData()

ilObjFile::beforeUpdateMetaData ( )
protected

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

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

◆ 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 1277 of file class.ilObjFile.php.

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

Referenced by beforeMDUpdateListener(), and updateWithVersion().

1278  {
1279  include_once './Modules/File/classes/class.ilObjFileAccess.php';
1280  $fileExtension = ilObjFileAccess::_getFileExtension($new_filename);
1281  $titleExtension = ilObjFileAccess::_getFileExtension($new_title);
1282  if ($titleExtension != $fileExtension && strlen($fileExtension) > 0) {
1283  // remove old extension
1284  $pi = pathinfo($this->getFileName());
1285  $suffix = $pi["extension"];
1286  if ($suffix != "") {
1287  if (substr($new_title, strlen($new_title) - strlen($suffix) - 1) == "." . $suffix) {
1288  $new_title = substr($new_title, 0, strlen($new_title) - strlen($suffix) - 1);
1289  }
1290  }
1291  $new_title .= '.' . $fileExtension;
1292  }
1293 
1294  return $new_title;
1295  }
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 423 of file class.ilObjFile.php.

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

Referenced by deleteVersions().

424  {
425  ilUtil::delDir($this->getDirectory());
426  $this->createDirectory();
427  }
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 1473 of file class.ilObjFile.php.

1474  {
1475  // v2 - v1 because version should be descending
1476  return (int) $v2["version"] - (int) $v1["version"];
1477  }

◆ copy()

ilObjFile::copy (   $a_source,
  $a_destination 
)

copy file

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

References getDirectory().

Referenced by rollback().

415  {
416  return copy($a_source, $this->getDirectory() . "/" . $a_destination);
417  }
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 294 of file class.ilObjFile.php.

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

Referenced by clearDataDirectory().

295  {
297  }
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 1555 of file class.ilObjFile.php.

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

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

1556  {
1557  // only normal files are supported
1558  if ($this->getMode() != self::MODE_OBJECT) {
1559  return;
1560  }
1561 
1562  require_once("./Services/Preview/classes/class.ilPreview.php");
1563  ilPreview::createPreview($this, $force);
1564  }
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 138 of file class.ilObjFile.php.

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

Referenced by doCreate().

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

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

Referenced by doDelete().

1571  {
1572  // only normal files are supported
1573  if ($this->getMode() != self::MODE_OBJECT) {
1574  return;
1575  }
1576 
1577  require_once("./Services/Preview/classes/class.ilPreview.php");
1578  ilPreview::deletePreview($this->getId());
1579  }
getMode()
mode is object or filelist
getId()
get object id public
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 435 of file class.ilObjFile.php.

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

436  {
437  if ($a_hist_entry_ids == null || count($a_hist_entry_ids) < 1) {
438  $this->clearDataDirectory();
439 
441 
442  self::handleQuotaUpdate($this);
443  } else {
444  $actualVersionDeleted = false;
445 
446  // get all versions
447  $versions = $this->getVersions();
448 
449  // delete each version
450  foreach ($a_hist_entry_ids as $hist_id) {
451  $entry = null;
452 
453  // get version
454  foreach ($versions as $index => $version) {
455  if ($version["hist_entry_id"] == $hist_id) {
456  // remove each history entry
458 
459  // delete directory
460  $version_dir = $this->getDirectory($version["version"]);
461  ilUtil::delDir($version_dir);
462 
463  // is actual version?
464  if ($version["version"] == $this->getVersion()) {
465  $actualVersionDeleted = true;
466  }
467 
468  // remove from array
469  unset($versions[$index]);
470  break;
471  }
472  }
473  }
474 
475  // update actual version if it was deleted before
476  if ($actualVersionDeleted) {
477  // get newest version (already sorted by getVersions)
478  $version = reset($versions);
479  $version['max_version'] = $this->getMaxVersion();
480  $this->updateWithVersion($version);
481  } else {
482  // updateWithVersion() will trigger quota, too
483  self::handleQuotaUpdate($this);
484  }
485  }
486  }
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:128
getId()
get object id public
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 800 of file class.ilObjFile.php.

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

Referenced by updateWithVersion().

801  {
802  if (is_null($a_hist_entry_id)) {
803  $file = $this->getDirectory($this->getVersion()) . "/" . $this->getFileName();
804  } else {
805  require_once("./Services/History/classes/class.ilHistory.php");
806  $entry = ilHistory::_getEntryByHistoryID($a_hist_entry_id);
807 
808  if ($entry === false) {
809  return false;
810  }
811 
812  $data = $this->parseInfoParams($entry);
813  $file = $this->getDirectory($data["version"]) . "/" . $data["filename"];
814  }
815  if (is_file($file)) {
816  $this->setFileSize(filesize($file));
817  }
818  }
parseInfoParams($entry)
Parses the info parameters ("info_params") of the specified history entry.
$data
Definition: storeScorm.php:23
getDirectory($a_version=0)
setFileSize($a_size)
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:

◆ 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 946 of file class.ilObjFile.php.

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

947  {
948  global $DIC;
949  $ilDB = $DIC['ilDB'];
950 
951  $a_new_obj->createDirectory();
952  $this->cloneMetaData($a_new_obj);
953 
954  // Copy all file versions
955  ilUtil::rCopy($this->getDirectory(), $a_new_obj->getDirectory());
956 
957  // object created now copy other settings
958  $query = "INSERT INTO file_data (file_id,file_name,file_type,file_size,version,rating,f_mode) VALUES ("
959  . $ilDB->quote($a_new_obj->getId(), 'integer') . ","
960  . $ilDB->quote($this->getFileName(), 'text') . ","
961  . $ilDB->quote($this->getFileType(), 'text') . ","
962  . $ilDB->quote((int) $this->getFileSize(), 'integer') . ", "
963  . $ilDB->quote($this->getVersion(), 'integer') . ", "
964  . $ilDB->quote($this->hasRating(), 'integer') . ", "
965  . $ilDB->quote($this->getMode(), 'text') . ")";
966  $res = $ilDB->manipulate($query);
967 
968  // copy all previews
969  require_once("./Services/Preview/classes/class.ilPreview.php");
970  ilPreview::copyPreviews($this->getId(), $a_new_obj->getId());
971 
972  // copy history entries
973  require_once("./Services/History/classes/class.ilHistory.php");
974  ilHistory::_copyEntriesForObject($this->getId(), $a_new_obj->getId());
975 
976  // Copy learning progress settings
977  include_once('Services/Tracking/classes/class.ilLPObjSettings.php');
978  $obj_settings = new ilLPObjSettings($this->getId());
979  $obj_settings->cloneSettings($a_new_obj->getId());
980  unset($obj_settings);
981 
982  // add news notification
983  $a_new_obj->addNewsNotification("file_created");
984 
985  return $a_new_obj;
986  }
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 _copyEntriesForObject($a_src_id, $a_dst_id)
copy all history entries for an object
foreach($_POST as $key=> $value) $res
getId()
get object id public
$query
static copyPreviews($a_src_id, $a_dest_id)
Copies the preview images from one preview to a new preview object.
global $ilDB
$DIC
Definition: xapitoken.php:46
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 125 of file class.ilObjFile.php.

References createProperties().

126  {
127  $this->createProperties($a_upload);
128  }
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 210 of file class.ilObjFile.php.

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

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

◆ doDelete()

ilObjFile::doDelete ( )
protected

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

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

1005  {
1006  global $DIC;
1007  $ilDB = $DIC['ilDB'];
1008 
1009  // delete file data entry
1010  $q = "DELETE FROM file_data WHERE file_id = " . $ilDB->quote($this->getId(), 'integer');
1011  $this->ilias->db->query($q);
1012 
1013  // delete history entries
1014  require_once("./Services/History/classes/class.ilHistory.php");
1016 
1017  self::handleQuotaUpdate($this);
1018 
1019  // delete entire directory and its content
1020  if (@is_dir($this->getDirectory())) {
1021  ilUtil::delDir($this->getDirectory());
1022  }
1023 
1024  // delete meta data
1025  if ($this->getMode() != self::MODE_FILELIST) {
1026  $this->deleteMetaData();
1027  }
1028 
1029  // delete preview
1030  $this->deletePreview();
1031  }
getMode()
mode is object or filelist
getDirectory($a_version=0)
getId()
get object id public
deletePreview()
Deletes the preview of the file object.
redirection script todo: (a better solution should control the processing via a xml file) ...
global $ilDB
$DIC
Definition: xapitoken.php:46
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 241 of file class.ilObjFile.php.

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

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

◆ doRead()

ilObjFile::doRead ( )
protected

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

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

490  {
491  global $DIC;
492 
493  $q = "SELECT * FROM file_data WHERE file_id = %s";
494  $r = $DIC->database()->queryF($q, ['integer'], [$this->getId()]);
495  $row = $r->fetchObject();
496 
497  $this->setFileName($this->secure($row->file_name));
498  $this->setFileType($row->file_type);
499  $this->setFileSize($row->file_size);
500  $this->setVersion($row->version ? $row->version : 1);
501  $this->setMaxVersion($row->max_version ? $row->max_version : 1);
502  $this->setMode($row->f_mode);
503  $this->setRating($row->rating);
504  $this->setPageCount($row->page_count);
505 
506  $this->initFileStorage();
507  }
setFileType($a_type)
setFileName($a_name)
setMode($a_mode)
mode is object or filelist
setVersion($a_version)
setFileSize($a_size)
getId()
get object id public
setMaxVersion($a_max_version)
initFileStorage()
init file storage object
setPageCount($page_count)
$DIC
Definition: xapitoken.php:46
setRating($a_value)
+ Here is the call graph for this function:

◆ doUpdate()

ilObjFile::doUpdate ( )
protected

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

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

Referenced by raiseUploadError().

522  {
523  global $DIC;
524 
525  $a_columns = $this->getArrayForDatabase();
526  $DIC->database()->update('file_data', $a_columns, [
527  'file_id' => [
528  'integer',
529  $this->getId(),
530  ],
531  ]);
532 
533  // update metadata with the current file version
534  $meta_version_column = ['meta_version' => ['integer', (int) $this->getVersion()]];
535  $DIC->database()->update('il_meta_lifecycle', $meta_version_column, [
536  'rbac_id' => [
537  'integer',
538  $this->getId(),
539  ],
540  ]);
541 
542  self::handleQuotaUpdate($this);
543 
544  return true;
545  }
getId()
get object id public
$DIC
Definition: xapitoken.php:46
+ 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 551 of file class.ilObjFile.php.

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

552  {
553  // add technical section with file size and format
554  $md_obj = new ilMD($this->getId(), 0, $this->getType());
555  if (!is_object($technical = $md_obj->getTechnical())) {
556  $technical = $md_obj->addTechnical();
557  $technical->save();
558  }
559  $technical->setSize($this->getFileSize());
560 
561  $format_ids = $technical->getFormatIds();
562  if (count($format_ids) > 0) {
563  $format = $technical->getFormat($format_ids[0]);
564  $format->setFormat($this->getFileType());
565  $format->update();
566  } else {
567  $format = $technical->addFormat();
568  $format->setFormat($this->getFileType());
569  $format->save();
570  }
571  $technical->update();
572  }
getId()
get object id public
$format
Definition: metadata.php:218
+ 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 1041 of file class.ilObjFile.php.

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

1042  {
1043  $subdir = "il_" . IL_INST_ID . "_file_" . $this->getId();
1044  ilUtil::makeDir($a_target_dir . "/objects/" . $subdir);
1045 
1046  $filedir = $this->getDirectory($this->getVersion());
1047 
1048  if (@!is_dir($filedir)) {
1049  $filedir = $this->getDirectory();
1050  }
1051 
1052  ilUtil::rCopy($filedir, $a_target_dir . "/objects/" . $subdir);
1053  }
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)
getId()
get object id public
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 632 of file class.ilObjFile.php.

References $action.

633  {
634  return $this->action;
635  }

◆ getArrayForDatabase()

ilObjFile::getArrayForDatabase ( )
private
Returns
array

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

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

Referenced by createProperties(), and doUpdate().

1622  {
1623  return [
1624  'file_id' => ['integer', $this->getId()],
1625  'file_name' => ['text', $this->getFileName()],
1626  'file_type' => ['text', $this->getFileType()],
1627  'file_size' => ['integer', (int) $this->getFileSize()],
1628  'version' => ['integer', (int) $this->getVersion()],
1629  'max_version' => ['integer', (int) $this->getMaxVersion()],
1630  'f_mode' => ['text', $this->getMode()],
1631  'page_count' => ['text', $this->getPageCount()],
1632  'rating' => ['integer', $this->hasRating()],
1633  ];
1634  }
getMode()
mode is object or filelist
getId()
get object id public
+ 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 274 of file class.ilObjFile.php.

References initFileStorage().

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

275  {
276  $version_subdir = "";
277 
278  if ($a_version) {
279  // BEGIN WebDAV Avoid double slash before version subdirectory
280  $version_subdir = sprintf("%03d", $a_version);
281  // END WebDAV Avoid double slash before version subdirectory
282  }
283 
284  if (!is_object($this->file_storage)) {
285  $this->initFileStorage();
286  }
287 
288  $str = $this->file_storage->getAbsolutePath() . '/' . $version_subdir;
289 
290  return $str;
291  }
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 668 of file class.ilObjFile.php.

References ilObjFileAccess\_lookupDiskUsage().

Referenced by handleQuotaUpdate().

669  {
670  require_once("./Modules/File/classes/class.ilObjFileAccess.php");
671 
672  return ilObjFileAccess::_lookupDiskUsage($this->id);
673  }
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 677 of file class.ilObjFile.php.

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

678  {
679  if (is_null($a_hist_entry_id)) {
680  $file = $this->getDirectory($this->getVersion()) . "/" . $this->getFileName();
681  } else {
682  require_once("./Services/History/classes/class.ilHistory.php");
683  $entry = ilHistory::_getEntryByHistoryID($a_hist_entry_id);
684 
685  if ($entry === false) {
686  return false;
687  }
688 
689  $data = $this->parseInfoParams($entry);
690  $file = $this->getDirectory($data["version"]) . "/" . $data["filename"];
691  }
692 
693  return $file;
694  }
parseInfoParams($entry)
Parses the info parameters ("info_params") of the specified history entry.
$data
Definition: storeScorm.php:23
getDirectory($a_version=0)
static _getEntryByHistoryID($a_hist_entry_id)
returns a single history entry
+ 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 882 of file class.ilObjFile.php.

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

Referenced by guessFileType().

883  {
884  require_once 'Modules/File/classes/class.ilObjFileAccess.php';
885 
887  }
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 587 of file class.ilObjFile.php.

References $filename.

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

588  {
589  return $this->filename;
590  }
+ Here is the caller graph for this function:

◆ getFileSize()

ilObjFile::getFileSize ( )

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

References $filesize.

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

621  {
622  return $this->filesize;
623  }
+ Here is the caller graph for this function:

◆ getFileType()

ilObjFile::getFileType ( )
Returns
string

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

References $filetype.

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

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

◆ getMaxVersion()

ilObjFile::getMaxVersion ( )

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

References $max_version.

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

718  {
719  return $this->max_version;
720  }
+ Here is the caller graph for this function:

◆ getMode()

ilObjFile::getMode ( )

mode is object or filelist

Returns
string mode

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

References $mode.

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

740  {
741  return $this->mode;
742  }
+ Here is the caller graph for this function:

◆ getPageCount()

ilObjFile::getPageCount ( )
Returns
int

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

References $page_count.

Referenced by getArrayForDatabase().

1604  {
1605  return $this->page_count;
1606  }
+ Here is the caller graph for this function:

◆ getRollbackUserId()

ilObjFile::getRollbackUserId ( )

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

References $rollback_user_id.

657  {
659  }

◆ getRollbackVersion()

ilObjFile::getRollbackVersion ( )

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

References $rollback_version.

645  {
647  }

◆ 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 1350 of file class.ilObjFile.php.

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

Referenced by rollback().

1351  {
1352  include_once("./Services/History/classes/class.ilHistory.php");
1354  if ($version === false) {
1355  return false;
1356  }
1357 
1358  // ilHistory returns different keys in _getEntryByHistoryID and _getEntriesForObject
1359  // so this makes it the same
1360  $version["hist_entry_id"] = $version["id"];
1361  $version["user_id"] = $version["usr_id"];
1362  $version["date"] = $version["hdate"];
1363  unset($version["id"], $version["usr_id"], $version["hdate"]);
1364 
1365  // parse params
1366  $params = $this->parseInfoParams($version);
1367 
1368  return array_merge($version, $params);
1369  }
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 1116 of file class.ilObjFile.php.

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

Referenced by beforeDelete(), and handleQuotaUpdate().

1117  {
1118  global $DIC;
1119  $ilDB = $DIC['ilDB'];
1120 
1121  // get usages in learning modules
1122  $q = "SELECT * FROM file_usage WHERE id = " . $ilDB->quote($this->getId(), "integer");
1123  $us_set = $ilDB->query($q);
1124  $ret = array();
1125  while ($us_rec = $ilDB->fetchAssoc($us_set)) {
1126  $ret[] = array(
1127  "type" => $us_rec["usage_type"],
1128  "id" => $us_rec["usage_id"],
1129  "lang" => $us_rec["usage_lang"],
1130  "hist_nr" => $us_rec["usage_hist_nr"],
1131  );
1132  }
1133 
1134  return $ret;
1135  }
getId()
get object id public
global $ilDB
$ret
Definition: parser.php:6
$DIC
Definition: xapitoken.php:46
+ 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 1318 of file class.ilObjFile.php.

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

Referenced by deleteVersions().

1318  : array
1319  {
1320  $versions = (array) ilHistory::_getEntriesForObject($this->getId(), $this->getType());
1321 
1322  if ($version_ids != null && count($version_ids) > 0) {
1323  foreach ($versions as $index => $version) {
1324  if (!in_array($version["hist_entry_id"], $version_ids, true)) {
1325  unset($versions[$index]);
1326  }
1327  }
1328  }
1329 
1330  // add custom entries
1331  foreach ($versions as $index => $version) {
1332  $params = $this->parseInfoParams($version);
1333  $versions[$index] = array_merge($version, $params);
1334  }
1335 
1336  // sort by version number (hist_entry_id will do for that)
1337  usort($versions, array($this, "compareVersions"));
1338 
1339  return $versions;
1340  }
parseInfoParams($entry)
Parses the info parameters ("info_params") of the specified history entry.
$index
Definition: metadata.php:128
getId()
get object id public
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 1171 of file class.ilObjFile.php.

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

1172  {
1173  global $DIC;
1174  $ilias = $DIC['ilias'];
1175 
1176  $zip = PATH_TO_ZIP;
1177 
1178  exec($zip . ' ' . ilUtil::escapeShellArg($this->getDirectory() . '/' . $this->getFileName())
1179  . " " . ilUtil::escapeShellArg($this->getDirectory() . '/' . '1.zip'));
1180 
1181  return $this->getDirectory() . '/1.zip';
1182  }
getDirectory($a_version=0)
static escapeShellArg($a_arg)
$DIC
Definition: xapitoken.php:46
+ 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 921 of file class.ilObjFile.php.

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

Referenced by determineFileSize(), and updateWithVersion().

922  {
923  $path = pathinfo($a_file);
924  if ($path["extension"] != "") {
925  $filename = $path["basename"];
926  } else {
927  $filename = "dummy." . $this->getFileExtension();
928  }
929  include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
930  $mime = ilMimeTypeUtil::getMimeType($a_file, $filename, $this->getFileType());
931 
932  return $mime;
933  }
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 1527 of file class.ilObjFile.php.

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

Referenced by raiseUploadError().

1528  {
1529  include_once "Services/MediaObjects/classes/class.ilObjMediaObject.php";
1530  $mob = new ilObjMediaObject();
1531 
1532  // file itself could be workspace item
1533  $parent_obj_ids = array($a_file->getId());
1534 
1535  foreach ($a_file->getUsages() as $item) {
1536  $parent_obj_id = $mob->getParentObjectIdForUsage($item);
1537  if ($parent_obj_id
1538  && !in_array($parent_obj_id, $parent_obj_ids)
1539  ) {
1540  $parent_obj_ids[] = $parent_obj_id;
1541  }
1542  }
1543 
1544  include_once "Services/DiskQuota/classes/class.ilDiskQuotaHandler.php";
1545  ilDiskQuotaHandler::handleUpdatedSourceObject($a_file->getType(), $a_file->getId(), $a_file->getDiskUsage(), $parent_obj_ids);
1546  }
getId()
get object id public
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 1594 of file class.ilObjFile.php.

References $rating.

Referenced by getArrayForDatabase().

1595  {
1596  return $this->rating;
1597  }
+ Here is the caller graph for this function:

◆ initFileStorage()

ilObjFile::initFileStorage ( )

init file storage object

public

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

References ilObject\getId().

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

1220  {
1221  $this->file_storage = new ilFSStorageFile($this->getId());
1222 
1223  return true;
1224  }
getId()
get object id public
Class ilFSStorageFile.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initType()

ilObjFile::initType ( )

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

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

◆ isHidden()

ilObjFile::isHidden ( )

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

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

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

Referenced by addNewsNotification().

907  {
908  require_once 'Modules/File/classes/class.ilObjFileAccess.php';
909 
910  return ilObjFileAccess::_isFileHidden($this->getTitle());
911  }
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 895 of file class.ilObjFile.php.

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

Referenced by determineFileSize().

896  {
897  require_once 'Modules/File/classes/class.ilObjFileAccess.php';
898 
899  return ilObjFileAccess::_isFileInline($this->getTitle());
900  }
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 1488 of file class.ilObjFile.php.

References $data, and $result.

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

1489  {
1490  $data = explode(",", $entry["info_params"]);
1491 
1492  // bugfix: first created file had no version number
1493  // this is a workaround for all files created before the bug was fixed
1494  if (empty($data[1])) {
1495  $data[1] = "1";
1496  }
1497 
1498  if (empty($data[2])) {
1499  $data[2] = "1";
1500  }
1501 
1502  $result = array(
1503  "filename" => $data[0],
1504  "version" => $data[1],
1505  "max_version" => $data[2],
1506  "rollback_version" => "",
1507  "rollback_user_id" => "",
1508  );
1509 
1510  // if rollback, the version contains the rollback version as well
1511  if ($entry["action"] == "rollback") {
1512  $tokens = explode("|", $result["max_version"]);
1513  if (count($tokens) > 1) {
1514  $result["max_version"] = $tokens[0];
1515  $result["rollback_version"] = $tokens[1];
1516 
1517  if (count($tokens) > 2) {
1518  $result["rollback_user_id"] = $tokens[2];
1519  }
1520  }
1521  }
1522 
1523  return $result;
1524  }
$data
Definition: storeScorm.php:23
$result
+ Here is the caller graph for this function:

◆ raiseUploadError()

ilObjFile::raiseUploadError (   $a_raise = true)

◆ replaceFile()

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

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

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

376  {
377  if ($result = $this->getUploadFile($a_upload_file, $a_filename, true)) {
378  ilHistory::_createEntry($this->getId(), "replace", $a_filename . "," . $this->getVersion() . "," . $this->getMaxVersion());
379  $this->addNewsNotification("file_updated");
380 
381  // create preview
382  $this->createPreview(true);
383  }
384 
385  return $result;
386  }
$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.
getId()
get object id public
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 1379 of file class.ilObjFile.php.

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

1380  {
1381  global $DIC;
1382  $ilDB = $DIC['ilDB'];
1383  $ilUser = $DIC['ilUser'];
1384 
1385  $source = $this->getSpecificVersion($version_id);
1386  if ($source === false) {
1387  $this->ilErr->raiseError($this->lng->txt("obj_not_found"), $this->ilErr->MESSAGE);
1388  }
1389 
1390  // get the new version number
1391  $new_version_nr = $this->getMaxVersion() + 1;
1392  $this->setMaxVersion($new_version_nr);
1393 
1394  // copy file
1395  $source_path = $this->getDirectory($source["version"]) . "/" . $source["filename"];
1396  $dest_dir = $this->getDirectory($new_version_nr);
1397  if (@!is_dir($dest_dir)) {
1398  ilUtil::makeDir($dest_dir);
1399  }
1400 
1401  copy($source_path, $dest_dir . "/" . $source["filename"]);
1402 
1403  // create new history entry based on the old one
1404  include_once("./Services/History/classes/class.ilHistory.php");
1405  ilHistory::_createEntry($this->getId(), "rollback", $source["filename"] . ","
1406  . $new_version_nr . ","
1407  . $this->getMaxVersion() . "|"
1408  . $source["version"] . "|"
1409  . $ilUser->getId());
1410 
1411  // get id of newest entry
1412  $entries = ilHistory::_getEntriesForObject($this->getId());
1413  $newest_entry_id = 0;
1414  foreach ($entries as $entry) {
1415  if ($entry["action"] == "rollback") {
1416  $newest_entry_id = $entry["hist_entry_id"];
1417  }
1418  }
1419  $new_version = $this->getSpecificVersion($newest_entry_id);
1420  $new_version['version'] = $new_version_nr;
1421  $new_version['max_version'] = $new_version_nr;
1422 
1423  // change user back to the original uploader
1424  ilHistory::_changeUserId($new_version["hist_entry_id"], $source["user_id"]);
1425 
1426  // update this file with the new version
1427  $this->updateWithVersion($new_version);
1428 
1429  $this->addNewsNotification("file_updated");
1430 
1431  return $new_version;
1432  }
static _changeUserId($a_hist_entry_id, $new_user_id)
Changes the user id of the specified history entry.
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.
getId()
get object id public
$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
$DIC
Definition: xapitoken.php:46
$source
Definition: metadata.php:76
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 626 of file class.ilObjFile.php.

627  {
628  $this->action = $a_action;
629  }

◆ setFileName()

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

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

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

579  {
580  $this->filename = $a_name;
581  }
+ Here is the caller graph for this function:

◆ setFileSize()

ilObjFile::setFileSize (   $a_size)
Parameters
$a_size

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

Referenced by determineFileSize(), and doRead().

615  {
616  $this->filesize = $a_size;
617  }
+ Here is the caller graph for this function:

◆ setFileType()

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

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

References $a_type.

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

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

◆ setMaxVersion()

ilObjFile::setMaxVersion (   $a_max_version)

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

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

712  {
713  $this->max_version = $a_max_version;
714  }
+ 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 728 of file class.ilObjFile.php.

Referenced by doRead().

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

◆ setNoMetaDataCreation()

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

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

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

◆ setPageCount()

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

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

References $page_count.

Referenced by doRead(), and raiseUploadError().

1613  {
1614  $this->page_count = $page_count;
1615  }
+ Here is the caller graph for this function:

◆ setRating()

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

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

Referenced by doRead().

1586  {
1587  $this->rating = (bool) $a_value;
1588  }
+ Here is the caller graph for this function:

◆ setRollbackUserId()

ilObjFile::setRollbackUserId (   $a_rollback_user_id)

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

651  {
652  $this->rollback_user_id = $a_rollback_user_id;
653  }

◆ setRollbackVersion()

ilObjFile::setRollbackVersion (   $a_rollback_version)

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

639  {
640  $this->rollback_version = $a_rollback_version;
641  }

◆ setVersion()

ilObjFile::setVersion (   $a_version)

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

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

700  {
701  $this->version = $a_version;
702  }
+ 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 1236 of file class.ilObjFile.php.

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

1237  {
1238  $this->setVersion($this->getVersion() + 1);
1239 
1240  if (@!is_dir($this->getDirectory($this->getVersion()))) {
1241  ilUtil::makeDir($this->getDirectory($this->getVersion()));
1242  }
1243 
1244  $file = $this->getDirectory($this->getVersion()) . "/" . $a_filename;
1245 
1246  $file = ilFileUtils::getValidFilename($file);
1247 
1248  ilFileUtils::rename($a_upload_file, $file);
1249 
1250  // create preview
1251  $this->createPreview();
1252  }
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 1440 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().

1441  {
1442  // update title (checkFileExtension must be called before setFileName!)
1443  $this->setTitle($this->checkFileExtension($version["filename"], $this->getTitle()));
1444 
1445  $this->setVersion($version["version"]);
1446  $this->setMaxVersion($version["max_version"]);
1447  $this->setFileName($version["filename"]);
1448 
1449  // evaluate mime type (reset file type before)
1450  $this->setFileType("");
1451  $this->setFileType($this->guessFileType($version["filename"]));
1452 
1453  // set filesize
1454  $this->determineFileSize();
1455 
1456  $this->update();
1457 
1458  // refresh preview
1459  $this->createPreview(true);
1460  }
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 81 of file class.ilObjFile.php.

Referenced by getAction().

◆ $file_storage

ilObjFile::$file_storage = null
private

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

◆ $filemaxsize

ilObjFile::$filemaxsize = "20000000"
protected

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

◆ $filename

ilObjFile::$filename = ''
protected

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

Referenced by getFileName(), and guessFileType().

◆ $filesize

ilObjFile::$filesize
protected

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

Referenced by getFileSize().

◆ $filetype

ilObjFile::$filetype = ''
protected

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

Referenced by getFileType().

◆ $log

ilObjFile::$log = null
protected

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

◆ $max_version

ilObjFile::$max_version = 1
protected

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

Referenced by getMaxVersion().

◆ $mode

ilObjFile::$mode = self::MODE_OBJECT

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

Referenced by getMode().

◆ $no_meta_data_creation

ilObjFile::$no_meta_data_creation
protected

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

◆ $page_count

ilObjFile::$page_count = 0
protected

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

Referenced by getPageCount(), and setPageCount().

◆ $raise_upload_error

ilObjFile::$raise_upload_error

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

◆ $rating

ilObjFile::$rating = false
protected

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

Referenced by hasRating().

◆ $rollback_user_id

ilObjFile::$rollback_user_id = null
protected

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

Referenced by getRollbackUserId().

◆ $rollback_version

ilObjFile::$rollback_version = null
protected

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

Referenced by getRollbackVersion().

◆ $version

ilObjFile::$version = 1
protected

◆ MODE_FILELIST

const ilObjFile::MODE_FILELIST = "filelist"

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

◆ MODE_OBJECT

const ilObjFile::MODE_OBJECT = "object"

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


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