Skip to content

Commit

Permalink
Fix #6158. Entity save command does not properly check for revision s…
Browse files Browse the repository at this point in the history
…upport (#6168)

* Fix #6158.
Entity save command does not properly check for revision support

* phpstan
  • Loading branch information
weitzman authored Nov 22, 2024
1 parent f17a1d7 commit 344ffc9
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Commands/core/EntityCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\Query\QueryInterface;
use Drupal\Core\Entity\RevisionableInterface;
use Drupal\Core\Entity\RevisionLogInterface;
use Drupal\Core\Session\AccountInterface;
use Drush\Attributes as CLI;
Expand Down Expand Up @@ -181,8 +180,9 @@ public function doSave(string $entity_type, array $ids, ?string $action, ?string
$message = [];
$storage = $this->entityTypeManager->getStorage($entity_type);
$entities = $storage->loadMultiple($ids);
$is_revisionable = $this->entityTypeManager->getDefinition($entity_type)->isRevisionable();
foreach ($entities as $entity) {
if (is_a($entity, RevisionableInterface::class)) {
if ($is_revisionable) {
/** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
$storage = \Drupal::entityTypeManager()->getStorage($entity->getEntityTypeId());
$entity = $storage->createRevision($entity, true);
Expand Down Expand Up @@ -211,7 +211,9 @@ public function doSave(string $entity_type, array $ids, ?string $action, ?string
$message = 'Unpublished.';
}
}
if (is_a($entity, RevisionLogInterface::class)) {
if ($is_revisionable) {
// This line satisfies the bully that is phpstan.
assert($entity instanceof RevisionLogInterface);
$entity->setRevisionLogMessage('Re-saved by Drush entity:save. ' . $message);
$entity->setRevisionCreationTime($this->time->getRequestTime());
$entity->setRevisionUserId($this->currentUser->id());
Expand Down

0 comments on commit 344ffc9

Please sign in to comment.