@@ -2,58 +2,57 @@ |
||
2 | 2 | |
3 | 3 | /** |
4 | 4 | * Goes through all the posts and pages, and converts old shortcodes to new ones |
5 | - |
|
6 | -*/ |
|
5 | + */ |
|
7 | 6 | |
8 | 7 | class EE_DMS_4_1_0_shortcodes extends EE_Data_Migration_Script_Stage |
9 | 8 | { |
10 | - public function __construct() |
|
11 | - { |
|
12 | - global $wpdb; |
|
13 | - $this->_pretty_name = __("Shortcodes", "event_espresso"); |
|
14 | - $this->_old_table = $wpdb->posts; |
|
15 | - parent::__construct(); |
|
16 | - } |
|
17 | - protected function _migrate_old_row($old_row) |
|
18 | - { |
|
19 | - $new_post_content = $this->_change_event_list_shortcode($old_row['post_content']); |
|
20 | - global $wpdb; |
|
21 | - $wpdb->query($wpdb->prepare("UPDATE ".$this->_old_table." SET post_content=%s WHERE ID=%d", $new_post_content, $old_row['ID'])); |
|
22 | - } |
|
9 | + public function __construct() |
|
10 | + { |
|
11 | + global $wpdb; |
|
12 | + $this->_pretty_name = __("Shortcodes", "event_espresso"); |
|
13 | + $this->_old_table = $wpdb->posts; |
|
14 | + parent::__construct(); |
|
15 | + } |
|
16 | + protected function _migrate_old_row($old_row) |
|
17 | + { |
|
18 | + $new_post_content = $this->_change_event_list_shortcode($old_row['post_content']); |
|
19 | + global $wpdb; |
|
20 | + $wpdb->query($wpdb->prepare("UPDATE ".$this->_old_table." SET post_content=%s WHERE ID=%d", $new_post_content, $old_row['ID'])); |
|
21 | + } |
|
23 | 22 | |
24 | - /** |
|
25 | - * replaces [EVENT_LIST... with [ESPRESSO_EVENTS...] |
|
26 | - * @param string $old_content |
|
27 | - */ |
|
28 | - private function _change_event_list_shortcode($old_content) |
|
29 | - { |
|
30 | - return str_replace("[EVENT_LIST", "[ESPRESSO_EVENTS", $old_content); |
|
31 | - } |
|
23 | + /** |
|
24 | + * replaces [EVENT_LIST... with [ESPRESSO_EVENTS...] |
|
25 | + * @param string $old_content |
|
26 | + */ |
|
27 | + private function _change_event_list_shortcode($old_content) |
|
28 | + { |
|
29 | + return str_replace("[EVENT_LIST", "[ESPRESSO_EVENTS", $old_content); |
|
30 | + } |
|
32 | 31 | |
33 | - public function _migration_step($num_items = 50) |
|
34 | - { |
|
35 | - global $wpdb; |
|
36 | - $start_at_record = $this->count_records_migrated(); |
|
37 | - $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table {$this->_sql_to_only_select_non_drafts()} LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A); |
|
38 | - $items_actually_migrated = 0; |
|
39 | - foreach ($rows as $old_row) { |
|
40 | - $this->_migrate_old_row($old_row); |
|
41 | - $items_actually_migrated++; |
|
42 | - } |
|
43 | - if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
44 | - $this->set_completed(); |
|
45 | - } |
|
46 | - return $items_actually_migrated; |
|
47 | - } |
|
48 | - public function _count_records_to_migrate() |
|
49 | - { |
|
50 | - global $wpdb; |
|
51 | - $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table.$this->_sql_to_only_select_non_drafts()); |
|
52 | - return $count; |
|
53 | - } |
|
32 | + public function _migration_step($num_items = 50) |
|
33 | + { |
|
34 | + global $wpdb; |
|
35 | + $start_at_record = $this->count_records_migrated(); |
|
36 | + $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table {$this->_sql_to_only_select_non_drafts()} LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A); |
|
37 | + $items_actually_migrated = 0; |
|
38 | + foreach ($rows as $old_row) { |
|
39 | + $this->_migrate_old_row($old_row); |
|
40 | + $items_actually_migrated++; |
|
41 | + } |
|
42 | + if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
43 | + $this->set_completed(); |
|
44 | + } |
|
45 | + return $items_actually_migrated; |
|
46 | + } |
|
47 | + public function _count_records_to_migrate() |
|
48 | + { |
|
49 | + global $wpdb; |
|
50 | + $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table.$this->_sql_to_only_select_non_drafts()); |
|
51 | + return $count; |
|
52 | + } |
|
54 | 53 | |
55 | - private function _sql_to_only_select_non_drafts() |
|
56 | - { |
|
57 | - return " WHERE post_type NOT IN ('revision','auto-draft','attachment','nav_menu_item') "; |
|
58 | - } |
|
54 | + private function _sql_to_only_select_non_drafts() |
|
55 | + { |
|
56 | + return " WHERE post_type NOT IN ('revision','auto-draft','attachment','nav_menu_item') "; |
|
57 | + } |
|
59 | 58 | } |