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

Background task handler for zip creation. More...

+ Inheritance diagram for ilZipBackgroundTaskHandler:
+ Collaboration diagram for ilZipBackgroundTaskHandler:

Public Member Functions

 __construct ()
 Constructor. More...
 
 setDeliveryFilename ($a_value)
 Sets the delivery file name. More...
 
 getDeliveryFilename ()
 Gets the delivery file name. More...
 
 getTask ()
 Get current task instance. More...
 
 process ()
 Process the task. More...
 
 cancel ()
 Cancel download. More...
 
 finish ()
 Finish download. More...
 
 deliver ()
 Deliver file. More...
 
 deleteTaskAndFiles ()
 Remove task and its files. More...
 
- Public Member Functions inherited from ilBackgroundTaskHandler
 getTask ()
 Get current task instance. More...
 
 init ($a_params)
 Init background task. More...
 
 process ()
 Process the task. More...
 
 cancel ()
 Cancel the task. More...
 
 finish ()
 Finish the task. More...
 
 deleteTaskAndFiles ()
 Remove task and its files. More...
 

Protected Member Functions

 setTask (ilBackgroundTask $a_task)
 Set current task instance. More...
 
 gatherFiles ()
 Copy files to target directory. More...
 
 deleteTempFiles ($a_delete_zip=true)
 Deletes the temporary files and folders belonging to this download. More...
 
 getTempFolderPath ()
 Gets the temporary folder path to copy the files and folders to. More...
 
 getTempZipFilePath ()
 Gets the full path of the temporary zip file that gets created. More...
 
 getTempBasePath ()
 Gets the temporary base path for all files and folders related to this download. More...
 

Protected Attributes

 $task
 
 $filename
 

Private Attributes

 $log
 

Additional Inherited Members

- Static Public Member Functions inherited from ilBackgroundTaskHandler
static getInstanceFromTask (ilBackgroundTask $a_task)
 Constructor/Factory. More...
 

Detailed Description

Background task handler for zip creation.

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 12 of file class.ilZipBackgroundTaskHandler.php.

Constructor & Destructor Documentation

◆ __construct()

ilZipBackgroundTaskHandler::__construct ( )

Constructor.

Returns
self

Reimplemented in ilFolderDownloadBackgroundTaskHandler.

Definition at line 27 of file class.ilZipBackgroundTaskHandler.php.

28 {
29 $this->log = ilLoggerFactory::getLogger('btsk');
30 $this->settings = new ilSetting("fold");
31 }
static getLogger($a_component_id)
Get component logger.
ILIAS Setting Class.
settings()
Definition: settings.php:2

References ilLoggerFactory\getLogger(), and settings().

+ Here is the call graph for this function:

Member Function Documentation

◆ cancel()

ilZipBackgroundTaskHandler::cancel ( )

Cancel download.

Returns
boolean

Implements ilBackgroundTaskHandler.

Definition at line 117 of file class.ilZipBackgroundTaskHandler.php.

118 {
119 $this->log->debug("");
120 $this->deleteTempFiles();
121
122 $this->task->setStatus(ilBackgroundTask::STATUS_CANCELLED);
123 $this->task->save();
124
125 return true;
126 }
deleteTempFiles($a_delete_zip=true)
Deletes the temporary files and folders belonging to this download.

References deleteTempFiles(), and ilBackgroundTask\STATUS_CANCELLED.

Referenced by process().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deleteTaskAndFiles()

ilZipBackgroundTaskHandler::deleteTaskAndFiles ( )

Remove task and its files.

Implements ilBackgroundTaskHandler.

Definition at line 154 of file class.ilZipBackgroundTaskHandler.php.

155 {
156 if (!$this->task) {
157 return;
158 }
159
160 $this->deleteTempFiles();
161
162 $this->task->delete();
163 unset($this->task);
164 }

References deleteTempFiles().

+ Here is the call graph for this function:

◆ deleteTempFiles()

ilZipBackgroundTaskHandler::deleteTempFiles (   $a_delete_zip = true)
protected

Deletes the temporary files and folders belonging to this download.

Parameters
bool$a_delete_zip

Definition at line 183 of file class.ilZipBackgroundTaskHandler.php.

184 {
185 $successful = true;
186
187 // delete temp directory
188 $tmp_folder = $this->getTempFolderPath();
189 if (is_dir($tmp_folder)) {
190 ilUtil::delDir($tmp_folder);
191 $successful = !file_exists($tmp_folder);
192 }
193
194 if ($a_delete_zip) {
195 // delete temp zip file
196 $tmp_file = $this->getTempZipFilePath();
197 if (file_exists($tmp_file)) {
198 $successful = @unlink($tmp_file);
199 }
200 }
201
202 return $successful;
203 }
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
getTempZipFilePath()
Gets the full path of the temporary zip file that gets created.
getTempFolderPath()
Gets the temporary folder path to copy the files and folders to.

References ilUtil\delDir(), getTempFolderPath(), and getTempZipFilePath().

Referenced by cancel(), deleteTaskAndFiles(), and finish().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deliver()

ilZipBackgroundTaskHandler::deliver ( )

Deliver file.

Definition at line 147 of file class.ilZipBackgroundTaskHandler.php.

148 {
149 $tmpzipfile = $this->getTempZipFilePath();
150 $deliverFilename = ilUtil::getAsciiFilename($this->getDeliveryFilename()) . ".zip";
151 ilUtil::deliverFile($tmpzipfile, $deliverFilename, '', false, true, false);
152 }
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
getDeliveryFilename()
Gets the delivery file name.

References ilUtil\deliverFile(), getDeliveryFilename(), and getTempZipFilePath().

+ Here is the call graph for this function:

◆ finish()

ilZipBackgroundTaskHandler::finish ( )

Finish download.

Implements ilBackgroundTaskHandler.

Definition at line 131 of file class.ilZipBackgroundTaskHandler.php.

132 {
133 global $DIC;
134 $ilCtrl = $DIC['ilCtrl'];
135
136 $this->deleteTempFiles(false);
137
138 $ilCtrl->setParameterByClass("ilbackgroundtaskhub", "tid", $this->task->getId());
139 $url = $ilCtrl->getLinkTargetByClass("ilbackgroundtaskhub", "deliver", "", false, false);
140
141 return array("redirect", $url);
142 }
global $ilCtrl
Definition: ilias.php:18
$url
global $DIC
Definition: saml.php:7

References $DIC, $ilCtrl, $url, and deleteTempFiles().

Referenced by ilFolderDownloadBackgroundTaskHandler\init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gatherFiles()

ilZipBackgroundTaskHandler::gatherFiles ( )
abstractprotected

Copy files to target directory.

Returns
int current step

Reimplemented in ilFolderDownloadBackgroundTaskHandler.

Referenced by process().

+ Here is the caller graph for this function:

◆ getDeliveryFilename()

ilZipBackgroundTaskHandler::getDeliveryFilename ( )

Gets the delivery file name.

Returns
string

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

References $filename.

Referenced by deliver().

+ Here is the caller graph for this function:

◆ getTask()

ilZipBackgroundTaskHandler::getTask ( )

Get current task instance.

Returns
\ilBackgroundTask

Implements ilBackgroundTaskHandler.

Definition at line 72 of file class.ilZipBackgroundTaskHandler.php.

References $task.

◆ getTempBasePath()

ilZipBackgroundTaskHandler::getTempBasePath ( )
protected

Gets the temporary base path for all files and folders related to this download.

Returns
int

Definition at line 235 of file class.ilZipBackgroundTaskHandler.php.

236 {
237 return ilUtil::getDataDir() . "/temp/dl_" . $this->task->getId();
238 }
static getDataDir()
get data directory (outside webspace)

References ilUtil\getDataDir().

Referenced by getTempFolderPath(), and getTempZipFilePath().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTempFolderPath()

ilZipBackgroundTaskHandler::getTempFolderPath ( )
protected

Gets the temporary folder path to copy the files and folders to.

Returns
int

Definition at line 215 of file class.ilZipBackgroundTaskHandler.php.

216 {
217 return $this->getTempBasePath() . ".tmp";
218 }
getTempBasePath()
Gets the temporary base path for all files and folders related to this download.

References getTempBasePath().

Referenced by deleteTempFiles(), ilFolderDownloadBackgroundTaskHandler\gatherFiles(), and process().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTempZipFilePath()

ilZipBackgroundTaskHandler::getTempZipFilePath ( )
protected

Gets the full path of the temporary zip file that gets created.

Returns
int

Definition at line 225 of file class.ilZipBackgroundTaskHandler.php.

226 {
227 return $this->getTempBasePath() . ".zip";
228 }

References getTempBasePath().

Referenced by deleteTempFiles(), deliver(), and process().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ process()

ilZipBackgroundTaskHandler::process ( )

Process the task.

Implements ilBackgroundTaskHandler.

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

78 {
79 $this->log->debug("start");
80 // create temporary file to download
81 $tmpdir = $this->getTempFolderPath();
83
84 // gather all files
85 $current_step = $this->gatherFiles();
86
87 // has been cancelled?
88 if ($this->task->isToBeCancelled()) {
89 return $this->cancel();
90 }
91
92 // :TODO: create zip in several steps
93
94 $this->task->setCurrentStep(++$current_step);
95 $this->task->save();
96
97 // create archive to download
98 $tmpzipfile = $this->getTempZipFilePath();
99 ilUtil::zip($tmpdir, $tmpzipfile, true);
100 ilUtil::delDir($tmpdir);
101
102 // has been cancelled?
103 if ($this->task->isToBeCancelled()) {
104 return $this->cancel();
105 }
106
107 $this->task->setStatus(ilBackgroundTask::STATUS_FINISHED);
108 $this->task->save();
109 $this->log->debug("end");
110 }
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
static makeDirParents($a_dir)
Create a new directory and all parent directories.
gatherFiles()
Copy files to target directory.

References cancel(), ilUtil\delDir(), gatherFiles(), getTempFolderPath(), getTempZipFilePath(), ilUtil\makeDirParents(), ilBackgroundTask\STATUS_FINISHED, and ilUtil\zip().

Referenced by ilFolderDownloadBackgroundTaskHandler\init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setDeliveryFilename()

ilZipBackgroundTaskHandler::setDeliveryFilename (   $a_value)

Sets the delivery file name.

Parameters
string

Definition at line 42 of file class.ilZipBackgroundTaskHandler.php.

43 {
44 $this->filename = $a_value;
45 }

◆ setTask()

ilZipBackgroundTaskHandler::setTask ( ilBackgroundTask  $a_task)
protected

Set current task instance.

Parameters
ilBackgroundTask$a_task

Definition at line 62 of file class.ilZipBackgroundTaskHandler.php.

63 {
64 $this->task = $a_task;
65 }

Referenced by ilFolderDownloadBackgroundTaskHandler\init().

+ Here is the caller graph for this function:

Field Documentation

◆ $filename

ilZipBackgroundTaskHandler::$filename
protected

◆ $log

ilZipBackgroundTaskHandler::$log
private

Definition at line 20 of file class.ilZipBackgroundTaskHandler.php.

◆ $task

ilZipBackgroundTaskHandler::$task
protected

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