RevDelFileList.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. /**
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along
  14. * with this program; if not, write to the Free Software Foundation, Inc.,
  15. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. * http://www.gnu.org/copyleft/gpl.html
  17. *
  18. * @file
  19. * @ingroup RevisionDelete
  20. */
  21. use MediaWiki\MediaWikiServices;
  22. use Wikimedia\Rdbms\IDatabase;
  23. /**
  24. * List for oldimage table items
  25. */
  26. class RevDelFileList extends RevDelList {
  27. /** @var array */
  28. public $storeBatch;
  29. /** @var array */
  30. public $deleteBatch;
  31. /** @var array */
  32. public $cleanupBatch;
  33. public function getType() {
  34. return 'oldimage';
  35. }
  36. public static function getRelationType() {
  37. return 'oi_archive_name';
  38. }
  39. public static function getRestriction() {
  40. return 'deleterevision';
  41. }
  42. public static function getRevdelConstant() {
  43. return File::DELETED_FILE;
  44. }
  45. /**
  46. * @param IDatabase $db
  47. * @return mixed
  48. */
  49. public function doQuery( $db ) {
  50. $archiveNames = [];
  51. foreach ( $this->ids as $timestamp ) {
  52. $archiveNames[] = $timestamp . '!' . $this->title->getDBkey();
  53. }
  54. $oiQuery = OldLocalFile::getQueryInfo();
  55. return $db->select(
  56. $oiQuery['tables'],
  57. $oiQuery['fields'],
  58. [
  59. 'oi_name' => $this->title->getDBkey(),
  60. 'oi_archive_name' => $archiveNames
  61. ],
  62. __METHOD__,
  63. [ 'ORDER BY' => 'oi_timestamp DESC' ],
  64. $oiQuery['joins']
  65. );
  66. }
  67. public function newItem( $row ) {
  68. return new RevDelFileItem( $this, $row );
  69. }
  70. public function clearFileOps() {
  71. $this->deleteBatch = [];
  72. $this->storeBatch = [];
  73. $this->cleanupBatch = [];
  74. }
  75. public function doPreCommitUpdates() {
  76. $status = Status::newGood();
  77. $repo = RepoGroup::singleton()->getLocalRepo();
  78. if ( $this->storeBatch ) {
  79. $status->merge( $repo->storeBatch( $this->storeBatch, FileRepo::OVERWRITE_SAME ) );
  80. }
  81. if ( !$status->isOK() ) {
  82. return $status;
  83. }
  84. if ( $this->deleteBatch ) {
  85. $status->merge( $repo->deleteBatch( $this->deleteBatch ) );
  86. }
  87. if ( !$status->isOK() ) {
  88. // Running cleanupDeletedBatch() after a failed storeBatch() with the DB already
  89. // modified (but destined for rollback) causes data loss
  90. return $status;
  91. }
  92. if ( $this->cleanupBatch ) {
  93. $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch ) );
  94. }
  95. return $status;
  96. }
  97. public function doPostCommitUpdates( array $visibilityChangeMap ) {
  98. $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
  99. ->newFile( $this->title );
  100. $file->purgeCache();
  101. $file->purgeDescription();
  102. // Purge full images from cache
  103. $purgeUrls = [];
  104. foreach ( $this->ids as $timestamp ) {
  105. $archiveName = $timestamp . '!' . $this->title->getDBkey();
  106. $file->purgeOldThumbnails( $archiveName );
  107. $purgeUrls[] = $file->getArchiveUrl( $archiveName );
  108. }
  109. DeferredUpdates::addUpdate(
  110. new CdnCacheUpdate( $purgeUrls ),
  111. DeferredUpdates::PRESEND
  112. );
  113. return Status::newGood();
  114. }
  115. public function getSuppressBit() {
  116. return File::DELETED_RESTRICTED;
  117. }
  118. }