From 6c8c0829ca936e35db67c05ec74235db13d144e8 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Sat, 19 Jan 2019 02:07:00 +0300 Subject: [PATCH] Update commands now can fallback to API for point-tools user retrieval if it's not found in the database. Also small bug fixed. --- .../Command/UpdateSubscriptionsCommand.php | 11 +++++++---- .../Command/UpdateUsersPrivacyCommand.php | 8 ++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Skobkin/Bundle/PointToolsBundle/Command/UpdateSubscriptionsCommand.php b/src/Skobkin/Bundle/PointToolsBundle/Command/UpdateSubscriptionsCommand.php index e8e3e1c..ab33530 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Command/UpdateSubscriptionsCommand.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Command/UpdateSubscriptionsCommand.php @@ -192,16 +192,19 @@ class UpdateSubscriptionsCommand extends Command try { $serviceUser = $this->userRepo->findActiveUserWithSubscribers($this->appUserId); } catch (\Exception $e) { - $this->logger->error('Error while getting active user with subscribers', ['app_user_id' => $appUserId]); + $this->logger->error('Error while getting active user with subscribers', ['app_user_id' => $this->appUserId]); throw $e; } if (!$serviceUser) { - $this->logger->critical('Service user not found or marked as removed'); - // @todo Retrieving user + $this->logger->warning('Service user not found or marked as removed. Falling back to API.'); - throw new \RuntimeException('Service user not found in the database'); + try { + $serviceUser = $this->api->getUserById($this->appUserId); + } catch (UserNotFoundException $e) { + throw new \RuntimeException('Service user not found in the database and could not be retrieved from API.'); + } } $this->logger->info('Getting service subscribers'); diff --git a/src/Skobkin/Bundle/PointToolsBundle/Command/UpdateUsersPrivacyCommand.php b/src/Skobkin/Bundle/PointToolsBundle/Command/UpdateUsersPrivacyCommand.php index 124adcd..f43af42 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Command/UpdateUsersPrivacyCommand.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Command/UpdateUsersPrivacyCommand.php @@ -164,9 +164,13 @@ class UpdateUsersPrivacyCommand extends Command } if (!$serviceUser) { - $this->logger->critical('Service user not found or marked as removed'); + $this->logger->warning('Service user not found or marked as removed. Falling back to API.'); - throw new \RuntimeException('Service user not found in the database'); + try { + $serviceUser = $this->api->getUserById($this->appUserId); + } catch (UserNotFoundException $e) { + throw new \RuntimeException('Service user not found in the database and could not be retrieved from API.'); + } } $this->logger->info('Getting service subscribers');