<?php
declare(strict_types=1);
namespace PrestashopConnectorBundleMigrations;
use App\Services\ObjectSerialize;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use Symfony\Component\Uid\UuidV6;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20241008111505 extends AbstractMigration
{
private ObjectSerialize $objectSerialize;
public function setObjectSerialize(ObjectSerialize $objectSerialize): void
{
$this->objectSerialize = $objectSerialize;
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
}
public function postUp(Schema $schema): void
{
parent::postUp($schema);
$contexts = $this->connection->executeQuery('SELECT * FROM context WHERE deleted_at IS NULL')
->fetchAllAssociative();
$firstInvoiceDate = $this->connection->executeQuery(
'SELECT validated_at FROM sales_bundle__invoice
WHERE validated_at IS NOT NULL AND deleted_at IS NULL
ORDER BY validated_at ASC LIMIT 1'
)->fetchOne();
$now = $defaultDate = new \DateTime();
if ($firstInvoiceDate) {
$defaultDate = new \DateTime($firstInvoiceDate);
}
$defaultDate = $defaultDate->format('Y-m-d');
$now = $now->format('Y-m-d H:i:s');
foreach ($contexts as $context) {
$this->connection->insert('configuration', [
'id' => (new UuidV6())->toBinary(),
'name' => 'prestashop_connector_bundle__limit_invoice_date',
'context_id' => $context['id'],
'value' => $this->objectSerialize->add((object) ['value' => $defaultDate]),
'created_at' => $now,
'updated_at' => $now
]);
}
}
}