ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCopyWorkspaceFilesToTempDirectoryJob.php
Go to the documentation of this file.
1<?php
2
27
34{
35 private ?ilLogger $logger = null;
36 protected string $target_directory;
37
38 public function __construct()
39 {
40 $this->logger = ilLoggerFactory::getLogger("pwsp");
41 }
42
43 public function getInputTypes(): array
44 {
45 return
46 [
47 new SingleType(ilWorkspaceCopyDefinition::class)
48 ];
49 }
50
51 public function getOutputType(): Type
52 {
53 return new SingleType(StringValue::class);
54 }
55
56 public function isStateless(): bool
57 {
58 return true;
59 }
60
61 public function run(array $input, Observer $observer): Value
62 {
63 $definition = $input[0];
64
65 $this->logger->info('Called copy files job');
66
67 $this->target_directory = $definition->getTempDir();
68
69 // create temp directory
70 $tmpdir = $this->createUniqueTempDirectory();
71 $targetdir = $this->createTargetDirectory($tmpdir);
72
73 // copy files from source to temp directory
74 //$this->copyFiles($targetdir, $input[0]);
75 $this->copyFiles($targetdir, $definition);
76
77 // zip
78
79 // return zip file name
80 $this->logger->debug('Returning new tempdirectory: ' . $targetdir);
81
82 $out = new StringValue();
83 $out->setValue($targetdir);
84 return $out;
85 }
86
91 protected function createUniqueTempDirectory(): string
92 {
93 $tmpdir = ilFileUtils::ilTempnam();
95 $this->logger->info('New temp directory: ' . $tmpdir);
96 return $tmpdir;
97 }
98
99 protected function createTargetDirectory(string $a_tmpdir): string
100 {
101 $final_dir = $a_tmpdir . "/" . $this->target_directory;
102 ilFileUtils::makeDirParents($final_dir);
103 $this->logger->info('New final directory: ' . $final_dir);
104 return $final_dir;
105 }
106
107 protected function copyFiles(
108 string $tmpdir,
109 ilWorkspaceCopyDefinition $definition
110 ): void {
111 foreach ($definition->getCopyDefinitions() as $copy_task) {
112 if (!file_exists($copy_task[ilWorkspaceCopyDefinition::COPY_SOURCE_DIR])) {
113 // if the "file" to be copied is an empty folder the directory has to be created so it will be contained in the download zip
114 $is_empty_folder = preg_match_all("/\/$/", $copy_task[ilWorkspaceCopyDefinition::COPY_TARGET_DIR]);
115 if ($is_empty_folder) {
117 $this->logger->notice('Empty folder has been created: ' . $tmpdir . '/' . $copy_task[ilWorkspaceCopyDefinition::COPY_SOURCE_DIR]);
118 } else {
119 $this->logger->notice('Cannot find file: ' . $copy_task[ilWorkspaceCopyDefinition::COPY_SOURCE_DIR]);
120 }
121 continue;
122 }
123 $this->logger->debug('Creating directory: ' . $tmpdir . '/' . dirname($copy_task[ilWorkspaceCopyDefinition::COPY_TARGET_DIR]));
125 $tmpdir . '/' . dirname($copy_task[ilWorkspaceCopyDefinition::COPY_TARGET_DIR])
126 );
127
128 $this->logger->debug(
129 'Copying from: ' .
131 ' to ' .
132 $tmpdir . '/' . $copy_task[ilWorkspaceCopyDefinition::COPY_TARGET_DIR]
133 );
134
135 copy(
137 $tmpdir . '/' . $copy_task[ilWorkspaceCopyDefinition::COPY_TARGET_DIR]
138 );
139 }
140 }
141
143 {
144 return 30;
145 }
146}
$out
Definition: buildRTE.php:24
copyFiles(string $tmpdir, ilWorkspaceCopyDefinition $definition)
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.
static getLogger(string $a_component_id)
Get component logger.
Component logger with individual log levels by component id.
Copy definition for workspace folders.