DeleteLinksJob.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Job to update link tables for pages
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. * http://www.gnu.org/copyleft/gpl.html
  19. *
  20. * @file
  21. * @ingroup JobQueue
  22. */
  23. use MediaWiki\MediaWikiServices;
  24. /**
  25. * Job to prune link tables for pages that were deleted
  26. *
  27. * Only DataUpdate classes should construct these jobs
  28. *
  29. * @ingroup JobQueue
  30. * @since 1.27
  31. */
  32. class DeleteLinksJob extends Job {
  33. function __construct( Title $title, array $params ) {
  34. parent::__construct( 'deleteLinks', $title, $params );
  35. $this->removeDuplicates = true;
  36. }
  37. function run() {
  38. if ( is_null( $this->title ) ) {
  39. $this->setLastError( "deleteLinks: Invalid title" );
  40. return false;
  41. }
  42. $pageId = $this->params['pageId'];
  43. // Serialize links updates by page ID so they see each others' changes
  44. $scopedLock = LinksUpdate::acquirePageLock( wfGetDB( DB_MASTER ), $pageId, 'job' );
  45. if ( $scopedLock === null ) {
  46. $this->setLastError( 'LinksUpdate already running for this page, try again later.' );
  47. return false;
  48. }
  49. if ( WikiPage::newFromID( $pageId, WikiPage::READ_LATEST ) ) {
  50. // The page was restored somehow or something went wrong
  51. $this->setLastError( "deleteLinks: Page #$pageId exists" );
  52. return false;
  53. }
  54. $factory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
  55. $timestamp = $this->params['timestamp'] ?? null;
  56. $page = WikiPage::factory( $this->title ); // title when deleted
  57. $update = new LinksDeletionUpdate( $page, $pageId, $timestamp );
  58. $update->setTransactionTicket( $factory->getEmptyTransactionTicket( __METHOD__ ) );
  59. $update->doUpdate();
  60. return true;
  61. }
  62. }