ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilCopyFilesToTempDirectoryJob.php
Go to the documentation of this file.
1<?php
2
8
9/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
10
18{
19
23 private $logger = null;
28
29
33 public function __construct()
34 {
35 $this->logger = $GLOBALS['DIC']->logger()->cal();
36 }
37
38
41 public function getInputTypes()
42 {
43 return
44 [
45 new SingleType(ilCopyDefinition::class),
46 ];
47 }
48
49
54 public function getOutputType()
55 {
56 return new SingleType(StringValue::class);
57 }
58
59
60 public function isStateless()
61 {
62 return true;
63 }
64
65
72 public function run(array $input, Observer $observer)
73 {
74 $definition = $input[0];
75
76 $this->logger->info('Called copy files job');
77
78 $this->target_directory = $definition->getTempDir();
79
80 // create temp directory
81 $tmpdir = $this->createUniqueTempDirectory();
82 $targetdir = $this->createTargetDirectory($tmpdir);
83
84 // copy files from source to temp directory
85 //$this->copyFiles($targetdir, $input[0]);
86 $this->copyFiles($targetdir, $definition);
87
88 // zip
89
90 // return zip file name
91 $this->logger->debug('Returning new tempdirectory: ' . $targetdir);
92
93 $out = new StringValue();
94 $out->setValue($targetdir);
95
96 return $out;
97 }
98
99
105 protected function createUniqueTempDirectory()
106 {
107 $tmpdir = ilUtil::ilTempnam();
108 ilUtil::makeDirParents($tmpdir);
109 $this->logger->info('New temp directory: ' . $tmpdir);
110
111 return $tmpdir;
112 }
113
114
115 protected function createTargetDirectory($a_tmpdir)
116 {
117 $final_dir = $a_tmpdir . "/" . $this->target_directory;
118 ilUtil::makeDirParents($final_dir);
119 $this->logger->info('New final directory: ' . $final_dir);
120
121 return $final_dir;
122 }
123
124
131 protected function copyFiles($tmpdir, ilCopyDefinition $definition)
132 {
133 foreach ($definition->getCopyDefinitions() as $copy_task) {
134 if($copy_task[ilCopyDefinition::COPY_SOURCE_DIR] === '') { // see https://mantis.ilias.de/view.php?id=31328
135 continue;
136 }
137 $this->logger->debug('Creating directory: ' . $tmpdir . '/' . dirname($copy_task[ilCopyDefinition::COPY_TARGET_DIR]));
139 $tmpdir . '/' . dirname($copy_task[ilCopyDefinition::COPY_TARGET_DIR])
140 );
141
142
143 if (!file_exists($copy_task[ilCopyDefinition::COPY_SOURCE_DIR])) {
144 // 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
145 $is_empty_folder = preg_match_all("/\/$/", $copy_task[ilCopyDefinition::COPY_TARGET_DIR]);
146 if ($is_empty_folder) {
147 mkdir($tmpdir . '/' . $copy_task[ilCopyDefinition::COPY_TARGET_DIR]);
148 $this->logger->notice('Empty folder has been created: ' . $tmpdir . '/' . $copy_task[ilCopyDefinition::COPY_SOURCE_DIR]);
149 } else {
150 $this->logger->notice('Cannot find file: ' . $copy_task[ilCopyDefinition::COPY_SOURCE_DIR]);
151 }
152 continue;
153 }
154
155
156 $this->logger->debug(
157 'Copying from: ' .
159 ' to ' .
160 $tmpdir . '/' . $copy_task[ilCopyDefinition::COPY_TARGET_DIR]
161 );
162
163 copy(
165 $tmpdir . '/' . $copy_task[ilCopyDefinition::COPY_TARGET_DIR]
166 );
167 }
168
169 return;
170 }
171
172
177 {
178 return 30;
179 }
180}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
An exception for terminatinating execution or to throw for unit testing.
Description of class class.
getCopyDefinitions()
Get copy definitions.
run(array $input, Observer $observer)
run the job
getExpectedTimeOfTaskInSeconds()
int the amount of seconds this task usually taskes. If your task-duration scales with the the amount ...
copyFiles($tmpdir, ilCopyDefinition $definition)
Copy files.
static ilTempnam($a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
static makeDirParents($a_dir)
Create a new directory and all parent directories.