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

(dev/drupal#79) Fail more gracefully when upgrading on PHP 5.x #584

Merged
merged 1 commit into from
Aug 22, 2019

Conversation

totten
Copy link
Member

@totten totten commented Aug 21, 2019

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 upgrading via drush or Drupal web UI on PHP 5.6, 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.drush.inc | civicrm.module =>
civicrm.settings.php => CRM_Core_ClassLoader => vendor/autoload.php =>
vendor/league/csv/src/functions.php)

After

When upgrading via drush on PHP 5.6, the error points to the actual problem.

[bknix-old:~/bknix/build/dmaster/web/sites/all/modules/civicrm] drush civicrm-upgrade-db
CiviCRM requires PHP 7.0.0+. Drush is running PHP 5.6.38.                                                                                                                [error]

When upgrading via web UI on PHP 5.6, the error message is similar:

CiviCRM requires PHP 7.0.0+. The web server is running PHP 5.6.38.

(Note: I tweaked the text to emphasize that the PHP version is determined by
the "drush" or "web server" environment - in some systems, these are
different environments with different PHP versions. A phrase like "your
version" can be confusing/misleading in those cases.)

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, we reproduce the constant and use a unit-test to ensure
its continued accuracy.

Also, it seems useful to put the same metadata in civicrm.info. I'm not
sure if D7 uses this in a meaningful way, but it's good to be accurate.

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 upgrading via drush or Drupal web UI on PHP 5.6, 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.drush.inc | civicrm.module` =>
`civicrm.settings.php` => `CRM_Core_ClassLoader` => `vendor/autoload.php` =>
`vendor/league/csv/src/functions.php`)

After
-----

When upgrading via drush on PHP 5.6, the error points to the actual problem.

```
[bknix-old:~/bknix/build/dmaster/web/sites/all/modules/civicrm] drush civicrm-upgrade-db
CiviCRM requires PHP 7.0.0+. Drush is running PHP 5.6.38.                                                                                                                [error]
```

When upgrading via web UI on PHP 5.6, the error message is similar:

```
CiviCRM requires PHP 7.0.0+. The web server is running PHP 5.6.38.
```

(Note: I tweaked the text to emphasize that the PHP version is determined by
the "drush" or "web server" environment - in some systems, these are
different environments with different PHP versions.  A phrase like "your
version" can be confusing/misleading in those cases.)

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, we reproduce the constant and use a unit-test to ensure
its continued accuracy.

Also, it seems useful to put the same metadata in `civicrm.info`.  I'm not
sure if D7 uses this in a meaningful way, but it's good to be accurate.
@civibot
Copy link

civibot bot commented Aug 21, 2019

(Standard links)

@civibot civibot bot added the 7.x-5.16 label Aug 21, 2019
@totten
Copy link
Member Author

totten commented Aug 21, 2019

I did some r-run on PHP 5.6 (web UI and CLI) to confirm they show the better PHP version error Similarly, I did r-run on PHP 7.0 (web UI and CLI) to confirm that they don't show a PHP version error.

@totten
Copy link
Member Author

totten commented Aug 21, 2019

jenkins, test this please

@eileenmcnaughton
Copy link
Contributor

Straight forward backport

@eileenmcnaughton eileenmcnaughton merged commit 32cd500 into civicrm:7.x-5.16 Aug 22, 2019
@totten totten deleted the 7.x-5.16-php-min branch August 22, 2019 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants