ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilDownloadWorkspaceFolderBackgroundTask.php
Go to the documentation of this file.
1<?php
2
5
6/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
7
14{
15
19 private $logger = null;
23 protected $user_id;
27 protected $object_wsp_ids;
33 protected $initiated_by_folder_action = false;
37 protected $task_factory = null;
43 protected $bucket_title;
49 protected $has_files = false;
50
51
59 public function __construct(int $a_usr_id, array $a_object_wsp_ids, bool $a_initiated_by_folder_action = false)
60 {
61 global $DIC;
62 $this->logger = ilLoggerFactory::getLogger("pwsp");
63 $this->user_id = $a_usr_id;
64 $this->object_wsp_ids = $a_object_wsp_ids;
65 $this->initiated_by_folder_action = $a_initiated_by_folder_action;
66 $this->task_factory = $DIC->backgroundTasks()->taskFactory();
67 $this->lng = $DIC->language();
68 }
69
70
76 public function setBucketTitle($a_title)
77 {
78 $this->bucket_title = $a_title;
79 }
80
81
87 public function getBucketTitle()
88 {
89 //TODO: fix ilUtil zip stuff
90 // Error If name starts "-"
91 // error massage from ilUtil->execQuoted = ["","zip error: Invalid command arguments (short option 'a' not supported)"]
92 if (substr($this->bucket_title, 0, 1) === "-") {
93 $this->bucket_title = ltrim($this->bucket_title, "-");
94 }
95
97 }
98
99
105 public function run()
106 {
107 // This is our Bucket
108 $this->logger->info('Started download workspace files background task');
109 $bucket = new BasicBucket();
110 $bucket->setUserId($this->user_id);
111 $this->logger->debug('Created bucket and set the following user id: ' . $this->user_id);
112
113 // Copy Definition
114 $definition = new ilWorkspaceCopyDefinition();
115 $normalized_name = ilUtil::getASCIIFilename($this->getBucketTitle());
116 $definition->setTempDir($normalized_name);
117 $definition->setObjectWspIds($this->object_wsp_ids);
118 $this->logger->debug('Created copy definition and added the following tempdir: ' . $normalized_name);
119
120 // Collect all files by the definition and prevent duplicates
121 $collect_job = $this->task_factory->createTask(ilCollectWorkspaceFilesJob::class, [$definition, $this->initiated_by_folder_action]);
122 $this->logger->debug('Collected files based on the following object ids: ');
123 $this->logger->dump($this->object_wsp_ids);
124
125 // Check the FileSize
126 $file_size_job = $this->task_factory->createTask(ilCheckSumOfWorkspaceFileSizesJob::class, [$collect_job]);
127
128 // Show problems with file-limit
129 $file_size_interaction = $this->task_factory->createTask(ilSumOfWorkspaceFileSizesTooLargeInteraction::class, [$file_size_job]);
130 $this->logger->debug('Determined the sum of all file sizes');
131
132 // move files from source dir to target directory
133 $copy_job = $this->task_factory->createTask(ilCopyWorkspaceFilesToTempDirectoryJob::class, [$file_size_interaction]);
134
135 // Zip it
136 $zip_job = $this->task_factory->createTask(ilZipJob::class, [$copy_job]);
137 $this->logger->debug('Moved files from source- to target-directory');
138
139 // Download
140 $download_name = new StringValue();
141 $download_name->setValue($normalized_name . '.zip');
142 $download_interaction = $this->task_factory->createTask(ilDownloadZipInteraction::class, [$zip_job, $download_name]);
143 $this->logger->debug('Created a download interaction with the following download name: ' . $download_name->getValue());
144
145 // last task to bucket
146 $bucket->setTask($download_interaction);
147 $bucket->setTitle($this->getBucketTitle());
148 $this->logger->debug('Added last task to bucket and set the following title: ' . $this->getBucketTitle());
149
150 $task_manager = $GLOBALS['DIC']->backgroundTasks()->taskManager();
151 $task_manager->run($bucket);
152 $this->logger->debug('Ran bucket in task manager');
153
154 return true;
155 }
156}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
An exception for terminatinating execution or to throw for unit testing.
__construct(int $a_usr_id, array $a_object_wsp_ids, bool $a_initiated_by_folder_action=false)
Constructor.
static getLogger($a_component_id)
Get component logger.
static getASCIIFilename($a_filename)
convert utf8 to ascii filename
Copy definition for worspace folders.
$DIC
Definition: xapitoken.php:46