ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
68  public function run(array $input, Observer $observer)
69  {
70  $cal_copy_def = $input[0];
71 
72  $this->logger->info('Called copy files job');
73 
74  $this->target_directory = $cal_copy_def->getTempDir();
75  //$this->target_directory = $input[1]->getValue();
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, $cal_copy_def);
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 
121  protected function copyFiles($tmpdir, ilCalendarCopyDefinition $definition)
122  {
123  foreach ($definition->getCopyDefinitions() as $copy_task) {
124  if (!file_exists($copy_task[ilCalendarCopyDefinition::COPY_SOURCE_DIR])) {
125  $this->logger->notice('Cannot find file: ' . $copy_task[ilCalendarCopyDefinition::COPY_SOURCE_DIR]);
126  continue;
127  }
128  $this->logger->debug('Creating directory: ' . $tmpdir . '/' . dirname($copy_task[ilCalendarCopyDefinition::COPY_TARGET_DIR]));
130  $tmpdir . '/' . dirname($copy_task[ilCalendarCopyDefinition::COPY_TARGET_DIR])
131  );
132 
133  $this->logger->debug(
134  'Copying from: ' .
135  $copy_task[ilCalendarCopyDefinition::COPY_SOURCE_DIR] .
136  ' to ' .
137  $tmpdir . '/' . $copy_task[ilCalendarCopyDefinition::COPY_TARGET_DIR]
138  );
139 
140  copy(
141  $copy_task[ilCalendarCopyDefinition::COPY_SOURCE_DIR],
142  $tmpdir . '/' . $copy_task[ilCalendarCopyDefinition::COPY_TARGET_DIR]
143  );
144  }
145  return;
146  }
147 
148 
153  {
154  return 30;
155  }
156 }
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 ...
static ilTempnam($a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.