Skip to content

Commit

Permalink
Avoid call to MongoDBs deprecated eval
Browse files Browse the repository at this point in the history
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"
```
  • Loading branch information
Robert Gruber committed Nov 4, 2016
1 parent 0f001ae commit db46ba6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 26 deletions.
17 changes: 6 additions & 11 deletions lib/Doctrine/ODM/MongoDB/SchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,30 +405,25 @@ 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;
}

/**
* Create the document database for a mapped class.
*
* @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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 0 additions & 13 deletions tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit db46ba6

Please sign in to comment.