PluginProbe
YayMail – WooCommerce Email Customizer / 4.3.3
YayMail – WooCommerce Email Customizer v4.3.3
4.4.4 4.4.3 4.4.2 4.4.1 trunk 1.9.6 2.1.4 2.1.5 3.2.2 3.2.6 3.2.7.1 3.2.8.1 3.2.9 3.3 3.3.1 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4 3.4.1 3.4.2 3.4.3 All 55 releases
← All changes | src/Models/MigrationModel.php +5 -43 trunk4.3.3 View file →
@@ -21,36 +21,8 @@
21 21 private function __construct() {
22 22 $this->logger = new Logger();
23 23 }
24 24
25 - /**
26 - * Safely unserialize values coming from backup/import data.
27 - *
28 - * @param mixed $value The value to unserialize.
29 - * @return mixed
30 - */
31 - private function safe_maybe_unserialize( $value ) {
32 - if ( ! is_string( $value ) ) {
33 - return $value;
34 - }
35 -
36 - if ( ! function_exists( 'is_serialized' ) || ! is_serialized( $value ) ) {
37 - return $value;
38 - }
39 -
40 - $unserialized = @unserialize( $value, [ 'allowed_classes' => false ] );
41 -
42 - if ( false === $unserialized && 'b:0;' !== $value ) {
43 - return $value;
44 - }
45 -
46 - if ( is_object( $unserialized ) ) {
47 - return $value;
48 - }
49 -
50 - return $unserialized;
51 - }
52 -
53 25 public function get_onload_data() {
54 26 return [
55 27 'required_migrations' => $this->get_required_migration_names(),
56 28 'backups' => $this->get_backups(),
@@ -123,11 +95,8 @@
123 95 // Restore the backed-up posts
124 96 $backed_up_posts = $backup['posts'];
125 97 $backed_up_postmeta = $backup['postmeta'];
126 98 foreach ( $backed_up_posts as $post ) {
127 - if ( ! isset( $post->post_type ) || 'yaymail_template' !== $post->post_type ) {
128 - continue;
129 - }
130 99 $wpdb->insert(
131 100 $wpdb->posts,
132 101 [
133 102 'post_author' => $post->post_author,
@@ -164,16 +133,9 @@
164 133 }
165 134 );
166 135 if ( ! empty( $postmetas_for_current_post ) ) {
167 136 foreach ( $postmetas_for_current_post as $postmeta ) {
168 - if ( ! isset( $postmeta->meta_key ) || strpos( (string) $postmeta->meta_key, 'yaymail' ) === false ) {
169 - continue;
170 - }
171 - add_post_meta(
172 - $inserted_post_id,
173 - $postmeta->meta_key,
174 - $this->safe_maybe_unserialize( $postmeta->meta_value )
175 - );
137 + add_post_meta( $inserted_post_id, $postmeta->meta_key, maybe_unserialize( $postmeta->meta_value ) );
176 138 }
177 139 }
178 140 }//end foreach
179 141
@@ -180,9 +142,9 @@
180 142 // Restore backed-up options
181 143 foreach ( $backup['options'] as $option ) {
182 144 // Only restore options that belong to YayMail (same pattern as export)
183 145 if ( strpos( $option->option_name, 'yaymail' ) !== false ) {
184 - update_option( $option->option_name, $this->safe_maybe_unserialize( $option->option_value ) );
146 + update_option( $option->option_name, maybe_unserialize( $option->option_value ) );
185 147 }
186 148 }
187 149
188 150 // Remove the succeeded migration log from db
@@ -254,9 +216,9 @@
254 216 }
255 217
256 218 private function get_required_migration_names() {
257 219 $old_version = MigrationHelper::format_version_number( get_option( 'yaymail_version' ) );
258 - $new_version = MigrationHelper::format_version_number( yaymail_version() );
220 + $new_version = MigrationHelper::format_version_number( YAYMAIL_VERSION );
259 221 $successful_migrations = get_option( AbstractMigration::SUCCESSFUL_MIGRATIONS, [] );
260 222
261 223 // If freshly installed or already on latest version with no migrations needed
262 224 if ( ( version_compare( $old_version, $new_version, '>=' ) && empty( $successful_migrations ) ) ) {
@@ -277,9 +239,9 @@
277 239 }
278 240
279 241 // Check if any migrations have already been run up to current version
280 242 foreach ( $successful_migrations as $migration ) {
281 - if ( empty( $migration['addon_namespace'] ) && version_compare( $migration['to_version'], yaymail_version(), '>=' ) ) {
243 + if ( empty( $migration['addon_namespace'] ) && version_compare( $migration['to_version'], YAYMAIL_VERSION, '>=' ) ) {
282 244 return apply_filters( 'yaymail_required_migration_names', [] );
283 245 }
284 246 }
285 247
@@ -304,9 +266,9 @@
304 266 $backups_result = $wpdb->get_results( $backup_options_query );// phpcs:ignore
305 267
306 268 $backups = [];
307 269 foreach ( $backups_result as $backup ) {
308 - $data = $this->safe_maybe_unserialize( $backup->option_value );
270 + $data = maybe_unserialize( $backup->option_value );
309 271 $backups[] = [
310 272 'created_date' => $data['created_date'] ?? 'created_date not found',
311 273 'name' => $backup->option_name ?? 'backup name not found',
312 274 ];