Symlink premium if Dotcom platform
[MAILPOET-5435]
This commit is contained in:
committed by
Aschepikov
parent
688d1ff0aa
commit
2d31cc4bc4
@@ -7,11 +7,13 @@ use MailPoet\API\JSON\Error as APIError;
|
||||
use MailPoet\Config\AccessControl;
|
||||
use MailPoet\Config\ServicesChecker;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
use MailPoet\WPCOM\DotcomHelperFunctions;
|
||||
use WP_Error;
|
||||
|
||||
class Premium extends APIEndpoint {
|
||||
const PREMIUM_PLUGIN_SLUG = 'mailpoet-premium';
|
||||
const PREMIUM_PLUGIN_PATH = 'mailpoet-premium/mailpoet-premium.php';
|
||||
const SIMLINK_PATH = '../../../../wordpress/plugins/mailpoet-premium/latest';
|
||||
|
||||
public $permissions = [
|
||||
'global' => AccessControl::PERMISSION_MANAGE_SETTINGS,
|
||||
@@ -23,12 +25,17 @@ class Premium extends APIEndpoint {
|
||||
/** @var WPFunctions */
|
||||
private $wp;
|
||||
|
||||
/** @var DotcomHelperFunctions */
|
||||
private $dotcomHelperFunctions;
|
||||
|
||||
public function __construct(
|
||||
ServicesChecker $servicesChecker,
|
||||
WPFunctions $wp
|
||||
WPFunctions $wp,
|
||||
DotcomHelperFunctions $dotcomHelperFunctions
|
||||
) {
|
||||
$this->servicesChecker = $servicesChecker;
|
||||
$this->wp = $wp;
|
||||
$this->dotcomHelperFunctions = $dotcomHelperFunctions;
|
||||
}
|
||||
|
||||
public function installPlugin() {
|
||||
@@ -46,6 +53,15 @@ class Premium extends APIEndpoint {
|
||||
}
|
||||
|
||||
$pluginInfo = (array)$pluginInfo;
|
||||
|
||||
// If we are in Dotcom platform, we try to symlink the plugin instead of downloading it
|
||||
if ($this->dotcomHelperFunctions->isDotcom()) {
|
||||
$result = symlink(self::SIMLINK_PATH, WP_PLUGIN_DIR . '/' . self::PREMIUM_PLUGIN_SLUG);
|
||||
if ($result === true) {
|
||||
return $this->successResponse();
|
||||
}
|
||||
}
|
||||
|
||||
$result = $this->wp->installPlugin($pluginInfo['download_link']);
|
||||
if ($result !== true) {
|
||||
return $this->error(__('Error when installing MailPoet Premium plugin.', 'mailpoet'));
|
||||
|
@@ -8,6 +8,7 @@ use MailPoet\API\JSON\SuccessResponse;
|
||||
use MailPoet\API\JSON\v1\Premium;
|
||||
use MailPoet\Config\ServicesChecker;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
use MailPoet\WPCOM\DotcomHelperFunctions;
|
||||
|
||||
class PremiumTest extends \MailPoetUnitTest {
|
||||
public function testItInstallsPlugin() {
|
||||
@@ -22,7 +23,7 @@ class PremiumTest extends \MailPoetUnitTest {
|
||||
'installPlugin' => Expected::once(true),
|
||||
]);
|
||||
|
||||
$premium = new Premium($servicesChecker, $wp);
|
||||
$premium = new Premium($servicesChecker, $wp, new DotcomHelperFunctions());
|
||||
$response = $premium->installPlugin();
|
||||
expect($response)->isInstanceOf(SuccessResponse::class);
|
||||
}
|
||||
@@ -37,7 +38,7 @@ class PremiumTest extends \MailPoetUnitTest {
|
||||
'installPlugin' => Expected::never(),
|
||||
]);
|
||||
|
||||
$premium = new Premium($servicesChecker, $wp);
|
||||
$premium = new Premium($servicesChecker, $wp, new DotcomHelperFunctions());
|
||||
$response = $premium->installPlugin();
|
||||
expect($response)->isInstanceOf(ErrorResponse::class);
|
||||
expect($response->getData()['errors'][0])->same([
|
||||
@@ -56,7 +57,7 @@ class PremiumTest extends \MailPoetUnitTest {
|
||||
'installPlugin' => Expected::never(),
|
||||
]);
|
||||
|
||||
$premium = new Premium($servicesChecker, $wp);
|
||||
$premium = new Premium($servicesChecker, $wp, new DotcomHelperFunctions());
|
||||
$response = $premium->installPlugin();
|
||||
expect($response)->isInstanceOf(ErrorResponse::class);
|
||||
expect($response->getData()['errors'][0])->same([
|
||||
@@ -77,7 +78,7 @@ class PremiumTest extends \MailPoetUnitTest {
|
||||
'installPlugin' => Expected::once(false),
|
||||
]);
|
||||
|
||||
$premium = new Premium($servicesChecker, $wp);
|
||||
$premium = new Premium($servicesChecker, $wp, new DotcomHelperFunctions());
|
||||
$response = $premium->installPlugin();
|
||||
expect($response)->isInstanceOf(ErrorResponse::class);
|
||||
expect($response->getData()['errors'][0])->same([
|
||||
@@ -95,7 +96,7 @@ class PremiumTest extends \MailPoetUnitTest {
|
||||
'activatePlugin' => Expected::once(null),
|
||||
]);
|
||||
|
||||
$premium = new Premium($servicesChecker, $wp);
|
||||
$premium = new Premium($servicesChecker, $wp, new DotcomHelperFunctions());
|
||||
$response = $premium->activatePlugin();
|
||||
expect($response)->isInstanceOf(SuccessResponse::class);
|
||||
}
|
||||
@@ -105,7 +106,7 @@ class PremiumTest extends \MailPoetUnitTest {
|
||||
'isPremiumKeyValid' => Expected::once(false),
|
||||
]);
|
||||
|
||||
$premium = new Premium($servicesChecker, new WPFunctions());
|
||||
$premium = new Premium($servicesChecker, new WPFunctions(), new DotcomHelperFunctions());
|
||||
$response = $premium->activatePlugin();
|
||||
expect($response)->isInstanceOf(ErrorResponse::class);
|
||||
expect($response->getData()['errors'][0])->same([
|
||||
@@ -123,7 +124,7 @@ class PremiumTest extends \MailPoetUnitTest {
|
||||
'activatePlugin' => Expected::once('error'),
|
||||
]);
|
||||
|
||||
$premium = new Premium($servicesChecker, $wp);
|
||||
$premium = new Premium($servicesChecker, $wp, new DotcomHelperFunctions());
|
||||
$response = $premium->activatePlugin();
|
||||
expect($response)->isInstanceOf(ErrorResponse::class);
|
||||
expect($response->getData()['errors'][0])->same([
|
||||
|
Reference in New Issue
Block a user