WIP: Symfony 6 project remake #2

Draft
skobkin wants to merge 103 commits from symfony6_remake into master
4 changed files with 25 additions and 16 deletions
Showing only changes of commit 5c916a636f - Show all commits

11
.env
View file

@ -38,3 +38,14 @@ MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0
###> symfony/mailer ### ###> symfony/mailer ###
# MAILER_DSN=null://null # MAILER_DSN=null://null
###< symfony/mailer ### ###< symfony/mailer ###
# Point tools settings
APP_USER_ID=435
APP_USER_LOGIN=point-tools
APP_POINT_DOMAIN=point.im
APP_POINT_SCHEME=https
APP_POINT_API_DELAY=5000
APP_CRAWLER_SECRET=some_secret_for_crawler_change_it_right_away
# Telegram Bot settings
TELEGRAM_BOT_TOKEN=123:abc

View file

@ -11,21 +11,19 @@ services:
autowire: true # Automatically injects dependencies in your services. autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc. autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
bind: bind:
# TODO: fix retrieval
# Point Tools # Point Tools
$appUserId: 435 $appUserId: '%env(int:APP_USER_ID)%'
$appUserLogin: 'point-tools' $appUserLogin: 'env(string:APP_USER_LOGIN)'
# Telegram Bot API # Telegram Bot API
$telegramToken: '' $telegramToken: 'env(string:TELEGRAM_BOT_TOKEN)'
$debugEnabled: '%kernel.debug%' $debugEnabled: '%kernel.debug%'
# Point API # Point API
$pointDomain: 'point.im' $pointDomain: 'env(string:APP_POINT_DOMAIN)'
$pointScheme: 'https' $pointScheme: 'env(string:APP_POINT_SCHEME)'
$pointApiDelay: 5000 $pointApiDelay: '%env(int:APP_POINT_API_DELAY)%'
$pointAppUserId: ''
$pointApiClient: '@app.point.http_client' $pointApiClient: '@app.point.http_client'
# Crawler API # Crawler API
$crawlerToken: '' $crawlerSecret: 'env(string:APP_CRAWLER_SECRET)'
# makes classes in src/ available to be used as services # makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name # this creates a service per class whose id is the fully-qualified class name

View file

@ -27,7 +27,7 @@ class UpdateSubscriptionsCommand extends Command
private readonly UserApi $api, private readonly UserApi $api,
private readonly SubscriptionsManager $subscriptionManager, private readonly SubscriptionsManager $subscriptionManager,
private readonly int $pointApiDelay, private readonly int $pointApiDelay,
private readonly int $pointAppUserId, private readonly int $appUserId,
) { ) {
parent::__construct(); parent::__construct();
} }
@ -155,9 +155,9 @@ class UpdateSubscriptionsCommand extends Command
} else { } else {
/** @var User $serviceUser */ /** @var User $serviceUser */
try { try {
$serviceUser = $this->userRepo->findActiveUserWithSubscribers($this->pointAppUserId); $serviceUser = $this->userRepo->findActiveUserWithSubscribers($this->appUserId);
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->error('Error while getting active user with subscribers', ['app_user_id' => $this->pointAppUserId]); $this->logger->error('Error while getting active user with subscribers', ['app_user_id' => $this->appUserId]);
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->pointAppUserId); $serviceUser = $this->api->getUserById($this->appUserId);
} 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->pointAppUserId); $usersForUpdate = $this->api->getUserSubscribersById($this->appUserId);
} 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');

View file

@ -12,7 +12,7 @@ use Symfony\Component\HttpFoundation\{Request, Response};
class CrawlerController extends AbstractApiController class CrawlerController extends AbstractApiController
{ {
public function __construct( public function __construct(
private readonly string $crawlerToken, private readonly string $crawlerSecret,
) { ) {
} }
@ -20,7 +20,7 @@ class CrawlerController extends AbstractApiController
{ {
$remoteToken = $request->request->get('token'); $remoteToken = $request->request->get('token');
if (!$this->crawlerToken || ($this->crawlerToken !== $remoteToken)) { if (!$this->crawlerSecret || ($this->crawlerSecret !== $remoteToken)) {
return $this->createErrorResponse( return $this->createErrorResponse(
'Token error. Please check it in crawler and API parameters.', 'Token error. Please check it in crawler and API parameters.',
Response::HTTP_FORBIDDEN, Response::HTTP_FORBIDDEN,