Skip to content

[dev/joomla#60] Use correct DB client to detect upgrade - #96

Open
webmaster-cses-org-uk wants to merge 1 commit into
civicrm:masterfrom
webmaster-cses-org-uk:patch-2
Open

[dev/joomla#60] Use correct DB client to detect upgrade#96
webmaster-cses-org-uk wants to merge 1 commit into
civicrm:masterfrom
webmaster-cses-org-uk:patch-2

Conversation

@webmaster-cses-org-uk

Copy link
Copy Markdown
Contributor

This PR is a proposed fix to issue #60, in which it was found that the query to detect the presence (or otherwise) of the civicrm_domain table in civicrm_detect_upgrade() fails if the CiviCRM and CMS databases are different and have different credentials / user access.

Before

Upgrades are treated as new installations if the database user for the CMS (Joomla!) database has no privileges to access the CiviCRM database (given that the databases are different).

This causes several issues, such as:

  • CIVICRM_DSN and other key settings are not copied across in the civicrm.settings.php files, i.e. #47 is not fixed.
  • Some permissions keep getting reset (core#6320).
  • A full set of unwanted civicrm_XXX tables keep getting created in the CMS database.

And possibly others I've not noticed.

After

Upgrades are correctly detected, by using the CiviCRM database client to access the information_schema, instead of the CMS database client, as appropriate.

All of the above problems go away.

Notes

This PR also changes the logic so that existing settings are copied from civicrm.settings.php as long as that file is readable, irrespective of whether it is an upgrade or not. This makes the behaviour of civicrm_setup_instance() consistent with civicrm_detect_upgrade(), and feels more appropriate. The rationale being, if someone has edited the settings file, you'd like to preserve this in any case.

This could be simplified further, to always use the CiviCRM database client. After all, we are only interested in checking whether a CiviCRM table exists.

Comment thread admin/configure.php
// if the CiviCRM and CMS database credentials are different, connect to the server using the
// right ones, to ensure we have access to the $database and can see it in information_schema
if ($database != $jConfig->db) {
CRM_Core_DAO::init(CIVICRM_DSN);

@webmaster-cses-org-uk webmaster-cses-org-uk Apr 18, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note 1:

This seems to be necessary, and works, even though we (apparently) don't set up the autoloading until later in civicrm_setup_instance().

Possibly we should factor the autoloading out and put it earlier in the process, to make sure that CRM_Core_DAO exists? Or get rid of the autoloading entirely, if (as it seems) it has already been done at a higher level?

Note 2:

We could simplify this further and just use CRM_Core_DAO always, getting rid of Joomla database calls entirely?

@webmaster-cses-org-uk webmaster-cses-org-uk changed the title [dev/joomla#60] Use correct DB client to detect upgrade if CiviCRM and CMS databases are different [dev/joomla#60] Use correct DB client to detect upgrade Apr 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant