4 * Storage layer class for WatchedItems.
11 class WatchedItemStore
{
16 private $loadBalancer;
18 public function __construct( LoadBalancer
$loadBalancer ) {
19 $this->loadBalancer
= $loadBalancer;
25 public static function getDefaultInstance() {
28 $instance = new self( wfGetLB() );
34 * Check if the given title already is watched by the user, and if so
35 * add a watch for the new title.
37 * To be used for page renames and such.
38 * This must be called separately for Subject and Talk pages
40 * @param LinkTarget $oldTarget
41 * @param LinkTarget $newTarget
43 public function duplicateEntry( LinkTarget
$oldTarget, LinkTarget
$newTarget ) {
44 $dbw = $this->loadBalancer
->getConnection( DB_MASTER
, [ 'watchlist' ] );
46 $result = $dbw->select(
48 [ 'wl_user', 'wl_notificationtimestamp' ],
50 'wl_namespace' => $oldTarget->getNamespace(),
51 'wl_title' => $oldTarget->getDBkey(),
57 $newNamespace = $newTarget->getNamespace();
58 $newDBkey = $newTarget->getDBkey();
60 # Construct array to replace into the watchlist
62 foreach ( $result as $row ) {
64 'wl_user' => $row->wl_user
,
65 'wl_namespace' => $newNamespace,
66 'wl_title' => $newDBkey,
67 'wl_notificationtimestamp' => $row->wl_notificationtimestamp
,
71 if ( !empty( $values ) ) {
73 # Note that multi-row replace is very efficient for MySQL but may be inefficient for
74 # some other DBMSes, mostly due to poor simulation by us
77 [ [ 'wl_user', 'wl_namespace', 'wl_title' ] ],
83 $this->loadBalancer
->reuseConnection( $dbw );