Merge pull request #743 from mailpoet/vendor_conflict
Add dependency checking requirement [MAILPOET-690]
This commit is contained in:
@@ -22,10 +22,11 @@ class Initializer {
|
||||
}
|
||||
|
||||
function init() {
|
||||
$requiments_check_results = $this->checkRequirements();
|
||||
$requirements_check_results = $this->checkRequirements();
|
||||
|
||||
// abort initialization if PDO extension is missing
|
||||
if(!$requiments_check_results[RequirementsChecker::TEST_PDO_EXTENSION]) return;
|
||||
if(!$requirements_check_results[RequirementsChecker::TEST_PDO_EXTENSION] ||
|
||||
!$requirements_check_results[RequirementsChecker::TEST_VENDOR_SOURCE]) return;
|
||||
|
||||
$this->setupDB();
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace MailPoet\Config;
|
||||
|
||||
use MailPoet\Config\Env;
|
||||
use MailPoet\Util\Helpers;
|
||||
use MailPoet\WP\Notice as WPNotice;
|
||||
|
||||
@@ -11,7 +12,30 @@ class RequirementsChecker {
|
||||
const TEST_FOLDER_PERMISSIONS = 'TempAndCacheFolderCreation';
|
||||
const TEST_PDO_EXTENSION = 'PDOExtension';
|
||||
const TEST_MBSTRING_EXTENSION = 'MbstringExtension';
|
||||
const TEST_VENDOR_SOURCE = 'VendorSource';
|
||||
|
||||
public $display_error_notice;
|
||||
public $vendor_classes = array(
|
||||
'\ORM',
|
||||
'\Model',
|
||||
'\Twig_Environment',
|
||||
'\Twig_Loader_Filesystem',
|
||||
'\Twig_Lexer',
|
||||
'\Twig_Extension',
|
||||
'\Twig_Extension_GlobalsInterface',
|
||||
'\Twig_SimpleFunction',
|
||||
'\Swift_Mailer',
|
||||
'\Swift_SmtpTransport',
|
||||
'\Swift_Message',
|
||||
'\Carbon\Carbon',
|
||||
'\Sudzy\ValidModel',
|
||||
'\Sudzy\ValidationException',
|
||||
'\Sudzy\Engine',
|
||||
'\pQuery',
|
||||
'\Cron\CronExpression',
|
||||
'\Html2Text\Html2Text',
|
||||
'\csstidy'
|
||||
);
|
||||
|
||||
function __construct($display_error_notice = true) {
|
||||
$this->display_error_notice = $display_error_notice;
|
||||
@@ -22,7 +46,8 @@ class RequirementsChecker {
|
||||
self::TEST_PDO_EXTENSION,
|
||||
self::TEST_PHP_VERSION,
|
||||
self::TEST_FOLDER_PERMISSIONS,
|
||||
self::TEST_MBSTRING_EXTENSION
|
||||
self::TEST_MBSTRING_EXTENSION,
|
||||
self::TEST_VENDOR_SOURCE
|
||||
);
|
||||
$results = array();
|
||||
foreach($available_tests as $test) {
|
||||
@@ -84,6 +109,43 @@ class RequirementsChecker {
|
||||
return true;
|
||||
}
|
||||
|
||||
function checkVendorSource() {
|
||||
foreach($this->vendor_classes as $dependency) {
|
||||
$dependency_path = $this->getDependencyPath($dependency);
|
||||
if(!$dependency_path) {
|
||||
$error = sprintf(
|
||||
__('A MailPoet dependency (%s) does not appear to be loaded correctly, thus MailPoet will not work correctly. Please reinstall the plugin.', 'mailpoet'),
|
||||
$dependency
|
||||
);
|
||||
|
||||
return $this->processError($error);
|
||||
}
|
||||
|
||||
$pattern = '#' . preg_quote(Env::$path) . '[\\\/]#';
|
||||
$is_loaded_by_plugin = preg_match($pattern, $dependency_path);
|
||||
if(!$is_loaded_by_plugin) {
|
||||
$error = sprintf(
|
||||
__('MailPoet has detected a dependency conflict (%s) with another plugin (%s), which may cause unexpected behavior. Please disable the offending plugin to fix this issue.', 'mailpoet'),
|
||||
$dependency,
|
||||
$dependency_path
|
||||
);
|
||||
|
||||
return $this->processError($error);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function getDependencyPath($namespaced_class) {
|
||||
try {
|
||||
$reflector = new \ReflectionClass($namespaced_class);
|
||||
return $reflector->getFileName();
|
||||
} catch(\ReflectionException $ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function processError($error) {
|
||||
if($this->display_error_notice) {
|
||||
WPNotice::displayError($error);
|
||||
|
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
namespace MailPoet\Util;
|
||||
use \Sunra\PhpSimple\HtmlDomParser;
|
||||
use csstidy;
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user