Skip to content

Commit 8b108b5

Browse files
committed
Protect against excessive insert on view
1 parent 4de5849 commit 8b108b5

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/PantheonDocumentStorage.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Drupal\Core\KeyValueStore\KeyValueStoreInterface;
1919
use Drupal\pantheon_content_publisher\Entity\PantheonDocument;
2020
use Symfony\Component\DependencyInjection\ContainerInterface;
21+
use Symfony\Component\HttpFoundation\RequestStack;
2122

2223
/**
2324
* Provides a list controller for the pantheon content publisher entity type.
@@ -37,6 +38,7 @@ public function __construct(
3738
protected EntityStorageInterface $collectionStorage,
3839
protected PantheonContentPublisherConverter $pantheonContentPublisherConverter,
3940
KeyValueFactoryInterface $keyValueFactory,
41+
protected RequestStack $requestStack,
4042
) {
4143
$this->seenStore = $keyValueFactory->get('pantheon_document.seen');
4244
parent::__construct($entity_type, $entity_field_manager, $cache, $memory_cache, $entity_type_bundle_info);
@@ -51,7 +53,8 @@ public static function createInstance(ContainerInterface $container, EntityTypeI
5153
$container->get('entity_type.bundle.info'),
5254
$container->get('entity_type.manager')->getStorage('pantheon_document_collection'),
5355
$container->get('pantheon_content_publisher.converter'),
54-
$container->get('keyvalue')
56+
$container->get('keyvalue'),
57+
$container->get('request_stack'),
5558
);
5659
}
5760

@@ -71,7 +74,7 @@ protected function doLoadMultiple(?array $ids = NULL) {
7174
$drupal_data = $this->pantheonContentPublisherConverter
7275
->convert($pantheon_data, $collection_name, $id);
7376
$document = PantheonDocument::create($drupal_data);
74-
if ($this->seenStore->setIfNotExists($id, 1)) {
77+
if ($this->requestStack->getCurrentRequest()->getMethod() === 'POST' && $this->seenStore->setIfNotExists($id, 1)) {
7578
$this->invokeHook('insert', $document);
7679
}
7780
$entities[$id] = $document->enforceIsNew(FALSE);

0 commit comments

Comments
 (0)