|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* FooVideo Migration Helpers Class |
|
4
|
|
|
*/ |
|
5
|
|
|
if ( ! class_exists( 'FooGallery_Pro_Video_Migration_Helper' ) ) { |
|
6
|
|
|
|
|
7
|
|
|
class FooGallery_Pro_Video_Migration_Helper { |
|
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
public function get_migration_state() { |
|
10
|
|
|
$state = get_option( 'foogallery-video-migration' ); |
|
11
|
|
|
|
|
12
|
|
|
//check for the default state |
|
13
|
|
|
if ( false === $state ) { |
|
14
|
|
|
$state = array( |
|
15
|
|
|
'step' => 0, |
|
16
|
|
|
'button_text' => __( 'Start Migration', 'foogallery' ), |
|
17
|
|
|
'message' => __('The migration will only take a few minutes. Click "Start Migration" to begin.', 'foogallery') |
|
18
|
|
|
); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
return $state; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function save_migration_state( $state ) { |
|
25
|
|
|
if ( get_option( 'foogallery-video-migration' ) !== false ) { |
|
26
|
|
|
update_option( 'foogallery-video-migration', $state ); |
|
27
|
|
|
} else { |
|
28
|
|
|
add_option( 'foogallery-video-migration', $state, null, 'no' ); |
|
29
|
|
|
} |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function run_next_migration_step() { |
|
33
|
|
|
$state = $this->get_migration_state(); |
|
34
|
|
|
|
|
35
|
|
|
if ( 0 === $state['step'] ) { |
|
36
|
|
|
//first we need to identify what needs to be migrated. |
|
37
|
|
|
|
|
38
|
|
|
//how many galleries are using the legacy videoslider template? |
|
39
|
|
|
$gallery_posts = get_posts( array( |
|
40
|
|
|
'fields' => 'ids', |
|
41
|
|
|
'post_type' => FOOGALLERY_CPT_GALLERY, |
|
42
|
|
|
'post_status' => array( 'publish', 'draft' ), |
|
43
|
|
|
'cache_results' => false, |
|
44
|
|
|
'nopaging' => true |
|
45
|
|
|
) ); |
|
46
|
|
|
|
|
47
|
|
|
//how many videos were imported into the media library with the legacy importer? |
|
48
|
|
|
$attachment_posts = get_posts( array( |
|
49
|
|
|
'fields' => 'ids', |
|
50
|
|
|
'post_type' => 'attachment', |
|
51
|
|
|
'cache_results' => false, |
|
52
|
|
|
'nopaging' => true, |
|
53
|
|
|
'meta_query' => array( |
|
54
|
|
|
array( |
|
55
|
|
|
'key' => FOO_VIDEO_POST_META, |
|
56
|
|
|
'compare' => 'EXISTS', |
|
57
|
|
|
) |
|
58
|
|
|
) |
|
59
|
|
|
) ); |
|
60
|
|
|
|
|
61
|
|
|
$state['step'] = 1; |
|
62
|
|
|
$state['button_text'] = __( 'Next', 'foogallery' ); |
|
63
|
|
|
$state['message'] = sprintf( __('We found %d galleries and %d videos that need to be migrated. Click Next to migrate the galleries first.', 'foogallery' ), count( $gallery_posts ), count( $attachment_posts ) ); |
|
64
|
|
|
$state['gallery_data'] = $gallery_posts; |
|
65
|
|
|
$state['attachment_data'] = $attachment_posts; |
|
66
|
|
|
|
|
67
|
|
|
} else if ( 1 === $state['step'] ) { |
|
68
|
|
|
//migrate the galleries |
|
69
|
|
|
|
|
70
|
|
|
$count = 0; |
|
71
|
|
|
foreach ($state['gallery_data'] as $gallery_id) { |
|
72
|
|
|
$this->migrate_gallery( $gallery_id ); |
|
73
|
|
|
$count++; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
$state['step'] = 2; |
|
77
|
|
|
$state['message'] = sprintf( __('%d galleries were successfully migrated. Click Next to migrate the video attachments.', 'foogallery' ), $count ); |
|
78
|
|
|
} else if ( 2 === $state['step'] ) { |
|
79
|
|
|
//migrate the attachments |
|
80
|
|
|
|
|
81
|
|
|
$count = 0; |
|
82
|
|
|
foreach ($state['attachment_data'] as $attachment_id) { |
|
83
|
|
|
$this->migrate_attachment( $attachment_id ); |
|
84
|
|
|
$count++; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
$state['step'] = 3; |
|
88
|
|
|
$state['button_text'] = __( 'Deactivate FooVideo', 'foogallery' ); |
|
89
|
|
|
$state['message'] = sprintf( __('%d video attachments were successfully migrated. You can now safely deactivate the FooVideo extension.', 'foogallery' ), $count ); |
|
90
|
|
|
} else if ( 3 === $state['step'] ) { |
|
|
|
|
|
|
91
|
|
|
//DEACTIVATE FOOVIDEO! |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
$this->save_migration_state( $state ); |
|
95
|
|
|
|
|
96
|
|
|
return $state; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function reset_state() { |
|
100
|
|
|
delete_option( 'foogallery-video-migration' ); |
|
101
|
|
|
return $this->get_migration_state(); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Migrate a gallery from the old video slider to the new slider |
|
106
|
|
|
* |
|
107
|
|
|
* @param $gallery_id |
|
108
|
|
|
*/ |
|
109
|
|
|
public function migrate_gallery( $gallery_id ) { |
|
110
|
|
|
$gallery = FooGallery::get_by_id( $gallery_id ); |
|
111
|
|
|
|
|
112
|
|
|
//get the old settings, so we can migrate to the new |
|
113
|
|
|
$settings = $gallery->settings; |
|
114
|
|
|
|
|
115
|
|
|
if ( 'videoslider' === $gallery->gallery_template ) { |
|
116
|
|
|
|
|
117
|
|
|
//update the gallery template |
|
118
|
|
|
update_post_meta( $gallery_id, FOOGALLERY_META_TEMPLATE, 'slider' ); |
|
119
|
|
|
|
|
120
|
|
|
//update the layout setting |
|
121
|
|
|
$this->migrate_setting( $settings, 'videoslider_layout', array( |
|
122
|
|
|
'rvs-vertical' => '', |
|
123
|
|
|
'rvs-horizontal' => 'fgs-horizontal' |
|
124
|
|
|
), 'slider_layout' ); |
|
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
//update the viewport setting |
|
127
|
|
|
$this->migrate_setting( $settings, 'videoslider_viewport', array( |
|
128
|
|
|
'' => '', |
|
129
|
|
|
'rvs-use-viewport' => 'yes' |
|
130
|
|
|
), 'slider_viewport' ); |
|
|
|
|
|
|
131
|
|
|
|
|
132
|
|
|
//update the theme setting |
|
133
|
|
|
$this->migrate_setting( $settings, 'videoslider_theme', array( |
|
134
|
|
|
'' => 'fg-dark', |
|
135
|
|
|
'rvs-light' => 'fg-light', |
|
136
|
|
|
'rvs-custom' => 'fg-custom' |
|
137
|
|
|
), 'slider_theme' ); |
|
|
|
|
|
|
138
|
|
|
|
|
139
|
|
|
//update the highlight setting |
|
140
|
|
|
$this->migrate_setting( $settings, 'videoslider_highlight', array( |
|
141
|
|
|
'' => 'fgs-purple', |
|
142
|
|
|
'rvs-blue-highlight' => 'fgs-blue', |
|
143
|
|
|
'rvs-green-highlight' => 'fgs-green', |
|
144
|
|
|
'rvs-orange-highlight' => 'fgs-orange', |
|
145
|
|
|
'rvs-red-highlight' => 'fgs-red', |
|
146
|
|
|
'rvs-custom-highlight' => 'fgs-custom' |
|
147
|
|
|
), 'slider_highlight' ); |
|
|
|
|
|
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
//we need to migrate the foovideo settings that are saved on all galleries |
|
151
|
|
|
$this->migrate_setting( $settings, $gallery->gallery_template . '_foovideo_video_overlay', array( |
|
152
|
|
|
'video-icon-default' => 'fg-video-default', |
|
153
|
|
|
'video-icon-1' => 'fg-video-1', |
|
154
|
|
|
'video-icon-2' => 'fg-video-2', |
|
155
|
|
|
'video-icon-3' => 'fg-video-3', |
|
156
|
|
|
'video-icon-4' => 'fg-video-4' |
|
157
|
|
|
), $gallery->gallery_template . '_video_hover_icon' ); |
|
|
|
|
|
|
158
|
|
|
|
|
159
|
|
|
$this->migrate_setting( $settings, $gallery->gallery_template . '_foovideo_sticky_icon', array( |
|
160
|
|
|
'video-icon-sticky' => 'fg-video-sticky', |
|
161
|
|
|
'' => '' |
|
162
|
|
|
), $gallery->gallery_template . '_video_sticky_icon' ); |
|
|
|
|
|
|
163
|
|
|
|
|
164
|
|
|
$this->migrate_setting( $settings, $gallery->gallery_template . '_foovideo_video_size', array( |
|
165
|
|
|
'640x360' => '640x360', |
|
166
|
|
|
'854x480' => '854x480', |
|
167
|
|
|
'960x540' => '960x540', |
|
168
|
|
|
'1024x576' => '1024x576', |
|
169
|
|
|
'1280x720' => '1280x720', |
|
170
|
|
|
'1366x768' => '1366x768', |
|
171
|
|
|
'1600x900' => '1600x900', |
|
172
|
|
|
'1920x1080' => '1920x1080', |
|
173
|
|
|
), $gallery->gallery_template . '_video_size' ); |
|
|
|
|
|
|
174
|
|
|
|
|
175
|
|
|
$this->migrate_setting( $settings, $gallery->gallery_template . '_foovideo_autoplay', array( |
|
176
|
|
|
'yes' => 'yes', |
|
177
|
|
|
'no' => 'no' |
|
178
|
|
|
), $gallery->gallery_template . '_video_autoplay' ); |
|
|
|
|
|
|
179
|
|
|
|
|
180
|
|
|
//update the gallery settings |
|
181
|
|
|
update_post_meta( $gallery_id, FOOGALLERY_META_SETTINGS, $settings ); |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* Migrate settings and the choice mappings |
|
186
|
|
|
* |
|
187
|
|
|
* @param array $settings |
|
188
|
|
|
* @param string $setting_name |
|
189
|
|
|
* @param array $mappings |
|
190
|
|
|
*/ |
|
191
|
|
|
function migrate_setting( &$settings, $setting_name, $mappings, $override_setting_name = false ) { |
|
|
|
|
|
|
192
|
|
|
$old_setting_name = $setting_name; |
|
193
|
|
|
foreach ( $settings as $name => $value) { |
|
194
|
|
|
if ( $old_setting_name === $name ) { |
|
195
|
|
|
foreach( $mappings as $mapping_key => $mapping_value ) { |
|
196
|
|
|
if ( $mapping_key === $value ) { |
|
197
|
|
|
if ( false === $override_setting_name ) { |
|
198
|
|
|
$override_setting_name = $setting_name; |
|
199
|
|
|
} |
|
200
|
|
|
$settings[$override_setting_name] = $mapping_value; |
|
201
|
|
|
return; |
|
202
|
|
|
} |
|
203
|
|
|
} |
|
204
|
|
|
} |
|
205
|
|
|
} |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
function migrate_attachment( $attachment_id ) { |
|
|
|
|
|
|
209
|
|
|
$video_info = get_post_meta( $attachment_id, FOO_VIDEO_POST_META, true ); |
|
210
|
|
|
$type = $video_info['type']; |
|
|
|
|
|
|
211
|
|
|
|
|
212
|
|
|
//need to update the post mime type |
|
213
|
|
|
$update_attachment = array( |
|
214
|
|
|
'ID' => $attachment_id, |
|
215
|
|
|
'post_mime_type' => 'image/foogallery' |
|
216
|
|
|
); |
|
217
|
|
|
|
|
218
|
|
|
wp_update_post( $update_attachment ); |
|
219
|
|
|
|
|
220
|
|
|
update_post_meta( $attachment_id, FOOGALLERY_VIDEO_POST_META, $video_info ); |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
} |
|
224
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.