SchedulingLicenseController.php
2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
namespace Wpae\App\Controller;
use PMXE_Plugin;
use Wpae\App\Service\License\LicenseActivator;
use Wpae\Http\JsonResponse;
use Wpae\Scheduling\LicensingManager;
class SchedulingLicenseController
{
/** @var LicensingManager */
private $licensingManager;
/** @var LicenseActivator */
private $licensingActivator;
private $slug = 'wp-all-export-pro';
public function __construct()
{
$this->licensingManager = new LicensingManager();
$this->licensingActivator = new LicenseActivator();
}
public function getSchedulingLicense()
{
$options = \PMXE_Plugin::getInstance()->getOption();
if (empty($options['scheduling_license'])) {
return false;
}
return new JsonResponse(
array(
'license' => $this->licensingManager->checkLicense($options['scheduling_license'], \PMXE_Plugin::getSchedulingName())
)
);
}
public function saveSchedulingLicenseAction()
{
$license = $_POST['license'];
if($this->licensingManager->checkLicense($license, \PMXE_Plugin::getSchedulingName())){
PMXE_Plugin::getInstance()->updateOption(array('scheduling_license' => $license));
$post['license_status'] = $this->check_scheduling_license();
$response = $this->activate_scheduling_licenses();
return new JsonResponse(array('success' => true));
} else {
return new JsonResponse(array('success'=> false));
}
}
/*
*
* Activate licenses for main plugin and all premium addons
*
*/
protected function activate_scheduling_licenses()
{
global $wpdb;
delete_transient(PMXE_Plugin::$cache_key);
$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name = %s", $this->slug . '_' . PMXE_Plugin::$cache_key) );
$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name = %s", $this->slug . '_timeout_' . PMXE_Plugin::$cache_key) );
delete_site_transient('update_plugins');
// retrieve the license from the database
return $this->licensingActivator->activateLicense(PMXE_Plugin::getSchedulingName(),\Wpae\App\Service\License\LicenseActivator::CONTEXT_SCHEDULING);
}
public function check_scheduling_license()
{
$options = PMXE_Plugin::getInstance()->getOption();
global $wpdb;
delete_transient(PMXE_Plugin::$cache_key);
$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name = %s", $this->slug . '_' . PMXE_Plugin::$cache_key) );
$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name = %s", $this->slug . '_timeout_' . PMXE_Plugin::$cache_key) );
return $this->licensingActivator->checkLicense(PMXE_Plugin::getSchedulingName(), $options, LicenseActivator::CONTEXT_SCHEDULING);
}
}