/** * Deletes a range of subscriptions. * * @param string $minId Entity id string indicating the first element in the deletion range * @param string $maxId Entity id string indicating the last element in the deletion range */ private function deleteSubscriptionRange($minId, $maxId) { $dbw = $this->repoConnectionManager->beginAtomicSection(__METHOD__); $conditions = array('cs_subscriber_id' => $this->subscriberWikiId, 'cs_entity_id >= ' . $dbw->addQuotes($minId), 'cs_entity_id <= ' . $dbw->addQuotes($maxId)); $dbw->delete('wb_changes_subscription', $conditions, __METHOD__); $this->repoConnectionManager->commitAtomicSection($dbw, __METHOD__); }
public function testBeginAtomicSection() { $connection = $this->getConnectionMock(); $lb = $this->getLoadBalancerMock(); $lb->expects($this->exactly(2))->method('getConnection')->with(DB_MASTER)->will($this->returnValue($connection)); $connection->expects($this->once())->method('startAtomic')->will($this->returnValue(null)); $manager = new ConsistentReadConnectionManager($lb); $manager->beginAtomicSection('TEST'); // Should also ask for a DB_MASTER connection. // This is asserted by the $lb mock. $manager->getReadConnection(); }
/** * @see SubscriptionManager::unsubscribe * * @param string $subscriber Global site ID of the client * @param EntityId[] $entityIds The entities to subscribe to. * * @throws InvalidArgumentException * @throws UsageTrackerException * @throws Exception */ public function unsubscribe($subscriber, array $entityIds) { if (!is_string($subscriber)) { throw new InvalidArgumentException('$subscriber must be a string.'); } $unsubscriptions = $this->idsToString($entityIds); $db = $this->connectionManager->beginAtomicSection(__METHOD__); try { $oldSubscriptions = $this->querySubscriptions($db, $subscriber, $unsubscriptions); $obsoleteSubscriptions = array_intersect($unsubscriptions, $oldSubscriptions); $this->deleteSubscriptions($db, $subscriber, $obsoleteSubscriptions); $this->connectionManager->commitAtomicSection($db, __METHOD__); } catch (Exception $ex) { $this->connectionManager->rollbackAtomicSection($db, __METHOD__); if ($ex instanceof DBError) { throw new UsageTrackerException($ex->getMessage(), $ex->getCode(), $ex); } else { throw $ex; } } }