WIP: Symfony 6 project remake #2
|
@ -18,11 +18,11 @@ use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
class RestoreRemovedUsersCommand extends Command
|
class RestoreRemovedUsersCommand extends Command
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly LoggerInterface $logger,
|
private readonly LoggerInterface $logger,
|
||||||
private readonly EntityManagerInterface $em,
|
private readonly EntityManagerInterface $em,
|
||||||
private readonly UserRepository $userRepo,
|
private readonly UserRepository $userRepo,
|
||||||
private readonly UserApi $userApi,
|
private readonly UserApi $userApi,
|
||||||
private readonly int $apiDelay,
|
private readonly int $pointApiDelay,
|
||||||
) {
|
) {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ class RestoreRemovedUsersCommand extends Command
|
||||||
$io = new SymfonyStyle($input, $output);
|
$io = new SymfonyStyle($input, $output);
|
||||||
|
|
||||||
foreach ($this->userRepo->findBy(['removed' => true]) as $removedUser) {
|
foreach ($this->userRepo->findBy(['removed' => true]) as $removedUser) {
|
||||||
\usleep($this->apiDelay);
|
\usleep($this->pointApiDelay);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$remoteUser = $this->userApi->getUserById($removedUser->getId());
|
$remoteUser = $this->userApi->getUserById($removedUser->getId());
|
||||||
|
|
|
@ -22,12 +22,12 @@ class UpdateSubscriptionsCommand extends Command
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly EntityManagerInterface $em,
|
private readonly EntityManagerInterface $em,
|
||||||
private readonly LoggerInterface $logger,
|
private readonly LoggerInterface $logger,
|
||||||
private readonly UserRepository $userRepo,
|
private readonly UserRepository $userRepo,
|
||||||
private readonly UserApi $api,
|
private readonly UserApi $api,
|
||||||
private readonly SubscriptionsManager $subscriptionManager,
|
private readonly SubscriptionsManager $subscriptionManager,
|
||||||
private readonly int $apiDelay,
|
private readonly int $pointApiDelay,
|
||||||
private readonly int $appUserId
|
private readonly int $pointAppUserId,
|
||||||
) {
|
) {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ class UpdateSubscriptionsCommand extends Command
|
||||||
$progress->start(count($usersForUpdate));
|
$progress->start(count($usersForUpdate));
|
||||||
|
|
||||||
foreach ($usersForUpdate as $user) {
|
foreach ($usersForUpdate as $user) {
|
||||||
usleep($this->apiDelay);
|
usleep($this->pointApiDelay);
|
||||||
|
|
||||||
$progress->advance();
|
$progress->advance();
|
||||||
$this->logger->info('Processing @'.$user->getLogin());
|
$this->logger->info('Processing @'.$user->getLogin());
|
||||||
|
@ -155,9 +155,9 @@ class UpdateSubscriptionsCommand extends Command
|
||||||
} else {
|
} else {
|
||||||
/** @var User $serviceUser */
|
/** @var User $serviceUser */
|
||||||
try {
|
try {
|
||||||
$serviceUser = $this->userRepo->findActiveUserWithSubscribers($this->appUserId);
|
$serviceUser = $this->userRepo->findActiveUserWithSubscribers($this->pointAppUserId);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->logger->error('Error while getting active user with subscribers', ['app_user_id' => $this->appUserId]);
|
$this->logger->error('Error while getting active user with subscribers', ['app_user_id' => $this->pointAppUserId]);
|
||||||
|
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
@ -166,7 +166,7 @@ class UpdateSubscriptionsCommand extends Command
|
||||||
$this->logger->warning('Service user not found or marked as removed. Falling back to API.');
|
$this->logger->warning('Service user not found or marked as removed. Falling back to API.');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$serviceUser = $this->api->getUserById($this->appUserId);
|
$serviceUser = $this->api->getUserById($this->pointAppUserId);
|
||||||
} catch (UserNotFoundException $e) {
|
} catch (UserNotFoundException $e) {
|
||||||
throw new \RuntimeException('Service user not found in the database and could not be retrieved from API.');
|
throw new \RuntimeException('Service user not found in the database and could not be retrieved from API.');
|
||||||
}
|
}
|
||||||
|
@ -175,7 +175,7 @@ class UpdateSubscriptionsCommand extends Command
|
||||||
$this->logger->info('Getting service subscribers');
|
$this->logger->info('Getting service subscribers');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$usersForUpdate = $this->api->getUserSubscribersById($this->appUserId);
|
$usersForUpdate = $this->api->getUserSubscribersById($this->pointAppUserId);
|
||||||
} catch (UserNotFoundException $e) {
|
} catch (UserNotFoundException $e) {
|
||||||
$this->logger->critical('Service user deleted or API response is invalid');
|
$this->logger->critical('Service user deleted or API response is invalid');
|
||||||
|
|
||||||
|
|
|
@ -23,11 +23,11 @@ class UpdateUsersPrivacyCommand extends Command
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly EntityManagerInterface $em,
|
private readonly EntityManagerInterface $em,
|
||||||
private readonly LoggerInterface $logger,
|
private readonly LoggerInterface $logger,
|
||||||
private readonly UserRepository $userRepo,
|
private readonly UserRepository $userRepo,
|
||||||
private readonly UserApi $api,
|
private readonly UserApi $api,
|
||||||
private readonly int $apiDelay,
|
private readonly int $pointApiDelay,
|
||||||
private readonly int $appUserId,
|
private readonly int $pointAppUserId,
|
||||||
) {
|
) {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ class UpdateUsersPrivacyCommand extends Command
|
||||||
$progress->start(count($usersForUpdate));
|
$progress->start(count($usersForUpdate));
|
||||||
|
|
||||||
foreach ($usersForUpdate as $user) {
|
foreach ($usersForUpdate as $user) {
|
||||||
usleep($this->apiDelay);
|
usleep($this->pointApiDelay);
|
||||||
|
|
||||||
$progress->advance();
|
$progress->advance();
|
||||||
$this->logger->info('Processing @'.$user->getLogin());
|
$this->logger->info('Processing @'.$user->getLogin());
|
||||||
|
@ -129,9 +129,9 @@ class UpdateUsersPrivacyCommand extends Command
|
||||||
|
|
||||||
/** @var User $serviceUser */
|
/** @var User $serviceUser */
|
||||||
try {
|
try {
|
||||||
$serviceUser = $this->userRepo->findActiveUserWithSubscribers($this->appUserId);
|
$serviceUser = $this->userRepo->findActiveUserWithSubscribers($this->pointAppUserId);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->logger->error('Error while getting active user with subscribers', ['app_user_id' => $this->appUserId]);
|
$this->logger->error('Error while getting active user with subscribers', ['app_user_id' => $this->pointAppUserId]);
|
||||||
|
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ class UpdateUsersPrivacyCommand extends Command
|
||||||
$this->logger->warning('Service user not found or marked as removed. Falling back to API.');
|
$this->logger->warning('Service user not found or marked as removed. Falling back to API.');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$serviceUser = $this->api->getUserById($this->appUserId);
|
$serviceUser = $this->api->getUserById($this->pointAppUserId);
|
||||||
} catch (UserNotFoundException $e) {
|
} catch (UserNotFoundException $e) {
|
||||||
throw new \RuntimeException('Service user not found in the database and could not be retrieved from API.');
|
throw new \RuntimeException('Service user not found in the database and could not be retrieved from API.');
|
||||||
}
|
}
|
||||||
|
@ -149,7 +149,7 @@ class UpdateUsersPrivacyCommand extends Command
|
||||||
$this->logger->info('Getting service subscribers');
|
$this->logger->info('Getting service subscribers');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return $this->api->getUserSubscribersById($this->appUserId);
|
return $this->api->getUserSubscribersById($this->pointAppUserId);
|
||||||
} catch (UserNotFoundException $e) {
|
} catch (UserNotFoundException $e) {
|
||||||
$this->logger->critical('Service user deleted or API response is invalid');
|
$this->logger->critical('Service user deleted or API response is invalid');
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue