ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ImportUploadHandlerGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
29
35{
37 protected array $supported_mime_types;
38
39 public function __construct()
40 {
42 global $DIC;
43 $this->temp_system = $DIC->filesystem()->temp();
44 $this->supported_mime_types = ilObjectGUI::SUPPORTED_IMPORT_MIME_TYPES;
46 }
47
51 final protected function getUploadResult(): HandlerResult
52 {
53 $this->upload->process();
54
55 $result_array = $this->upload->getResults();
56 $result = end($result_array);
57
58 $tempname = '';
59 if ($result instanceof UploadResult
60 && in_array($result->getMimeType(), $this->supported_mime_types)
61 && $result->isOK()) {
62 $status = HandlerResult::STATUS_OK;
63 $message = 'Upload ok';
64 $tempname = $this->moveUploadedFileToTemp($result);
65 } else {
66 $status = HandlerResult::STATUS_FAILED;
67 $message = $result->getStatus()->getMessage();
68 }
69
70 return new BasicHandlerResult(
72 $status,
73 $tempname,
75 );
76 }
77
78 final protected function getRemoveResult(string $filename): HandlerResult
79 {
80 return new BasicHandlerResult(
82 HandlerResult::STATUS_OK,
84 "We just don't do anything here."
85 );
86 }
87
88 final public function getInfoResult(string $file_name): ?FileInfoResult
89 {
90 if ($this->temp_system->hasDir($file_name)
91 && ($files = $this->temp_system->listContents($file_name))) {
92 $path = $files[0]->getPath();
93 $filename = basename($path);
94 $title = $filename;
95 $mime = $this->temp_system->getMimeType($path);
96 $size = intval($this->temp_system->getSize($path, DataSize::Byte)->inBytes());
97
98 } else {
99 $title = $mime = 'unknown';
100 $size = 0;
101 }
102
103 return new BasicFileInfoResult(
105 $file_name,
106 $title,
107 $size,
108 $mime
109 );
110 }
111
115 final public function getInfoForExistingFiles(array $file_names): array
116 {
117 return [$this->getInfoResult($file_names[0])];
118 }
119
120 final protected function moveUploadedFileToTemp(UploadResult $result): string
121 {
122 $tempfile_path = uniqid('tmp');
123 $this->temp_system->createDir($tempfile_path);
124 $this->temp_system->put(
125 $tempfile_path . DIRECTORY_SEPARATOR . ilFileUtils::getValidFilename($result->getName()),
126 file_get_contents($result->getPath())
127 );
128 return $tempfile_path;
129 }
130}
$filename
Definition: buildRTE.php:78
This class provides the data size with additional information to remove the work to calculate the siz...
Definition: DataSize.php:31
moveUploadedFileToTemp(UploadResult $result)
static getValidFilename(string $a_filename)
const SUPPORTED_IMPORT_MIME_TYPES
The filesystem interface provides the public interface for the Filesystem service API consumer.
Definition: Filesystem.php:37
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$path
Definition: ltiservices.php:30
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26
$message
Definition: xapiexit.php:31