diff --git a/dist/feca_mailshots_plugin-1.0.30.zip b/dist/feca_mailshots_plugin-1.0.30.zip new file mode 100644 index 0000000..9cdf3f5 Binary files /dev/null and b/dist/feca_mailshots_plugin-1.0.30.zip differ diff --git a/feca_mailshots_plugin/feca_mailshots_plugin.php b/feca_mailshots_plugin/feca_mailshots_plugin.php index 33725af..9ab2dc0 100644 --- a/feca_mailshots_plugin/feca_mailshots_plugin.php +++ b/feca_mailshots_plugin/feca_mailshots_plugin.php @@ -3,7 +3,7 @@ * Plugin Name: FECA Mailshots * Plugin URI: https://fenedge.co.uk/ * Description: FECA mailshots plugin. - * Version: 1.0.29 + * Version: 1.0.31 * Requires at least: 6.0 * Requires PHP: 7.4 * Author: FECA diff --git a/feca_mailshots_plugin/src/autoload.php b/feca_mailshots_plugin/src/autoload.php index 86e3c24..81a73a2 100644 --- a/feca_mailshots_plugin/src/autoload.php +++ b/feca_mailshots_plugin/src/autoload.php @@ -8,12 +8,41 @@ $autoloadCandidates = [ dirname(__DIR__, 2) . '/vendor/autoload.php', // Backward-compatible: workspace/shared vendor ]; foreach ($autoloadCandidates as $composerAutoload) { - if (is_file($composerAutoload)) { - require_once $composerAutoload; + if (is_file($composerAutoload) && feca_mailshots_composer_autoload_is_usable($composerAutoload)) { + try { + require_once $composerAutoload; + } catch (\Throwable $e) { + error_log('FECA Mailshots skipped unusable Composer autoload: ' . $e->getMessage()); + continue; + } break; } } +function feca_mailshots_composer_autoload_is_usable(string $composerAutoload): bool +{ + $vendorDir = dirname($composerAutoload); + $autoloadFiles = $vendorDir . '/composer/autoload_files.php'; + if (!is_file($autoloadFiles)) { + return true; + } + + $files = require $autoloadFiles; + if (!is_array($files)) { + error_log('FECA Mailshots Composer autoload_files.php did not return an array.'); + return false; + } + + foreach ($files as $file) { + if (!is_string($file) || !is_file($file)) { + error_log('FECA Mailshots Composer dependency file is missing: ' . (is_scalar($file) ? (string) $file : 'unknown')); + return false; + } + } + + return true; +} + spl_autoload_register(static function (string $class): void { $prefix = 'FecaMailshots\\'; if (strncmp($class, $prefix, strlen($prefix)) !== 0) { diff --git a/scripts/deploy_remote.sh b/scripts/deploy_remote.sh index 83dda37..65d1f17 100755 --- a/scripts/deploy_remote.sh +++ b/scripts/deploy_remote.sh @@ -174,6 +174,7 @@ else echo "Error: ${LOCAL_VENDOR_DIR}/autoload.php is missing. Install dependencies first (scripts/install_dependencies.sh)." >&2 exit 1 fi + php "${REPO_ROOT}/scripts/validate_composer_vendor.php" "${LOCAL_VENDOR_DIR}" fi ssh -p "${SSH_PORT}" \ @@ -217,5 +218,11 @@ rsync "${VENDOR_RSYNC_ARGS[@]}" \ if [[ "${DRY_RUN}" -eq 1 ]]; then echo "Dry-run complete. No remote files were changed." else + ssh -p "${SSH_PORT}" \ + -i "${SSH_KEY_PATH}" \ + -o BatchMode=yes \ + -o StrictHostKeyChecking=accept-new \ + "${SSH_TARGET}" \ + "test -f '${REMOTE_DIR}/vendor/autoload.php' && test -f '${REMOTE_DIR}/vendor/thecodingmachine/safe/lib/special_cases.php'" echo "Deploy complete." fi diff --git a/scripts/package_plugin.sh b/scripts/package_plugin.sh index b187c0a..77c1f55 100755 --- a/scripts/package_plugin.sh +++ b/scripts/package_plugin.sh @@ -94,6 +94,7 @@ if [[ ! -f "${REPO_ROOT}/vendor/autoload.php" ]]; then echo "Error: vendor/autoload.php is missing after dependency install." >&2 exit 1 fi +php "${REPO_ROOT}/scripts/validate_composer_vendor.php" "${REPO_ROOT}/vendor" rsync -a \ --delete \ @@ -108,6 +109,7 @@ rsync -a \ mkdir -p "${STAGE_DIR}/vendor" rsync -a --delete "${REPO_ROOT}/vendor/" "${STAGE_DIR}/vendor/" +php "${REPO_ROOT}/scripts/validate_composer_vendor.php" "${STAGE_DIR}/vendor" ARCHIVE_PATH="${OUTPUT_DIR}/${PLUGIN_BASENAME}-${VERSION}.zip" rm -f "${ARCHIVE_PATH}" diff --git a/scripts/validate_composer_vendor.php b/scripts/validate_composer_vendor.php new file mode 100644 index 0000000..31ca3da --- /dev/null +++ b/scripts/validate_composer_vendor.php @@ -0,0 +1,39 @@ +