46 $this->
logger = $DIC->logger()->cal();
68 return new SingleType(ilCopyDefinition::class);
87 $this->
logger->debug(
'Start collecting files!');
88 $this->
logger->dump($input);
89 $definition = $input[0];
90 $initiated_by_folder_action = $input[1]->getValue();
91 $object_ref_ids = $definition->getObjectRefIds();
94 foreach ($object_ref_ids as $object_ref_id) {
96 $object_type = $object->getType();
97 $object_name = $object->getTitle();
98 $object_temp_dir =
"";
100 if ($object_type ==
"fold") {
102 $files_from_folder = self::recurseFolder($object_ref_id, $object_name, $object_temp_dir, $num_recursions, $initiated_by_folder_action);
103 $files = array_merge($files, $files_from_folder);
104 } elseif (($object_type ==
"file") && (($file_dirs = self::getFileDirs(
109 $files[] = $file_dirs;
112 $this->
logger->debug(
'Collected files:');
113 $this->
logger->dump($files);
116 foreach ($files as $file) {
117 $definition->addCopyDefinition($file[
'source_dir'], $file[
'target_dir']);
118 $this->
logger->debug(
'Added new copy definition: ' . $file[
'source_dir'] .
' -> ' . $file[
'target_dir']);
121 $is_empty_folder = preg_match_all(
"/\/$/", $file[
'target_dir']);
122 if (!$is_empty_folder) {
126 $definition->setObjectRefIds($object_ref_ids);
127 $definition->setNumFiles($num_files);
139 private static function getFileDirs($a_ref_id, $a_file_name, $a_temp_dir)
143 $user = $DIC->user();
144 $ilAccess = $DIC->access();
145 if ($ilAccess->checkAccessOfUser($user->getId(),
"read",
"", $a_ref_id)) {
147 $source_dir = $file->getFile();
148 if (@!is_file($source_dir)) {
156 if (isset(self::$targets[$target_dir])) {
157 $target_info = pathinfo($target_dir);
159 $extension = isset($target_info[
"extension"]) ?
"." . $target_info[
"extension"] :
"";
160 $target_dir = $a_temp_dir .
$filename .
" (" . ++self::$targets[$target_dir] .
")" . $extension;
162 self::$targets[$target_dir] = 0;
166 "source_dir" => $source_dir,
167 "target_dir" => $target_dir,
182 private static function recurseFolder($a_ref_id, $a_folder_name, $a_temp_dir, $a_num_recursions, $a_initiated_by_folder_action): array
186 $num_recursions = $a_num_recursions + 1;
187 $tree = $DIC->repositoryTree();
188 $ilAccess = $DIC->access();
193 if ($num_recursions <= 1 && $a_initiated_by_folder_action) {
194 $temp_dir = $a_temp_dir;
199 $subtree = $tree->getChildsByTypeFilter($a_ref_id, array(
"fold",
"file"));
201 foreach ($subtree as $child) {
202 if (!$ilAccess->checkAccess(
"read",
"", $child[
"ref_id"])) {
208 if ($child[
"type"] ==
"fold") {
209 $files_from_folder = self::recurseFolder($child[
"ref_id"], $child[
'title'], $temp_dir, $num_recursions, $a_initiated_by_folder_action);
210 $files = array_merge($files, $files_from_folder);
212 if (($child[
"type"] ==
"file") && (($dirs = self::getFileDirs($child[
"ref_id"], $child[
'title'], $temp_dir)) !==
false)) {
218 if (empty($subtree)) {
221 "target_dir" => $temp_dir .
'/',
static getFileDirs($a_ref_id, $a_file_name, $a_temp_dir)
static recurseFolder($a_ref_id, $a_folder_name, $a_temp_dir, $a_num_recursions, $a_initiated_by_folder_action)
Description of class class.
Class ChatMainBarProvider .
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
run(array $input, \ILIAS\BackgroundTasks\Observer $observer)
static getASCIIFilename(string $a_filename)
static _isInTrash(int $ref_id)
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
getExpectedTimeOfTaskInSeconds()
int the amount of seconds this task usually taskes. If your task-duration scales with the the amount ...