Skip to content

Commit 23b0c3b

Browse files
authored
Fix unpublishing of documents
1 parent fbf6780 commit 23b0c3b

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/Controller/PantheonContentPublisherController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function webhook(Request $request): Response {
5050
if ($decoded['event'] === 'article.unpublish') {
5151
$this->entityQueue->createItem([
5252
'entity_type' => 'pantheon_document',
53+
'bundle' => $collection_id,
5354
'entity_id' => $entity_id,
5455
'delete' => 1,
5556
]);

src/Plugin/QueueWorker/EntityQueueWorker.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,20 @@ public static function create(ContainerInterface $container, array $configuratio
4646
*/
4747
public function processItem($data): void {
4848
$entity_type_id = $data['entity_type'];
49-
$entity = $this->entityTypeManager
50-
->getStorage($entity_type_id)
51-
->load($data['entity_id']);
52-
if ($entity) {
53-
if (empty($data['delete'])) {
54-
$entity->save();
55-
}
56-
else {
57-
$entity->delete();
58-
}
49+
$storage = $this->entityTypeManager->getStorage($entity_type_id);
50+
51+
if (empty($data['delete'])) {
52+
$entity = $storage->load($data['entity_id']);
53+
$entity->save();
54+
}
55+
else {
56+
$entityType = $this->entityTypeManager->getDefinition($entity_type_id);
57+
$entity = $storage->create([
58+
$entityType->getKey('bundle') => $data['bundle'],
59+
$entityType->getKey('id') => $data['entity_id'],
60+
]);
61+
$entity->enforceIsNew(FALSE);
62+
$entity->delete();
5963
}
6064
$index_storage = $this->entityTypeManager->getStorage('search_api_index');
6165
$datasource_id = "entity:$entity_type_id";

0 commit comments

Comments
 (0)