diff --git a/src/Propel/Generator/Behavior/I18n/I18nBehavior.php b/src/Propel/Generator/Behavior/I18n/I18nBehavior.php index b10a24be9..fb4d573fb 100644 --- a/src/Propel/Generator/Behavior/I18n/I18nBehavior.php +++ b/src/Propel/Generator/Behavior/I18n/I18nBehavior.php @@ -132,6 +132,7 @@ public function getI18nColumns(): array $columns = []; $i18nTable = $this->getI18nTable(); $columnNames = $this->getI18nColumnNamesFromConfig(); + if ($columnNames) { // Strategy 1: use the i18n_columns parameter foreach ($columnNames as $columnName) { @@ -386,8 +387,10 @@ protected function getLocaleColumnName(): string protected function getI18nColumnNamesFromConfig(): array { $columnNames = explode(',', $this->getParameter('i18n_columns')); + foreach ($columnNames as $key => $columnName) { $columnName = trim($columnName); + if ($columnName) { $columnNames[$key] = $columnName; } else { diff --git a/src/Propel/Generator/Behavior/Versionable/VersionableBehavior.php b/src/Propel/Generator/Behavior/Versionable/VersionableBehavior.php index 65ca90a40..62b9af2b3 100644 --- a/src/Propel/Generator/Behavior/Versionable/VersionableBehavior.php +++ b/src/Propel/Generator/Behavior/Versionable/VersionableBehavior.php @@ -254,17 +254,18 @@ public function getVersionTablePhpName(): string */ public function getVersionableFks(): array { - $versionableFKs = []; - $fks = $this->getTable()->getForeignKeys(); - if ($fks) { - foreach ($fks as $fk) { - if ($fk->getForeignTable()->hasBehavior($this->getName()) && !$fk->isComposite()) { - $versionableFKs[] = $fk; - } + $versionableForeignKeys = []; + if (!$this->getTable()) { + return $versionableForeignKeys; + } + + foreach ($this->getTable()->getForeignKeys() as $foreignKey) { + if ($foreignKey->getForeignTable()->hasBehavior($this->getName()) && !$foreignKey->isComposite()) { + $versionableForeignKeys[] = $foreignKey; } } - return $versionableFKs; + return $versionableForeignKeys; } /** @@ -273,12 +274,13 @@ public function getVersionableFks(): array public function getVersionableReferrers(): array { $versionableReferrers = []; - $fks = $this->getTable()->getReferrers(); - if ($fks) { - foreach ($fks as $fk) { - if ($fk->getTable()->hasBehavior($this->getName()) && !$fk->isComposite()) { - $versionableReferrers[] = $fk; - } + if (!$this->getTable()) { + return $versionableReferrers; + } + + foreach ($this->getTable()->getReferrers() as $foreignKey) { + if ($foreignKey->getTable()->hasBehavior($this->getName()) && !$foreignKey->isComposite()) { + $versionableReferrers[] = $foreignKey; } } diff --git a/src/Propel/Generator/Builder/Om/ObjectBuilder.php b/src/Propel/Generator/Builder/Om/ObjectBuilder.php index aff98e473..e2e840bfa 100644 --- a/src/Propel/Generator/Builder/Om/ObjectBuilder.php +++ b/src/Propel/Generator/Builder/Om/ObjectBuilder.php @@ -4123,8 +4123,8 @@ protected function addFKAttributes(string &$script, ForeignKey $fk): void protected function addFKMutator(string &$script, ForeignKey $fk): void { $fkTable = $fk->getForeignTable(); - $interface = $fk->getInterface(); + if ($interface) { $className = $this->declareClass($interface); } else { @@ -4211,13 +4211,12 @@ public function set" . $this->getFKPhpNameAffix($fk, false) . "($className \$v = protected function addFKAccessor(string &$script, ForeignKey $fk): void { $table = $this->getTable(); - $varName = $this->getFKVarName($fk); - $fkQueryBuilder = $this->getNewStubQueryBuilder($fk->getForeignTable()); $fkObjectBuilder = $this->getNewObjectBuilder($fk->getForeignTable())->getStubObjectBuilder(); $returnDesc = ''; $interface = $fk->getInterface(); + if ($interface) { $className = $this->declareClass($interface); } else { @@ -4324,7 +4323,7 @@ protected function addRefFKGetJoinMethods(string &$script, ForeignKey $refFK): v $joinBehavior = $this->getBuildProperty('generator.objectModel.useLeftJoinsInDoJoinMethods') ? 'Criteria::LEFT_JOIN' : 'Criteria::INNER_JOIN'; $fkQueryClassName = $this->getClassNameFromBuilder($this->getNewStubQueryBuilder($refFK->getTable())); - $relCol = $this->getRefFKPhpNameAffix($refFK, $plural = true); + $relCol = $this->getRefFKPhpNameAffix($refFK, true); $className = $this->getClassNameFromTable($tblFK); @@ -4422,9 +4421,11 @@ protected function addRefFKAttributes(string &$script, ForeignKey $refFK): void */ protected function addRefFKMethods(string &$script): void { - if (!$referrers = $this->getTable()->getReferrers()) { + $referrers = $this->getTable()->getReferrers(); + if (!$referrers) { return; } + $this->addInitRelations($script, $referrers); foreach ($referrers as $refFK) { $this->declareClassFromBuilder($this->getNewStubObjectBuilder($refFK->getTable()), 'Child'); @@ -4575,7 +4576,7 @@ protected function addRefFKAdd(string &$script, ForeignKey $refFK): void $collName = $this->getRefFKCollVarName($refFK); - $scheduledForDeletion = lcfirst($this->getRefFKPhpNameAffix($refFK, $plural = true)) . 'ScheduledForDeletion'; + $scheduledForDeletion = lcfirst($this->getRefFKPhpNameAffix($refFK, true)) . 'ScheduledForDeletion'; $script .= " /** @@ -4588,7 +4589,7 @@ protected function addRefFKAdd(string &$script, ForeignKey $refFK): void public function add" . $this->getRefFKPhpNameAffix($refFK, false) . "($className \$l) { if (\$this->$collName === null) { - \$this->init" . $this->getRefFKPhpNameAffix($refFK, $plural = true) . "(); + \$this->init" . $this->getRefFKPhpNameAffix($refFK, true) . "(); \$this->{$collName}Partial = true; } @@ -4616,7 +4617,7 @@ public function add" . $this->getRefFKPhpNameAffix($refFK, false) . "($className protected function addRefFKCount(string &$script, ForeignKey $refFK): void { $fkQueryClassName = $this->getClassNameFromBuilder($this->getNewStubQueryBuilder($refFK->getTable())); - $relCol = $this->getRefFKPhpNameAffix($refFK, $plural = true); + $relCol = $this->getRefFKPhpNameAffix($refFK, true); $collName = $this->getRefFKCollVarName($refFK); $joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable()); @@ -4670,7 +4671,7 @@ public function count{$relCol}(?Criteria \$criteria = null, bool \$distinct = fa protected function addRefFKGet(string &$script, ForeignKey $refFK): void { $fkQueryClassName = $this->getClassNameFromBuilder($this->getNewStubQueryBuilder($refFK->getTable())); - $relCol = $this->getRefFKPhpNameAffix($refFK, $plural = true); + $relCol = $this->getRefFKPhpNameAffix($refFK, true); $collName = $this->getRefFKCollVarName($refFK); $className = $this->getClassNameFromTable($refFK->getTable()); @@ -4698,7 +4699,7 @@ public function get$relCol(?Criteria \$criteria = null, ?ConnectionInterface \$c if (\$this->isNew()) { // return empty collection if (null === \$this->$collName) { - \$this->init" . $this->getRefFKPhpNameAffix($refFK, $plural = true) . "(); + \$this->init" . $this->getRefFKPhpNameAffix($refFK, true) . "(); } else { \$collectionClassName = " . $this->getClassNameFromBuilder($this->getNewTableMapBuilder($refFK->getTable())) . "::getTableMap()->getCollectionClassName(); @@ -4714,7 +4715,7 @@ public function get$relCol(?Criteria \$criteria = null, ?ConnectionInterface \$c if (null !== \$criteria) { if (false !== \$this->{$collName}Partial && count(\$$collName)) { - \$this->init" . $this->getRefFKPhpNameAffix($refFK, $plural = true) . "(false); + \$this->init" . $this->getRefFKPhpNameAffix($refFK, true) . "(false); foreach (\$$collName as \$obj) { if (false == \$this->{$collName}->contains(\$obj)) { @@ -4862,7 +4863,7 @@ protected function addRefFKRemove(string &$script, ForeignKey $refFK): void $className = $this->getClassNameFromTable($refFK->getTable()); } - $relatedName = $this->getRefFKPhpNameAffix($refFK, $plural = true); + $relatedName = $this->getRefFKPhpNameAffix($refFK, true); $relatedObjectClassName = $this->getRefFKPhpNameAffix($refFK, false); $inputCollection = lcfirst($relatedName . 'ScheduledForDeletion'); $lowerRelatedObjectClassName = lcfirst($relatedObjectClassName); @@ -5277,7 +5278,7 @@ protected function addCrossFkScheduledForDeletion(string &$script, CrossForeignK */ protected function addRefFkScheduledForDeletion(string &$script, ForeignKey $refFK): void { - $relatedName = $this->getRefFKPhpNameAffix($refFK, $plural = true); + $relatedName = $this->getRefFKPhpNameAffix($refFK, true); $lowerRelatedName = lcfirst($relatedName); $lowerSingleRelatedName = lcfirst($this->getRefFKPhpNameAffix($refFK, false)); $queryClassName = $this->getNewStubQueryBuilder($refFK->getTable())->getClassname(); @@ -5373,7 +5374,7 @@ public function clear{$relCol}() */ protected function addRefFKPartial(string &$script, ForeignKey $refFK): void { - $relCol = $this->getRefFKPhpNameAffix($refFK, $plural = true); + $relCol = $this->getRefFKPhpNameAffix($refFK, true); $collName = $this->getRefFKCollVarName($refFK); $script .= " diff --git a/src/Propel/Generator/Builder/Om/TableMapBuilder.php b/src/Propel/Generator/Builder/Om/TableMapBuilder.php index 6c08586df..58c082e9b 100644 --- a/src/Propel/Generator/Builder/Om/TableMapBuilder.php +++ b/src/Propel/Generator/Builder/Om/TableMapBuilder.php @@ -343,11 +343,8 @@ public static function getValueSet(string \$colname): array public function addInheritanceColumnConstants(string &$script): void { $col = $this->getTable()->getChildrenColumn(); - if (!$col) { - return; - } - if (!$col->isEnumeratedClasses()) { + if (!$col || !$col->isEnumeratedClasses()) { return; } diff --git a/src/Propel/Generator/Config/GeneratorConfig.php b/src/Propel/Generator/Config/GeneratorConfig.php index 3534aef01..32cd3f0a9 100644 --- a/src/Propel/Generator/Config/GeneratorConfig.php +++ b/src/Propel/Generator/Config/GeneratorConfig.php @@ -196,19 +196,22 @@ public function getConfiguredPluralizer(): PluralizerInterface */ public function getBuildConnections(): array { - if ($this->buildConnections === null) { - $connectionNames = $this->get()['generator']['connections']; + if ($this->buildConnections !== null) { + return $this->buildConnections; + } - $reverseConnection = $this->getConfigProperty('reverse.connection'); - if ($reverseConnection !== null && !in_array($reverseConnection, $connectionNames, true)) { - $connectionNames[] = $reverseConnection; - } + $connectionNames = $this->get()['generator']['connections']; + $reverseConnection = $this->getConfigProperty('reverse.connection'); - foreach ($connectionNames as $name) { - $definition = $this->getConfigProperty('database.connections.' . $name); - if ($definition) { - $this->buildConnections[$name] = $definition; - } + if ($reverseConnection !== null && !in_array($reverseConnection, $connectionNames, true)) { + $connectionNames[] = $reverseConnection; + } + + foreach ($connectionNames as $name) { + $definition = $this->getConfigProperty('database.connections.' . $name); + + if ($definition) { + $this->buildConnections[$name] = $definition; } } diff --git a/src/Propel/Generator/Model/Behavior.php b/src/Propel/Generator/Model/Behavior.php index 25e83c709..0a1372680 100644 --- a/src/Propel/Generator/Model/Behavior.php +++ b/src/Propel/Generator/Model/Behavior.php @@ -447,8 +447,9 @@ public function getColumnForParameter(string $name): ?Column protected function setupObject(): void { $this->setName($this->getAttribute('name')); + $id = $this->getAttribute('id'); - if (!$this->allowMultiple() && $id = $this->getAttribute('id')) { + if (!$this->allowMultiple() && $id) { throw new LogicException(sprintf('Defining an ID (%s) on a behavior which does not allow multiple instances makes no sense', $id)); } diff --git a/src/Propel/Generator/Model/Diff/DatabaseDiff.php b/src/Propel/Generator/Model/Diff/DatabaseDiff.php index 31a57a3a0..7546ebfcf 100644 --- a/src/Propel/Generator/Model/Diff/DatabaseDiff.php +++ b/src/Propel/Generator/Model/Diff/DatabaseDiff.php @@ -335,18 +335,26 @@ public function getReverseDiff(): self */ public function getDescription(): string { + $numberOfAddedTables = $this->countAddedTables(); + $numberOfRemovedTables = $this->countRemovedTables(); + $numberOfModifiedTables = $this->countModifiedTables(); + $numberOfRenamedTables = $this->countRenamedTables(); $changes = []; - if ($count = $this->countAddedTables()) { - $changes[] = sprintf('%d added tables', $count); + + if ($numberOfAddedTables) { + $changes[] = sprintf('%d added tables', $numberOfAddedTables); } - if ($count = $this->countRemovedTables()) { - $changes[] = sprintf('%d removed tables', $count); + + if ($numberOfRemovedTables) { + $changes[] = sprintf('%d removed tables', $numberOfRemovedTables); } - if ($count = $this->countModifiedTables()) { - $changes[] = sprintf('%d modified tables', $count); + + if ($numberOfModifiedTables) { + $changes[] = sprintf('%d modified tables', $numberOfModifiedTables); } - if ($count = $this->countRenamedTables()) { - $changes[] = sprintf('%d renamed tables', $count); + + if ($numberOfRenamedTables) { + $changes[] = sprintf('%d renamed tables', $numberOfRenamedTables); } return implode(', ', $changes); @@ -358,26 +366,85 @@ public function getDescription(): string public function __toString(): string { $ret = ''; - if ($addedTables = $this->getAddedTables()) { + $ret = $this->appendAddedTablesToString($ret); + $ret = $this->appendRemovedTablesToString($ret); + $ret = $this->appendModifiedTablesToString($ret); + + return $this->appendRenamedTablesToString($ret); + } + + /** + * @param string $ret + * + * @return string + */ + protected function appendAddedTablesToString(string $ret): string + { + $addedTables = $this->getAddedTables(); + + if ($addedTables) { $ret .= "addedTables:\n"; + foreach ($addedTables as $tableName => $table) { $ret .= sprintf(" - %s\n", $tableName); } } - if ($removedTables = $this->getRemovedTables()) { + + return $ret; + } + + /** + * @param string $ret + * + * @return string + */ + protected function appendRemovedTablesToString(string $ret): string + { + $removedTables = $this->getRemovedTables(); + + if ($removedTables) { $ret .= "removedTables:\n"; + foreach ($removedTables as $tableName => $table) { $ret .= sprintf(" - %s\n", $tableName); } } - if ($modifiedTables = $this->getModifiedTables()) { + + return $ret; + } + + /** + * @param string $ret + * + * @return string + */ + protected function appendModifiedTablesToString(string $ret): string + { + $modifiedTables = $this->getModifiedTables(); + + if ($modifiedTables) { $ret .= "modifiedTables:\n"; + foreach ($modifiedTables as $tableDiff) { $ret .= $tableDiff->__toString(); } } - if ($renamedTables = $this->getRenamedTables()) { + + return $ret; + } + + /** + * @param string $ret + * + * @return string + */ + protected function appendRenamedTablesToString(string $ret): string + { + $renamedTables = $this->getRenamedTables(); + + if ($renamedTables) { $ret .= "renamedTables:\n"; + foreach ($renamedTables as $fromName => $toName) { $ret .= sprintf(" %s: %s\n", $fromName, $toName); } diff --git a/src/Propel/Generator/Model/Diff/TableDiff.php b/src/Propel/Generator/Model/Diff/TableDiff.php index d45225664..3f1a1aeb2 100644 --- a/src/Propel/Generator/Model/Diff/TableDiff.php +++ b/src/Propel/Generator/Model/Diff/TableDiff.php @@ -1082,81 +1082,234 @@ public function __clone() */ public function __toString(): string { - $ret = ''; - $ret .= sprintf(" %s:\n", $this->fromTable->getName()); - if ($addedColumns = $this->getAddedColumns()) { + $ret = sprintf(" %s:\n", $this->fromTable->getName()); + $ret = $this->appendAddedColumnsToString($ret); + $ret = $this->appendRemovedColumnsToString($ret); + $ret = $this->appendModifiedColumnsToString($ret); + $ret = $this->appendRenamedColumnsToString($ret); + $ret = $this->appendAddedIndicesToString($ret); + $ret = $this->appendRemovedIndicesToString($ret); + $ret = $this->appendModifiedIndicesToString($ret); + $ret = $this->appendAddedFksToString($ret); + $ret = $this->appendRemovedFksToString($ret); + + return $this->appendModifiedFksToString($ret); + } + + /** + * @param string $ret + * + * @return string + */ + protected function appendAddedColumnsToString(string $ret): string + { + $addedColumns = $this->getAddedColumns(); + + if ($addedColumns) { $ret .= " addedColumns:\n"; + foreach ($addedColumns as $colname => $column) { $ret .= sprintf(" - %s\n", $colname); } } - if ($removedColumns = $this->getRemovedColumns()) { + + return $ret; + } + + /** + * @param string $ret + * + * @return string + */ + protected function appendRemovedColumnsToString(string $ret): string + { + $removedColumns = $this->getRemovedColumns(); + + if ($removedColumns) { $ret .= " removedColumns:\n"; + foreach ($removedColumns as $colname => $column) { $ret .= sprintf(" - %s\n", $colname); } } - if ($modifiedColumns = $this->getModifiedColumns()) { + + return $ret; + } + + /** + * @param string $ret + * + * @return string + */ + protected function appendModifiedColumnsToString(string $ret): string + { + $modifiedColumns = $this->getModifiedColumns(); + + if ($modifiedColumns) { $ret .= " modifiedColumns:\n"; + foreach ($modifiedColumns as $colDiff) { $ret .= (string)$colDiff; } } - if ($renamedColumns = $this->getRenamedColumns()) { + + return $ret; + } + + /** + * @param string $ret + * + * @return string + */ + protected function appendRenamedColumnsToString(string $ret): string + { + $renamedColumns = $this->getRenamedColumns(); + + if ($renamedColumns) { $ret .= " renamedColumns:\n"; + foreach ($renamedColumns as $columnRenaming) { [$fromColumn, $toColumn] = $columnRenaming; $ret .= sprintf(" %s: %s\n", $fromColumn->getName(), $toColumn->getName()); } } - if ($addedIndices = $this->getAddedIndices()) { + + return $ret; + } + + /** + * @param string $ret + * + * @return string + */ + protected function appendAddedIndicesToString(string $ret): string + { + $addedIndices = $this->getAddedIndices(); + + if ($addedIndices) { $ret .= " addedIndices:\n"; + foreach ($addedIndices as $indexName => $index) { $ret .= sprintf(" - %s\n", $indexName); } } - if ($removedIndices = $this->getRemovedIndices()) { + + return $ret; + } + + /** + * @param string $ret + * + * @return string + */ + protected function appendRemovedIndicesToString(string $ret): string + { + $removedIndices = $this->getRemovedIndices(); + + if ($removedIndices) { $ret .= " removedIndices:\n"; + foreach ($removedIndices as $indexName => $index) { $ret .= sprintf(" - %s\n", $indexName); } } - if ($modifiedIndices = $this->getModifiedIndices()) { + + return $ret; + } + + /** + * @param string $ret + * + * @return string + */ + protected function appendModifiedIndicesToString(string $ret): string + { + $modifiedIndices = $this->getModifiedIndices(); + + if ($modifiedIndices) { $ret .= " modifiedIndices:\n"; + foreach ($modifiedIndices as $indexName => $indexDiff) { $ret .= sprintf(" - %s\n", $indexName); } } - if ($addedFks = $this->getAddedFks()) { + + return $ret; + } + + /** + * @param string $ret + * + * @return string + */ + protected function appendAddedFksToString(string $ret): string + { + $addedFks = $this->getAddedFks(); + + if ($addedFks) { $ret .= " addedFks:\n"; + foreach ($addedFks as $fkName => $fk) { $ret .= sprintf(" - %s\n", $fkName); } } - if ($removedFks = $this->getRemovedFks()) { + + return $ret; + } + + /** + * @param string $ret + * + * @return string + */ + protected function appendRemovedFksToString(string $ret): string + { + $removedFks = $this->getRemovedFks(); + + if ($removedFks) { $ret .= " removedFks:\n"; + foreach ($removedFks as $fkName => $fk) { $ret .= sprintf(" - %s\n", $fkName); } } - if ($modifiedFks = $this->getModifiedFks()) { + + return $ret; + } + + /** + * @param string $ret + * + * @return string + */ + protected function appendModifiedFksToString(string $ret): string + { + $modifiedFks = $this->getModifiedFks(); + + if ($modifiedFks) { $ret .= " modifiedFks:\n"; + foreach ($modifiedFks as $fkName => $fkFromTo) { $ret .= sprintf(" %s:\n", $fkName); [$fromFk, $toFk] = $fkFromTo; $fromLocalColumns = json_encode($fromFk->getLocalColumns()); $toLocalColumns = json_encode($toFk->getLocalColumns()); + if ($fromLocalColumns != $toLocalColumns) { $ret .= sprintf(" localColumns: from %s to %s\n", $fromLocalColumns, $toLocalColumns); } + $fromForeignColumns = json_encode($fromFk->getForeignColumns()); $toForeignColumns = json_encode($toFk->getForeignColumns()); + if ($fromForeignColumns != $toForeignColumns) { $ret .= sprintf(" foreignColumns: from %s to %s\n", $fromForeignColumns, $toForeignColumns); } + if ($fromFk->normalizeFKey($fromFk->getOnUpdate()) != $toFk->normalizeFKey($toFk->getOnUpdate())) { $ret .= sprintf(" onUpdate: from %s to %s\n", $fromFk->getOnUpdate(), $toFk->getOnUpdate()); } + if ($fromFk->normalizeFKey($fromFk->getOnDelete()) != $toFk->normalizeFKey($toFk->getOnDelete())) { $ret .= sprintf(" onDelete: from %s to %s\n", $fromFk->getOnDelete(), $toFk->getOnDelete()); } diff --git a/src/Propel/Generator/Model/ForeignKey.php b/src/Propel/Generator/Model/ForeignKey.php index 6676de3c0..ea7c8cba7 100644 --- a/src/Propel/Generator/Model/ForeignKey.php +++ b/src/Propel/Generator/Model/ForeignKey.php @@ -466,7 +466,8 @@ public function getForeignTableName(): ?string } $database = $this->getDatabase(); - if ($database && ($schema = $this->parentTable->guessSchemaName()) && $platform && $platform->supportsSchemas()) { + $schema = $this->parentTable->guessSchemaName(); + if ($database && $schema && $platform && $platform->supportsSchemas()) { return $schema . $platform->getSchemaDelimiter() . $this->foreignTableCommonName; diff --git a/src/Propel/Generator/Model/Index.php b/src/Propel/Generator/Model/Index.php index b4d47ddf0..a025f9ef5 100644 --- a/src/Propel/Generator/Model/Index.php +++ b/src/Propel/Generator/Model/Index.php @@ -93,8 +93,8 @@ public function getName(): string { $this->doNaming(); - if ($this->table && ($database = $this->table->getDatabase())) { - return substr($this->name, 0, $database->getMaxColumnNameLength()); + if ($this->table && $this->table->getDatabase()) { + return substr($this->name, 0, $this->table->getDatabase()->getMaxColumnNameLength()); } return $this->name; diff --git a/src/Propel/Generator/Model/Table.php b/src/Propel/Generator/Model/Table.php index d4d588174..95cdd679f 100644 --- a/src/Propel/Generator/Model/Table.php +++ b/src/Propel/Generator/Model/Table.php @@ -1188,7 +1188,11 @@ public function getName(): string */ public function guessSchemaName(): ?string { - return $this->schema ?: $this->database->getSchema(); + if ($this->schema) { + return $this->schema; + } + + return $this->database ? $this->database->getSchema() : null; } /** diff --git a/src/Propel/Generator/Platform/DefaultPlatform.php b/src/Propel/Generator/Platform/DefaultPlatform.php index 70c75f41a..78ef3529d 100644 --- a/src/Propel/Generator/Platform/DefaultPlatform.php +++ b/src/Propel/Generator/Platform/DefaultPlatform.php @@ -416,13 +416,22 @@ public function getColumnDDL(Column $col): string } else { $ddl[] = $sqlType; } - if ($default = $this->getColumnDefaultValueDDL($col)) { + + $default = $this->getColumnDefaultValueDDL($col); + + if ($default) { $ddl[] = $default; } - if ($notNull = $this->getNullString($col->isNotNull())) { + + $notNull = $this->getNullString($col->isNotNull()); + + if ($notNull) { $ddl[] = $notNull; } - if ($autoIncrement = $col->getAutoIncrementString()) { + + $autoIncrement = $col->getAutoIncrementString(); + + if ($autoIncrement) { $ddl[] = $autoIncrement; } @@ -890,12 +899,19 @@ public function getModifyTableDDL(TableDiff $tableDiff): string foreach ($tableDiff->getRenamedColumns() as $columnRenaming) { $columnChangeString .= $this->getRenameColumnDDL($columnRenaming[0], $columnRenaming[1]); } - if ($modifiedColumns = $tableDiff->getModifiedColumns()) { + + $modifiedColumns = $tableDiff->getModifiedColumns(); + + if ($modifiedColumns) { $columnChangeString .= $this->getModifyColumnsDDL($modifiedColumns); } - if ($addedColumns = $tableDiff->getAddedColumns()) { + + $addedColumns = $tableDiff->getAddedColumns(); + + if ($addedColumns) { $columnChangeString .= $this->getAddColumnsDDL($addedColumns); } + foreach ($tableDiff->getRemovedColumns() as $column) { $columnChangeString .= $this->getRemoveColumnDDL($column); } @@ -946,11 +962,15 @@ public function getModifyTableColumnsDDL(TableDiff $tableDiff): string $ret .= $this->getRenameColumnDDL($columnRenaming[0], $columnRenaming[1]); } - if ($modifiedColumns = $tableDiff->getModifiedColumns()) { + $modifiedColumns = $tableDiff->getModifiedColumns(); + + if ($modifiedColumns) { $ret .= $this->getModifyColumnsDDL($modifiedColumns); } - if ($addedColumns = $tableDiff->getAddedColumns()) { + $addedColumns = $tableDiff->getAddedColumns(); + + if ($addedColumns) { $ret .= $this->getAddColumnsDDL($addedColumns); } @@ -1566,7 +1586,9 @@ public function normalizeTable(Table $table): void } foreach ($table->getColumns() as $column) { - if ($column->getSize() && $defaultSize = $this->getDefaultTypeSize($column->getType())) { + $defaultSize = $this->getDefaultTypeSize($column->getType()); + + if ($column->getSize() && $defaultSize) { if ($column->getScale() === null && (int)$column->getSize() === $defaultSize) { $column->setSize(null); } diff --git a/src/Propel/Generator/Platform/MysqlPlatform.php b/src/Propel/Generator/Platform/MysqlPlatform.php index f661edd50..ad4ca938d 100644 --- a/src/Propel/Generator/Platform/MysqlPlatform.php +++ b/src/Propel/Generator/Platform/MysqlPlatform.php @@ -91,10 +91,12 @@ public function setGeneratorConfig(GeneratorConfigInterface $generatorConfig): v if ($defaultTableEngine) { $this->defaultTableEngine = $defaultTableEngine; } + $tableEngineKeyword = $mysqlConfig['tableEngineKeyword']; if ($tableEngineKeyword) { $this->tableEngineKeyword = $tableEngineKeyword; } + $uuidColumnType = $mysqlConfig['uuidColumnType']; if ($uuidColumnType) { $enable = strtolower($uuidColumnType) === 'native'; @@ -519,6 +521,7 @@ public function getColumnDDL(Column $col): string if ($autoIncrement) { $ddl[] = $autoIncrement; } + if ($col->getDescription()) { $ddl[] = 'COMMENT ' . $this->quote($col->getDescription()); } diff --git a/src/Propel/Generator/Platform/PgsqlPlatform.php b/src/Propel/Generator/Platform/PgsqlPlatform.php index f038fd250..486b7fcd1 100755 --- a/src/Propel/Generator/Platform/PgsqlPlatform.php +++ b/src/Propel/Generator/Platform/PgsqlPlatform.php @@ -446,13 +446,12 @@ protected function getAddColumnComment(Column $column): string $pattern = " COMMENT ON COLUMN %s.%s IS %s; "; - $description = $column->getDescription(); - if ($description) { + if ($column->getDescription()) { return sprintf( $pattern, $this->quoteIdentifier($column->getTable()->getName()), $this->quoteIdentifier($column->getName()), - $this->quote($description), + $this->quote($column->getDescription()), ); } @@ -523,10 +522,12 @@ public function getColumnDDL(Column $col): string if ($default) { $ddl[] = $default; } + $notNull = $this->getNullString($col->isNotNull()); if ($notNull) { $ddl[] = $notNull; } + $autoIncrement = $col->getAutoIncrementString(); if ($autoIncrement) { $ddl[] = $autoIncrement; @@ -708,6 +709,7 @@ public function getModifyColumnDDL(ColumnDiff $columnDiff): string if ($using) { $sqlType .= $using; } + $ret .= sprintf( $pattern, $this->quoteIdentifier($table->getName()), diff --git a/src/Propel/Generator/Reverse/MysqlSchemaParser.php b/src/Propel/Generator/Reverse/MysqlSchemaParser.php index c67e8e174..3a306b215 100644 --- a/src/Propel/Generator/Reverse/MysqlSchemaParser.php +++ b/src/Propel/Generator/Reverse/MysqlSchemaParser.php @@ -154,6 +154,7 @@ protected function parseTables(Database $database, ?Table $filterTable = null): if ($schema) { $sql .= ' FROM ' . $database->getPlatform()->doQuoting($schema); } + $sql .= sprintf(" LIKE '%s'", $filterTable->getCommonName()); } else { $schema = $database->getSchema(); diff --git a/src/Propel/Generator/Reverse/PgsqlSchemaParser.php b/src/Propel/Generator/Reverse/PgsqlSchemaParser.php index 80febdd29..5fa466fc8 100755 --- a/src/Propel/Generator/Reverse/PgsqlSchemaParser.php +++ b/src/Propel/Generator/Reverse/PgsqlSchemaParser.php @@ -233,10 +233,9 @@ protected function addColumns(Table $table, int $oid): void $searchPath = '?'; $params = [$table->getDatabase()->getSchema()]; - $schema = $table->getSchema(); + if ($schema) { - $searchPath = '?'; $params = [$schema]; } elseif (!$table->getDatabase()->getSchema()) { $stmt = $this->dbh->query('SHOW search_path'); diff --git a/src/Propel/Generator/Util/QuickBuilder.php b/src/Propel/Generator/Util/QuickBuilder.php index c0d8f8433..6f5f18135 100644 --- a/src/Propel/Generator/Util/QuickBuilder.php +++ b/src/Propel/Generator/Util/QuickBuilder.php @@ -468,9 +468,9 @@ public function getClassesForTable(Table $table, ?array $classTargets = null): s $script .= $this->fixNamespaceDeclarations($class); } - $col = $table->getChildrenColumn(); - if ($col && $col->isEnumeratedClasses()) { - foreach ($col->getChildren() as $child) { + $column = $table->getChildrenColumn(); + if ($column && $column->isEnumeratedClasses()) { + foreach ($column->getChildren() as $child) { if (!$child->getAncestor()) { continue; } diff --git a/src/Propel/Runtime/ActiveQuery/Criteria.php b/src/Propel/Runtime/ActiveQuery/Criteria.php index eb2a7fad7..26c0503f7 100644 --- a/src/Propel/Runtime/ActiveQuery/Criteria.php +++ b/src/Propel/Runtime/ActiveQuery/Criteria.php @@ -2168,7 +2168,8 @@ public function quoteIdentifier(string $string, string $tableName = ''): string } //find table name and ask tableMap if quoting is enabled - if (!$tableName && ($pos = strrpos($string, '.')) !== false) { + $pos = strrpos($string, '.'); + if (!$tableName && $pos !== false) { $tableName = substr($string, 0, $pos); } diff --git a/src/Propel/Runtime/ActiveQuery/ModelCriteria.php b/src/Propel/Runtime/ActiveQuery/ModelCriteria.php index e9195bdad..275c669a9 100644 --- a/src/Propel/Runtime/ActiveQuery/ModelCriteria.php +++ b/src/Propel/Runtime/ActiveQuery/ModelCriteria.php @@ -2283,8 +2283,8 @@ protected function getColumnFromName(string $columnName, bool $failSilently = tr $tableMap = $this->joins[$shortClass]->getTableMap(); } elseif ($this->hasSelectQuery($prefix)) { return $this->getColumnFromSubQuery($prefix, $columnName, $failSilently); - } elseif ($modelJoin = $this->getModelJoinByTableName($prefix)) { - $tableMap = $modelJoin->getTableMap(); + } elseif ($this->getModelJoinByTableName($prefix)) { + $tableMap = $this->getModelJoinByTableName($prefix)->getTableMap(); } elseif ($failSilently) { return [null, null]; } else {