|
Server : LiteSpeed System : Linux server104.web-hosting.com 4.18.0-513.24.1.lve.1.el8.x86_64 #1 SMP Thu May 9 15:10:09 UTC 2024 x86_64 User : saleoqej ( 6848) PHP Version : 8.0.30 Disable Function : NONE Directory : /home/saleoqej/chijamzacademy.com/wp-content/plugins/notificationx-pro/includes/Core/ |
<?php
/**
* Extension Factory
*
* @package NotificationX\Extensions
*/
namespace NotificationXPro\Core;
use NotificationX\Admin\Cron;
use NotificationX\Core\Upgrader as UpgraderFree;
use NotificationX\GetInstance;
use NotificationXPro\Admin\Settings;
use NotificationXPro\Feature\SalesFeatures;
/**
* Upgrader Class
*/
class Upgrader extends UpgraderFree {
/**
* Initially Invoked when initialized.
*/
public function __construct() {
parent::__construct();
$installed_ver = $this->database->get_option("nx_pro_version", false);
if(!$installed_ver || version_compare($installed_ver, '2.0.0', '<')){
$free_upgraded = $this->database->get_option("notificationx_2x_upgraded", false);
if( $free_upgraded ) {
try {
add_action('plugins_loaded', [$this, 'nx_2x_migration'], 20);
$this->database->update_option('notificationx_pro_2x_upgraded', true, 'no');
} catch (\Exception $th) {
return;
}
$this->database->update_option( 'nx_pro_version', NOTIFICATIONX_PRO_VERSION, 'no' );
}
}
if(!$installed_ver || version_compare($installed_ver, '2.0.2', '<')){
add_action('plugins_loaded', [$this, 'migrate_roles'], 20);
$this->database->update_option( 'nx_pro_version', NOTIFICATIONX_PRO_VERSION, 'no' );
}
if ($installed_ver !== NOTIFICATIONX_PRO_VERSION) {
$this->license_migration();
}
}
public function nx_2x_migration(){
$posts = PostType::get_instance()->get_posts(
[ 'source' => [ 'in', SalesFeatures::get_instance()->sales_count_sources ] ],
'nx_id'
);
if(!empty($posts) && is_array($posts)){
foreach ($posts as $post) {
Cron::get_instance()->set_cron_single($post['nx_id']);
Cron::get_instance()->set_cron($post['nx_id'], 'nx_sales_count_interval');
}
}
}
public function migrate_roles(){
$settings = Settings::get_instance()->get_selected_roles();
$role_cap_map = Settings::get_instance()->get_role_map($settings);
do_action('wpd_add_cap', $role_cap_map);
}
public function license_migration() {
$license_key = get_option( 'notificationx-pro-license-key', false);
if( $license_key !== false ) {
$license_status = get_option( 'notificationx-pro-license-status');
$license_data = get_transient( 'notificationx-pro-license_data');
update_option( NOTIFICATIONX_PRO_SL_DB_PREFIX . "_license", $license_key, 'no' );
update_option( NOTIFICATIONX_PRO_SL_DB_PREFIX . "_license_status", $license_status, 'no' );
set_transient( NOTIFICATIONX_PRO_SL_DB_PREFIX . "_license_data", $license_data, MONTH_IN_SECONDS * 3 );
}
}
}