Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added MongoDB support #1

Merged
merged 13 commits into from Jan 27, 2017
Merged

Added MongoDB support #1

merged 13 commits into from Jan 27, 2017

Conversation

smilesrg
Copy link
Contributor

Added MongoDB support

@@ -22,10 +22,14 @@
"source": "https://github.com/portphp/doctrine",
"docs": "https://portphp.readthedocs.org"
},
"minimum-stability": "dev",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this kind of configuration should go to the bottom of the file: most people are rather interested in requirements than stability settings for development.

@sagikazarmark
Copy link
Contributor

@smilesrg Awesome work. 👍

Added a few comments though.

@ddeboer @Baachi thoughts?

"doctrine/orm": "~2.4"
"doctrine/orm": "~2.4",
"doctrine/mongodb": "dev-master",
"doctrine/mongodb-odm": "dev-master"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why these aggressive dependencies? @sagikazarmark And I think we should create a separate doctrine-mongo-adapter and move this there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the plan was to support object manager in one adapter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we decided that in portphp/portphp#13. However, that means the dependencies here need to be moved to require-dev.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you already mentioned that above.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then why do we need a separate mongo adapter?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You’re right, we don’t (as long as we move the deps to require-dev).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! 👍

@smilesrg
Copy link
Contributor Author

@sagikazarmark @ddeboer Please accept portphp/portphp#26

@sagikazarmark
Copy link
Contributor

See my comment on that PR

@smilesrg
Copy link
Contributor Author

@sagikazarmark
Copy link
Contributor

Not on PHP 5.4, but with lowest dependencies. One of the dependencies version must be higher.

You can try it:

$ composer update --prefer-lowest --prefer-stable

and run tests. Try moving the lowest dependency up.

@smilesrg
Copy link
Contributor Author

@sagikazarmark Done! :-)

@sagikazarmark
Copy link
Contributor

Great. Awaiting for response from @ddeboer

$query = $this->objectManager->createQuery(
sprintf('SELECT COUNT(o) FROM %s o', $this->objectName)
);
$query = $this->objectManager->createQueryBuilder()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you use the query builder here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For getting this method work for both Doctrine ORM and Doctrine MongoDB ODM.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay.

@@ -262,47 +287,50 @@ protected function disableLogging()
*/
protected function reEnableLogging()
{
$config = $this->entityManager->getConnection()->getConfiguration();
//TODO: do we need to add support for MongoDB logging?
if (!($this->objectManager instanceof \Doctrine\ORM\EntityManager)) return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should throw an exception if the odm is used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? If ODM is used, it will just do nothing. This is expected behaviour. Logger should be disabled/enabled only for EntityManager

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah i think this isn't expected. If i call an method and he does not throw any exception, i would expect that he works.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's your proposition then? If the ODM is used, this method shouldn't be called. Should I change the code this way?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would simply throw an Exception if the objectManager property isn't a Doctrine\ORM\EntityManager.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then this exception should be handled in the client code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly. If the user tries some illegal actions, an exception should be thrown.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively we could create a OdmReader and an OrmReader which extends a common class, so that specific features are only present when they are necessary. @smilesrg @Baachi what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a user tries to do illegal actions. The logger for SQL is disabled to speed up the write operations. Honesty, I don't know how to disable the logging for MongoDB. That's why this functionality is supported for Doctrine ORM only.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so this is an internal thing. Still, a separated class would simply solve this issue.

@Baachi
Copy link
Contributor

Baachi commented Jul 20, 2015

Hey Sergey,

i would really say thank you for your work. Really great PR 👍

I'm 👍 on this.

@smilesrg
Copy link
Contributor Author

Thanks, Baachi :-)

@sagikazarmark
Copy link
Contributor

I agree with @Baachi 👍

@ddeboer
Copy link
Member

ddeboer commented Aug 2, 2015

@smilesrg Looks great! can you please squash commits?

@smilesrg
Copy link
Contributor Author

smilesrg commented Aug 3, 2015

@ddeboer done

@smilesrg
Copy link
Contributor Author

@ddeboer any news on acception this PR?

@ddeboer ddeboer mentioned this pull request Jan 27, 2017
@ddeboer ddeboer merged commit db7ab31 into portphp:master Jan 27, 2017
@smilesrg
Copy link
Contributor Author

@ddeboer wow, after 1.5 years it has been merged today :-) Hope my contribution will be helpful :-)

@ddeboer
Copy link
Member

ddeboer commented Jan 27, 2017

Yeah, sorry about that delay. It’s definitely helpful! Thanks for your work. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants