Diff: STRATO-apps/wordpress_03/app/wp-content/themes/blocksy/inc/classes/db-versioning/v2-0-0.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
3
+
namespace Blocksy\DbVersioning;
4
+
5
+
class V200 {
6
+
public function migrate() {
7
+
$this->migrate_sale_badge();
8
+
$this->migrate_woocommerce_extra_features();
9
+
$this->migrate_post_types_extra_features();
10
+
$this->migrate_single_product();
11
+
$this->migrate_archive_card();
12
+
$this->migrate_image_sizes();
13
+
14
+
new \Blocksy\LegacyWidgetsTransformer();
15
+
16
+
$values_cleaner = new \Blocksy\DbVersioning\DefaultValuesCleaner();
17
+
18
+
$values_cleaner->clean_header();
19
+
$values_cleaner->clean_footer();
20
+
21
+
$this->cleanup_color_palette_theme_mod();
22
+
23
+
$should_migrate_color_palette = apply_filters(
24
+
'blocksy:db-versioning:v2:should-migrate-color-palette',
25
+
true
26
+
);
27
+
28
+
if ($should_migrate_color_palette) {
29
+
$did_migrate = $this->migrate_color_palette();
30
+
31
+
wp_cache_flush();
32
+
33
+
if ($did_migrate) {
34
+
return 'RETRY';
35
+
}
36
+
37
+
$r = new \Blocksy\Database\SearchReplace();
38
+
39
+
$result = $r->invoke([
40
+
'old' => 'paletteColor',
41
+
'new' => 'theme-palette-color-'
42
+
]);
43
+
44
+
if ($result && isset($result['total']) && $result['total'] > 0) {
45
+
return 'RETRY';
46
+
}
47
+
}
48
+
}
49
+
50
+
public function migrate_post_types_extra_features() {
51
+
$blocksy_ext_post_types_extra_settings = get_option(
52
+
'blocksy_ext_post_types_extra_settings',
53
+
'__empty__'
54
+
);
55
+
56
+
if ($blocksy_ext_post_types_extra_settings !== '__empty__') {
57
+
return;
58
+
}
59
+
60
+
if (
61
+
in_array(
62
+
'post-types-extra',
63
+
get_option('blocksy_active_extensions', [])
64
+
)
65
+
) {
66
+
update_option(
67
+
'blocksy_ext_post_types_extra_settings',
68
+
[
69
+
'features' => [
70
+
'read-time' => true,
71
+
'dynamic-data' => true,
72
+
'filtering' => true,
73
+
'taxonomies-customization' => true
74
+
]
75
+
]
76
+
);
77
+
}
78
+
}
79
+
80
+
public function migrate_woocommerce_extra_features() {
81
+
$blocksy_ext_woocommerce_extra_settings = get_option(
82
+
'blocksy_ext_woocommerce_extra_settings',
83
+
'__empty__'
84
+
);
85
+
86
+
if ($blocksy_ext_woocommerce_extra_settings !== '__empty__') {
87
+
return;
88
+
}
89
+
90
+
$should_update = false;
91
+
92
+
$woo_extra_settings = [
93
+
'features' => [
94
+
'floating-cart' => false,
95
+
'quick-view' => false,
96
+
'filters' => false,
97
+
'wishlist' => false,
98
+
'single-product-share-box' => false,
99
+
'advanced-gallery' => false,
100
+
'search-by-sku' => false,
101
+
'free-shipping' => false,
102
+
'variation-swatches' => false,
103
+
'product-brands' => false,
104
+
'product-affiliates' => false
105
+
],
106
+
107
+
'product-brands-slug' => 'brand'
108
+
];
109
+
110
+
if (
111
+
in_array(
112
+
'woocommerce-extra',
113
+
get_option('blocksy_active_extensions', [])
114
+
)
115
+
) {
116
+
$woo_extra_settings['advanced-gallery'] = true;
117
+
118
+
if (
119
+
get_theme_mod('has_archive_wishlist', 'no') === 'yes'
120
+
||
121
+
get_theme_mod('has_single_wishlist', 'no') === 'yes'
122
+
||
123
+
get_theme_mod('has_quick_view_wishlist', 'no') === 'yes'
124
+
) {
125
+
$woo_extra_settings['wishlist'] = true;
126
+
}
127
+
}
128
+
129
+
$has_floating_bar = get_theme_mod('has_floating_bar', '__empty__');
130
+
131
+
if ($has_floating_bar !== '__empty__') {
132
+
$woo_extra_settings['features'][
133
+
'floating-cart'
134
+
] = $has_floating_bar === 'yes';
135
+
136
+
$should_update = true;
137
+
}
138
+
139
+
$woocommerce_quickview_enabled = get_theme_mod(
140
+
'woocommerce_quickview_enabled',
141
+
'__empty__'
142
+
);
143
+
if ($woocommerce_quickview_enabled !== '__empty__') {
144
+
$woo_extra_settings['features'][
145
+
'quick-view'
146
+
] = $woocommerce_quickview_enabled === 'yes';
147
+
148
+
$should_update = true;
149
+
}
150
+
151
+
if ($should_update) {
152
+
update_option(
153
+
'blocksy_ext_woocommerce_extra_settings',
154
+
$woo_extra_settings
155
+
);
156
+
}
157
+
}
158
+
159
+
public function migrate_sale_badge() {
160
+
$sale_badge_custom_value = get_theme_mod(
161
+
'sale_badge_custom_value',
162
+
'__empty__'
163
+
);
164
+
165
+
if ($sale_badge_custom_value !== '__empty__') {
166
+
set_theme_mod(
167
+
'sale_badge_custom_value',
168
+
str_replace('[value]', '{value}', $sale_badge_custom_value)
169
+
);
170
+
}
171
+
172
+
$has_sale_badge = get_theme_mod('has_sale_badge', '__empty__');
173
+
$has_product_single_onsale = get_option(
174
+
'has_product_single_onsale',
175
+
'__empty__'
176
+
);
177
+
178
+
if ($has_sale_badge === '__empty__' || is_array($has_sale_badge)) {
179
+
return;
180
+
}
181
+
182
+
$future_value = [
183
+
'archive' => true,
184
+
'single' => true
185
+
];
186
+
187
+
$future_value['archive'] = $has_sale_badge === 'yes';
188
+
189
+
if ($has_product_single_onsale !== '__empty__') {
190
+
$future_value['single'] = $has_product_single_onsale === 'yes';
191
+
}
192
+
193
+
set_theme_mod('has_sale_badge', $future_value);
194
+
}
195
+
196
+
public function migrate_single_product() {
197
+
if (! function_exists('blocksy_get_woo_single_layout_defaults')) {
198
+
return;
199
+
}
200
+
201
+
$woo_single_layout = get_theme_mod(
202
+
'woo_single_layout',
203
+
blocksy_get_woo_single_layout_defaults()
204
+
);
205
+
206
+
$has_product_single_title = get_theme_mod(
207
+
'has_product_single_title',
208
+
'__empty__'
209
+
);
210
+
211
+
$has_product_single_rating = get_theme_mod(
212
+
'has_product_single_rating',
213
+
'__empty__'
214
+
);
215
+
216
+
$has_product_single_meta = get_theme_mod(
217
+
'has_product_single_meta',
218
+
'__empty__'
219
+
);
220
+
221
+
$touched = false;
222
+
223
+
foreach ($woo_single_layout as $index => $layer) {
224
+
if (
225
+
$layer['id'] === 'product_title'
226
+
&&
227
+
$has_product_single_title !== '__empty__'
228
+
) {
229
+
$touched = true;
230
+
$woo_single_layout[$index]['enabled'] =
231
+
$has_product_single_title === 'yes';
232
+
}
233
+
234
+
if (
235
+
$layer['id'] === 'product_rating'
236
+
&&
237
+
$has_product_single_rating !== '__empty__'
238
+
) {
239
+
$touched = true;
240
+
$woo_single_layout[$index]['enabled'] =
241
+
$has_product_single_rating === 'yes';
242
+
}
243
+
244
+
if (
245
+
$layer['id'] === 'product_meta'
246
+
&&
247
+
$has_product_single_meta !== '__empty__'
248
+
) {
249
+
$touched = true;
250
+
$woo_single_layout[$index]['enabled'] =
251
+
$has_product_single_meta === 'yes';
252
+
}
253
+
}
254
+
255
+
if ($touched) {
256
+
set_theme_mod('woo_single_layout', $woo_single_layout);
257
+
}
258
+
}
259
+
260
+
public function migrate_archive_card() {
261
+
if (! function_exists('blocksy_get_woo_archive_layout_defaults')) {
262
+
return;
263
+
}
264
+
265
+
$woo_card_layout = get_theme_mod(
266
+
'woo_card_layout',
267
+
blocksy_get_woo_archive_layout_defaults()
268
+
);
269
+
270
+
$touched = false;
271
+
272
+
foreach ($woo_card_layout as $index => $layer) {
273
+
if ($layer['id'] === 'product_image') {
274
+
$blocksy_woocommerce_thumbnail_cropping = get_theme_mod(
275
+
'blocksy_woocommerce_thumbnail_cropping',
276
+
'__empty__'
277
+
);
278
+
279
+
if ($blocksy_woocommerce_thumbnail_cropping !== '__empty__') {
280
+
$touched = true;
281
+
$woo_card_layout[$index]['blocksy_woocommerce_archive_thumbnail_cropping'] = $blocksy_woocommerce_thumbnail_cropping;
282
+
}
283
+
284
+
$product_image_hover = get_theme_mod(
285
+
'product_image_hover',
286
+
'__empty__'
287
+
);
288
+
289
+
if ($product_image_hover !== '__empty__') {
290
+
$touched = true;
291
+
$woo_card_layout[$index]['product_image_hover'] = $product_image_hover;
292
+
}
293
+
294
+
$has_archive_video_thumbnail = get_theme_mod(
295
+
'has_archive_video_thumbnail',
296
+
'__empty__'
297
+
);
298
+
299
+
if ($has_archive_video_thumbnail !== '__empty__') {
300
+
$touched = true;
301
+
$woo_card_layout[$index]['has_archive_video_thumbnail'] = $has_archive_video_thumbnail;
302
+
}
303
+
}
304
+
305
+
if ($layer['id'] === 'product_rating') {
306
+
$has_star_rating = get_theme_mod(
307
+
'has_star_rating',
308
+
'__empty__'
309
+
);
310
+
311
+
if ($has_star_rating !== '__empty__') {
312
+
$touched = true;
313
+
$woo_card_layout[$index]['enabled'] = $has_star_rating === 'yes';
314
+
}
315
+
}
316
+
317
+
if ($layer['id'] === 'product_meta') {
318
+
$has_product_categories = get_theme_mod(
319
+
'has_product_categories',
320
+
'__empty__'
321
+
);
322
+
323
+
if ($has_product_categories !== '__empty__') {
324
+
$touched = true;
325
+
$woo_card_layout[$index]['enabled'] = $has_product_categories === 'yes';
326
+
}
327
+
}
328
+
329
+
if ($layer['id'] === 'product_desc') {
330
+
$has_excerpt = get_theme_mod(
331
+
'has_excerpt',
332
+
'__empty__'
333
+
);
334
+
335
+
$excerpt_length = get_theme_mod(
336
+
'excerpt_length',
337
+
'__empty__'
338
+
);
339
+
340
+
if ($has_excerpt !== '__empty__') {
341
+
$touched = true;
342
+
$woo_card_layout[$index]['enabled'] = $has_excerpt === 'yes';
343
+
}
344
+
345
+
if ($excerpt_length !== '__empty__') {
346
+
$touched = true;
347
+
$woo_card_layout[$index]['excerpt_length'] = $excerpt_length;
348
+
}
349
+
}
350
+
351
+
if (
352
+
$layer['id'] === 'product_add_to_cart'
353
+
||
354
+
$layer['id'] === 'product_add_to_cart_and_price'
355
+
) {
356
+
$has_product_action_button = get_theme_mod(
357
+
'has_product_action_button',
358
+
'__empty__'
359
+
);
360
+
361
+
if ($has_product_action_button !== '__empty__') {
362
+
$touched = true;
363
+
$woo_card_layout[$index]['enabled'] = $has_product_action_button === 'yes';
364
+
}
365
+
}
366
+
}
367
+
368
+
if (
369
+
$touched
370
+
&&
371
+
get_theme_mod('woo_card_layout', '__empty__') === '__empty__'
372
+
) {
373
+
set_theme_mod('woo_card_layout', $woo_card_layout);
374
+
}
375
+
376
+
blocksy_manager()->db_versioning->migrate_options([
377
+
[
378
+
'old' => 'shop_cards_alignment_1',
379
+
'new' => 'shop_cards_alignment'
380
+
]
381
+
]);
382
+
}
383
+
384
+
public function cleanup_color_palette_theme_mod() {
385
+
$colorPalette = get_theme_mod('colorPalette', '__empty__');
386
+
387
+
if ($colorPalette === '__empty__') {
388
+
return;
389
+
}
390
+
391
+
$did_update = false;
392
+
393
+
if (isset($colorPalette['palettes'])) {
394
+
$did_update = true;
395
+
unset($colorPalette['palettes']);
396
+
}
397
+
398
+
if (isset($colorPalette['current_palette'])) {
399
+
$did_update = true;
400
+
unset($colorPalette['current_palette']);
401
+
}
402
+
403
+
if ($did_update) {
404
+
set_theme_mod('colorPalette', $colorPalette);
405
+
}
406
+
}
407
+
408
+
public function migrate_color_palette() {
409
+
$r = new \Blocksy\Database\SearchReplace();
410
+
411
+
$result = $r->invoke([
412
+
'old' => 'paletteColor',
413
+
'new' => 'theme-palette-color-'
414
+
]);
415
+
416
+
$did_migrate = false;
417
+
418
+
if ($result && isset($result['total']) && $result['total'] > 0) {
419
+
$did_migrate = true;
420
+
421
+
$r->invoke([
422
+
'old' => 'var(--color)',
423
+
'new' => 'var(--theme-text-color)',
424
+
'dry_run' => false
425
+
]);
426
+
427
+
$r->invoke([
428
+
'old' => 'paletteColor',
429
+
'new' => 'theme-palette-color-',
430
+
'dry_run' => false
431
+
]);
432
+
433
+
$r->invoke([
434
+
'old' => 'buttonInitialColor',
435
+
'new' => 'theme-button-background-initial-color',
436
+
'dry_run' => false
437
+
]);
438
+
}
439
+
440
+
if (function_exists('gspb_GreenShift_plugin_init')) {
441
+
$greenshift_variables = [
442
+
'--linkInitialColor' => '--theme-link-initial-color',
443
+
'--container-width' => '--theme-container-width',
444
+
'--normal-container-max-width' => '--theme-normal-container-max-width',
445
+
'--narrow-container-max-width' => '--theme-narrow-container-max-width',
446
+
'--buttonFontFamily' => '--theme-button-font-family',
447
+
'--fontFamily' => '--theme-font-family',
448
+
'--buttonFontSize' => '--theme-button-font-size',
449
+
'--buttonFontWeight' => '--theme-button-font-weight',
450
+
'--buttonFontStyle' => '--theme-button-font-style',
451
+
'--buttonLineHeight' => '--theme-button-line-height',
452
+
'--buttonLetterSpacing' => '--theme-button-letter-spacing',
453
+
'--buttonTextTransform' => '--theme-button-text-transform',
454
+
'--buttonTextDecoration' => '--theme-button-text-decoration',
455
+
'--buttonTextInitialColor' => '--theme-button-text-initial-color',
456
+
'--button-border' => '--theme-button-border',
457
+
'--buttonInitialColor' => '--theme-button-background-initial-color',
458
+
'--buttonMinHeight' => '--theme-button-min-height',
459
+
'--buttonBorderRadius' => '--theme-button-border-radius',
460
+
'--button-padding' => '--theme-button-padding',
461
+
'--button-border-hover-color' => '--theme-button-border-hover-color',
462
+
'--buttonTextHoverColor' => '--theme-button-text-hover-color',
463
+
'--buttonHoverColor' => '--theme-button-background-hover-color'
464
+
];
465
+
466
+
foreach ($greenshift_variables as $old => $new) {
467
+
$result = $r->invoke([
468
+
'old' => $old,
469
+
'new' => $new,
470
+
'tables' => [
471
+
_get_meta_table('post')
472
+
]
473
+
]);
474
+
475
+
if ($result && $result['total'] > 0) {
476
+
$r->invoke([
477
+
'old' => $old,
478
+
'new' => $new,
479
+
'tables' => [
480
+
_get_meta_table('post')
481
+
],
482
+
'dry_run' => false
483
+
]);
484
+
}
485
+
}
486
+
}
487
+
488
+
return $did_migrate;
489
+
}
490
+
491
+
public function migrate_image_sizes() {
492
+
$archive_thumbnail = get_option(
493
+
'woocommerce_archive_thumbnail_image_width',
494
+
'__empty__'
495
+
);
496
+
497
+
$thumbnail = get_option(
498
+
'woocommerce_thumbnail_image_width',
499
+
'__empty__'
500
+
);
501
+
502
+
if ($archive_thumbnail !== '__empty__' || $thumbnail === '__empty__') {
503
+
return;
504
+
}
505
+
506
+
update_option(
507
+
'woocommerce_archive_thumbnail_image_width',
508
+
$thumbnail
509
+
);
510
+
511
+
update_option(
512
+
'woocommerce_archive_thumbnail_cropping',
513
+
get_option('woocommerce_thumbnail_cropping', '1:1')
514
+
);
515
+
516
+
update_option(
517
+
'woocommerce_archive_thumbnail_cropping_custom_width',
518
+
get_option('woocommerce_thumbnail_cropping_custom_width', '4')
519
+
);
520
+
521
+
update_option(
522
+
'woocommerce_archive_thumbnail_cropping_custom_height',
523
+
get_option('woocommerce_thumbnail_cropping_custom_height', '3')
524
+
);
525
+
}
526
+
}
527
+