ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
DownloadAllCollectFilesJob.php
Go to the documentation of this file.
1<?php
2
20
27
33{
34 private ?\ilLogger $logger = null;
35 protected int $user_id = 0;
36 protected int $mcst_id = 0;
37 protected int $mcst_ref_id = 0;
38 protected \ilLanguage $lng;
39 protected string $target_directory = "";
40 protected string $temp_dir = "";
41 protected string $sanitized_title = "";
42 protected \ilObjMediaCast $media_cast;
43
44 public function __construct()
45 {
46 global $DIC;
47 $this->lng = $DIC->language();
48 $this->lng->loadLanguageModule('mcst');
49 $this->logger = $DIC->logger()->mcst();
50
51 $this->sanitized_title = "images";
52 }
53
54 public function getInputTypes(): array
55 {
56 return
57 [
58 new SingleType(IntegerValue::class),
59 new SingleType(IntegerValue::class)
60 ];
61 }
62
64 {
65 return new SingleType(StringValue::class);
66 }
67
68 public function isStateless(): bool
69 {
70 return true;
71 }
72
74 {
75 return 30;
76 }
77
78 public function run(array $input, Observer $observer): StringValue
79 {
80 $this->user_id = $input[0]->getValue();
81 $this->mcst_ref_id = $input[1]->getValue();
82
83 $this->logger->debug("Get Mediacast " . $this->mcst_ref_id);
84 $this->media_cast = new \ilObjMediaCast($this->mcst_ref_id);
85
86 $target_dir = $this->createDirectory();
87
88 $this->logger->debug("Collect in " . $target_dir);
89 $this->collectMediaFiles($target_dir);
90 $this->logger->debug("Finished collecting.");
91
92 $out = new StringValue();
93 $out->setValue($target_dir);
94 return $out;
95 }
96
97 protected function createDirectory(): string
98 {
99 // temp dir
100 $this->temp_dir = \ilFileUtils::ilTempnam();
101
102 // target dir
103 $path = $this->temp_dir . DIRECTORY_SEPARATOR;
104 $this->target_directory = $path . $this->sanitized_title;
105 \ilFileUtils::makeDirParents($this->target_directory);
106
108 }
109
110 public function collectMediaFiles(string $target_dir): void
111 {
112 $cnt = 0;
113 foreach ($this->media_cast->getSortedItemsArray() as $item) {
114 $mob = new \ilObjMediaObject($item["mob_id"]);
115 $med = $mob->getMediaItem("Standard");
116
117 $cnt++;
118 $str_cnt = str_pad($cnt, 4, "0", STR_PAD_LEFT);
119
120 if ($med->getLocationType() === "Reference") {
121 $resource = $med->getLocation();
122 copy($resource, $target_dir . DIRECTORY_SEPARATOR . $str_cnt . basename($resource));
123 } else {
124 try { // this skips broken objects
125 $stream = $med->getLocationStream();
126 file_put_contents(
127 $target_dir . DIRECTORY_SEPARATOR . $str_cnt . $med->getLocation(),
128 $stream->getContents()
129 );
130 } catch (\Exception $e) {
131 }
132 }
133 }
134 }
135}
$out
Definition: buildRTE.php:24
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
Component logger with individual log levels by component id.
$path
Definition: ltiservices.php:30
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26