Skip to content

Commit

Permalink
Fixed conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
tuutti committed Oct 30, 2023
2 parents bd7acba + c8ed69e commit fa8a528
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
- name: Start services
working-directory: ${{ env.DRUPAL_ROOT }}
run: |
vendor/bin/drush runserver $SIMPLETEST_BASE_URL > /dev/null 2>&1 &
vendor/bin/drush runserver $SIMPLETEST_BASE_URL --dns > /dev/null 2>&1 &
chromedriver --port=4444 > /dev/null 2>&1 &
- name: Run PHPUnit tests
Expand Down
35 changes: 30 additions & 5 deletions src/Entity/Revision/RevisionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\TranslatableInterface;
use Drupal\Core\Entity\TranslatableRevisionableInterface;

/**
* A class to manage revisions.
Expand Down Expand Up @@ -60,7 +60,7 @@ private function assertEntityType(string $entityType) : void {
try {
$definition = $this->entityTypeManager->getDefinition($entityType);

if (!$definition->isRevisionable()) {
if (!$definition->isRevisionable() || !$definition->entityClassImplements(TranslatableRevisionableInterface::class)) {
throw new \InvalidArgumentException('Entity type does not support revisions.');
}
}
Expand Down Expand Up @@ -154,10 +154,10 @@ public function getRevisionsPerLanguage(
$revision = $storage->loadRevision($vid);

foreach ($revision->getTranslationLanguages() as $langcode => $language) {
assert($revision instanceof TranslatableInterface);
if ($revision->hasTranslation($langcode) && $revision->getTranslation($langcode)->isRevisionTranslationAffected()) {
$revisions[$langcode][] = $revision->getLoadedRevisionId();
if (!$this->isValidRevision($langcode, $revision)) {
continue;
}
$revisions[$langcode][] = $revision->getLoadedRevisionId();
}
}

Expand All @@ -168,6 +168,31 @@ public function getRevisionsPerLanguage(
return $revisions;
}

/**
* Check if given revision is valid for deletion.
*
* @param string $langcode
* The langcode.
* @param \Drupal\Core\Entity\TranslatableRevisionableInterface $revision
* The revision to test.
*
* @return bool
* TRUE if given revision is valid for deletion.
*/
private function isValidRevision(string $langcode, TranslatableRevisionableInterface $revision) : bool {
// Skip default revisions and revision without translation for given
// language.
if (!$revision->hasTranslation($langcode) || $revision->isDefaultRevision()) {
return FALSE;
}
$revision = $revision->getTranslation($langcode);

if (!$revision->isRevisionTranslationAffected() || $revision->isLatestTranslationAffectedRevision()) {
return FALSE;
}
return TRUE;
}

/**
* Gets revisions for the given entity type and id.
*
Expand Down
6 changes: 3 additions & 3 deletions tests/src/Kernel/Entity/Revision/RevisionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,16 @@ public function testRevision() : void {
$storage->createRevision($rmt)->save();
}
// Make sure items are queued on entity update.
$this->assertQueueItems(6);
$this->assertQueueItems(5);

$revisions = $this->getSut()->getRevisionsPerLanguage('remote_entity_test', $entity->id());

// We have $i + 1 revisions (11) in total, except sv, which has 10 because
// we skipped one revision on purpose.
foreach (['en' => 6, 'fi' => 6, 'sv' => 5] as $langcode => $expected) {
foreach (['en' => 5, 'fi' => 5, 'sv' => 4] as $langcode => $expected) {
$this->assertCount($expected, $revisions[$langcode]);
}
$this->assertCount(6, $this->getSut()->getRevisions('remote_entity_test', $entity->id()));
$this->assertCount(5, $this->getSut()->getRevisions('remote_entity_test', $entity->id()));

// Make sure no revisions are returned when $keep exceeds the number of
// total revisions.
Expand Down

0 comments on commit fa8a528

Please sign in to comment.