X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fdeferred%2FLinksDeletionUpdate.php;h=d7848400efeff93af8f2cf70bc0e52f99d7843d9;hb=c0cb80beac069254edf9f77b7ce149af6568be23;hp=bbdfcf1705851e779c412b209f25220ba73bea6d;hpb=78c47763ab93a9f7680d304c99e89c15c2a353a4;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/deferred/LinksDeletionUpdate.php b/includes/deferred/LinksDeletionUpdate.php index bbdfcf1705..d7848400ef 100644 --- a/includes/deferred/LinksDeletionUpdate.php +++ b/includes/deferred/LinksDeletionUpdate.php @@ -19,49 +19,48 @@ * * @file */ - /** * Update object handling the cleanup of links tables after a page was deleted. **/ -class LinksDeletionUpdate extends SqlDataUpdate { - /** @var WikiPage The WikiPage that was deleted */ - protected $mPage; +class LinksDeletionUpdate extends SqlDataUpdate implements EnqueueableDataUpdate { + /** @var WikiPage */ + protected $page; + /** @var integer */ + protected $pageId; /** - * Constructor - * * @param WikiPage $page Page we are updating + * @param integer|null $pageId ID of the page we are updating [optional] * @throws MWException */ - function __construct( WikiPage $page ) { + function __construct( WikiPage $page, $pageId = null ) { parent::__construct( false ); // no implicit transaction - $this->mPage = $page; - - if ( !$page->exists() ) { + $this->page = $page; + if ( $page->exists() ) { + $this->pageId = $page->getId(); + } elseif ( $pageId ) { + $this->pageId = $pageId; + } else { throw new MWException( "Page ID not known, perhaps the page doesn't exist?" ); } } - /** - * Do some database updates after deletion - */ public function doUpdate() { - $title = $this->mPage->getTitle(); - $id = $this->mPage->getId(); + # Page may already be deleted, so don't just getId() + $id = $this->pageId; # Delete restrictions for it $this->mDb->delete( 'page_restrictions', array( 'pr_page' => $id ), __METHOD__ ); # Fix category table counts - $cats = array(); - $res = $this->mDb->select( 'categorylinks', 'cl_to', array( 'cl_from' => $id ), __METHOD__ ); - - foreach ( $res as $row ) { - $cats[] = $row->cl_to; - } - - $this->mPage->updateCategoryCounts( array(), $cats ); + $cats = $this->mDb->selectFieldValues( + 'categorylinks', + 'cl_to', + array( 'cl_from' => $id ), + __METHOD__ + ); + $this->page->updateCategoryCounts( array(), $cats ); # If using cascading deletes, we can skip some explicit deletes if ( !$this->mDb->cascadingDeletes() ) { @@ -79,6 +78,7 @@ class LinksDeletionUpdate extends SqlDataUpdate { # If using cleanup triggers, we can skip some manual deletes if ( !$this->mDb->cleanupTriggers() ) { + $title = $this->page->getTitle(); # Find recentchanges entries to clean up... $rcIdsForTitle = $this->mDb->selectFieldValues( 'recentchanges', 'rc_id', @@ -102,4 +102,16 @@ class LinksDeletionUpdate extends SqlDataUpdate { } } } -} \ No newline at end of file + + public function getAsJobSpecification() { + return array( + 'wiki' => $this->mDb->getWikiID(), + 'job' => new JobSpecification( + 'deleteLinks', + array( 'pageId' => $this->page->getId() ), + array( 'removeDuplicates' => true ), + $this->page->getTitle() + ) + ); + } +}