Symlink premium if Dotcom platform

[MAILPOET-5435]
This commit is contained in:
Brezo Cordero
2023-07-20 22:36:25 -05:00
committed by Aschepikov
parent 688d1ff0aa
commit 2d31cc4bc4
2 changed files with 25 additions and 8 deletions

View File

@@ -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'));