Skip to content

Check for required PHP extensions upon plugin initialization #4930

Merged
swissspidy merged 37 commits intomainfrom
feature/compatiblity
Nov 2, 2020
Merged

Check for required PHP extensions upon plugin initialization #4930
swissspidy merged 37 commits intomainfrom
feature/compatiblity

Conversation

@spacedmonkey
Copy link
Copy Markdown
Contributor

@spacedmonkey spacedmonkey commented Oct 20, 2020

Summary

Create a new Compatibility class and move repeated logic like checks for PHP and WordPress versions to new class. Each method on the class implements a check and can be called from different contexts. The class has some new checks, mostly copied from the AMP plugin.

Relevant Technical Choices

Implementing these checks as a class means if the plugin isn't built then the class file has to be loaded manually. There is no way around this but it does work pretty well in my testing.

Lots of the checks are set as class properties. There has two benefits.

  1. Makes the code more portable. ( Could the amp plugin use this code. ).
  2. Improves testability, allowing invalid versions numbers to be set in unit tests.

Standard gettings and setters have been used to populate values into class properties. This makes the signature of the contractor a little cleaner.

This list of extensions, functions and classes was generated by doing a lot of research into the code. It is different from the amp list. Specially the json extension check.

To-do

  • Add unit tests.
  • Feedback from AMP team.
  • Get feedback on what checks fire where from @swissspidy

User-facing changes

One implement, is that if multiple check fail, this will be displayed to the user, using bullet points. See this example.

image

Testing Instructions

Installed plugin on site that doesn't have stories min require, like PHP 5.5 or WordPress 5.2 and active plugin. See warning message.

Fixes #4791

@google-cla google-cla bot added the cla: yes label Oct 20, 2020
@spacedmonkey spacedmonkey self-assigned this Oct 20, 2020
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Oct 20, 2020

Size Change: 0 B

Total Size: 1.4 MB

ℹ️ View Unchanged
Filename Size Change
assets/css/edit-story.css 909 B 0 B
assets/css/stories-dashboard.css 939 B 0 B
assets/css/web-stories-embed-block.css 515 B 0 B
assets/js/chunk-fonts-********************.js 43.7 kB 0 B
assets/js/chunk-web-stories-template-0-********************.js 10.2 kB 0 B
assets/js/chunk-web-stories-template-1-********************.js 10.2 kB 0 B
assets/js/chunk-web-stories-template-2-********************.js 9.97 kB 0 B
assets/js/chunk-web-stories-template-3-********************.js 10.5 kB 0 B
assets/js/chunk-web-stories-template-4-********************.js 10.6 kB 0 B
assets/js/chunk-web-stories-template-5-********************.js 6.83 kB 0 B
assets/js/chunk-web-stories-template-6-********************.js 9.87 kB 0 B
assets/js/chunk-web-stories-template-7-********************.js 9.75 kB 0 B
assets/js/chunk-web-stories-textset-0-********************.js 5.25 kB 0 B
assets/js/chunk-web-stories-textset-1-********************.js 6.58 kB 0 B
assets/js/chunk-web-stories-textset-2-********************.js 7.83 kB 0 B
assets/js/chunk-web-stories-textset-3-********************.js 15.2 kB 0 B
assets/js/chunk-web-stories-textset-4-********************.js 4.38 kB 0 B
assets/js/chunk-web-stories-textset-5-********************.js 5.68 kB 0 B
assets/js/chunk-web-stories-textset-6-********************.js 5.47 kB 0 B
assets/js/chunk-web-stories-textset-7-********************.js 10.3 kB 0 B
assets/js/edit-story.js 528 kB 0 B
assets/js/stories-dashboard.js 593 kB 0 B
assets/js/web-stories-activation-notice.js 74.1 kB 0 B
assets/js/web-stories-embed-block.js 17.5 kB 0 B

compressed-size-action

@codecov
Copy link
Copy Markdown

codecov bot commented Oct 20, 2020

Codecov Report

Merging #4930 into main will decrease coverage by 0.33%.
The diff coverage is 83.90%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4930      +/-   ##
==========================================
- Coverage   76.15%   75.81%   -0.34%     
==========================================
  Files         920      921       +1     
  Lines       16294    16381      +87     
==========================================
+ Hits        12409    12420      +11     
- Misses       3885     3961      +76     
Flag Coverage Δ
#karmatests 52.44% <ø> (-3.00%) ⬇️
#unittests 65.72% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
includes/Compatibility.php 83.90% <83.90%> (ø)
assets/src/edit-story/utils/loadStylesheet.js 0.00% <0.00%> (-100.00%) ⬇️
assets/src/edit-story/app/font/fontProvider.js 42.00% <0.00%> (-22.00%) ⬇️
...components/library/panes/text/textSets/textSets.js 64.70% <0.00%> (-20.59%) ⬇️
assets/src/edit-story/utils/localStore.js 85.71% <0.00%> (-14.29%) ⬇️
...s/src/edit-story/elements/media/useAverageColor.js 78.57% <0.00%> (-14.29%) ⬇️
...it-story/components/library/panes/text/textPane.js 85.71% <0.00%> (-14.29%) ⬇️
...src/edit-story/components/library/libraryLayout.js 87.50% <0.00%> (-12.50%) ⬇️
...ts/src/edit-story/components/panels/panel/panel.js 68.42% <0.00%> (-12.29%) ⬇️
...dit-story/components/fontPicker/fontSearchInput.js 80.00% <0.00%> (-12.00%) ⬇️
... and 11 more

@spacedmonkey
Copy link
Copy Markdown
Contributor Author

CC @westonruter and @schlessera as this PR may interest them.

@spacedmonkey spacedmonkey requested a review from miina October 21, 2020 09:44
add_action( 'admin_notices', __NAMESPACE__ . '\_print_missing_build_admin_notice' );

if ( ( defined( 'WP_CLI' ) && WP_CLI ) || 'true' === getenv( 'CI' ) || 'cli' === PHP_SAPI ) {
// In CLI context, existence of the JS files is not required.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's ditch this.

While existence of the JS files is not required in CLI context, this should be surfaced to the user nonetheless, because it still means the plugin is incomplete and not working as expected.

That means we can use the same checks in CLI context and regular context.

That means we can just use one run_checks() method in both places.

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.

@swissspidy I remember why we did this in the first place. Without the javascript files the unit tests fail. Building javascript will take time and massively slow down the phpunit tests runs. I have a workaround here a43bae9

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.

Copy link
Copy Markdown
Collaborator

@swissspidy swissspidy left a comment

Choose a reason for hiding this comment

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

Approved

@swissspidy swissspidy merged commit 46f16e7 into main Nov 2, 2020
@swissspidy swissspidy deleted the feature/compatiblity branch November 2, 2020 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Group: WordPress Changes related to WordPress or Gutenberg integration Type: Enhancement New feature or improvement of an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Check for required PHP extensions upon plugin initialization

3 participants