From cc2fb1a07065eb51cff7b1b8e43d9dd2cbd2ccc7 Mon Sep 17 00:00:00 2001 From: Adrian Olek Date: Thu, 6 Mar 2014 23:09:26 +0100 Subject: [PATCH 1/6] Added index flags support in annotation, xml & yaml mapping drivers. --- doctrine-mapping.xsd | 1 + .../ORM/Mapping/Driver/AnnotationDriver.php | 5 ++++- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 14 +++++++++++--- lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php | 13 ++++++++++++- lib/Doctrine/ORM/Mapping/Index.php | 5 +++++ lib/Doctrine/ORM/Tools/SchemaTool.php | 7 ++++++- 6 files changed, 39 insertions(+), 6 deletions(-) diff --git a/doctrine-mapping.xsd b/doctrine-mapping.xsd index b6728f0de..f7364b7f7 100644 --- a/doctrine-mapping.xsd +++ b/doctrine-mapping.xsd @@ -341,6 +341,7 @@ + diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index e127d8372..09479b77e 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -101,7 +101,10 @@ class AnnotationDriver extends AbstractAnnotationDriver if ($tableAnnot->indexes !== null) { foreach ($tableAnnot->indexes as $indexAnnot) { - $index = array('columns' => $indexAnnot->columns); + $index = array( + 'columns' => $indexAnnot->columns, + 'flags' => $indexAnnot->flags + ); if ( ! empty($indexAnnot->name)) { $primaryTable['indexes'][$indexAnnot->name] = $index; diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 3d867e1c5..c81c083e1 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -196,14 +196,22 @@ class XmlDriver extends FileDriver $metadata->table['indexes'] = array(); foreach ($xmlRoot->indexes->index as $index) { $columns = explode(',', (string)$index['columns']); - + + if(!isset($index['flags'])) { + $flags = array(); + } else { + $flags = explode(',', (string)$index['flags']); + } + if (isset($index['name'])) { $metadata->table['indexes'][(string)$index['name']] = array( - 'columns' => $columns + 'columns' => $columns, + 'flags' => $flags ); } else { $metadata->table['indexes'][] = array( - 'columns' => $columns + 'columns' => $columns, + 'flags' => $flags ); } } diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index 48aa7021b..6e3342902 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -213,8 +213,19 @@ class YamlDriver extends FileDriver $columns = $index['columns']; } + if(!isset($index['flags'])) + { + $flags = array(); + } elseif (is_string($index['flags'])) { + $flags = explode(',', $index['flags']); + $flags = array_map('trim', $flags); + } else { + $flags = $index['flags']; + } + $metadata->table['indexes'][$index['name']] = array( - 'columns' => $columns + 'columns' => $columns, + 'flags' => $flags ); } } diff --git a/lib/Doctrine/ORM/Mapping/Index.php b/lib/Doctrine/ORM/Mapping/Index.php index a6696c4b6..ff4532d47 100644 --- a/lib/Doctrine/ORM/Mapping/Index.php +++ b/lib/Doctrine/ORM/Mapping/Index.php @@ -34,4 +34,9 @@ final class Index implements Annotation * @var array */ public $columns; + + /** + * @var array + */ + public $flags; } diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index ad8b84f68..abad1013a 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -264,7 +264,12 @@ class SchemaTool if (isset($class->table['indexes'])) { foreach ($class->table['indexes'] as $indexName => $indexData) { - $table->addIndex($indexData['columns'], is_numeric($indexName) ? null : $indexName); + if(!isset($indexData['flags'])) + { + $indexData['flags'] = array(); + } + + $table->addIndex($indexData['columns'], is_numeric($indexName) ? null : $indexName, (array) $indexData['flags']); } } From b3a2988d2cdd64392fd1f40d5a15d8c3e461e8bf Mon Sep 17 00:00:00 2001 From: Adrian Olek Date: Thu, 6 Mar 2014 23:54:41 +0100 Subject: [PATCH 2/6] CS fixes --- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 2 +- lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php | 3 +-- lib/Doctrine/ORM/Tools/SchemaTool.php | 5 ++--- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index c81c083e1..5bb1e7b51 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -197,7 +197,7 @@ class XmlDriver extends FileDriver foreach ($xmlRoot->indexes->index as $index) { $columns = explode(',', (string)$index['columns']); - if(!isset($index['flags'])) { + if( ! isset($index['flags'])) { $flags = array(); } else { $flags = explode(',', (string)$index['flags']); diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index 6e3342902..d0e52c718 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -213,8 +213,7 @@ class YamlDriver extends FileDriver $columns = $index['columns']; } - if(!isset($index['flags'])) - { + if( ! isset($index['flags'])) { $flags = array(); } elseif (is_string($index['flags'])) { $flags = explode(',', $index['flags']); diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index abad1013a..9bca3ed66 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -264,12 +264,11 @@ class SchemaTool if (isset($class->table['indexes'])) { foreach ($class->table['indexes'] as $indexName => $indexData) { - if(!isset($indexData['flags'])) - { + if( ! isset($indexData['flags'])) { $indexData['flags'] = array(); } - $table->addIndex($indexData['columns'], is_numeric($indexName) ? null : $indexName, (array) $indexData['flags']); + $table->addIndex($indexData['columns'], is_numeric($indexName) ? null : $indexName, (array)$indexData['flags']); } } From 32ed32cf5652774e21138e4054de7899c3b4c464 Mon Sep 17 00:00:00 2001 From: Adrian Olek Date: Sat, 8 Mar 2014 00:22:35 +0100 Subject: [PATCH 3/6] Added index flags test --- .../ORM/Mapping/Driver/AnnotationDriver.php | 5 ++- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 26 ++++++------- .../ORM/Mapping/Driver/YamlDriver.php | 39 ++++++++++--------- .../ORM/Mapping/AbstractMappingDriverTest.php | 24 ++++++++++++ .../Doctrine.Tests.ORM.Mapping.Comment.php | 22 +++++++++++ ...Doctrine.Tests.ORM.Mapping.Comment.dcm.xml | 18 +++++++++ ...Doctrine.Tests.ORM.Mapping.Comment.dcm.yml | 9 +++++ 7 files changed, 108 insertions(+), 35 deletions(-) create mode 100644 tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Comment.php create mode 100644 tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Comment.dcm.xml create mode 100644 tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Comment.dcm.yml diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index 09479b77e..4156318ae 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -103,8 +103,11 @@ class AnnotationDriver extends AbstractAnnotationDriver foreach ($tableAnnot->indexes as $indexAnnot) { $index = array( 'columns' => $indexAnnot->columns, - 'flags' => $indexAnnot->flags ); + + if( ! empty($indexAnnot->flags)) { + $index['flags'] = $indexAnnot->flags; + } if ( ! empty($indexAnnot->name)) { $primaryTable['indexes'][$indexAnnot->name] = $index; diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 5bb1e7b51..6a38045cd 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -194,25 +194,21 @@ class XmlDriver extends FileDriver // Evaluate if (isset($xmlRoot->indexes)) { $metadata->table['indexes'] = array(); - foreach ($xmlRoot->indexes->index as $index) { - $columns = explode(',', (string)$index['columns']); + foreach ($xmlRoot->indexes->index as $indexXml) { + $columns = explode(',', (string)$indexXml['columns']); - if( ! isset($index['flags'])) { - $flags = array(); - } else { - $flags = explode(',', (string)$index['flags']); + $index = array( + 'columns' => $columns + ); + + if( isset($indexXml['flags'])) { + $index['flags'] = explode(',', (string)$indexXml['flags']); } - if (isset($index['name'])) { - $metadata->table['indexes'][(string)$index['name']] = array( - 'columns' => $columns, - 'flags' => $flags - ); + if (isset($indexXml['name'])) { + $metadata->table['indexes'][(string)$indexXml['name']] = $index; } else { - $metadata->table['indexes'][] = array( - 'columns' => $columns, - 'flags' => $flags - ); + $metadata->table['indexes'][] = $index; } } } diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index d0e52c718..2b8a2ce1c 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -201,31 +201,32 @@ class YamlDriver extends FileDriver // Evaluate indexes if (isset($element['indexes'])) { - foreach ($element['indexes'] as $name => $index) { - if ( ! isset($index['name'])) { - $index['name'] = $name; + foreach ($element['indexes'] as $name => $indexYml) { + if ( ! isset($indexYml['name'])) { + $indexYml['name'] = $name; } - if (is_string($index['columns'])) { - $columns = explode(',', $index['columns']); + if (is_string($indexYml['columns'])) { + $columns = explode(',', $indexYml['columns']); $columns = array_map('trim', $columns); } else { - $columns = $index['columns']; + $columns = $indexYml['columns']; } - - if( ! isset($index['flags'])) { - $flags = array(); - } elseif (is_string($index['flags'])) { - $flags = explode(',', $index['flags']); - $flags = array_map('trim', $flags); - } else { - $flags = $index['flags']; - } - - $metadata->table['indexes'][$index['name']] = array( - 'columns' => $columns, - 'flags' => $flags + + $index = array( + 'columns' => $columns ); + + if(isset($indexYml['flags'])) { + if (is_string($indexYml['flags'])) { + $flags = explode(',', $indexYml['flags']); + $index['flags'] = array_map('trim', $flags); + } else { + $index['flags'] = $indexYml['flags']; + } + } + + $metadata->table['indexes'][$indexYml['name']] = $index; } } diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index 49e387e5d..129f7c611 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -73,6 +73,18 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase return $class; } + public function testEntityIndexFlags() + { + $class = $this->createClassMetadata('Doctrine\Tests\ORM\Mapping\Comment'); + + $this->assertEquals(array( + 0 => array( + 'columns' => array('content'), + 'flags' => array('fulltext') + ) + ), $class->table['indexes']); + } + /** * @depends testEntityTableNameAndInheritance * @param ClassMetadata $class @@ -1266,3 +1278,15 @@ class DDC807SubClasse2 {} class Address {} class Phonenumber {} class Group {} + +/** + * @Entity + * @Table(indexes={@Index(columns={"content"}, flags={"fulltext"})}) + */ +class Comment +{ + /** + * @Column(type="text") + */ + private $content; +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Comment.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Comment.php new file mode 100644 index 000000000..a520e0cb1 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Comment.php @@ -0,0 +1,22 @@ +setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE); +$metadata->setPrimaryTable(array( + 'indexes' => array( + array('columns' => array('content'), 'flags' => array('fulltext')) + ) + )); + + +$metadata->mapField(array( + 'fieldName' => 'content', + 'type' => 'text', + 'scale' => 0, + 'length' => NULL, + 'unique' => false, + 'nullable' => false, + 'precision' => 0, + 'columnName' => 'content', +)); \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Comment.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Comment.dcm.xml new file mode 100644 index 000000000..659ddccd8 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Comment.dcm.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Comment.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Comment.dcm.yml new file mode 100644 index 000000000..2186f6a27 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Comment.dcm.yml @@ -0,0 +1,9 @@ +Doctrine\Tests\ORM\Mapping\Comment: + type: entity + fields: + content: + type: text + indexes: + 0: + columns: content + flags: fulltext From 72bb16173a2881a872ff72f9cf7c67e693ff0e62 Mon Sep 17 00:00:00 2001 From: Adrian Olek Date: Sat, 8 Mar 2014 00:52:31 +0100 Subject: [PATCH 4/6] Added Comment entity mapping for StaticPHPDriver test --- .../ORM/Mapping/AbstractMappingDriverTest.php | 21 +++++++++++++++++++ .../Doctrine.Tests.ORM.Mapping.Comment.php | 1 - 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index 129f7c611..7a22dc1da 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -1289,4 +1289,25 @@ class Comment * @Column(type="text") */ private $content; + + public static function loadMetadata(ClassMetadataInfo $metadata) + { + $metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE); + $metadata->setPrimaryTable(array( + 'indexes' => array( + array('columns' => array('content'), 'flags' => array('fulltext')) + ) + )); + + $metadata->mapField(array( + 'fieldName' => 'content', + 'type' => 'text', + 'scale' => 0, + 'length' => NULL, + 'unique' => false, + 'nullable' => false, + 'precision' => 0, + 'columnName' => 'content', + )); + } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Comment.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Comment.php index a520e0cb1..124aafe1d 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Comment.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Comment.php @@ -9,7 +9,6 @@ $metadata->setPrimaryTable(array( ) )); - $metadata->mapField(array( 'fieldName' => 'content', 'type' => 'text', From eccd8f85bc8abb568b94c591c7c936a9a0e49f57 Mon Sep 17 00:00:00 2001 From: Adrian Olek Date: Sun, 13 Apr 2014 23:45:42 +0200 Subject: [PATCH 5/6] cs fixes --- lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php | 2 +- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index 4156318ae..fbd818d2b 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -105,7 +105,7 @@ class AnnotationDriver extends AbstractAnnotationDriver 'columns' => $indexAnnot->columns, ); - if( ! empty($indexAnnot->flags)) { + if ( ! empty($indexAnnot->flags)) { $index['flags'] = $indexAnnot->flags; } diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 6a38045cd..a66531e3c 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -201,7 +201,7 @@ class XmlDriver extends FileDriver 'columns' => $columns ); - if( isset($indexXml['flags'])) { + if (isset($indexXml['flags'])) { $index['flags'] = explode(',', (string)$indexXml['flags']); } From a87d3e080e7f4d391b338ee27d4e73aee15b3c45 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Mon, 14 Apr 2014 01:19:32 +0200 Subject: [PATCH 6/6] Minor CS fixes on top of #973 --- .../ORM/Mapping/Driver/AnnotationDriver.php | 4 +--- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 10 +++------- lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php | 14 ++++---------- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index fbd818d2b..3f46e2c95 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -101,9 +101,7 @@ class AnnotationDriver extends AbstractAnnotationDriver if ($tableAnnot->indexes !== null) { foreach ($tableAnnot->indexes as $indexAnnot) { - $index = array( - 'columns' => $indexAnnot->columns, - ); + $index = array('columns' => $indexAnnot->columns); if ( ! empty($indexAnnot->flags)) { $index['flags'] = $indexAnnot->flags; diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index a66531e3c..e08ee7ae6 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -195,18 +195,14 @@ class XmlDriver extends FileDriver if (isset($xmlRoot->indexes)) { $metadata->table['indexes'] = array(); foreach ($xmlRoot->indexes->index as $indexXml) { - $columns = explode(',', (string)$indexXml['columns']); - - $index = array( - 'columns' => $columns - ); + $index = array('columns' => explode(',', (string) $indexXml['columns'])); if (isset($indexXml['flags'])) { - $index['flags'] = explode(',', (string)$indexXml['flags']); + $index['flags'] = explode(',', (string) $indexXml['flags']); } if (isset($indexXml['name'])) { - $metadata->table['indexes'][(string)$indexXml['name']] = $index; + $metadata->table['indexes'][(string) $indexXml['name']] = $index; } else { $metadata->table['indexes'][] = $index; } diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index 2b8a2ce1c..2772913cc 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -207,20 +207,14 @@ class YamlDriver extends FileDriver } if (is_string($indexYml['columns'])) { - $columns = explode(',', $indexYml['columns']); - $columns = array_map('trim', $columns); + $index = array('columns' => array_map('trim', explode(',', $indexYml['columns']))); } else { - $columns = $indexYml['columns']; + $index = array('columns' => $indexYml['columns']); } - - $index = array( - 'columns' => $columns - ); - if(isset($indexYml['flags'])) { + if (isset($indexYml['flags'])) { if (is_string($indexYml['flags'])) { - $flags = explode(',', $indexYml['flags']); - $index['flags'] = array_map('trim', $flags); + $index['flags'] = array_map('trim', explode(',', $indexYml['flags'])); } else { $index['flags'] = $indexYml['flags']; }