This commit is contained in:
Sergio Álvarez 2022-05-23 20:40:22 +02:00
parent 703ef3c5b1
commit b58b92bc30
No known key found for this signature in database
GPG Key ID: 622780889DFDBDA5
14 changed files with 390 additions and 92 deletions

View File

@ -4,7 +4,7 @@
"minimum-stability": "stable",
"prefer-stable": true,
"require": {
"php": ">=8.0.2",
"php": ">=8.1",
"ext-ctype": "*",
"ext-iconv": "*",
"doctrine/doctrine-bundle": "^2.6",

View File

@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20220523155141 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
// Added 'status' to INSERT
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('DROP INDEX IDX_E4F82A3DED5CA9E6');
$this->addSql('CREATE TEMPORARY TABLE __temp__mer_para_sub AS SELECT id, service_id, sub_date, unsub_date, pin FROM mer_para_sub');
$this->addSql('DROP TABLE mer_para_sub');
$this->addSql('CREATE TABLE mer_para_sub (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, service_id INTEGER NOT NULL, sub_date DATETIME NOT NULL --(DC2Type:datetime_immutable)
, unsub_date DATETIME DEFAULT NULL --(DC2Type:datetime_immutable)
, pin INTEGER DEFAULT NULL, status INTEGER NOT NULL, CONSTRAINT FK_E4F82A3DED5CA9E6 FOREIGN KEY (service_id) REFERENCES mer_service (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('INSERT INTO mer_para_sub (id, service_id, sub_date, unsub_date, pin, status) SELECT id, service_id, sub_date, unsub_date, pin, 1 FROM __temp__mer_para_sub');
$this->addSql('DROP TABLE __temp__mer_para_sub');
$this->addSql('CREATE INDEX IDX_E4F82A3DED5CA9E6 ON mer_para_sub (service_id)');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP INDEX IDX_E4F82A3DED5CA9E6');
$this->addSql('CREATE TEMPORARY TABLE __temp__mer_para_sub AS SELECT id, service_id, pin, sub_date, unsub_date FROM mer_para_sub');
$this->addSql('DROP TABLE mer_para_sub');
$this->addSql('CREATE TABLE mer_para_sub (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, service_id INTEGER NOT NULL, pin INTEGER DEFAULT NULL, sub_date DATETIME NOT NULL --(DC2Type:datetime_immutable)
, unsub_date DATETIME DEFAULT NULL --(DC2Type:datetime_immutable)
)');
$this->addSql('INSERT INTO mer_para_sub (id, service_id, pin, sub_date, unsub_date) SELECT id, service_id, pin, sub_date, unsub_date FROM __temp__mer_para_sub');
$this->addSql('DROP TABLE __temp__mer_para_sub');
$this->addSql('CREATE INDEX IDX_E4F82A3DED5CA9E6 ON mer_para_sub (service_id)');
}
}

View File

@ -0,0 +1,52 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20220523155631 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE mer_be_sub (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, service_id INTEGER NOT NULL, code VARCHAR(255) DEFAULT NULL, status INTEGER NOT NULL, sub_date DATETIME NOT NULL --(DC2Type:datetime_immutable)
, unsub_date DATETIME DEFAULT NULL --(DC2Type:datetime_immutable)
)');
$this->addSql('CREATE INDEX IDX_CA4C3EB8ED5CA9E6 ON mer_be_sub (service_id)');
$this->addSql('DROP INDEX IDX_E4F82A3DED5CA9E6');
$this->addSql('CREATE TEMPORARY TABLE __temp__mer_para_sub AS SELECT id, service_id, sub_date, unsub_date, pin, status FROM mer_para_sub');
$this->addSql('DROP TABLE mer_para_sub');
$this->addSql('CREATE TABLE mer_para_sub (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, service_id INTEGER NOT NULL, sub_date DATETIME NOT NULL --(DC2Type:datetime_immutable)
, unsub_date DATETIME DEFAULT NULL --(DC2Type:datetime_immutable)
, pin INTEGER DEFAULT NULL, status INTEGER NOT NULL, CONSTRAINT FK_E4F82A3DED5CA9E6 FOREIGN KEY (service_id) REFERENCES mer_service (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('INSERT INTO mer_para_sub (id, service_id, sub_date, unsub_date, pin, status) SELECT id, service_id, sub_date, unsub_date, pin, status FROM __temp__mer_para_sub');
$this->addSql('DROP TABLE __temp__mer_para_sub');
$this->addSql('CREATE INDEX IDX_E4F82A3DED5CA9E6 ON mer_para_sub (service_id)');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP TABLE mer_be_sub');
$this->addSql('DROP INDEX IDX_E4F82A3DED5CA9E6');
$this->addSql('CREATE TEMPORARY TABLE __temp__mer_para_sub AS SELECT id, service_id, pin, status, sub_date, unsub_date FROM mer_para_sub');
$this->addSql('DROP TABLE mer_para_sub');
$this->addSql('CREATE TABLE mer_para_sub (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, service_id INTEGER NOT NULL, pin INTEGER DEFAULT NULL, status INTEGER NOT NULL, sub_date DATETIME NOT NULL --(DC2Type:datetime_immutable)
, unsub_date DATETIME DEFAULT NULL --(DC2Type:datetime_immutable)
)');
$this->addSql('INSERT INTO mer_para_sub (id, service_id, pin, status, sub_date, unsub_date) SELECT id, service_id, pin, status, sub_date, unsub_date FROM __temp__mer_para_sub');
$this->addSql('DROP TABLE __temp__mer_para_sub');
$this->addSql('CREATE INDEX IDX_E4F82A3DED5CA9E6 ON mer_para_sub (service_id)');
}
}

View File

@ -2,8 +2,11 @@
namespace App\Controller;
use App\Repository\MerBeSubRepository;
use App\Repository\MerParaSubRepository;
use App\Repository\MerServiceRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Repository\Entity1Repository;
@ -11,18 +14,38 @@ use App\Repository\Entity1Repository;
class IndexController extends AbstractController
{
#[Route('/', name: 'app_index')]
public function index(Entity1Repository $repo, MerParaSubRepository $subRepo): Response
public function index(
Entity1Repository $repo,
MerParaSubRepository $paraSubRepo,
MerBeSubRepository $beSubRepo
): Response
{
// repo dummy
$sm = $repo->getSchemaManager();
$sub = $subRepo->findOne();
dump($sub);
dump($sub->getService());
foreach ($paraSubRepo->findAll() as $sub) {
dump($sub);
}
dump('-------------------');
foreach ($beSubRepo->findAll() as $sub) {
dump($sub);
}
return $this->render('index/index.html.twig', [
'controller_name' => 'IndexController',
'schemaManager' => $sm
'schemaManager' => $sm,
//'offer_id' => $sub->getService()->ge
]);
}
#[Route('/notification/dm', name: 'notification_dm')]
public function notificationDm(Request $request, MerServiceRepository $repo): Response
{
foreach ($repo->findByOfferId($request->query->get('offer_id')) as $sub) {
dump($sub);
}
return $this->render('index/notificationDm.html.twig');
}
}

View File

@ -3,9 +3,11 @@
namespace App\DataFixtures;
use App\Entity\MerBeDM;
use App\Entity\MerBeSub;
use App\Entity\MerParaDM;
use App\Entity\MerParaDT;
use App\Entity\MerParaSub;
use App\Enum\SubStatus;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
@ -13,42 +15,65 @@ class MerFixtures extends Fixture
{
public function load(ObjectManager $manager): void
{
// service1
$tmp = new MerParaDM();
$tmp->setMccMnc(12345)->setOfferId(221)->setProductCode('code1');
$manager->persist($tmp);
$ser1 = new MerParaDM();
$ser1->setMccMnc(12345)
->setOfferId(221)
->setProductCode('code1');
// sub
$sub = new MerParaSub();
$sub->setService($tmp)->setPin(1122)->setSubDate(new \DateTimeImmutable('now'));
$manager->persist($sub);
$ser2 = new MerParaDM();
$ser2->setMccMnc(12345)
->setOfferId(223)
->setProductCode('code2');
// service 2
$tmp = new MerParaDM();
$tmp->setMccMnc(12345)->setOfferId(223)->setProductCode('code2');
$manager->persist($tmp);
$ser3 = new MerParaDT();
$ser3->setMccMnc(12345)
->setServiceId('ser-vi-ce1')
->setApiKey('api1');
// sub
$sub = new MerParaSub();
$sub->setService($tmp)->setPin(2211)->setSubDate(new \DateTimeImmutable('now'));
$manager->persist($sub);
$ser4 = new MerParaDT();
$ser4->setMccMnc(12341)
->setServiceId('ser-vi-ce2')
->setApiKey('api2');
$sub = new MerParaSub();
$sub->setService($tmp)->setSubDate(new \DateTimeImmutable('now'));
$manager->persist($sub);
$ser5 = new MerBeDM();
$ser5->setMccMnc(12341)
->setOfferId(112)
->setActivationCode('active1');
// service 3
$tmp = new MerParaDT();
$tmp->setMccMnc(12345)->setServiceId('ser-vi-ce1')->setApiKey('api1');
$manager->persist($tmp);
$sub1 = new MerParaSub();
$sub1->setService($ser1)
->setStatus(SubStatus::ACTIVE)
->setPin(1122)
->setSubDate(new \DateTimeImmutable('now'));
$tmp = new MerParaDT();
$tmp->setMccMnc(12341)->setServiceId('ser-vi-ce2')->setApiKey('api2');
$manager->persist($tmp);
$sub2 = new MerParaSub();
$sub2->setService($ser3)
->setStatus(SubStatus::PREREGISTERED)
->setPin(2211)
->setSubDate(new \DateTimeImmutable('now'));
$tmp = new MerBeDM();
$tmp->setMccMnc(12341)->setOfferId(112)->setActivationCode('active1');
$manager->persist($tmp);
$sub3 = new MerParaSub();
$sub3->setService($ser3)
->setStatus(SubStatus::CANCELLED)
->setSubDate(new \DateTimeImmutable('yesterday'))
->setUnsubDate(new \DateTimeImmutable('now'));
$sub4 = new MerBeSub();
$sub4->setService($ser5)
->setStatus(SubStatus::REGISTERED)
->setCode('CoDe')
->setSubDate(new \DateTimeImmutable('now'));
$manager->persist($ser1);
$manager->persist($ser2);
$manager->persist($ser3);
$manager->persist($ser4);
$manager->persist($ser5);
$manager->persist($sub1);
$manager->persist($sub2);
$manager->persist($sub3);
$manager->persist($sub4);
$manager->flush();
}

27
src/Entity/MerBeSub.php Normal file
View File

@ -0,0 +1,27 @@
<?php
namespace App\Entity;
use App\Repository\MerParaSubRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
class MerBeSub
{
use MerSubBaseTrait;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $code;
public function getCode(): ?int
{
return $this->code;
}
public function setCode(?string $code): self
{
$this->code = $code;
return $this;
}
}

View File

@ -8,29 +8,11 @@ use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: MerParaSubRepository::class)]
class MerParaSub
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
use MerSubBaseTrait;
#[ORM\Column(type: 'integer', nullable: true)]
private $pin;
#[ORM\ManyToOne(targetEntity: MerService::class)]
#[ORM\JoinColumn(nullable: false)]
private MerService $service;
#[ORM\Column(type: 'datetime_immutable')]
private $subDate;
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private $unsubDate;
public function getId(): ?int
{
return $this->id;
}
public function getPin(): ?int
{
return $this->pin;
@ -42,40 +24,4 @@ class MerParaSub
return $this;
}
public function getService(): ?MerService
{
return $this->service;
}
public function setService(?MerService $service): self
{
$this->service = $service;
return $this;
}
public function getSubDate(): ?\DateTimeImmutable
{
return $this->subDate;
}
public function setSubDate(\DateTimeImmutable $subDate): self
{
$this->subDate = $subDate;
return $this;
}
public function getUnsubDate(): ?\DateTimeImmutable
{
return $this->unsubDate;
}
public function setUnsubDate(?\DateTimeImmutable $unsubDate): self
{
$this->unsubDate = $unsubDate;
return $this;
}
}

View File

@ -0,0 +1,80 @@
<?php
namespace App\Entity;
use App\Enum\SubStatus;
use Doctrine\ORM\Mapping as ORM;
trait MerSubBaseTrait
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(enumType: SubStatus::class)]
private SubStatus $status;
#[ORM\ManyToOne(targetEntity: MerService::class)]
#[ORM\JoinColumn(nullable: false)]
private MerService $service;
#[ORM\Column(type: 'datetime_immutable')]
private $subDate;
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private $unsubDate;
public function getId(): ?int
{
return $this->id;
}
public function getStatus(): SubStatus
{
return $this->status;
}
public function setStatus(SubStatus $status): self
{
$this->status = $status;
return $this;
}
public function getService(): ?MerService
{
return $this->service;
}
public function setService(?MerService $service): self
{
$this->service = $service;
return $this;
}
public function getSubDate(): ?\DateTimeImmutable
{
return $this->subDate;
}
public function setSubDate(\DateTimeImmutable $subDate): self
{
$this->subDate = $subDate;
return $this;
}
public function getUnsubDate(): ?\DateTimeImmutable
{
return $this->unsubDate;
}
public function setUnsubDate(?\DateTimeImmutable $unsubDate): self
{
$this->unsubDate = $unsubDate;
return $this;
}
}

12
src/Enum/SubStatus.php Normal file
View File

@ -0,0 +1,12 @@
<?php
namespace App\Enum;
enum SubStatus: int
{
case PREREGISTERED = 1;
case REGISTERED = 2;
case ACTIVE = 3;
case CANCELLED = 4;
case EXPIRED = 5;
}

View File

@ -0,0 +1,66 @@
<?php
namespace App\Repository;
use App\Entity\MerBeSub;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<MerBeSub>
*
* @method MerBeSub|null find($id, $lockMode = null, $lockVersion = null)
* @method MerBeSub|null findOneBy(array $criteria, array $orderBy = null)
* @method MerBeSub[] findAll()
* @method MerBeSub[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class MerBeSubRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, MerBeSub::class);
}
public function add(MerBeSub $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(MerBeSub $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
// /**
// * @return MerBeSub[] Returns an array of MerBeSub objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('m')
// ->andWhere('m.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('m.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
public function findOne(): ?MerBeSub
{
return $this->createQueryBuilder('m')
->orderBy('m.id', 'ASC')
->setMaxResults(1)
->getQuery()
->getOneOrNullResult()
;
}
}

View File

@ -67,7 +67,7 @@ class MerParaSubRepository extends ServiceEntityRepository
public function findOne(): ?MerParaSub
{
return $this->createQueryBuilder('m')
->orderBy('m.id', 'DESC')
->orderBy('m.id', 'ASC')
->setMaxResults(1)
->getQuery()
->getOneOrNullResult()

View File

@ -62,4 +62,14 @@ class MerServiceRepository extends ServiceEntityRepository
// ->getOneOrNullResult()
// ;
// }
public function findByOfferId(int $offerId)
{
return $this->createQueryBuilder('s')
->andWhere('s.offer_id = :offer_id')
->setParameter('offer_id', $offerId)
->getQuery()
->getResult()
;
}
}

View File

@ -32,4 +32,6 @@
</li>
{% endfor %}
</ul>
<p><a href="{{ path('notification_dm', {'offer_id': 112}) }}">dm notification</a></p>
{% endblock %}

View File

@ -0,0 +1,7 @@
{% extends 'base.html.twig' %}
{% block title %}notif dm!{% endblock %}
{% block body %}
<p>check profiler output</p>
{% endblock %}