unique key violation exception is thrown as \Exception thus we need to check the reason
This commit is contained in:
parent
bb38c41b2f
commit
b09210655e
@ -4,7 +4,6 @@ declare(strict_types=1);
|
|||||||
namespace OCA\GPodderSync\Controller;
|
namespace OCA\GPodderSync\Controller;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
|
||||||
use GuzzleHttp\Psr7\Response;
|
use GuzzleHttp\Psr7\Response;
|
||||||
use OCA\GPodderSync\Core\EpisodeAction\EpisodeActionReader;
|
use OCA\GPodderSync\Core\EpisodeAction\EpisodeActionReader;
|
||||||
use OCA\GPodderSync\Db\EpisodeAction\EpisodeActionEntity;
|
use OCA\GPodderSync\Db\EpisodeAction\EpisodeActionEntity;
|
||||||
@ -12,6 +11,7 @@ use OCA\GPodderSync\Db\EpisodeAction\EpisodeActionRepository;
|
|||||||
use OCA\GPodderSync\Db\EpisodeAction\EpisodeActionWriter;
|
use OCA\GPodderSync\Db\EpisodeAction\EpisodeActionWriter;
|
||||||
use OCP\AppFramework\Controller;
|
use OCP\AppFramework\Controller;
|
||||||
use OCP\AppFramework\Http\JSONResponse;
|
use OCP\AppFramework\Http\JSONResponse;
|
||||||
|
use OCP\DB\Exception;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
|
|
||||||
class EpisodeActionController extends Controller {
|
class EpisodeActionController extends Controller {
|
||||||
@ -66,12 +66,14 @@ class EpisodeActionController extends Controller {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
return $this->episodeActionWriter->save($episodeActionEntity);
|
return $this->episodeActionWriter->save($episodeActionEntity);
|
||||||
} catch (UniqueConstraintViolationException $ex) {
|
} catch (\Exception $exception) {
|
||||||
$IdEpisodeActionEntityToUpdate = $this->episodeActionRepository->findByEpisode($episodeAction->getEpisode(), $this->userId)->getId();
|
if ($exception->getReason() === Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
|
||||||
$episodeActionEntity->setId($IdEpisodeActionEntityToUpdate);
|
$idEpisodeActionEntityToUpdate = $this->episodeActionRepository->findByEpisode($episodeAction->getEpisode(), $this->userId)->getId();
|
||||||
|
$episodeActionEntity->setId($idEpisodeActionEntityToUpdate);
|
||||||
return $this->episodeActionWriter->update($episodeActionEntity);
|
return $this->episodeActionWriter->update($episodeActionEntity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -3,10 +3,10 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace OCA\GPodderSync\Core\SubscriptionChange;
|
namespace OCA\GPodderSync\Core\SubscriptionChange;
|
||||||
|
|
||||||
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
|
||||||
use OCA\GPodderSync\Db\SubscriptionChange\SubscriptionChangeEntity;
|
use OCA\GPodderSync\Db\SubscriptionChange\SubscriptionChangeEntity;
|
||||||
use OCA\GPodderSync\Db\SubscriptionChange\SubscriptionChangeRepository;
|
use OCA\GPodderSync\Db\SubscriptionChange\SubscriptionChangeRepository;
|
||||||
use OCA\GPodderSync\Db\SubscriptionChange\SubscriptionChangeWriter;
|
use OCA\GPodderSync\Db\SubscriptionChange\SubscriptionChangeWriter;
|
||||||
|
use OCP\DB\Exception;
|
||||||
|
|
||||||
class SubscriptionChangeSaver {
|
class SubscriptionChangeSaver {
|
||||||
|
|
||||||
@ -48,13 +48,15 @@ class SubscriptionChangeSaver {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$this->subscriptionChangeWriter->create($subscriptionChangeEntity);
|
$this->subscriptionChangeWriter->create($subscriptionChangeEntity);
|
||||||
} catch (UniqueConstraintViolationException $ex) {
|
} catch (\Exception $exception) {
|
||||||
|
if ($exception->getReason() === Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
|
||||||
$idEpisodeActionEntityToUpdate = $this->subscriptionChangeRepository->findByUrl($subscriptionChangeEntity->getUrl(), $userId)->getId();
|
$idEpisodeActionEntityToUpdate = $this->subscriptionChangeRepository->findByUrl($subscriptionChangeEntity->getUrl(), $userId)->getId();
|
||||||
$subscriptionChangeEntity->setId($idEpisodeActionEntityToUpdate);
|
$subscriptionChangeEntity->setId($idEpisodeActionEntityToUpdate);
|
||||||
$this->subscriptionChangeWriter->update($subscriptionChangeEntity);
|
$this->subscriptionChangeWriter->update($subscriptionChangeEntity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user