Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Om rename : the big change #175

Merged
merged 38 commits into from

5 participants

@jaugustin
Collaborator

Hi,

Work on om-rename #35 is finished, now it's time to merge it back.

a little PR with 60 changed files with 817 additions and 598 deletions ;)

and all tests are GREEN

Build Status

@jaugustin
Collaborator

grrrr it need a rebase

jaugustin and others added some commits
@jaugustin jaugustin [Generator] start renaming Base object from Om dir to base dir withou…
…t Base prefix
5ad5781
@jaugustin jaugustin [Generator] refactor declareClass to handle Alias, manual or automati…
…caly
14452d8
@jaugustin jaugustin [Generator] continue to rename Base classes b7c4c46
@jaugustin jaugustin [Generator] fix use of FQCN, add parameter to getClassname 2ae0712
@jaugustin jaugustin [Runtime][Collection] fix setModel to handle FQCN correctly, fix call…
… to getModel
32111e7
@jaugustin jaugustin [Runtime][ObjectCollection] fix FQCN feys for from/to Array e2ea88f
@jaugustin jaugustin [Generator][QuickBuilder] fix Base prefix for non-namespaced class, f…
…ix auto namespace in quickbuilder
7c751f4
@jaugustin jaugustin [Generator] add 4 new getClassname methods, use it in the right place 44a7593
@jaugustin jaugustin [Generator] fix willdurand rebase ac88602
@jaugustin jaugustin [Runtime] fix collection tests 42e7177
@jaugustin jaugustin [Runtime] fix some tests (work in progress) ad82988
@jaugustin jaugustin [WIP]fedex day: om rename to Base a7c874c
@jaugustin jaugustin [Generator][Builder] fix Object builder tests and use lcfirst 254e8df
@jaugustin jaugustin [Generator][Util] fix QuickBuilder tests 0bd0aab
@willdurand willdurand [Generator] Fixed some unit tests, added a LogicException d1101c4
@jaugustin jaugustin [Generator][TableMapBuild] change FQCN to CN for extends TableMap ed1130f
@jaugustin jaugustin [Runtime][ModelCriteria] fix test, handle FQCN or QCN has Model input
[Runtime][ModelWith] fix test, handle FQCN or QCN has Model input
1cbda7a
@jaugustin jaugustin [Runtime][Map] fix getTableMap when class doesn't have namespace
[Runtime][Query] fix join to use FQCN or QCN => force QCN
c67fea3
@jaugustin jaugustin [Generator][Builder] fix tests of declareClass whith duclicate exception 1897efa
@jaugustin jaugustin [Generator][Behavior] fix AggregateColumn, wrong classname with names…
…apce, remove lcfirst hack for php 5.2
67a0d79
@jaugustin jaugustin [Generator][Behavior] fix build ConcreteInheritanceBehavior, setParen…
…tClass set QCN instead of FQCN
2a508a6
@jaugustin jaugustin [Generator][Behavior] fix getPeerClassNameWithNamespace for NestedSet c1e3869
@willdurand willdurand Updated gitignore
Removed composer.lock
36ed53f
@willdurand willdurand [Generator] Fixed CS 49398cc
@jaugustin jaugustin [Generator][I18n] fix generate wrong query filterBy
[Generator][Builder] fix generate class without namespace, add whitelist
class (PDO, Exception, DateTime
remove unecessary use statement DateTimeZone
6f2f1e7
@jaugustin jaugustin [Generator][QuickBuilder] fix rebase of #155 56485ab
@jaugustin jaugustin [Generator][Builder] fix issue with non namespaced Model, fix namespa…
…ce of QueryInheritance force Base when needed, the end of #35
1f5cf64
@jaugustin
Collaborator

green and mergeable,

...sionable/VersionableBehaviorObjectBuilderModifier.php
@@ -487,7 +487,10 @@ public function getAllVersions(\$con = null)
protected function addComputeDiff(&$script)
{
$versionTable = $this->behavior->getVersionTable();
+ $versionARClassname = $this->builder->getClassnameFromBuilder($this->builder->getNewStubObjectBuilder($versionTable));
@jaugustin Collaborator

seems unused

@jaugustin Collaborator

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
...sionable/VersionableBehaviorObjectBuilderModifier.php
@@ -487,7 +487,10 @@ public function getAllVersions(\$con = null)
protected function addComputeDiff(&$script)
{
$versionTable = $this->behavior->getVersionTable();
+ $versionARClassname = $this->builder->getClassnameFromBuilder($this->builder->getNewStubObjectBuilder($versionTable));
+ $versionForeignColumn = $versionTable->getColumn($this->behavior->getParameter('version_column'));
@jaugustin Collaborator

seems unused

@jaugustin Collaborator

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/Propel/Generator/Builder/Om/AbstractOMBuilder.php
@@ -33,6 +35,14 @@
protected $declaredClasses = array();
/**
+ * Mapping bettwen fully qualified classnames and their short classname or alias
+ * @var array
+ */
+ protected $declaredShortClassesOrAlias = array();
+
+ protected $whiteListOfDeclaratedClasses = array('PDO', 'Exception', 'DateTime');
@jaugustin Collaborator

need a little comment

@hhamon Collaborator
hhamon added a note

$whiteListOfDeclaredClasses instead of $whiteListOfDeclaratedClasses

@jaugustin Collaborator

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@fzaninotto

:raised_hands:
:pray:
:muscle:
:clap:

nuff said

src/Propel/Generator/Builder/Om/AbstractOMBuilder.php
((100 lines not shown))
+ } elseif (false === array_search($class, $this->whiteListOfDeclaratedClasses, true)) { //force alias for model without namespace
+
+ return true;
+ }
+ }
+ if ('Base' == $namespace && '' == $this->getNamespace()) {
+ if (false === array_search($class, $this->whiteListOfDeclaratedClasses, true)) { //force alias for model without namespace
+
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public function declareClassNamespacePrefix($class, $namespace = '', $aliasPrefix = false)
@jaugustin Collaborator

missing phpDoc

@jaugustin Collaborator

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/Propel/Generator/Command/ModelBuild.php
@@ -85,7 +85,7 @@ protected function configure()
->addOption('disable-namespace-auto-package', null, InputOption::VALUE_NONE,
'Disable namespace auto-packaging')
->addOption('base-prefix', null, InputOption::VALUE_REQUIRED,
- 'Prefix for base classes', 'Base')
+ 'Prefix for base classes', '') //should be removed
@willdurand Owner

and so what?

@jaugustin Collaborator

done ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/Propel/Generator/Util/QuickBuilder.php
@@ -278,4 +278,17 @@ public function fixNamespaceDeclarations($source)
return $output;
}
+
+ /**
+ * prevent generated class without namespace to fail
+ * @param string $code
+ * @return string
+ */
+ protected function forceNamespace($code) {
@hhamon Collaborator
hhamon added a note

parenthesis must be on the following line

@jaugustin Collaborator

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/Propel/Runtime/Collection/Collection.php
@@ -47,6 +47,12 @@ class Collection extends ArrayObject implements Serializable
protected $model = '';
/**
+ * the fully qualified classname of the model
@hhamon Collaborator
hhamon added a note

the => The ^^

@jaugustin Collaborator

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@hhamon hhamon commented on the diff
src/Propel/Runtime/Map/DatabaseMap.php
((16 lines not shown))
$this->addTableFromMapClass($tmClass);
-
- return $this->tablesByPhpName[$phpName];
- } else {
- throw new TableNotFoundException("Cannot fetch TableMap for undefined table phpName: $phpName");
+ if (array_key_exists($phpName, $this->tablesByPhpName)) {
+ return $this->tablesByPhpName[$phpName];
+ }
+ $phpName = '\\'.$phpName;
+ if (array_key_exists($phpName, $this->tablesByPhpName)) {
@hhamon Collaborator
hhamon added a note

if (isset($this->tablesByPhpName[$phpName])) { would be a bit faster than array_key_exists

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@hhamon hhamon commented on the diff
src/Propel/Runtime/Query/ModelCriteria.php
@@ -99,7 +99,12 @@ public function __construct($dbName = null, $modelName = null, $modelAlias = nul
{
$this->setDbName($dbName);
$this->originalDbName = $dbName;
- $this->modelName = $modelName;
+ if (0 === strpos($modelName, '\\')) {
+ $this->modelName = substr($modelName, 1);
@hhamon Collaborator
hhamon added a note

Maybe you may use a ternary operator here

@willdurand Owner

no need here. readability over all :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@hhamon hhamon commented on the diff
src/Propel/Runtime/Query/ModelWith.php
@@ -71,7 +71,11 @@ public function init(ModelJoin $join)
public function setModelName($modelName)
{
- $this->modelName = $modelName;
+ if (0 === strpos($modelName, '\\')) {
+ $this->modelName = substr($modelName, 1);
@hhamon Collaborator
hhamon added a note

ternary operator instead here?

@willdurand Owner

no need here. readability over all :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@jaugustin jaugustin commented on the diff
src/Propel/Generator/Builder/Om/AbstractPeerBuilder.php
@@ -279,7 +279,7 @@ static public function getColumnName(Column $col, $phpName = null)
}
if (null !== $phpName) {
- return sprintf('%sPeer::$s', $phpName, $const);
+ return sprintf('static::$s', $const);
@jaugustin Collaborator

I change this but I don't think the old code was good : $const could never be used
@fzaninotto @willdurand
maybe this code is dead ?

@jaugustin Collaborator

this is definitely dead code, used for compatibility but the function is never called

@willdurand Owner

remove it.

@jaugustin Collaborator

maybe it's only the phpName option never used ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@willdurand
Owner

@hhamon if you can run your quality checkers, I'll be glad to merge your fixes :)

...pel/Generator/Builder/Om/MultiExtendObjectBuilder.php
@@ -33,7 +33,7 @@ class MultiExtendObjectBuilder extends AbstractObjectBuilder
*/
public function getUnprefixedClassname()
{
- return $this->getChild()->getClassname();
+ return $this->getChild()->getClassName();
@jaugustin Collaborator

maybe getClassName of Propel\Generator\Model\Inheritance could be renamed to getClassname ?

Do we want to normalize Classname vs ClassName (maybe another issue for that)

@willdurand Owner

ClassName everywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/Propel/Generator/Builder/Om/ObjectBuilder.php
@@ -3448,9 +3452,11 @@ protected function addRefFKAdd(&$script, ForeignKey $refFK)
$joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable());
$className = $joinedTableObjectBuilder->getObjectClassname();
+ /* FIXME : use the right methode to get the base Classes
@jaugustin Collaborator

Oups I don't remember this

@jaugustin Collaborator

fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/Propel/Generator/Builder/Om/ObjectBuilder.php
((5 lines not shown))
$tblFK = $refFK->getTable();
$foreignObjectName = '$' . $tblFK->getStudlyPhpName();
$script .= "
/**
+ * {$this->getRefFKPhpNameAffix($crossFK, false)} != {$this->getFKPhpNameAffix($crossFK, false)}
@jaugustin Collaborator

oups! this seems to be a debug comment :wink:

@jaugustin Collaborator

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/Propel/Generator/Builder/Om/QueryBuilder.php
@@ -38,8 +38,10 @@ public function getNamespace()
if ($this->getGeneratorConfig() && $omns = $this->getGeneratorConfig()->getBuildProperty('namespaceOm')) {
@jaugustin Collaborator

Maybe this could be remove because we force Base as a subdirectory the configuration is not necessary and I am not sure that it could work with a different parametter

@willdurand Owner

good to remove

@jaugustin Collaborator

removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/Propel/Generator/Builder/Om/QueryBuilder.php
((6 lines not shown))
if ($namespace = $fkQueryBuilder->getNamespace()) {
- $queryClass = '\\' . $namespace . '\\' . $queryClass;
+ $queryClass = '\\' . $queryClass;
@jaugustin Collaborator

I think the "\\" is not needed because $queryClass is already a FQCN

@jaugustin Collaborator

removed useless code (the if block) :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/Propel/Generator/Builder/Om/QueryBuilder.php
((6 lines not shown))
if ($namespace = $fkQueryBuilder->getNamespace()) {
- $queryClass = '\\' . $namespace . '\\' . $queryClass;
+ $queryClass = '\\' . $queryClass;
@jaugustin Collaborator

the same here :
I think the "\" is not needed because $queryClass is already a FQCN

@willdurand Owner

you comment about your own stuffs, you're magic :p

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/Propel/Generator/Util/QuickBuilder.php
@@ -201,7 +198,9 @@ public function getClassesForTable(Table $table, array $classTargets = null)
if ($table->getInterface()) {
$interface = $this->getConfig()->getConfiguredBuilder('interface', $target)->build();
- $interface = "\nnamespace\n{\n" . $interface . "\n}\n";
+ if (false === strpos($class, 'namespace')) {
@jaugustin Collaborator

is it necessary or is is it double with the fixNamespaceDeclarations() ?

@jaugustin Collaborator

removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
tools/generator/default.properties
@@ -87,7 +87,7 @@ propel.addSaveMethod = true
propel.addTimeStamp = false
propel.addValidateMethod = true
propel.addHooks = true
-propel.basePrefix = Base
+propel.basePrefix =
@jaugustin Collaborator

totally remove this ?

@willdurand Owner

agreed

@willdurand Owner

btw, I'm not sure this default.properties file is style needed.. I'll clean the project later. But yes, remove this parameter.

@jaugustin Collaborator

removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
...r/ConcreteInheritance/ConcreteInheritanceBehavior.php
@@ -136,22 +136,13 @@ public function parentClass($builder)
$parentTable = $this->getParentTable();
switch (get_class($builder)) {
case 'Propel\Generator\Builder\Om\ObjectBuilder':
- $objectBuilder = $builder->getNewStubObjectBuilder($parentTable);
- $builder->declareClass($objectBuilder->getFullyQualifiedClassname());
-
- return $objectBuilder->getClassname();
+ return $builder->declareClassFromBuilder($builder->getNewStubObjectBuilder($parentTable), true);
break;
@stof
stof added a note

break is useless as there is a return statement above

@jaugustin Collaborator

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/Propel/Generator/Builder/Om/AbstractOMBuilder.php
((5 lines not shown))
* @var array
*/
protected $declaredClasses = array();
/**
+ * Mapping bettwen fully qualified classnames and their short classname or alias
@stof
stof added a note

typo here

@jaugustin Collaborator

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/Propel/Generator/Builder/Om/AbstractOMBuilder.php
((42 lines not shown))
* @return string
*/
public function getFullyQualifiedClassname()
{
+ return '\\' . $this->getQualifiedClassname();
if ($namespace = $this->getNamespace()) {
@stof
stof added a note

you can remove all this dead code as the method returns above

@jaugustin Collaborator

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/Propel/Generator/Builder/Om/AbstractOMBuilder.php
((22 lines not shown))
}
/**
- * Returns the namespaced classname if there is a namespace, and the raw classname otherwise
+ * Returns the qualified classname (e.g. Model\Book)
+ *
+ * @return string
+ */
+ public function getQualifiedClassname()
+ {
+ if ($namespace = $this->getNamespace()) {
+ return $namespace . '\\' . $this->getUnqualifiedClassname();
+ } else {
@stof
stof added a note

does Propel follow the same rule than Symfony2 regarding not using else when not needed ? I don't remember what the agreement was when we discussed the coding standards months ago

@stof
stof added a note

Btw, I saw many other places where such a comment could have been applied

@jaugustin Collaborator

done for this file, but it should be done for all the lib

@willdurand Owner

yep, I know..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@jaugustin
Collaborator

if everyone is ok with the code :) I think this could be merge

@willdurand willdurand merged commit 8a65452 into from
@willdurand
Owner

Merged!

@hhamon hhamon referenced this pull request from a commit in hhamon/Propel2
@fzaninotto fzaninotto Fix archivable behavior when used with unique index.
If a table has unique columns, the resulting archive table has set
UNIQUE indices on these columns.

While this seems like a good idea at the first glance, it's a bug
because you can't delete two records which share the same value in this
colum.

This patch fixes the issue by copying unique indices to indices on the
archive table.

Closes #175.
9080b45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 14, 2012
  1. @jaugustin
  2. @jaugustin
  3. @jaugustin
  4. @jaugustin
  5. @jaugustin
  6. @jaugustin
  7. @jaugustin

    [Generator][QuickBuilder] fix Base prefix for non-namespaced class, f…

    jaugustin authored
    …ix auto namespace in quickbuilder
  8. @jaugustin
  9. @jaugustin
  10. @jaugustin
  11. @jaugustin
  12. @jaugustin

    [WIP]fedex day: om rename to Base

    jaugustin authored jaugustin committed
  13. @jaugustin
  14. @jaugustin
  15. @willdurand @jaugustin
  16. @jaugustin
  17. @jaugustin

    [Runtime][ModelCriteria] fix test, handle FQCN or QCN has Model input

    jaugustin authored
    [Runtime][ModelWith] fix test, handle FQCN or QCN has Model input
  18. @jaugustin

    [Runtime][Map] fix getTableMap when class doesn't have namespace

    jaugustin authored
    [Runtime][Query] fix join to use FQCN or QCN => force QCN
  19. @jaugustin
  20. @jaugustin

    [Generator][Behavior] fix AggregateColumn, wrong classname with names…

    jaugustin authored
    …apce, remove lcfirst hack for php 5.2
  21. @jaugustin

    [Generator][Behavior] fix build ConcreteInheritanceBehavior, setParen…

    jaugustin authored
    …tClass set QCN instead of FQCN
  22. @jaugustin
  23. @willdurand @jaugustin

    Updated gitignore

    willdurand authored jaugustin committed
    Removed composer.lock
  24. @willdurand @jaugustin

    [Generator] Fixed CS

    willdurand authored jaugustin committed
  25. @jaugustin

    [Generator][I18n] fix generate wrong query filterBy

    jaugustin authored
    [Generator][Builder] fix generate class without namespace, add whitelist
    class (PDO, Exception, DateTime
    remove unecessary use statement DateTimeZone
  26. @jaugustin
  27. @jaugustin

    [Generator][Builder] fix issue with non namespaced Model, fix namespa…

    jaugustin authored
    …ce of QueryInheritance force Base when needed, the end of #35
  28. @willdurand
  29. @willdurand
  30. @jaugustin
  31. @jaugustin
  32. @jaugustin
Commits on Apr 15, 2012
  1. @jaugustin
  2. @jaugustin

    CS remove useless break

    jaugustin authored
  3. @jaugustin
  4. @jaugustin

    remove useless code ;)

    jaugustin authored
  5. @jaugustin

    Update UPDATE.md

    jaugustin authored
  6. @willdurand
Something went wrong with that request. Please try again.