| @@ -25,23 +25,22 @@ | ||
| 25 | 25 | |
| 26 | 26 | if ( self::$first_instilled && version_compare( self::$first_instilled, RTSB_VERSION, '==' ) ) { |
| 27 | 27 | return; |
| 28 | 28 | } |
| 29 | - $v_2_0_4 = ExtraSettings::instance()->get_option( 'settings_migration_v_2_0_4', false ); | |
| 29 | + $v_2_0_4 = ExtraSettings::instance()->get_option( 'settings_migration_v_2_0_4', false ); | |
| 30 | 30 | if ( ! $v_2_0_4 ) { |
| 31 | 31 | self::settings_migration_plugin_v_2_0_4(); |
| 32 | - ExtraSettings::instance()->set_option( 'settings_migration_v_2_0_4', RTSB_VERSION ); | |
| 32 | + ExtraSettings::instance()->set_option( 'settings_migration_v_2_0_4' , RTSB_VERSION ); | |
| 33 | 33 | return; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - $v_2_1_16 = ExtraSettings::instance()->get_option( 'template_settings_migration_v_2_1_16', false ); | |
| 37 | - if ( ! $v_2_1_16 ) { | |
| 38 | - // error_log( print_r( $v_2_1_16 , true) . "\n\n", 3, __DIR__ . '/log.txt' ); | |
| 39 | - self::template_settings_migration_plugin_v_2_1_16(); | |
| 40 | - ExtraSettings::instance()->set_option( 'template_settings_migration_v_2_1_16', RTSB_VERSION ); | |
| 41 | - return; | |
| 42 | - } | |
| 43 | - // return; | |
| 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; | |
| 44 | 43 | } |
| 45 | 44 | /** |
| 46 | 45 | * @return void |
| 47 | 46 | */ |
| @@ -47,12 +46,12 @@ | ||
| 47 | 46 | */ |
| 48 | 47 | private static function remove_option_for_missing_builder_v_2_0_4( $name ) { |
| 49 | 48 | $array = explode( '_', $name ); |
| 50 | 49 | $post_id = end( $array ); |
| 51 | - if ( ! is_numeric( $post_id ) ) { | |
| 50 | + if( ! is_numeric( $post_id ) ){ | |
| 52 | 51 | return; |
| 53 | 52 | } |
| 54 | - if ( get_post_status( $post_id ) ) { | |
| 53 | + if( get_post_status( $post_id ) ){ | |
| 55 | 54 | return; |
| 56 | 55 | } |
| 57 | 56 | TemplateSettings::instance()->delete_option( $name ); |
| 58 | 57 | } |
| @@ -59,26 +58,27 @@ | ||
| 59 | 58 | /** |
| 60 | 59 | * @return void |
| 61 | 60 | */ |
| 62 | 61 | public static function settings_migration_plugin_v_2_0_4() { |
| 62 | + // Prefixes to search for | |
| 63 | 63 | global $wpdb; |
| 64 | - // Prefixes to search for. | |
| 64 | + // Prefixes to search for | |
| 65 | 65 | $prefixes = [ |
| 66 | 66 | 'rtsb_tb_template', |
| 67 | 67 | 'rtsb_template_specific', |
| 68 | - 'rtsb_template_for', | |
| 68 | + 'rtsb_template_for' | |
| 69 | 69 | ]; |
| 70 | 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 ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 77 | - if ( $options_with_prefix ) { | |
| 78 | - foreach ( $options_with_prefix as $option ) { | |
| 79 | - $value = maybe_unserialize( $option->option_value ); | |
| 80 | - if ( ! empty( $value ) ) { | |
| 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 | 81 | TemplateSettings::instance()->set_option( $option->option_name, $value ); |
| 82 | 82 | } |
| 83 | 83 | delete_option( $option->option_name ); |
| 84 | 84 | self::remove_option_for_missing_builder_v_2_0_4( $option->option_name ); |
| @@ -90,46 +90,27 @@ | ||
| 90 | 90 | $extra_prefixes = [ |
| 91 | 91 | 'rtsb_version', |
| 92 | 92 | 'rtsb_wishlist_db_version', |
| 93 | 93 | 'rtsb_compare_db_version', |
| 94 | - 'rtsbpro_version', | |
| 94 | + 'rtsbpro_version' | |
| 95 | 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 ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 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 ); | |
| 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 | 107 | } |
| 108 | 108 | delete_option( $option->option_name ); |
| 109 | 109 | } |
| 110 | 110 | } |
| 111 | 111 | } |
| 112 | + | |
| 113 | + | |
| 112 | 114 | } |
| 113 | 115 | |
| 114 | - /** | |
| 115 | - * @return void | |
| 116 | - */ | |
| 117 | - private static function template_settings_migration_plugin_v_2_1_16() { | |
| 118 | - $args = [ | |
| 119 | - 'post_type' => BuilderFns::$post_type_tb, | |
| 120 | - 'numberposts' => -1, | |
| 121 | - 'fields' => 'ids', | |
| 122 | - ]; | |
| 123 | - $posts_id = get_posts( $args ); | |
| 124 | - if ( ! empty( $posts_id ) ) { | |
| 125 | - foreach ( $posts_id as $id ) { | |
| 126 | - $template_type = BuilderFns::builder_type( $id ); | |
| 127 | - $options_name = BuilderFns::option_name_by_template_id( $id ); | |
| 128 | - $product_ids = TemplateSettings::instance()->get_option( $options_name ); | |
| 129 | - if ( 'product' === $template_type && ! empty( $product_ids ) ) { | |
| 130 | - update_post_meta( $id, '_is_product_page_template_for', 'specific_products' ); | |
| 131 | - } | |
| 132 | - } | |
| 133 | - } | |
| 134 | - } | |
| 135 | -} | |
| 116 | +} | |