Changeset View
Changeset View
Standalone View
Standalone View
src/applications/people/editor/PhabricatorUserEditor.php
| Show First 20 Lines • Show All 663 Lines • ▼ Show 20 Lines | $user->openTransaction(); | ||||
| $log->setNewValue($email->getAddress()); | $log->setNewValue($email->getAddress()); | ||||
| $log->save(); | $log->save(); | ||||
| } | } | ||||
| $user->endWriteLocking(); | $user->endWriteLocking(); | ||||
| $user->saveTransaction(); | $user->saveTransaction(); | ||||
| } | } | ||||
| /* -( Subscribing and Unsubscribing from Push Notifications )----------- */ | |||||
| /** | |||||
| * @task webpush | |||||
| */ | |||||
| public function addSubscription( | |||||
| PhabricatorUser $user, | |||||
| PhabricatorUserWebPushSubscriber $subscriber) { | |||||
| $actor = $this->requireActor(); | |||||
| if (!$user->getID()) { | |||||
| throw new Exception(pht('User has not been created yet!')); | |||||
| } | |||||
| if ($subscriber->getID()) { | |||||
| throw new Exception(pht('Subscription has already been created!')); | |||||
| } | |||||
| $user->openTransaction(); | |||||
| $user->beginWriteLocking(); | |||||
| $user->reload(); | |||||
| try { | |||||
| $subscriber->save(); | |||||
| } catch (AphrontDuplicateKeyQueryException $ex) { | |||||
| $user->endWriteLocking(); | |||||
| $user->killTransaction(); | |||||
| throw $ex; | |||||
| } | |||||
| $log = PhabricatorUserLog::initializeNewLog( | |||||
| $actor, | |||||
| $user->getPHID(), | |||||
| PhabricatorUserLog::ACTION_WEBPUSH_ADD); | |||||
| $log->setNewValue($subscriber->getSubscriptionId()); | |||||
| $log->save(); | |||||
| $user->endWriteLocking(); | |||||
| $user->saveTransaction(); | |||||
| return $this; | |||||
| } | |||||
| /** | |||||
| * @task webpush | |||||
| */ | |||||
| public function removeSubscription( | |||||
| PhabricatorUser $user, | |||||
| PhabricatorUserWebPushSubscriber $subscriber) { | |||||
| $actor = $this->requireActor(); | |||||
| if (!$user->getID()) { | |||||
| throw new Exception(pht('User has not been created yet!')); | |||||
| } | |||||
| if (!$subscriber->getID()) { | |||||
| throw new Exception(pht('Subscription has already been deleted!')); | |||||
| } | |||||
| $user->openTransaction(); | |||||
| $user->beginWriteLocking(); | |||||
| $user->reload(); | |||||
| try { | |||||
| $subscriber->delete(); | |||||
| } catch (AphrontQueryException $ex) { | |||||
| $user->endWriteLocking(); | |||||
| $user->killTransaction(); | |||||
| throw $ex; | |||||
| } | |||||
| $log = PhabricatorUserLog::initializeNewLog( | |||||
| $actor, | |||||
| $user->getPHID(), | |||||
| PhabricatorUserLog::ACTION_WEBPUSH_REMOVE); | |||||
| $log->setNewValue($subscriber->getSubscriptionId()); | |||||
| $log->save(); | |||||
| $user->endWriteLocking(); | |||||
| $user->saveTransaction(); | |||||
| return $this; | |||||
| } | |||||
| /* -( Internals )---------------------------------------------------------- */ | /* -( Internals )---------------------------------------------------------- */ | ||||
| /** | /** | ||||
| * @task internal | * @task internal | ||||
| */ | */ | ||||
| private function willAddEmail(PhabricatorUserEmail $email) { | private function willAddEmail(PhabricatorUserEmail $email) { | ||||
| ▲ Show 20 Lines • Show All 55 Lines • Show Last 20 Lines | |||||