ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilCtrlAwareStorageUploadHandler.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 
17 
18 /******************************************************************************
19  *
20  * This file is part of ILIAS, a powerful learning management system.
21  *
22  * ILIAS is licensed with the GPL-3.0, you should have received a copy
23  * of said license along with the source code.
24  *
25  * If this is not the case or you just want to try ILIAS, you'll find
26  * us at:
27  * https://www.ilias.de
28  * https://github.com/ILIAS-eLearning
29  *
30  *****************************************************************************/
31 
38 {
40  protected \ILIAS\ResourceStorage\Services $storage;
41 
42  public function __construct(ResourceStakeholder $stakeholder)
43  {
44  global $DIC;
46  $this->storage = $DIC->resourceStorage();
47  $this->stakeholder = $stakeholder;
48  }
49 
50  protected function getUploadResult(): HandlerResult
51  {
52  $this->upload->register(new ilCountPDFPagesPreProcessors());
53  $this->upload->process();
54 
55  $result_array = $this->upload->getResults();
56  $result = end($result_array);
57 
58  if ($result instanceof UploadResult && $result->isOK()) {
59  if (!$this->is_chunked) {
60  $identifier = $this->storage->manage()->upload($result, $this->stakeholder)->serialize();
61  $status = HandlerResult::STATUS_OK;
62  $message = "file upload OK";
63  } else {
64  $identifier = '';
65  $status = HandlerResult::STATUS_FAILED;
66  $message = 'chunking not supported';
67  }
68  } else {
69  $identifier = '';
70  $status = HandlerResult::STATUS_FAILED;
71  $message = $result->getStatus()->getMessage();
72  }
73 
74  return new BasicHandlerResult($this->getFileIdentifierParameterName(), $status, $identifier, $message);
75  }
76 
77  protected function getRemoveResult(string $identifier): HandlerResult
78  {
79  if (null !== ($id = $this->storage->manage()->find($identifier))) {
80  $this->storage->manage()->remove($id, $this->stakeholder);
81  $status = HandlerResult::STATUS_OK;
82  $message = "file removal OK";
83  } else {
84  $status = HandlerResult::STATUS_OK;
85  $message = "file with identifier '$identifier' doesn't exist, nothing to do.";
86  }
87 
88  return new BasicHandlerResult($this->getFileIdentifierParameterName(), $status, $identifier, $message);
89  }
90 
91  public function getInfoResult(string $identifier): ?FileInfoResult
92  {
93  if (null !== ($id = $this->storage->manage()->find($identifier))) {
94  $revision = $this->storage->manage()->getCurrentRevision($id)->getInformation();
95  $title = $revision->getTitle();
96  $size = $revision->getSize();
97  $mime = $revision->getMimeType();
98  } else {
99  $title = $mime = 'unknown';
100  $size = 0;
101  }
102 
103  return new BasicFileInfoResult($this->getFileIdentifierParameterName(), $identifier, $title, $size, $mime);
104  }
105 
106  public function getInfoForExistingFiles(array $file_ids): array
107  {
108  $info_results = [];
109  foreach ($file_ids as $identifier) {
110  $info_results[] = $this->getInfoResult($identifier);
111  }
112 
113  return $info_results;
114  }
115 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
Class ilCtrlAwareStorageUploadHandler.
__construct(Container $dic, ilPlugin $plugin)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$message
Definition: xapiexit.php:32
Class ilCountPDFPagesPreProcessors.