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

[REF] Use OO when determining what to suggest for settings.php prefixes for drupal/backdrop views, instead of scattered "if cms ==" #21042

Merged
merged 1 commit into from
Sep 14, 2021

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Aug 6, 2021

Overview

I took a look at #20682 and it seemed clear that
in it's current state it would fix one CMS (d9) & break another (d7). This is
an alternate that will hopefully be non-breaky

Before

See #20682

After

fixed - hopefully without breaking anything else

Technical Details

The discussion by @demeritcowboy @homotechsual @demeritcowboy @seamuslee001 seems to indicate this would be a be a safer approach

Comments

ping @pradpnayak

@civibot
Copy link

civibot bot commented Aug 6, 2021

(Standard links)

@demeritcowboy
Copy link
Contributor

See also eileenmcnaughton/civicrm_entity#312 (comment) which was just merged recently. I'm not sure at the moment whether that makes this unnecessary or is separate. @jackrabbithanna @KarinG

@eileenmcnaughton
Copy link
Contributor Author

Oh yeah - I saw @KarinG pasted that link on the original but I didn't actually click through on it - I see what you mean

@herbdool
Copy link
Contributor

herbdool commented Aug 7, 2021

I haven't looked too closely but I recall us having an issue with civi integration with views in Backdrop but it was because of a new support for latest MySQL. @laryn do you know if there's an issue someplace?

@jackrabbithanna
Copy link
Contributor

Recently Matt made a PR where it is no longer necessary to add the "views integration" database prefix settings in the Drupal's settings.local.php

Also, the PR you referenced did fix a bug that caused an SQL that is that error or a similar error as posted for this issue.

Perhaps test Civi without your PR with the latest of the 8.x-3.x branch in the github repo, for Drupal 8/9 I'm not sure any fixes are necessary in Civi Core, but I could be wrong.

@eileenmcnaughton
Copy link
Contributor Author

I'm gonna close this out if people don't think it's needed

@herbdool
Copy link
Contributor

herbdool commented Aug 7, 2021

As far as Backdrop is concerned this PR is still an improvement by moving the logic to the userframework class. It might not address the official bug but it's still good.

I found: backdrop/backdrop-issues#4745. I believe that we'll still need the separate logic between Drupal 7 and Backdrop.

Can we revive this PR @eileenmcnaughton or does it need a new issue?

@eileenmcnaughton
Copy link
Contributor Author

@herbdool - tada - it's back - actually you are right - I didn't include any actual change as far as I can tell - so no reason not to merge this

*/
public function getCMSDatabasePrefix(): string {
$crmDatabase = DB::parseDSN(CRM_Core_Config::singleton()->dsn)['database'];
$cmsDatabase = DB::parseDSN(CRM_Core_Config::singleton()->dsn)['database'];
Copy link
Contributor

Choose a reason for hiding this comment

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

??? This looks wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

does doesn't it....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and yet, like magic....

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks better now

@herbdool
Copy link
Contributor

herbdool commented Aug 7, 2021

I haven't tested but looks like it'll work the same as before. LGTM

@KarinG
Copy link
Contributor

KarinG commented Aug 7, 2021

What is the issue that is being fixed here?

Drupal 9 / Views with latest CiviCRM entity PR 312 is working with Drupal and CiviCRM tables in a single database as well as with Drupal and CiviCRM tables in two separate databases ->without<- (as this has been deprecated) specifying

$databases['default']['default']['prefix']= array(
'default' => '',
'civicrm_acl'

in the settings.php file

And it’s working for very complicated Views involving Views relationships joining both Drupal and CiviCRM tables.

And we have added a first Views automated test in CiviCRM Entity now.

I thought all things Views should live in CiviCRM Entity - that’s why I had Matt help me make this possible via CiviCRM Entity.

@pradpnayak - who first posted referenced an SE issue w/ database prefixes - but those are deprecated - so what’s the issue that needs fixing post CiviCRM Entity PR 312?

@herbdool
Copy link
Contributor

herbdool commented Aug 8, 2021

@KarinG I mentioned above why I asked to reopen this PR.

This is not so much about d9 as about just putting existing logic in the right place. The prefix setting is better in the class.

Maybe the PR could be renamed?

@demeritcowboy
Copy link
Contributor

demeritcowboy commented Aug 8, 2021

Some thoughts:

  • What this form does is display some stuff on screen, it's not directly involved in how views integrates. Ideally it would display the correct thing to avoid frustration when setting up a new site (for drupal 7/backdrop), but no existing sites will suddenly break from this.
  • I'd suggest not adding the drupal 9 class because it doesn't do anything because it never gets called since there is no CIVICRM_UF=Drupal9 and likely never will be.
  • It previously compared the full DSN. Now it only compares the db name. That should be ok though.
  • When the next civicrm_entity is released a followup PR could be done to display something to the user for Drupal8+ that it's no longer needed (if I'm understanding correctly).
  • It would be good to at least give this a minimal run. Has anyone run it yet?

if ($crmDatabase === $cmsDatabase) {
return '';
}
return "`$cmsDatabase`.";
Copy link
Contributor

Choose a reason for hiding this comment

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

I was just testing this (drupal 7) - this is backwards - you need the crmdatabase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@demeritcowboy do you want to push in the changes that this PR needs?

@demeritcowboy
Copy link
Contributor

There was a larger question raised:

I thought all things Views should live in CiviCRM Entity

Would it make sense to just take this section of the form completely out of core and let civicrm_entity provide a page to tell the user whatever it thinks is right?

@herbdool
Copy link
Contributor

herbdool commented Aug 9, 2021

@demeritcowboy wouldn't your proposal mean that all sites regardless of CMS would need to install that module? I don't think that would work. Not all D7 sites would need the full civicrm_entity capability and the module doesn't currently exist for Backdrop.

@KarinG
Copy link
Contributor

KarinG commented Aug 9, 2021

As of D8 / D9 all views integration is supported by CiviCRM entity

D7 views integration should stay as is - CiviCRM entity is not and should not be required.

Still not at all clear to me what ‘Drupal 9 views fix’ is being fixed here. We have a lot of Drupal 9 views that are working fine especially after we sorted out civicrm entity to handle single vs separate database scenarios. If the title of this PR is wrong can someone please suggest a better one with steps to reproduce?

@demeritcowboy demeritcowboy changed the title drupal 9 views fix (alternative) [REF] Use OO when determining what to suggest for settings.php prefixes for drupal/backdrop views, instead of scattered "if cms ==" Aug 9, 2021
@demeritcowboy
Copy link
Contributor

@KarinG I've changed the title.

@herbdool Good to know civicrm_entity doesn't work with backdrop. And yes right even drupal 7 doesn't require it for views.

To recap then:

  • Backdrop: No backticks.
  • Drupal 7: Backticks
  • Drupal 8: The prefixes aren't needed if you are running off the latest civicrm_entity from git, but still needed if you are running off the latest download of the module from drupal.org. Not sure what composer does (nobody knows what composer does).
  • Drupal 9: Might need something different from drupal 8, but people are encouraged to use the latest civicrm_entity from git instead.
  • Drupal 10: It will NOT work if using an older civicrm_entity regardless of prefixes or not - you MUST use the latest civicrm_entity from git.

Side note: Line 76 references a non-existent variable.

@KarinG
Copy link
Contributor

KarinG commented Aug 9, 2021

Thanks Dave 👍

@jackrabbithanna -> can you please queue up a release for CiviCRM Entity? Then >= D8 views will -no longer- require prefixes regardless of whether people use a single or separate db-s - until then people are going to hit ‘something not working’ and will look in CiviCRM core to fix it.

@seamuslee001
Copy link
Contributor

So my other question is that does D7 still work with Backticks or not, given that Backdrop effectively ported the recent D7 patches for MySQL 8 which is what caused the backticks to no longer work on Backdrop, does D7 still need them.

As for composer if you just use drupal/civicrm_entity then it depends on what is in the drupal releases / git repo in drupal's world but if you specify to use the github then it will be what ever is in the Eileen repo setup.

@eileenmcnaughton
Copy link
Contributor Author

@demeritcowboy my reason for adding an empty d9 class is that say in future we Do have a function that differs between 8 & 9. Then we could have upgrading fun - ie you can't set d9 on your pre-upgraded DB because it isn't there until the code base supports it but you really want to set it before you put the new code base there (I'm remembering this being tricky with d6->d7) - of course in writing this I realised we'd need to add a permissions stub too

@jackrabbithanna
Copy link
Contributor

@KarinG still having some consequences of the activity and event entity types having bundles based on the event type and activity type .. that layout builder issue I mentioned .. but maybe this Views stuff is more important and worth a release.

@eileenmcnaughton
Copy link
Contributor Author

@jackrabbithanna - if it doesn't break anything then release it :-)

@jackrabbithanna
Copy link
Contributor

Its a different feature, but got to choose the lesser of two evils sometimes

@eileenmcnaughton
Copy link
Contributor Author

@demeritcowboy I think this is mergeable but there has been a lot of tangential conversation - is that your take?

@demeritcowboy
Copy link
Contributor

Hi,
It's not mergeable. For one it has the crm and cms backwards.
It sounded like there was a plan to make a release for civicrm_entity with the latest goodies, but I don't see that on drupal.org yet.
I'd maybe suggest closing this for now.

@herbdool
Copy link
Contributor

herbdool commented Aug 25, 2021

civicrm_entity is a separate issue at this point. Doesn't affect the merits of this. Other than fixing that one error I think it's mergable

@demeritcowboy
Copy link
Contributor

civicrm_entity is relevant in the sense that if we can drop any code related to drupal 8+ then that has more merit, and as noted in the comments possibly even the drupal 7 part can go.

This PR takes non-trivial time to test - obviously nobody tested it - I'd rather not spend more of my time on this version if it's going to be changing anyway - I stopped when the crm/cms thing came up, so there's still more to test.

@eileenmcnaughton
Copy link
Contributor Author

@demeritcowboy ok - I'll close

@herbdool
Copy link
Contributor

@demeritcowboy How can the D7 part be removed? Is civicrm_entity going to be required for all Drupal sites?

Regarding the empty D9 class I thought that was already explained above. It's not just related to Views.

I haven't had a chance yet to test it but I figured it was good on the principle of better refactoring.

@demeritcowboy
Copy link
Contributor

D7 removed in the sense it might now be the same as backdrop.

@eileenmcnaughton
Copy link
Contributor Author

I just took a quick look & fixed the crm vs cms & re-opened based on @herbdool - but this does require testing on at minimum backdrop & at least one other cms I guess

I don't have strong opinions about push through vs abandon but I do think this is cleaner & will make it easier to add d9 overrides if & when the time comes

@herbdool
Copy link
Contributor

I'll try to test it tomorrow. Or after my time off in a couple weeks.

* However, this string should contain backticks, or not, in accordance with the
* CMS's drupal views expectations, if any.
*/
public function getCRMDatabasePrefix(): string {
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 that this should just return '' and this code should actually sit in the DrupalBase.php class which is shared by the Drupal 7 (Drupal.php), Backdrop and Drupal 8 classes as appropriately

Copy link
Contributor

Choose a reason for hiding this comment

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

@seamuslee001 do you mean the default is returning an empty string and then in the Drupal 7 class and Backdrop class add a check if $crmDatabase === $cmsDatabase?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@seamuslee001 the reason I landed on the base class is that it is still a valid db prefix beyond drupal - even if it isn't used

$dsn = CRM_Utils_SQL::autoSwitchDSN($config->dsn);
$dsnArray = DB::parseDSN($dsn);

$dsnArray = DB::parseDSN(CRM_Utils_SQL::autoSwitchDSN($config->dsn));
$tableNames = CRM_Core_DAO::getTableNames();
asort($tableNames);
$tablePrefixes = '$databases[\'default\'][\'default\'][\'prefix\']= [';
Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately we still have a $config->userFramework === 'Backdrop' just below this. Do we need another method for $tablePrefixes? Though I see other references above as well to WordPress, Drupal 8, etc so maybe the whole buildForm should be passed in from the classes? Or leave that for a future issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's leave out of scope of this given how stalled it is

@herbdool
Copy link
Contributor

I've tested in Backdrop and the PR looks fine. I won't have time to test Drupal7 for a couple weeks.

@herbdool
Copy link
Contributor

@demeritcowboy I'm not sure if Drupal 7 is now the same as Backdrop. I recall that they took a slightly different approach and not sure if Drupal 7 took away the backticks. I'm assuming it's backwards compatible?

@eileenmcnaughton
Copy link
Contributor Author

@demeritcowboy @seamuslee001 where do you think this is at given @herbdool's testing (above)

I just re-read through the code & I believe that for d7 (untested) & d8 (tested) the db would have backticks before and after this change

@herbdool
Copy link
Contributor

herbdool commented Sep 13, 2021

@eileenmcnaughton I've now tested in d7 as well. Before and after, the format looks the same. Like

'`civicrm`.'

So I believe this meets the goal of refactoring here. Code is better, output is the same.

@eileenmcnaughton
Copy link
Contributor Author

@demeritcowboy @seamuslee001 ^^

/**
* Drupal specific stuff goes here.
*/
class CRM_Utils_System_Drupal9 extends CRM_Utils_System_Drupal8 {}
Copy link
Contributor

Choose a reason for hiding this comment

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

@eileenmcnaughton I genuinely don't see a need for this at all given that we are not changing the UF between Drupal 8 -> Drupal 9

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@seamuslee001 yeah - it feels 'right' to me to put this here because it seems inevitable there will be some variance at some point - but TBH my involvement in this one is just that I was trying to resolve an old stalled PR. (I've already tried to close it twice :-))

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 merge it if this was not included

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK - I've removed it - I guess putting this to bed is more important than my feeling it should be added

@seamuslee001
Copy link
Contributor

I would also just add that I think I tested this on d7 but without the backticks and that seem to work as well (maybe some compatibility layer exists there somewhere)

I took a look at civicrm#20682 and it seemed clear that
in it's current state it would fix one CMS (d9) & break another (d7). This is
an alternate that will hopefully be non-breaky
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants