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