Beispiel #1
0
 /**
  * Delete all versions of the file.
  *
  * Moves the files into an archive directory (or deletes them)
  * and removes the database rows.
  *
  * Cache purging is done; logging is caller's responsibility.
  *
  * @param string $reason
  * @param bool $suppress
  * @return FileRepoStatus
  */
 function delete($reason, $suppress = false)
 {
     if ($this->getRepo()->getReadOnlyReason() !== false) {
         return $this->readOnlyFatalStatus();
     }
     $batch = new LocalFileDeleteBatch($this, $reason, $suppress);
     $this->lock();
     // begin
     $batch->addCurrent();
     # Get old version relative paths
     $archiveNames = $batch->addOlds();
     $status = $batch->execute();
     $this->unlock();
     // done
     if ($status->isOK()) {
         DeferredUpdates::addUpdate(SiteStatsUpdate::factory(array('images' => -1)));
     }
     // Hack: the lock()/unlock() pair is nested in a transaction so the locking is not
     // tied to BEGIN/COMMIT. To avoid slow purges in the transaction, move them outside.
     $file = $this;
     $this->getRepo()->getMasterDB()->onTransactionIdle(function () use($file, $archiveNames) {
         global $wgUseSquid;
         $file->purgeEverything();
         foreach ($archiveNames as $archiveName) {
             $file->purgeOldThumbnails($archiveName);
         }
         if ($wgUseSquid) {
             // Purge the squid
             $purgeUrls = array();
             foreach ($archiveNames as $archiveName) {
                 $purgeUrls[] = $file->getArchiveUrl($archiveName);
             }
             SquidUpdate::purge($purgeUrls);
         }
     });
     return $status;
 }
Beispiel #2
0
 /**
  * Delete all versions of the file.
  *
  * Moves the files into an archive directory (or deletes them)
  * and removes the database rows.
  *
  * Cache purging is done; logging is caller's responsibility.
  *
  * @param $reason
  * @param $suppress
  * @return FileRepoStatus object.
  */
 function delete($reason, $suppress = false)
 {
     $this->lock();
     $batch = new LocalFileDeleteBatch($this, $reason, $suppress);
     $batch->addCurrent();
     # Get old version relative paths
     $dbw = $this->repo->getMasterDB();
     $result = $dbw->select('oldimage', array('oi_archive_name'), array('oi_name' => $this->getName()));
     foreach ($result as $row) {
         $batch->addOld($row->oi_archive_name);
         $this->purgeOldThumbnails($row->oi_archive_name);
     }
     $status = $batch->execute();
     if ($status->ok) {
         // Update site_stats
         $site_stats = $dbw->tableName('site_stats');
         $dbw->query("UPDATE {$site_stats} SET ss_images=ss_images-1", __METHOD__);
         $this->purgeEverything();
     }
     $this->unlock();
     return $status;
 }
 /**
  * Delete all versions of the file.
  *
  * Moves the files into an archive directory (or deletes them)
  * and removes the database rows.
  *
  * Cache purging is done; logging is caller's responsibility.
  *
  * @param $reason
  * @param $suppress
  * @return FileRepoStatus object.
  */
 function delete($reason, $suppress = false)
 {
     if ($this->getRepo()->getReadOnlyReason() !== false) {
         return $this->readOnlyFatalStatus();
     }
     $batch = new LocalFileDeleteBatch($this, $reason, $suppress);
     $this->lock();
     // begin
     $batch->addCurrent();
     # Get old version relative paths
     $archiveNames = $batch->addOlds();
     $status = $batch->execute();
     $this->unlock();
     // done
     if ($status->isOK()) {
         DeferredUpdates::addUpdate(SiteStatsUpdate::factory(array('images' => -1)));
     }
     $this->purgeEverything();
     foreach ($archiveNames as $archiveName) {
         $this->purgeOldThumbnails($archiveName);
     }
     return $status;
 }
Beispiel #4
0
 /**
  * Delete all versions of the file.
  *
  * Moves the files into an archive directory (or deletes them)
  * and removes the database rows.
  *
  * Cache purging is done; logging is caller's responsibility.
  *
  * @param string $reason
  * @param bool $suppress
  * @param User|null $user
  * @return FileRepoStatus
  */
 function delete($reason, $suppress = false, $user = null)
 {
     if ($this->getRepo()->getReadOnlyReason() !== false) {
         return $this->readOnlyFatalStatus();
     }
     $batch = new LocalFileDeleteBatch($this, $reason, $suppress, $user);
     $this->lock();
     // begin
     $batch->addCurrent();
     # Get old version relative paths
     $archiveNames = $batch->addOlds();
     $status = $batch->execute();
     $this->unlock();
     // done
     if ($status->isOK()) {
         DeferredUpdates::addUpdate(SiteStatsUpdate::factory(['images' => -1]));
     }
     // Hack: the lock()/unlock() pair is nested in a transaction so the locking is not
     // tied to BEGIN/COMMIT. To avoid slow purges in the transaction, move them outside.
     $that = $this;
     $this->getRepo()->getMasterDB()->onTransactionIdle(function () use($that, $archiveNames) {
         $that->purgeEverything();
         foreach ($archiveNames as $archiveName) {
             $that->purgeOldThumbnails($archiveName);
         }
     });
     // Purge the CDN
     $purgeUrls = [];
     foreach ($archiveNames as $archiveName) {
         $purgeUrls[] = $this->getArchiveUrl($archiveName);
     }
     DeferredUpdates::addUpdate(new CdnCacheUpdate($purgeUrls), DeferredUpdates::PRESEND);
     return $status;
 }
Beispiel #5
0
 /**
  * Delete all versions of the file.
  *
  * Moves the files into an archive directory (or deletes them)
  * and removes the database rows.
  *
  * Cache purging is done; logging is caller's responsibility.
  *
  * @param string $reason
  * @param bool $suppress
  * @param User|null $user
  * @return Status
  */
 function delete($reason, $suppress = false, $user = null)
 {
     if ($this->getRepo()->getReadOnlyReason() !== false) {
         return $this->readOnlyFatalStatus();
     }
     $batch = new LocalFileDeleteBatch($this, $reason, $suppress, $user);
     $this->lock();
     // begin
     $batch->addCurrent();
     // Get old version relative paths
     $archiveNames = $batch->addOlds();
     $status = $batch->execute();
     $this->unlock();
     // done
     if ($status->isOK()) {
         DeferredUpdates::addUpdate(SiteStatsUpdate::factory(['images' => -1]));
     }
     // To avoid slow purges in the transaction, move them outside...
     DeferredUpdates::addUpdate(new AutoCommitUpdate($this->getRepo()->getMasterDB(), __METHOD__, function () use($archiveNames) {
         $this->purgeEverything();
         foreach ($archiveNames as $archiveName) {
             $this->purgeOldThumbnails($archiveName);
         }
     }), DeferredUpdates::PRESEND);
     // Purge the CDN
     $purgeUrls = [];
     foreach ($archiveNames as $archiveName) {
         $purgeUrls[] = $this->getArchiveUrl($archiveName);
     }
     DeferredUpdates::addUpdate(new CdnCacheUpdate($purgeUrls), DeferredUpdates::PRESEND);
     return $status;
 }
Beispiel #6
0
 /**
  * Delete all versions of the file.
  *
  * Moves the files into an archive directory (or deletes them)
  * and removes the database rows.
  *
  * Cache purging is done; logging is caller's responsibility.
  *
  * @param $reason
  * @param $suppress
  * @return FileRepoStatus object.
  */
 function delete($reason, $suppress = false)
 {
     global $wgUseSquid;
     $this->lock();
     // begin
     $batch = new LocalFileDeleteBatch($this, $reason, $suppress);
     $batch->addCurrent();
     # Get old version relative paths
     $dbw = $this->repo->getMasterDB();
     $result = $dbw->select('oldimage', array('oi_archive_name'), array('oi_name' => $this->getName()));
     $archiveNames = [];
     foreach ($result as $row) {
         $batch->addOld($row->oi_archive_name);
         $archiveNames[] = $row->oi_archive_name;
     }
     $status = $batch->execute();
     if ($status->ok) {
         // Update site_stats
         $site_stats = $dbw->tableName('site_stats');
         $dbw->query("UPDATE {$site_stats} SET ss_images=ss_images-1", __METHOD__);
     }
     $this->unlock();
     // done
     if ($status->ok) {
         $this->purgeEverything();
         foreach ($archiveNames as $archiveName) {
             $this->purgeOldThumbnails($archiveName);
         }
         if ($wgUseSquid) {
             // Purge the squid
             $purgeUrls = array();
             foreach ($archiveNames as $archiveName) {
                 $purgeUrls[] = $this->getArchiveUrl($archiveName);
             }
             SquidUpdate::purge($purgeUrls);
         }
     }
     return $status;
 }