Bundle Twilio + AWS SDKs in releases, add SNS install path
Gitea release workflow now runs composer install --no-dev before zipping, so
each release ships vendor/ with both Twilio and AWS SDKs. The plugin's loader
priority is flipped to match: internal vendor/autoload.php first (always
current after every plugin update), external wp-content/twilio-sdk/ second
(legacy/manual install fallback).
AWS SDK detection wired in alongside Twilio: composer's bundled autoloader
covers Aws\… natively when present; otherwise plugin falls back to a new
external location wp-content/aws-sdk/ via install-aws-sdk-external.sh, which
drops the AWS SDK PHAR with a tiny autoload shim. AWS-missing admin notice
fires only when twp_sms_provider === 'aws_sns' so existing Twilio SMS users
see no new noise.
Loader priority flip applied in three places that all had the same
external-first pattern: twilio-wp-plugin.php (twp_check_sdk_installation),
class-twp-twilio-api.php (init_sdk_client), class-twp-webhooks.php
(constructor). twp_check_sdk_after_update messaging updated to reflect that
plugin updates now bundle the SDK.
Files:
.gitea/workflows/release.yml — composer install before ZIP
twilio-wp-plugin.php — TWP_EXTERNAL_AWS_SDK_DIR, dual-SDK
detection, twp_aws_sdk_missing_notice
includes/class-twp-twilio-api.php — internal-first autoloader
includes/class-twp-webhooks.php — internal-first autoloader
install-aws-sdk-external.sh — new AWS SDK PHAR installer
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
121
install-aws-sdk-external.sh
Executable file
121
install-aws-sdk-external.sh
Executable file
@@ -0,0 +1,121 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script to install AWS SDK for PHP to an external location
|
||||
# This prevents SDK from being deleted when WordPress updates the plugin
|
||||
#
|
||||
# Location: wp-content/aws-sdk/ (outside plugin folder)
|
||||
#
|
||||
# Uses the official single-file PHAR distribution from aws/aws-sdk-php releases.
|
||||
# The PHAR ships its own composer-generated autoloader, so no PSR-4 wiring needed.
|
||||
|
||||
echo "Installing AWS SDK for PHP (latest) to external location..."
|
||||
echo "This will install the SDK outside the plugin folder to survive plugin updates."
|
||||
|
||||
# Check if we can download files
|
||||
if ! command -v curl &> /dev/null; then
|
||||
echo "ERROR: curl is required to download the SDK"
|
||||
echo "Please install curl and try again"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get the script directory (plugin directory)
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
# Calculate wp-content directory (two levels up from plugin)
|
||||
# Plugin is at: wp-content/plugins/twilio-wp-plugin/
|
||||
# We want: wp-content/aws-sdk/
|
||||
WP_CONTENT_DIR="$(dirname "$(dirname "$SCRIPT_DIR")")"
|
||||
SDK_DIR="$WP_CONTENT_DIR/aws-sdk"
|
||||
|
||||
echo "Plugin directory: $SCRIPT_DIR"
|
||||
echo "SDK will be installed to: $SDK_DIR"
|
||||
|
||||
# Create SDK directory
|
||||
mkdir -p "$SDK_DIR"
|
||||
|
||||
# Download the latest PHAR release
|
||||
echo "Downloading AWS SDK PHAR from GitHub..."
|
||||
TEMP_DIR=$(mktemp -d)
|
||||
cd "$TEMP_DIR"
|
||||
|
||||
if ! curl -L https://github.com/aws/aws-sdk-php/releases/latest/download/aws.phar -o aws.phar; then
|
||||
echo "ERROR: Failed to download AWS SDK PHAR"
|
||||
echo "Please check your internet connection and try again"
|
||||
rm -rf "$TEMP_DIR"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Verify the download is non-empty (PHAR is roughly 12 MB)
|
||||
if [ ! -s "$TEMP_DIR/aws.phar" ]; then
|
||||
echo "ERROR: Downloaded AWS SDK PHAR is empty or missing"
|
||||
rm -rf "$TEMP_DIR"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Remove existing SDK if it exists
|
||||
if [ -f "$SDK_DIR/aws.phar" ]; then
|
||||
echo "Removing existing AWS SDK installation..."
|
||||
rm -f "$SDK_DIR/aws.phar"
|
||||
fi
|
||||
|
||||
# Move the PHAR into place
|
||||
echo "Installing SDK files..."
|
||||
if ! mv "$TEMP_DIR/aws.phar" "$SDK_DIR/aws.phar"; then
|
||||
echo "ERROR: Failed to move AWS SDK PHAR into place"
|
||||
rm -rf "$TEMP_DIR"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create the autoloader shim
|
||||
cat > "$SDK_DIR/autoload.php" << 'EOF'
|
||||
<?php
|
||||
/**
|
||||
* AWS SDK for PHP Autoloader (External Installation)
|
||||
* This file loads the AWS SDK via its bundled PHAR distribution.
|
||||
*
|
||||
* Location: wp-content/aws-sdk/autoload.php
|
||||
* This location survives WordPress plugin updates.
|
||||
*
|
||||
* The aws.phar file is the official single-file build from aws/aws-sdk-php
|
||||
* and ships with its own composer-generated autoloader, so all we need to
|
||||
* do is require_once the PHAR itself.
|
||||
*/
|
||||
|
||||
// Prevent multiple registrations
|
||||
if (!defined('TWP_AWS_AUTOLOADER_REGISTERED')) {
|
||||
define('TWP_AWS_AUTOLOADER_REGISTERED', true);
|
||||
|
||||
// The PHAR contains its own autoloader stub; requiring it registers
|
||||
// the AWS\, Aws\, GuzzleHttp\, and supporting namespaces.
|
||||
$aws_phar = __DIR__ . '/aws.phar';
|
||||
if (file_exists($aws_phar)) {
|
||||
require_once $aws_phar;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
# Clean up temp directory
|
||||
cd "$SCRIPT_DIR"
|
||||
rm -rf "$TEMP_DIR"
|
||||
|
||||
# Verify installation
|
||||
echo ""
|
||||
echo "Verifying installation..."
|
||||
if [ -f "$SDK_DIR/aws.phar" ] && [ -s "$SDK_DIR/aws.phar" ] && [ -f "$SDK_DIR/autoload.php" ]; then
|
||||
echo "=============================================="
|
||||
echo "AWS SDK for PHP installed successfully!"
|
||||
echo "=============================================="
|
||||
echo ""
|
||||
echo "Installation location: $SDK_DIR"
|
||||
echo ""
|
||||
echo "This SDK is installed OUTSIDE the plugin folder,"
|
||||
echo "so it will NOT be deleted when WordPress updates the plugin."
|
||||
echo ""
|
||||
echo "Next steps:"
|
||||
echo " 1. In WP admin, open the Twilio plugin Settings page."
|
||||
echo " 2. Switch SMS provider to \"Amazon SNS\"."
|
||||
echo " 3. Enter AWS Access Key, Secret Key, and Region (e.g. us-west-2)."
|
||||
else
|
||||
echo "Installation failed - files not found"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user