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

Make sonata.media.admin.media.manager an alias of sonata.admin.manager.orm / sonata.admin.manager.doctrine_mongodb #1821

Merged
merged 1 commit into from
Oct 13, 2020

Conversation

jorrit
Copy link
Contributor

@jorrit jorrit commented Sep 23, 2020

Subject

Since sonata-project/doctrine-orm-admin-bundle 3.22 the constructor of Sonata\DoctrineORMAdminBundle\Model\ModelManager throws a deprecation warning when the second argument is not provided. The file doctrine_orm_admin.xml of the media bundle registers this class as the service sonata.media.admin.media.manager without this argument. I think this service can be made an alias of sonata.admin.manager.orm. This makes sure the parameters are correct regardless of the orm bundle version.

Maybe I've overlooked something that would make this solution invalid, but it seems this solution also makes sure there is just one instance of the ModelManager, which seems a plus.

I am targeting this branch, because it is a backwards compatible change.

Changelog

### Changed
- When using Doctrine ORM or MongoDB the service `sonata.media.admin.media.manager` is now an alias of `sonata.admin.manager.orm` or `sonata.admin.manager.doctrine_mongodb` instead of a separate service implemented by the same class.

### Fixed
- Deprecation notice in `Sonata\DoctrineORMAdminBundle\Model\ModelManager` and `Sonata\DoctrineMongoDBAdminBundle\Model\ModelManager`.

franmomu
franmomu previously approved these changes Sep 23, 2020
Copy link
Member

@franmomu franmomu left a comment

Choose a reason for hiding this comment

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

Seems like a fine solution 👍

@phansys
Copy link
Member

phansys commented Sep 23, 2020

I think this is a good proposal, I'd just like to have a clear idea about how both services are currently registered, in order to avoid any potential edge case where the aliased service could not be found.
Could you please provide a little explanation @jorrit?

@jorrit
Copy link
Contributor Author

jorrit commented Sep 24, 2020

The service sonata.admin.manager.orm is created unconditionally by the SonataDoctrineORMAdmin bundle (see https://github.com/sonata-project/SonataDoctrineORMAdminBundle/blob/3.x/src/Resources/config/doctrine_orm.xml).
It is set to the same class as sonata.media.admin.media.manager but depending on the version of the ORM bundle it will have the right amount of arguments.

@jorrit jorrit changed the title Make sonata.media.admin.media.manager an alias of `sonata.admin.man… Make sonata.media.admin.media.manager an alias of sonata.admin.manager.orm Sep 24, 2020
@phansys
Copy link
Member

phansys commented Sep 24, 2020

This service was unconditionally available before this change. Now, it aliases a service which might not exist if doctrine/orm is not installed.
IMO, if we decide to make this change, we should take the same action for all the available managers.

@jorrit
Copy link
Contributor Author

jorrit commented Sep 24, 2020

The class these two services are currently referring to is Sonata\DoctrineORMAdminBundle\Model\ModelManager so right now these can only exist when SonataDoctrineORMAdminBundle is installed. Nothing will change there.

Furthermore, sonata_orm_admin.xml will only be loaded when the sonata_media.db_driver setting is set to doctrine_orm.

I would prefer to remove the sonata.media.admin.media.manager service altogether and change the setModelManager call of sonata.media.admin.media to sonata.admin.manager.orm directly, but the service is public so that would be a BC break.

@phansys
Copy link
Member

phansys commented Sep 24, 2020

I'm referring to these sibling services:

The phpcr implementation seems to be following the same alias approach:

<service id="sonata.media.admin.media.manager" alias="sonata.admin.manager.doctrine_phpcr" public="true"/>

But not mongodb:

<service id="sonata.media.admin.media.manager" class="Sonata\DoctrineMongoDBAdminBundle\Model\ModelManager" public="true">

…undle model manager service

Instead of duplicating the existing `sonata.admin.manager.orm` or `sonata.admin.manager.doctrine_mongodb` services.

This prevents a deprecation notice for sonata-project/doctrine-orm-admin-bundle since 3.22 and sonata-project/doctrine-mongodb-admin-bundle for the first release after 3.3.0.
@jorrit
Copy link
Contributor Author

jorrit commented Sep 24, 2020

I hadn't looked at the other persistence bundles. It's interesting that PHPCR already uses an alias. This confirms that it works. I changed mongodb too, which seems to have the same deprecation situation (see sonata-project/SonataDoctrineMongoDBAdminBundle@b382c81)

@jorrit jorrit changed the title Make sonata.media.admin.media.manager an alias of sonata.admin.manager.orm Make sonata.media.admin.media.manager an alias of sonata.admin.manager.orm / sonata.admin.manager.doctrine_mongodb Sep 24, 2020
Copy link
Member

@phansys phansys left a comment

Choose a reason for hiding this comment

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

Excellent!
I think we could remove the "sonata.media.admin.media.manager" definition if its aliased service doesn't exist (which is the case for custom managers).

@jorrit
Copy link
Contributor Author

jorrit commented Sep 29, 2020

@phansys What situation would that be? Wouldn't sonata.admin.manager.orm point to the custom manager also?

@phansys
Copy link
Member

phansys commented Sep 29, 2020

@phansys What situation would that be? Wouldn't sonata.admin.manager.orm point to the custom manager also?

We are currently supporting 3 built-in managers: orm, doctrine_mongodb and doctrine_phpcr. I was thinking that also custom managers were allowed and inferred from the manager_type option, but this is not the case:

->scalarNode('db_driver')
->defaultValue('no_driver')
->info('Choose persistence mechanism driver from the following list: "doctrine_orm", "doctrine_mongodb", "doctrine_phpcr"')
->validate()
->ifNotInArray(self::DB_DRIVERS)
->thenInvalid('SonataMediaBundle - Invalid db driver %s.')
->end()
->end()

So, forget about my last comment.

@phansys phansys requested a review from a team September 30, 2020 12:26
@phansys phansys added the patch label Sep 30, 2020
@phansys phansys merged commit e086b56 into sonata-project:3.x Oct 13, 2020
@phansys
Copy link
Member

phansys commented Oct 13, 2020

Thank you @jorrit!

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

Successfully merging this pull request may close these issues.

None yet

3 participants