-
-
Notifications
You must be signed in to change notification settings - Fork 824
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
CRM-17652 - Update composer and Symfony for Drupal 8 #10694
Conversation
Can one of the admins verify this patch? |
jenkins, ok to test |
composer.json
Outdated
"name": "civicrm/civicrm-core", | ||
"description": "Open source constituent relationship management for non-profits, NGOs and advocacy organizations.", | ||
"type": "library", | ||
"authors": [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for drafting this. TBH, though, there've been a lot of contributors, and there's a more complete list in CONTRIBUTORS.txt
, contributor-key.yml
, and release-notes/*.md
. I'd like to avoid a fourth one. ;) For composer.json
, maybe just list "CiviCRM LLC" or "civicrm.org ". (If a it really needs human, then maybe the current core team.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's intended to be humans per the composer documentation, but it's optional and we could even omit it, but pretty much all libraries whose composer.json files I've looked at provide it.
Looking at Symfony's composer.json, they actually put the project lead and then an entry for the "Symfony Community". That's not quite right per the docs, but we could do something similar here? If that's OK with you, I can update my PR!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that idea perhaps having the Core team + community, i think the idea is these are the people actively maintaining the thing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @dsnopek! I was hoping to jam on this earlier, but took advantage of my vacation to vacation, instead :P
CRM/Core/ClassLoader.php
Outdated
@@ -104,7 +104,8 @@ public function register($prepend = FALSE) { | |||
} | |||
$civicrm_base_path = dirname(dirname(__DIR__)); | |||
|
|||
require_once dirname(dirname(__DIR__)) . '/vendor/autoload.php'; | |||
// @todo: need some way to check if we should register vendor or not |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible to check if a required class exists, and if it does not then load the autoloader?
We could check if \Composer\Autoload\ClassLoader
exists. In the generated autoloader_real.php
the randomly named class has
public static function loadClassLoader($class)
{
if ('Composer\Autoload\ClassLoader' === $class) {
require __DIR__ . '/ClassLoader.php';
}
}
So if that exists, we know an autoloader has been bootstrapped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, we could do class_exists()
on a class from a CiviCRM dependency. I think I'd prefer something more direct, though, like checking if the vendor directory exists, which it shouldn't if installed via composer as opposed to from a tarball... Lemme try that!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just pushed a new commit that checks for the local vendor autoload, and loads it if it's there
CRM/Core/ClassLoader.php
Outdated
@@ -123,7 +124,8 @@ public function register($prepend = FALSE) { | |||
); | |||
$include_paths = implode(PATH_SEPARATOR, $include_paths); | |||
set_include_path($include_paths . PATH_SEPARATOR . get_include_path()); | |||
require_once "$civicrm_base_path/vendor/autoload.php"; | |||
// @todo: need some way to check if we should register vendor or not | |||
//require_once "$civicrm_base_path/vendor/autoload.php"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above.
composer.json
Outdated
"symfony/process": "~2.5.0", | ||
"psr/log": "1.0.0", | ||
"symfony/finder": "~2.5.0", | ||
"symfony/config": "^2.5.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can keep ~
but use ||
to allow different? so ~2.5 || ~2.8
to compatibility with Drupal. But also, as stated in StackExchange.. 2.5 is outdated and not receiving releases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well ~2.5
would allow 2.8 because there isn't the last .0
on there. We probably actually should do ~2.5 || ~3.0
to be compatible with Drupal 8.4.x but I haven't tested with 8.4.x yet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, yeah. https://semver.mwl.be/#?package=symfony%2Fprocess&version=~2.5%20%7C%7C%20~3.0&minimum-stability=stable that looks like it'd be the trick (for also supporting 8.4.x)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoa, that link is amazing! Thanks for sharing that :-)
CRM/Core/ClassLoader.php
Outdated
|
||
// @todo: need some way to check if we should register vendor or not | ||
//require_once dirname(dirname(__DIR__)) . '/vendor/autoload.php'; | ||
if (file_exists($composer_autoload)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The conditional is a good idea, although I'm wondering if we might actually need to check both locations like https://github.com/civicrm/cv/blob/v0.1.27/bin/cv#L9
Reason: for better or worse, Civi has two bootstrap processes:
- CMS-first (typical case; ex: a page-request hits Drupal, which then boots Civi by loading
civicrm.settings.php
andCRM_Core_Config::singleton()
) - Civi-first (less typical case; ex: request hits
extern/rest.php
,extern/ipn.php
,bin/cli.php
, orcv
; this readscivicrm.settings.php
and then boots CMS viaCRM_Utils_System_*::loadBootStrap()
)
In the second scenario, the classloader needs to be available.
Speculation: this should be fine as long as Civi+CMS behavior are convergent -- they both say require_once vendor/autoload.php
for the same copy of autoload.php
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. So, the code should probably be changed to look first for the local vendor directory first (will be present in a non-composer based install), but if it's not there, then look for a top-level vendor directory (will be present in a composer-based install).
I'll take a look! I first need to figure out a good way to test (trying bin/cli.php
seems like it'd be the easiest?) and see the failure when using a Civi-first entry point, and then I can try that code change and see if it fixes it.
Thanks for the info :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just pushed some changes that get bin/cli.php
bootstrapping Drupal 8 (or at least not crashing when trying to do so). It required creating a settings_location.php
file because the default logic for finding the Drupal config directory in civicrm.config.php doesn't work with civicrm-core installed by composer. I don't know if there's a sane way to fix that, since I don't know what all the cases in there are for and I don't want to break something
I finally got around to testing with Drupal 8.4.x -- the composer change described above in the thread with @mglaman works! However, there were some additional changes required, because there was some stuff added in Symfony 2.6 which deprecated some Symfony 2.5 methods, and of course, the deprecated methods are removed in 3.x. So, I had to change some code around building the service container, and push the minimum Symfony dependency up to 2.6. Hopefully, that's acceptable? If not, I can make a separate branch/PR for supporting Drupal 8.4, but 8.4 will be release on October 4th, so it's coming up pretty quick But after all that, I got it working on Drupal 8.4 :-) |
@dsnopek nice work Regarding the version bump to 2.6, that works for me. Two caveats:
|
Ah, yeah. Well, that'll continue to work in any Symfony 2.x version (those methods are still there but deprecated), but that'll fail when using that extension with Symfony 3.x, ie. with Drupal 8.4. So, that extension won't break right away, and maybe the developer will pay attention to the deprecation notices :-) |
@dsnopek David i just want to check that you were able to enable other modules through the GUI once CiviCRM had been installed is that correct? |
@seamuslee001 Yes! I reported that worked on this comment on the JIRA ticket - I've written some crazy large comments on that issue, so I don't blame you for not noticing that bit of information :-) |
How awesome is this! Fantastic @dsnopek really appreciate your time with this...So how do I test this...Do I just apply the patch to an already working installation, or do I need to use civibuild to build CiviCRM against master + this PR ? Are their any steps for applying this for testing that we should be aware of? |
It's the same process as I originally posted in JIRA and on Stack Exchange (but I have been evolving the gist which is the steps to replace Here's the steps again:
I don't know if anyone other than me has tested these steps yet, so I'd really appreciate any feedback on them! |
Hrm. I merged the master branch (because there was a conflict) and it's failing in Jenkins in a way I don't totally understand. Any advice on how to fix it? |
Hi @dsnopek I would recommend that you rebase your branch against civicrm's master branch with git rebase -i /master then do git push composer-library -f |
@seamuslee001 Hm, I'd normally not rebase on a branch that was pushed remotely. However, if that the normal process for CiviCRM PRs, I can certainly do that! |
…CiviCRM classes" This reverts commit 51d83d0.
…tible with Symfony 3.x (need new method to replace deprecated method)
3dcf001
to
e73a88e
Compare
Rebased! Hopefully tests will start working again :-) |
And we're back to passing. Yay! :-) |
Hi @dsnopek - thanks for all your work on this! I went through the steps you listed - above - and 💯 x 👍 ! I've got a functional (freshly baked) Drupal 8.3.6; CiviCRM 4.7.22; I've been able to:
Thank you & Merci! |
@totten i feel like with Karin's comment this has had plenty of testing now and seems sane |
Just to clarify - I followed the exact steps in: #10694 (comment) |
CRM/Core/ClassLoader.php
Outdated
* @return void | ||
*/ | ||
protected function requireComposerAutoload() { | ||
$civicrm_base_path = dirname(dirname(__DIR__)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure you can use
$civicrm_base_path = dirname(__FILE__, 2);
$top_path = dirname(__FILE__, 5);
Would be good to include a comment clarifying what's magic about the 5-th parent directory (and/or use a Drupal method to discover Drupal root, if that's what that is).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's neat.
According to http://php.net/dirname , the second argument was added in PHP 7. We'll be stuck with multiple dirname()
s for a while.
Thanks, @KarinG! I'm super glad it worked :-) @xurizaemon Whoa! How is it possible that I never knew that I don't think we can use a Drupal method to discover the Drupal root because we could end up here through an alternate entrypoint before Drupal is bootstrapped (ex. |
I just pushed a commit with the changes suggested by @xurizaemon! |
Hrm. It looks like the tests are failing because the version of PHP that's running the tests doesn't support the 2nd argument to |
I think these changes are better in than out. @dsnopek , do you still want the "WIP" label on here? Aside: In the past, we've encountered unexpected issues when touching this area (esp. involving tarball builds), so I'd like to do a quick trial-run of generating+installing tarballs before merging. So far, |
I tested David's process and it works out. You must install Drupal the
normal way. In stalling Drupal with composer breaks loading any css and js
resources because when you install Drupal via composer you can't set the
resource url because the webroot is in the web directory of the drupal
docroot, and vendor directory can't be set for the resource url.
|
@totten Like I said on the JIRA issue, I think this is mergable in it's current state. There's still more that should be done to improve the installation process, but we can address that in follow-ups. So... I'll remove the "WIP" label! |
Yep we have two separate verification tests, it's definitely a huge improvement for the issue. It's got my vote |
OK, I've confirmed that my testing issues on Backdrop+Joomla were unrelated. Let's merge this! |
Woohoo! Thanks, Everyone! :-) |
Jippie! What's next? It would be aswesome if we can civibuild create dmaster --cms-ver 8.3.6 ahead of the upcoming Sprints @totten! |
@KarinG IIRC, it has been possible to say Those scripts need to be updated, though. They match the original file-layout of the D8 port. Now that we're making progress toward |
Hi @totten - sorry - yes that's what I meant - would you be able to update those scripts by the time the Sprints come around? I got things to work following the steps outlined above but it's a lot of steps/long process; it would be awesome if you could update your buildkit scipts. |
I was able to install into a drupal-composer/drupal-project based site. Follow the instructions above from the project root, not Drupal root. Then...
That got it to install, though it was broken; no menu, no style, etc. Go to http://www.yourdomain.com/civicrm/admin/setting/url?reset=1 and set the first edit control (there's no label displayed) to http://www.yourdomain.coml/vendor/civicrm/civicrm-core and save. I haven't done extensive testing but so far it seems to be working fine and I'm able to install other modules. |
@konadave so for it to work currently, you want to install Drupal 8 "like normal", that is not with composer....then follow the steps that David S. has provided. the reason that the css, js etc... doesn't work, is because with a standard composer based install, the website doc root is in <project_root>/web ... basically the website docroot and the project root are not the same directory. CiviCRM is then placed in <project_root>/vendor/..... and you can't set the Resource URL to point to the Civi installation, because it is out of the website docroot.... Further work will be required in CiviCRM Core to make this work with D8 installed in the beginning with composer |
@jackrabbithanna I have it working using the steps I outlined. The symlink puts the vendor directory in docroot. |
@konadave sorry I guess I didn't read your comment well the first time....thanks for documenting that...Not sure if that should become the "set" method or if something else should be developed, if so we should make another jira issue and pr about that |
Work in progress PR for https://issues.civicrm.org/jira/browse/CRM-17652
Remaining tasks