/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }