Lucas Werkmeister (WMDE) has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/349180 )
Change subject: Don’t wipe the constraints table upon import
......................................................................
Don’t wipe the constraints table upon import
Once we start reading constraints from statements (which will also be
written to the database), the CSV file will no longer be the sole source
of constraints in the repository, so the import shouldn’t remove
constraints that don’t come from the CSV file. The easiest way to do
this (since we don’t track the source of the constraints) is to remove
the repository reset, and then to update the repository so that it can
update (replace) existing constraints.
A new option, --reset, is added to get the old behavior, in case one
wants to remove outdated constraints.
Change-Id: Iadcae75bc9384ea5bf0ac49f7fddf6a49f3bab0e
---
M includes/ConstraintRepository.php
M maintenance/UpdateConstraintsTable.php
2 files changed, 12 insertions(+), 2 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseQualityConstraints
refs/changes/80/349180/1
diff --git a/includes/ConstraintRepository.php
b/includes/ConstraintRepository.php
index dc39e52..83964c6 100644
--- a/includes/ConstraintRepository.php
+++ b/includes/ConstraintRepository.php
@@ -32,6 +32,10 @@
}
/**
+ * Batch-inserts a list of constraints into the database.
+ * If the constraint already exists (identified by its constraint ID),
+ * it is completely replaced.
+ *
* @param Constraint[] $constraints
*
* @throws DBUnexpectedError
@@ -51,7 +55,7 @@
);
$db = wfGetDB( DB_MASTER );
- return $db->insert( CONSTRAINT_TABLE, $accumulator );
+ return $db->replace( CONSTRAINT_TABLE, [ 'constraint_guid' ],
$accumulator );
}
/**
diff --git a/maintenance/UpdateConstraintsTable.php
b/maintenance/UpdateConstraintsTable.php
index 3221bfe..7372eb7 100644
--- a/maintenance/UpdateConstraintsTable.php
+++ b/maintenance/UpdateConstraintsTable.php
@@ -33,6 +33,10 @@
true,
true
);
+ $this->addOption(
+ 'reset',
+ 'Clear the constraints table before adding the
constraints.'
+ );
$this->setBatchSize( 1000 );
}
@@ -44,7 +48,9 @@
}
$constraintRepo =
ConstraintReportFactory::getDefaultInstance()->getConstraintRepository();
- $constraintRepo->deleteAll( $this->mBatchSize );
+ if ( $this->getOption( 'reset' ) ) {
+ $constraintRepo->deleteAll( $this->mBatchSize );
+ }
$this->insertValues( $constraintRepo, $csvFile );
fclose( $csvFile );
}
--
To view, visit https://gerrit.wikimedia.org/r/349180
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iadcae75bc9384ea5bf0ac49f7fddf6a49f3bab0e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseQualityConstraints
Gerrit-Branch: master
Gerrit-Owner: Lucas Werkmeister (WMDE) <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits