From 0fe26747ddfe227109fe63c38efc5abee3544050 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 6 Aug 2014 06:01:56 -0700 Subject: [PATCH] Added a script to find missing LocalRepo files Change-Id: I507bd43c6a74568ce94844146c9e20a4d8d17d46 --- maintenance/findMissingFiles.php | 85 ++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 maintenance/findMissingFiles.php diff --git a/maintenance/findMissingFiles.php b/maintenance/findMissingFiles.php new file mode 100644 index 0000000000..8c7169980a --- /dev/null +++ b/maintenance/findMissingFiles.php @@ -0,0 +1,85 @@ +mDescription = 'Find registered files with no corresponding file.'; + $this->addOption( 'start', 'Starting file name', false, true ); + $this->setBatchSize( 200 ); + } + + function execute() { + $lastName = $this->getOption( 'start', '' ); + + $repo = RepoGroup::singleton()->getLocalRepo(); + $dbr = $repo->getSlaveDB(); + $be = $repo->getBackend(); + + do { + $res = $dbr->select( 'image', + 'img_name', + array( "img_name >= " . $dbr->addQuotes( $lastName ) ), + __METHOD__, + array( 'ORDER BY' => 'img_name', 'LIMIT' => $this->mBatchSize ) + ); + + // Check if any of these files are missing... + $pathsByName = array(); + foreach ( $res as $row ) { + $file = $repo->newFile( $row->img_name ); + $pathsByName[$row->img_name] = $file->getPath(); + $lastName = $row->img_name; + } + $be->preloadFileStat( array( 'srcs' => $pathsByName ) ); + foreach ( $pathsByName as $path ) { + if ( $be->fileExists( array( 'src' => $path ) ) === false ) { + $this->output( "$path\n" ); + } + } + + // Find all missing old versions of any of the files in this batch... + if ( count( $pathsByName ) ) { + $ores = $dbr->select( 'oldimage', + array( 'oi_name', 'oi_archive_name' ), + array( 'oi_name' => array_keys( $pathsByName ) ), + __METHOD__ + ); + foreach ( $ores as $row ) { + if ( !strlen( $row->oi_archive_name ) ) { + continue; // broken row + } + $file = $repo->newFromArchiveName( $row->oi_name, $row->oi_archive_name ); + $path = $file->getPath(); + if ( $be->fileExists( array( 'src' => $path ) ) === false ) { + $this->output( "$path\n" ); + } + } + } + } while ( $res->numRows() >= $this->mBatchSize ); + } +} + +$maintClass = 'FindMissingFiles'; +require_once RUN_MAINTENANCE_IF_MAIN; -- 2.20.1