PluginProbe
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar / 3.2.8
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar v3.2.8
3.3.1 3.3.0 3.2.14 3.2.13 3.2.12 3.2.11 3.2.10 3.2.9 3.2.8 3.2.7 trunk 0.2.5.5 0.2.5.6 0.2.5.7 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.2.1 All 156 releases
notificationx / includes / Core / Upgrader.php

Upgrader.php in NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar 3.2.8, at includes/Core/Upgrader.php

95 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Extension Factory
5 *
6 * @package NotificationX\Extensions
7 */
8
9 namespace NotificationX\Core;
10
11 use NotificationX\GetInstance;
12 use NotificationX\NotificationX;
13
14 /**
15 * @method static Upgrader get_instance($args = null)
16 */
17 class Upgrader {
18 /**
19 * Instance of Upgrader
20 *
21 * @var Upgrader
22 */
23 use GetInstance;
24
25 protected $database;
26
27 /**
28 * Initially Invoked when initialized.
29 */
30 public function __construct() {
31 $this->database = Database::get_instance();
32 $nx_free_version = $this->database->get_option('nx_free_version');
33 $nx_db_version = $this->database->get_option('nx_db_version');
34
35 // Show milestone notification only for 3.1.10
36 $force_milstone = get_option('notificationx_force_milestone', '');
37 if ( version_compare( NOTIFICATIONX_VERSION, '3.1.10', '==' ) && empty($force_milstone) ) {
38 delete_option('notificationx_milestone_level');
39 }
40
41 // Show popup notification only for 3.1.10
42 $force_popup = get_option('nx_force_popup_dismissed', '');
43 if ( version_compare( NOTIFICATIONX_VERSION, '3.1.10', '==' ) && empty($force_popup) ) {
44 delete_option('nx_initial_popup_dismissed');
45 }
46
47 $_is_table_created = false;
48 if ($nx_db_version === false || $nx_db_version != Database::$version) {
49 try {
50 Database::get_instance()->Create_DB();
51 $this->database->update_option('nx_db_version', Database::$version, 'no');
52 $_is_table_created = true;
53 } catch (\Exception $th) {
54 error_log('NX: Database Creation Failed');
55 }
56 }
57
58 if((!$nx_free_version || version_compare($nx_free_version, '2.0.0', '<')) && $_is_table_created ){
59 try {
60 Migration::get_instance();
61 $this->database->update_option('notificationx_2x_upgraded', true, 'no');
62 } catch (\Exception $th) {
63 error_log('NX: Migration Failed');
64 }
65 $this->database->update_option( 'nx_free_version', NOTIFICATIONX_VERSION, 'no' );
66 } elseif(!$nx_free_version && $_is_table_created ){
67 $this->database->update_option( 'nx_free_version', NOTIFICATIONX_VERSION, 'no' );
68 }
69 if ( version_compare($nx_free_version, '2.8.0', '<=') ) {
70 $this->migrate_for_donation();
71 }
72 if ($nx_free_version !== NOTIFICATIONX_VERSION) {
73 $this->database->update_option( 'nx_free_version', NOTIFICATIONX_VERSION, 'no' );
74 $this->clear_transient();
75 }
76 }
77
78 public function clear_transient(){
79 delete_transient('nx_builder_fields');
80 }
81
82 public function migrate_for_donation() {
83 $posts = Database::get_instance()->get_col( Database::$table_posts, 'data', ['type' => 'donation'] );
84
85 if ( ! empty( $posts ) ) {
86 foreach( $posts as $post ) {
87 if ( isset( $post['notification-template']['first_param'] ) && $post['notification-template']['first_param'] === 'tag_sales_count' ) {
88 $post['notification-template']['first_param'] = 'tag_donation_count';
89 Database::get_instance()->update_post( Database::$table_posts, ['data' => $post], $post['nx_id'] );
90 }
91 }
92 }
93 }
94 }
95