Addshore has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/363599 )
Change subject: Make sure a page is created as part of first operation
......................................................................
Make sure a page is created as part of first operation
Prior to this file revsions were imported first,
apparently these do not necesarily create a page entry
and thus if these break can leave the site in a bit of
a broken state.
By creating a text revision first a page entry will always
be created. If more things then fail the page can simply be
deleted.
Bug: T147451
Change-Id: I91f01dd75926c694c8d07fc3694839eca70e5531
---
M src/Data/ImportOperations.php
M src/Interfaces/ImportOperation.php
M src/Operations/FileRevisionFromRemoteUrl.php
M src/Operations/TextRevisionFromTextRevision.php
M src/Services/Importer.php
5 files changed, 13 insertions(+), 55 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/FileImporter
refs/changes/99/363599/1
diff --git a/src/Data/ImportOperations.php b/src/Data/ImportOperations.php
index e96f05b..0a5e988 100644
--- a/src/Data/ImportOperations.php
+++ b/src/Data/ImportOperations.php
@@ -68,20 +68,4 @@
return true;
}
- /**
- * Rollback this operation to persistent storage.
- * @return bool success
- */
- public function rollback() {
- $this->throwExceptionOnBadState( self::COMMIT_RUN );
- $this->state = self::ROLLBACK_RUN;
- foreach ( $this->importOperations as $importOperation ) {
- if ( !$importOperation->rollback() ) {
- // TODO log?
- return false;
- }
- }
- return true;
- }
-
}
diff --git a/src/Interfaces/ImportOperation.php
b/src/Interfaces/ImportOperation.php
index 16c3522..08069dd 100644
--- a/src/Interfaces/ImportOperation.php
+++ b/src/Interfaces/ImportOperation.php
@@ -17,10 +17,4 @@
*/
public function commit();
- /**
- * Rollback this operation to persistent storage.
- * @return bool success
- */
- public function rollback();
-
}
diff --git a/src/Operations/FileRevisionFromRemoteUrl.php
b/src/Operations/FileRevisionFromRemoteUrl.php
index 0b73aff..8ccd8a7 100644
--- a/src/Operations/FileRevisionFromRemoteUrl.php
+++ b/src/Operations/FileRevisionFromRemoteUrl.php
@@ -96,13 +96,4 @@
return $this->wikiRevision->importUpload();
}
- /**
- * Rollback this operation to persistent storage.
- * @return bool success
- */
- public function rollback() {
- // TODO: Implement rollback() method.
- return false;
- }
-
}
diff --git a/src/Operations/TextRevisionFromTextRevision.php
b/src/Operations/TextRevisionFromTextRevision.php
index 9e0971b..e1b10b6 100644
--- a/src/Operations/TextRevisionFromTextRevision.php
+++ b/src/Operations/TextRevisionFromTextRevision.php
@@ -60,13 +60,4 @@
return $this->wikiRevision->importOldRevision();
}
- /**
- * Rollback this operation to persistent storage.
- * @return bool success
- */
- public function rollback() {
- // TODO: Implement rollback() method.
- return false;
- }
-
}
diff --git a/src/Services/Importer.php b/src/Services/Importer.php
index 0238353..8340fa4 100644
--- a/src/Services/Importer.php
+++ b/src/Services/Importer.php
@@ -86,6 +86,18 @@
// TODO the type of ImportOperation created should be decided
somewhere
+ /**
+ * Text revisions should be added first. See T147451.
+ * This ensures that the page entry is created and if something
fails it can thus be deleted.
+ */
+ foreach ( $importDetails->getTextRevisions()->toArray() as
$textRevision ) {
+ $importOperations->add( new
TextRevisionFromTextRevision(
+ $plannedTitle,
+ $textRevision,
+ $this->wikiRevisionFactory
+ ) );
+ }
+
foreach ( $importDetails->getFileRevisions()->toArray() as
$fileRevision ) {
$importOperations->add( new FileRevisionFromRemoteUrl(
$plannedTitle,
@@ -96,14 +108,6 @@
) );
}
- foreach ( $importDetails->getTextRevisions()->toArray() as
$textRevision ) {
- $importOperations->add( new
TextRevisionFromTextRevision(
- $plannedTitle,
- $textRevision,
- $this->wikiRevisionFactory
- ) );
- }
-
if ( !$importOperations->prepare() ) {
$this->logger->error( 'Failed to prepare operations.' );
throw new RuntimeException( 'Failed to prepare
operations.' );
@@ -111,13 +115,7 @@
if ( !$importOperations->commit() ) {
$this->logger->error( 'Failed to commit operations.' );
- if ( !$importOperations->rollback() ) {
- $this->logger->critical( 'Failed to rollback
operations.' );
- throw new RuntimeException( 'Failed to commit
and rollback operations.' );
- } else {
- $this->logger->info( 'Successfully rolled back
operations' );
- throw new RuntimeException( 'Failed to commit
operations, but rolled back successfully!' );
- }
+ throw new RuntimeException( 'Failed to commit
operations.' );
}
// TODO the below should be an ImportOperation
--
To view, visit https://gerrit.wikimedia.org/r/363599
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I91f01dd75926c694c8d07fc3694839eca70e5531
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/FileImporter
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits