From 54476882c7045e39dc309f383945af5508d552ce Mon Sep 17 00:00:00 2001 From: Christian Heinrich Date: Tue, 6 Jul 2010 17:06:31 +0200 Subject: [PATCH 1/2] CLI configured for development purposes --- tools/sandbox/cli-config.php | 61 ++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/tools/sandbox/cli-config.php b/tools/sandbox/cli-config.php index c949668e0..8e503e234 100644 --- a/tools/sandbox/cli-config.php +++ b/tools/sandbox/cli-config.php @@ -1,36 +1,63 @@ register(); -$classLoader = new \Doctrine\Common\ClassLoader('Doctrine\DBAL', realpath(__DIR__ . '/../../lib/vendor/doctrine-dbal/lib')); -$classLoader->register(); -$classLoader = new \Doctrine\Common\ClassLoader('Doctrine\Common', realpath(__DIR__ . '/../../lib/vendor/doctrine-common/lib')); -$classLoader->register(); -$classLoader = new \Doctrine\Common\ClassLoader('Symfony', realpath(__DIR__ . '/../../lib/vendor')); -$classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader('Entities', __DIR__); $classLoader->register(); + $classLoader = new \Doctrine\Common\ClassLoader('Proxies', __DIR__); $classLoader->register(); +require_once '/var/workspaces/nexxone/library/Zend/Acl/Resource/Interface.php'; +require_once '/var/workspaces/nexxone/library/Zend/Acl/Role/Interface.php'; + +$classLoader = new \Doctrine\Common\ClassLoader('Core\Model', '/var/workspaces/nexxone/application/modules/core/models/'); +$classLoader->register(); + +$classLoader = new \Doctrine\Common\ClassLoader('Content\Model', '/var/workspaces/nexxone/application/modules/content/models/'); +$classLoader->register(); + +$classLoader = new \Doctrine\Common\ClassLoader('User\Model', '/var/workspaces/nexxone/application/modules/user/models/'); +$classLoader->register(); + + $config = new \Doctrine\ORM\Configuration(); $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache); -$driverImpl = $config->newDefaultAnnotationDriver(array(__DIR__."/Entities")); -$config->setMetadataDriverImpl($driverImpl); $config->setProxyDir(__DIR__ . '/Proxies'); -$config->setProxyNamespace('Proxies'); -$connectionOptions = array( - 'driver' => 'pdo_sqlite', - 'path' => 'database.sqlite' +$config->setProxyNamespace('LivandoCMSProxies'); +$driver = new Doctrine\ORM\Mapping\Driver\YamlDriver( + array( + '/var/workspaces/nexxone/application/modules/core/config/schema', + '/var/workspaces/nexxone/application/modules/content/config/schema', + '/var/workspaces/nexxone/application/modules/user/config/schema', + ) ); +#$driver = new Doctrine\ORM\Mapping\Driver\YamlDriver(array('./yaml/'), YamlDriver::PRELOAD); +$config->setMetadataDriverImpl($driver); -$em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config); +$conn = new \Doctrine\DBAL\Connection( + array ( + 'pdo' => new PDO( + "mysql:host=localhost;dbname=nexxone;unix_socket=/var/run/mysqld/mysqld.sock", + 'root', + 'mysql5023' + ) + ), + new Doctrine\DBAL\Driver\PDOMySql\Driver(), + $config + ); + +//$connectionOptions = array( +// 'driver' => 'pdo_sqlite', +// 'path' => 'database.sqlite' +//); + +// These are required named variables (names can't change!) +$em = \Doctrine\ORM\EntityManager::create($conn, $config); $helpers = array( 'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()), 'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em) -); \ No newline at end of file +); From 9b03a1ecdde5b58fc63469016929637511c9eaca Mon Sep 17 00:00:00 2001 From: Christian Heinrich Date: Tue, 6 Jul 2010 20:19:43 +0200 Subject: [PATCH 2/2] Added testcase for #DDC-671 --- .../ORM/Mapping/YamlMappingDriverTest.php | 68 ++++++++++++++++++- ...ts.ORM.Mapping.AbstractContentItem.dcm.yml | 17 +++++ ...ctrine.Tests.ORM.Mapping.Directory.dcm.yml | 17 +++++ .../Doctrine.Tests.ORM.Mapping.Page.dcm.yml | 7 ++ 4 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.AbstractContentItem.dcm.yml create mode 100644 tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Directory.dcm.yml create mode 100644 tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Page.dcm.yml diff --git a/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php index 2aad38645..741621aa9 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php @@ -18,4 +18,70 @@ class YamlMappingDriverTest extends AbstractMappingDriverTest return new YamlDriver(__DIR__ . DIRECTORY_SEPARATOR . 'yaml'); } -} \ No newline at end of file + public function testJoinTablesWithMappedSuperclassForYamlDriver() { + $em = $this->_getTestEntityManager(); + $em->getConfiguration()->setMetadataDriverImpl(new \Doctrine\ORM\Mapping\Driver\YamlDriver(__DIR__ .'/yaml/')); + $qb = $em->createQueryBuilder(); + + $qb->select('f') + ->from('Doctrine\Tests\ORM\Mapping\Page', 'f') + ->join('f.parentDirectory', 'd') + ->where( + $qb->expr()->andx( + $qb->expr()->eq('d.url', ':url'), + $qb->expr()->eq('f.extension', ':extension') + ) + ) + ->setParameter('url', "test") + ->setParameter('filename', "filename") + ->setParameter('extension', "extension"); + + // Is there a way to generalize this more? (Instead of a2_., check if the table prefix in the ON clause is set within a FROM or JOIN clause..) + $this->assertTrue(strpos($qb->getQuery()->getSql(), 'a2_.') === false); + } +} + +class Directory extends AbstractContentItem { + + protected $subDirectories; + + /** + * This is a collection of files that are contained in this Directory. Files, for example, could be Pages, but even other files + * like media files (css, images etc) are possible. + * + * @var \Doctrine\Common\Collections\Collection + * @access protected + */ + protected $containedFiles; + + /** + * @var string + */ + protected $url; +} + +class Page + extends AbstractContentItem { + + protected $extension = "html"; +} + +abstract class AbstractContentItem { + /** + * Doctrine2 entity id + * @var integer + */ + private $id; + + /** + * The parent directory + * @var Directory + */ + protected $parentDirectory; + + /** + * Filename (without extension) or directory name + * @var string + */ + protected $name; +} diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.AbstractContentItem.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.AbstractContentItem.dcm.yml new file mode 100644 index 000000000..419eb0449 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.AbstractContentItem.dcm.yml @@ -0,0 +1,17 @@ +Doctrine\Tests\ORM\Mapping\AbstractContentItem: + type: mappedSuperclass + table: abstract_item + id: + id: + type: integer + unsigned: true + generator: + strategy: AUTO + fields: + # FilesystemIdentifier + manyToOne: + parentDirectory: + targetEntity: Doctrine\Tests\ORM\Mapping\Directory + joinColumn: + name: parent_directory_id + referencedColumnName: id diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Directory.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Directory.dcm.yml new file mode 100644 index 000000000..129ae6b28 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Directory.dcm.yml @@ -0,0 +1,17 @@ +Doctrine\Tests\ORM\Mapping\Directory: + type: entity + table: core_content_directories + fields: + url: + type: string + length: 255 + oneToMany: + subDirectories: + targetEntity: Doctrine\Tests\ORM\Mapping\Directory + mappedBy: parentDirectory + cascade: + [ all ] + containedFiles: + targetEntity: Doctrine\Tests\ORM\Mapping\Page + mappedBy: parentDirectory + cascade: [ remove ] diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Page.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Page.dcm.yml new file mode 100644 index 000000000..a3b0fb836 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Page.dcm.yml @@ -0,0 +1,7 @@ +Doctrine\Tests\ORM\Mapping\Page: + type: entity + table: core_content_pages + fields: + extension: + type: string + length: 10