public function execute() { global $wgExternalSharedDB, $wgWikiaDatacenter; $this->output("Wikis migration started ... \n"); $this->time = time(); $migrated = 0; $limit = $this->getOption('limit', -1); $debug = $this->hasOption('debug'); $force = $this->hasOption('force'); $wikis = $this->getOption('wiki', null); $forceAll = $this->hasOption('all'); $this->dryRun = $this->hasOption('dry-run'); $this->noDeletes = $this->hasOption('no-deletes'); $this->calculateMd5 = $this->hasOption('md5'); $this->syncSecondary = $this->hasOption('sync'); if ($this->syncSecondary) { $force = true; $forceAll = true; } $this->dc = $this->getOption('dc', 'sjc,res'); # don't migrate top 200 Wikis $top200Wikis = array(); if (!$forceAll) { $top200Wikis = DataMartService::getWAM200Wikis(); if (count($top200Wikis) != 200) { $this->output("Number of Top 200 Wikis is different than 200 !\n"); exit; } if ($debug) { $this->output("Top 200 Wikis: " . implode(", ", $top200Wikis) . "\n"); } } # don't migrate video.wikia.com & corp.wikia.com $this->disabled_wikis = array_merge($top200Wikis, $this->disabled_wikis); foreach ($this->disabled_wikis as $k => $v) { $this->disabled_wikis[$k] = intval($v); } if ($this->syncSecondary) { $this->disabled_wikis = array(); } $wikiIds = null; if ($wikis !== null) { $wikiIds = array(); foreach (explode(',', $wikis) as $id) { if (is_numeric($id) && $id >= 0) { $wikiIds[] = $id; } } if (count($wikiIds) == 0) { $wikiIds = null; } } $this->db = $this->getDB(DB_SLAVE, array(), $wgExternalSharedDB); $order = $this->hasOption('reverse') ? " DESC" : ""; $res = $this->db->select(array('city_list', 'city_variables'), array('city_id', 'city_dbname'), array_merge(array('city_public' => 1), !$force ? array('cv_value is null or cv_value != "b:1;"') : array(), is_array($wikiIds) ? array('city_id' => $wikiIds) : array()), __CLASS__, array_merge(array('ORDER BY' => "city_last_timestamp{$order}, city_id{$order}"), $limit > 0 ? array('LIMIT' => $limit) : array()), array('city_variables' => array('LEFT JOIN', 'city_list.city_id = city_variables.cv_city_id and cv_variable_id = 1334'))); $this->output(sprintf("Found %d wikis in database...\n", $res->numRows())); $this->output("Building list of wiki IDs...\n"); $removedCount = 0; $queue = array(); while ($row = $res->fetchObject()) { $id = intval($row->city_id); $dbname = $row->city_dbname; if (!in_array($id, $this->disabled_wikis)) { $queue[$id] = $dbname; } else { $removedCount++; } } $this->output(sprintf("Skipped %d wikis that are on blacklist...\n", $removedCount)); $this->output(sprintf("Scheduling %d wikis for migration...\n", count($queue))); if ($this->hasOption('stats-only')) { return; } $this->output("\nRun migrateImagesToSwift script \n"); $this->output("Building list of processes to run...\n"); $processes = array(); foreach ($queue as $id => $dbname) { if ($this->calculateMd5) { $process = $this->getMd5Process($id, $dbname); } elseif ($this->syncSecondary) { $process = $this->getSyncProcess($id, $dbname); } else { $process = $this->getMigrationProcess($id, $dbname); } $processes[] = $process; } $threads = $this->getOption('threads', self::THREADS_DEFAULT); $threads = intval($threads); $threadDelay = $this->getOption('delay', self::DELAY_DEFAULT); $threadDelay = intval($threadDelay); $this->output("Using {$threads} threads...\n"); $runner = new \Wikia\Swift\Process\Runner($processes, $threads, $threadDelay); $runner->run(); $this->output(sprintf("\nMigrated %d Wikis in %s\n", $migrated, Wikia::timeDuration(time() - $this->time))); $this->output("\nDone!\n"); }
public function execute() { global $wgExternalSharedDB; $this->output("Wikis migration started ... \n"); $this->time = time(); $migrated = 0; $limit = $this->getOption('limit', self::DEFAULT_LIMIT); $debug = $this->hasOption('debug'); $procs = $this->getOption('procs', self::MIGRATE_PROCS); $force = $this->hasOption('force'); $wikis = $this->getOption('wiki', ''); # don't migrate top 200 Wikis $top200Wikis = DataMartService::getWAM200Wikis(); if (count($top200Wikis) != 200) { $this->output("Number of Top 200 Wikis is different than 200 !\n"); exit; } # don't migrate video.wikia.com & corp.wikia.com $this->disabled_wikis = array_merge($top200Wikis, $this->disabled_wikis); if ($debug) { $this->output("Top 200 Wikis: " . implode(", ", $top200Wikis) . "\n"); } $this->db = $this->getDB(DB_SLAVE, array(), $wgExternalSharedDB); $where = ['city_public' => 1, 'city_image_migrate.city_id is null']; if (!empty($wikis)) { $where['city_list.city_id'] = explode(",", $wikis); } $join = ['city_image_migrate.city_id = city_list.city_id', 'city_image_migrate.locked is not null']; $res = $this->db->select(['city_list', 'city_image_migrate'], ['city_list.city_id', 'city_list.city_dbname'], $where, 'MigrateImagesToSwift', ['ORDER BY' => 'city_last_timestamp, city_id', 'LIMIT' => $limit], ['city_image_migrate' => ['LEFT JOIN', $join]]); $to_migrate = []; $i = 0; $x = 0; while ($row = $res->fetchObject()) { $this->output("\tAdd {$row->city_dbname} to migration package ... "); if (in_array($row->city_id, $this->disabled_wikis)) { $this->output("don't migrate it now \n"); continue; } $to_migrate[$row->city_id] = $row->city_dbname; $this->output("done \n "); $i++; } $this->output("\n\nRun migrateImagesToSwift script \n"); foreach ($to_migrate as $id => $dbname) { # check how many Wikis is locked and sleep if needed $this->isLocked($procs); # run main migration script written by Macbre $this->output("\tMigrate Wiki {$id}: {$dbname} ... "); $cmd = sprintf(self::CMD, $this->getOption('conf'), $id, $force ? ' --force' : '', self::SCRIPT_PROCS, $this->makePath($dbname)); if ($debug) { $this->output("\n\tRun cmd: {$cmd} \n"); } global $wgMaxShellTime; $wgMaxShellTime = 0; $result = wfShellExec($cmd, $retval); if ($retval) { $this->output("Error code {$retval}: {$result} \n"); } else { $this->output("Done in " . Wikia::timeDuration(time() - $this->time) . "\n"); } $migrated++; } $this->output(sprintf("\nMigrated %d Wikis in %s\n", $migrated, Wikia::timeDuration(time() - $this->time))); $this->output("\nDone!\n"); }