ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
Publisher.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ilLogger;
24use ilAccess;
31
33{
34 public function __construct(
35 protected ExposedRecordsRepository $exposed_repo,
36 protected ResourceStatusRepository $status_repo,
37 protected RepoObjectHandler $repo_object_handler,
38 protected ExportHandler $export_handler,
39 protected PublishingSettings $publishing_settings,
40 protected SimpleDCXMLWriter $xml_writer,
41 protected ilAccess $access
42 ) {
43 }
44
45 public function block(int $obj_id): void
46 {
47 $this->status_repo->setHarvestingBlocked($obj_id, true);
48 }
49
50 public function checkPermissionsForBlock(int $ref_id, string $type, int $obj_id): bool
51 {
52 return $this->access->checkAccess('write', '', $ref_id, $type, $obj_id);
53 }
54
55 public function unblock(int $obj_id): void
56 {
57 $this->status_repo->setHarvestingBlocked($obj_id, false);
58 }
59
60 public function checkPermissionsForUnblock(int $ref_id, string $type, int $obj_id): bool
61 {
62 return $this->access->checkAccess('write', '', $ref_id, $type, $obj_id);
63 }
64
65 public function publish(int $obj_id, string $type): void
66 {
67 $target_ref_id = $this->publishing_settings->getContainerRefIDForPublishing();
68 $new_ref_id = $this->harvestObject($obj_id, $target_ref_id);
69 $this->publishObjectToOAIPMH($obj_id, $type, $new_ref_id);
70 }
71
72 public function checkPermissionsForPublish(int $ref_id, string $type, int $obj_id): bool
73 {
74 $target_ref_id = $this->publishing_settings->getContainerRefIDForPublishing();
75 return $this->access->checkAccess('write', '', $ref_id, $type, $obj_id) &&
76 $this->access->checkAccess('create_' . $type, '', $target_ref_id);
77 }
78
79 public function withdraw(int $obj_id): void
80 {
81 $this->exposed_repo->updateRecord($obj_id, true, null);
82
83 $ref_id = $this->status_repo->getHarvestRefID($obj_id);
85 $this->status_repo->deleteHarvestRefID($obj_id);
86
87 if ($this->publishing_settings->isAutomaticPublishingEnabled()) {
88 $this->block($obj_id);
89 }
90 }
91
92 public function checkPermissionsForWithdraw(int $ref_id, string $type, int $obj_id): bool
93 {
94 $harvested_ref_id = $this->status_repo->getHarvestRefID($obj_id);
95 return $this->access->checkAccess('write', '', $ref_id, $type, $obj_id) &&
96 $this->access->checkAccess('delete', '', $harvested_ref_id, $type, $obj_id);
97 }
98
99 public function submit(int $obj_id): void
100 {
101 $target_ref_id = $this->publishing_settings->getContainerRefIDForEditorialStep();
102 $this->harvestObject($obj_id, $target_ref_id);
103 }
104
105 public function checkPermissionsForSubmit(int $ref_id, string $type, int $obj_id): bool
106 {
107 $target_ref_id = $this->publishing_settings->getContainerRefIDForEditorialStep();
108 return $this->access->checkAccess('write', '', $ref_id, $type, $obj_id) &&
109 $this->access->checkAccess('create_' . $type, '', $target_ref_id);
110 }
111
112 public function accept(int $obj_id, string $type): void
113 {
114 $harvested_ref_id = $this->status_repo->getHarvestRefID($obj_id);
115
116 $publishing_ref_id = $this->publishing_settings->getContainerRefIDForPublishing();
117 $ref_id_in_publishing = $this->repo_object_handler->referenceObjectInTargetContainer($obj_id, $publishing_ref_id);
118 $this->status_repo->setHarvestRefID($obj_id, $ref_id_in_publishing);
119
120 $this->deleteReferenceIfOthersExist($harvested_ref_id);
121
122 $this->publishObjectToOAIPMH($obj_id, $type, $ref_id_in_publishing);
123 }
124
125 public function checkPermissionsForAccept(int $ref_id, string $type, int $obj_id): bool
126 {
127 $publishing_ref_id = $this->publishing_settings->getContainerRefIDForPublishing();
128 $harvested_ref_id = $this->status_repo->getHarvestRefID($obj_id);
129 return $this->access->checkAccess('write', '', $ref_id, $type, $obj_id) &&
130 $this->access->checkAccess('delete', '', $harvested_ref_id, $type, $obj_id) &&
131 $this->access->checkAccess('create_' . $type, '', $publishing_ref_id);
132 }
133
134 public function reject(int $obj_id): void
135 {
136 $ref_id = $this->status_repo->getHarvestRefID($obj_id);
138 $this->status_repo->deleteHarvestRefID($obj_id);
139
140 if ($this->publishing_settings->isAutomaticPublishingEnabled()) {
141 $this->block($obj_id);
142 }
143 }
144
145 public function checkPermissionsForReject(int $ref_id, string $type, int $obj_id): bool
146 {
147 $harvested_ref_id = $this->status_repo->getHarvestRefID($obj_id);
148 return $this->access->checkAccess('write', '', $ref_id, $type, $obj_id) &&
149 $this->access->checkAccess('delete', '', $harvested_ref_id, $type, $obj_id);
150 }
151
152 protected function harvestObject(int $obj_id, int $target_ref_id): int
153 {
154 $new_ref_id = $this->repo_object_handler->referenceObjectInTargetContainer(
155 $obj_id,
156 $target_ref_id
157 );
158 $this->status_repo->setHarvestRefID($obj_id, $new_ref_id);
159
160 if (!$this->export_handler->hasPublicAccessExport($obj_id)) {
161 $this->export_handler->createPublicAccessExport($obj_id);
162 }
163 return $new_ref_id;
164 }
165
166 protected function publishObjectToOAIPMH(int $obj_id, string $type, int $ref_id): void
167 {
168 $simple_dc_xml = $this->xml_writer->writeSimpleDCMetaData(
169 $obj_id,
170 $ref_id,
171 $type
172 );
173 if ($this->exposed_repo->doesRecordExistForObjID($obj_id)) {
174 $this->exposed_repo->updateRecord(
175 $obj_id,
176 false,
177 $simple_dc_xml
178 );
179 } else {
180 $this->exposed_repo->createRecord(
181 $obj_id,
182 $this->buildIdentifier($obj_id, $type),
183 $simple_dc_xml
184 );
185 }
186 }
187
188 protected function deleteReferenceIfOthersExist(int $ref_id): void
189 {
190 if ($this->repo_object_handler->isOnlyReference($ref_id)) {
191 return;
192 }
193 $this->repo_object_handler->deleteReference($ref_id);
194 }
195
196 protected function buildIdentifier(int $obj_id, string $type): string
197 {
198 return 'il__' . $type . '_' . $obj_id;
199 }
200}
checkPermissionsForBlock(int $ref_id, string $type, int $obj_id)
Definition: Publisher.php:50
checkPermissionsForReject(int $ref_id, string $type, int $obj_id)
Definition: Publisher.php:145
buildIdentifier(int $obj_id, string $type)
Definition: Publisher.php:196
checkPermissionsForSubmit(int $ref_id, string $type, int $obj_id)
Definition: Publisher.php:105
publishObjectToOAIPMH(int $obj_id, string $type, int $ref_id)
Definition: Publisher.php:166
checkPermissionsForWithdraw(int $ref_id, string $type, int $obj_id)
Definition: Publisher.php:92
checkPermissionsForAccept(int $ref_id, string $type, int $obj_id)
Definition: Publisher.php:125
harvestObject(int $obj_id, int $target_ref_id)
Definition: Publisher.php:152
checkPermissionsForUnblock(int $ref_id, string $type, int $obj_id)
Definition: Publisher.php:60
checkPermissionsForPublish(int $ref_id, string $type, int $obj_id)
Definition: Publisher.php:72
__construct(protected ExposedRecordsRepository $exposed_repo, protected ResourceStatusRepository $status_repo, protected RepoObjectHandler $repo_object_handler, protected ExportHandler $export_handler, protected PublishingSettings $publishing_settings, protected SimpleDCXMLWriter $xml_writer, protected ilAccess $access)
Definition: Publisher.php:34
Class ilAccessHandler Checks access for ILIAS objects.
Component logger with individual log levels by component id.
$ref_id
Definition: ltiauth.php:66