4include_once 
"Services/BackgroundTask/classes/class.ilZipBackgroundTaskHandler.php";
 
   33        parent::__construct();
 
   43        $obj->setTask($a_task);
 
   46        $obj->setRefIds(
$params[
"ref_ids"]);
 
   48        $ref_id = (
sizeof(
$params[
"ref_ids"]) == 1)
 
   69        return (
bool) 
$settings->get(
"bgtask_download", 
false);
 
   89        $this->ref_ids = $a_val;
 
  108        return "il.BgTask.init('" . static::class . 
"', " . $a_ref_id . 
");";
 
  118        if (!self::$initialized) {
 
  123            $url = 
$ilCtrl->getLinkTargetByClass(array(
"ilrepositorygui", 
"ilobjfoldergui", 
"ilbackgroundtaskhub"), 
"", 
"", 
true, 
false);
 
  125            $tpl->addJavaScript(
"Services/BackgroundTask/js/BgTask.js");
 
  126            $tpl->addOnLoadCode(
'il.BgTask.setAjax("' . 
$url . 
'");');
 
  129            include_once 
"Services/UIComponent/Modal/classes/class.ilModalGUI.php";
 
  132            self::$initialized = 
true;
 
  141    public function init($a_params = 
null)
 
  148            $this->
setRefIds(explode(
",", $a_params));
 
  151        $file_count = $total_bytes = 0;
 
  154        include_once 
"Services/BackgroundTask/classes/class.ilBackgroundTaskJson.php";
 
  162            if ($size_limit_mb > 0 && $total_bytes > $size_limit_mb) {
 
  166                include_once 
"Services/BackgroundTask/classes/class.ilBackgroundTask.php";
 
  168                $task->setHandlerId(get_class($this));
 
  170                $task->setParams(array(
 
  173                $task->setSteps($file_count + 1); 
 
  184                    if (
sizeof($existing)) {
 
  219        foreach ($this->
getRefIds() as $ref_id) {
 
  221            if ($this->task->isToBeCancelled()) {
 
  230            switch ($object->getType()) {
 
  232                    $this->
recurseFolder($ref_id, $object->getTitle(), $tmpdir, $current_step);
 
  236                    $this->
copyFile($object->getId(), $object->getTitle(), $tmpdir, $current_step);
 
  241        return $current_step;
 
  261        include_once(
"./Modules/File/classes/class.ilObjFileAccess.php");
 
  264        foreach ($a_ref_ids as $ref_id) {
 
  273                    $subtree = 
$tree->getChildsByTypeFilter($ref_id, array(
"fold", 
"file"));
 
  274                    if (count($subtree) > 0) {
 
  275                        $child_ref_ids = array();
 
  276                        foreach ($subtree as $child) {
 
  277                            $child_ref_ids[] = $child[
"ref_id"];
 
  299    protected function recurseFolder($a_ref_id, $a_title, $a_tmpdir, &$a_current_step)
 
  307        $subtree = 
$tree->getChildsByTypeFilter($a_ref_id, array(
"fold", 
"file"));
 
  308        foreach ($subtree as $child) {
 
  310            if ($this->task->isToBeCancelled()) {
 
  318            switch ($child[
"type"]) {
 
  320                    $this->
recurseFolder($child[
"ref_id"], $child[
"title"], $tmpdir, $a_current_step);
 
  324                    $this->
copyFile($child[
"obj_id"], $child[
"title"], $tmpdir, $a_current_step);
 
  338    protected function copyFile($a_obj_id, $a_title, $a_tmpdir, &$a_current_step)
 
  341        $this->task->setCurrentStep(++$a_current_step);
 
  348        if (file_exists($new_filename)) {
 
  353        include_once 
"Modules/File/classes/class.ilObjFile.php";
 
  355        if (!copy($old_filename, $new_filename)) {
 
  356            throw new ilFileException(
"Could not copy " . $old_filename . 
" to " . $new_filename);
 
  359        touch($new_filename, filectime($old_filename));
 
  377        $duplicate_has_array_entry = 
false;
 
  378        foreach (self::$duplicate_files as &$duplicate_file) {
 
  379            if ($duplicate_file[
'file_name'] == $duplicate_filename) {
 
  380                $duplicate_has_array_entry = 
true;
 
  381                $copy_number = $duplicate_file[
'copy_number'];
 
  383                $duplicate_file[
'copy_number']++;
 
  389        if (!$duplicate_has_array_entry) {
 
  390            self::$duplicate_files[] = [
 
  391                'file_name' => $duplicate_filename,
 
  397        $path = pathinfo($duplicate_filename, PATHINFO_DIRNAME);
 
  398        $filename = pathinfo($duplicate_filename, PATHINFO_FILENAME);
 
  399        $extension = pathinfo($duplicate_filename, PATHINFO_EXTENSION);
 
  400        $new_filename = 
$path . 
"/" . 
$filename . 
" (" . $copy_number . 
")." . $extension;
 
  402        return $new_filename;
 
  415        $ilAccess = 
$DIC[
'ilAccess'];
 
  417        if (!$ilAccess->checkAccess(
"read", 
"", $ref_id)) {
 
  440        return (
int) $this->
settings->get(
"bgtask_download_limit", 0);
 
  450        return (
int) $this->
settings->get(
"bgtask_download_tcount", 0);
 
  460        return (
int) $this->
settings->get(
"bgtask_download_tsize", 0);
 
An exception for terminatinating execution or to throw for unit testing.
static getFailedJson($a_message)
Get json for failed task.
static getProcessingJson($a_task_id, $a_message, $a_steps)
Get json for processing task.
static getFinishedJson($a_task_id, $a_cmd, $a_result)
Get json for finished task.
static getBlockedJson($a_task_id)
Get json for blocked task.
static getActiveByUserId($a_user_id)
getParams()
Gets the params.
Class to report exception.
Background task handler for folder downloads.
setRefIds($a_val)
Sets the involved reference ids.
validateAccess($ref_id)
Check file access.
calculateRecursive($a_ref_ids, &$a_file_count, &$a_file_size)
Calculates the number and size of the files being downloaded recursively.
static isActive()
Is folder background download active?
__construct()
Constructor.
gatherFiles()
Copy files to target directory.
recurseFolder($a_ref_id, $a_title, $a_tmpdir, &$a_current_step)
Copies a folder and its files to the specified temporary directory.
copyFile($a_obj_id, $a_title, $a_tmpdir, &$a_current_step)
Copies a file to the specified temporary directory.
static renameDuplicateFile($duplicate_filename)
bugfix mantis 24309: add a number in round brackets to the filename (in front of the file-type-extens...
getDownloadSizeLimit()
Get overall download size limit.
getTotalSizeThreshold()
Get total size threshold.
static initObjectListAction()
init js for background download
static getObjectListAction($a_ref_id)
Get object list action.
static getInstanceFromTask(ilBackgroundTask $a_task)
Constructor/Factory.
init($a_params=null)
Init background task.
getRefIds()
Gets the involved reference ids.
getFileCountThreshold()
Get file count threshold.
static initJS(ilTemplate $a_main_tpl=null)
Init javascript.
static _lookupFileSize($a_id)
Quickly looks up the file size from the database and returns the number of bytes.
static _lookupAbsolutePath($obj_id, $a_version=null)
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
static _isInTrash($a_ref_id)
checks wether object is in trash
static _lookupType($a_id, $a_reference=false)
lookup object type
static formatSize($size, $a_mode='short', $a_lng=null)
Returns the specified file size value in a human friendly form.
static getASCIIFilename($a_filename)
convert utf8 to ascii filename
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
Background task handler for zip creation.
process()
Process the task.
setTask(ilBackgroundTask $a_task)
Set current task instance.
getTempFolderPath()
Gets the temporary folder path to copy the files and folders to.
foreach($_POST as $key=> $value) $res