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

Fail more gracefully when upgrading on PHP 5.x - 5.16 backport #162

Merged
merged 2 commits into from
Aug 21, 2019

Conversation

kcristiano
Copy link
Member

Backport #161

This version requirement officially went up to PHP 7.0 circa Civi 5.14. However, at that time, the upgrade metadata was kept at PHP 5.6 to allow somewhat softer landing for stragglers. That's no longer possible in Civi 5.16+,

This just gives a clearer error when someone tries to upgrade with PHP 5.x.

totten added 2 commits August 20, 2019 20:00
This version requirement officially went up to PHP 7.0 circa Civi 5.14.
However, at that time, the upgrade metadata was kept at PHP 5.6 to allow
somewhat softer landing for stragglers.  That's no longer possible in Civi
5.16+,

This just gives a clearer error when someone tries to upgrade with PHP 5.x.

Before
------

When accessing a Civi-WordPress site on PHP 5.6 (or running wp-cli), the Civi class-loader fails to initialize.

```
Parse error: syntax error, unexpected ':', expecting '{' in /Users/totten/bknix/build/dmaster/web/sites/all/modules/civicrm/vendor/league/csv/src/functions.php on line 33
```

(Approximate call-path: `civicrm.php` => `civicrm.settings.php` =>
`CRM_Core_ClassLoader` => `vendor/autoload.php` => `vendor/league/csv/src/functions.php`)

After
-----

When accessing a Civi-WordPress site on PHP 5.6 (or running wp-cli), the error message is:

```
CiviCRM requires PHP version 7.0.0 or greater. You are running PHP version 5.6.38
```

Comments
--------

The canonical representation of the minimum PHP version is in
`$civicrm_root/CRM/Upgrade/Form.php`.  However, correctly reading that
metadata requires loading `civicrm.settings.php`, which triggers the crash.

To work around this, this patch reproduces the constant and uses a unit-test
to ensure its continued accuracy.
@kcristiano
Copy link
Member Author

@totten here is the backport PR

@totten
Copy link
Member

totten commented Aug 21, 2019

Danke schoen. r-run locally on a 5.16 build (alongside civicrm/civicrm-core#15090), and it worked the same as on 5.16. 👍

@totten totten merged commit 81d551e into civicrm:5.16 Aug 21, 2019
@christianwach
Copy link
Member

@totten Just a pedantic note to say that it would be nice to have a docblock for the assertPhpSupport method :)

Also, when using sprintf with more than one substitution, one should denote the placeholders as %1$s, %2$s, and so on -- this is because some languages may alter the order in which substitutions take place.

@kcristiano
Copy link
Member Author

@christianwach good points. Once this is merged against master let's do a cleanup PR. While this solves the immediate regression your changes should be made.

@totten
Copy link
Member

totten commented Aug 21, 2019

@christianwach - Oh, yup, very good. :) I'll post a PR on master.

For the sprintf bit - thanks, I'd never seen that notation before. I suppose that makes sprintf() a better building block for l10n cases. Also without l10n, it seems useful on general cleanliness (i.e. if someone revises the prose in the future, they don't need re-order the other bits of PHP code).

@christianwach
Copy link
Member

I suppose that makes sprintf() a better building block for l10n cases.

@totten Absolutely. WordPress uses this notation liberally - random example here. FWIW, the comment /* translators: ... */ in the example also has a format to help translators with less technical ability understand the substitutions where necessary.

My go-to resource is this article which is old but still valid. Not ashamed to say that I refer to it regularly!

HTH :)

@kcristiano kcristiano deleted the 5.16.backport branch November 11, 2019 13:16
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.

3 participants