function newFileFromRow($row) { if (isset($row->img_name)) { return LocalFile::newFromRow($row, $this); } elseif (isset($row->oi_name)) { return OldLocalFile::newFromRow($row, $this); } else { throw new MWException(__METHOD__ . ': invalid row'); } }
public function purgeImagesSQL($whereSQL) { # Purge files of any images # lance.gatlin@gmail.com: tested good 16Jul11 $images_rows = $this->dbw->select('image', array('*'), array($whereSQL)); if ($images_rows->numRows() == 0) { return; } $imageNames = array(); foreach ($images_rows as $row) { $file = LocalFile::newFromRow($row, $this->repo); # Purge thumbnails and purge cache for pages using this image $file->purgeEverything(); # Purge thumbnail directories // TODO: Mediawiki does not purge the directories used to store thumbnails $path = $file->getPath(); if ($path !== false && file_exists($path)) { unlink($path); } $imageNames[] = "'" . $row->img_name . "'"; } # Purge images # lance.gatlin@gmail.com: tested good 9Jul11 $this->dbw->delete('image', array($whereSQL)); # Purge old versions of these images $imageNames_list = implode(',', $imageNames); $this->purgeOldImagesSQL("oi_name IN ({$imageNames_list})"); $this->purgePagesSQL("page_title IN ({$imageNames_list}) AND page_namespace={$this->nsFile}"); }
public function execute() { global $wgUser; $wgUser = User::newFromName(self::USER); $this->isDryRun = $this->hasOption('dry-run'); $this->otherLocation = $this->getOption('other-location'); $this->repo = RepoGroup::singleton()->getLocalRepo(); $this->dbr = $this->getDB(DB_SLAVE); $images = 0; $imagesMissing = 0; $imagesFixed = 0; $res = $this->dbr->select('image', LocalFile::selectFields(), '', __METHOD__); $count = $res->numRows(); $this->output(sprintf("Checking all images (%d images)%s...\n\n", $count, $this->isDryRun ? ' in dry run mode' : '')); while ($row = $res->fetchObject()) { $file = LocalFile::newFromRow($row, $this->repo); // 1. check file size (img_size = 0 in image table) $this->checkFileSize($file); // 2. check for missing files on FS / Swift storage $result = $this->processMissingFile($file); switch ($result) { case self::RESULT_RESTORED: $imagesFixed++; $imagesMissing++; break; case self::RESULT_NOT_RESTORED: $imagesMissing++; break; } // progress if (++$images % 100) { $this->output(sprintf("%d%%\r", $images / $count * 100)); } } // summary if (!empty($this->otherLocation)) { $this->output(sprintf("Restored %d images from second location \n", count($this->foundMissing))); $this->output("List of restored files: \n"); $this->output(sprintf("%s\n\n", implode("\t\n", $this->foundMissing))); } $this->output(sprintf("Detected %d missing images (%.2f%% of %d images) and fixed %d images\n\n", $imagesMissing, $imagesMissing / $count * 100, $count, $imagesFixed)); }