Dependency Injection refactoring according to new autowiring and autoconfiguration. A bunch of classes refactored.
This commit is contained in:
parent
d018c94a7a
commit
b8f912b91d
|
@ -1,9 +1,182 @@
|
|||
# Learn more about services, parameters and containers at
|
||||
# http://symfony.com/doc/current/book/service_container.html
|
||||
parameters:
|
||||
# parameter_name: value
|
||||
|
||||
services:
|
||||
# service_name:
|
||||
# class: AppBundle\Directory\ClassName
|
||||
# arguments: ["@another_service_name", "plain_value", "%parameter_name%"]
|
||||
_defaults:
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
public: false
|
||||
|
||||
Skobkin\Bundle\PointToolsBundle\:
|
||||
resource: '../../src/Skobkin/Bundle/PointToolsBundle/*'
|
||||
exclude: '../../src/Skobkin/Bundle/PointToolsBundle/{DataFixtures,DependencyInjection,DQL,DTO,Entity,Exception,Repository,Twig}'
|
||||
|
||||
Skobkin\Bundle\PointToolsBundle\Controller\:
|
||||
resource: '../../src/Skobkin/Bundle/PointToolsBundle/Controller'
|
||||
public: true
|
||||
tags: ['controller.service_arguments']
|
||||
|
||||
# HTTP client for Telegram
|
||||
app.http.telegram_client:
|
||||
class: GuzzleHttp\Client
|
||||
arguments: [{ timeout: 3.0 }]
|
||||
tags:
|
||||
- { name: csa_guzzle.client }
|
||||
|
||||
# HTTP client for Point API
|
||||
GuzzleHttp\Client:
|
||||
class: GuzzleHttp\Client
|
||||
autowiring_types: GuzzleHttp\ClientInterface
|
||||
arguments: [ { base_uri: '%point_base_url%', timeout: 5.0 } ]
|
||||
tags:
|
||||
- { name: csa_guzzle.client }
|
||||
|
||||
|
||||
# Point API clients
|
||||
# User
|
||||
Skobkin\Bundle\PointToolsBundle\Service\Api\UserApi:
|
||||
tags:
|
||||
- { name: monolog.logger, channel: point_user_api }
|
||||
# Post
|
||||
Skobkin\Bundle\PointToolsBundle\Service\Api\PostApi:
|
||||
tags:
|
||||
- { name: monolog.logger, channel: point_post_api }
|
||||
|
||||
|
||||
# Point subscription manager
|
||||
Skobkin\Bundle\PointToolsBundle\Service\SubscriptionsManager:
|
||||
# TODO deal with autowire for EventDispatcherInterface
|
||||
tags:
|
||||
- { name: monolog.logger, channel: subscribers_update }
|
||||
|
||||
|
||||
# Console commands
|
||||
# @todo https://github.com/symfony/symfony/blob/3.4/UPGRADE-3.4.md#httpkernel
|
||||
# Subsribers update
|
||||
Skobkin\Bundle\PointToolsBundle\Command\UpdateSubscriptionsCommand:
|
||||
arguments:
|
||||
$apiDelay: '%point_api_delay%'
|
||||
$appUserId: '%point_id%'
|
||||
tags:
|
||||
- { name: console.command }
|
||||
- { name: monolog.logger, channel: subscribers_update }
|
||||
# Privacy update
|
||||
Skobkin\Bundle\PointToolsBundle\Command\UpdateUsersPrivacyCommand:
|
||||
arguments:
|
||||
$apiDelay: '%point_api_delay%'
|
||||
$appUserId: '%point_id%'
|
||||
tags:
|
||||
- { name: console.command }
|
||||
- { name: monolog.logger, channel: privacy_update }
|
||||
# Restore users removed by error
|
||||
Skobkin\Bundle\PointToolsBundle\Command\RestoreRemovedUsersCommand:
|
||||
arguments:
|
||||
$apiDelay: '%point_api_delay%'
|
||||
tags:
|
||||
- { name: console.command }
|
||||
# Webhook management
|
||||
Skobkin\Bundle\PointToolsBundle\Command\TelegramWebHookCommand:
|
||||
arguments:
|
||||
$telegramToken: '%telegram_token%'
|
||||
$telegramWebhookMaxConnections: '%telegram_max_connections%'
|
||||
tags: [{ name: console.command }]
|
||||
# Send message
|
||||
Skobkin\Bundle\PointToolsBundle\Command\TelegramSendMessageCommand:
|
||||
arguments:
|
||||
$logChatId: '%telegram_log_chat_id%'
|
||||
tags: [{ name: console.command }]
|
||||
|
||||
|
||||
# Entity repositories as services
|
||||
# User
|
||||
Skobkin\Bundle\PointToolsBundle\Repository\UserRepository:
|
||||
factory: 'doctrine:getRepository'
|
||||
arguments: ['Skobkin\Bundle\PointToolsBundle\Entity\User']
|
||||
# Subscription
|
||||
Skobkin\Bundle\PointToolsBundle\Repository\SubscriptionRepository:
|
||||
factory: 'doctrine:getRepository'
|
||||
arguments: ['Skobkin\Bundle\PointToolsBundle\Entity\Subscription']
|
||||
# Subscription record/event
|
||||
Skobkin\Bundle\PointToolsBundle\Repository\SubscriptionEventRepository:
|
||||
factory: 'doctrine:getRepository'
|
||||
arguments: ['Skobkin\Bundle\PointToolsBundle\Entity\SubscriptionEvent']
|
||||
|
||||
# Subscription record/event
|
||||
Skobkin\Bundle\PointToolsBundle\Repository\UserRenameEventRepository:
|
||||
factory: 'doctrine:getRepository'
|
||||
arguments: ['Skobkin\Bundle\PointToolsBundle\Entity\UserRenameEvent']
|
||||
# Post repository
|
||||
Skobkin\Bundle\PointToolsBundle\Repository\Blogs\PostRepository:
|
||||
factory: 'doctrine:getRepository'
|
||||
arguments: ['Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Post']
|
||||
# Comment repository
|
||||
Skobkin\Bundle\PointToolsBundle\Repository\Blogs\CommentRepository:
|
||||
factory: 'doctrine:getRepository'
|
||||
arguments: ['Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment']
|
||||
# Tag repository
|
||||
Skobkin\Bundle\PointToolsBundle\Repository\Blogs\TagRepository:
|
||||
factory: 'doctrine:getRepository'
|
||||
arguments: ['Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Tag']
|
||||
# File repository
|
||||
Skobkin\Bundle\PointToolsBundle\Repository\Blogs\FileRepository:
|
||||
factory: 'doctrine:getRepository'
|
||||
arguments: ['Skobkin\Bundle\PointToolsBundle\Entity\Blogs\File']
|
||||
# Telegram Account repository
|
||||
Skobkin\Bundle\PointToolsBundle\Repository\Telegram\AccountRepository:
|
||||
factory: 'doctrine:getRepository'
|
||||
arguments: ['Skobkin\Bundle\PointToolsBundle\Entity\Telegram\Account']
|
||||
|
||||
# Custom Markdown parser
|
||||
app.point.markdown_parser:
|
||||
class: Skobkin\Bundle\PointToolsBundle\Service\Markdown\PointParser
|
||||
arguments: [[], '@router']
|
||||
tags:
|
||||
- { name: markdown.parser }
|
||||
|
||||
|
||||
# Event listeners
|
||||
# User name changed in Doctrine
|
||||
Skobkin\Bundle\PointToolsBundle\EventListener\UsersUpdatedSubscriber:
|
||||
tags:
|
||||
- { name: doctrine.event_subscriber, connection: default }
|
||||
# User renaming
|
||||
Skobkin\Bundle\PointToolsBundle\EventListener\UsersRenamedListener:
|
||||
tags:
|
||||
- { name: kernel.event_listener, event: app.users.renamed }
|
||||
# User subscribers updated
|
||||
Skobkin\Bundle\PointToolsBundle\EventListener\UserSubscribersUpdatedListener:
|
||||
tags:
|
||||
- { name: kernel.event_listener, event: app.user.subscribers_updated }
|
||||
|
||||
|
||||
# Twig extensions
|
||||
Skobkin\Bundle\PointToolsBundle\Twig\PointUrlExtension:
|
||||
arguments:
|
||||
$pointDomain: '%point_domain%'
|
||||
$pointScheme: '%point_scheme%'
|
||||
$pointBaseUrl: '%point_base_url%'
|
||||
|
||||
# Telegram services
|
||||
# Bot API client
|
||||
unreal4u\TelegramAPI\TgLog:
|
||||
autowiring_types: unreal4u\TelegramAPI\TgLog
|
||||
arguments:
|
||||
$client: '@app.http.telegram_client'
|
||||
$botToken: '%telegram_token%'
|
||||
# Logger API client
|
||||
app.telegram.logger_client:
|
||||
class: unreal4u\TelegramAPI\TgLog
|
||||
arguments:
|
||||
$botToken: '%telegram_token%'
|
||||
$logger: null
|
||||
$client: '@app.http.telegram_client'
|
||||
|
||||
# Monolog handler
|
||||
unreal4u\MonologHandler:
|
||||
arguments:
|
||||
$chatId: '%telegram_log_chat_id%'
|
||||
$level: 'error'
|
||||
|
||||
# Private message processor
|
||||
Skobkin\Bundle\PointToolsBundle\Service\Telegram\PrivateMessageProcessor:
|
||||
arguments:
|
||||
$appUserId: '%point_id%'
|
||||
|
|
12
app/crontab
12
app/crontab
|
@ -1,10 +1,10 @@
|
|||
# Point-Tools
|
||||
# Subscriptions
|
||||
# Primary subscribers
|
||||
*/10 * * * * flock -n /tmp/point_tools_sub_update.lock timeout 300 /usr/bin/php /var/www/point-tools/current/app/console point:update:subscriptions --env=prod
|
||||
# App users
|
||||
0 0 * * * flock -n /tmp/point_tools_sub_update_all.lock timeout 3600 /usr/bin/php /var/www/point-tools/current/app/console point:update:subscriptions --all-users --env=prod
|
||||
*/10 * * * * flock -n /tmp/point_tools_sub_update.lock timeout 300 /usr/bin/php /var/www/point.skobk.in/current/app/console point:update:subscriptions --env=prod
|
||||
# All users
|
||||
0 0 * * * flock -n /tmp/point_tools_sub_update_all.lock timeout 3600 /usr/bin/php /var/www/point.skobk.in/current/app/console point:update:subscriptions --all-users --env=prod
|
||||
# Privacy
|
||||
0 1 * * * flock -n /tmp/point_tools_privacy_update_all.lock timeout 3600 /usr/bin/php /var/www/point.skobk.in/current/app/console point:update:privacy --all-users --env=prod
|
||||
# Other
|
||||
# Restore users deleted by mistake
|
||||
0 0 */7 * * flock -n /tmp/point_tools_restore_users.lock timeout 300 /usr/bin/php /var/www/point-tools/current/app/console point:users:restore --env=prod
|
||||
0 0 */7 * * flock -n /tmp/point_tools_restore_users.lock timeout 300 /usr/bin/php /var/www/point.skobk.in/current/app/console point:users:restore --env=prod
|
||||
|
||||
|
|
|
@ -2,11 +2,10 @@
|
|||
|
||||
namespace Skobkin\Bundle\PointToolsBundle\Command;
|
||||
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Skobkin\Bundle\PointToolsBundle\Entity\User;
|
||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\{InputInterface, InputArgument, InputOption};
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
|
@ -19,8 +18,18 @@ use Symfony\Component\Filesystem\Filesystem;
|
|||
* WHERE u.id <> (-1)
|
||||
* ) TO '/tmp/point_users.csv' WITH HEADER DELIMITER '|' CSV;
|
||||
*/
|
||||
class ImportUsersCommand extends ContainerAwareCommand
|
||||
class ImportUsersCommand extends Command
|
||||
{
|
||||
/** @var EntityManager */
|
||||
private $em;
|
||||
|
||||
public function __construct(EntityManager $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
|
@ -48,7 +57,6 @@ class ImportUsersCommand extends ContainerAwareCommand
|
|||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$em = $this->getContainer()->get('doctrine.orm.entity_manager');
|
||||
$fs = new Filesystem();
|
||||
|
||||
$fileName = $input->getArgument('file');
|
||||
|
@ -80,9 +88,9 @@ class ImportUsersCommand extends ContainerAwareCommand
|
|||
$user = new User($row[0], $createdAt, $row[1], $row[2]);
|
||||
|
||||
if (!$input->getOption('check-only')) {
|
||||
$em->persist($user);
|
||||
$em->flush($user);
|
||||
$em->detach($user);
|
||||
$this->em->persist($user);
|
||||
$this->em->flush($user);
|
||||
$this->em->detach($user);
|
||||
}
|
||||
|
||||
if (OutputInterface::VERBOSITY_VERBOSE === $output->getVerbosity()) {
|
||||
|
|
|
@ -14,31 +14,22 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||
|
||||
class RestoreRemovedUsersCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
/**
|
||||
* @var EntityManagerInterface
|
||||
*/
|
||||
|
||||
/** @var EntityManagerInterface */
|
||||
private $em;
|
||||
|
||||
/**
|
||||
* @var UserRepository
|
||||
*/
|
||||
/** @var UserRepository */
|
||||
private $userRepo;
|
||||
|
||||
/**
|
||||
* @var UserApi
|
||||
*/
|
||||
/** @var UserApi */
|
||||
private $userApi;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
/** @var int */
|
||||
private $delay;
|
||||
|
||||
public function __construct(LoggerInterface $logger, EntityManagerInterface $em, UserRepository $userRepo, UserApi $userApi, int $delay)
|
||||
public function __construct(LoggerInterface $logger, EntityManagerInterface $em, UserRepository $userRepo, UserApi $userApi, int $apiDelay)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
@ -46,7 +37,7 @@ class RestoreRemovedUsersCommand extends Command
|
|||
$this->em = $em;
|
||||
$this->userRepo = $userRepo;
|
||||
$this->userApi = $userApi;
|
||||
$this->delay = $delay;
|
||||
$this->delay = $apiDelay;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,35 +3,24 @@
|
|||
namespace Skobkin\Bundle\PointToolsBundle\Command;
|
||||
|
||||
use Skobkin\Bundle\PointToolsBundle\Service\Telegram\MessageSender;
|
||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\{InputArgument, InputInterface, InputOption};
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class TelegramSendMessageCommand extends ContainerAwareCommand
|
||||
class TelegramSendMessageCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @var MessageSender
|
||||
*/
|
||||
/** @var MessageSender */
|
||||
private $messenger;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
/** @var int */
|
||||
private $logChatId;
|
||||
|
||||
public function setMessenger(MessageSender $messenger): void
|
||||
public function __construct(MessageSender $messenger, int $logChatId)
|
||||
{
|
||||
$this->messenger = $messenger;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $logChatId
|
||||
*/
|
||||
public function setLogChatId(int $logChatId): void
|
||||
{
|
||||
$this->logChatId = $logChatId;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,63 +2,43 @@
|
|||
|
||||
namespace Skobkin\Bundle\PointToolsBundle\Command;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Symfony\Bundle\FrameworkBundle\Routing\Router;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\{InputArgument, InputInterface};
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use unreal4u\TelegramAPI\Telegram\Methods\DeleteWebhook;
|
||||
use unreal4u\TelegramAPI\Telegram\Methods\SetWebhook;
|
||||
use unreal4u\TelegramAPI\Telegram\Methods\{DeleteWebhook, SetWebhook};
|
||||
use unreal4u\TelegramAPI\TgLog;
|
||||
|
||||
/**
|
||||
* Sets or deletes Telegram bot Web-Hook
|
||||
* @see https://core.telegram.org/bots/api#setwebhook
|
||||
*/
|
||||
class TelegramWebHookCommand extends ContainerAwareCommand
|
||||
class TelegramWebHookCommand extends Command
|
||||
{
|
||||
private const MODE_SET = 'set';
|
||||
private const MODE_DELETE = 'delete';
|
||||
|
||||
/**
|
||||
* @var TgLog
|
||||
*/
|
||||
/** @var TgLog */
|
||||
private $client;
|
||||
|
||||
/**
|
||||
* @var Router
|
||||
*/
|
||||
/** @var Router */
|
||||
private $router;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
/** @var string */
|
||||
private $token;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
/** @var int */
|
||||
private $maxConnections;
|
||||
|
||||
public function setClient(TgLog $client): void
|
||||
public function __construct(TgLog $client, Router $router, string $telegramToken, int $telegramWebhookMaxConnections)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->client = $client;
|
||||
}
|
||||
|
||||
public function setRouter(Router $router): void
|
||||
{
|
||||
$this->router = $router;
|
||||
}
|
||||
|
||||
public function setToken(string $token): void
|
||||
{
|
||||
$this->token = $token;
|
||||
}
|
||||
|
||||
public function setMaxConnections(int $maxConnections)
|
||||
{
|
||||
$this->maxConnections = $maxConnections;
|
||||
$this->token = $telegramToken;
|
||||
$this->maxConnections = $telegramWebhookMaxConnections;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,7 +8,7 @@ use Skobkin\Bundle\PointToolsBundle\Entity\{Subscription, User};
|
|||
use Skobkin\Bundle\PointToolsBundle\Exception\Api\UserNotFoundException;
|
||||
use Skobkin\Bundle\PointToolsBundle\Repository\UserRepository;
|
||||
use Skobkin\Bundle\PointToolsBundle\Service\{SubscriptionsManager, Api\UserApi};
|
||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Helper\ProgressBar;
|
||||
use Symfony\Component\Console\Input\{InputInterface, InputOption};
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
@ -16,51 +16,33 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||
/**
|
||||
* @todo https://symfony.com/doc/current/console/lockable_trait.html
|
||||
*/
|
||||
class UpdateSubscriptionsCommand extends ContainerAwareCommand
|
||||
class UpdateSubscriptionsCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @var EntityManagerInterface
|
||||
*/
|
||||
/** @var EntityManagerInterface */
|
||||
private $em;
|
||||
|
||||
/**
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
|
||||
/**
|
||||
* @var UserRepository
|
||||
*/
|
||||
/** @var UserRepository */
|
||||
private $userRepo;
|
||||
|
||||
/**
|
||||
* @var InputInterface
|
||||
*/
|
||||
/** @var InputInterface */
|
||||
private $input;
|
||||
|
||||
/**
|
||||
* @var UserApi
|
||||
*/
|
||||
/** @var UserApi */
|
||||
private $api;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
/** @var int */
|
||||
private $apiDelay = 500000;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
/** @var int */
|
||||
private $appUserId;
|
||||
|
||||
/**
|
||||
* @var SubscriptionsManager
|
||||
*/
|
||||
/** @var SubscriptionsManager */
|
||||
private $subscriptionManager;
|
||||
|
||||
/**
|
||||
* @var ProgressBar
|
||||
*/
|
||||
/** @var ProgressBar */
|
||||
private $progress;
|
||||
|
||||
public function __construct(
|
||||
|
|
|
@ -8,12 +8,12 @@ use Skobkin\Bundle\PointToolsBundle\Entity\{Subscription, User};
|
|||
use Skobkin\Bundle\PointToolsBundle\Exception\Api\{ForbiddenException, UserNotFoundException};
|
||||
use Skobkin\Bundle\PointToolsBundle\Repository\UserRepository;
|
||||
use Skobkin\Bundle\PointToolsBundle\Service\Api\UserApi;
|
||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Helper\ProgressBar;
|
||||
use Symfony\Component\Console\Input\{InputInterface, InputOption};
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class UpdateUsersPrivacyCommand extends ContainerAwareCommand
|
||||
class UpdateUsersPrivacyCommand extends Command
|
||||
{
|
||||
/** @var EntityManagerInterface */
|
||||
private $em;
|
||||
|
|
|
@ -2,13 +2,15 @@
|
|||
|
||||
namespace Skobkin\Bundle\PointToolsBundle\Controller\Api;
|
||||
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use JMS\Serializer\Serializer;
|
||||
use Skobkin\Bundle\PointToolsBundle\DTO\Api\PostsPage;
|
||||
use Skobkin\Bundle\PointToolsBundle\Service\Factory\Blogs\PostFactory;
|
||||
use Symfony\Component\HttpFoundation\{Request, Response};
|
||||
|
||||
class CrawlerController extends AbstractApiController
|
||||
{
|
||||
public function receiveAllPageAction(Request $request): Response
|
||||
public function receiveAllPageAction(Request $request, Serializer $serializer, PostFactory $postFactory, EntityManager $em): Response
|
||||
{
|
||||
$remoteToken = $request->request->get('token');
|
||||
$localToken = $this->getParameter('crawler_token');
|
||||
|
@ -19,16 +21,11 @@ class CrawlerController extends AbstractApiController
|
|||
|
||||
$json = $request->request->get('json');
|
||||
|
||||
$serializer = $this->get('jms_serializer');
|
||||
|
||||
$page = $serializer->deserialize($json, PostsPage::class, 'json');
|
||||
|
||||
/** @var PostFactory $factory */
|
||||
$factory = $this->get('app.point.post_factory');
|
||||
|
||||
$continue = $factory->createFromPageDTO($page);
|
||||
$continue = $postFactory->createFromPageDTO($page);
|
||||
|
||||
$this->getDoctrine()->getManager()->flush();
|
||||
$em->flush();
|
||||
|
||||
return $this->createSuccessResponse([
|
||||
'continue' => $continue,
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
namespace Skobkin\Bundle\PointToolsBundle\Controller;
|
||||
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
use Skobkin\Bundle\PointToolsBundle\Entity\SubscriptionEvent;
|
||||
use Skobkin\Bundle\PointToolsBundle\Entity\User;
|
||||
use Skobkin\Bundle\PointToolsBundle\Entity\{SubscriptionEvent, User};
|
||||
use Skobkin\Bundle\PointToolsBundle\Repository\SubscriptionEventRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
|
@ -15,9 +15,9 @@ class ApiController extends Controller
|
|||
*
|
||||
* @ParamConverter("user", class="SkobkinPointToolsBundle:User")
|
||||
*/
|
||||
public function lastUserSubscribersByIdAction(User $user): Response
|
||||
public function lastUserSubscribersByIdAction(User $user, SubscriptionEventRepository $subscriptionEventRepository): Response
|
||||
{
|
||||
$qb = $this->getDoctrine()->getRepository('SkobkinPointToolsBundle:SubscriptionEvent')->createQueryBuilder('se');
|
||||
$qb = $subscriptionEventRepository->createQueryBuilder('se');
|
||||
$qb
|
||||
->select(['se', 'sub'])
|
||||
->innerJoin('se.subscriber', 'sub')
|
||||
|
|
|
@ -2,23 +2,17 @@
|
|||
|
||||
namespace Skobkin\Bundle\PointToolsBundle\Controller;
|
||||
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Knp\Component\Pager\Paginator;
|
||||
use Skobkin\Bundle\PointToolsBundle\Repository\SubscriptionEventRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\{Request, Response};
|
||||
|
||||
class EventsController extends Controller
|
||||
{
|
||||
public function lastAction(Request $request): Response
|
||||
public function lastAction(Request $request, SubscriptionEventRepository $eventRepository, Paginator $paginator): Response
|
||||
{
|
||||
/** @var EntityManager $em */
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$paginator = $this->get('knp_paginator');
|
||||
|
||||
$eventsPagination = $paginator->paginate(
|
||||
$em->getRepository('SkobkinPointToolsBundle:SubscriptionEvent')->createLastSubscriptionEventsQuery(),
|
||||
$eventRepository->createLastSubscriptionEventsQuery(),
|
||||
$request->query->getInt('page', 1),
|
||||
20
|
||||
);
|
||||
|
|
|
@ -4,18 +4,21 @@ namespace Skobkin\Bundle\PointToolsBundle\Controller;
|
|||
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Skobkin\Bundle\PointToolsBundle\Form\UserSearchType;
|
||||
use Skobkin\Bundle\PointToolsBundle\Repository\{SubscriptionEventRepository, SubscriptionRepository, UserRepository};
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\Form\FormError;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\{JsonResponse, Request, Response};
|
||||
|
||||
class MainController extends Controller
|
||||
{
|
||||
const AJAX_AUTOCOMPLETE_SIZE = 10;
|
||||
|
||||
public function indexAction(Request $request): Response
|
||||
{
|
||||
public function indexAction(
|
||||
Request $request,
|
||||
UserRepository $userRepository,
|
||||
SubscriptionRepository $subscriptionRepository,
|
||||
SubscriptionEventRepository $subscriptionEventRepository
|
||||
): Response {
|
||||
/** @var EntityManager $em */
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
|
@ -32,7 +35,7 @@ class MainController extends Controller
|
|||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$login = $form->get('login')->getData();
|
||||
|
||||
if (null !== $user = $em->getRepository('SkobkinPointToolsBundle:User')->findOneBy(['login' => $login])) {
|
||||
if (null !== $user = $userRepository->findOneBy(['login' => $login])) {
|
||||
return $this->redirectToRoute('user_show', ['login' => $login]);
|
||||
}
|
||||
|
||||
|
@ -42,9 +45,9 @@ class MainController extends Controller
|
|||
return $this->render('SkobkinPointToolsBundle:Main:index.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'autocomplete_size' => self::AJAX_AUTOCOMPLETE_SIZE,
|
||||
'users_count' => $em->getRepository('SkobkinPointToolsBundle:User')->getUsersCount(),
|
||||
'subscribers_count' => $em->getRepository('SkobkinPointToolsBundle:Subscription')->getUserSubscribersCountById($this->getParameter('point_id')),
|
||||
'events_count' => $em->getRepository('SkobkinPointToolsBundle:SubscriptionEvent')->getLastDayEventsCount(),
|
||||
'users_count' => $userRepository->getUsersCount(),
|
||||
'subscribers_count' => $subscriptionRepository->getUserSubscribersCountById($this->getParameter('point_id')),
|
||||
'events_count' => $subscriptionEventRepository->getLastDayEventsCount(),
|
||||
'service_login' => $this->getParameter('point_login'),
|
||||
]);
|
||||
}
|
||||
|
@ -56,13 +59,13 @@ class MainController extends Controller
|
|||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function searchUserAjaxAction(string $login): Response
|
||||
public function searchUserAjaxAction(string $login, UserRepository $userRepository): Response
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$result = [];
|
||||
|
||||
foreach ($em->getRepository('SkobkinPointToolsBundle:User')->findUsersLikeLogin($login, self::AJAX_AUTOCOMPLETE_SIZE) as $user) {
|
||||
foreach ($userRepository->findUsersLikeLogin($login, self::AJAX_AUTOCOMPLETE_SIZE) as $user) {
|
||||
$result[] = [
|
||||
'login' => $user->getLogin(),
|
||||
'name' => $user->getName(),
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Skobkin\Bundle\PointToolsBundle\Controller;
|
||||
|
||||
use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Post;
|
||||
use Skobkin\Bundle\PointToolsBundle\Repository\Blogs\PostRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
@ -14,10 +15,10 @@ class PostController extends Controller
|
|||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function showAction(Post $post): Response
|
||||
public function showAction(Post $post, PostRepository $postRepository): Response
|
||||
{
|
||||
return $this->render('SkobkinPointToolsBundle:Post:show.html.twig', [
|
||||
'post' => $this->getDoctrine()->getRepository('SkobkinPointToolsBundle:Blogs\Post')->getPostWithComments($post->getId()),
|
||||
'post' => $postRepository->getPostWithComments($post->getId()),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
namespace Skobkin\Bundle\PointToolsBundle\Controller;
|
||||
|
||||
use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Post;
|
||||
use Knp\Component\Pager\Paginator;
|
||||
use Skobkin\Bundle\PointToolsBundle\Repository\Blogs\PostRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
|
@ -10,13 +11,8 @@ class PublicFeedController extends Controller
|
|||
{
|
||||
private const POSTS_PER_PAGE = 20;
|
||||
|
||||
public function indexAction(Request $request)
|
||||
public function indexAction(Request $request, PostRepository $postRepository, Paginator $paginator)
|
||||
{
|
||||
// @todo autowire
|
||||
$postRepository = $this->getDoctrine()->getRepository(Post::class);
|
||||
|
||||
$paginator = $this->get('knp_paginator');
|
||||
|
||||
$postsPagination = $paginator->paginate(
|
||||
$postRepository->createPublicFeedPostsQuery(),
|
||||
$request->query->getInt('page', 1),
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
namespace Skobkin\Bundle\PointToolsBundle\Controller\Telegram;
|
||||
|
||||
use Skobkin\Bundle\PointToolsBundle\Service\Telegram\IncomingUpdateDispatcher;
|
||||
use Symfony\Bridge\Monolog\Logger;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\{JsonResponse, Request, Response};
|
||||
use unreal4u\TelegramAPI\Telegram\Types\Update;
|
||||
|
||||
/**
|
||||
|
@ -13,14 +13,12 @@ use unreal4u\TelegramAPI\Telegram\Types\Update;
|
|||
*/
|
||||
class WebHookController extends Controller
|
||||
{
|
||||
public function receiveUpdateAction(Request $request, string $token): Response
|
||||
public function receiveUpdateAction(Request $request, string $token, IncomingUpdateDispatcher $updateDispatcher, Logger $logger): Response
|
||||
{
|
||||
if ($token !== $savedToken = $this->getParameter('telegram_token')) {
|
||||
throw $this->createNotFoundException();
|
||||
}
|
||||
|
||||
$logger = $this->get('logger');
|
||||
|
||||
$content = json_decode($request->getContent(), true);
|
||||
|
||||
$update = new Update(
|
||||
|
@ -29,7 +27,7 @@ class WebHookController extends Controller
|
|||
);
|
||||
|
||||
try {
|
||||
$this->get('app.telegram.update_dispatcher')->process($update);
|
||||
$updateDispatcher->process($update);
|
||||
} catch (\Exception $e) {
|
||||
if ($this->getParameter('kernel.debug')) {
|
||||
throw $e;
|
||||
|
|
|
@ -2,52 +2,61 @@
|
|||
|
||||
namespace Skobkin\Bundle\PointToolsBundle\Controller;
|
||||
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Knp\Component\Pager\Paginator;
|
||||
use Skobkin\Bundle\PointToolsBundle\DTO\{DailyEvents, TopUserDTO};
|
||||
use Skobkin\Bundle\PointToolsBundle\Entity\User;
|
||||
use Skobkin\Bundle\PointToolsBundle\Repository\{SubscriptionEventRepository, UserRenameEventRepository, UserRepository};
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Ob\HighchartsBundle\Highcharts\Highchart;
|
||||
use Symfony\Component\HttpFoundation\{Request, Response};
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
/** @var TranslatorInterface */
|
||||
private $translator;
|
||||
|
||||
public function __construct(TranslatorInterface $translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $login
|
||||
*/
|
||||
public function showAction(Request $request, string $login): Response
|
||||
{
|
||||
/** @var EntityManager $em */
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
public function showAction(
|
||||
Request $request,
|
||||
string $login,
|
||||
SubscriptionEventRepository $subscriptionEventRepository,
|
||||
UserRepository $userRepository,
|
||||
UserRenameEventRepository $renameEventRepository,
|
||||
Paginator $paginator
|
||||
): Response {
|
||||
/** @var User $user */
|
||||
$user = $em->getRepository('SkobkinPointToolsBundle:User')->findUserByLogin($login);
|
||||
$user = $userRepository->findUserByLogin($login);
|
||||
|
||||
if (!$user) {
|
||||
throw $this->createNotFoundException('User ' . $login . ' not found.');
|
||||
}
|
||||
|
||||
$paginator = $this->get('knp_paginator');
|
||||
|
||||
$subscriberEventsPagination = $paginator->paginate(
|
||||
$em->getRepository('SkobkinPointToolsBundle:SubscriptionEvent')->createUserLastSubscribersEventsQuery($user),
|
||||
$subscriptionEventRepository->createUserLastSubscribersEventsQuery($user),
|
||||
$request->query->getInt('page', 1),
|
||||
10
|
||||
);
|
||||
|
||||
return $this->render('SkobkinPointToolsBundle:User:show.html.twig', [
|
||||
'user' => $user,
|
||||
'subscribers' => $em->getRepository('SkobkinPointToolsBundle:User')->findUserSubscribersById($user->getId()),
|
||||
'subscribers' => $userRepository->findUserSubscribersById($user->getId()),
|
||||
'subscriptions_log' => $subscriberEventsPagination,
|
||||
'rename_log' => $em->getRepository('SkobkinPointToolsBundle:UserRenameEvent')->findBy(['user' => $user], ['date' => 'DESC'], 10),
|
||||
'rename_log' => $renameEventRepository->findBy(['user' => $user], ['date' => 'DESC'], 10),
|
||||
]);
|
||||
}
|
||||
|
||||
public function topAction(): Response
|
||||
public function topAction(UserRepository $userRepository, SubscriptionEventRepository $subscriptionEventRepository): Response
|
||||
{
|
||||
$userRepo = $this->getDoctrine()->getManager()->getRepository('SkobkinPointToolsBundle:User');
|
||||
$subscriptionsRecordsRepo = $this->getDoctrine()->getManager()->getRepository('SkobkinPointToolsBundle:SubscriptionEvent');
|
||||
$topUsers = $userRepo->getTopUsers();
|
||||
$eventsByDay = $subscriptionsRecordsRepo->getLastEventsByDay();
|
||||
$topUsers = $userRepository->getTopUsers();
|
||||
$eventsByDay = $subscriptionEventRepository->getLastEventsByDay();
|
||||
|
||||
return $this->render('@SkobkinPointTools/User/top.html.twig', [
|
||||
'events_dynamic_chat' => $this->createEventsDynamicChart($eventsByDay),
|
||||
|
@ -89,8 +98,6 @@ class UserController extends Controller
|
|||
|
||||
private function createChart(string $blockId, string $type, array $data, string $bottomLabel, string $amountLabel): Highchart
|
||||
{
|
||||
$translator = $this->get('translator');
|
||||
|
||||
$chartData = [
|
||||
'keys' => [],
|
||||
'values' => [],
|
||||
|
@ -104,7 +111,7 @@ class UserController extends Controller
|
|||
|
||||
// Chart
|
||||
$series = [[
|
||||
'name' => $translator->trans($amountLabel),
|
||||
'name' => $this->translator->trans($amountLabel),
|
||||
'data' => $chartData['values'],
|
||||
]];
|
||||
|
||||
|
@ -112,10 +119,10 @@ class UserController extends Controller
|
|||
$ob = new Highchart();
|
||||
$ob->chart->renderTo($blockId);
|
||||
$ob->chart->type($type);
|
||||
$ob->title->text($translator->trans($bottomLabel));
|
||||
$ob->title->text($this->translator->trans($bottomLabel));
|
||||
$ob->xAxis->title(['text' => null]);
|
||||
$ob->xAxis->categories($chartData['keys']);
|
||||
$ob->yAxis->title(['text' => $translator->trans($amountLabel)]);
|
||||
$ob->yAxis->title(['text' => $this->translator->trans($amountLabel)]);
|
||||
$ob->plotOptions->bar([
|
||||
'dataLabels' => [
|
||||
'enabled' => true
|
||||
|
|
|
@ -142,11 +142,12 @@ class Account
|
|||
return $this->firstName;
|
||||
}
|
||||
|
||||
public function setFirstName(string $firstName): Account
|
||||
public function updateFromMessageData(string $firstName, ?string $lastName, ?string $username, int $chatId): void
|
||||
{
|
||||
$this->firstName = $firstName;
|
||||
|
||||
return $this;
|
||||
$this->lastName = $lastName;
|
||||
$this->username = $username;
|
||||
$this->chatId = $chatId;
|
||||
}
|
||||
|
||||
public function getLastName(): ?string
|
||||
|
@ -154,32 +155,11 @@ class Account
|
|||
return $this->lastName;
|
||||
}
|
||||
|
||||
public function setLastName(?string $lastName = null): Account
|
||||
{
|
||||
$this->lastName = $lastName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUsername(): string
|
||||
{
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
public function setUsername(string $username = null): Account
|
||||
{
|
||||
$this->username = $username;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setChatId(int $chatId): self
|
||||
{
|
||||
$this->chatId = $chatId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getChatId(): int
|
||||
{
|
||||
return $this->chatId;
|
||||
|
|
|
@ -157,7 +157,7 @@ class User
|
|||
/**
|
||||
* @return Subscription[]|ArrayCollection
|
||||
*/
|
||||
public function getSubscribers(): ArrayCollection
|
||||
public function getSubscribers(): iterable
|
||||
{
|
||||
return $this->subscribers;
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ class User
|
|||
/**
|
||||
* @return Subscription[]|ArrayCollection
|
||||
*/
|
||||
public function getSubscriptions(): ArrayCollection
|
||||
public function getSubscriptions(): iterable
|
||||
{
|
||||
return $this->subscriptions;
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ class User
|
|||
/**
|
||||
* @return SubscriptionEvent[]|ArrayCollection
|
||||
*/
|
||||
public function getNewSubscriberEvents(): ArrayCollection
|
||||
public function getNewSubscriberEvents(): iterable
|
||||
{
|
||||
return $this->newSubscriberEvents;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
* @ORM\Index(name="idx_rename_log_date", columns={"date"}),
|
||||
* @ORM\Index(name="idx_rename_log_old_login", columns={"old_login"})
|
||||
* })
|
||||
* @ORM\Entity(readOnly=true)
|
||||
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\UserRenameEventRepository", readOnly=true)
|
||||
*/
|
||||
class UserRenameEvent
|
||||
{
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Skobkin\Bundle\PointToolsBundle\Repository;
|
||||
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Skobkin\Bundle\PointToolsBundle\Entity\UserRenameEvent;
|
||||
|
||||
class UserRenameEventRepository extends EntityRepository
|
||||
{
|
||||
public function add(UserRenameEvent $event)
|
||||
{
|
||||
$this->getEntityManager()->persist($event);
|
||||
}
|
||||
}
|
|
@ -1,276 +1 @@
|
|||
services:
|
||||
# HTTP client for Telegram
|
||||
app.http.telegram_client:
|
||||
class: GuzzleHttp\Client
|
||||
arguments: [{ timeout: 3.0 }]
|
||||
tags:
|
||||
- { name: csa_guzzle.client }
|
||||
|
||||
# HTTP client for Point API
|
||||
app.http.point_client:
|
||||
class: GuzzleHttp\Client
|
||||
autowiring_types: GuzzleHttp\ClientInterface
|
||||
arguments: [ { base_uri: '%point_base_url%', timeout: 5.0 } ]
|
||||
tags:
|
||||
- { name: csa_guzzle.client }
|
||||
|
||||
|
||||
# Point API clients
|
||||
# Abstract API client with common dependency
|
||||
app.point.abstract_api:
|
||||
abstract: true
|
||||
autowire: true
|
||||
# User
|
||||
app.point.api_user:
|
||||
class: Skobkin\Bundle\PointToolsBundle\Service\Api\UserApi
|
||||
parent: app.point.abstract_api
|
||||
autowire: true
|
||||
tags:
|
||||
- { name: monolog.logger, channel: point_user_api }
|
||||
# Post
|
||||
app.point.api_post:
|
||||
class: Skobkin\Bundle\PointToolsBundle\Service\Api\PostApi
|
||||
parent: app.point.abstract_api
|
||||
autowire: true
|
||||
tags:
|
||||
- { name: monolog.logger, channel: point_post_api }
|
||||
|
||||
|
||||
# Point subscription manager
|
||||
app.point.subscriptions_manager:
|
||||
class: Skobkin\Bundle\PointToolsBundle\Service\SubscriptionsManager
|
||||
# TODO deal with autowire for EventDispatcherInterface
|
||||
arguments:
|
||||
- '@event_dispatcher'
|
||||
- '@logger'
|
||||
- '@app.point.subscription_repository'
|
||||
- '@app.point.subscription_record_repository'
|
||||
tags:
|
||||
- { name: monolog.logger, channel: subscribers_update }
|
||||
|
||||
|
||||
# Console commands
|
||||
# @todo https://github.com/symfony/symfony/blob/3.4/UPGRADE-3.4.md#httpkernel
|
||||
# Subsribers update
|
||||
app.point.update_subscribers_command:
|
||||
class: Skobkin\Bundle\PointToolsBundle\Command\UpdateSubscriptionsCommand
|
||||
arguments:
|
||||
- '@doctrine.orm.entity_manager'
|
||||
- '@logger'
|
||||
- '@app.point.user_repository'
|
||||
- '@app.point.api_user'
|
||||
- '@app.point.subscriptions_manager'
|
||||
- '%point_api_delay%'
|
||||
- '%point_id%'
|
||||
tags:
|
||||
- { name: console.command }
|
||||
- { name: monolog.logger, channel: subscribers_update }
|
||||
# Privacy update
|
||||
app.point.update_privacy_command:
|
||||
class: Skobkin\Bundle\PointToolsBundle\Command\UpdateUsersPrivacyCommand
|
||||
#autowire: []
|
||||
arguments:
|
||||
- '@doctrine.orm.entity_manager'
|
||||
- '@logger'
|
||||
- '@app.point.user_repository'
|
||||
- '@app.point.api_user'
|
||||
- '%point_api_delay%'
|
||||
- '%point_id%'
|
||||
tags:
|
||||
- { name: console.command }
|
||||
- { name: monolog.logger, channel: privacy_update }
|
||||
# Restore users removed by error
|
||||
app.point.restore_users:
|
||||
class: Skobkin\Bundle\PointToolsBundle\Command\RestoreRemovedUsersCommand
|
||||
arguments:
|
||||
- '@logger'
|
||||
- '@doctrine.orm.entity_manager'
|
||||
- '@app.point.user_repository'
|
||||
- '@app.point.api_user'
|
||||
- '%point_api_delay%'
|
||||
tags:
|
||||
- { name: console.command }
|
||||
# Webhook management
|
||||
app.telegram.webhook_command:
|
||||
class: Skobkin\Bundle\PointToolsBundle\Command\TelegramWebHookCommand
|
||||
#autowire: []
|
||||
calls:
|
||||
- [setClient, ['@app.telegram.bot_client']]
|
||||
- [setRouter, ['@router']]
|
||||
- [setToken, ['%telegram_token%']]
|
||||
tags: [{ name: console.command }]
|
||||
# Send message
|
||||
app.telegram.send_message:
|
||||
class: Skobkin\Bundle\PointToolsBundle\Command\TelegramSendMessageCommand
|
||||
#autowire: []
|
||||
calls:
|
||||
- [setMessenger, ['@app.telegram.message_sender']]
|
||||
- [setLogChatId, ['%telegram_log_chat_id%']]
|
||||
tags: [{ name: console.command }]
|
||||
|
||||
|
||||
# Entity repositories as services
|
||||
# User
|
||||
app.point.user_repository:
|
||||
class: Skobkin\Bundle\PointToolsBundle\Repository\UserRepository
|
||||
factory: 'doctrine:getRepository'
|
||||
arguments: ['Skobkin\Bundle\PointToolsBundle\Entity\User']
|
||||
# Subscription
|
||||
app.point.subscription_repository:
|
||||
class: Skobkin\Bundle\PointToolsBundle\Repository\SubscriptionRepository
|
||||
factory: 'doctrine:getRepository'
|
||||
arguments: ['Skobkin\Bundle\PointToolsBundle\Entity\Subscription']
|
||||
# Subscription record/event
|
||||
app.point.subscription_record_repository:
|
||||
class: Skobkin\Bundle\PointToolsBundle\Repository\SubscriptionEventRepository
|
||||
factory: 'doctrine:getRepository'
|
||||
arguments: ['Skobkin\Bundle\PointToolsBundle\Entity\SubscriptionEvent']
|
||||
# Post repository
|
||||
app.point.post_repository:
|
||||
class: Skobkin\Bundle\PointToolsBundle\Repository\Blogs\PostRepository
|
||||
factory: 'doctrine:getRepository'
|
||||
arguments: ['Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Post']
|
||||
# Comment repository
|
||||
app.point.comment_repository:
|
||||
class: Skobkin\Bundle\PointToolsBundle\Repository\Blogs\CommentRepository
|
||||
factory: 'doctrine:getRepository'
|
||||
arguments: ['Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment']
|
||||
# Tag repository
|
||||
app.point.tag_repository:
|
||||
class: Skobkin\Bundle\PointToolsBundle\Repository\Blogs\TagRepository
|
||||
factory: 'doctrine:getRepository'
|
||||
arguments: ['Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Tag']
|
||||
# File repository
|
||||
app.point.file_repository:
|
||||
class: Skobkin\Bundle\PointToolsBundle\Repository\Blogs\FileRepository
|
||||
factory: 'doctrine:getRepository'
|
||||
arguments: ['Skobkin\Bundle\PointToolsBundle\Entity\Blogs\File']
|
||||
# Telegram Account repository
|
||||
app.point.telegram_account_repository:
|
||||
class: Skobkin\Bundle\PointToolsBundle\Repository\Telegram\AccountRepository
|
||||
factory: 'doctrine:getRepository'
|
||||
arguments: ['Skobkin\Bundle\PointToolsBundle\Entity\Telegram\Account']
|
||||
|
||||
|
||||
# Factories
|
||||
# Abstract factory
|
||||
app.point.abstract_factory:
|
||||
abstract: true
|
||||
autowire: true
|
||||
# User
|
||||
app.point.user_factory:
|
||||
class: Skobkin\Bundle\PointToolsBundle\Service\Factory\UserFactory
|
||||
parent: app.point.abstract_factory
|
||||
autowire: true
|
||||
# Comment
|
||||
app.point.comment_factory:
|
||||
class: Skobkin\Bundle\PointToolsBundle\Service\Factory\Blogs\CommentFactory
|
||||
parent: app.point.abstract_factory
|
||||
autowire: true
|
||||
# Tag
|
||||
app.point.tag_factory:
|
||||
class: Skobkin\Bundle\PointToolsBundle\Service\Factory\Blogs\TagFactory
|
||||
parent: app.point.abstract_factory
|
||||
autowire: true
|
||||
# File
|
||||
app.point.file_factory:
|
||||
class: Skobkin\Bundle\PointToolsBundle\Service\Factory\Blogs\FileFactory
|
||||
parent: app.point.abstract_factory
|
||||
autowire: true
|
||||
# Post
|
||||
app.point.post_factory:
|
||||
class: Skobkin\Bundle\PointToolsBundle\Service\Factory\Blogs\PostFactory
|
||||
parent: app.point.abstract_factory
|
||||
autowire: true
|
||||
# Telegram account
|
||||
app.telegram.telegram_account_factory:
|
||||
class: Skobkin\Bundle\PointToolsBundle\Service\Factory\Telegram\AccountFactory
|
||||
parent: app.point.abstract_factory
|
||||
autowire: true
|
||||
|
||||
|
||||
# Custom Markdown parser
|
||||
app.point.markdown_parser:
|
||||
class: Skobkin\Bundle\PointToolsBundle\Service\Markdown\PointParser
|
||||
arguments: [[], '@router']
|
||||
tags:
|
||||
- { name: markdown.parser }
|
||||
|
||||
|
||||
# Event listeners
|
||||
# User name changed in Doctrine
|
||||
app.event_listener.users_updated:
|
||||
class: Skobkin\Bundle\PointToolsBundle\EventListener\UsersUpdatedSubscriber
|
||||
arguments: ['@event_dispatcher']
|
||||
tags:
|
||||
- { name: doctrine.event_subscriber, connection: default }
|
||||
# User renaming
|
||||
app.event_listener.users_renamed_notifier:
|
||||
class: Skobkin\Bundle\PointToolsBundle\EventListener\UsersRenamedListener
|
||||
autowire: true
|
||||
tags:
|
||||
- { name: kernel.event_listener, event: app.users.renamed }
|
||||
# User subscribers updated
|
||||
app.event_listener.user_subscribers_updated:
|
||||
class: Skobkin\Bundle\PointToolsBundle\EventListener\UserSubscribersUpdatedListener
|
||||
autowire: true
|
||||
tags:
|
||||
- { name: kernel.event_listener, event: app.user.subscribers_updated }
|
||||
|
||||
|
||||
# Twig extensions
|
||||
app.twig.point_users_extension:
|
||||
class: Skobkin\Bundle\PointToolsBundle\Twig\PointUrlExtension
|
||||
public: false
|
||||
arguments:
|
||||
- '%point_domain%'
|
||||
- '%point_scheme%'
|
||||
- '%point_base_url%'
|
||||
tags:
|
||||
- { name: twig.extension }
|
||||
|
||||
|
||||
# Telegram services
|
||||
# Bot API client
|
||||
app.telegram.bot_client:
|
||||
class: unreal4u\TelegramAPI\TgLog
|
||||
autowiring_types: unreal4u\TelegramAPI\TgLog
|
||||
arguments: ['%telegram_token%', '@logger', '@app.http.telegram_client']
|
||||
# Logger API client
|
||||
app.telegram.logger_client:
|
||||
class: unreal4u\TelegramAPI\TgLog
|
||||
arguments: ['%telegram_token%', null, '@app.http.telegram_client']
|
||||
|
||||
# Monolog handler
|
||||
app.log.telegram_handler:
|
||||
class: unreal4u\MonologHandler
|
||||
arguments:
|
||||
- '@app.telegram.logger_client'
|
||||
- '%telegram_log_chat_id%'
|
||||
- 'error'
|
||||
|
||||
# User notifier
|
||||
app.telegram.notifier:
|
||||
class: Skobkin\Bundle\PointToolsBundle\Service\Telegram\Notifier
|
||||
autowire: true
|
||||
|
||||
# Message sender
|
||||
app.telegram.message_sender:
|
||||
class: Skobkin\Bundle\PointToolsBundle\Service\Telegram\MessageSender
|
||||
autowire: true
|
||||
# Common incoming message processor
|
||||
app.telegram.update_dispatcher:
|
||||
class: Skobkin\Bundle\PointToolsBundle\Service\Telegram\IncomingUpdateDispatcher
|
||||
autowire: true
|
||||
# InlineQuery processor
|
||||
app.telegram.inline_query_processor:
|
||||
class: Skobkin\Bundle\PointToolsBundle\Service\Telegram\InlineQueryProcessor
|
||||
lazy: true
|
||||
autowire: true
|
||||
# Private message processor
|
||||
app.telegram.private_message_processor:
|
||||
class: Skobkin\Bundle\PointToolsBundle\Service\Telegram\PrivateMessageProcessor
|
||||
lazy: true
|
||||
autowire: true
|
||||
calls:
|
||||
- [setPointUserId, ['%point_id%']]
|
||||
|
|
|
@ -3,26 +3,18 @@
|
|||
namespace Skobkin\Bundle\PointToolsBundle\Service\Factory\Blogs;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Skobkin\Bundle\PointToolsBundle\Repository\Blogs\CommentRepository;
|
||||
use Skobkin\Bundle\PointToolsBundle\Repository\Blogs\PostRepository;
|
||||
use Skobkin\Bundle\PointToolsBundle\Service\Factory\AbstractFactory;
|
||||
use Skobkin\Bundle\PointToolsBundle\Service\Factory\UserFactory;
|
||||
use Skobkin\Bundle\PointToolsBundle\Repository\Blogs\{CommentRepository, PostRepository};
|
||||
use Skobkin\Bundle\PointToolsBundle\Service\Factory\{AbstractFactory, UserFactory};
|
||||
|
||||
class CommentFactory extends AbstractFactory
|
||||
{
|
||||
/**
|
||||
* @var CommentRepository
|
||||
*/
|
||||
/** @var CommentRepository */
|
||||
private $commentRepository;
|
||||
|
||||
/**
|
||||
* @var PostRepository
|
||||
*/
|
||||
/** @var PostRepository */
|
||||
private $postRepository;
|
||||
|
||||
/**
|
||||
* @var UserFactory
|
||||
*/
|
||||
/** @var UserFactory */
|
||||
private $userFactory;
|
||||
|
||||
|
||||
|
|
|
@ -10,9 +10,7 @@ use Skobkin\Bundle\PointToolsBundle\Service\Factory\AbstractFactory;
|
|||
|
||||
class FileFactory extends AbstractFactory
|
||||
{
|
||||
/**
|
||||
* @var FileRepository
|
||||
*/
|
||||
/** @var FileRepository */
|
||||
private $fileRepository;
|
||||
|
||||
|
||||
|
|
|
@ -4,48 +4,30 @@ namespace Skobkin\Bundle\PointToolsBundle\Service\Factory\Blogs;
|
|||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Skobkin\Bundle\PointToolsBundle\DTO\Api\MetaPost;
|
||||
use Skobkin\Bundle\PointToolsBundle\DTO\Api\Post as PostDTO;
|
||||
use Skobkin\Bundle\PointToolsBundle\DTO\Api\PostsPage;
|
||||
use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Post;
|
||||
use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\PostTag;
|
||||
use Skobkin\Bundle\PointToolsBundle\Entity\User;
|
||||
use Skobkin\Bundle\PointToolsBundle\Exception\Factory\Blog\InvalidDataException;
|
||||
use Skobkin\Bundle\PointToolsBundle\DTO\Api\{MetaPost, Post as PostDTO, PostsPage};
|
||||
use Skobkin\Bundle\PointToolsBundle\Entity\{Blogs\Post, Blogs\PostTag, User};
|
||||
use Skobkin\Bundle\PointToolsBundle\Exception\{Api\InvalidResponseException, Factory\Blog\InvalidDataException};
|
||||
use Skobkin\Bundle\PointToolsBundle\Repository\Blogs\PostRepository;
|
||||
use Skobkin\Bundle\PointToolsBundle\Exception\Api\InvalidResponseException;
|
||||
use Skobkin\Bundle\PointToolsBundle\Service\Factory\AbstractFactory;
|
||||
use Skobkin\Bundle\PointToolsBundle\Service\Factory\UserFactory;
|
||||
use Skobkin\Bundle\PointToolsBundle\Service\Factory\{AbstractFactory, UserFactory};
|
||||
|
||||
class PostFactory extends AbstractFactory
|
||||
{
|
||||
/**
|
||||
* @var EntityManagerInterface
|
||||
*/
|
||||
/** @var EntityManagerInterface */
|
||||
private $em;
|
||||
|
||||
/**
|
||||
* @var PostRepository
|
||||
*/
|
||||
/** @var PostRepository */
|
||||
private $postRepository;
|
||||
|
||||
/**
|
||||
* @var UserFactory
|
||||
*/
|
||||
/** @var UserFactory */
|
||||
private $userFactory;
|
||||
|
||||
/**
|
||||
* @var FileFactory
|
||||
*/
|
||||
/** @var FileFactory */
|
||||
private $fileFactory;
|
||||
|
||||
/**
|
||||
* @var CommentFactory
|
||||
*/
|
||||
/** @var CommentFactory */
|
||||
private $commentFactory;
|
||||
|
||||
/**
|
||||
* @var TagFactory
|
||||
*/
|
||||
/** @var TagFactory */
|
||||
private $tagFactory;
|
||||
|
||||
|
||||
|
|
|
@ -9,9 +9,7 @@ use Skobkin\Bundle\PointToolsBundle\Service\Factory\AbstractFactory;
|
|||
|
||||
class TagFactory extends AbstractFactory
|
||||
{
|
||||
/**
|
||||
* @var TagRepository
|
||||
*/
|
||||
/** @var TagRepository */
|
||||
private $tagRepository;
|
||||
|
||||
|
||||
|
|
|
@ -10,9 +10,7 @@ use unreal4u\TelegramAPI\Telegram\Types\Message;
|
|||
|
||||
class AccountFactory extends AbstractFactory
|
||||
{
|
||||
/**
|
||||
* @var AccountRepository
|
||||
*/
|
||||
/** @var AccountRepository */
|
||||
private $accountRepo;
|
||||
|
||||
|
||||
|
@ -30,12 +28,12 @@ class AccountFactory extends AbstractFactory
|
|||
}
|
||||
|
||||
// Setting/updating account data
|
||||
$account
|
||||
->setFirstName($message->from->first_name)
|
||||
->setLastName($message->from->last_name)
|
||||
->setUsername($message->from->username)
|
||||
->setChatId($message->chat->id)
|
||||
;
|
||||
$account->updateFromMessageData(
|
||||
$message->from->first_name,
|
||||
$message->from->last_name,
|
||||
$message->from->username,
|
||||
$message->chat->id
|
||||
);
|
||||
|
||||
return $account;
|
||||
}
|
||||
|
|
|
@ -3,34 +3,23 @@
|
|||
namespace Skobkin\Bundle\PointToolsBundle\Service;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Skobkin\Bundle\PointToolsBundle\Entity\Subscription;
|
||||
use Skobkin\Bundle\PointToolsBundle\Entity\SubscriptionEvent;
|
||||
use Skobkin\Bundle\PointToolsBundle\Entity\User;
|
||||
use Skobkin\Bundle\PointToolsBundle\Entity\{Subscription, SubscriptionEvent, User};
|
||||
use Skobkin\Bundle\PointToolsBundle\Event\UserSubscribersUpdatedEvent;
|
||||
use Skobkin\Bundle\PointToolsBundle\Repository\SubscriptionEventRepository;
|
||||
use Skobkin\Bundle\PointToolsBundle\Repository\SubscriptionRepository;
|
||||
use Skobkin\Bundle\PointToolsBundle\Repository\{SubscriptionEventRepository, SubscriptionRepository};
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
class SubscriptionsManager
|
||||
{
|
||||
/**
|
||||
* @var SubscriptionRepository
|
||||
*/
|
||||
/** @var SubscriptionRepository */
|
||||
private $subscriptionRepo;
|
||||
|
||||
/**
|
||||
* @var SubscriptionEventRepository
|
||||
*/
|
||||
/** @var SubscriptionEventRepository */
|
||||
private $subscriptionRecordRepo;
|
||||
|
||||
/**
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
/** @var EventDispatcherInterface */
|
||||
private $eventDispatcher;
|
||||
|
||||
/**
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
|
||||
|
||||
|
|
|
@ -12,14 +12,10 @@ class IncomingUpdateDispatcher
|
|||
const CHAT_TYPE_PRIVATE = 'private';
|
||||
const CHAT_TYPE_GROUP = 'group';
|
||||
|
||||
/**
|
||||
* @var InlineQueryProcessor
|
||||
*/
|
||||
/** @var InlineQueryProcessor */
|
||||
private $inlineQueryProcessor;
|
||||
|
||||
/**
|
||||
* @var PrivateMessageProcessor
|
||||
*/
|
||||
/** @var PrivateMessageProcessor */
|
||||
private $privateMessageProcessor;
|
||||
|
||||
|
||||
|
|
|
@ -10,14 +10,10 @@ use unreal4u\TelegramAPI\TgLog;
|
|||
|
||||
class InlineQueryProcessor
|
||||
{
|
||||
/**
|
||||
* @var UserRepository
|
||||
*/
|
||||
/** @var UserRepository */
|
||||
private $userRepo;
|
||||
|
||||
/**
|
||||
* @var TgLog
|
||||
*/
|
||||
/** @var TgLog */
|
||||
private $client;
|
||||
|
||||
|
||||
|
|
|
@ -17,14 +17,10 @@ class MessageSender
|
|||
public const PARSE_MARKDOWN = 'Markdown';
|
||||
public const PARSE_HTML5 = 'HTML';
|
||||
|
||||
/**
|
||||
* @var TgLog
|
||||
*/
|
||||
/** @var TgLog */
|
||||
private $client;
|
||||
|
||||
/**
|
||||
* @var \Twig_Environment
|
||||
*/
|
||||
/** @var \Twig_Environment */
|
||||
private $twig;
|
||||
|
||||
/**
|
||||
|
|
|
@ -10,14 +10,10 @@ use Skobkin\Bundle\PointToolsBundle\Repository\Telegram\AccountRepository;
|
|||
*/
|
||||
class Notifier
|
||||
{
|
||||
/**
|
||||
* @var AccountRepository
|
||||
*/
|
||||
/** @var AccountRepository */
|
||||
private $accountsRepo;
|
||||
|
||||
/**
|
||||
* @var MessageSender
|
||||
*/
|
||||
/** @var MessageSender */
|
||||
private $messenger;
|
||||
|
||||
|
||||
|
|
|
@ -3,67 +3,41 @@
|
|||
namespace Skobkin\Bundle\PointToolsBundle\Service\Telegram;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Skobkin\Bundle\PointToolsBundle\Entity\Telegram\Account;
|
||||
use Skobkin\Bundle\PointToolsBundle\Entity\User;
|
||||
use Skobkin\Bundle\PointToolsBundle\Entity\{Telegram\Account, User};
|
||||
use Skobkin\Bundle\PointToolsBundle\Exception\Telegram\CommandProcessingException;
|
||||
use Skobkin\Bundle\PointToolsBundle\Repository\SubscriptionEventRepository;
|
||||
use Skobkin\Bundle\PointToolsBundle\Repository\SubscriptionRepository;
|
||||
use Skobkin\Bundle\PointToolsBundle\Repository\Telegram\AccountRepository;
|
||||
use Skobkin\Bundle\PointToolsBundle\Repository\UserRepository;
|
||||
use Skobkin\Bundle\PointToolsBundle\Repository\{SubscriptionEventRepository, SubscriptionRepository, Telegram\AccountRepository, UserRepository};
|
||||
use Skobkin\Bundle\PointToolsBundle\Service\Factory\Telegram\AccountFactory;
|
||||
use Skobkin\Bundle\PointToolsBundle\Service\Api\UserApi;
|
||||
use unreal4u\TelegramAPI\Telegram\Types\Message;
|
||||
use unreal4u\TelegramAPI\Telegram\Types\ReplyKeyboardMarkup;
|
||||
use unreal4u\TelegramAPI\Telegram\Types\ReplyKeyboardRemove;
|
||||
use unreal4u\TelegramAPI\Telegram\Types\{Message, ReplyKeyboardMarkup, ReplyKeyboardRemove};
|
||||
|
||||
/**
|
||||
* Processes all private messages
|
||||
*/
|
||||
/** Processes all private messages */
|
||||
class PrivateMessageProcessor
|
||||
{
|
||||
/**
|
||||
* @var MessageSender
|
||||
*/
|
||||
/** @var MessageSender */
|
||||
private $messenger;
|
||||
|
||||
/**
|
||||
* @var UserApi
|
||||
*/
|
||||
/** @var UserApi */
|
||||
private $userApi;
|
||||
|
||||
/**
|
||||
* @var AccountFactory
|
||||
*/
|
||||
/** @var AccountFactory */
|
||||
private $accountFactory;
|
||||
|
||||
/**
|
||||
* @var EntityManagerInterface
|
||||
*/
|
||||
/** @var EntityManagerInterface */
|
||||
private $em;
|
||||
|
||||
/**
|
||||
* @var UserRepository
|
||||
*/
|
||||
/** @var UserRepository */
|
||||
private $userRepo;
|
||||
|
||||
/**
|
||||
* @var AccountRepository
|
||||
*/
|
||||
/** @var AccountRepository */
|
||||
private $accountRepo;
|
||||
|
||||
/**
|
||||
* @var SubscriptionRepository
|
||||
*/
|
||||
/** @var SubscriptionRepository */
|
||||
private $subscriptionRepo;
|
||||
|
||||
/**
|
||||
* @var SubscriptionEventRepository
|
||||
*/
|
||||
/** @var SubscriptionEventRepository */
|
||||
private $subscriptionEventRepo;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
/** @var int */
|
||||
private $pointUserId;
|
||||
|
||||
|
||||
|
@ -75,7 +49,8 @@ class PrivateMessageProcessor
|
|||
SubscriptionEventRepository $subscriptionRecordRepository,
|
||||
MessageSender $messageSender,
|
||||
UserApi $userApi,
|
||||
AccountFactory $accountFactory
|
||||
AccountFactory $accountFactory,
|
||||
int $appUserId
|
||||
) {
|
||||
$this->em = $em;
|
||||
$this->userRepo = $userRepository;
|
||||
|
@ -85,11 +60,7 @@ class PrivateMessageProcessor
|
|||
$this->messenger = $messageSender;
|
||||
$this->userApi = $userApi;
|
||||
$this->accountFactory = $accountFactory;
|
||||
}
|
||||
|
||||
public function setPointUserId(int $pointUserId)
|
||||
{
|
||||
$this->pointUserId = $pointUserId;
|
||||
$this->pointUserId = $appUserId;
|
||||
}
|
||||
|
||||
public function process(Message $message): void
|
||||
|
|
Loading…
Reference in a new issue