ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilCopyWorkspaceFilesToTempDirectoryJob.php
Go to the documentation of this file.
1<?php
2
10
11/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
12
20{
24 private $logger = null;
25
30
31
35 public function __construct()
36 {
37 $this->logger = ilLoggerFactory::getLogger("pwsp");
38 }
39
42 public function getInputTypes()
43 {
44 return
45 [
46 new SingleType(ilWorkspaceCopyDefinition::class)
47 ];
48 }
49
54 public function getOutputType()
55 {
56 return new SingleType(StringValue::class);
57 }
58
59 public function isStateless()
60 {
61 return true;
62 }
63
69 public function run(array $input, Observer $observer)
70 {
71 $definition = $input[0];
72
73 $this->logger->info('Called copy files job');
74
75 $this->target_directory = $definition->getTempDir();
76
77 // create temp directory
78 $tmpdir = $this->createUniqueTempDirectory();
79 $targetdir = $this->createTargetDirectory($tmpdir);
80
81 // copy files from source to temp directory
82 //$this->copyFiles($targetdir, $input[0]);
83 $this->copyFiles($targetdir, $definition);
84
85 // zip
86
87 // return zip file name
88 $this->logger->debug('Returning new tempdirectory: ' . $targetdir);
89
90 $out = new StringValue();
91 $out->setValue($targetdir);
92 return $out;
93 }
94
100 protected function createUniqueTempDirectory()
101 {
102 $tmpdir = ilUtil::ilTempnam();
103 ilUtil::makeDirParents($tmpdir);
104 $this->logger->info('New temp directory: ' . $tmpdir);
105 return $tmpdir;
106 }
107
108 protected function createTargetDirectory($a_tmpdir)
109 {
110 $final_dir = $a_tmpdir . "/" . $this->target_directory;
111 ilUtil::makeDirParents($final_dir);
112 $this->logger->info('New final directory: ' . $final_dir);
113 return $final_dir;
114 }
115
122 protected function copyFiles($tmpdir, ilWorkspaceCopyDefinition $definition)
123 {
124 foreach ($definition->getCopyDefinitions() as $copy_task) {
125 if (!file_exists($copy_task[ilWorkspaceCopyDefinition::COPY_SOURCE_DIR])) {
126 // 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
127 $is_empty_folder = preg_match_all("/\/$/", $copy_task[ilWorkspaceCopyDefinition::COPY_TARGET_DIR]);
128 if ($is_empty_folder) {
129 mkdir($tmpdir . '/' . $copy_task[ilWorkspaceCopyDefinition::COPY_TARGET_DIR]);
130 $this->logger->notice('Empty folder has been created: ' . $tmpdir . '/' . $copy_task[ilWorkspaceCopyDefinition::COPY_SOURCE_DIR]);
131 } else {
132 $this->logger->notice('Cannot find file: ' . $copy_task[ilWorkspaceCopyDefinition::COPY_SOURCE_DIR]);
133 }
134 continue;
135 }
136 $this->logger->debug('Creating directory: ' . $tmpdir . '/' . dirname($copy_task[ilWorkspaceCopyDefinition::COPY_TARGET_DIR]));
138 $tmpdir . '/' . dirname($copy_task[ilWorkspaceCopyDefinition::COPY_TARGET_DIR])
139 );
140
141 $this->logger->debug(
142 'Copying from: ' .
144 ' to ' .
145 $tmpdir . '/' . $copy_task[ilWorkspaceCopyDefinition::COPY_TARGET_DIR]
146 );
147
148 copy(
150 $tmpdir . '/' . $copy_task[ilWorkspaceCopyDefinition::COPY_TARGET_DIR]
151 );
152 }
153 return;
154 }
155
160 {
161 return 30;
162 }
163}
An exception for terminatinating execution or to throw for unit testing.
getExpectedTimeOfTaskInSeconds()
int the amount of seconds this task usually taskes. If your task-duration scales with the the amount ...
copyFiles($tmpdir, ilWorkspaceCopyDefinition $definition)
Copy files.
static getLogger($a_component_id)
Get component logger.
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.
Copy definition for worspace folders.