Diff: STRATO-apps/wordpress_03/app/wp-content/themes/blocksy/inc/classes/db-versioning/v2-0-96.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
3
+
namespace Blocksy\DbVersioning;
4
+
5
+
class V2096 {
6
+
public function migrate() {
7
+
$this->migrate_brands_slug();
8
+
$this->migrate_product_brand_terms();
9
+
10
+
flush_rewrite_rules();
11
+
}
12
+
13
+
private function migrate_brands_slug() {
14
+
if (! class_exists('\Blocksy\Extensions\WoocommerceExtra\Storage')) {
15
+
return;
16
+
}
17
+
18
+
$storage = new \Blocksy\Extensions\WoocommerceExtra\Storage();
19
+
$settings = $storage->get_settings();
20
+
21
+
if (
22
+
isset($settings['product-brands-slug'])
23
+
&&
24
+
$settings['product-brands-slug'] !== 'brand'
25
+
&&
26
+
get_option('woocommerce_product_brand_slug', '__empty__') === '__empty__'
27
+
) {
28
+
update_option(
29
+
'woocommerce_product_brand_slug',
30
+
$settings['product-brands-slug']
31
+
);
32
+
}
33
+
}
34
+
35
+
private function process_site() {
36
+
$taxonomy = 'product_brands';
37
+
38
+
global $wpdb;
39
+
40
+
$results = $wpdb->get_results(
41
+
$wpdb->prepare(
42
+
"
43
+
SELECT t.term_id, t.name, t.slug
44
+
FROM {$wpdb->terms} AS t
45
+
INNER JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id
46
+
WHERE tt.taxonomy = %s
47
+
",
48
+
$taxonomy
49
+
)
50
+
);
51
+
52
+
if (
53
+
! $results
54
+
||
55
+
empty($results)
56
+
) {
57
+
return;
58
+
}
59
+
60
+
foreach ($results as $term) {
61
+
$native_brand = get_term_by(
62
+
'slug',
63
+
$term->slug,
64
+
'product_brand'
65
+
);
66
+
67
+
if ($native_brand) {
68
+
wp_delete_term(
69
+
$native_brand->term_id,
70
+
'product_brand'
71
+
);
72
+
}
73
+
74
+
$options = blocksy_get_taxonomy_options($term->term_id);
75
+
76
+
if (
77
+
! $options
78
+
||
79
+
empty($options)
80
+
) {
81
+
continue;
82
+
}
83
+
84
+
update_term_meta(
85
+
$term->term_id,
86
+
'thumbnail_id',
87
+
sanitize_text_field(wp_unslash(
88
+
isset($options['icon_image']['attachment_id']) ? $options['icon_image']['attachment_id'] : ''
89
+
))
90
+
);
91
+
92
+
unset($options['icon_image']);
93
+
94
+
update_term_meta(
95
+
$term->term_id,
96
+
'blocksy_taxonomy_meta_options',
97
+
$options
98
+
);
99
+
}
100
+
101
+
$wpdb->update(
102
+
$wpdb->term_taxonomy,
103
+
[
104
+
'taxonomy' => 'product_brand'
105
+
],
106
+
[
107
+
'taxonomy' => 'product_brands'
108
+
]
109
+
);
110
+
111
+
$wpdb->update(
112
+
$wpdb->prefix . 'blocksy_product_taxonomies_lookup',
113
+
[
114
+
'taxonomy' => 'product_brand'
115
+
],
116
+
[
117
+
'taxonomy' => 'product_brands'
118
+
]
119
+
);
120
+
}
121
+
122
+
private function migrate_product_brand_terms() {
123
+
124
+
if (! is_multisite()) {
125
+
$this->process_site();
126
+
return;
127
+
}
128
+
129
+
if ( ! function_exists( 'get_sites' ) ) {
130
+
require_once ABSPATH . 'wp-includes/class-wp-site-query.php';
131
+
require_once ABSPATH . 'wp-includes/ms-site.php';
132
+
}
133
+
134
+
$blog_list = get_sites();
135
+
136
+
if (
137
+
! $blog_list
138
+
||
139
+
empty($blog_list)
140
+
) {
141
+
return;
142
+
}
143
+
144
+
foreach ($blog_list as $blog) {
145
+
switch_to_blog($blog->blog_id);
146
+
$this->process_site();
147
+
148
+
restore_current_blog();
149
+
}
150
+
}
151
+
}
152
+
153
+