Completed
Branch BUG/4.10-migrations-fails (411864)
by
unknown
08:45 queued 50s
created
4_10_0_stages/EE_DMS_4_10_0_Event_Question_Group.dmsstage.php 2 patches
Indentation   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -14,134 +14,134 @@
 block discarded – undo
14 14
 
15 15
 
16 16
 
17
-    /**
18
-     * Just initializes the status of the migration
19
-     */
20
-    public function __construct()
21
-    {
22
-        global $wpdb;
23
-        $this->_pretty_name = __('Event-Question Group Relations', 'event_espresso');
24
-        $this->_old_table = $wpdb->prefix.'esp_event_question_group';
25
-        $this->_extra_where_sql = "WHERE EQG_primary = 0 AND EQG_additional=0";
26
-        parent::__construct();
27
-    }
17
+	/**
18
+	 * Just initializes the status of the migration
19
+	 */
20
+	public function __construct()
21
+	{
22
+		global $wpdb;
23
+		$this->_pretty_name = __('Event-Question Group Relations', 'event_espresso');
24
+		$this->_old_table = $wpdb->prefix.'esp_event_question_group';
25
+		$this->_extra_where_sql = "WHERE EQG_primary = 0 AND EQG_additional=0";
26
+		parent::__construct();
27
+	}
28 28
 
29 29
 
30
-    /**
31
-     * Removes the duplicate event_question_group rows that only had EQG_primary=0. Now we just have one row
32
-     * joining event-to-question-groups with two columns: EQG_primary and EQG_additional, indicating which question
33
-     * groups apply to which category of registrant.
34
-     * @param array $event_question_group an associative array where keys are column names and values are their values.
35
-     * @return null
36
-     */
37
-    protected function _migrate_old_row($event_question_group)
38
-    {
39
-        if (isset($event_question_group['EVT_ID'], $event_question_group['QSG_ID'])) {
40
-            global $wpdb;
41
-            // If the question group was also for primary attendees, we should just update that row.
42
-            // And we delete this row.
43
-            // Updating all the rows could be slow on massive DBs, so do the slow selection first, then a quick update
44
-            // in order to avoid locking the table for too long.
45
-            $ids_to_update = $wpdb->get_col(
46
-                $wpdb->prepare(
47
-                    'SELECT EQG_ID FROM ' . $this->_old_table . ' WHERE EQG_primary=1 AND EVT_ID=%d AND QSG_ID=%d',
48
-                    $event_question_group['EQG_ID'],
49
-                    $event_question_group['QSG_ID']
50
-                )
51
-            );
52
-            if ($ids_to_update) {
53
-                $success = $wpdb->query(
54
-                    'UPDATE '
55
-                    . $this->_old_table
56
-                    . ' SET EQG_additional=1 WHERE EQG_ID IN ('
57
-                    . implode(',', array_map('intval', $ids_to_update))
58
-                    . ') LIMIT ' . count($ids_to_update)
59
-                );
60
-                if ($success) {
61
-                    // Ok it's confirmed: the question group WAS for the primary attendee group too. So
62
-                    // now we just need to delete this row.
63
-                    $successful_delete = $wpdb->delete(
64
-                        $this->_old_table,
65
-                        [
66
-                            'EQG_ID' => $event_question_group['EQG_ID']
67
-                        ],
68
-                        ['%d']
69
-                    );
70
-                    if (!$successful_delete) {
71
-                        $this->add_error(
72
-                            sprintf(
73
-                                __('Could not delete old event-question group relation row "%1$s" because "%2$s"', 'event_espresso'),
74
-                                wp_json_encode($event_question_group),
75
-                                $wpdb->last_error
76
-                            )
77
-                        );
78
-                    }
79
-                } else {
80
-                    // Oh, the question group actually was NOT for the primary attendee. So we just need to update this row
81
-                    // Let's do the selection separately from the deletion, this way we don't lock big tables for too long.
82
-                    $ids_to_update2 = $wpdb->get_col(
83
-                        $wpdb->prepare(
84
-                            'SELECT EQG_ID FROM '
85
-                            . $this->_old_table
86
-                            . ' WHERE EVT_ID=%d AND QSG_ID=%d',
87
-                            $event_question_group['EVT_ID'],
88
-                            $event_question_group['QSG_ID']
89
-                        )
90
-                    );
91
-                    if ($ids_to_update2) {
92
-                        $wpdb->query(
93
-                            'UPDATE '
94
-                            . $this->_old_table
95
-                            . ' SET EQG_additional=1 WHERE EQG_ID IN ('
96
-                            . implode(',', array_map('intval', $ids_to_update2))
97
-                            . ') LIMIT ' . count($ids_to_update2)
98
-                        );
99
-                    }
100
-                }
101
-            }
102
-        }
103
-    }
30
+	/**
31
+	 * Removes the duplicate event_question_group rows that only had EQG_primary=0. Now we just have one row
32
+	 * joining event-to-question-groups with two columns: EQG_primary and EQG_additional, indicating which question
33
+	 * groups apply to which category of registrant.
34
+	 * @param array $event_question_group an associative array where keys are column names and values are their values.
35
+	 * @return null
36
+	 */
37
+	protected function _migrate_old_row($event_question_group)
38
+	{
39
+		if (isset($event_question_group['EVT_ID'], $event_question_group['QSG_ID'])) {
40
+			global $wpdb;
41
+			// If the question group was also for primary attendees, we should just update that row.
42
+			// And we delete this row.
43
+			// Updating all the rows could be slow on massive DBs, so do the slow selection first, then a quick update
44
+			// in order to avoid locking the table for too long.
45
+			$ids_to_update = $wpdb->get_col(
46
+				$wpdb->prepare(
47
+					'SELECT EQG_ID FROM ' . $this->_old_table . ' WHERE EQG_primary=1 AND EVT_ID=%d AND QSG_ID=%d',
48
+					$event_question_group['EQG_ID'],
49
+					$event_question_group['QSG_ID']
50
+				)
51
+			);
52
+			if ($ids_to_update) {
53
+				$success = $wpdb->query(
54
+					'UPDATE '
55
+					. $this->_old_table
56
+					. ' SET EQG_additional=1 WHERE EQG_ID IN ('
57
+					. implode(',', array_map('intval', $ids_to_update))
58
+					. ') LIMIT ' . count($ids_to_update)
59
+				);
60
+				if ($success) {
61
+					// Ok it's confirmed: the question group WAS for the primary attendee group too. So
62
+					// now we just need to delete this row.
63
+					$successful_delete = $wpdb->delete(
64
+						$this->_old_table,
65
+						[
66
+							'EQG_ID' => $event_question_group['EQG_ID']
67
+						],
68
+						['%d']
69
+					);
70
+					if (!$successful_delete) {
71
+						$this->add_error(
72
+							sprintf(
73
+								__('Could not delete old event-question group relation row "%1$s" because "%2$s"', 'event_espresso'),
74
+								wp_json_encode($event_question_group),
75
+								$wpdb->last_error
76
+							)
77
+						);
78
+					}
79
+				} else {
80
+					// Oh, the question group actually was NOT for the primary attendee. So we just need to update this row
81
+					// Let's do the selection separately from the deletion, this way we don't lock big tables for too long.
82
+					$ids_to_update2 = $wpdb->get_col(
83
+						$wpdb->prepare(
84
+							'SELECT EQG_ID FROM '
85
+							. $this->_old_table
86
+							. ' WHERE EVT_ID=%d AND QSG_ID=%d',
87
+							$event_question_group['EVT_ID'],
88
+							$event_question_group['QSG_ID']
89
+						)
90
+					);
91
+					if ($ids_to_update2) {
92
+						$wpdb->query(
93
+							'UPDATE '
94
+							. $this->_old_table
95
+							. ' SET EQG_additional=1 WHERE EQG_ID IN ('
96
+							. implode(',', array_map('intval', $ids_to_update2))
97
+							. ') LIMIT ' . count($ids_to_update2)
98
+						);
99
+					}
100
+				}
101
+			}
102
+		}
103
+	}
104 104
 
105
-    /**
106
-     * Gets the rows for the existing table that shouldn't exist in 4.10.
107
-     * Specifically the rows where EQG_primary=false and EQG_additional=false.
108
-     * Gotcha: because the migration is REMOVING rows as it goes, we shouldn't use the offset.
109
-     *
110
-     * @global wpdb $wpdb
111
-     * @param int   $limit
112
-     * @return array of arrays like $wpdb->get_results($sql, ARRAY_A)
113
-     */
114
-    protected function _get_rows($limit)
115
-    {
116
-        global $wpdb;
117
-        $query = "SELECT * FROM {$this->_old_table} {$this->_extra_where_sql} " . $wpdb->prepare(
118
-            "LIMIT %d",
119
-            $limit
120
-        );
121
-        return $wpdb->get_results($query, ARRAY_A);
122
-    }
105
+	/**
106
+	 * Gets the rows for the existing table that shouldn't exist in 4.10.
107
+	 * Specifically the rows where EQG_primary=false and EQG_additional=false.
108
+	 * Gotcha: because the migration is REMOVING rows as it goes, we shouldn't use the offset.
109
+	 *
110
+	 * @global wpdb $wpdb
111
+	 * @param int   $limit
112
+	 * @return array of arrays like $wpdb->get_results($sql, ARRAY_A)
113
+	 */
114
+	protected function _get_rows($limit)
115
+	{
116
+		global $wpdb;
117
+		$query = "SELECT * FROM {$this->_old_table} {$this->_extra_where_sql} " . $wpdb->prepare(
118
+			"LIMIT %d",
119
+			$limit
120
+		);
121
+		return $wpdb->get_results($query, ARRAY_A);
122
+	}
123 123
 
124
-    /**
125
-     * Slight departure from the normal procedure here: because this removes rows from the DB, we need to ensure
126
-     * we count the records first, then do the migration.
127
-     *
128
-     * @param int $num_items
129
-     * @return int number of items ACTUALLY migrated
130
-     */
131
-    public function _migration_step($num_items = 50)
132
-    {
133
-        // Count the items right away. This migration step will be removing those rows, so we need to count them
134
-        // right away to get an accurate count.
135
-        $this->count_records_to_migrate();
136
-        $rows = $this->_get_rows($num_items);
137
-        $items_actually_migrated = 0;
138
-        foreach ($rows as $old_row) {
139
-            $this->_migrate_old_row($old_row);
140
-            $items_actually_migrated++;
141
-        }
142
-        if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
143
-            $this->set_completed();
144
-        }
145
-        return $items_actually_migrated;
146
-    }
124
+	/**
125
+	 * Slight departure from the normal procedure here: because this removes rows from the DB, we need to ensure
126
+	 * we count the records first, then do the migration.
127
+	 *
128
+	 * @param int $num_items
129
+	 * @return int number of items ACTUALLY migrated
130
+	 */
131
+	public function _migration_step($num_items = 50)
132
+	{
133
+		// Count the items right away. This migration step will be removing those rows, so we need to count them
134
+		// right away to get an accurate count.
135
+		$this->count_records_to_migrate();
136
+		$rows = $this->_get_rows($num_items);
137
+		$items_actually_migrated = 0;
138
+		foreach ($rows as $old_row) {
139
+			$this->_migrate_old_row($old_row);
140
+			$items_actually_migrated++;
141
+		}
142
+		if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
143
+			$this->set_completed();
144
+		}
145
+		return $items_actually_migrated;
146
+	}
147 147
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
             // in order to avoid locking the table for too long.
45 45
             $ids_to_update = $wpdb->get_col(
46 46
                 $wpdb->prepare(
47
-                    'SELECT EQG_ID FROM ' . $this->_old_table . ' WHERE EQG_primary=1 AND EVT_ID=%d AND QSG_ID=%d',
47
+                    'SELECT EQG_ID FROM '.$this->_old_table.' WHERE EQG_primary=1 AND EVT_ID=%d AND QSG_ID=%d',
48 48
                     $event_question_group['EQG_ID'],
49 49
                     $event_question_group['QSG_ID']
50 50
                 )
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
                     . $this->_old_table
56 56
                     . ' SET EQG_additional=1 WHERE EQG_ID IN ('
57 57
                     . implode(',', array_map('intval', $ids_to_update))
58
-                    . ') LIMIT ' . count($ids_to_update)
58
+                    . ') LIMIT '.count($ids_to_update)
59 59
                 );
60 60
                 if ($success) {
61 61
                     // Ok it's confirmed: the question group WAS for the primary attendee group too. So
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
                         ],
68 68
                         ['%d']
69 69
                     );
70
-                    if (!$successful_delete) {
70
+                    if ( ! $successful_delete) {
71 71
                         $this->add_error(
72 72
                             sprintf(
73 73
                                 __('Could not delete old event-question group relation row "%1$s" because "%2$s"', 'event_espresso'),
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
                             . $this->_old_table
95 95
                             . ' SET EQG_additional=1 WHERE EQG_ID IN ('
96 96
                             . implode(',', array_map('intval', $ids_to_update2))
97
-                            . ') LIMIT ' . count($ids_to_update2)
97
+                            . ') LIMIT '.count($ids_to_update2)
98 98
                         );
99 99
                     }
100 100
                 }
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
     protected function _get_rows($limit)
115 115
     {
116 116
         global $wpdb;
117
-        $query = "SELECT * FROM {$this->_old_table} {$this->_extra_where_sql} " . $wpdb->prepare(
117
+        $query = "SELECT * FROM {$this->_old_table} {$this->_extra_where_sql} ".$wpdb->prepare(
118 118
             "LIMIT %d",
119 119
             $limit
120 120
         );
Please login to merge, or discard this patch.