jenkins-bot has submitted this change and it was merged.
Change subject: Update rows with missing workflow_page_id
......................................................................
Update rows with missing workflow_page_id
In some cases we have created workflow instances before the related Title
has an ArticleID assigned to it. This goes through and sets that value.
Change-Id: I7a48f09fcdcb9ec3def002e4ad907b2c59f64687
---
A maintenance/FlowUpdateWorkflowPageId.php
1 file changed, 110 insertions(+), 0 deletions(-)
Approvals:
Matthias Mullie: Looks good to me, approved
jenkins-bot: Verified
diff --git a/maintenance/FlowUpdateWorkflowPageId.php
b/maintenance/FlowUpdateWorkflowPageId.php
new file mode 100644
index 0000000..5056ecd
--- /dev/null
+++ b/maintenance/FlowUpdateWorkflowPageId.php
@@ -0,0 +1,110 @@
+<?php
+
+use Flow\Container;
+use Flow\Model\UUID;
+
+$IP = getenv( 'MW_INSTALL_PATH' );
+if ( $IP === false ) {
+ $IP = dirname( __FILE__ ) . '/../../..';
+}
+require_once( "$IP/maintenance/Maintenance.php" );
+require_once __DIR__ . "/../../Echo/includes/BatchRowUpdate.php";
+
+/**
+ * In some cases we have created workflow instances before the related Title
+ * has an ArticleID assigned to it. This goes through and sets that value
+ *
+ * @ingroup Maintenance
+ */
+class FlowUpdateWorkflowPageId extends Maintenance {
+ public function __construct() {
+ parent::__construct();
+ $this->mDescription = "Update workflow_page_id with the page id
of its specified ns/title";
+ $this->setBatchSize( 300 );
+ }
+
+ /**
+ * Assembles the update components, runs them, and reports
+ * on what they did
+ */
+ public function execute() {
+ global $wgFlowCluster, $wgLang;
+
+ $dbw = Container::get( 'db.factory' )->getDB( DB_MASTER );
+
+ $it = new EchoBatchRowIterator(
+ $dbw,
+ 'flow_workflow',
+ 'workflow_id',
+ $this->mBatchSize
+ );
+ $it->setFetchColumns( array( '*' ) );
+ $it->addConditions( array(
+ 'workflow_wiki' => wfWikiId(),
+ 'workflow_page_id' => 0,
+ ) );
+
+
+ $gen = new WorkflowPageIdUpdateGenerator( $wgLang );
+ $writer = new EchoBatchRowWriter( $dbw, 'flow_workflow',
$wgFlowCluster );
+ $updater = new EchoBatchRowUpdate( $it, $writer, $gen );
+
+ $updater->execute();
+
+ $this->output( $gen->report() );
+
+ return true;
+ }
+}
+
+/**
+ * Looks at rows from the flow_workflow table and returns an update
+ * for the workflow_page_id field if necessary.
+ */
+class WorkflowPageIdUpdateGenerator implements EchoRowUpdateGenerator {
+ /**
+ * @var Language|StubUserLang
+ */
+ protected $lang;
+ protected $fixedCount = 0;
+ protected $failed = array();
+
+ /**
+ * @param Language|StubUserLang $lang
+ */
+ public function __construct( $lang ) {
+ $this->lang = $lang;
+ }
+
+ public function update( $row ) {
+ $title = Title::makeTitleSafe( $row->workflow_namespace,
$row->workflow_title_text );
+ if ( $title === null ) {
+ throw new Exception( sprintf(
+ 'Could not create title for %s at %s:%s',
+ UUID::create( $row->workflow_id
)->getAlphadecimal(),
+ $this->lang->getNsText(
$row->workflow_namespace ) ?: $row->workflow_namespace,
+ $row->workflow_title_text
+ ) );
+ }
+
+ if ( $title->getArticleID() !== (int)$row->workflow_page_id ) {
+ // This makes the assumption the page has not moved or
been deleted?
+ ++$this->fixedCount;
+ return array(
+ 'workflow_page_id' => $title->getArticleID(),
+ );
+ } elseif ( !$row->workflow_page_id ) {
+ // No id exists for this workflow?
+ $this->failed[] = $row;
+ }
+
+ return array();
+ }
+
+ public function report() {
+ return "Updated {$this->fixedCount} workflows\nFailed: " .
count( $this->failed ) . "\n\n" . print_r( $this->failed, true );
+ }
+}
+
+$maintClass = "FlowUpdateWorkflowPageId";
+require_once( DO_MAINTENANCE );
--
To view, visit https://gerrit.wikimedia.org/r/203962
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I7a48f09fcdcb9ec3def002e4ad907b2c59f64687
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>
Gerrit-Reviewer: Mattflaschen <[email protected]>
Gerrit-Reviewer: Matthias Mullie <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits