PluginProbe
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar / 3.2.11
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar v3.2.11
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.11, at includes/Core/Upgrader.php

99 lines 3.6 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 // The onboarding Setup Wizard is only launched for new users on fresh
74 // activation (handled by the activation redirect in NotificationX.php).
75 // Existing users updating the plugin should NOT be sent through the
76 // wizard again, so we only bump the stored version here.
77 $this->database->update_option( 'nx_free_version', NOTIFICATIONX_VERSION, 'no' );
78 $this->clear_transient();
79 }
80 }
81
82 public function clear_transient(){
83 delete_transient('nx_builder_fields');
84 }
85
86 public function migrate_for_donation() {
87 $posts = Database::get_instance()->get_col( Database::$table_posts, 'data', ['type' => 'donation'] );
88
89 if ( ! empty( $posts ) ) {
90 foreach( $posts as $post ) {
91 if ( isset( $post['notification-template']['first_param'] ) && $post['notification-template']['first_param'] === 'tag_sales_count' ) {
92 $post['notification-template']['first_param'] = 'tag_donation_count';
93 Database::get_instance()->update_post( Database::$table_posts, ['data' => $post], $post['nx_id'] );
94 }
95 }
96 }
97 }
98 }
99