ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilZipJob.php
Go to the documentation of this file.
1 <?php
23 
30 class ilZipJob extends AbstractJob
31 {
32  private ?ilLogger $logger;
33  private \ILIAS\Filesystem\Util\Archive\Archives $archives;
34 
38  public function __construct()
39  {
40  global $DIC;
41  $this->logger = $DIC->logger()->cal();
42  $this->archives = $DIC->archives();
43  }
44 
45 
49  public function getInputTypes(): array
50  {
51  return
52  [
53  new SingleType(StringValue::class),
54  ];
55  }
56 
57 
61  public function getOutputType(): Type
62  {
63  return new SingleType(StringValue::class);
64  }
65 
66 
70  public function isStateless(): bool
71  {
72  return true;
73  }
74 
75 
80  public function run(array $input, \ILIAS\BackgroundTasks\Observer $observer): Value
81  {
82  $this->logger->debug('Start zipping input dir!');
83  $this->logger->dump($input);
84  $string = $input[0]->getValue();
85  $tmpdir = rtrim($string, "/");
86  $this->logger->debug('Zipping directory:' . $tmpdir);
87  $zip_name = $tmpdir . '.zip';
88 
89  $zip = $this->archives->zip([]);
90  $zip->addDirectory($tmpdir);
91  $zip_stream = $zip->get();
92  stream_copy_to_stream($zip_stream->detach(), fopen($zip_name, 'wb')); // we currently have to write to disk
93 
94  // delete temp directory
95  ilFileUtils::delDir($tmpdir);
96 
97  $zip_file_name = new StringValue();
98  $zip_file_name->setValue($zip_name);
99 
100  return $zip_file_name;
101  }
102 
103 
108  {
109  return 30;
110  }
111 }
ILIAS Filesystem Util Archive Archives $archives
__construct()
Construct.
Class ChatMainBarProvider .
run(array $input, \ILIAS\BackgroundTasks\Observer $observer)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
getExpectedTimeOfTaskInSeconds()
int the amount of seconds this task usually taskes. If your task-duration scales with the the amount ...
ilLogger $logger
Description of class class.