From 37616e98ec9088136168819f5785898565701176 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sun, 20 Mar 2011 20:34:03 +0000 Subject: [PATCH] * Added findFileFromKey() function * Added doc comments to findBySha1() --- includes/filerepo/RepoGroup.php | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/includes/filerepo/RepoGroup.php b/includes/filerepo/RepoGroup.php index 4c712fd5e4..80f94eb24c 100644 --- a/includes/filerepo/RepoGroup.php +++ b/includes/filerepo/RepoGroup.php @@ -211,14 +211,44 @@ class RepoGroup { return false; } + /** + * Find an instance of the file with this key, created at the specified time + * Returns false if the file does not exist. + * + * @param $hash String SHA-1 + * @param $options Option array, same as findFile() + * @return File object or false if it is not found + */ + function findFileFromKey( $hash, $options = array() ) { + if ( !$this->reposInitialised ) { + $this->initialiseRepos(); + } + + $file = $this->localRepo->findFileFromKey( $hash, $options ); + if ( !$file ) { + foreach ( $this->foreignRepos as $repo ) { + $file = $repo->findFileFromKey( $hash, $options ); + if ( $file ) break; + } + } + return $file; + } + + /** + * Find all instances of files with this key + * + * @param $hash String SHA-1 + * @return Array of File objects + */ function findBySha1( $hash ) { if ( !$this->reposInitialised ) { $this->initialiseRepos(); } $result = $this->localRepo->findBySha1( $hash ); - foreach ( $this->foreignRepos as $repo ) + foreach ( $this->foreignRepos as $repo ) { $result = array_merge( $result, $repo->findBySha1( $hash ) ); + } return $result; } -- 2.20.1