Completed
Branch BUG/4.10-migrations-fails (fdcc88)
by
unknown
08:50 queued 47s
created
4_10_0_stages/EE_DMS_4_10_0_Event_Question_Group.dmsstage.php 2 patches
Indentation   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -14,135 +14,135 @@
 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['EVT_ID'],
49
-                    $event_question_group['QSG_ID']
50
-                )
51
-            );
52
-            $success = false;
53
-            if ($ids_to_update) {
54
-                $success = $wpdb->query(
55
-                    'UPDATE '
56
-                    . $this->_old_table
57
-                    . ' SET EQG_additional=1 WHERE EQG_ID IN ('
58
-                    . implode(',', array_map('intval', $ids_to_update))
59
-                    . ') LIMIT ' . count($ids_to_update)
60
-                );
61
-            }
62
-            if ($success) {
63
-                // Ok it's confirmed: the question group WAS for the primary attendee group too. So
64
-                // now we just need to delete this row.
65
-                $successful_delete = $wpdb->delete(
66
-                    $this->_old_table,
67
-                    [
68
-                        'EQG_ID' => $event_question_group['EQG_ID']
69
-                    ],
70
-                    ['%d']
71
-                );
72
-                if (!$successful_delete) {
73
-                    $this->add_error(
74
-                        sprintf(
75
-                            __('Could not delete old event-question group relation row "%1$s" because "%2$s"', 'event_espresso'),
76
-                            wp_json_encode($event_question_group),
77
-                            $wpdb->last_error
78
-                        )
79
-                    );
80
-                }
81
-            } else {
82
-                // Oh, the question group actually was NOT for the primary attendee. So we just need to update this row
83
-                // Let's do the selection separately from the deletion, this way we don't lock big tables for too long.
84
-                $ids_to_update2 = $wpdb->get_col(
85
-                    $wpdb->prepare(
86
-                        'SELECT EQG_ID FROM '
87
-                        . $this->_old_table
88
-                        . ' WHERE EVT_ID=%d AND QSG_ID=%d',
89
-                        $event_question_group['EVT_ID'],
90
-                        $event_question_group['QSG_ID']
91
-                    )
92
-                );
93
-                if ($ids_to_update2) {
94
-                    $wpdb->query(
95
-                        'UPDATE '
96
-                        . $this->_old_table
97
-                        . ' SET EQG_additional=1 WHERE EQG_ID IN ('
98
-                        . implode(',', array_map('intval', $ids_to_update2))
99
-                        . ') LIMIT ' . count($ids_to_update2)
100
-                    );
101
-                }
102
-            }
103
-        }
104
-    }
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['EVT_ID'],
49
+					$event_question_group['QSG_ID']
50
+				)
51
+			);
52
+			$success = false;
53
+			if ($ids_to_update) {
54
+				$success = $wpdb->query(
55
+					'UPDATE '
56
+					. $this->_old_table
57
+					. ' SET EQG_additional=1 WHERE EQG_ID IN ('
58
+					. implode(',', array_map('intval', $ids_to_update))
59
+					. ') LIMIT ' . count($ids_to_update)
60
+				);
61
+			}
62
+			if ($success) {
63
+				// Ok it's confirmed: the question group WAS for the primary attendee group too. So
64
+				// now we just need to delete this row.
65
+				$successful_delete = $wpdb->delete(
66
+					$this->_old_table,
67
+					[
68
+						'EQG_ID' => $event_question_group['EQG_ID']
69
+					],
70
+					['%d']
71
+				);
72
+				if (!$successful_delete) {
73
+					$this->add_error(
74
+						sprintf(
75
+							__('Could not delete old event-question group relation row "%1$s" because "%2$s"', 'event_espresso'),
76
+							wp_json_encode($event_question_group),
77
+							$wpdb->last_error
78
+						)
79
+					);
80
+				}
81
+			} else {
82
+				// Oh, the question group actually was NOT for the primary attendee. So we just need to update this row
83
+				// Let's do the selection separately from the deletion, this way we don't lock big tables for too long.
84
+				$ids_to_update2 = $wpdb->get_col(
85
+					$wpdb->prepare(
86
+						'SELECT EQG_ID FROM '
87
+						. $this->_old_table
88
+						. ' WHERE EVT_ID=%d AND QSG_ID=%d',
89
+						$event_question_group['EVT_ID'],
90
+						$event_question_group['QSG_ID']
91
+					)
92
+				);
93
+				if ($ids_to_update2) {
94
+					$wpdb->query(
95
+						'UPDATE '
96
+						. $this->_old_table
97
+						. ' SET EQG_additional=1 WHERE EQG_ID IN ('
98
+						. implode(',', array_map('intval', $ids_to_update2))
99
+						. ') LIMIT ' . count($ids_to_update2)
100
+					);
101
+				}
102
+			}
103
+		}
104
+	}
105 105
 
106
-    /**
107
-     * Gets the rows for the existing table that shouldn't exist in 4.10.
108
-     * Specifically the rows where EQG_primary=false and EQG_additional=false.
109
-     * Gotcha: because the migration is REMOVING rows as it goes, we shouldn't use the offset.
110
-     *
111
-     * @global wpdb $wpdb
112
-     * @param int   $limit
113
-     * @return array of arrays like $wpdb->get_results($sql, ARRAY_A)
114
-     */
115
-    protected function _get_rows($limit)
116
-    {
117
-        global $wpdb;
118
-        $query = "SELECT * FROM {$this->_old_table} {$this->_extra_where_sql} " . $wpdb->prepare(
119
-            "LIMIT %d",
120
-            $limit
121
-        );
122
-        return $wpdb->get_results($query, ARRAY_A);
123
-    }
106
+	/**
107
+	 * Gets the rows for the existing table that shouldn't exist in 4.10.
108
+	 * Specifically the rows where EQG_primary=false and EQG_additional=false.
109
+	 * Gotcha: because the migration is REMOVING rows as it goes, we shouldn't use the offset.
110
+	 *
111
+	 * @global wpdb $wpdb
112
+	 * @param int   $limit
113
+	 * @return array of arrays like $wpdb->get_results($sql, ARRAY_A)
114
+	 */
115
+	protected function _get_rows($limit)
116
+	{
117
+		global $wpdb;
118
+		$query = "SELECT * FROM {$this->_old_table} {$this->_extra_where_sql} " . $wpdb->prepare(
119
+			"LIMIT %d",
120
+			$limit
121
+		);
122
+		return $wpdb->get_results($query, ARRAY_A);
123
+	}
124 124
 
125
-    /**
126
-     * Slight departure from the normal procedure here: because this removes rows from the DB, we need to ensure
127
-     * we count the records first, then do the migration.
128
-     *
129
-     * @param int $num_items
130
-     * @return int number of items ACTUALLY migrated
131
-     */
132
-    public function _migration_step($num_items = 50)
133
-    {
134
-        // Count the items right away. This migration step will be removing those rows, so we need to count them
135
-        // right away to get an accurate count.
136
-        $this->count_records_to_migrate();
137
-        $rows = $this->_get_rows($num_items);
138
-        $items_actually_migrated = 0;
139
-        foreach ($rows as $old_row) {
140
-            $this->_migrate_old_row($old_row);
141
-            $items_actually_migrated++;
142
-        }
143
-        if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
144
-            $this->set_completed();
145
-        }
146
-        return $items_actually_migrated;
147
-    }
125
+	/**
126
+	 * Slight departure from the normal procedure here: because this removes rows from the DB, we need to ensure
127
+	 * we count the records first, then do the migration.
128
+	 *
129
+	 * @param int $num_items
130
+	 * @return int number of items ACTUALLY migrated
131
+	 */
132
+	public function _migration_step($num_items = 50)
133
+	{
134
+		// Count the items right away. This migration step will be removing those rows, so we need to count them
135
+		// right away to get an accurate count.
136
+		$this->count_records_to_migrate();
137
+		$rows = $this->_get_rows($num_items);
138
+		$items_actually_migrated = 0;
139
+		foreach ($rows as $old_row) {
140
+			$this->_migrate_old_row($old_row);
141
+			$items_actually_migrated++;
142
+		}
143
+		if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
144
+			$this->set_completed();
145
+		}
146
+		return $items_actually_migrated;
147
+	}
148 148
 }
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['EVT_ID'],
49 49
                     $event_question_group['QSG_ID']
50 50
                 )
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
                     . $this->_old_table
57 57
                     . ' SET EQG_additional=1 WHERE EQG_ID IN ('
58 58
                     . implode(',', array_map('intval', $ids_to_update))
59
-                    . ') LIMIT ' . count($ids_to_update)
59
+                    . ') LIMIT '.count($ids_to_update)
60 60
                 );
61 61
             }
62 62
             if ($success) {
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
                     ],
70 70
                     ['%d']
71 71
                 );
72
-                if (!$successful_delete) {
72
+                if ( ! $successful_delete) {
73 73
                     $this->add_error(
74 74
                         sprintf(
75 75
                             __('Could not delete old event-question group relation row "%1$s" because "%2$s"', 'event_espresso'),
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
                         . $this->_old_table
97 97
                         . ' SET EQG_additional=1 WHERE EQG_ID IN ('
98 98
                         . implode(',', array_map('intval', $ids_to_update2))
99
-                        . ') LIMIT ' . count($ids_to_update2)
99
+                        . ') LIMIT '.count($ids_to_update2)
100 100
                     );
101 101
                 }
102 102
             }
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
     protected function _get_rows($limit)
116 116
     {
117 117
         global $wpdb;
118
-        $query = "SELECT * FROM {$this->_old_table} {$this->_extra_where_sql} " . $wpdb->prepare(
118
+        $query = "SELECT * FROM {$this->_old_table} {$this->_extra_where_sql} ".$wpdb->prepare(
119 119
             "LIMIT %d",
120 120
             $limit
121 121
         );
Please login to merge, or discard this patch.