Compare commits
No commits in common. "64855c50766913491a2bd917f56c376836663b4d" and "3fd76ff0ab04c0289e711e2d7136e1747b4a1bd6" have entirely different histories.
64855c5076
...
3fd76ff0ab
|
@ -1,17 +1,12 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Command;
|
||||
namespace src\PointToolsBundle\Command;
|
||||
|
||||
use App\Entity\User;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Doctrine\ORM\{EntityManager, EntityManagerInterface};
|
||||
use src\PointToolsBundle\Entity\User;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\{InputInterface, InputArgument, InputOption};
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
/**
|
||||
|
@ -23,17 +18,23 @@ use Symfony\Component\Filesystem\Filesystem;
|
|||
* WHERE u.id <> (-1)
|
||||
* ) TO '/tmp/point_users.csv' WITH HEADER DELIMITER '|' CSV;
|
||||
*/
|
||||
#[AsCommand(name: 'app:import:users', description: 'Import users from CSV file')]
|
||||
class ImportUsersCommand extends Command
|
||||
{
|
||||
public function __construct(private readonly EntityManagerInterface $em)
|
||||
/** @var EntityManager */
|
||||
private $em;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure(): void
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('point:import:users')
|
||||
->setDescription('Import users from CSV file')
|
||||
->addArgument(
|
||||
'file',
|
||||
InputArgument::REQUIRED,
|
||||
|
@ -54,23 +55,20 @@ class ImportUsersCommand extends Command
|
|||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$fs = new Filesystem();
|
||||
|
||||
$fileName = $input->getArgument('file');
|
||||
|
||||
if (!($fs->exists($fileName) && \is_readable($fileName))) {
|
||||
$io->error('File does not exists or not readable.');
|
||||
|
||||
return Command::FAILURE;
|
||||
if (!($fs->exists($fileName) && is_readable($fileName))) {
|
||||
$output->writeln('File does not exists or not readable.');
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (false === ($file = fopen($fileName, 'rb'))) {
|
||||
$io->error('fopen() error');
|
||||
|
||||
return Command::FAILURE;
|
||||
if (false === ($file = fopen($fileName, 'r'))) {
|
||||
$output->writeln('fopen() error');
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!$input->getOption('no-skip-first')) {
|
||||
|
@ -81,7 +79,7 @@ class ImportUsersCommand extends Command
|
|||
$count = 0;
|
||||
|
||||
while (false !== ($row = fgetcsv($file, 1000, '|'))) {
|
||||
if (\count($row) !== 4) {
|
||||
if (count($row) !== 4) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -95,15 +93,15 @@ class ImportUsersCommand extends Command
|
|||
$this->em->detach($user);
|
||||
}
|
||||
|
||||
if (OutputInterface::VERBOSITY_VERBOSE === $io->getVerbosity()) {
|
||||
$io->info('@' . $row[1] . ' added');
|
||||
if (OutputInterface::VERBOSITY_VERBOSE === $output->getVerbosity()) {
|
||||
$output->writeln('@' . $row[1] . ' added');
|
||||
}
|
||||
|
||||
$count++;
|
||||
}
|
||||
|
||||
$io->success($count . ' users imported.');
|
||||
$output->writeln($count . ' users imported.');
|
||||
|
||||
return Command::SUCCESS;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,40 +1,67 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Command;
|
||||
namespace src\PointToolsBundle\Command;
|
||||
|
||||
use App\Exception\Api\UserNotFoundException;
|
||||
use App\Repository\UserRepository;
|
||||
use App\Service\Api\UserApi;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use src\PointToolsBundle\Entity\User;
|
||||
use src\PointToolsBundle\Exception\Api\UserNotFoundException;
|
||||
use src\PointToolsBundle\Repository\UserRepository;
|
||||
use src\PointToolsBundle\Service\Api\UserApi;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
#[AsCommand(name: 'app:users:restore', description: 'Check removed users status and restore if user was deleted by error.')]
|
||||
class RestoreRemovedUsersCommand extends Command
|
||||
{
|
||||
public function __construct(
|
||||
private readonly LoggerInterface $logger,
|
||||
private readonly EntityManagerInterface $em,
|
||||
private readonly UserRepository $userRepo,
|
||||
private readonly UserApi $userApi,
|
||||
private readonly int $apiDelay,
|
||||
) {
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
|
||||
/** @var EntityManagerInterface */
|
||||
private $em;
|
||||
|
||||
/** @var UserRepository */
|
||||
private $userRepo;
|
||||
|
||||
/** @var UserApi */
|
||||
private $userApi;
|
||||
|
||||
/** @var int */
|
||||
private $delay;
|
||||
|
||||
public function __construct(LoggerInterface $logger, EntityManagerInterface $em, UserRepository $userRepo, UserApi $userApi, int $apiDelay)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->logger = $logger;
|
||||
$this->em = $em;
|
||||
$this->userRepo = $userRepo;
|
||||
$this->userApi = $userApi;
|
||||
$this->delay = $apiDelay;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$this
|
||||
->setName('point:users:restore')
|
||||
->setDescription('Check removed users status and restore if user was deleted by error.')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
/** @var User $removedUser */
|
||||
foreach ($this->userRepo->findBy(['removed' => true]) as $removedUser) {
|
||||
\usleep($this->apiDelay);
|
||||
usleep($this->delay);
|
||||
|
||||
try {
|
||||
/** @var User $remoteUser */
|
||||
$remoteUser = $this->userApi->getUserById($removedUser->getId());
|
||||
|
||||
if ($remoteUser->getId() === $removedUser->getId()) {
|
||||
|
@ -43,6 +70,7 @@ class RestoreRemovedUsersCommand extends Command
|
|||
'login' => $removedUser->getLogin(),
|
||||
]);
|
||||
$removedUser->restore();
|
||||
|
||||
$this->em->flush();
|
||||
}
|
||||
} catch (UserNotFoundException $e) {
|
||||
|
@ -65,7 +93,5 @@ class RestoreRemovedUsersCommand extends Command
|
|||
}
|
||||
|
||||
$this->em->flush();
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
namespace src\PointToolsBundle\Event;
|
||||
|
||||
use src\PointToolsBundle\Entity\User;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* Dispatched when user subscribers list was changed
|
||||
*/
|
||||
class UserSubscribersUpdatedEvent extends Event
|
||||
{
|
||||
const NAME = 'app.user.subscribers_updated';
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* @var User[]
|
||||
*/
|
||||
private $subscribed;
|
||||
|
||||
/**
|
||||
* @var User[]
|
||||
*/
|
||||
private $unsubscribed;
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param User[] $subscribed
|
||||
* @param User[] $unsubscribed
|
||||
*/
|
||||
public function __construct(User $user, array $subscribed, array $unsubscribed)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->subscribed = $subscribed;
|
||||
$this->unsubscribed = $unsubscribed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public function getUser(): User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User[]
|
||||
*/
|
||||
public function getSubscribedUsers(): array
|
||||
{
|
||||
return $this->subscribed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User[]
|
||||
*/
|
||||
public function getUnsubscribedUsers(): array
|
||||
{
|
||||
return $this->unsubscribed;
|
||||
}
|
||||
}
|
37
old/src/PointToolsBundle/Event/UsersRenamedEvent.php
Normal file
37
old/src/PointToolsBundle/Event/UsersRenamedEvent.php
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace src\PointToolsBundle\Event;
|
||||
|
||||
use src\PointToolsBundle\Entity\UserRenameEvent;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* Dispatched when one or more users were renamed
|
||||
*/
|
||||
class UsersRenamedEvent extends Event
|
||||
{
|
||||
const NAME = 'app.users.renamed';
|
||||
|
||||
/**
|
||||
* @var UserRenameEvent[]
|
||||
*/
|
||||
private $renames;
|
||||
|
||||
/**
|
||||
* UsersRenamedEvent constructor.
|
||||
*
|
||||
* @param UserRenameEvent[] $renames
|
||||
*/
|
||||
public function __construct(array $renames)
|
||||
{
|
||||
$this->renames = $renames;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return UserRenameEvent[]
|
||||
*/
|
||||
public function getRenames(): array
|
||||
{
|
||||
return $this->renames;
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Event;
|
||||
|
||||
use App\Entity\User;
|
||||
use Symfony\Contracts\EventDispatcher\Event;
|
||||
|
||||
/** Dispatched when user subscribers list was changed */
|
||||
class UserSubscribersUpdatedEvent extends Event
|
||||
{
|
||||
const NAME = 'app.user.subscribers_updated';
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param User[] $subscribed
|
||||
* @param User[] $unsubscribed
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly User $user,
|
||||
public readonly array $subscribed,
|
||||
public readonly array $unsubscribed
|
||||
) {
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Event;
|
||||
|
||||
use App\Entity\UserRenameEvent;
|
||||
use Symfony\Contracts\EventDispatcher\Event;
|
||||
|
||||
/** Dispatched when one or more users were renamed */
|
||||
class UsersRenamedEvent extends Event
|
||||
{
|
||||
const NAME = 'app.users.renamed';
|
||||
|
||||
/** @param UserRenameEvent[] $renames */
|
||||
public function __construct(
|
||||
public readonly array $renames
|
||||
) {
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue