Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"InfoAction": "ProfessionalWiki\\PersistentPageIdentifiers\\EntryPoints\\PersistentPageIdentifiersHooks::onInfoAction",
"LoadExtensionSchemaUpdates": "ProfessionalWiki\\PersistentPageIdentifiers\\EntryPoints\\PersistentPageIdentifiersHooks::onLoadExtensionSchemaUpdates",
"ParserFirstCallInit": "ProfessionalWiki\\PersistentPageIdentifiers\\EntryPoints\\PersistentPageIdentifiersHooks::onParserFirstCallInit",
"PageSaveComplete": "ProfessionalWiki\\PersistentPageIdentifiers\\EntryPoints\\PersistentPageIdentifiersHooks::onPageSaveComplete"
"PageSaveComplete": "ProfessionalWiki\\PersistentPageIdentifiers\\EntryPoints\\PersistentPageIdentifiersHooks::onPageSaveComplete",
"RevisionUndeleted": "ProfessionalWiki\\PersistentPageIdentifiers\\EntryPoints\\PersistentPageIdentifiersHooks::onRevisionUndeleted"
},

"config": {
Expand Down
16 changes: 16 additions & 0 deletions src/EntryPoints/PersistentPageIdentifiersHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,20 @@ public static function onPageSaveComplete(
PersistentPageIdentifiersExtension::getInstance()->newCreatePersistentPageIdentifier()->createId( $wikiPage->getId() );
}

public static function onRevisionUndeleted( RevisionRecord $restoredRevision, ?int $oldPageId ): void {
if ( $oldPageId !== null ) {
return;
}

// TODO: untested
$repo = PersistentPageIdentifiersExtension::getInstance()->getPersistentPageIdentifiersRepo();
$oldPersistentId = $repo->getPersistentId( $restoredRevision->getPageId() );

if ( $oldPersistentId === null ) {
return;
}

$repo->savePersistentId( $restoredRevision->getPageId(), $oldPersistentId );
Comment on lines +61 to +69
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is incomplete anyway, since we'll need to remove the old row in persistent_page_ids table due to the UNIQUE constraint.

Otherwise, we can drop the constraint, but then we end up with different page_ids mapping to the same persistent_id. This seems fundamentally wrong:

  • there should be only one page with a specific persistent ID
  • if deleted page_id=1 has persistent_id=FOO, and an undelete leads to it becoming page_id=2 with peristent_id=FOO, would it still be possible to undelete page_id=1 again?

But the above is dependent on figuring out when a page ID is missing in the first place.

}

}
44 changes: 44 additions & 0 deletions tests/Integration/PageUndeleteIntegrationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare( strict_types = 1 );

namespace ProfessionalWiki\PersistentPageIdentifiers\Tests\Integration;

use ProfessionalWiki\PersistentPageIdentifiers\Adapters\DatabasePersistentPageIdentifiersRepo;
use ProfessionalWiki\PersistentPageIdentifiers\Application\PersistentPageIdentifiersRepo;
use ProfessionalWiki\PersistentPageIdentifiers\Tests\PersistentPageIdentifiersIntegrationTest;
use WikiPage;

/**
* @covers \ProfessionalWiki\PersistentPageIdentifiers\EntryPoints\PersistentPageIdentifiersHooks::onRevisionUndeleted
* @group Database
*/
class PageUndeleteIntegrationTest extends PersistentPageIdentifiersIntegrationTest {

private PersistentPageIdentifiersRepo $repo;

protected function setUp(): void {
parent::setUp();
$this->tablesUsed[] = 'persistent_page_ids';
$this->repo = new DatabasePersistentPageIdentifiersRepo( $this->db );
}

public function testUndeletedPageWithOldPageIdHasSamePersistentId(): void {
$page = $this->createPageWithText();
$pageId = $page->getId();
$persistentId = $this->repo->getPersistentId( $pageId );

$this->deletePage( $page );
$this->undeletePage( $page );

$this->assertSame( $pageId, $page->getId() );
$this->assertSame( $persistentId, $this->repo->getPersistentId( $pageId ) );
}

private function undeletePage( WikiPage $page ): void {
$this->getServiceContainer()->getUndeletePageFactory()
->newUndeletePage( $page, $this->getTestUser()->getAuthority() )
->undeleteUnsafe( 'test undelete' );
}

}