markup
3 years ago
data-migration.php
3 years ago
migration-contract.php
5 years ago
migration.php
3 years ago
migration.php
340 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WP_Social\Xs_Migration; |
| 4 | |
| 5 | use WP_Social\Inc\Admin_Settings; |
| 6 | |
| 7 | /** |
| 8 | * Class Migration |
| 9 | * |
| 10 | * @package WP_Social\Xs_Migration |
| 11 | */ |
| 12 | class Migration extends Data_Migration { |
| 13 | |
| 14 | /** |
| 15 | * |
| 16 | * @param $wpOptionKey |
| 17 | * @param $executionPlanKey |
| 18 | * @param $existingOption |
| 19 | * |
| 20 | * @return array |
| 21 | */ |
| 22 | public function convert_from_1_3_0_to_1_3_1($wpOptionKey, $executionPlanKey, $existingOption) { |
| 23 | |
| 24 | $log = $existingOption['execution_plan'][$executionPlanKey]['log']; |
| 25 | |
| 26 | return [ |
| 27 | 'status' => 'success', |
| 28 | 'log' => $log, |
| 29 | ]; |
| 30 | } |
| 31 | |
| 32 | |
| 33 | /** |
| 34 | * |
| 35 | * @param $wpOptionKey |
| 36 | * @param $executionPlanKey |
| 37 | * @param $existingOption |
| 38 | * |
| 39 | * @return array |
| 40 | */ |
| 41 | public function convert_from_1_3_1_to_1_3_2($wpOptionKey, $executionPlanKey, $existingOption) { |
| 42 | |
| 43 | $log = $existingOption['execution_plan'][$executionPlanKey]['log']; |
| 44 | |
| 45 | return [ |
| 46 | 'status' => 'success', |
| 47 | 'log' => $log, |
| 48 | ]; |
| 49 | } |
| 50 | |
| 51 | |
| 52 | /** |
| 53 | * |
| 54 | * @param $wpOptionKey |
| 55 | * @param $executionPlanKey |
| 56 | * @param $existingOption |
| 57 | * |
| 58 | * @return array |
| 59 | */ |
| 60 | public function convert_from_1_3_2_to_1_3_3($wpOptionKey, $executionPlanKey, $existingOption) { |
| 61 | |
| 62 | $log = $existingOption['execution_plan'][$executionPlanKey]['log']; |
| 63 | |
| 64 | return [ |
| 65 | 'status' => 'success', |
| 66 | 'log' => $log, |
| 67 | ]; |
| 68 | } |
| 69 | |
| 70 | |
| 71 | /** |
| 72 | * |
| 73 | * @param $wpOptionKey |
| 74 | * @param $executionPlanKey |
| 75 | * @param $existingOption |
| 76 | * |
| 77 | * @return array |
| 78 | */ |
| 79 | public function convert_from_1_3_3_to_1_3_4($wpOptionKey, $executionPlanKey, $existingOption) { |
| 80 | |
| 81 | $log = $existingOption['execution_plan'][$executionPlanKey]['log']; |
| 82 | |
| 83 | return [ |
| 84 | 'status' => 'success', |
| 85 | 'log' => $log, |
| 86 | ]; |
| 87 | } |
| 88 | |
| 89 | |
| 90 | /** |
| 91 | * |
| 92 | * @param $wpOptionKey |
| 93 | * @param $executionPlanKey |
| 94 | * @param $existingOption |
| 95 | * |
| 96 | * @return array |
| 97 | */ |
| 98 | public function convert_from_1_3_4_to_1_3_5($wpOptionKey, $executionPlanKey, $existingOption) { |
| 99 | |
| 100 | $log = $existingOption['execution_plan'][$executionPlanKey]['log']; |
| 101 | |
| 102 | $checkList = $existingOption['execution_plan'][$executionPlanKey]['progress'][__FUNCTION__]['check_list']; |
| 103 | $weightLifted = 0; #this value will be the programmers intuition, our goal is to not to give work more than 10 seconds |
| 104 | |
| 105 | if(empty($checkList)) { |
| 106 | |
| 107 | $checkList['option_updated'] = false; |
| 108 | $checkList['form_data_processed'] = false; |
| 109 | |
| 110 | $existingOption['execution_plan'][$executionPlanKey]['progress'][__FUNCTION__]['check_list'] = $checkList; |
| 111 | } |
| 112 | |
| 113 | |
| 114 | if($checkList['option_updated'] === false) { |
| 115 | |
| 116 | $opt = $this->prepareOption_1_3_4_to_1_3_5(); |
| 117 | |
| 118 | if(!empty($opt)) { |
| 119 | |
| 120 | foreach($opt as $opKey => $opVal) { |
| 121 | |
| 122 | //update_option($opKey, $opVal); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | $weightLifted += 30; # AR: feeling it may take 3 seconds to return the result so putting 3*10 = 30; |
| 127 | |
| 128 | $checkList['option_updated'] = true; |
| 129 | |
| 130 | $existingOption['execution_plan'][$executionPlanKey]['progress'][__FUNCTION__]['check_list'] = $checkList; |
| 131 | } |
| 132 | |
| 133 | |
| 134 | if($weightLifted <= 100 && $checkList['form_data_processed'] === false) { |
| 135 | |
| 136 | $tmp = []; |
| 137 | |
| 138 | if(empty($existingOption['execution_plan'][$executionPlanKey]['progress'][__FUNCTION__]['form_data_processed'])) { |
| 139 | |
| 140 | #this is not hardcoded, we are assuming we have to query the post table and this is the total posts |
| 141 | $tmp['total'] = 300; |
| 142 | #We will process 50 queries per request, so this is mysql limit in the query |
| 143 | $tmp['rate'] = 50; |
| 144 | #This is the starting/progress done, in query it will be offset |
| 145 | $tmp['offset'] = 0; |
| 146 | #This is calculated from rate * offset |
| 147 | $tmp['done'] = 0; |
| 148 | |
| 149 | $existingOption['execution_plan'][$executionPlanKey]['progress'][__FUNCTION__]['form_data_processed'] = $tmp; |
| 150 | |
| 151 | } else { |
| 152 | |
| 153 | $tmp = $existingOption['execution_plan'][$executionPlanKey]['progress'][__FUNCTION__]['form_data_processed']; |
| 154 | } |
| 155 | |
| 156 | #Now we do not want to process more than 10 seconds[imagined], |
| 157 | #Also keep checking if we finished all the data from database |
| 158 | while($weightLifted < 100 && $tmp['done'] < $tmp['total']) { |
| 159 | |
| 160 | $tmp['offset']++; |
| 161 | $tmp['done'] = $tmp['offset'] * $tmp['rate']; |
| 162 | |
| 163 | //do the work here |
| 164 | // |
| 165 | // |
| 166 | |
| 167 | #Now check if above work is the last of it, if then finish the task |
| 168 | if($tmp['done'] >= $tmp['total']) { |
| 169 | //this task is finished.. |
| 170 | $existingOption['execution_plan'][$executionPlanKey]['progress'][__FUNCTION__]['check_list']['form_data_processed'] = true; |
| 171 | } |
| 172 | |
| 173 | $weightLifted += 70; #feeling it may take 7 seconds or less |
| 174 | } |
| 175 | |
| 176 | |
| 177 | $existingOption['execution_plan'][$executionPlanKey]['progress'][__FUNCTION__]['form_data_processed'] = $tmp; |
| 178 | |
| 179 | if($weightLifted >= 100) { |
| 180 | $existingOption['execution_plan'][$executionPlanKey]['progress'][__FUNCTION__]['status'] = self::STATUS_METHOD_PAUSED; |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | #Now check if all the checklist is completed... |
| 185 | $done = true; |
| 186 | |
| 187 | foreach($checkList as $item) { |
| 188 | |
| 189 | if($item === false) $done = false; |
| 190 | } |
| 191 | |
| 192 | if($done === true) { |
| 193 | |
| 194 | #this means this method is completed all the work it supposed to do |
| 195 | $existingOption['execution_plan'][$executionPlanKey]['progress'][__FUNCTION__]['status'] = self::STATUS_FINISHED; |
| 196 | } |
| 197 | |
| 198 | |
| 199 | //update_option($wpOptionKey, $existingOption); |
| 200 | |
| 201 | return [ |
| 202 | 'status' => 'success', |
| 203 | 'log' => $log, |
| 204 | ]; |
| 205 | } |
| 206 | |
| 207 | |
| 208 | /** |
| 209 | * |
| 210 | */ |
| 211 | private function prepareOption_1_3_4_to_1_3_5() { |
| 212 | |
| 213 | $keySDC = 'xs_style_setting_data_counter'; |
| 214 | $keySDS = 'xs_style_setting_data_share'; |
| 215 | |
| 216 | |
| 217 | $oldStructureOptions = [ |
| 218 | $keySDC => [ |
| 219 | 'login_button_style' => 'style-class', |
| 220 | ], |
| 221 | |
| 222 | $keySDS => [ |
| 223 | 'login_button_style' => 'style-class', |
| 224 | 'login_button_content' => 'style_name', |
| 225 | 'login_content' => '', |
| 226 | ] |
| 227 | ]; |
| 228 | |
| 229 | |
| 230 | $newStructureOptions = [ |
| 231 | $keySDC => [ |
| 232 | 'login_button_style' => [ |
| 233 | 'style' => 'style-1:wslu-none' |
| 234 | ], |
| 235 | ], |
| 236 | |
| 237 | $keySDS => [ |
| 238 | 'login_button_content' => 'right_content', #def value |
| 239 | |
| 240 | 'login_content' => 'before_content', #def value |
| 241 | |
| 242 | 'main_content' => [ |
| 243 | 'style' => 'style-1:wslu-none', |
| 244 | 'show_social_count_share' => '1', |
| 245 | ], |
| 246 | |
| 247 | 'fixed_display' => [ |
| 248 | 'style' => 'style-1:wslu-none', |
| 249 | 'show_social_count_share' => '1', |
| 250 | ], |
| 251 | ] |
| 252 | ]; |
| 253 | |
| 254 | |
| 255 | if(get_option($oldStructureOptions[$keySDC])) { |
| 256 | |
| 257 | if(!empty($oldStructureOptions[$keySDC]['login_button_style'])) { |
| 258 | |
| 259 | $styleArr = Admin_Settings::counter_styles(); |
| 260 | |
| 261 | if( method_exists( \WP_Social_Pro\Inc\Admin_Settings::class, 'counter_hover_effects' ) ){ |
| 262 | |
| 263 | $hoverArr = \WP_Social_Pro\Inc\Admin_Settings::counter_hover_effects(); |
| 264 | |
| 265 | }else{ |
| 266 | |
| 267 | $hoverArr = \WP_Social_Pro\Inc\Admin_Settings::$counter_hover_effects; |
| 268 | |
| 269 | } |
| 270 | |
| 271 | $foundKey = 'style-1'; |
| 272 | $defHoverKey = 'none-none'; |
| 273 | |
| 274 | foreach($styleArr as $key => $item) { |
| 275 | |
| 276 | if($item['class'] == $oldStructureOptions[$keySDC]['login_button_style']) { |
| 277 | |
| 278 | $foundKey = $key; |
| 279 | |
| 280 | break; |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | |
| 285 | $newStructureOptions[$keySDC]['login_button_style']['style'] = $styleArr[$foundKey]['class'] . ':' . $hoverArr[$defHoverKey]['class']; |
| 286 | |
| 287 | } else { |
| 288 | |
| 289 | unset($newStructureOptions[$keySDC]); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | |
| 294 | if(get_option($oldStructureOptions[$keySDS])) { |
| 295 | |
| 296 | if(!empty($oldStructureOptions[$keySDS]['login_content'])) { |
| 297 | |
| 298 | $newStructureOptions[$keySDS]['login_content'] = $oldStructureOptions[$keySDS]['login_content']; |
| 299 | } |
| 300 | |
| 301 | if(!empty($oldStructureOptions[$keySDS]['login_button_content'])) { |
| 302 | |
| 303 | $newStructureOptions[$keySDS]['login_button_content'] = $oldStructureOptions[$keySDS]['login_button_content']; |
| 304 | } |
| 305 | |
| 306 | if(!empty($oldStructureOptions[$keySDS]['login_button_style'])) { |
| 307 | |
| 308 | $styleArr = Admin_Settings::share_styles(); |
| 309 | |
| 310 | if( method_exists( \WP_Social_Pro\Inc\Admin_Settings::class, 'share_hover_effects' ) ){ |
| 311 | |
| 312 | $hoverArr = \WP_Social_Pro\Inc\Admin_Settings::share_hover_effects(); |
| 313 | |
| 314 | }else{ |
| 315 | |
| 316 | $hoverArr = \WP_Social_Pro\Inc\Admin_Settings::$share_hover_effects; |
| 317 | } |
| 318 | |
| 319 | |
| 320 | $foundKey = 'style-1'; |
| 321 | $defHoverKey = 'none-none'; |
| 322 | |
| 323 | foreach($styleArr as $key => $item) { |
| 324 | |
| 325 | if($item['class'] == $oldStructureOptions[$keySDC]['login_button_style']) { |
| 326 | |
| 327 | $foundKey = $key; |
| 328 | |
| 329 | break; |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | $newStructureOptions[$keySDS]['main_content']['style'] = $styleArr[$foundKey]['class'] . ':' . $hoverArr[$defHoverKey]['class']; |
| 334 | $newStructureOptions[$keySDS]['fixed_display']['style'] = $styleArr[$foundKey]['class'] . ':' . $hoverArr[$defHoverKey]['class']; |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | } |
| 339 | |
| 340 | } |