From db46ba6d7b16380729172a7e0d98912d33785a59 Mon Sep 17 00:00:00 2001 From: Robert Gruber Date: Wed, 2 Nov 2016 18:45:17 +0100 Subject: [PATCH] Avoid call to MongoDBs deprecated eval Document databases are created automatically. No manual call is required. This avoids calls to MongoDBs deprecated `eval`. When using the `schema:create`-command at deploy time this will avoid MongoDB startup warnings like ``` "2016-10-21T14:05:35.870+0000 W COMMAND [conn581654] the eval command is deprecated" ``` --- lib/Doctrine/ODM/MongoDB/SchemaManager.php | 17 ++++++----------- .../Console/Command/Schema/CreateCommand.php | 4 ++-- .../ODM/MongoDB/Tests/SchemaManagerTest.php | 13 ------------- 3 files changed, 8 insertions(+), 26 deletions(-) diff --git a/lib/Doctrine/ODM/MongoDB/SchemaManager.php b/lib/Doctrine/ODM/MongoDB/SchemaManager.php index f1d9bf386e..6b44bffd59 100644 --- a/lib/Doctrine/ODM/MongoDB/SchemaManager.php +++ b/lib/Doctrine/ODM/MongoDB/SchemaManager.php @@ -405,15 +405,12 @@ public function dropDocumentDatabase($documentName) /** * Create all the mapped document databases in the metadata factory. + * + * @deprecated document databases must not be created, databases are created automatically */ public function createDatabases() { - foreach ($this->metadataFactory->getAllMetadata() as $class) { - if ($class->isMappedSuperclass || $class->isEmbeddedDocument) { - continue; - } - $this->createDocumentDatabase($class->name); - } + return; } /** @@ -421,14 +418,12 @@ public function createDatabases() * * @param string $documentName * @throws \InvalidArgumentException + * + * @deprecated document databases must not be created, databases are created automatically */ public function createDocumentDatabase($documentName) { - $class = $this->dm->getClassMetadata($documentName); - if ($class->isMappedSuperclass || $class->isEmbeddedDocument) { - throw new \InvalidArgumentException('Cannot delete document indexes for mapped super classes or embedded documents.'); - } - $this->dm->getDocumentDatabase($documentName)->execute('function() { return true; }'); + return; } /** diff --git a/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/Schema/CreateCommand.php b/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/Schema/CreateCommand.php index fa458496c0..d3d5ed9c0a 100644 --- a/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/Schema/CreateCommand.php +++ b/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/Schema/CreateCommand.php @@ -96,12 +96,12 @@ protected function processCollection(SchemaManager $sm) protected function processDocumentDb(SchemaManager $sm, $document) { - $sm->createDocumentDatabase($document); + return; } protected function processDb(SchemaManager $sm) { - $sm->createDatabases(); + return; } protected function processDocumentIndex(SchemaManager $sm, $document) diff --git a/tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php b/tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php index 0a022a9364..db9c845ca3 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php @@ -253,19 +253,6 @@ public function testDropDocumentCollection() $this->schemaManager->dropDocumentCollection(\Documents\CmsArticle::class); } - public function testCreateDocumentDatabase() - { - foreach ($this->documentDatabases as $class => $database) { - if ($class === \Documents\CmsArticle::class) { - $database->expects($this->once())->method('execute'); - } else { - $database->expects($this->never())->method('execute'); - } - } - - $this->schemaManager->createDocumentDatabase(\Documents\CmsArticle::class); - } - public function testDropDocumentDatabase() { foreach ($this->documentDatabases as $class => $database) {