ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilCalendarCopyFilesToTempDirectoryJob.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 
29  protected $target_directory;
30 
34  public function __construct()
35  {
36  $this->logger = $GLOBALS['DIC']->logger()->cal();
37  }
38 
41  public function getInputTypes()
42  {
43  return
44  [
45  new SingleType(ilCalendarCopyDefinition::class)
46  ];
47  }
48 
53  public function getOutputType()
54  {
55  return new SingleType(StringValue::class);
56  }
57 
58  public function isStateless()
59  {
60  return true;
61  }
62 
73  public function run(array $input, Observer $observer)
74  {
75  $cal_copy_def = $input[0];
76 
77  $this->logger->info('Called copy files job');
78 
79  $this->target_directory = $cal_copy_def->getTempDir();
80  //$this->target_directory = $input[1]->getValue();
81 
82  // create temp directory
83  $tmpdir = $this->createUniqueTempDirectory();
84  $targetdir = $this->createTargetDirectory($tmpdir);
85 
86  // copy files from source to temp directory
87  //$this->copyFiles($targetdir, $input[0]);
88  $this->copyFiles($targetdir, $cal_copy_def);
89 
90  // zip
91 
92  // return zip file name
93  $this->logger->debug('Returning new tempdirectory: ' . $targetdir);
94 
95  $out = new StringValue();
96  $out->setValue($targetdir);
97  return $out;
98  }
99 
105  protected function createUniqueTempDirectory()
106  {
107  $tmpdir = ilUtil::ilTempnam();
108  ilUtil::makeDirParents($tmpdir);
109  $this->logger->info('New temp directory: ' . $tmpdir);
110  return $tmpdir;
111  }
112 
113  protected function createTargetDirectory($a_tmpdir)
114  {
115  $final_dir = $a_tmpdir . "/" . $this->target_directory;
116  ilUtil::makeDirParents($final_dir);
117  $this->logger->info('New final directory: ' . $final_dir);
118  return $final_dir;
119  }
120 
126  protected function copyFiles($tmpdir, ilCalendarCopyDefinition $definition)
127  {
128  foreach ($definition->getCopyDefinitions() as $copy_task) {
129  if (!file_exists($copy_task[ilCalendarCopyDefinition::COPY_SOURCE_DIR])) {
130  $this->logger->notice('Cannot find file: ' . $copy_task[ilCalendarCopyDefinition::COPY_SOURCE_DIR]);
131  continue;
132  }
133  $this->logger->debug('Creating directory: ' . $tmpdir . '/' . dirname($copy_task[ilCalendarCopyDefinition::COPY_TARGET_DIR]));
135  $tmpdir . '/' . dirname($copy_task[ilCalendarCopyDefinition::COPY_TARGET_DIR])
136  );
137 
138  $this->logger->debug(
139  'Copying from: ' .
140  $copy_task[ilCalendarCopyDefinition::COPY_SOURCE_DIR] .
141  ' to ' .
142  $tmpdir . '/' . $copy_task[ilCalendarCopyDefinition::COPY_TARGET_DIR]
143  );
144 
145  copy(
146  $copy_task[ilCalendarCopyDefinition::COPY_SOURCE_DIR],
147  $tmpdir . '/' . $copy_task[ilCalendarCopyDefinition::COPY_TARGET_DIR]
148  );
149  }
150  return;
151  }
152 
153 
158  {
159  return 30;
160  }
161 }
static makeDirParents($a_dir)
Create a new directory and all parent directories.
getCopyDefinitions()
Get copy definitions.
run(array $input, Observer $observer)
run the job
copyFiles($tmpdir, ilCalendarCopyDefinition $definition)
Copy files.
getExpectedTimeOfTaskInSeconds()
int the amount of seconds this task usually taskes. If your task-duration scales with the the amount ...
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
Create styles array
The data for the language used.
static ilTempnam($a_temp_path=null)
Create a temporary file in an ILIAS writable directory.