ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 119 of file class.ilZipBackgroundTaskHandler.php.

120 {
121 $this->log->debug("");
122 $this->deleteTempFiles();
123
124 $this->task->setStatus(ilBackgroundTask::STATUS_CANCELLED);
125 $this->task->save();
126
127 return true;
128 }
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 155 of file class.ilZipBackgroundTaskHandler.php.

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

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 185 of file class.ilZipBackgroundTaskHandler.php.

186 {
187 $successful = true;
188
189 // delete temp directory
190 $tmp_folder = $this->getTempFolderPath();
191 if(is_dir($tmp_folder))
192 {
193 ilUtil::delDir($tmp_folder);
194 $successful = !file_exists($tmp_folder);
195 }
196
197 if($a_delete_zip)
198 {
199 // delete temp zip file
200 $tmp_file = $this->getTempZipFilePath();
201 if(file_exists($tmp_file))
202 {
203 $successful = @unlink($tmp_file);
204 }
205 }
206
207 return $successful;
208 }
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 148 of file class.ilZipBackgroundTaskHandler.php.

149 {
150 $tmpzipfile = $this->getTempZipFilePath();
151 $deliverFilename = ilUtil::getAsciiFilename($this->getDeliveryFilename()) . ".zip";
152 ilUtil::deliverFile($tmpzipfile, $deliverFilename, '', false, true, false);
153 }
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 133 of file class.ilZipBackgroundTaskHandler.php.

134 {
135 global $ilCtrl;
136
137 $this->deleteTempFiles(false);
138
139 $ilCtrl->setParameterByClass("ilbackgroundtaskhub", "tid", $this->task->getId());
140 $url = $ilCtrl->getLinkTargetByClass("ilbackgroundtaskhub", "deliver", "", false, false);
141
142 return array("redirect", $url);
143 }
global $ilCtrl
Definition: ilias.php:18
$url
Definition: shib_logout.php:72

References $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 240 of file class.ilZipBackgroundTaskHandler.php.

241 {
242 return ilUtil::getDataDir() . "/temp/dl_" . $this->task->getId();
243 }
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 220 of file class.ilZipBackgroundTaskHandler.php.

221 {
222 return $this->getTempBasePath() . ".tmp";
223 }
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 230 of file class.ilZipBackgroundTaskHandler.php.

231 {
232 return $this->getTempBasePath() . ".zip";
233 }

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 {
90 return $this->cancel();
91 }
92
93 // :TODO: create zip in several steps
94
95 $this->task->setCurrentStep(++$current_step);
96 $this->task->save();
97
98 // create archive to download
99 $tmpzipfile = $this->getTempZipFilePath();
100 ilUtil::zip($tmpdir, $tmpzipfile, true);
101 ilUtil::delDir($tmpdir);
102
103 // has been cancelled?
104 if($this->task->isToBeCancelled())
105 {
106 return $this->cancel();
107 }
108
109 $this->task->setStatus(ilBackgroundTask::STATUS_FINISHED);
110 $this->task->save();
111 $this->log->debug("end");
112 }
static zip($a_dir, $a_file, $compress_content=false)
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

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

Referenced by getDeliveryFilename().

◆ $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: