public function setBits($bits)
 {
     # Queue the file op
     # @todo FIXME: Move to LocalFile.php
     if ($this->isDeleted()) {
         if ($bits & File::DELETED_FILE) {
             # Still deleted
         } else {
             # Newly undeleted
             $key = $this->file->getStorageKey();
             $srcRel = $this->file->repo->getDeletedHashPath($key) . $key;
             $this->list->storeBatch[] = array($this->file->repo->getVirtualUrl('deleted') . '/' . $srcRel, 'public', $this->file->getRel());
             $this->list->cleanupBatch[] = $key;
         }
     } elseif ($bits & File::DELETED_FILE) {
         # Newly deleted
         $key = $this->file->getStorageKey();
         $dstRel = $this->file->repo->getDeletedHashPath($key) . $key;
         $this->list->deleteBatch[] = array($this->file->getRel(), $dstRel);
     }
     # Do the database operations
     $dbw = wfGetDB(DB_MASTER);
     $dbw->update('oldimage', array('oi_deleted' => $bits), array('oi_name' => $this->row->oi_name, 'oi_timestamp' => $this->row->oi_timestamp, 'oi_deleted' => $this->getBits()), __METHOD__);
     return (bool) $dbw->affectedRows();
 }
Example #2
0
/**
 * Handler for the LocalFilePurgeThumbnails hook.
 * To avoid excess inclusion of cloudfiles.php, a hook handler can be added
 * to CommonSettings.php which includes this file and calls this function.
 *
 * @param $file File
 * @param $archiveName string|false
 * @return true
 */
function wmfPurgeBackendThumbCache(File $file, $archiveName)
{
    global $site, $lang;
    // CommonSettings.php
    // Get thumbnail dir relative to thumb zone
    if ($archiveName !== false) {
        $thumbRel = $file->getArchiveThumbRel($archiveName);
        // old version
    } else {
        $thumbRel = $file->getRel();
        // current version
    }
    // Get the container for the thumb zone and delete the objects
    $container = wmfGetSwiftThumbContainer($site, $lang, "{$thumbRel}/");
    if ($container) {
        // sanity
        $files = $container->list_objects(0, NULL, "{$thumbRel}/");
        foreach ($files as $file) {
            try {
                $container->delete_object($file);
            } catch (NoSuchObjectException $e) {
                // probably a race condition
                wfDebugLog('swiftThumb', "Could not delete `{$file}`; object does not exist.");
            }
        }
    }
    return true;
}
 /**
  * @param File $file
  * @param bool $dumpContents
  * @return string
  */
 function writeUpload($file, $dumpContents = false)
 {
     if ($file->isOld()) {
         $archiveName = "      " . Xml::element('archivename', null, $file->getArchiveName()) . "\n";
     } else {
         $archiveName = '';
     }
     if ($dumpContents) {
         $be = $file->getRepo()->getBackend();
         # Dump file as base64
         # Uses only XML-safe characters, so does not need escaping
         # @todo Too bad this loads the contents into memory (script might swap)
         $contents = '      <contents encoding="base64">' . chunk_split(base64_encode($be->getFileContents(array('src' => $file->getPath())))) . "      </contents>\n";
     } else {
         $contents = '';
     }
     if ($file->isDeleted(File::DELETED_COMMENT)) {
         $comment = Xml::element('comment', array('deleted' => 'deleted'));
     } else {
         $comment = Xml::elementClean('comment', null, $file->getDescription());
     }
     return "    <upload>\n" . $this->writeTimestamp($file->getTimestamp()) . $this->writeContributor($file->getUser('id'), $file->getUser('text')) . "      " . $comment . "\n" . "      " . Xml::element('filename', null, $file->getName()) . "\n" . $archiveName . "      " . Xml::element('src', null, $file->getCanonicalURL()) . "\n" . "      " . Xml::element('size', null, $file->getSize()) . "\n" . "      " . Xml::element('sha1base36', null, $file->getSha1()) . "\n" . "      " . Xml::element('rel', null, $file->getRel()) . "\n" . $contents . "    </upload>\n";
 }