Skip to content

Commit

Permalink
Compser: Read once, fail gracefully (and more) (#12442)
Browse files Browse the repository at this point in the history
* Read once, fail gracefully

* Improve inline comment

* Adding more inline documentation on the loading process.

* run composer install on build scripts

* Remove extra slash

`JETPACK__PLUGIN_DIR` already has a trailing slash.

* Restore @jeherve's original soft fallback for unbuilt Jetpack.

This reverts commit 77ee45f.

* Update inline docs at 0238eab
  • Loading branch information
kraftbj authored and jeherve committed May 24, 2019
1 parent 886d264 commit ff16087
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
20 changes: 18 additions & 2 deletions jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ function jetpack_admin_missing_autoloader() { ?>
<?php
}

/**
* This is where the loading of Jetpack begins.
*
* First, we check for our supported version of PHP and load our composer autoloader. If either of these fail,
* we "pause" Jetpack by ending the loading process and displaying an admin_notice to inform the site owner.
*
* After both those things happen successfully, we require the legacy files, then add on to various hooks that we expect
* to always run.
*
* Lastly, we fire Jetpack::init() to fire up the engines.
*/
if ( version_compare( phpversion(), JETPACK__MINIMUM_PHP_VERSION, '<' ) ) {
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
error_log(
Expand All @@ -164,8 +175,13 @@ function jetpack_admin_missing_autoloader() { ?>
return;
}

// Load all the packages.
$jetpack_autoloader = JETPACK__PLUGIN_DIR . '/vendor/autoload.php';
/**
* Load all the packages.
*
* We want to fail gracefully if `composer install` has not been executed yet, so we are checking for the autoloader.
* If the autoloader is not present, let's log the failure, pause Jetpack, and display a nice admin notice.
*/
$jetpack_autoloader = JETPACK__PLUGIN_DIR . 'vendor/autoload.php';
if ( is_readable( $jetpack_autoloader ) ) {
require $jetpack_autoloader;
} else {
Expand Down
9 changes: 9 additions & 0 deletions tools/build-jetpack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ if [[ $ADD_BETA_VERSION -eq 1 ]]; then
echo "Now at version $CURRENT_VERSION!"
fi

# Checking for composer
hash composer 2>/dev/null || {
echo >&2 "This script requires you to have composer package manager installed."
echo >&2 "Please install it following the instructions on https://getcomposer.org/. Aborting.";
exit 1;
}

composer --cwd $TARGET_DIR install

# Checking for yarn
hash yarn 2>/dev/null || {
echo >&2 "This script requires you to have yarn package manager installed."
Expand Down
9 changes: 9 additions & 0 deletions tools/build-release-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,15 @@ echo ""

echo "Building Jetpack"

# Checking for composer
hash composer 2>/dev/null || {
echo >&2 "This script requires you to have composer package manager installed."
echo >&2 "Please install it following the instructions on https://getcomposer.org/. Aborting.";
exit 1;
}

composer install

# Checking for yarn
hash yarn 2>/dev/null || {
echo >&2 "This script requires you to have yarn package manager installed."
Expand Down
9 changes: 9 additions & 0 deletions tools/deploy-to-master-stable-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ echo ""

echo "Building Jetpack"

# Checking for composer
hash composer 2>/dev/null || {
echo >&2 "This script requires you to have composer package manager installed."
echo >&2 "Please install it following the instructions on https://getcomposer.org/. Aborting.";
exit 1;
}

composer install

# Checking for yarn
hash yarn 2>/dev/null || {
echo >&2 "This script requires you to have yarn package manager installed."
Expand Down

0 comments on commit ff16087

Please sign in to comment.