コード例 #1
0
ファイル: Image.php プロジェクト: Jobava/diacritice-meta-repo
 /**
  * Do the dirty work of backing up an image row and its file
  * (if $wgSaveDeletedFiles is on) and removing the originals.
  *
  * Must be run while the file store is locked and a database
  * transaction is open to avoid race conditions.
  *
  * @return FSTransaction
  */
 private function prepareDeleteVersion($path, $reason, $table, $fieldMap, $where, $suppress = false, $fname)
 {
     global $wgUser, $wgSaveDeletedFiles;
     // Dupe the file into the file store
     if (file_exists($path)) {
         if ($wgSaveDeletedFiles) {
             $group = 'deleted';
             $store = FileStore::get($group);
             $key = FileStore::calculateKey($path, $this->extension);
             $transaction = $store->insert($key, $path, FileStore::DELETE_ORIGINAL);
         } else {
             $group = null;
             $key = null;
             $transaction = FileStore::deleteFile($path);
         }
     } else {
         wfDebug(__METHOD__ . " deleting already-missing '{$path}'; moving on to database\n");
         $group = null;
         $key = null;
         $transaction = new FSTransaction();
         // empty
     }
     if ($transaction === false) {
         // Fail to restore?
         wfDebug(__METHOD__ . ": import to file store failed, aborting\n");
         throw new MWException("Could not archive and delete file {$path}");
         return false;
     }
     // Bitfields to further supress the image content
     // Note that currently, live images are stored elsewhere
     // and cannot be partially deleted
     $bitfield = 0;
     if ($suppress) {
         $bitfield |= self::DELETED_FILE;
         $bitfield |= self::DELETED_COMMENT;
         $bitfield |= self::DELETED_USER;
         $bitfield |= self::DELETED_RESTRICTED;
     }
     $dbw = wfGetDB(DB_MASTER);
     $storageMap = array('fa_storage_group' => $dbw->addQuotes($group), 'fa_storage_key' => $dbw->addQuotes($key), 'fa_deleted_user' => $dbw->addQuotes($wgUser->getId()), 'fa_deleted_timestamp' => $dbw->timestamp(), 'fa_deleted_reason' => $dbw->addQuotes($reason), 'fa_deleted' => $bitfield);
     $allFields = array_merge($storageMap, $fieldMap);
     try {
         if ($wgSaveDeletedFiles) {
             $dbw->insertSelect('filearchive', $table, $allFields, $where, $fname);
         }
         $dbw->delete($table, $where, $fname);
     } catch (DBQueryError $e) {
         // Something went horribly wrong!
         // Leave the file as it was...
         wfDebug(__METHOD__ . ": database error, rolling back file transaction\n");
         $transaction->rollback();
         throw $e;
     }
     return $transaction;
 }