Revert: User removal support.
This commit is contained in:
parent
3ab7993d04
commit
38d0ab50be
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Application\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Migrations\AbstractMigration;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
/**
|
||||
* User removal support
|
||||
*/
|
||||
class Version20170116224555 extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function up(Schema $schema)
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
|
||||
|
||||
$this->addSql('ALTER TABLE users.users ADD is_removed BOOLEAN DEFAULT FALSE NOT NULL');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function down(Schema $schema)
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
|
||||
|
||||
$this->addSql('ALTER TABLE users.users DROP is_removed');
|
||||
}
|
||||
}
|
|
@ -75,9 +75,15 @@ class ImportUsersCommand extends ContainerAwareCommand
|
|||
continue;
|
||||
}
|
||||
|
||||
$createdAt = \DateTime::createFromFormat('Y-m-d_H:i:s', $row[3]) ?: new \DateTime();
|
||||
$createdAt = \DateTime::createFromFormat('Y-m-d_H:i:s', $row[3]);
|
||||
|
||||
$user = new User($row[0], $createdAt, $row[1], $row[2]);
|
||||
if (!$createdAt) {
|
||||
$createdAt = new \DateTime();
|
||||
}
|
||||
|
||||
$user = (new User($row[0], $row[1], $row[2]))
|
||||
->setCreatedAt($createdAt)
|
||||
;
|
||||
|
||||
if (!$input->getOption('check-only')) {
|
||||
$em->persist($user);
|
||||
|
|
|
@ -6,7 +6,6 @@ use Doctrine\ORM\EntityManagerInterface;
|
|||
use Psr\Log\LoggerInterface;
|
||||
use Skobkin\Bundle\PointToolsBundle\Entity\Subscription;
|
||||
use Skobkin\Bundle\PointToolsBundle\Entity\User;
|
||||
use Skobkin\Bundle\PointToolsBundle\Exception\Api\UserNotFoundException;
|
||||
use Skobkin\Bundle\PointToolsBundle\Repository\UserRepository;
|
||||
use Skobkin\Bundle\PointToolsBundle\Service\SubscriptionsManager;
|
||||
use Skobkin\Bundle\PointToolsBundle\Service\Api\UserApi;
|
||||
|
@ -186,11 +185,6 @@ class UpdateSubscriptionsCommand extends ContainerAwareCommand
|
|||
|
||||
try {
|
||||
$userCurrentSubscribers = $this->api->getUserSubscribersById($user->getId());
|
||||
} catch (UserNotFoundException $e) {
|
||||
$this->logger->warning('User not found. Marking as removed', ['login' => $user->getLogin(), 'user_id' => $user->getId()]);
|
||||
$user->markAsRemoved();
|
||||
|
||||
continue;
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error(
|
||||
'Error while getting subscribers. Skipping.',
|
||||
|
@ -228,16 +222,14 @@ class UpdateSubscriptionsCommand extends ContainerAwareCommand
|
|||
|
||||
private function getUsersForUpdate(int $appUserId): array
|
||||
{
|
||||
$usersForUpdate = [];
|
||||
|
||||
if ($this->input->getOption('all-users')) {
|
||||
$usersForUpdate = $this->userRepo->findBy(['removed' => false]);
|
||||
$usersForUpdate = $this->userRepo->findAll();
|
||||
} else {
|
||||
/** @var User $serviceUser */
|
||||
$serviceUser = $this->userRepo->findActiveUserWithSubscribers($appUserId);
|
||||
$serviceUser = $this->userRepo->find($appUserId);
|
||||
|
||||
if (!$serviceUser) {
|
||||
$this->logger->critical('Service user not found');
|
||||
$this->logger->info('Service user not found');
|
||||
// @todo Retrieving user
|
||||
|
||||
throw new \RuntimeException('Service user not found in the database');
|
||||
|
@ -247,10 +239,6 @@ class UpdateSubscriptionsCommand extends ContainerAwareCommand
|
|||
|
||||
try {
|
||||
$usersForUpdate = $this->api->getUserSubscribersById($appUserId);
|
||||
} catch (UserNotFoundException $e) {
|
||||
$this->logger->critical('Service user deleted or API response is invalid');
|
||||
|
||||
throw $e;
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->warning(
|
||||
'Error while getting service subscribers. Fallback to local list.',
|
||||
|
@ -263,6 +251,8 @@ class UpdateSubscriptionsCommand extends ContainerAwareCommand
|
|||
]
|
||||
);
|
||||
|
||||
$usersForUpdate = [];
|
||||
|
||||
/** @var Subscription $subscription */
|
||||
foreach ((array) $serviceUser->getSubscribers() as $subscription) {
|
||||
$usersForUpdate[] = $subscription->getSubscriber();
|
||||
|
|
|
@ -27,7 +27,9 @@ class LoadUserData extends AbstractFixture implements OrderedFixtureInterface
|
|||
$userId = 99999;
|
||||
|
||||
foreach ($this->users as $userData) {
|
||||
$user = new User($userId--, new \DateTime(), $userData['login'], $userData['name']);
|
||||
$user = (new User($userId--, $userData['login'], $userData['name']))
|
||||
->setCreatedAt(new \DateTime())
|
||||
;
|
||||
|
||||
$om->persist($user);
|
||||
|
||||
|
|
|
@ -68,25 +68,17 @@ class User
|
|||
|
||||
/**
|
||||
* @var ArrayCollection|SubscriptionEvent[]
|
||||
*
|
||||
* @ORM\OneToMany(targetEntity="SubscriptionEvent", mappedBy="author", fetch="EXTRA_LAZY")
|
||||
*/
|
||||
private $newSubscriberEvents;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*
|
||||
* @ORM\Column(name="is_removed", type="boolean", options={"default": false})
|
||||
*/
|
||||
private $removed = false;
|
||||
|
||||
|
||||
public function __construct(int $id, \DateTime $createdAt = null, string $login = null, string $name = null)
|
||||
public function __construct(int $id, string $login = null, string $name = null)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->login = $login;
|
||||
$this->name = $name;
|
||||
$this->createdAt = $createdAt ?: new \DateTime();
|
||||
$this->createdAt = new \DateTime();
|
||||
|
||||
$this->subscribers = new ArrayCollection();
|
||||
$this->subscriptions = new ArrayCollection();
|
||||
|
@ -106,25 +98,30 @@ class User
|
|||
return $this->id;
|
||||
}
|
||||
|
||||
public function setLogin(string $login): self
|
||||
{
|
||||
$this->login = $login;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLogin(): string
|
||||
{
|
||||
return $this->login;
|
||||
}
|
||||
|
||||
public function getName(): ?string
|
||||
public function setName(?string $name): self
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function updateLoginAndName(string $login, string $name): self
|
||||
{
|
||||
$this->login = $login;
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function addSubscriber(Subscription $subscribers): self
|
||||
{
|
||||
$this->subscribers[] = $subscribers;
|
||||
|
@ -173,18 +170,15 @@ class User
|
|||
return $this->createdAt;
|
||||
}
|
||||
|
||||
public function setCreatedAt(\DateTime $createdAt): self
|
||||
{
|
||||
$this->createdAt = $createdAt;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUpdatedAt(): ?\DateTime
|
||||
{
|
||||
return $this->updatedAt;
|
||||
}
|
||||
|
||||
public function isRemoved(): bool
|
||||
{
|
||||
return $this->isRemoved();
|
||||
}
|
||||
|
||||
public function markAsRemoved(): void
|
||||
{
|
||||
$this->removed = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,19 +13,6 @@ class UserRepository extends EntityRepository
|
|||
$this->getEntityManager()->persist($entity);
|
||||
}
|
||||
|
||||
public function findActiveUserWithSubscribers(int $id): ?User
|
||||
{
|
||||
$qb = $this->createQueryBuilder('u');
|
||||
|
||||
return $qb
|
||||
->select(['u', ''])
|
||||
->innerJoin('u.subscribers', 's')
|
||||
->innerJoin('s.subscriber', 'us')
|
||||
->where('u.removed = FALSE')
|
||||
->getQuery()->getOneOrNullResult()
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Case-insensitive user search
|
||||
*/
|
||||
|
|
|
@ -51,6 +51,22 @@ class AbstractApi
|
|||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make GET request and return response body
|
||||
*/
|
||||
public function getGetResponseBody($path, array $parameters = []): StreamInterface
|
||||
{
|
||||
return $this->sendGetRequest($path, $parameters)->getBody();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make POST request and return response body
|
||||
*/
|
||||
public function getPostResponseBody(string $path, array $parameters = []): StreamInterface
|
||||
{
|
||||
return $this->sendPostRequest($path, $parameters)->getBody();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make GET request and return DTO objects
|
||||
*
|
||||
|
@ -81,22 +97,6 @@ class AbstractApi
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make GET request and return response body
|
||||
*/
|
||||
public function getGetResponseBody($path, array $parameters = []): StreamInterface
|
||||
{
|
||||
return $this->sendGetRequest($path, $parameters)->getBody();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make POST request and return response body
|
||||
*/
|
||||
public function getPostResponseBody(string $path, array $parameters = []): StreamInterface
|
||||
{
|
||||
return $this->sendPostRequest($path, $parameters)->getBody();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path Request path
|
||||
* @param array $parameters Key => Value array of query parameters
|
||||
|
@ -151,12 +151,6 @@ class AbstractApi
|
|||
$code = $response->getStatusCode();
|
||||
$reason = $response->getReasonPhrase();
|
||||
|
||||
// @todo remove after fix
|
||||
// Temporary fix until @arts fixes this bug
|
||||
if ('{"error": "UserNotFound"}' === (string) $response->getBody()) {
|
||||
throw new NotFoundException($reason, $code);
|
||||
}
|
||||
|
||||
switch ($code) {
|
||||
case SymfonyResponse::HTTP_UNAUTHORIZED:
|
||||
throw new UnauthorizedException($reason, $code);
|
||||
|
|
|
@ -39,14 +39,16 @@ class UserFactory extends AbstractFactory
|
|||
|
||||
/** @var User $user */
|
||||
if (null === ($user = $this->userRepository->find($userData->getId()))) {
|
||||
$user = new User(
|
||||
$userData->getId(),
|
||||
\DateTime::createFromFormat('Y-m-d_H:i:s', $userData->getCreated()) ?: new \DateTime()
|
||||
);
|
||||
// Creating new user
|
||||
$user = new User($userData->getId());
|
||||
$this->userRepository->add($user);
|
||||
}
|
||||
|
||||
$user->updateLoginAndName($userData->getLogin(), $userData->getName());
|
||||
// Updating data
|
||||
$user
|
||||
->setLogin($userData->getLogin())
|
||||
->setName($userData->getName())
|
||||
;
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
|
|
@ -52,7 +52,6 @@ class SubscriptionsManager
|
|||
*/
|
||||
public function updateUserSubscribers(User $user, $newSubscribersList = []): void
|
||||
{
|
||||
// @todo optimize
|
||||
$tmpOldSubscribers = $user->getSubscribers();
|
||||
|
||||
$oldSubscribersList = [];
|
||||
|
|
|
@ -14,15 +14,15 @@ class UserSubscribersUpdatedEventTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
public function testCreate()
|
||||
{
|
||||
$user = new User(99999, new \DateTime(), 'testuser', 'Test User 1');
|
||||
$user = new User(99999, 'testuser', 'Test User 1');
|
||||
|
||||
$subscribed = [
|
||||
new User(99998, new \DateTime(), 'testuser2', 'Test User 2'),
|
||||
new User(99998, 'testuser2', 'Test User 2'),
|
||||
];
|
||||
|
||||
$unsubscribed = [
|
||||
new User(99997, new \DateTime(), 'testuser3', 'Test User 3'),
|
||||
new User(99996, new \DateTime(), 'testuser4', 'Test User 4'),
|
||||
new User(99997, 'testuser3', 'Test User 3'),
|
||||
new User(99996, 'testuser4', 'Test User 4'),
|
||||
];
|
||||
|
||||
return new UserSubscribersUpdatedEvent($user, $subscribed, $unsubscribed);
|
||||
|
|
|
@ -15,7 +15,7 @@ class UsersRenamedEventTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
public function testGetRenames()
|
||||
{
|
||||
$user = new User(99999, new \DateTime(), 'testuser', 'Test User 1');
|
||||
$user = new User(99999, 'testuser', 'Test User 1');
|
||||
$renameRecords = [
|
||||
new UserRenameEvent($user, 'testuser_old1'),
|
||||
new UserRenameEvent($user, 'testuser_old2'),
|
||||
|
|
Loading…
Reference in a new issue