Example #1
0
 /**
  * Moves an image from a safe private location
  * Caller is responsible for clearing caches
  * @param File $oimage
  * @returns mixed, string timestamp on success, false on failure
  */
 function makeOldImagePublic($oimage)
 {
     $transaction = new FSTransaction();
     if (!FileStore::lock()) {
         wfDebug(__METHOD__ . " could not acquire filestore lock\n");
         return false;
     }
     $store = FileStore::get('deleted');
     if (!$store) {
         wfDebug(__METHOD__ . ": skipping row with no file.\n");
         return false;
     }
     $key = $oimage->sha1 . '.' . $oimage->getExtension();
     $destDir = $oimage->getArchivePath();
     if (!is_dir($destDir)) {
         wfMkdirParents($destDir);
     }
     $destPath = $destDir . DIRECTORY_SEPARATOR . $oimage->archive_name;
     // Check if any other stored revisions use this file;
     // if so, we shouldn't remove the file from the hidden
     // archives so they will still work. Check hidden files first.
     $useCount = $this->dbw->selectField('oldimage', '1', array('oi_sha1' => $oimage->sha1, 'oi_deleted & ' . File::DELETED_FILE => File::DELETED_FILE), __METHOD__, array('FOR UPDATE'));
     // Check the rest of the deleted archives too.
     // (these are the ones that don't show in the image history)
     if (!$useCount) {
         $useCount = $this->dbw->selectField('filearchive', '1', array('fa_storage_group' => 'deleted', 'fa_storage_key' => $key), __METHOD__, array('FOR UPDATE'));
     }
     if ($useCount == 0) {
         wfDebug(__METHOD__ . ": nothing else using {$oimage->sha1}, will deleting after\n");
         $flags = FileStore::DELETE_ORIGINAL;
     } else {
         $flags = 0;
     }
     $transaction->add($store->export($key, $destPath, $flags));
     wfDebug(__METHOD__ . ": set db items, applying file transactions\n");
     $transaction->commit();
     FileStore::unlock();
     $m = explode('!', $oimage->archive_name, 2);
     $timestamp = $m[0];
     return $timestamp;
 }