Skip to content

Commit

Permalink
Duplicate revisions on import
Browse files Browse the repository at this point in the history
  • Loading branch information
it-spiderman committed Sep 4, 2024
1 parent 45c0990 commit a33dc7c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@
"services": [
"PermissionManager",
"DataAccountingTransferEntityFactory",
"DataAccountingImporter"
"DataAccountingImporter",
"DataAccountingVerificationEngine"
]
},
{
Expand Down
18 changes: 17 additions & 1 deletion includes/API/ImportRevisionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use DataAccounting\Transfer\TransferContext;
use DataAccounting\Transfer\TransferEntityFactory;
use DataAccounting\Transfer\TransferRevisionEntity;
use DataAccounting\Verification\VerificationEngine;
use MediaWiki\Permissions\PermissionManager;
use MediaWiki\Rest\HttpException;
use MediaWiki\Rest\SimpleHandler;
Expand All @@ -20,19 +21,25 @@ class ImportRevisionHandler extends SimpleHandler {
/** @var Importer */
private $importer;

/** @var VerificationEngine */
private $verificationEngine;

/**
* @param PermissionManager $permissionManager
* @param TransferEntityFactory $transferEntityFactory
* @param Importer $importer
* @param VerificationEngine $verificationEngine
*/
public function __construct(
PermissionManager $permissionManager,
TransferEntityFactory $transferEntityFactory,
Importer $importer
Importer $importer,
VerificationEngine $verificationEngine
) {
$this->transferEntityFactory = $transferEntityFactory;
$this->importer = $importer;
$this->permissionManager = $permissionManager;
$this->verificationEngine = $verificationEngine;
}

/** @inheritDoc */
Expand All @@ -50,6 +57,15 @@ public function run() {
if ( !( $context instanceof TransferContext ) ) {
throw new HttpException( 'Context not valid' );
}

$hash = $this->getBodyData( 'revision' )['metadata']['verification_hash'] ?? null;
if ( !$hash ) {
throw new HttpException( 'Revision hash not provided' );
}
$entity = $this->verificationEngine->getLookup()->verificationEntityFromHash( $hash );
if ( $entity ) {
throw new HttpException( 'Revision already exists', 201 );
}
$revisionEntity = $this->transferEntityFactory->newRevisionEntityFromApiData(
$this->getBodyData( 'revision' )
);
Expand Down
1 change: 1 addition & 0 deletions includes/Transfer/Importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ private function prepRevision(

$revId = $revisionEntity->getContent()['rev_id'] ?? 0;
if ( $revId ) {

$revision->setID( $revId );
}

Expand Down

0 comments on commit a33dc7c

Please sign in to comment.