/**
  * @dataProvider provider_readerSetFetchColumns
  */
 public function testReaderSetFetchColumns($message, array $columns, array $primaryKeys, array $fetchColumns)
 {
     $db = $this->mockDb();
     $db->expects($this->once())->method('select')->with('some_table', $columns)->will($this->returnValue(new ArrayIterator(array())));
     $reader = new EchoBatchRowIterator($db, 'some_table', $primaryKeys, 22);
     $reader->setFetchColumns($fetchColumns);
     // triggers first database select
     $reader->rewind();
 }
 protected function doDBUpdates()
 {
     $iterator = new EchoBatchRowIterator(wfGetDB(DB_SLAVE), 'logging', 'log_id', $this->mBatchSize);
     $iterator->setFetchColumns(array('log_id', 'log_params'));
     $iterator->addConditions(array('log_type' => array('delete', 'suppress'), 'log_action' => array('flow-delete-post', 'flow-suppress-post', 'flow-restore-post', 'flow-delete-topic', 'flow-suppress-topic', 'flow-restore-topic')));
     $updater = new EchoBatchRowUpdate($iterator, new EchoBatchRowWriter(wfGetDB(DB_MASTER), 'logging'), new LogRowUpdateGenerator($this));
     $updater->setOutput(array($this, 'output'));
     $updater->execute();
     return true;
 }
 public function execute()
 {
     global $wgFlowCluster;
     $dbFactory = Container::get('db.factory');
     $storage = Container::get('storage');
     $rootPostLoader = Container::get('loader.root_post');
     $iterator = new EchoBatchRowIterator($dbFactory->getDB(DB_SLAVE), 'flow_workflow', 'workflow_id', $this->mBatchSize);
     $iterator->setFetchColumns(array('workflow_id', 'workflow_type', 'workflow_last_update_timestamp'));
     $iterator->addConditions(array('workflow_wiki' => wfWikiId()));
     $updater = new EchoBatchRowUpdate($iterator, new UpdateWorkflowLastUpdateTimestampWriter($storage, $wgFlowCluster), new UpdateWorkflowLastUpdateTimestampGenerator($storage, $rootPostLoader));
     $updater->setOutput(array($this, 'output'));
     $updater->execute();
 }
 /**
  * Assembles the update components, runs them, and reports
  * on what they did
  */
 public function doDbUpdates()
 {
     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()));
     $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;
 }
 protected function doDBUpdates()
 {
     $container = Container::getContainer();
     $dbFactory = $container['db.factory'];
     $dbw = $dbFactory->getDb(DB_MASTER);
     $storage = $container['storage'];
     $moderationLoggingListener = $container['storage.post.listeners.moderation_logging'];
     $rowIterator = new EchoBatchRowIterator($dbw, 'flow_revision', 'rev_id', $this->mBatchSize);
     $rowIterator->setFetchColumns(array('rev_id', 'rev_type'));
     // Fetch rows that are a moderation action
     $rowIterator->addConditions(array('rev_change_type' => ModerationLoggingListener::getModerationChangeTypes(), 'rev_user_wiki' => wfWikiID()));
     $start = $this->getOption('start');
     $startId = UUID::create($start);
     $rowIterator->addConditions(array('rev_id > ' . $dbw->addQuotes($startId->getBinary())));
     $stop = $this->getOption('stop');
     $stopId = UUID::create($stop);
     $rowIterator->addConditions(array('rev_id < ' . $dbw->addQuotes($stopId->getBinary())));
     $total = $fail = 0;
     foreach ($rowIterator as $batch) {
         $dbw->begin();
         foreach ($batch as $row) {
             $total++;
             $objectManager = $storage->getStorage($row->rev_type);
             $revId = UUID::create($row->rev_id);
             $obj = $objectManager->get($revId);
             if (!$obj) {
                 $this->error('Could not load revision: ' . $revId->getAlphadecimal());
                 $fail++;
                 continue;
             }
             $workflow = $obj->getCollection()->getWorkflow();
             $moderationLoggingListener->onAfterInsert($obj, array(), array('workflow' => $workflow));
         }
         $dbw->commit();
         $storage->clear();
         $dbFactory->waitForSlaves();
     }
     $this->output("Processed a total of {$total} moderation revisions.\n");
     if ($fail !== 0) {
         $this->error("Errors were encountered while processing {$fail} of them.\n");
     }
     return true;
 }
 public function execute()
 {
     $pattern = implode('|', array('IAmABad RedirectChain', 'IAmABad RedirectSelf', 'IDontExistLink', 'IDontExistRdir', 'IDontExistRdirLinked', 'ILinkIRedirectToNonExistentPages', 'ILinkToNonExistentPages', 'IRedirectToNonExistentPages', 'IRedirectToNonExistentPagesLinked', 'Move', 'PreferRecent First exists with contents ', 'PreferRecent Second Second exists with contents ', 'PreferRecent Third exists with contents ', 'ReallyLongLink', 'StartsAsRedirect', 'ToBeRedirect', 'WeightedLink', 'WeightedLinkRdir', 'WeightedLinkRemoveUpdate', 'WLDoubleRdir', 'WLRURdir'));
     $pattern = "/{$pattern}/";
     $dbw = wfGetDB(DB_MASTER);
     $user = \User::newFromName('Admin');
     $it = new \EchoBatchRowIterator($dbw, 'page', 'page_id', 500);
     $it->setFetchColumns(array('*'));
     $it = new \RecursiveIteratorIterator($it);
     foreach ($it as $row) {
         if (preg_match($pattern, $row->page_title) !== 1) {
             continue;
         }
         $title = \Title::newFromRow($row);
         $pageObj = \WikiPage::factory($title);
         echo "Deleting page {$title}\n";
         $pageObj->doDeleteArticleReal('cirrussearch maint task');
     }
 }
 public function doDBUpdates()
 {
     // Can't be done in constructor, happens too early in
     // boot process
     $this->dbFactory = Container::get('db.factory');
     $this->storage = Container::get('storage');
     // Since this is a one-shot maintenance script just reach in via reflection
     // to change lenghts
     $this->contentLengthProperty = new ReflectionProperty('Flow\\Model\\AbstractRevision', 'contentLength');
     $this->contentLengthProperty->setAccessible(true);
     $this->previousContentLengthProperty = new ReflectionProperty('Flow\\Model\\AbstractRevision', 'previousContentLength');
     $this->previousContentLengthProperty->setAccessible(true);
     $dbw = $this->dbFactory->getDb(DB_MASTER);
     // Walk through the flow_revision table
     $it = new EchoBatchRowIterator($dbw, 'flow_revision', 'rev_id', $this->mBatchSize);
     // Only fetch rows created by users from the current wiki.
     $it->addConditions(array('rev_user_wiki' => wfWikiId()));
     // We only need the id and type field
     $it->setFetchColumns(array('rev_id', 'rev_type'));
     $total = $fail = 0;
     foreach ($it as $batch) {
         $dbw->begin();
         foreach ($batch as $row) {
             $total++;
             if (!isset(self::$revisionTypes[$row->rev_type])) {
                 $this->output('Unknown revision type: ' . $row->rev_type);
                 $fail++;
                 continue;
             }
             $om = $this->storage->getStorage(self::$revisionTypes[$row->rev_type]);
             $revId = UUID::create($row->rev_id);
             $obj = $om->get($revId);
             if (!$obj) {
                 $this->output('Could not load revision: ' . $revId->getAlphadecimal());
                 $fail++;
                 continue;
             }
             if ($obj->isFirstRevision()) {
                 $previous = null;
             } else {
                 $previous = $om->get($obj->getPrevRevisionId());
                 if (!$previous) {
                     $this->output('Could not locate previous revision: ' . $obj->getPrevRevisionId()->getAlphadecimal());
                     $fail++;
                     continue;
                 }
             }
             $this->updateRevision($obj, $previous);
             try {
                 $om->put($obj);
             } catch (\Exception $e) {
                 $this->error('Failed to update revision ' . $obj->getRevisionId()->getAlphadecimal() . ': ' . $e->getMessage() . "\n" . 'Please make sure rev_content, rev_content_length, rev_flags & rev_previous_content_length are part of RevisionStorage::$allowedUpdateColumns.');
                 throw $e;
             }
             $this->output('.');
         }
         $dbw->commit();
         $this->storage->clear();
         $this->dbFactory->waitForSlaves();
     }
     return true;
 }
<?php

require_once "{$IP}/maintenance/commandLine.inc";
require_once "{$IP}/extensions/Flow/FlowActions.php";
$moderationChangeTypes = array('hide-post', 'hide-topic', 'delete-post', 'delete-topic', 'suppress-post', 'suppress-topic', 'lock-topic', 'restore-post', 'restore-topic');
$csvOutput = fopen('repair_results_from_parent_' . wfWikiId() . '.csv', 'w');
if (!$csvOutput) {
    die("Could not open results file\n");
}
fputcsv($csvOutput, array("uuid", "esurl", "flags"));
$dbr = Flow\Container::get('db.factory')->getDB(DB_SLAVE);
$it = new EchoBatchRowIterator($dbr, 'flow_revision', array('rev_id'), 10);
$it->addConditions(array('rev_user_wiki' => wfWikiId()));
$it->setFetchColumns(array('rev_change_type', 'rev_parent_id'));
$totalNullContentWithParent = 0;
$totalNullParentContent = 0;
$totalBadQueryResult = 0;
$totalMatched = 0;
foreach ($it as $batch) {
    foreach ($batch as $rev) {
        $item = ExternalStore::fetchFromURL($rev->rev_content);
        if ($item) {
            // contains valid data
            continue;
        }
        $changeType = $rev->rev_change_type;
        while (is_string($wgFlowActions[$changeType])) {
            $changeType = $wgFlowActions[$changeType];
        }
        if (!in_array($changeType, $moderationChangeTypes)) {
            // doesn't inherit content
<?php

require_once "{$IP}/maintenance/commandLine.inc";
require_once "{$IP}/extensions/Flow/FlowActions.php";
$moderationChangeTypes = array('hide-post', 'hide-topic', 'delete-post', 'delete-topic', 'suppress-post', 'suppress-topic', 'lock-topic', 'restore-post', 'restore-topic');
$plaintextChangeTypes = array('edit-title', 'new-topic');
$csvOutput = fopen('repair_results_' . wfWikiId() . '.csv', 'w');
if (!$csvOutput) {
    die("Could not open results file\n");
}
fputcsv($csvOutput, array("uuid", "esurl", "flags"));
$it = new EchoBatchRowIterator(Flow\Container::get('db.factory')->getDB(DB_SLAVE), 'flow_revision', array('rev_id'), 10);
$it->addConditions(array('rev_user_wiki' => wfWikiId()));
$it->setFetchColumns(array('rev_content', 'rev_content_length', 'rev_change_type', 'rev_parent_id'));
$dbr = wfGetDB(DB_SLAVE);
$totalMissingConsidered = 0;
$totalCompleteMatch = 0;
$totalMultipleMatches = 0;
$totalResolvedMultipleMatches = 0;
$totalNoMatch = 0;
$totalNoChangeRevisions = 0;
$totalMatchButInvalid = 0;
foreach ($it as $batch) {
    foreach ($batch as $rev) {
        $item = ExternalStore::fetchFromURL($rev->rev_content);
        if ($item) {
            // contains valid data
            continue;
        }
        ++$totalMissingConsidered;
        $uuid = Flow\Model\UUID::create($rev->rev_id);