diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2007-09-14 13:18:58 +0200 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2007-09-14 13:18:58 +0200 |
commit | 8f416baead93a48e5799e44b8bd2e2c4859f4e04 (patch) | |
tree | cd47ac55eb80a39e3225e8b4f3161b88ea16c2cf /includes/filerepo/LocalRepo.php | |
parent | d7d08bd1a17618c7d77a6b9b2989e9f7293d6ed6 (diff) |
auf Version 1.11 aktualisiert; Login-Bug behoben
Diffstat (limited to 'includes/filerepo/LocalRepo.php')
-rw-r--r-- | includes/filerepo/LocalRepo.php | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/includes/filerepo/LocalRepo.php b/includes/filerepo/LocalRepo.php new file mode 100644 index 00000000..72f9e9a6 --- /dev/null +++ b/includes/filerepo/LocalRepo.php @@ -0,0 +1,65 @@ +<?php +/** + * A repository that stores files in the local filesystem and registers them + * in the wiki's own database. This is the most commonly used repository class. + */ +class LocalRepo extends FSRepo { + var $fileFactory = array( 'LocalFile', 'newFromTitle' ); + var $oldFileFactory = array( 'OldLocalFile', 'newFromTitle' ); + + function getSlaveDB() { + return wfGetDB( DB_SLAVE ); + } + + function getMasterDB() { + return wfGetDB( DB_MASTER ); + } + + 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' ); + } + } + + function newFromArchiveName( $title, $archiveName ) { + return OldLocalFile::newFromArchiveName( $title, $this, $archiveName ); + } + + /** + * Delete files in the deleted directory if they are not referenced in the + * filearchive table. This needs to be done in the repo because it needs to + * interleave database locks with file operations, which is potentially a + * remote operation. + * @return FileRepoStatus + */ + function cleanupDeletedBatch( $storageKeys ) { + $root = $this->getZonePath( 'deleted' ); + $dbw = $this->getMasterDB(); + $status = $this->newGood(); + $storageKeys = array_unique($storageKeys); + foreach ( $storageKeys as $key ) { + $hashPath = $this->getDeletedHashPath( $key ); + $path = "$root/$hashPath$key"; + $dbw->begin(); + $inuse = $dbw->selectField( 'filearchive', '1', + array( 'fa_storage_group' => 'deleted', 'fa_storage_key' => $key ), + __METHOD__, array( 'FOR UPDATE' ) ); + if ( !$inuse ) { + wfDebug( __METHOD__ . ": deleting $key\n" ); + if ( !@unlink( $path ) ) { + $status->error( 'undelete-cleanup-error', $path ); + $status->failCount++; + } + } else { + wfDebug( __METHOD__ . ": $key still in use\n" ); + $status->successCount++; + } + $dbw->commit(); + } + return $status; + } +} |