Fix use of RawMessage in Status::getMessage()
[mediawiki.git] / includes / WatchedItemStore.php
blob83a5856869be87588906f9ccf57f5987fd5ba5ed
1 <?php
3 /**
4 * Storage layer class for WatchedItems.
5 * Database interaction
7 * @author Addshore
9 * @since 1.27
11 class WatchedItemStore {
13 /**
14 * @var LoadBalancer
16 private $loadBalancer;
18 public function __construct( LoadBalancer $loadBalancer ) {
19 $this->loadBalancer = $loadBalancer;
22 /**
23 * @return self
25 public static function getDefaultInstance() {
26 static $instance;
27 if ( !$instance ) {
28 $instance = new self( wfGetLB() );
30 return $instance;
33 /**
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(
47 'watchlist',
48 [ 'wl_user', 'wl_notificationtimestamp' ],
50 'wl_namespace' => $oldTarget->getNamespace(),
51 'wl_title' => $oldTarget->getDBkey(),
53 __METHOD__,
54 [ 'FOR UPDATE' ]
57 $newNamespace = $newTarget->getNamespace();
58 $newDBkey = $newTarget->getDBkey();
60 # Construct array to replace into the watchlist
61 $values = [];
62 foreach ( $result as $row ) {
63 $values[] = [
64 'wl_user' => $row->wl_user,
65 'wl_namespace' => $newNamespace,
66 'wl_title' => $newDBkey,
67 'wl_notificationtimestamp' => $row->wl_notificationtimestamp,
71 if ( !empty( $values ) ) {
72 # Perform replace
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
75 $dbw->replace(
76 'watchlist',
77 [ [ 'wl_user', 'wl_namespace', 'wl_title' ] ],
78 $values,
79 __METHOD__
83 $this->loadBalancer->reuseConnection( $dbw );