-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store region last update in db (instead of cache) (#803)
* Create Region entity * Add migration * Update REgionProvider.php * Update NewMapperCommand.php * Update UpdateCommand.php * Apply fixes from StyleCI Co-authored-by: StyleCI Bot <[email protected]>
- Loading branch information
1 parent
149106e
commit 8dd02f3
Showing
6 changed files
with
172 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?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 Version20221115184831 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Create table "region"'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
// this up() migration is auto-generated, please modify it to your needs | ||
$this->addSql('CREATE TABLE region (id VARCHAR(255) NOT NULL, last_update DATETIME NOT NULL, PRIMARY KEY(id))'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->addSql('DROP TABLE region'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace App\Entity; | ||
|
||
use App\Repository\RegionRepository; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Entity(repositoryClass=RegionRepository::class) | ||
*/ | ||
class Region | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\Column(type="string") | ||
*/ | ||
private ?string $id = null; | ||
|
||
/** | ||
* @ORM\Column(type="datetime") | ||
*/ | ||
private $lastUpdate; | ||
|
||
public function getId(): ?string | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function setId(string $id): self | ||
{ | ||
$this->id = $id; | ||
|
||
return $this; | ||
} | ||
|
||
public function getLastUpdate(): \DateTime | ||
{ | ||
return $this->lastUpdate; | ||
} | ||
|
||
public function setLastUpdate(\DateTime $lastUpdate): self | ||
{ | ||
$this->lastUpdate = $lastUpdate; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace App\Repository; | ||
|
||
use App\Entity\Region; | ||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | ||
use Doctrine\Persistence\ManagerRegistry; | ||
|
||
/** | ||
* @extends ServiceEntityRepository<Region> | ||
* | ||
* @method Region|null find($id, $lockMode = null, $lockVersion = null) | ||
* @method Region|null findOneBy(array $criteria, array $orderBy = null) | ||
* @method Region[] findAll() | ||
* @method Region[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) | ||
*/ | ||
class RegionRepository extends ServiceEntityRepository | ||
{ | ||
public function __construct(ManagerRegistry $registry) | ||
{ | ||
parent::__construct($registry, Region::class); | ||
} | ||
|
||
public function save(Region $entity, bool $flush = false): void | ||
{ | ||
$this->getEntityManager()->persist($entity); | ||
|
||
if ($flush) { | ||
$this->getEntityManager()->flush(); | ||
} | ||
} | ||
|
||
public function remove(Region $entity, bool $flush = false): void | ||
{ | ||
$this->getEntityManager()->remove($entity); | ||
|
||
if ($flush) { | ||
$this->getEntityManager()->flush(); | ||
} | ||
} | ||
|
||
// /** | ||
// * @return Region[] Returns an array of Region objects | ||
// */ | ||
// public function findByExampleField($value): array | ||
// { | ||
// return $this->createQueryBuilder('r') | ||
// ->andWhere('r.exampleField = :val') | ||
// ->setParameter('val', $value) | ||
// ->orderBy('r.id', 'ASC') | ||
// ->setMaxResults(10) | ||
// ->getQuery() | ||
// ->getResult() | ||
// ; | ||
// } | ||
|
||
// public function findOneBySomeField($value): ?Region | ||
// { | ||
// return $this->createQueryBuilder('r') | ||
// ->andWhere('r.exampleField = :val') | ||
// ->setParameter('val', $value) | ||
// ->getQuery() | ||
// ->getOneOrNullResult() | ||
// ; | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters