ILIAS  release_8 Revision v8.24
class.ilCalendarCopyFilesToTempDirectoryJob.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
13
14/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
15
21{
23
24 protected string $target_directory;
25
29 public function __construct()
30 {
31 global $DIC;
32
33 $this->logger = $DIC->logger()->cal();
34 }
35
39 public function getInputTypes(): array
40 {
41 return
42 [
43 new SingleType(ilCalendarCopyDefinition::class)
44 ];
45 }
46
51 public function getOutputType(): Type
52 {
53 return new SingleType(StringValue::class);
54 }
55
59 public function isStateless(): bool
60 {
61 return true;
62 }
63
67 public function run(array $input, Observer $observer): Value
68 {
69 $cal_copy_def = $input[0];
70
71 $this->logger->info('Called copy files job');
72
73 $this->target_directory = $cal_copy_def->getTempDir();
74 //$this->target_directory = $input[1]->getValue();
75
76 // create temp directory
77 $tmpdir = $this->createUniqueTempDirectory();
78 $targetdir = $this->createTargetDirectory($tmpdir);
79
80 // copy files from source to temp directory
81 //$this->copyFiles($targetdir, $input[0]);
82 $this->copyFiles($targetdir, $cal_copy_def);
83
84 // zip
85
86 // return zip file name
87 $this->logger->debug('Returning new tempdirectory: ' . $targetdir);
88
89 $out = new StringValue();
90 $out->setValue($targetdir);
91 return $out;
92 }
93
99 protected function createUniqueTempDirectory(): string
100 {
101 $tmpdir = ilFileUtils::ilTempnam();
103 $this->logger->info('New temp directory: ' . $tmpdir);
104 return $tmpdir;
105 }
106
107 protected function createTargetDirectory(string $a_tmpdir): string
108 {
109 $final_dir = $a_tmpdir . "/" . $this->target_directory;
110 ilFileUtils::makeDirParents($final_dir);
111 $this->logger->info('New final directory: ' . $final_dir);
112 return $final_dir;
113 }
114
120 protected function copyFiles(string $tmpdir, ilCalendarCopyDefinition $definition): void
121 {
122 foreach ($definition->getCopyDefinitions() as $copy_task) {
123 if (!file_exists($copy_task[ilCalendarCopyDefinition::COPY_SOURCE_DIR])) {
124 $this->logger->notice('Cannot find file: ' . $copy_task[ilCalendarCopyDefinition::COPY_SOURCE_DIR]);
125 continue;
126 }
127 $this->logger->debug('Creating directory: ' . $tmpdir . '/' . dirname($copy_task[ilCalendarCopyDefinition::COPY_TARGET_DIR]));
129 $tmpdir . '/' . dirname($copy_task[ilCalendarCopyDefinition::COPY_TARGET_DIR])
130 );
131
132 $this->logger->debug(
133 'Copying from: ' .
135 ' to ' .
136 $tmpdir . '/' . $copy_task[ilCalendarCopyDefinition::COPY_TARGET_DIR]
137 );
138
139 copy(
141 $tmpdir . '/' . $copy_task[ilCalendarCopyDefinition::COPY_TARGET_DIR]
142 );
143 }
144 }
145
150 {
151 return 30;
152 }
153}
$out
Definition: buildRTE.php:24
getExpectedTimeOfTaskInSeconds()
int the amount of seconds this task usually taskes. If your task-duration scales with the the amount ...
copyFiles(string $tmpdir, ilCalendarCopyDefinition $definition)
Copy files.
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: feed.php:28