-
Notifications
You must be signed in to change notification settings - Fork 243
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
🐛 N°8278 - Avoid autoloaders class name conflict by ensuring all existing have a unique name #704
🐛 N°8278 - Avoid autoloaders class name conflict by ensuring all existing have a unique name #704
Conversation
The sample module sample-module.zip |
Proposal of unit tests:
|
@jf-cbd careful when you change the target branch, sometimes you need to "rebase onto" the original branch as well. Otherwise there is a whole lot of extra commits in the PR like now. You should either do it or poke the author so he does it. I'll do it :) |
06e2da9
to
0bb6e94
Compare
@jf-cbd Done! |
Btw, you changed the target branch to |
Alright, thanks for doing it @Molkobain ! Concerning the problem of autoloaders class name conflicts, we decided to split the problem in two part : |
Alright, sounds great! |
Perfect, let's merge :) |
Thank you @Molkobain 😉 |
…ting have a unique name (#704) * 🐛 Avoid autoloaders class name conflict by ensuring all existing have a unique name * 🐛 Redump itop-attachments autoloaders for correct suffix
…ting have a unique name (#704) * 🐛 Avoid autoloaders class name conflict by ensuring all existing have a unique name * 🐛 Redump itop-attachments autoloaders for correct suffix
…ting have a unique name (#704) * 🐛 Avoid autoloaders class name conflict by ensuring all existing have a unique name * 🐛 Redump itop-attachments autoloaders for correct suffix
Base information
Symptom (bug)
When running a setup, it crashes during compilation saying that an autloader class with the same name is already loaded:
This is a very similar symptom than what we had several times (without understanding it at the time) during the development of new portal modules compatible with both iTop 2.6 & 2.7. Which was actually when we introduced autoloaders and composer in portal modules.
Reproduction procedure (bug)
composer.json
file that contains nothing but the license and the autoload configurationcomposer install
on the module'scomposer.json
fileNote: You'll find attach to this PR a minimal module with the corresponding
composer.json
file to ease reproduction.Cause (bug)
Both the
itop-portal-base/portal
and my module have the same PHP class name for the autoloader:d751713988987e9331980363e24189ce
The regression cause is that in 3.2.1, the
itop-portal-base
module's autoloaders were udpated in 9fadbb5e. Changing the autoloader class name toComposerAutoloaderInitd751713988987e9331980363e24189ce
which is kind of the default one (see root cause section).Root cause
In the latest versions of Composer, when there is a
composer.lock
, the suffix of the autoloader class (e.g.d751713988987e9331980363e24189ce
) is a hash (md5) based on some of the information in thecomposer.json
file.If none of the properties are defined in the
composer.json
, then the hash will always be the same:d751713988987e9331980363e24189ce
Composer source references:
Locker::getContentHash()
Note: The
composer.lock
file is not generated if you only dump the autoloaders. You have to install/update for it to be generated. Which is not done on all modules.Proposed solution (bug and enhancement)
Add the missing
"name"
information in modules'composer.json
files and re-dump the autoloaders. It makes sense as module are supposed to be individual packages. Also this is something that is done in many existing Combodo's modules.Exception for
itop-portal-base/portal/composer.json
file, as it is not at the root of the module, naming itcombodo/itop-portal-base
would be misleading. Naming it something likecombodo/itop-portal-base_portal
would be weird as well.So I went with using the
autoloader-suffix
conf. property (documentation) that forces the suffix of the class name.Mind that we could consider forcing the suffix of autoloaders in all modules, that way we would ensure uniqueness without relying on Composer's black box algorythm. But as it's not the current policy in existing modules, I didn't. Feel free to tell me if you want to adjust the PR accordingly.
Workaround
For people having the issue with their module, you can juste set a
"name"
property in yourcomposer.json
:Checklist before requesting a review
Checklist of things to do before PR is ready to merge