diff --git a/CHANGELOG.md b/CHANGELOG.md index 0be42ad..38a2bf3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,14 @@ All notable changes to this project will be documented in this file. ### Added - Add support of variadic parameters in `ide-helper:models` [\#1234 / shaffe-fr](https://github.com/barryvdh/laravel-ide-helper/pull/1234) +2021-06-18, 2.10.1 +------------------ +### Added +- Added Type registration according to [Custom Mapping Types documentation](https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/types.html#custom-mapping-types) + +### Fixed +- Fixing issue where configured custom_db_types could cause a DBAL exception to be thrown while running `ide-helper:models` + 2021-04-09, 2.10.0 ------------------ ### Added diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index 57b8fea..4a40ca8 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -17,6 +17,8 @@ use Barryvdh\Reflection\DocBlock\Context; use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer; use Barryvdh\Reflection\DocBlock\Tag; use Composer\Autoload\ClassMapGenerator; +use Doctrine\DBAL\Exception as DBALException; +use Doctrine\DBAL\Types\Type; use Illuminate\Console\Command; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; use Illuminate\Database\Eloquent\Factories\Factory; @@ -415,6 +417,8 @@ class ModelsCommand extends Command * Load the properties from the database table. * * @param \Illuminate\Database\Eloquent\Model $model + * + * @throws DBALException If custom field failed to register */ public function getPropertiesFromTable($model) { @@ -426,6 +430,14 @@ class ModelsCommand extends Command $platformName = $databasePlatform->getName(); $customTypes = $this->laravel['config']->get("ide-helper.custom_db_types.{$platformName}", []); foreach ($customTypes as $yourTypeName => $doctrineTypeName) { + try { + if(!Type::hasType($yourTypeName)) { + Type::addType($yourTypeName, get_class(Type::getType($doctrineTypeName))); + } + } catch (DBALException $exception) { + $this->error("Failed registering custom db type \"$yourTypeName\" as \"$doctrineTypeName\""); + throw $exception; + } $databasePlatform->registerDoctrineTypeMapping($yourTypeName, $doctrineTypeName); }