This removes static logic from WatchedItem into a class that we can slowly fill with watchlist database and storage things. This also removes the dual namespace handling in the new implementation. Change-Id: Ia67ab1d200ac393c65013b2091e61acefcb3defb
86 lines
1.9 KiB
PHP
86 lines
1.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Storage layer class for WatchedItems.
|
|
* Database interaction
|
|
*
|
|
* @author Addshore
|
|
*
|
|
* @since 1.27
|
|
*/
|
|
class WatchedItemStore {
|
|
|
|
/**
|
|
* @var LoadBalancer
|
|
*/
|
|
private $loadBalancer;
|
|
|
|
public function __construct( LoadBalancer $loadBalancer ) {
|
|
$this->loadBalancer = $loadBalancer;
|
|
}
|
|
|
|
/**
|
|
* @return self
|
|
*/
|
|
public static function getDefaultInstance() {
|
|
static $instance;
|
|
if ( !$instance ) {
|
|
$instance = new self( wfGetLB() );
|
|
}
|
|
return $instance;
|
|
}
|
|
|
|
/**
|
|
* Check if the given title already is watched by the user, and if so
|
|
* add a watch for the new title.
|
|
*
|
|
* To be used for page renames and such.
|
|
* This must be called separately for Subject and Talk pages
|
|
*
|
|
* @param LinkTarget $oldTarget
|
|
* @param LinkTarget $newTarget
|
|
*/
|
|
public function duplicateEntry( LinkTarget $oldTarget, LinkTarget $newTarget ) {
|
|
$dbw = $this->loadBalancer->getConnection( DB_MASTER, [ 'watchlist' ] );
|
|
|
|
$result = $dbw->select(
|
|
'watchlist',
|
|
[ 'wl_user', 'wl_notificationtimestamp' ],
|
|
[
|
|
'wl_namespace' => $oldTarget->getNamespace(),
|
|
'wl_title' => $oldTarget->getDBkey(),
|
|
],
|
|
__METHOD__,
|
|
[ 'FOR UPDATE' ]
|
|
);
|
|
|
|
$newNamespace = $newTarget->getNamespace();
|
|
$newDBkey = $newTarget->getDBkey();
|
|
|
|
# Construct array to replace into the watchlist
|
|
$values = [];
|
|
foreach ( $result as $row ) {
|
|
$values[] = [
|
|
'wl_user' => $row->wl_user,
|
|
'wl_namespace' => $newNamespace,
|
|
'wl_title' => $newDBkey,
|
|
'wl_notificationtimestamp' => $row->wl_notificationtimestamp,
|
|
];
|
|
}
|
|
|
|
if ( !empty( $values ) ) {
|
|
# Perform replace
|
|
# Note that multi-row replace is very efficient for MySQL but may be inefficient for
|
|
# some other DBMSes, mostly due to poor simulation by us
|
|
$dbw->replace(
|
|
'watchlist',
|
|
[ [ 'wl_user', 'wl_namespace', 'wl_title' ] ],
|
|
$values,
|
|
__METHOD__
|
|
);
|
|
}
|
|
|
|
$this->loadBalancer->reuseConnection( $dbw );
|
|
}
|
|
|
|
}
|