[TOOLS] Add warning to update code in bin/generate_entity_fields
This commit is contained in:
parent
93276ce8d0
commit
a1a6f5f4fd
|
@ -27,6 +27,7 @@ $files = array_merge(glob(ROOT . '/src/Entity/*.php'),
|
||||||
glob(ROOT . '/plugins/*/Entity/*.php')));
|
glob(ROOT . '/plugins/*/Entity/*.php')));
|
||||||
|
|
||||||
$classes = [];
|
$classes = [];
|
||||||
|
$nullable_no_defaults_warning = [];
|
||||||
|
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
|
|
||||||
|
@ -64,6 +65,9 @@ foreach ($files as $file) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($nullable === '?' || \array_key_exists('default', $field_schema)) && $type != '\DateTimeInterface') {
|
if (($nullable === '?' || \array_key_exists('default', $field_schema)) && $type != '\DateTimeInterface') {
|
||||||
|
if (!\array_key_exists('default', $field_schema)) {
|
||||||
|
$nullable_no_defaults_warning[] = "{$class}::{$field}";
|
||||||
|
}
|
||||||
$default = $field_schema['default'] ?? null;
|
$default = $field_schema['default'] ?? null;
|
||||||
if (\is_string($default)) {
|
if (\is_string($default)) {
|
||||||
$default = "'{$default}'";
|
$default = "'{$default}'";
|
||||||
|
@ -107,3 +111,10 @@ foreach ($files as $file) {
|
||||||
$out_file = preg_replace("%\\s*{$begin}.*{$end}%smu", $code, $in_file);
|
$out_file = preg_replace("%\\s*{$begin}.*{$end}%smu", $code, $in_file);
|
||||||
file_put_contents($file, $out_file);
|
file_put_contents($file, $out_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($nullable_no_defaults_warning)) {
|
||||||
|
echo "Warning: The following don't have a default value, but we're assigning it `null`. Doctrine might not like this, so update it\n";
|
||||||
|
foreach ($nullable_no_defaults_warning as $n) {
|
||||||
|
echo " {$n}\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user