ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilDownloadContainerFilesBackgroundTask.php
Go to the documentation of this file.
1<?php
2
5
6include_once('Services/BackgroundTasks/classes/class.ilCopyDefinition.php');
7include_once('Services/BackgroundTasks/classes/Jobs/class.ilCollectFilesJob.php');
8include_once('Services/BackgroundTasks/classes/Jobs/class.ilCheckSumOfFileSizesJob.php');
9include_once('Services/BackgroundTasks/classes/UserInteractions/class.ilSumOfFileSizesTooLargeInteraction.php');
10include_once('Services/BackgroundTasks/classes/Jobs/class.ilCopyFilesToTempDirectoryJob.php');
11include_once('Services/BackgroundTasks/classes/Jobs/class.ilZipJob.php');
12include_once('Services/BackgroundTasks/classes/UserInteractions/class.ilDownloadZipInteraction.php');
13
14/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
15
23{
24
28 private $logger = null;
32 protected $user_id;
36 protected $object_ref_ids;
42 protected $initiated_by_folder_action = false;
46 protected $task_factory = null;
52 protected $bucket_title;
58 protected $has_files = false;
59
60
67 public function __construct($a_usr_id, $a_object_ref_ids, $a_initiated_by_folder_action)
68 {
69 global $DIC;
70 $this->logger = $DIC->logger()->cal();
71 $this->user_id = $a_usr_id;
72 $this->object_ref_ids = $a_object_ref_ids;
73 $this->initiated_by_folder_action = $a_initiated_by_folder_action;
74 $this->task_factory = $DIC->backgroundTasks()->taskFactory();
75 $this->lng = $DIC->language();
76 }
77
78
84 public function setBucketTitle($a_title)
85 {
86 $this->bucket_title = $a_title;
87 }
88
89
95 public function getBucketTitle()
96 {
97 //TODO: fix ilUtil zip stuff
98 // Error If name starts "-"
99 // error massage from ilUtil->execQuoted = ["","zip error: Invalid command arguments (short option 'a' not supported)"]
100 if (substr($this->bucket_title, 0, 1) === "-") {
101 $this->bucket_title = ltrim($this->bucket_title, "-");
102 }
103
104 return $this->bucket_title;
105 }
106
107
113 public function run()
114 {
115 // This is our Bucket
116 $this->logger->info('Started download container files background task');
117 $bucket = new BasicBucket();
118 $bucket->setUserId($this->user_id);
119 $this->logger->debug('Created bucket and set the following user id: ' . $this->user_id);
120
121 // Copy Definition
122 $definition = new ilCopyDefinition();
123 $normalized_name = ilUtil::getASCIIFilename($this->getBucketTitle());
124 $definition->setTempDir($normalized_name);
125 $definition->setObjectRefIds($this->object_ref_ids);
126 $this->logger->debug('Created copy definition and added the following tempdir: ' . $normalized_name);
127
128 // Collect all files and folders by the definition and prevent duplicates
129 $collect_job = $this->task_factory->createTask(ilCollectFilesJob::class, [$definition, $this->initiated_by_folder_action]);
130 $this->logger->debug('Collected files based on the following object ids: ');
131 $this->logger->dump($this->object_ref_ids);
132
133 // Check the FileSize
134 $file_size_job = $this->task_factory->createTask(ilCheckSumOfFileSizesJob::class, [$collect_job]);
135
136 // Show problems with file-limit
137 $file_size_interaction = $this->task_factory->createTask(ilSumOfFileSizesTooLargeInteraction::class, [$file_size_job]);
138 $this->logger->debug('Determined the sum of all file sizes');
139
140 // move files from source dir to target directory
141 $copy_job = $this->task_factory->createTask(ilCopyFilesToTempDirectoryJob::class, [$file_size_interaction]);
142
143 // Zip it
144 $zip_job = $this->task_factory->createTask(ilZipJob::class, [$copy_job]);
145 $this->logger->debug('Moved files from source- to target-directory');
146
147 // Download
148 $download_name = new StringValue();
149 $download_name->setValue($normalized_name . '.zip');
150 $download_interaction = $this->task_factory->createTask(ilDownloadZipInteraction::class, [$zip_job, $download_name]);
151 $this->logger->debug('Created a download interaction with the following download name: ' . $download_name->getValue());
152
153 // last task to bucket
154 $bucket->setTask($download_interaction);
155 $bucket->setTitle($this->getBucketTitle());
156 $this->logger->debug('Added last task to bucket and set the following title: ' . $this->getBucketTitle());
157
158 $task_manager = $GLOBALS['DIC']->backgroundTasks()->taskManager();
159 $task_manager->run($bucket);
160 $this->logger->debug('Ran bucket in task manager');
161
162 return true;
163 }
164}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
An exception for terminatinating execution or to throw for unit testing.
Description of class class.
__construct($a_usr_id, $a_object_ref_ids, $a_initiated_by_folder_action)
Constructor.
static getASCIIFilename($a_filename)
convert utf8 to ascii filename
global $DIC
Definition: goto.php:24