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