PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.1.6
ShopBuilder – WooCommerce Builder For Elementor v2.1.6
3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.3.0 All 62 releases
shopbuilder / app / Helpers / Migration.php

Migration.php in ShopBuilder – WooCommerce Builder For Elementor 2.1.6, at app/Helpers/Migration.php

116 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 namespace RadiusTheme\SB\Helpers;
4
5 // Do not allow directly accessing this file.
6 use RadiusTheme\SB\Models\ExtraSettings;
7 use RadiusTheme\SB\Models\TemplateSettings;
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit( 'This script cannot be accessed directly.' );
11 }
12
13 class Migration {
14 private static $first_instilled;
15
16 public static function init() {
17 self::$first_instilled = ExtraSettings::instance()->get_option( 'first_instilled_version', false );
18 add_action( 'init', [ __CLASS__, 'the_migration' ], 5 );
19 }
20
21 /**
22 * @return void
23 */
24 public static function the_migration() {
25
26 if ( self::$first_instilled && version_compare( self::$first_instilled, RTSB_VERSION, '==' ) ) {
27 return;
28 }
29 $v_2_0_4 = ExtraSettings::instance()->get_option( 'settings_migration_v_2_0_4', false );
30 if ( ! $v_2_0_4 ) {
31 self::settings_migration_plugin_v_2_0_4();
32 ExtraSettings::instance()->set_option( 'settings_migration_v_2_0_4' , RTSB_VERSION );
33 return;
34 }
35
36 /*
37 * Example Migration
38 else if ( ! AdditionalSettings::instance()->get_option( 'template_settings_migration_v_2_0_4' ) ) {
39 } else if ( ! AdditionalSettings::instance()->get_option( 'template_settings_migration_v_2_0_5' ) ) {
40 }
41 */
42 return;
43 }
44 /**
45 * @return void
46 */
47 private static function remove_option_for_missing_builder_v_2_0_4( $name ) {
48 $array = explode( '_', $name );
49 $post_id = end( $array );
50 if( ! is_numeric( $post_id ) ){
51 return;
52 }
53 if( get_post_status( $post_id ) ){
54 return;
55 }
56 TemplateSettings::instance()->delete_option( $name );
57 }
58 /**
59 * @return void
60 */
61 public static function settings_migration_plugin_v_2_0_4() {
62 // Prefixes to search for
63 global $wpdb;
64 // Prefixes to search for
65 $prefixes = [
66 'rtsb_tb_template',
67 'rtsb_template_specific',
68 'rtsb_template_for'
69 ];
70
71 // Array to store matching options
72 // Loop through each prefix
73 foreach ($prefixes as $prefix) {
74 // Run a direct database query to fetch option names and values
75 $query = $wpdb->prepare("SELECT option_name, option_value FROM {$wpdb->options} WHERE option_name LIKE %s", $wpdb->esc_like($prefix) . '%');
76 $options_with_prefix = $wpdb->get_results($query, OBJECT);
77 if ($options_with_prefix) {
78 foreach ($options_with_prefix as $option) {
79 $value = maybe_unserialize($option->option_value);
80 if( ! empty( $value ) ){
81 TemplateSettings::instance()->set_option( $option->option_name, $value );
82 }
83 delete_option( $option->option_name );
84 self::remove_option_for_missing_builder_v_2_0_4( $option->option_name );
85 }
86 }
87 }
88
89 // Extra Setings.
90 $extra_prefixes = [
91 'rtsb_version',
92 'rtsb_wishlist_db_version',
93 'rtsb_compare_db_version',
94 'rtsbpro_version'
95 ];
96 // Array to store matching options
97 // Loop through each prefix
98 foreach ($extra_prefixes as $prefix) {
99 // Run a direct database query to fetch option names and values
100 $query = $wpdb->prepare("SELECT option_name, option_value FROM {$wpdb->options} WHERE option_name LIKE %s", $wpdb->esc_like($prefix) . '%');
101 $options_with_prefix = $wpdb->get_results($query, OBJECT);
102 if ($options_with_prefix) {
103 foreach ($options_with_prefix as $option) {
104 $value = maybe_unserialize($option->option_value);
105 if( ! empty( $value ) ){
106 ExtraSettings::instance()->set_option( $option->option_name , $value );
107 }
108 delete_option( $option->option_name );
109 }
110 }
111 }
112
113
114 }
115
116 }