ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCalendarCopyFilesToTempDirectoryJob.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
29
35{
38
39 protected string $target_directory;
40
44 public function __construct()
45 {
46 global $DIC;
47
48 $this->irss = $DIC->resourceStorage();
49 $this->logger = $DIC->logger()->cal();
50 }
51
55 public function getInputTypes(): array
56 {
57 return
58 [
59 new SingleType(ilCalendarRessourceStorageCopyDefinition::class)
60 ];
61 }
62
67 public function getOutputType(): Type
68 {
69 return new SingleType(StringValue::class);
70 }
71
75 public function isStateless(): bool
76 {
77 return true;
78 }
79
83 public function run(array $input, Observer $observer): Value
84 {
85 $cal_copy_def = $input[0];
86
87 $this->logger->info('Called copy files job');
88
89 $this->target_directory = $cal_copy_def->getTempDir();
90 //$this->target_directory = $input[1]->getValue();
91
92 // create temp directory
93 $tmpdir = $this->createUniqueTempDirectory();
94 $targetdir = $this->createTargetDirectory($tmpdir);
95
96 // copy files from source to temp directory
97 //$this->copyFiles($targetdir, $input[0]);
98 $this->copyFiles($targetdir, $cal_copy_def);
99
100 // zip
101
102 // return zip file name
103 $this->logger->debug('Returning new tempdirectory: ' . $targetdir);
104
105 $out = new StringValue();
106 $out->setValue($targetdir);
107 return $out;
108 }
109
115 protected function createUniqueTempDirectory(): string
116 {
117 $tmpdir = ilFileUtils::ilTempnam();
119 $this->logger->info('New temp directory: ' . $tmpdir);
120 return $tmpdir;
121 }
122
123 protected function createTargetDirectory(string $a_tmpdir): string
124 {
125 $final_dir = $a_tmpdir . "/" . $this->target_directory;
126 ilFileUtils::makeDirParents($final_dir);
127 $this->logger->info('New final directory: ' . $final_dir);
128 return $final_dir;
129 }
130
134 protected function copyFiles(string $tmpdir, ilCalendarRessourceStorageCopyDefinition $definition): void
135 {
136 foreach ($definition->getCopyDefinitions() as $copy_task) {
138 $this->copyWithRId($tmpdir, $copy_task);
139 } else {
140 $this->copyWithAbsolutePath($tmpdir, $copy_task);
141 }
142 }
143 }
144
145 protected function copyWithRId(string $tmpdir, array $copy_task)
146 {
149 $resource_identification = $this->irss->manage()->find($rid);
150
151 if(is_null($resource_identification)) {
152 $this->logger->notice('Cannot ressource identification of rid: ' . $rid);
153 return;
154 }
155
156 $this->logger->debug('Creating directory: ' . $tmpdir . '/' . dirname($target_dir));
157 ilFileUtils::makeDirParents($tmpdir . '/' . dirname($target_dir));
158 $this->logger->debug('Copying ressource with id: ' . $rid . ' to ' . $tmpdir . '/' . $target_dir);
159
160 file_put_contents(
162 $this->irss->consume()->stream($resource_identification)->getStream()
163 );
164 }
165
166 protected function copyWithAbsolutePath(string $tmpdir, array $copy_task)
167 {
170
171 if (!file_exists($absolute_path)) {
172 $this->logger->notice('Cannot find file: ' . $absolute_path);
173 return;
174 }
175
176 $this->logger->debug('Creating directory: ' . $tmpdir . '/' . dirname($target_dir));
177 ilFileUtils::makeDirParents($tmpdir . '/' . dirname($target_dir));
178 $this->logger->debug('Copying from: ' . $absolute_path . ' to ' . $tmpdir . '/' . $target_dir);
179
180 copy($absolute_path, $tmpdir . '/' . $target_dir);
181 }
182
187 {
188 return 30;
189 }
190}
$out
Definition: buildRTE.php:24
copyFiles(string $tmpdir, ilCalendarRessourceStorageCopyDefinition $definition)
Copy files.
getExpectedTimeOfTaskInSeconds()
int the amount of seconds this task usually taskes. If your task-duration scales with the the amount ...
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
Component logger with individual log levels by component id.
global $DIC
Definition: shib_login.php:26