Skip to content

Commit

Permalink
fix(submission): change expire_date from date to date time (#867)
Browse files Browse the repository at this point in the history
  • Loading branch information
Davidmattei authored Apr 9, 2024
1 parent ab6c217 commit 9de994f
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
{% endif %}
{%- endblock -%}

{%- block modified -%}<td data-order="{{ data.task_modified|date('U') }}">{{ data.task_modified -}}</td>{%- endblock -%}
{%- block modified -%}<td data-order="{{ data.task_modified|date('U') }}">{{ data.task_modified|date(date_time_format) -}}</td>{%- endblock -%}

{%- block actions -%}
<div class="btn-group">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace EMS\CoreBundle\DataTable\Type;

use EMS\CoreBundle\Core\DataTable\Type\AbstractEntityTableType;
use EMS\CoreBundle\Form\Data\DateTableColumn;
use EMS\CoreBundle\Form\Data\DatetimeTableColumn;
use EMS\CoreBundle\Form\Data\EntityTable;
use EMS\CoreBundle\Form\Data\TableAbstract;
Expand All @@ -27,7 +26,7 @@ public function build(EntityTable $table): void
$table->addColumn('form-submission.index.column.form', 'name');
$table->addColumn('form-submission.index.column.locale', 'locale');
$table->addColumnDefinition(new DatetimeTableColumn('form-submission.index.column.created', 'created'));
$table->addColumnDefinition(new DateTableColumn('form-submission.index.column.expire_date', 'expireDate'));
$table->addColumnDefinition(new DatetimeTableColumn('form-submission.index.column.expire_date', 'expireDate'));

$table->addItemGetAction('form.submissions.download', 'form-submission.form-submissions.download', 'download');
$table->addItemPostAction('form.submissions.process', 'form-submission.form-submissions.process', 'check', 'form-submission.form-submissions.confirm');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace Application\Migrations;

use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20240409120638 extends AbstractMigration
{
public function getDescription(): string
{
return 'Form submission change expire_date from date to datetime';
}

public function up(Schema $schema): void
{
$this->abortIf(
!$this->connection->getDatabasePlatform() instanceof MySQLPlatform,
"Migration can only be executed safely on '\Doctrine\DBAL\Platforms\MySQLPlatform'."
);

$this->addSql('ALTER TABLE form_submission CHANGE expire_date expire_date DATETIME DEFAULT NULL');
}

public function down(Schema $schema): void
{
$this->abortIf(
!$this->connection->getDatabasePlatform() instanceof MySQLPlatform,
"Migration can only be executed safely on '\Doctrine\DBAL\Platforms\MySQLPlatform'."
);

$this->addSql('ALTER TABLE form_submission CHANGE expire_date expire_date DATE DEFAULT NULL');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace Application\Migrations;

use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20240409120406 extends AbstractMigration
{
public function getDescription(): string
{
return 'Form submission change expire_date from date to datetime';
}

public function up(Schema $schema): void
{
$this->abortIf(
!$this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform,
"Migration can only be executed safely on '\Doctrine\DBAL\Platforms\PostgreSQLPlatform'."
);

$this->addSql('ALTER TABLE form_submission ALTER expire_date TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
}

public function down(Schema $schema): void
{
$this->abortIf(
!$this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform,
"Migration can only be executed safely on '\Doctrine\DBAL\Platforms\PostgreSQLPlatform'."
);

$this->addSql('ALTER TABLE form_submission ALTER expire_date TYPE DATE');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
{% endif %}
{%- endblock -%}

{%- block modified -%}<td data-order="{{ data.task_modified|date('U') }}">{{ data.task_modified -}}</td>{%- endblock -%}
{%- block modified -%}<td data-order="{{ data.task_modified|date('U') }}">{{ data.task_modified|date(date_time_format) -}}</td>{%- endblock -%}

{%- block actions -%}
<div class="btn-group">
Expand Down
9 changes: 5 additions & 4 deletions EMS/submission-bundle/src/Entity/FormSubmission.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ class FormSubmission implements EntityInterface, \JsonSerializable
protected $files;

/**
* @ORM\Column(name="expire_date", type="date", nullable=true)
* @ORM\Column(name="expire_date", type="datetime", nullable=true)
*/
private ?\DateTime $expireDate;
private ?\DateTimeInterface $expireDate;

/**
* @ORM\Column(name="label", type="string", length=255)
Expand Down Expand Up @@ -144,7 +144,8 @@ public function toArray(): array
}

if ($this->files->count() > 0) {
$data['files'] = $this->files->toArray();
$files = $this->files->toArray();
$data['files'] = \array_map(static fn (FormSubmissionFile $f) => $f->toArray(), $files);
} else {
unset($data['files']);
}
Expand Down Expand Up @@ -203,7 +204,7 @@ public function getLabel(): ?string
return $this->label;
}

public function getExpireDate(): ?\DateTime
public function getExpireDate(): ?\DateTimeInterface
{
return $this->expireDate;
}
Expand Down
8 changes: 8 additions & 0 deletions EMS/submission-bundle/src/Entity/FormSubmissionFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ public function __construct(/**
* @return array<string, mixed>
*/
public function jsonSerialize(): array
{
return $this->toArray();
}

/**
* @return array<string, mixed>
*/
public function toArray(): array
{
return [
'id' => $this->id->toString(),
Expand Down
2 changes: 1 addition & 1 deletion EMS/submission-bundle/src/Request/DatabaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function getLabel(): string
return $this->label;
}

public function getExpireDate(): ?\DateTime
public function getExpireDate(): ?\DateTimeInterface
{
return $this->expireDate ? \DateTime::createFromImmutable($this->expireDate) : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Application\Migrations;

use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

Expand Down
37 changes: 37 additions & 0 deletions elasticms-web/migrations/pdo_mysql/Version20240409121627.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20240409121627 extends AbstractMigration
{
public function getDescription(): string
{
return 'Form submission change expire_date from date to datetime';
}

public function up(Schema $schema): void
{
$this->abortIf(
!$this->connection->getDatabasePlatform() instanceof MySQLPlatform,
"Migration can only be executed safely on '\Doctrine\DBAL\Platforms\MySQLPlatform'."
);

$this->addSql('ALTER TABLE form_submission CHANGE expire_date expire_date DATETIME DEFAULT NULL');
}

public function down(Schema $schema): void
{
$this->abortIf(
!$this->connection->getDatabasePlatform() instanceof MySQLPlatform,
"Migration can only be executed safely on '\Doctrine\DBAL\Platforms\MySQLPlatform'."
);

$this->addSql('ALTER TABLE form_submission CHANGE expire_date expire_date DATE DEFAULT NULL');
}
}
37 changes: 37 additions & 0 deletions elasticms-web/migrations/pdo_pgsql/Version20240409121450.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20240409121450 extends AbstractMigration
{
public function getDescription(): string
{
return 'Form submission change expire_date from date to datetime';
}

public function up(Schema $schema): void
{
$this->abortIf(
!$this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform,
"Migration can only be executed safely on '\Doctrine\DBAL\Platforms\PostgreSQLPlatform'."
);

$this->addSql('ALTER TABLE form_submission ALTER expire_date TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
}

public function down(Schema $schema): void
{
$this->abortIf(
!$this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform,
"Migration can only be executed safely on '\Doctrine\DBAL\Platforms\PostgreSQLPlatform'."
);

$this->addSql('ALTER TABLE form_submission ALTER expire_date TYPE DATE');
}
}

0 comments on commit 9de994f

Please sign in to comment.