Skip to content

Commit

Permalink
refs #558 Map Date/Time types to string to avoid issues importing seeds
Browse files Browse the repository at this point in the history
  • Loading branch information
ajibarra committed Aug 26, 2022
1 parent e0b0547 commit 05478a5
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Command/BakeSeedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
use Cake\Console\ConsoleIo;
use Cake\Console\ConsoleOptionParser;
use Cake\Core\Configure;
use Cake\Database\Type\StringType;
use Cake\Database\TypeFactory;
use Cake\Datasource\ConnectionManager;
use Cake\Utility\Inflector;

Expand All @@ -42,6 +44,22 @@ class BakeSeedCommand extends SimpleBakeCommand
*/
protected $_name;

/**
* @inheritDoc
*/
public function initialize(): void
{
parent::initialize();
// Mapping date/time types to String to avoid creating seeds
// with FrozenDate/FrozenTime objects. refs #558
TypeFactory::map('datetime', StringType::class);
TypeFactory::map('date', StringType::class);
TypeFactory::map('datetimefractional', StringType::class);
TypeFactory::map('timestamp', StringType::class);
TypeFactory::map('timestampfractional', StringType::class);
TypeFactory::map('timestamptimezone', StringType::class);
}

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -134,6 +152,7 @@ public function templateData(Arguments $arguments): array

/** @var array $records */
$records = $query->toArray();

$records = $this->prettifyArray($records);
}

Expand Down

0 comments on commit 05478a5

Please sign in to comment.