public function execute()
 {
     global $wgEchoCluster;
     $reader = new EchoBatchRowIterator(MWEchoDbFactory::getDB(DB_SLAVE), $this->table, $this->idField, $this->mBatchSize);
     $reader->addConditions(array("event_page_title IS NOT NULL", "event_page_id" => null));
     $updater = new EchoBatchRowUpdate($reader, new EchoBatchRowWriter(MWEchoDbFactory::getDB(DB_MASTER), $this->table, $wgEchoCluster), new EchoSuppressionRowUpdateGenerator());
     $updater->setOutput(array($this, '__internalOutput'));
     $updater->execute();
 }
 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');
     }
 }
示例#7
0
 /**
  * Runs the batch update process
  */
 public function execute()
 {
     foreach ($this->reader as $rows) {
         $updates = array();
         foreach ($rows as $row) {
             $update = $this->generator->update($row);
             if ($update) {
                 $updates[] = array('primaryKey' => $this->reader->extractPrimaryKeys($row), 'changes' => $update);
             }
         }
         if ($updates) {
             $this->output("Processing " . count($updates) . " rows\n");
             $this->writer->write($updates);
         }
     }
     $this->output("Completed\n");
 }
 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
 /**
  * Slightly hackish to use reflection, but asserting different parameters
  * to consecutive calls of DatabaseBase::select in phpunit is error prone
  *
  * @dataProvider provider_readerSelectConditions
  */
 public function testReaderSelectConditionsMultiplePrimaryKeys($message, $expectedSecondIteration, $primaryKeys, $batchSize = 3)
 {
     $results = $this->genSelectResult($batchSize, $batchSize * 3, function () {
         static $i = 0, $j = 100, $k = 1000;
         return array('id_field' => ++$i, 'foo' => ++$j, 'bar' => ++$k);
     });
     $db = $this->mockDbConsecutiveSelect($results);
     $conditions = array('bar' => 42, 'baz' => 'hai');
     $reader = new EchoBatchRowIterator($db, 'some_table', $primaryKeys, $batchSize);
     $reader->addConditions($conditions);
     $buildConditions = new ReflectionMethod($reader, 'buildConditions');
     $buildConditions->setAccessible(true);
     // On first iteration only the passed conditions must be used
     $this->assertEquals($conditions, $buildConditions->invoke($reader), 'First iteration must return only the conditions passed in addConditions');
     $reader->rewind();
     // Second iteration must use the maximum primary key of last set
     $this->assertEquals($conditions + $expectedSecondIteration, $buildConditions->invoke($reader), $message);
 }