From: Aaron Schulz Date: Sun, 20 Mar 2011 20:34:03 +0000 (+0000) Subject: * Added findFileFromKey() function X-Git-Tag: 1.31.0-rc.0~31284 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=37616e98ec9088136168819f5785898565701176;p=lhc%2Fweb%2Fwiklou.git * Added findFileFromKey() function * Added doc comments to findBySha1() --- 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; }