mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-27 17:20:40 +00:00
Merge "Remove overbroad DB error catching in ApiEchoPushSubscriptionsCreate"
This commit is contained in:
commit
ea200ace05
|
@ -47,9 +47,9 @@ class SubscriptionManager extends EchoAbstractMapper {
|
|||
* @param User $user
|
||||
* @param string $provider Provider name string (validated by presence in the PARAM_TYPE array)
|
||||
* @param string $token Subscriber token provided by the push provider
|
||||
* @throws DBError if the subscription ID already exists in the DB
|
||||
* @return bool true if the subscription was created; false if the token already exists
|
||||
*/
|
||||
public function create( User $user, string $provider, string $token ): void {
|
||||
public function create( User $user, string $provider, string $token ): bool {
|
||||
$this->dbw->insert(
|
||||
'echo_push_subscription',
|
||||
[
|
||||
|
@ -59,8 +59,10 @@ class SubscriptionManager extends EchoAbstractMapper {
|
|||
'eps_token_sha256' => hash( 'sha256', $token ),
|
||||
'eps_updated' => $this->dbw->timestamp()
|
||||
],
|
||||
__METHOD__
|
||||
__METHOD__,
|
||||
[ 'IGNORE' ]
|
||||
);
|
||||
return (bool)$this->dbw->affectedRows();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,7 +4,6 @@ namespace EchoPush\Api;
|
|||
|
||||
use ApiBase;
|
||||
use ApiMain;
|
||||
use DBError;
|
||||
use EchoPush\SubscriptionManager;
|
||||
use EchoServices;
|
||||
use Wikimedia\ParamValidator\ParamValidator;
|
||||
|
@ -59,9 +58,8 @@ class ApiEchoPushSubscriptionsCreate extends ApiBase {
|
|||
public function execute(): void {
|
||||
$provider = $this->getParameter( 'provider' );
|
||||
$token = $this->getParameter( 'providertoken' );
|
||||
try {
|
||||
$this->subscriptionManager->create( $this->getUser(), $provider, $token );
|
||||
} catch ( DBError $e ) {
|
||||
$success = $this->subscriptionManager->create( $this->getUser(), $provider, $token );
|
||||
if ( !$success ) {
|
||||
$this->dieWithError( 'apierror-echo-push-token-exists' );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue