ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilDownloadContainerFilesBackgroundTask.php
Go to the documentation of this file.
1<?php
2
22
30{
31 protected ilLanguage $lng;
33 protected int $user_id;
37 protected array $object_ref_ids;
38 // determines whether the task has been initiated by a folder's action drop-down to prevent a folder duplicate inside the zip.
39 protected bool $initiated_by_folder_action = false;
40 protected ?TaskFactory $task_factory = null;
41 protected string $bucket_title; // title of the task showed in the main menu.
42 protected bool $has_files = false; // if the task has collected files to create the ZIP file.
43
44
45 public function __construct(
46 int $a_usr_id,
47 array $a_object_ref_ids,
48 bool $a_initiated_by_folder_action
49 ) {
50 global $DIC;
51 $this->logger = $DIC->logger()->cal();
52 $this->user_id = $a_usr_id;
53 $this->object_ref_ids = $a_object_ref_ids;
54 $this->initiated_by_folder_action = $a_initiated_by_folder_action;
55 $this->task_factory = $DIC->backgroundTasks()->taskFactory();
56 $this->lng = $DIC->language();
57 }
58
59 public function setBucketTitle(string $a_title): void
60 {
61 $this->bucket_title = $a_title;
62 }
63
64 public function getBucketTitle(): string
65 {
66 //TODO: fix ilUtil zip stuff
67 // Error If name starts "-"
68 // error massage from ilUtil->execQuoted = ["","zip error: Invalid command arguments (short option 'a' not supported)"]
69 if ($this->bucket_title[0] === "-") {
70 $this->bucket_title = ltrim($this->bucket_title, "-");
71 }
72
74 }
75
76
77 public function run(): bool
78 {
79 // This is our Bucket
80 $this->logger->info('Started download container files background task');
81 $bucket = new BasicBucket();
82 $bucket->setUserId($this->user_id);
83 $this->logger->debug('Created bucket and set the following user id: ' . $this->user_id);
84
85 // Copy Definition
86 $definition = new ilCopyDefinition();
87 $normalized_name = ilFileUtils::getASCIIFilename($this->getBucketTitle());
88 $definition->setTempDir($normalized_name);
89 $definition->setObjectRefIds($this->object_ref_ids);
90 $this->logger->debug('Created copy definition and added the following tempdir: ' . $normalized_name);
91
92 // Collect all files by the definition and prevent duplicates
93 $collect_job = $this->task_factory->createTask(ilCollectFilesJob::class, [$definition, $this->initiated_by_folder_action]);
94 $this->logger->debug('Collected files based on the following object ids: ');
95 $this->logger->dump($this->object_ref_ids);
96
97 // Check the FileSize
98 $file_size_job = $this->task_factory->createTask(ilCheckSumOfFileSizesJob::class, [$collect_job]);
99
100 // Show problems with file-limit
101 $file_size_interaction = $this->task_factory->createTask(ilSumOfFileSizesTooLargeInteraction::class, [$file_size_job]);
102 $this->logger->debug('Determined the sum of all file sizes');
103
104 // move files from source dir to target directory
105 $copy_job = $this->task_factory->createTask(ilCopyFilesToTempDirectoryJob::class, [$file_size_interaction]);
106
107 // Zip it
108 $zip_job = $this->task_factory->createTask(ilZipJob::class, [$copy_job]);
109 $this->logger->debug('Moved files from source- to target-directory');
110
111 // Download
112 $download_name = new StringValue();
113 $download_name->setValue($normalized_name . '.zip');
114 $download_interaction = $this->task_factory->createTask(ilDownloadZipInteraction::class, [$zip_job, $download_name]);
115 $this->logger->debug('Created a download interaction with the following download name: ' . $download_name->getValue());
116
117 // last task to bucket
118 $bucket->setTask($download_interaction);
119 $bucket->setTitle($this->getBucketTitle());
120 $this->logger->debug('Added last task to bucket and set the following title: ' . $this->getBucketTitle());
121
122 $task_manager = $GLOBALS['DIC']->backgroundTasks()->taskManager();
123 $task_manager->run($bucket);
124 $this->logger->debug('Ran bucket in task manager');
125
126 return true;
127 }
128}
Description of class class.
__construct(int $a_usr_id, array $a_object_ref_ids, bool $a_initiated_by_folder_action)
static getASCIIFilename(string $a_filename)
language handling
Component logger with individual log levels by component id.
global $DIC
Definition: shib_login.php:26
$GLOBALS["DIC"]
Definition: wac.php:54