ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCtrlAwareStorageUploadHandler.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
29
36{
37 protected Services $storage;
38
39 public function __construct(protected ResourceStakeholder $stakeholder)
40 {
41 global $DIC;
43 $this->storage = $DIC->resourceStorage();
44 }
45
46 protected function getUploadResult(): HandlerResult
47 {
48 $this->upload->register(new ilCountPDFPagesPreProcessors());
49 $this->upload->process();
50
51 $result_array = $this->upload->getResults();
52 $result = end($result_array);
53
54 if ($result instanceof UploadResult && $result->isOK()) {
55 if (!$this->is_chunked) {
56 $identifier = $this->storage->manage()->upload($result, $this->stakeholder)->serialize();
57 $status = HandlerResult::STATUS_OK;
58 $message = "file upload OK";
59 } else {
60 $identifier = '';
61 $status = HandlerResult::STATUS_FAILED;
62 $message = 'chunking not supported';
63 }
64 } else {
65 $identifier = '';
66 $status = HandlerResult::STATUS_FAILED;
67 $message = $result->getStatus()->getMessage();
68 }
69
70 return new BasicHandlerResult($this->getFileIdentifierParameterName(), $status, $identifier, $message);
71 }
72
73 protected function getRemoveResult(string $identifier): HandlerResult
74 {
75 if (null !== ($id = $this->storage->manage()->find($identifier))) {
76 $this->storage->manage()->remove($id, $this->stakeholder);
77 $status = HandlerResult::STATUS_OK;
78 $message = "file removal OK";
79 } else {
80 $status = HandlerResult::STATUS_OK;
81 $message = "file with identifier '$identifier' doesn't exist, nothing to do.";
82 }
83
84 return new BasicHandlerResult($this->getFileIdentifierParameterName(), $status, $identifier, $message);
85 }
86
87 public function getInfoResult(string $identifier): ?FileInfoResult
88 {
89 if (null !== ($id = $this->storage->manage()->find($identifier))) {
90 $revision = $this->storage->manage()->getCurrentRevision($id)->getInformation();
91 $title = $revision->getTitle();
92 $size = $revision->getSize();
93 $mime = $revision->getMimeType();
94 } else {
95 $title = $mime = 'unknown';
96 $size = 0;
97 }
98
99 return new BasicFileInfoResult($this->getFileIdentifierParameterName(), $identifier, $title, $size, $mime);
100 }
101
102 public function getInfoForExistingFiles(array $file_ids): array
103 {
104 $info_results = [];
105 foreach ($file_ids as $identifier) {
106 $info_results[] = $this->getInfoResult($identifier);
107 }
108
109 return $info_results;
110 }
111}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Class ilCountPDFPagesPreProcessors.
Class ilCtrlAwareStorageUploadHandler.
__construct(protected ResourceStakeholder $stakeholder)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26
$message
Definition: xapiexit.php:31