Completed
Branch FET/reg-form-builder/main (d0d867)
by
unknown
09:57 queued 24s
created
4_6_0_stages/EE_DMS_4_6_0_payment_method_currencies.dmsstage.php 3 patches
Doc Comments   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -128,6 +128,9 @@  discard block
 block discarded – undo
128 128
         return $items_actually_migrated;
129 129
     }
130 130
 
131
+    /**
132
+     * @param integer $num_items_to_migrate
133
+     */
131 134
     private function _gather_relations_to_add($num_items_to_migrate)
132 135
     {
133 136
         $relations_to_add_this_step = array();
@@ -160,8 +163,6 @@  discard block
 block discarded – undo
160 163
 
161 164
     /**
162 165
      * Adds teh relation between the payment method and the currencies it can be used for
163
-     * @param int $id
164
-     * @param string $gateway_slug
165 166
      */
166 167
     private function _add_currency_relations($pm_id, $currency_code)
167 168
     {
Please login to merge, or discard this patch.
Indentation   +166 added lines, -166 removed lines patch added patch discarded remove patch
@@ -12,176 +12,176 @@
 block discarded – undo
12 12
  */
13 13
 class EE_DMS_4_6_0_payment_method_currencies extends EE_Data_Migration_Script_Stage
14 14
 {
15
-    protected $_currency_table_name;
16
-    protected $_currency_payment_method_table_name;
17
-    protected $_payment_method_table_name;
18
-    /**
19
-     * each key is the name of a 4.1-style gateway we know how to migrate to 4.6
20
-     * @var array
21
-     */
22
-    protected $_gateway_currencies = array(
23
-        'Aim' => array(
24
-            'AUD',
25
-            'USD',
26
-            'CAD',
27
-            'EUR',
28
-            'GBP',
29
-            'NZD',
30
-        ),
31
-        'Bank' => 'all',
32
-        'Check' => 'all',
33
-        'Invoice' => 'all',
34
-        'Mijireh' => 'all',
35
-        'Paypal_Pro' => array(
36
-            'USD',
37
-            'GBP',
38
-            'CAD',
39
-            'AUD',
40
-            'BRL',
41
-            'CHF',
42
-            'CZK',
43
-            'DKK',
44
-            'EUR',
45
-            'HKD',
46
-            'HUF',
47
-            'ILS',
48
-            'JPY',
49
-            'MXN',
50
-            'MYR',
51
-            'NOK',
52
-            'NZD',
53
-            'PHP',
54
-            'PLN',
55
-            'SEK',
56
-            'SGD',
57
-            'THB',
58
-            'TRY',
59
-            'TWD',
60
-        ),
61
-        'Paypal_Standard' => array(
62
-            'USD',
63
-            'GBP',
64
-            'CAD',
65
-            'AUD',
66
-            'BRL',
67
-            'CHF',
68
-            'CZK',
69
-            'DKK',
70
-            'EUR',
71
-            'HKD',
72
-            'HUF',
73
-            'ILS',
74
-            'JPY',
75
-            'MXN',
76
-            'MYR',
77
-            'NOK',
78
-            'NZD',
79
-            'PHP',
80
-            'PLN',
81
-            'SEK',
82
-            'SGD',
83
-            'THB',
84
-            'TRY',
85
-            'TWD'
86
-        )
87
-    );
88
-    public function __construct()
89
-    {
90
-        global $wpdb;
91
-        $this->_pretty_name = __('Payment Method Currencies', 'event_espresso');
92
-        $this->_payment_method_table_name = $wpdb->prefix . 'esp_payment_method';
93
-        $this->_currency_payment_method_table_name = $wpdb->prefix . 'esp_currency_payment_method';
94
-        $this->_currency_table_name = $wpdb->prefix . 'esp_currency';
95
-        parent::__construct();
96
-    }
15
+	protected $_currency_table_name;
16
+	protected $_currency_payment_method_table_name;
17
+	protected $_payment_method_table_name;
18
+	/**
19
+	 * each key is the name of a 4.1-style gateway we know how to migrate to 4.6
20
+	 * @var array
21
+	 */
22
+	protected $_gateway_currencies = array(
23
+		'Aim' => array(
24
+			'AUD',
25
+			'USD',
26
+			'CAD',
27
+			'EUR',
28
+			'GBP',
29
+			'NZD',
30
+		),
31
+		'Bank' => 'all',
32
+		'Check' => 'all',
33
+		'Invoice' => 'all',
34
+		'Mijireh' => 'all',
35
+		'Paypal_Pro' => array(
36
+			'USD',
37
+			'GBP',
38
+			'CAD',
39
+			'AUD',
40
+			'BRL',
41
+			'CHF',
42
+			'CZK',
43
+			'DKK',
44
+			'EUR',
45
+			'HKD',
46
+			'HUF',
47
+			'ILS',
48
+			'JPY',
49
+			'MXN',
50
+			'MYR',
51
+			'NOK',
52
+			'NZD',
53
+			'PHP',
54
+			'PLN',
55
+			'SEK',
56
+			'SGD',
57
+			'THB',
58
+			'TRY',
59
+			'TWD',
60
+		),
61
+		'Paypal_Standard' => array(
62
+			'USD',
63
+			'GBP',
64
+			'CAD',
65
+			'AUD',
66
+			'BRL',
67
+			'CHF',
68
+			'CZK',
69
+			'DKK',
70
+			'EUR',
71
+			'HKD',
72
+			'HUF',
73
+			'ILS',
74
+			'JPY',
75
+			'MXN',
76
+			'MYR',
77
+			'NOK',
78
+			'NZD',
79
+			'PHP',
80
+			'PLN',
81
+			'SEK',
82
+			'SGD',
83
+			'THB',
84
+			'TRY',
85
+			'TWD'
86
+		)
87
+	);
88
+	public function __construct()
89
+	{
90
+		global $wpdb;
91
+		$this->_pretty_name = __('Payment Method Currencies', 'event_espresso');
92
+		$this->_payment_method_table_name = $wpdb->prefix . 'esp_payment_method';
93
+		$this->_currency_payment_method_table_name = $wpdb->prefix . 'esp_currency_payment_method';
94
+		$this->_currency_table_name = $wpdb->prefix . 'esp_currency';
95
+		parent::__construct();
96
+	}
97 97
 
98
-    protected function _count_records_to_migrate()
99
-    {
100
-        $count = 0;
101
-        foreach ($this->_gateway_currencies as $currencies) {
102
-            if ($currencies == 'all') {
103
-                $currencies = $this->_get_all_currencies();
104
-            }
105
-            $count += count($currencies);
106
-        }
107
-        return $count;
108
-    }
98
+	protected function _count_records_to_migrate()
99
+	{
100
+		$count = 0;
101
+		foreach ($this->_gateway_currencies as $currencies) {
102
+			if ($currencies == 'all') {
103
+				$currencies = $this->_get_all_currencies();
104
+			}
105
+			$count += count($currencies);
106
+		}
107
+		return $count;
108
+	}
109 109
 
110 110
 
111 111
 
112
-    protected function _migration_step($num_items_to_migrate = 50)
113
-    {
114
-        $items_actually_migrated = 0;
115
-        $relations_to_add_this_step = $this->_gather_relations_to_add($num_items_to_migrate);
116
-        foreach ($relations_to_add_this_step as $pm_slug => $currencies) {
117
-            $id = $this->get_migration_script()->get_mapping_new_pk('EE_Gateway_Config', $pm_slug, $this->_payment_method_table_name);
118
-            foreach ($currencies as $currency) {
119
-                if ($id) {
120
-                    $this->_add_currency_relations($id, $currency);
121
-                }
122
-                $items_actually_migrated++;
123
-            }
124
-        }
125
-        if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
126
-            $this->set_completed();
127
-        }
128
-        return $items_actually_migrated;
129
-    }
112
+	protected function _migration_step($num_items_to_migrate = 50)
113
+	{
114
+		$items_actually_migrated = 0;
115
+		$relations_to_add_this_step = $this->_gather_relations_to_add($num_items_to_migrate);
116
+		foreach ($relations_to_add_this_step as $pm_slug => $currencies) {
117
+			$id = $this->get_migration_script()->get_mapping_new_pk('EE_Gateway_Config', $pm_slug, $this->_payment_method_table_name);
118
+			foreach ($currencies as $currency) {
119
+				if ($id) {
120
+					$this->_add_currency_relations($id, $currency);
121
+				}
122
+				$items_actually_migrated++;
123
+			}
124
+		}
125
+		if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
126
+			$this->set_completed();
127
+		}
128
+		return $items_actually_migrated;
129
+	}
130 130
 
131
-    private function _gather_relations_to_add($num_items_to_migrate)
132
-    {
133
-        $relations_to_add_this_step = array();
134
-        $migrate_up_to_count = $this->count_records_migrated() + $num_items_to_migrate;
135
-        $iterator = 0;
136
-        foreach ($this->_gateway_currencies as $pm_slug => $currencies) {
137
-            if ($currencies == 'all') {
138
-                $currencies = $this->_get_all_currencies();
139
-            }
140
-            foreach ($currencies as $currency_code) {
141
-                if (
142
-                    $this->count_records_migrated() <= $iterator &&
143
-                        $iterator < $migrate_up_to_count
144
-                ) {
145
-                    $relations_to_add_this_step[ $pm_slug ] [] = $currency_code;
146
-                }
147
-                $iterator++;
148
-            }
149
-        }
150
-        return $relations_to_add_this_step;
151
-    }
152
-    /**
153
-     * Gets all the currency codes in the database
154
-     * @return array
155
-     */
156
-    private function _get_all_currencies()
157
-    {
158
-        global $wpdb;
159
-        $currencies = $wpdb->get_col("SELECT CUR_code FROM {$this->_currency_table_name}");
160
-        return $currencies;
161
-    }
131
+	private function _gather_relations_to_add($num_items_to_migrate)
132
+	{
133
+		$relations_to_add_this_step = array();
134
+		$migrate_up_to_count = $this->count_records_migrated() + $num_items_to_migrate;
135
+		$iterator = 0;
136
+		foreach ($this->_gateway_currencies as $pm_slug => $currencies) {
137
+			if ($currencies == 'all') {
138
+				$currencies = $this->_get_all_currencies();
139
+			}
140
+			foreach ($currencies as $currency_code) {
141
+				if (
142
+					$this->count_records_migrated() <= $iterator &&
143
+						$iterator < $migrate_up_to_count
144
+				) {
145
+					$relations_to_add_this_step[ $pm_slug ] [] = $currency_code;
146
+				}
147
+				$iterator++;
148
+			}
149
+		}
150
+		return $relations_to_add_this_step;
151
+	}
152
+	/**
153
+	 * Gets all the currency codes in the database
154
+	 * @return array
155
+	 */
156
+	private function _get_all_currencies()
157
+	{
158
+		global $wpdb;
159
+		$currencies = $wpdb->get_col("SELECT CUR_code FROM {$this->_currency_table_name}");
160
+		return $currencies;
161
+	}
162 162
 
163
-    /**
164
-     * Adds teh relation between the payment method and the currencies it can be used for
165
-     * @param int $id
166
-     * @param string $gateway_slug
167
-     */
168
-    private function _add_currency_relations($pm_id, $currency_code)
169
-    {
170
-        global $wpdb;
171
-        $cur_pm_relation = array(
172
-                    'CUR_code' => $currency_code,
173
-                    'PMD_ID' => $pm_id,
174
-                );
175
-        $success = $wpdb->insert(
176
-            $this->_currency_payment_method_table_name,
177
-            $cur_pm_relation,
178
-            array(
179
-                    '%s',// CUR_code
180
-                    '%d',// PMD_ID
181
-                )
182
-        );
183
-        if (! $success) {
184
-            $this->add_error(sprintf(__('Could not add currency relation %s because %s', "event_espresso"), wp_json_encode($cur_pm_relation), $wpdb->last_error));
185
-        }
186
-    }
163
+	/**
164
+	 * Adds teh relation between the payment method and the currencies it can be used for
165
+	 * @param int $id
166
+	 * @param string $gateway_slug
167
+	 */
168
+	private function _add_currency_relations($pm_id, $currency_code)
169
+	{
170
+		global $wpdb;
171
+		$cur_pm_relation = array(
172
+					'CUR_code' => $currency_code,
173
+					'PMD_ID' => $pm_id,
174
+				);
175
+		$success = $wpdb->insert(
176
+			$this->_currency_payment_method_table_name,
177
+			$cur_pm_relation,
178
+			array(
179
+					'%s',// CUR_code
180
+					'%d',// PMD_ID
181
+				)
182
+		);
183
+		if (! $success) {
184
+			$this->add_error(sprintf(__('Could not add currency relation %s because %s', "event_espresso"), wp_json_encode($cur_pm_relation), $wpdb->last_error));
185
+		}
186
+	}
187 187
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -89,9 +89,9 @@  discard block
 block discarded – undo
89 89
     {
90 90
         global $wpdb;
91 91
         $this->_pretty_name = __('Payment Method Currencies', 'event_espresso');
92
-        $this->_payment_method_table_name = $wpdb->prefix . 'esp_payment_method';
93
-        $this->_currency_payment_method_table_name = $wpdb->prefix . 'esp_currency_payment_method';
94
-        $this->_currency_table_name = $wpdb->prefix . 'esp_currency';
92
+        $this->_payment_method_table_name = $wpdb->prefix.'esp_payment_method';
93
+        $this->_currency_payment_method_table_name = $wpdb->prefix.'esp_currency_payment_method';
94
+        $this->_currency_table_name = $wpdb->prefix.'esp_currency';
95 95
         parent::__construct();
96 96
     }
97 97
 
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
                     $this->count_records_migrated() <= $iterator &&
143 143
                         $iterator < $migrate_up_to_count
144 144
                 ) {
145
-                    $relations_to_add_this_step[ $pm_slug ] [] = $currency_code;
145
+                    $relations_to_add_this_step[$pm_slug] [] = $currency_code;
146 146
                 }
147 147
                 $iterator++;
148 148
             }
@@ -176,11 +176,11 @@  discard block
 block discarded – undo
176 176
             $this->_currency_payment_method_table_name,
177 177
             $cur_pm_relation,
178 178
             array(
179
-                    '%s',// CUR_code
180
-                    '%d',// PMD_ID
179
+                    '%s', // CUR_code
180
+                    '%d', // PMD_ID
181 181
                 )
182 182
         );
183
-        if (! $success) {
183
+        if ( ! $success) {
184 184
             $this->add_error(sprintf(__('Could not add currency relation %s because %s', "event_espresso"), wp_json_encode($cur_pm_relation), $wpdb->last_error));
185 185
         }
186 186
     }
Please login to merge, or discard this patch.
core/data_migration_scripts/4_6_0_stages/EE_DMS_4_6_0_payments.dmsstage.php 3 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -58,7 +58,6 @@
 block discarded – undo
58 58
             'IV'=>  __("Invoice", 'event_espresso'),
59 59
             'MO'=>  __("Money Order", 'event_espresso'),
60 60
      * @global type $wpdb
61
-     * @param int $id
62 61
      * @return string
63 62
      */
64 63
     protected function _get_payment_method_id_by_gateway_name($gateway_name, $old_pay_method_column)
Please login to merge, or discard this patch.
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -11,44 +11,44 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class EE_DMS_4_6_0_payments extends EE_Data_Migration_Script_Stage_Table
13 13
 {
14
-    protected $_payment_method_table;
15
-    public function __construct()
16
-    {
17
-        global $wpdb;
18
-        $this->_old_table = $wpdb->prefix . 'esp_payment';
19
-        $this->_payment_method_table = $wpdb->prefix . 'esp_payment_method';
20
-        $this->_pretty_name = __('Payment-Payment Method Relations', 'event_espresso');
21
-        parent::__construct();
22
-    }
23
-    protected function _migrate_old_row($payment_row)
24
-    {
25
-        global $wpdb;
26
-        // get the payment method's ID
27
-        $PMD_ID = apply_filters('FHEE__EE_DMS_4_6_0_payments__migrate_old_row__PMD_ID', $this->_get_payment_method_id_by_gateway_name($payment_row['PAY_gateway'], $payment_row['PAY_method']));
28
-        if (! $PMD_ID) {
29
-            $this->add_error(sprintf(__('Could not find payment method with PMD_type = \'%1$s\' when migrating payment row %2$s so just assigned it an unknown payment method', 'event_espresso'), $payment_row['PAY_gateway'], $this->_json_encode($payment_row)));
30
-            $PMD_ID = 0;
31
-        }
32
-        $new_values = array(
33
-            'PMD_ID' => $PMD_ID,
34
-            'PAY_source' => ( $payment_row['PAY_via_admin'] ? 'ADMIN' : 'CART' ) );
35
-        $wheres = array( 'PAY_ID' => $payment_row['PAY_ID'] );
36
-        $new_value_datatypes = array( '%d', '%s' );
37
-        $where_datatypes = array( '%d' );
38
-        $success = $wpdb->update(
39
-            $this->_old_table,
40
-            $new_values,
41
-            $wheres,
42
-            $new_value_datatypes,
43
-            $where_datatypes
44
-        );
45
-        if (! $success) {
46
-            $this->add_error(sprintf(__('Couldnt set %1$s row in table %2$s where %3$s', 'event_espresso'), $this->_json_encode($new_values), $this->_old_table, $this->_json_encode($wheres)));
47
-        }
48
-    }
49
-    /**
50
-     *
51
-     *  array(
14
+	protected $_payment_method_table;
15
+	public function __construct()
16
+	{
17
+		global $wpdb;
18
+		$this->_old_table = $wpdb->prefix . 'esp_payment';
19
+		$this->_payment_method_table = $wpdb->prefix . 'esp_payment_method';
20
+		$this->_pretty_name = __('Payment-Payment Method Relations', 'event_espresso');
21
+		parent::__construct();
22
+	}
23
+	protected function _migrate_old_row($payment_row)
24
+	{
25
+		global $wpdb;
26
+		// get the payment method's ID
27
+		$PMD_ID = apply_filters('FHEE__EE_DMS_4_6_0_payments__migrate_old_row__PMD_ID', $this->_get_payment_method_id_by_gateway_name($payment_row['PAY_gateway'], $payment_row['PAY_method']));
28
+		if (! $PMD_ID) {
29
+			$this->add_error(sprintf(__('Could not find payment method with PMD_type = \'%1$s\' when migrating payment row %2$s so just assigned it an unknown payment method', 'event_espresso'), $payment_row['PAY_gateway'], $this->_json_encode($payment_row)));
30
+			$PMD_ID = 0;
31
+		}
32
+		$new_values = array(
33
+			'PMD_ID' => $PMD_ID,
34
+			'PAY_source' => ( $payment_row['PAY_via_admin'] ? 'ADMIN' : 'CART' ) );
35
+		$wheres = array( 'PAY_ID' => $payment_row['PAY_ID'] );
36
+		$new_value_datatypes = array( '%d', '%s' );
37
+		$where_datatypes = array( '%d' );
38
+		$success = $wpdb->update(
39
+			$this->_old_table,
40
+			$new_values,
41
+			$wheres,
42
+			$new_value_datatypes,
43
+			$where_datatypes
44
+		);
45
+		if (! $success) {
46
+			$this->add_error(sprintf(__('Couldnt set %1$s row in table %2$s where %3$s', 'event_espresso'), $this->_json_encode($new_values), $this->_old_table, $this->_json_encode($wheres)));
47
+		}
48
+	}
49
+	/**
50
+	 *
51
+	 *  array(
52 52
             'PP' => __( 'PayPal', 'event_espresso' ),
53 53
             'CC' => __( 'Credit Card', 'event_espresso' ),
54 54
             'DB'=>  __("Debit Card", 'event_espresso'),
@@ -57,44 +57,44 @@  discard block
 block discarded – undo
57 57
             'BK'=>  __("Bank", 'event_espresso'),
58 58
             'IV'=>  __("Invoice", 'event_espresso'),
59 59
             'MO'=>  __("Money Order", 'event_espresso'),
60
-     * @global type $wpdb
61
-     * @param int $id
62
-     * @return string
63
-     */
64
-    protected function _get_payment_method_id_by_gateway_name($gateway_name, $old_pay_method_column)
65
-    {
66
-        global $wpdb;
67
-        // convert from old known PAY_method values to their corresponding
68
-        // PMD_type or default PMD_name
69
-        switch ($old_pay_method_column) {
70
-            case 'PP':
71
-                $pmd_type = 'Paypal_Standard';
72
-                break;
73
-            case 'CC':
74
-                $pmd_type = 'Credit_Card';
75
-                break;
76
-            case 'DB':
77
-                $pmd_type = 'Debit_Card';
78
-                break;
79
-            case 'CHQ':
80
-                $pmd_type = 'Check';
81
-                break;
82
-            case 'CSH':
83
-                $pmd_type = 'Cash';
84
-                break;
85
-            case 'BK':
86
-                $pmd_type = 'Bank';
87
-                break;
88
-            case 'IV':
89
-                $pmd_type = 'Invoice';
90
-                break;
91
-            case 'MO':
92
-                $pmd_type = 'Money_Order';
93
-                break;
94
-            default:
95
-                $pmd_type = $gateway_name;
96
-        }
97
-        $pmd_name = str_replace("_", " ", $pmd_type);
98
-        return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM " . $wpdb->prefix . "esp_payment_method WHERE PMD_type = %s OR PMD_name = %s", $pmd_type, $pmd_name));
99
-    }
60
+	 * @global type $wpdb
61
+	 * @param int $id
62
+	 * @return string
63
+	 */
64
+	protected function _get_payment_method_id_by_gateway_name($gateway_name, $old_pay_method_column)
65
+	{
66
+		global $wpdb;
67
+		// convert from old known PAY_method values to their corresponding
68
+		// PMD_type or default PMD_name
69
+		switch ($old_pay_method_column) {
70
+			case 'PP':
71
+				$pmd_type = 'Paypal_Standard';
72
+				break;
73
+			case 'CC':
74
+				$pmd_type = 'Credit_Card';
75
+				break;
76
+			case 'DB':
77
+				$pmd_type = 'Debit_Card';
78
+				break;
79
+			case 'CHQ':
80
+				$pmd_type = 'Check';
81
+				break;
82
+			case 'CSH':
83
+				$pmd_type = 'Cash';
84
+				break;
85
+			case 'BK':
86
+				$pmd_type = 'Bank';
87
+				break;
88
+			case 'IV':
89
+				$pmd_type = 'Invoice';
90
+				break;
91
+			case 'MO':
92
+				$pmd_type = 'Money_Order';
93
+				break;
94
+			default:
95
+				$pmd_type = $gateway_name;
96
+		}
97
+		$pmd_name = str_replace("_", " ", $pmd_type);
98
+		return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM " . $wpdb->prefix . "esp_payment_method WHERE PMD_type = %s OR PMD_name = %s", $pmd_type, $pmd_name));
99
+	}
100 100
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -15,8 +15,8 @@  discard block
 block discarded – undo
15 15
     public function __construct()
16 16
     {
17 17
         global $wpdb;
18
-        $this->_old_table = $wpdb->prefix . 'esp_payment';
19
-        $this->_payment_method_table = $wpdb->prefix . 'esp_payment_method';
18
+        $this->_old_table = $wpdb->prefix.'esp_payment';
19
+        $this->_payment_method_table = $wpdb->prefix.'esp_payment_method';
20 20
         $this->_pretty_name = __('Payment-Payment Method Relations', 'event_espresso');
21 21
         parent::__construct();
22 22
     }
@@ -25,16 +25,16 @@  discard block
 block discarded – undo
25 25
         global $wpdb;
26 26
         // get the payment method's ID
27 27
         $PMD_ID = apply_filters('FHEE__EE_DMS_4_6_0_payments__migrate_old_row__PMD_ID', $this->_get_payment_method_id_by_gateway_name($payment_row['PAY_gateway'], $payment_row['PAY_method']));
28
-        if (! $PMD_ID) {
28
+        if ( ! $PMD_ID) {
29 29
             $this->add_error(sprintf(__('Could not find payment method with PMD_type = \'%1$s\' when migrating payment row %2$s so just assigned it an unknown payment method', 'event_espresso'), $payment_row['PAY_gateway'], $this->_json_encode($payment_row)));
30 30
             $PMD_ID = 0;
31 31
         }
32 32
         $new_values = array(
33 33
             'PMD_ID' => $PMD_ID,
34
-            'PAY_source' => ( $payment_row['PAY_via_admin'] ? 'ADMIN' : 'CART' ) );
35
-        $wheres = array( 'PAY_ID' => $payment_row['PAY_ID'] );
36
-        $new_value_datatypes = array( '%d', '%s' );
37
-        $where_datatypes = array( '%d' );
34
+            'PAY_source' => ($payment_row['PAY_via_admin'] ? 'ADMIN' : 'CART') );
35
+        $wheres = array('PAY_ID' => $payment_row['PAY_ID']);
36
+        $new_value_datatypes = array('%d', '%s');
37
+        $where_datatypes = array('%d');
38 38
         $success = $wpdb->update(
39 39
             $this->_old_table,
40 40
             $new_values,
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
             $new_value_datatypes,
43 43
             $where_datatypes
44 44
         );
45
-        if (! $success) {
45
+        if ( ! $success) {
46 46
             $this->add_error(sprintf(__('Couldnt set %1$s row in table %2$s where %3$s', 'event_espresso'), $this->_json_encode($new_values), $this->_old_table, $this->_json_encode($wheres)));
47 47
         }
48 48
     }
@@ -95,6 +95,6 @@  discard block
 block discarded – undo
95 95
                 $pmd_type = $gateway_name;
96 96
         }
97 97
         $pmd_name = str_replace("_", " ", $pmd_type);
98
-        return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM " . $wpdb->prefix . "esp_payment_method WHERE PMD_type = %s OR PMD_name = %s", $pmd_type, $pmd_name));
98
+        return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM ".$wpdb->prefix."esp_payment_method WHERE PMD_type = %s OR PMD_name = %s", $pmd_type, $pmd_name));
99 99
     }
100 100
 }
Please login to merge, or discard this patch.
data_migration_scripts/4_6_0_stages/EE_DMS_4_6_0_transactions.dmsstage.php 3 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -50,7 +50,6 @@
 block discarded – undo
50 50
     /**
51 51
      *
52 52
      * @global type $wpdb
53
-     * @param int $id
54 53
      * @return string
55 54
      */
56 55
     protected function _get_payment_method_id_by_gateway_name($gateway_name)
Please login to merge, or discard this patch.
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -11,51 +11,51 @@
 block discarded – undo
11 11
  */
12 12
 class EE_DMS_4_6_0_transactions extends EE_Data_Migration_Script_Stage_Table
13 13
 {
14
-    protected $_transaction_table;
15
-    protected $_payment_method_table;
16
-    public function __construct()
17
-    {
18
-        global $wpdb;
19
-        $this->_old_table = $wpdb->prefix . 'esp_extra_meta';
20
-        $this->_transaction_table = $wpdb->prefix . 'esp_transaction';
21
-        $this->_payment_method_table = $wpdb->prefix . 'esp_payment_method';
22
-        $this->_pretty_name = __('Transaction Payment Method Relations', 'event_espresso');
23
-        $this->_extra_where_sql = "WHERE EXM_key = 'gateway' AND EXM_type = 'Transaction'";
24
-        parent::__construct();
25
-    }
26
-    protected function _migrate_old_row($extra_meta_row)
27
-    {
28
-        global $wpdb;
29
-        // get the payment method's ID
30
-        $PMD_ID = $this->_get_payment_method_id_by_gateway_name($extra_meta_row['EXM_value']);
31
-        if (! $PMD_ID) {
32
-            $this->add_error(sprintf(__('Could not find payment method with PMD_type = \'%1$s\' when migrating extra meta row %2$s', 'event_espresso'), $extra_meta_row['EXM_value'], $this->_json_encode($extra_meta_row)));
33
-            return;
34
-        }
35
-        $new_values = array( 'PMD_ID' => $PMD_ID );
36
-        $wheres = array( 'TXN_ID' => $extra_meta_row['OBJ_ID'] );
37
-        $new_value_datatypes = array( '%d' );
38
-        $where_datatypes = array( '%d' );
39
-        $success = $wpdb->update(
40
-            $this->_transaction_table,
41
-            $new_values,
42
-            $wheres,
43
-            $new_value_datatypes,
44
-            $where_datatypes
45
-        );
46
-        if (! $success) {
47
-            $this->add_error(sprintf(__('Couldnt set %1$s row in table %2$s where %3$s', 'event_espresso'), $this->_json_encode($new_values), $this->_transaction_table, $this->_json_encode($wheres)));
48
-        }
49
-    }
50
-    /**
51
-     *
52
-     * @global type $wpdb
53
-     * @param int $id
54
-     * @return string
55
-     */
56
-    protected function _get_payment_method_id_by_gateway_name($gateway_name)
57
-    {
58
-        global $wpdb;
59
-        return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM " . $wpdb->prefix . "esp_payment_method WHERE PMD_type = %s", $gateway_name));
60
-    }
14
+	protected $_transaction_table;
15
+	protected $_payment_method_table;
16
+	public function __construct()
17
+	{
18
+		global $wpdb;
19
+		$this->_old_table = $wpdb->prefix . 'esp_extra_meta';
20
+		$this->_transaction_table = $wpdb->prefix . 'esp_transaction';
21
+		$this->_payment_method_table = $wpdb->prefix . 'esp_payment_method';
22
+		$this->_pretty_name = __('Transaction Payment Method Relations', 'event_espresso');
23
+		$this->_extra_where_sql = "WHERE EXM_key = 'gateway' AND EXM_type = 'Transaction'";
24
+		parent::__construct();
25
+	}
26
+	protected function _migrate_old_row($extra_meta_row)
27
+	{
28
+		global $wpdb;
29
+		// get the payment method's ID
30
+		$PMD_ID = $this->_get_payment_method_id_by_gateway_name($extra_meta_row['EXM_value']);
31
+		if (! $PMD_ID) {
32
+			$this->add_error(sprintf(__('Could not find payment method with PMD_type = \'%1$s\' when migrating extra meta row %2$s', 'event_espresso'), $extra_meta_row['EXM_value'], $this->_json_encode($extra_meta_row)));
33
+			return;
34
+		}
35
+		$new_values = array( 'PMD_ID' => $PMD_ID );
36
+		$wheres = array( 'TXN_ID' => $extra_meta_row['OBJ_ID'] );
37
+		$new_value_datatypes = array( '%d' );
38
+		$where_datatypes = array( '%d' );
39
+		$success = $wpdb->update(
40
+			$this->_transaction_table,
41
+			$new_values,
42
+			$wheres,
43
+			$new_value_datatypes,
44
+			$where_datatypes
45
+		);
46
+		if (! $success) {
47
+			$this->add_error(sprintf(__('Couldnt set %1$s row in table %2$s where %3$s', 'event_espresso'), $this->_json_encode($new_values), $this->_transaction_table, $this->_json_encode($wheres)));
48
+		}
49
+	}
50
+	/**
51
+	 *
52
+	 * @global type $wpdb
53
+	 * @param int $id
54
+	 * @return string
55
+	 */
56
+	protected function _get_payment_method_id_by_gateway_name($gateway_name)
57
+	{
58
+		global $wpdb;
59
+		return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM " . $wpdb->prefix . "esp_payment_method WHERE PMD_type = %s", $gateway_name));
60
+	}
61 61
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -16,9 +16,9 @@  discard block
 block discarded – undo
16 16
     public function __construct()
17 17
     {
18 18
         global $wpdb;
19
-        $this->_old_table = $wpdb->prefix . 'esp_extra_meta';
20
-        $this->_transaction_table = $wpdb->prefix . 'esp_transaction';
21
-        $this->_payment_method_table = $wpdb->prefix . 'esp_payment_method';
19
+        $this->_old_table = $wpdb->prefix.'esp_extra_meta';
20
+        $this->_transaction_table = $wpdb->prefix.'esp_transaction';
21
+        $this->_payment_method_table = $wpdb->prefix.'esp_payment_method';
22 22
         $this->_pretty_name = __('Transaction Payment Method Relations', 'event_espresso');
23 23
         $this->_extra_where_sql = "WHERE EXM_key = 'gateway' AND EXM_type = 'Transaction'";
24 24
         parent::__construct();
@@ -28,14 +28,14 @@  discard block
 block discarded – undo
28 28
         global $wpdb;
29 29
         // get the payment method's ID
30 30
         $PMD_ID = $this->_get_payment_method_id_by_gateway_name($extra_meta_row['EXM_value']);
31
-        if (! $PMD_ID) {
31
+        if ( ! $PMD_ID) {
32 32
             $this->add_error(sprintf(__('Could not find payment method with PMD_type = \'%1$s\' when migrating extra meta row %2$s', 'event_espresso'), $extra_meta_row['EXM_value'], $this->_json_encode($extra_meta_row)));
33 33
             return;
34 34
         }
35
-        $new_values = array( 'PMD_ID' => $PMD_ID );
36
-        $wheres = array( 'TXN_ID' => $extra_meta_row['OBJ_ID'] );
37
-        $new_value_datatypes = array( '%d' );
38
-        $where_datatypes = array( '%d' );
35
+        $new_values = array('PMD_ID' => $PMD_ID);
36
+        $wheres = array('TXN_ID' => $extra_meta_row['OBJ_ID']);
37
+        $new_value_datatypes = array('%d');
38
+        $where_datatypes = array('%d');
39 39
         $success = $wpdb->update(
40 40
             $this->_transaction_table,
41 41
             $new_values,
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
             $new_value_datatypes,
44 44
             $where_datatypes
45 45
         );
46
-        if (! $success) {
46
+        if ( ! $success) {
47 47
             $this->add_error(sprintf(__('Couldnt set %1$s row in table %2$s where %3$s', 'event_espresso'), $this->_json_encode($new_values), $this->_transaction_table, $this->_json_encode($wheres)));
48 48
         }
49 49
     }
@@ -56,6 +56,6 @@  discard block
 block discarded – undo
56 56
     protected function _get_payment_method_id_by_gateway_name($gateway_name)
57 57
     {
58 58
         global $wpdb;
59
-        return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM " . $wpdb->prefix . "esp_payment_method WHERE PMD_type = %s", $gateway_name));
59
+        return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM ".$wpdb->prefix."esp_payment_method WHERE PMD_type = %s", $gateway_name));
60 60
     }
61 61
 }
Please login to merge, or discard this patch.
core/data_migration_scripts/EE_Data_Migration_Class_Base.core.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -325,7 +325,7 @@
 block discarded – undo
325 325
      * @param array  $old_row_as_array
326 326
      * @param string $new_table
327 327
      * @param array  $new_row_as_array columns=>values like used in wpdb->insert
328
-     * @param array  $data_types       numerically indexed
328
+     * @param string[]  $data_types       numerically indexed
329 329
      * @return string
330 330
      */
331 331
     protected function _create_error_message_for_db_insertion(
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
      */
186 186
     public function add_error($error, $force = false)
187 187
     {
188
-        if (! defined('EE_DMS_ERROR_LIMIT')) {
188
+        if ( ! defined('EE_DMS_ERROR_LIMIT')) {
189 189
             $limit = 50;
190 190
         } else {
191 191
             $limit = EE_DMS_ERROR_LIMIT;
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
                 $this->_errors[] = "Limit reached; removed first half of errors to save space";
202 202
                 $this->_errors[] = $error;
203 203
             } else {
204
-                $this->_errors[ $limit ] = 'More, but limit reached...';
204
+                $this->_errors[$limit] = 'More, but limit reached...';
205 205
             }
206 206
         } else {
207 207
             $this->_errors[] = $error;
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
         $new_columns_and_values_for_string = array();
344 344
         $count = 0;
345 345
         foreach ($new_row_as_array as $column => $value) {
346
-            $new_columns_and_values_for_string[] = " $column => $value (" . $data_types[ $count++ ] . ")";
346
+            $new_columns_and_values_for_string[] = " $column => $value (".$data_types[$count++].")";
347 347
         }
348 348
         return sprintf(
349 349
             __(
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
         foreach ($array_of_data as $name => $value) {
375 375
             $unserialized_data = @unserialize($value);
376 376
             if ($unserialized_data === false) {
377
-                $fields_to_include[ $name ] = $value;
377
+                $fields_to_include[$name] = $value;
378 378
             }
379 379
         }
380 380
         return wp_json_encode($fields_to_include);
Please login to merge, or discard this patch.
Indentation   +404 added lines, -404 removed lines patch added patch discarded remove patch
@@ -17,408 +17,408 @@
 block discarded – undo
17 17
 abstract class EE_Data_Migration_Class_Base
18 18
 {
19 19
 
20
-    /**
21
-     * @var $records_to_migrate int count of all that have been migrated
22
-     */
23
-    protected $_records_to_migrate = 0;
24
-
25
-    /**
26
-     *
27
-     * @var $records_migrated int
28
-     */
29
-    protected $_records_migrated = 0;
30
-
31
-    /**
32
-     * Whether this migration script is done or not. This COULD be deduced by
33
-     * _records_to_migrate and _records_migrated, but that might nto be accurate
34
-     *
35
-     * @var string one of EE_Data_migration_Manager::status_* constants
36
-     */
37
-    protected $_status = null;
38
-
39
-    /**
40
-     * internationalized name of this class. Convention is to NOT restate that
41
-     * this class if a migration script or a migration script stage
42
-     *
43
-     * @var string (i18ned)
44
-     */
45
-    protected $_pretty_name = null;
46
-
47
-    /**
48
-     * @var array
49
-     */
50
-    protected $_errors = array();
51
-
52
-    /**
53
-     * @var \EventEspresso\core\services\database\TableManager $table_manager
54
-     */
55
-    protected $_table_manager;
56
-
57
-    /**
58
-     * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
59
-     */
60
-    protected $_table_analysis;
61
-
62
-
63
-    /**
64
-     * Just initializes the status of the migration
65
-     *
66
-     * @param TableManager  $table_manager
67
-     * @param TableAnalysis $table_analysis
68
-     */
69
-    public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
70
-    {
71
-        $this->_table_manager = $table_manager;
72
-        $this->_table_analysis = $table_analysis;
73
-        $this->set_status(EE_Data_Migration_Manager::status_continue);
74
-    }
75
-
76
-
77
-    /**
78
-     * Just gets the pretty name for this migration script or stage
79
-     *
80
-     * @throws EE_Error
81
-     * @return string
82
-     */
83
-    public function pretty_name()
84
-    {
85
-        if ($this->_pretty_name === null) {
86
-            throw new EE_Error(
87
-                sprintf(
88
-                    __(
89
-                        "Please give a pretty name to the migration script stage %s by assigning the property _pretty_name in the constructor",
90
-                        "event_espresso"
91
-                    ),
92
-                    get_class($this)
93
-                )
94
-            );
95
-        }
96
-        return $this->_pretty_name;
97
-    }
98
-
99
-    /**
100
-     *
101
-     * @return int
102
-     */
103
-    public function count_records_to_migrate()
104
-    {
105
-        if ($this->_records_to_migrate == null) {
106
-            $this->_records_to_migrate = $this->_count_records_to_migrate();
107
-        }
108
-        return $this->_records_to_migrate;
109
-    }
110
-
111
-    /**
112
-     * Counts records already migrated. This should only be implemented by EE_Data_Migration_Script_base and
113
-     * EE_Data_migration_Script_Stage
114
-     *
115
-     * @return int
116
-     */
117
-    abstract public function count_records_migrated();
118
-
119
-    /**
120
-     * Counts the records to migrate; the public version may cache it
121
-     *
122
-     * @return int
123
-     */
124
-    abstract protected function _count_records_to_migrate();
125
-
126
-    /**
127
-     * Returns a string indicating the migration script's status.
128
-     *
129
-     * @return string one of EE_Data_Migration_Manager::status_* constants
130
-     * @throws EE_Error
131
-     */
132
-    public function get_status()
133
-    {
134
-        if ($this->_status === null) {
135
-            throw new EE_Error(
136
-                sprintf(
137
-                    __(
138
-                        "Trying to get status of Migration class %s, but it has not been initialized yet. It should be set in the constructor.",
139
-                        "event_espresso"
140
-                    ),
141
-                    get_class($this)
142
-                )
143
-            );
144
-        }
145
-        return $this->_status;
146
-    }
147
-
148
-    /**
149
-     *
150
-     * @param string $status
151
-     * @return void
152
-     */
153
-    protected function set_status($status)
154
-    {
155
-        $this->_status = $status;
156
-    }
157
-
158
-    /**
159
-     * @return array of strings
160
-     */
161
-    abstract public function get_errors();
162
-
163
-    /**
164
-     * Returns the last error that occurred. If none occurred, returns null
165
-     *
166
-     * @return string
167
-     */
168
-    public function get_last_error()
169
-    {
170
-        $errors = $this->get_errors();
171
-        if ($errors) {
172
-            return end($errors);
173
-        } else {
174
-            return null;
175
-        }
176
-    }
177
-
178
-    /**
179
-     * Adds an error to the array of errors on this class.
180
-     *
181
-     * @param string  $error a string describing the error that will be useful for debugging. Consider including all
182
-     *                       the data that led to the error, and a stack trace etc.
183
-     * @param boolean $force force the error to be added (because otherwise we have a limit). If forcing and errors are
184
-     *                       already at their limit, we will purposefully forget the first half
185
-     */
186
-    public function add_error($error, $force = false)
187
-    {
188
-        if (! defined('EE_DMS_ERROR_LIMIT')) {
189
-            $limit = 50;
190
-        } else {
191
-            $limit = EE_DMS_ERROR_LIMIT;
192
-        }
193
-        // make sure errors is an array, see ticket #8261
194
-        if (is_string($this->_errors)) {
195
-            $this->_errors = array($this->_errors);
196
-        }
197
-        if (count($this->_errors) >= $limit) {
198
-            if ($force) {
199
-                // get rid of the first half of the errors and any above the limit
200
-                $this->_errors = array_slice($this->_errors, $limit / 2, $limit / 2);
201
-                $this->_errors[] = "Limit reached; removed first half of errors to save space";
202
-                $this->_errors[] = $error;
203
-            } else {
204
-                $this->_errors[ $limit ] = 'More, but limit reached...';
205
-            }
206
-        } else {
207
-            $this->_errors[] = $error;
208
-        }
209
-    }
210
-
211
-    /**
212
-     * Indicates there was a fatal error and the migration cannot possibly continue
213
-     *
214
-     * @return boolean
215
-     */
216
-    public function is_broken()
217
-    {
218
-        return $this->get_status() == EE_Data_Migration_Manager::status_fatal_error;
219
-    }
220
-
221
-    /**
222
-     * @deprecated since 4.6.12
223
-     */
224
-    public function is_borked()
225
-    {
226
-        EE_Error::doing_it_wrong(
227
-            'is_borked',
228
-            __(
229
-                'The cheeky "is_borked" method had been replaced with the more proper "is_broken"',
230
-                'event_espresso'
231
-            ),
232
-            '4.6.12'
233
-        );
234
-        return $this->is_broken();
235
-    }
236
-
237
-    /**
238
-     * Sets the status to as having a fatal error
239
-     */
240
-    public function set_broken()
241
-    {
242
-        $this->_status = EE_Data_Migration_Manager::status_fatal_error;
243
-    }
244
-
245
-    /**
246
-     *
247
-     * @deprecated since 4.6.12
248
-     */
249
-    public function set_borked()
250
-    {
251
-        EE_Error::doing_it_wrong(
252
-            'is_borked',
253
-            __(
254
-                'The cheeky "is_borked" method had been replaced with the more proper "is_broken"',
255
-                'event_espresso'
256
-            ),
257
-            '4.6.12'
258
-        );
259
-        return $this->set_broken();
260
-    }
261
-
262
-    /**
263
-     * Checks if this thing believes it is completed
264
-     *
265
-     * @return boolean
266
-     */
267
-    public function is_completed()
268
-    {
269
-        return $this->get_status() == EE_Data_Migration_Manager::status_completed;
270
-    }
271
-
272
-    /**
273
-     * Checks if the current script has more to do or not (ie, if it's status is CONTINUE)
274
-     *
275
-     * @return boolean
276
-     */
277
-    public function has_more_to_do()
278
-    {
279
-        return $this->get_status() == EE_Data_Migration_Manager::status_continue;
280
-    }
281
-
282
-    /**
283
-     * Marks that we believe this migration thing is completed
284
-     */
285
-    public function set_completed()
286
-    {
287
-        $this->_status = EE_Data_Migration_Manager::status_completed;
288
-    }
289
-
290
-    /**
291
-     * Marks that we think this migration class can continue to migrate
292
-     */
293
-    public function reattempt()
294
-    {
295
-        $this->_status = EE_Data_Migration_Manager::status_continue;
296
-        $this->add_error(__('Reattempt migration', 'event_espresso'), true);
297
-    }
298
-
299
-    /**
300
-     * A lot like "__sleep()" magic method in purpose, this is meant for persisting this class'
301
-     * properties to the DB. However, we don't want to use __sleep() because its quite
302
-     * possible that this class is defined when it goes to sleep, but NOT available when it
303
-     * awakes (eg, this class is part of an addon that is deactivated at some point).
304
-     */
305
-    public function properties_as_array()
306
-    {
307
-        $properties = get_object_vars($this);
308
-        $properties['class'] = get_class($this);
309
-        unset($properties['_migration_script']);
310
-        unset($properties['_table_manager']);
311
-        unset($properties['_table_analysis']);
312
-        return $properties;
313
-    }
314
-
315
-    /**
316
-     * Sets all of the properties of this script stage to match what's in the array, which is assumed
317
-     * to have been made from the properties_as_array() function.
318
-     *
319
-     * @param array $array_of_properties like what's produced from properties_as_array() method
320
-     */
321
-    abstract public function instantiate_from_array_of_properties($array_of_properties);
322
-
323
-    /**
324
-     * Convenience method for showing a database insertion error
325
-     *
326
-     * @param string $old_table
327
-     * @param array  $old_row_as_array
328
-     * @param string $new_table
329
-     * @param array  $new_row_as_array columns=>values like used in wpdb->insert
330
-     * @param array  $data_types       numerically indexed
331
-     * @return string
332
-     */
333
-    protected function _create_error_message_for_db_insertion(
334
-        $old_table,
335
-        $old_row_as_array,
336
-        $new_table,
337
-        $new_row_as_array,
338
-        $data_types
339
-    ) {
340
-        global $wpdb;
341
-        $old_columns_and_values_for_string = array();
342
-        foreach ($old_row_as_array as $column => $value) {
343
-            $old_columns_and_values_for_string[] = "$column => $value";
344
-        }
345
-        $new_columns_and_values_for_string = array();
346
-        $count = 0;
347
-        foreach ($new_row_as_array as $column => $value) {
348
-            $new_columns_and_values_for_string[] = " $column => $value (" . $data_types[ $count++ ] . ")";
349
-        }
350
-        return sprintf(
351
-            __(
352
-                'Received error "%6$s" inserting row %5$s %1$s %5$s into table %2$s.%5$s Data used was %5$s %3$s %5$s from table %4$s.',
353
-                'event_espresso'
354
-            ),
355
-            implode(", ", $new_columns_and_values_for_string),
356
-            $new_table,
357
-            implode(", ", $old_columns_and_values_for_string),
358
-            $old_table,
359
-            '<br/>',
360
-            $wpdb->last_error
361
-        );
362
-    }
363
-
364
-
365
-    /**
366
-     * Same as json_encode, just avoids putting
367
-     * serialized arrays into the http build query, as that would
368
-     *
369
-     * @param array $array_of_data
370
-     * @return string
371
-     */
372
-    protected function _json_encode($array_of_data)
373
-    {
374
-        // we'd rather NOT serialize the transaction details
375
-        $fields_to_include = array();
376
-        foreach ($array_of_data as $name => $value) {
377
-            $unserialized_data = @unserialize($value);
378
-            if ($unserialized_data === false) {
379
-                $fields_to_include[ $name ] = $value;
380
-            }
381
-        }
382
-        return wp_json_encode($fields_to_include);
383
-    }
384
-
385
-    /**
386
-     * Gets the table manager (or throws an exception if it cannot be retrieved)
387
-     *
388
-     * @return TableManager
389
-     * @throws EE_Error
390
-     */
391
-    protected function _get_table_manager()
392
-    {
393
-        if ($this->_table_manager instanceof TableManager) {
394
-            return $this->_table_manager;
395
-        } else {
396
-            throw new EE_Error(
397
-                sprintf(
398
-                    __('Table manager on migration class %1$s is not set properly.', 'event_espresso'),
399
-                    get_class($this)
400
-                )
401
-            );
402
-        }
403
-    }
404
-
405
-    /**
406
-     * Gets the injected table analyzer, or throws an exception
407
-     *
408
-     * @return TableAnalysis
409
-     * @throws EE_Error
410
-     */
411
-    protected function _get_table_analysis()
412
-    {
413
-        if ($this->_table_analysis instanceof TableAnalysis) {
414
-            return $this->_table_analysis;
415
-        } else {
416
-            throw new EE_Error(
417
-                sprintf(
418
-                    __('Table analysis class on migration class %1$s is not set properly.', 'event_espresso'),
419
-                    get_class($this)
420
-                )
421
-            );
422
-        }
423
-    }
20
+	/**
21
+	 * @var $records_to_migrate int count of all that have been migrated
22
+	 */
23
+	protected $_records_to_migrate = 0;
24
+
25
+	/**
26
+	 *
27
+	 * @var $records_migrated int
28
+	 */
29
+	protected $_records_migrated = 0;
30
+
31
+	/**
32
+	 * Whether this migration script is done or not. This COULD be deduced by
33
+	 * _records_to_migrate and _records_migrated, but that might nto be accurate
34
+	 *
35
+	 * @var string one of EE_Data_migration_Manager::status_* constants
36
+	 */
37
+	protected $_status = null;
38
+
39
+	/**
40
+	 * internationalized name of this class. Convention is to NOT restate that
41
+	 * this class if a migration script or a migration script stage
42
+	 *
43
+	 * @var string (i18ned)
44
+	 */
45
+	protected $_pretty_name = null;
46
+
47
+	/**
48
+	 * @var array
49
+	 */
50
+	protected $_errors = array();
51
+
52
+	/**
53
+	 * @var \EventEspresso\core\services\database\TableManager $table_manager
54
+	 */
55
+	protected $_table_manager;
56
+
57
+	/**
58
+	 * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
59
+	 */
60
+	protected $_table_analysis;
61
+
62
+
63
+	/**
64
+	 * Just initializes the status of the migration
65
+	 *
66
+	 * @param TableManager  $table_manager
67
+	 * @param TableAnalysis $table_analysis
68
+	 */
69
+	public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
70
+	{
71
+		$this->_table_manager = $table_manager;
72
+		$this->_table_analysis = $table_analysis;
73
+		$this->set_status(EE_Data_Migration_Manager::status_continue);
74
+	}
75
+
76
+
77
+	/**
78
+	 * Just gets the pretty name for this migration script or stage
79
+	 *
80
+	 * @throws EE_Error
81
+	 * @return string
82
+	 */
83
+	public function pretty_name()
84
+	{
85
+		if ($this->_pretty_name === null) {
86
+			throw new EE_Error(
87
+				sprintf(
88
+					__(
89
+						"Please give a pretty name to the migration script stage %s by assigning the property _pretty_name in the constructor",
90
+						"event_espresso"
91
+					),
92
+					get_class($this)
93
+				)
94
+			);
95
+		}
96
+		return $this->_pretty_name;
97
+	}
98
+
99
+	/**
100
+	 *
101
+	 * @return int
102
+	 */
103
+	public function count_records_to_migrate()
104
+	{
105
+		if ($this->_records_to_migrate == null) {
106
+			$this->_records_to_migrate = $this->_count_records_to_migrate();
107
+		}
108
+		return $this->_records_to_migrate;
109
+	}
110
+
111
+	/**
112
+	 * Counts records already migrated. This should only be implemented by EE_Data_Migration_Script_base and
113
+	 * EE_Data_migration_Script_Stage
114
+	 *
115
+	 * @return int
116
+	 */
117
+	abstract public function count_records_migrated();
118
+
119
+	/**
120
+	 * Counts the records to migrate; the public version may cache it
121
+	 *
122
+	 * @return int
123
+	 */
124
+	abstract protected function _count_records_to_migrate();
125
+
126
+	/**
127
+	 * Returns a string indicating the migration script's status.
128
+	 *
129
+	 * @return string one of EE_Data_Migration_Manager::status_* constants
130
+	 * @throws EE_Error
131
+	 */
132
+	public function get_status()
133
+	{
134
+		if ($this->_status === null) {
135
+			throw new EE_Error(
136
+				sprintf(
137
+					__(
138
+						"Trying to get status of Migration class %s, but it has not been initialized yet. It should be set in the constructor.",
139
+						"event_espresso"
140
+					),
141
+					get_class($this)
142
+				)
143
+			);
144
+		}
145
+		return $this->_status;
146
+	}
147
+
148
+	/**
149
+	 *
150
+	 * @param string $status
151
+	 * @return void
152
+	 */
153
+	protected function set_status($status)
154
+	{
155
+		$this->_status = $status;
156
+	}
157
+
158
+	/**
159
+	 * @return array of strings
160
+	 */
161
+	abstract public function get_errors();
162
+
163
+	/**
164
+	 * Returns the last error that occurred. If none occurred, returns null
165
+	 *
166
+	 * @return string
167
+	 */
168
+	public function get_last_error()
169
+	{
170
+		$errors = $this->get_errors();
171
+		if ($errors) {
172
+			return end($errors);
173
+		} else {
174
+			return null;
175
+		}
176
+	}
177
+
178
+	/**
179
+	 * Adds an error to the array of errors on this class.
180
+	 *
181
+	 * @param string  $error a string describing the error that will be useful for debugging. Consider including all
182
+	 *                       the data that led to the error, and a stack trace etc.
183
+	 * @param boolean $force force the error to be added (because otherwise we have a limit). If forcing and errors are
184
+	 *                       already at their limit, we will purposefully forget the first half
185
+	 */
186
+	public function add_error($error, $force = false)
187
+	{
188
+		if (! defined('EE_DMS_ERROR_LIMIT')) {
189
+			$limit = 50;
190
+		} else {
191
+			$limit = EE_DMS_ERROR_LIMIT;
192
+		}
193
+		// make sure errors is an array, see ticket #8261
194
+		if (is_string($this->_errors)) {
195
+			$this->_errors = array($this->_errors);
196
+		}
197
+		if (count($this->_errors) >= $limit) {
198
+			if ($force) {
199
+				// get rid of the first half of the errors and any above the limit
200
+				$this->_errors = array_slice($this->_errors, $limit / 2, $limit / 2);
201
+				$this->_errors[] = "Limit reached; removed first half of errors to save space";
202
+				$this->_errors[] = $error;
203
+			} else {
204
+				$this->_errors[ $limit ] = 'More, but limit reached...';
205
+			}
206
+		} else {
207
+			$this->_errors[] = $error;
208
+		}
209
+	}
210
+
211
+	/**
212
+	 * Indicates there was a fatal error and the migration cannot possibly continue
213
+	 *
214
+	 * @return boolean
215
+	 */
216
+	public function is_broken()
217
+	{
218
+		return $this->get_status() == EE_Data_Migration_Manager::status_fatal_error;
219
+	}
220
+
221
+	/**
222
+	 * @deprecated since 4.6.12
223
+	 */
224
+	public function is_borked()
225
+	{
226
+		EE_Error::doing_it_wrong(
227
+			'is_borked',
228
+			__(
229
+				'The cheeky "is_borked" method had been replaced with the more proper "is_broken"',
230
+				'event_espresso'
231
+			),
232
+			'4.6.12'
233
+		);
234
+		return $this->is_broken();
235
+	}
236
+
237
+	/**
238
+	 * Sets the status to as having a fatal error
239
+	 */
240
+	public function set_broken()
241
+	{
242
+		$this->_status = EE_Data_Migration_Manager::status_fatal_error;
243
+	}
244
+
245
+	/**
246
+	 *
247
+	 * @deprecated since 4.6.12
248
+	 */
249
+	public function set_borked()
250
+	{
251
+		EE_Error::doing_it_wrong(
252
+			'is_borked',
253
+			__(
254
+				'The cheeky "is_borked" method had been replaced with the more proper "is_broken"',
255
+				'event_espresso'
256
+			),
257
+			'4.6.12'
258
+		);
259
+		return $this->set_broken();
260
+	}
261
+
262
+	/**
263
+	 * Checks if this thing believes it is completed
264
+	 *
265
+	 * @return boolean
266
+	 */
267
+	public function is_completed()
268
+	{
269
+		return $this->get_status() == EE_Data_Migration_Manager::status_completed;
270
+	}
271
+
272
+	/**
273
+	 * Checks if the current script has more to do or not (ie, if it's status is CONTINUE)
274
+	 *
275
+	 * @return boolean
276
+	 */
277
+	public function has_more_to_do()
278
+	{
279
+		return $this->get_status() == EE_Data_Migration_Manager::status_continue;
280
+	}
281
+
282
+	/**
283
+	 * Marks that we believe this migration thing is completed
284
+	 */
285
+	public function set_completed()
286
+	{
287
+		$this->_status = EE_Data_Migration_Manager::status_completed;
288
+	}
289
+
290
+	/**
291
+	 * Marks that we think this migration class can continue to migrate
292
+	 */
293
+	public function reattempt()
294
+	{
295
+		$this->_status = EE_Data_Migration_Manager::status_continue;
296
+		$this->add_error(__('Reattempt migration', 'event_espresso'), true);
297
+	}
298
+
299
+	/**
300
+	 * A lot like "__sleep()" magic method in purpose, this is meant for persisting this class'
301
+	 * properties to the DB. However, we don't want to use __sleep() because its quite
302
+	 * possible that this class is defined when it goes to sleep, but NOT available when it
303
+	 * awakes (eg, this class is part of an addon that is deactivated at some point).
304
+	 */
305
+	public function properties_as_array()
306
+	{
307
+		$properties = get_object_vars($this);
308
+		$properties['class'] = get_class($this);
309
+		unset($properties['_migration_script']);
310
+		unset($properties['_table_manager']);
311
+		unset($properties['_table_analysis']);
312
+		return $properties;
313
+	}
314
+
315
+	/**
316
+	 * Sets all of the properties of this script stage to match what's in the array, which is assumed
317
+	 * to have been made from the properties_as_array() function.
318
+	 *
319
+	 * @param array $array_of_properties like what's produced from properties_as_array() method
320
+	 */
321
+	abstract public function instantiate_from_array_of_properties($array_of_properties);
322
+
323
+	/**
324
+	 * Convenience method for showing a database insertion error
325
+	 *
326
+	 * @param string $old_table
327
+	 * @param array  $old_row_as_array
328
+	 * @param string $new_table
329
+	 * @param array  $new_row_as_array columns=>values like used in wpdb->insert
330
+	 * @param array  $data_types       numerically indexed
331
+	 * @return string
332
+	 */
333
+	protected function _create_error_message_for_db_insertion(
334
+		$old_table,
335
+		$old_row_as_array,
336
+		$new_table,
337
+		$new_row_as_array,
338
+		$data_types
339
+	) {
340
+		global $wpdb;
341
+		$old_columns_and_values_for_string = array();
342
+		foreach ($old_row_as_array as $column => $value) {
343
+			$old_columns_and_values_for_string[] = "$column => $value";
344
+		}
345
+		$new_columns_and_values_for_string = array();
346
+		$count = 0;
347
+		foreach ($new_row_as_array as $column => $value) {
348
+			$new_columns_and_values_for_string[] = " $column => $value (" . $data_types[ $count++ ] . ")";
349
+		}
350
+		return sprintf(
351
+			__(
352
+				'Received error "%6$s" inserting row %5$s %1$s %5$s into table %2$s.%5$s Data used was %5$s %3$s %5$s from table %4$s.',
353
+				'event_espresso'
354
+			),
355
+			implode(", ", $new_columns_and_values_for_string),
356
+			$new_table,
357
+			implode(", ", $old_columns_and_values_for_string),
358
+			$old_table,
359
+			'<br/>',
360
+			$wpdb->last_error
361
+		);
362
+	}
363
+
364
+
365
+	/**
366
+	 * Same as json_encode, just avoids putting
367
+	 * serialized arrays into the http build query, as that would
368
+	 *
369
+	 * @param array $array_of_data
370
+	 * @return string
371
+	 */
372
+	protected function _json_encode($array_of_data)
373
+	{
374
+		// we'd rather NOT serialize the transaction details
375
+		$fields_to_include = array();
376
+		foreach ($array_of_data as $name => $value) {
377
+			$unserialized_data = @unserialize($value);
378
+			if ($unserialized_data === false) {
379
+				$fields_to_include[ $name ] = $value;
380
+			}
381
+		}
382
+		return wp_json_encode($fields_to_include);
383
+	}
384
+
385
+	/**
386
+	 * Gets the table manager (or throws an exception if it cannot be retrieved)
387
+	 *
388
+	 * @return TableManager
389
+	 * @throws EE_Error
390
+	 */
391
+	protected function _get_table_manager()
392
+	{
393
+		if ($this->_table_manager instanceof TableManager) {
394
+			return $this->_table_manager;
395
+		} else {
396
+			throw new EE_Error(
397
+				sprintf(
398
+					__('Table manager on migration class %1$s is not set properly.', 'event_espresso'),
399
+					get_class($this)
400
+				)
401
+			);
402
+		}
403
+	}
404
+
405
+	/**
406
+	 * Gets the injected table analyzer, or throws an exception
407
+	 *
408
+	 * @return TableAnalysis
409
+	 * @throws EE_Error
410
+	 */
411
+	protected function _get_table_analysis()
412
+	{
413
+		if ($this->_table_analysis instanceof TableAnalysis) {
414
+			return $this->_table_analysis;
415
+		} else {
416
+			throw new EE_Error(
417
+				sprintf(
418
+					__('Table analysis class on migration class %1$s is not set properly.', 'event_espresso'),
419
+					get_class($this)
420
+				)
421
+			);
422
+		}
423
+	}
424 424
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Message_Template_Group.model.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
      * @param        $messenger
85 85
      * @param string $orderby
86 86
      * @param string $order
87
-     * @return array all (including trashed or inactive) message template group objects for the given messenger
87
+     * @return EE_Base_Class[] all (including trashed or inactive) message template group objects for the given messenger
88 88
      */
89 89
     public function get_all_message_templates_by_messenger($messenger, $orderby = 'GRP_ID', $order = 'ASC')
90 90
     {
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
     /**
342 342
      * This sends things to the validator for the given messenger and message type.
343 343
      *
344
-     * @param  array $fields the incoming fields to check.
344
+     * @param  string $fields the incoming fields to check.
345 345
      *                       Note this array is in the formatted fields from the form fields setup.
346 346
      *                       So we need to reformat this into an array of expected field refs by the validator.
347 347
      *                       Note also that this is not only the fields for the Message Template Group
Please login to merge, or discard this patch.
Indentation   +425 added lines, -425 removed lines patch added patch discarded remove patch
@@ -12,429 +12,429 @@
 block discarded – undo
12 12
 class EEM_Message_Template_Group extends EEM_Soft_Delete_Base
13 13
 {
14 14
 
15
-    // private instance of the EEM_Message_Template_Group object
16
-    protected static $_instance = null;
17
-
18
-
19
-
20
-    protected function __construct($timezone = null)
21
-    {
22
-        $this->singular_item = __('Message Template Group', 'event_espresso');
23
-        $this->plural_item = __('Message Template Groups', 'event_espresso');
24
-        $this->_tables = array(
25
-            'Message_Template_Group' => new EE_Primary_Table('esp_message_template_group', 'GRP_ID')
26
-        );
27
-        $this->_fields = array(
28
-            'Message_Template_Group' => array(
29
-                'GRP_ID' => new EE_Primary_Key_Int_Field('GRP_ID', __('Message Template Group ID', 'event_espresso')),
30
-                'MTP_name' => new EE_Plain_Text_Field('MTP_name', __('The name of the template group', 'event_espresso'), false, ''),
31
-                'MTP_description' => new EE_Simple_HTML_Field('MTP_description', __('A brief description about this template.', 'event_espresso'), false, ''),
32
-                'MTP_user_id' => new EE_WP_User_Field('MTP_user_id', __('Template Creator ID', 'event_espresso'), false, get_current_user_id()),
33
-                'MTP_messenger' => new EE_Plain_Text_Field('MTP_messenger', __('Messenger Used for Template', 'event_espresso'), false, 'email'),
34
-                'MTP_message_type' => new EE_Plain_Text_Field('MTP_message_type', __('Message Type', 'event_espresso'), false, 'registration'),
35
-                'MTP_is_global' => new EE_Boolean_Field('MTP_is_global', __('Flag indicating if Template Group is Global', 'event_espresso'), false, true),
36
-                'MTP_is_override' => new EE_Boolean_Field('MTP_is_override', __('Flag indicating if Template Group overrides any other Templates for the messenger/messagetype combination', 'event_espresso'), false, false),
37
-                'MTP_deleted' => new EE_Trashed_Flag_Field('MTP_deleted', __('Flag indicating whether this has been trashed', 'event_espresso'), false, false),
38
-                'MTP_is_active' => new EE_Boolean_Field('MTP_is_active', __('Flag indicating whether template group is active', 'event_espresso'), false, true)
39
-            )
40
-        );
41
-        $this->_model_relations = array(
42
-            'Message_Template' => new EE_Has_Many_Relation(),
43
-            'Message' => new EE_Has_Many_Relation(),
44
-            'Event' => new EE_HABTM_Relation('Event_Message_Template'),
45
-            'WP_User' => new EE_Belongs_To_Relation()
46
-        );
47
-        foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
48
-            $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('MTP_is_global');
49
-        }
50
-        $this->_caps_slug = 'messages';
51
-
52
-        parent::__construct($timezone);
53
-    }
54
-
55
-
56
-
57
-    /**
58
-     * get_all_trashed_message_templates_by_event
59
-     *
60
-     * @access public
61
-     * @param int    $EVT_ID specific event id
62
-     * @param string $orderby
63
-     * @param string $order
64
-     * @param null   $limit
65
-     * @param bool   $count
66
-     * @return array message template objects that are attached to a specific event.
67
-     */
68
-    public function get_all_trashed_message_templates_by_event(
69
-        $EVT_ID,
70
-        $orderby = 'GRP_ID',
71
-        $order = 'ASC',
72
-        $limit = null,
73
-        $count = false
74
-    ) {
75
-        $query_params = array( array('Event.EVT_ID' => $EVT_ID), 'order_by' => array($orderby => $order), 'limit' => $limit );
76
-        return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params);
77
-    }
78
-
79
-
80
-
81
-    /**
82
-     * get_all_message_templates_by_messenger
83
-     *
84
-     * @access public
85
-     * @param        $messenger
86
-     * @param string $orderby
87
-     * @param string $order
88
-     * @return array all (including trashed or inactive) message template group objects for the given messenger
89
-     */
90
-    public function get_all_message_templates_by_messenger($messenger, $orderby = 'GRP_ID', $order = 'ASC')
91
-    {
92
-        return $this->get_all_deleted_and_undeleted(
93
-            array( array( 'MTP_messenger' => $messenger ), 'order_by' => array( $orderby => $order ) )
94
-        );
95
-    }
96
-
97
-
98
-
99
-    /**
100
-     * This simply adds on any messenger/message type filters that may be present in the $_POST global
101
-     * @param  array  $_where any existing where conditions to append these to.
102
-     * @return array          original where conditions or original with additional filters.
103
-     */
104
-    protected function _maybe_mtp_filters($_where = array())
105
-    {
106
-        // account for messenger or message type filters
107
-        if (
108
-            isset($_REQUEST['ee_messenger_filter_by'])
109
-            && $_REQUEST['ee_messenger_filter_by'] != 'none_selected'
110
-            && $_REQUEST['ee_messenger_filter_by'] != 'all'
111
-        ) {
112
-            $_where['MTP_messenger'] =  $_REQUEST['ee_messenger_filter_by'] ;
113
-        }
114
-
115
-        if (
116
-            isset($_REQUEST['ee_message_type_filter_by'])
117
-            && $_REQUEST['ee_message_type_filter_by'] != 'none_selected'
118
-        ) {
119
-            $_where['MTP_message_type'] = $_REQUEST['ee_message_type_filter_by'];
120
-        }
121
-
122
-        return $_where;
123
-    }
124
-
125
-
126
-
127
-    /**
128
-     * get_all_active_message_templates groups
129
-     *
130
-     * @access public
131
-     * @param string $orderby
132
-     * @param string $order
133
-     * @param null   $limit
134
-     * @param bool   $count
135
-     * @param bool   $global
136
-     * @param bool   $user_check
137
-     * @return array all active (non_trashed, active) message template objects
138
-     */
139
-    public function get_all_active_message_templates(
140
-        $orderby = 'GRP_ID',
141
-        $order = 'ASC',
142
-        $limit = null,
143
-        $count = false,
144
-        $global = true,
145
-        $user_check = false
146
-    ) {
147
-        $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false );
148
-        $_where['MTP_is_active'] = true;
149
-        $_where = $this->_maybe_mtp_filters($_where);
150
-
151
-        if (
152
-            $user_check
153
-            && ! $global
154
-            && ! EE_Registry::instance()->CAP->current_user_can(
155
-                'ee_read_others_messages',
156
-                'get_all_active_message_templates'
157
-            )
158
-        ) {
159
-            $_where['MTP_user_id'] = get_current_user_id();
160
-        }
161
-
162
-        $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
163
-
164
-        return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
165
-    }
166
-
167
-
168
-
169
-    /**
170
-     *    retrieve ALL message_template groups from db regardless of wht
171
-     *
172
-     * @access    public
173
-     * @param string $orderby
174
-     * @param string $order
175
-     * @param null   $limit
176
-     * @param bool   $count
177
-     * @return mixed array on success, FALSE on fail
178
-     */
179
-    public function get_all_message_templates($orderby = 'GRP_ID', $order = 'ASC', $limit = null, $count = false)
180
-    {
181
-        $_where = $this->_maybe_mtp_filters();
182
-
183
-        $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
184
-
185
-        $r_templates = $count
186
-            ? $this->count_deleted_and_undeleted($query_params, 'GRP_ID', true)
187
-            : $this->get_all_deleted_and_undeleted($query_params);
188
-
189
-        return $r_templates;
190
-    }
191
-
192
-
193
-
194
-
195
-    /**
196
-     * This gets all the custom templates attached to a specific event
197
-     * @param  int      $EVT_ID         event id
198
-     * @param  array  $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
199
-     * @return  EE_Message_Template_Group[]
200
-     */
201
-    public function get_all_custom_templates_by_event($EVT_ID, $query_params = array())
202
-    {
203
-        $where = array_merge($query_params, array( 'Event.EVT_ID' => $EVT_ID ));
204
-        return $this->get_all(
205
-            array( $where )
206
-        );
207
-    }
208
-
209
-
210
-
211
-    /**
212
-     * get_all_trashed_grouped_message_templates
213
-     * this returns ONLY the template groups where ALL contexts are trashed and none of the group are non-trashed
214
-     *
215
-     * @access public
216
-     * @param string $orderby
217
-     * @param string $order
218
-     * @param null   $limit
219
-     * @param bool   $count
220
-     * @param bool   $global
221
-     * @return \EE_Message_Template_Group[] message template groups.
222
-     */
223
-    public function get_all_trashed_grouped_message_templates(
224
-        $orderby = 'GRP_ID',
225
-        $order = 'ASC',
226
-        $limit = null,
227
-        $count = false,
228
-        $global = true
229
-    ) {
230
-        $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false );
231
-        $_where['MTP_is_active'] = true;
232
-        $_where = $this->_maybe_mtp_filters($_where);
233
-
234
-        $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
235
-
236
-        return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params);
237
-    }
238
-
239
-
240
-
241
-    /**
242
-     * this returns the message template group(s) for a given event, messenger, and message template
243
-     *
244
-     * @param  string             $messenger
245
-     * @param  string             $message_type
246
-     * @param                     $evt_id
247
-     * @param  string             $orderby pointless at this point but still included
248
-     * @param  string             $order
249
-     * @param  mixed (array|null) $limit   array($offset, $num)
250
-     * @param  bool               $count   true = just return count, false = objects
251
-     * @param  bool               $active  ignore "active" or not. (default only return active)
252
-     * @return \mixed[]) depending on $count.
253
-     */
254
-    public function get_event_message_templates_by_m_and_mt_and_evt(
255
-        $messenger,
256
-        $message_type,
257
-        $evt_id,
258
-        $orderby = 'GRP_ID',
259
-        $order = 'ASC',
260
-        $limit = null,
261
-        $count = false,
262
-        $active = true
263
-    ) {
264
-        $_where = array(
265
-            'MTP_messenger' => $messenger,
266
-            'MTP_message_type' => $message_type,
267
-            'Event.EVT_ID' => $evt_id,
268
-            'MTP_is_global' => true,
269
-            'MTP_is_active' => $active
270
-        );
271
-
272
-        $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
273
-
274
-        return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
275
-    }
276
-
277
-
278
-
279
-
280
-    /**
281
-     * get all GLOBAL message template groups for the given messenger and message type
282
-     *
283
-     * @param  string $messenger    slug for messenger
284
-     * @param  string $message_type slug for message type
285
-     * @param  string $orderby      what column to orderby
286
-     * @param  string $order        ASC or DESC
287
-     * @param  mixed (array|null) $limit array($offset, $num)
288
-     * @param  bool   $count        true = just return count, false = objects
289
-     * @param  bool   $active       ignore "active" or not. (default only return active) -
290
-     *                              'all' means return both inactive AND inactive.
291
-     * @return array               message template objects that are global (i.e. non-event)
292
-     */
293
-    public function get_global_message_template_by_m_and_mt(
294
-        $messenger,
295
-        $message_type,
296
-        $orderby = 'GRP_ID',
297
-        $order = 'ASC',
298
-        $limit = null,
299
-        $count = false,
300
-        $active = true
301
-    ) {
302
-        $_where = array(
303
-            'MTP_messenger' => $messenger,
304
-            'MTP_message_type' => $message_type,
305
-            'MTP_is_global' => true,
306
-        );
307
-
308
-        if ($active != 'all') {
309
-            $_where['MTP_is_active'] = $active;
310
-        }
311
-
312
-        $query_params = array( $_where, 'order_by' => array( $orderby => $order ), 'limit' => $limit );
313
-
314
-        return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
315
-    }
316
-
317
-
318
-
319
-
320
-    /**
321
-     * get all custom message template groups for the given messenger and message type
322
-     * @param  string $messenger    messenger
323
-     * @param  string $message_type messagetype
324
-     * @param  array  $query_params same as EEM_Base->get_all()
325
-     * @return EE_Message_Template_Group[]
326
-     */
327
-    public function get_custom_message_template_by_m_and_mt($messenger, $message_type, $query_params = array())
328
-    {
329
-        return $this->get_all(
330
-            array_merge(
331
-                $query_params,
332
-                array(
333
-                    array(
334
-                        'MTP_is_global'    => false,
335
-                        'MTP_messenger'    => $messenger,
336
-                        'MTP_message_type' => $message_type
337
-                    )
338
-                )
339
-            )
340
-        );
341
-    }
342
-
343
-
344
-
345
-    /**
346
-     * This sends things to the validator for the given messenger and message type.
347
-     *
348
-     * @param  array $fields the incoming fields to check.
349
-     *                       Note this array is in the formatted fields from the form fields setup.
350
-     *                       So we need to reformat this into an array of expected field refs by the validator.
351
-     *                       Note also that this is not only the fields for the Message Template Group
352
-     *                       but ALSO for Message Template.
353
-     * @param string $context      The context the fields were obtained from.
354
-     * @param string $messenger    The messenger we are validating
355
-     * @param string $message_type The message type we are validating.
356
-     * @return mixed If the fields all check out then we return true otherwise error messages are returned
357
-     *                       (indexed by field name);
358
-     * @throws \EE_Error
359
-     */
360
-    public function validate($fields, $context, $messenger, $message_type)
361
-    {
362
-
363
-        $assembled_fields = array();
364
-
365
-        // let's loop through all the fields and set them up in the right format
366
-        foreach ($fields as $index => $value) {
367
-            // first let's figure out if the value['content'] in the current index is an array.
368
-            //  If it is then this is special fields that are used in parsing special shortcodes (i.e. 'attendee_list').
369
-            if (is_array($value['content'])) {
370
-                $assembled_fields[ $value['name'] ] = $value['content']['main'];
371
-                // loop through the content and get the other fields.
372
-                foreach ($value['content'] as $name => $val) {
373
-                    if ($name == 'main') {
374
-                        continue;
375
-                    }
376
-                    $assembled_fields[ $name ] = $val;
377
-                }
378
-                continue;
379
-            }
380
-
381
-            // okay if we're here then this is just a straight field=>$value arrangement
382
-            $assembled_fields[ $value['name'] ] = $value['content'];
383
-        }
384
-
385
-        // now we've got the assembled_fields.
386
-        // We need to setup the string for the appropriate validator class and call that.
387
-        $m_ref = ucwords(str_replace('_', ' ', $messenger));
388
-        $m_ref = str_replace(' ', '_', $m_ref);
389
-        $mt_ref = ucwords(str_replace('_', ' ', $message_type));
390
-        $mt_ref = str_replace(' ', '_', $mt_ref);
391
-
392
-        $classname = 'EE_Messages_' . $m_ref . '_' . $mt_ref . '_Validator';
393
-
394
-        if (!class_exists($classname)) {
395
-            $msg[] = __('The Validator class was unable to load', 'event_espresso');
396
-            $msg[] = sprintf(
397
-                __(
398
-                    'The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class',
399
-                    'event_espresso'
400
-                ),
401
-                $classname
402
-            );
403
-            throw new EE_Error(implode('||', $msg));
404
-        }
405
-
406
-        $a = new ReflectionClass($classname);
407
-        $_VLD = $a->newInstance($assembled_fields, $context);
408
-        $result = $_VLD->validate();
409
-        return $result;
410
-    }
411
-
412
-
413
-
414
-    /**
415
-     * Updates all message template groups matching the incoming arguments to inactive status.
416
-     *
417
-     * @param array $messenger_names    The messenger slugs.
418
-     *                              If empty then all templates matching the message types are marked inactive.
419
-     *                              Otherwise only templates matching the messengers and message types.
420
-     * @param array $message_type_names     The message type slugs.
421
-     *                              If empty then all templates matching the messengers are marked inactive.
422
-     *                              Otherwise only templates matching the messengers and message types.
423
-     *
424
-     * @return int  count of updated records.
425
-     */
426
-    public function deactivate_message_template_groups_for($messenger_names = array(), $message_type_names = array())
427
-    {
428
-        $query_args = array();
429
-        if (empty($messenger_names) && empty($message_type_names)) {
430
-            return 0;
431
-        }
432
-        if (! empty($messenger_names)) {
433
-            $query_args[0]['MTP_messenger'] = array( 'IN', (array) $messenger_names );
434
-        }
435
-        if (! empty($message_type_names)) {
436
-            $query_args[0]['MTP_message_type'] = array( 'IN', (array) $message_type_names );
437
-        }
438
-        return $this->update(array( 'MTP_is_active' => false ), $query_args);
439
-    }
15
+	// private instance of the EEM_Message_Template_Group object
16
+	protected static $_instance = null;
17
+
18
+
19
+
20
+	protected function __construct($timezone = null)
21
+	{
22
+		$this->singular_item = __('Message Template Group', 'event_espresso');
23
+		$this->plural_item = __('Message Template Groups', 'event_espresso');
24
+		$this->_tables = array(
25
+			'Message_Template_Group' => new EE_Primary_Table('esp_message_template_group', 'GRP_ID')
26
+		);
27
+		$this->_fields = array(
28
+			'Message_Template_Group' => array(
29
+				'GRP_ID' => new EE_Primary_Key_Int_Field('GRP_ID', __('Message Template Group ID', 'event_espresso')),
30
+				'MTP_name' => new EE_Plain_Text_Field('MTP_name', __('The name of the template group', 'event_espresso'), false, ''),
31
+				'MTP_description' => new EE_Simple_HTML_Field('MTP_description', __('A brief description about this template.', 'event_espresso'), false, ''),
32
+				'MTP_user_id' => new EE_WP_User_Field('MTP_user_id', __('Template Creator ID', 'event_espresso'), false, get_current_user_id()),
33
+				'MTP_messenger' => new EE_Plain_Text_Field('MTP_messenger', __('Messenger Used for Template', 'event_espresso'), false, 'email'),
34
+				'MTP_message_type' => new EE_Plain_Text_Field('MTP_message_type', __('Message Type', 'event_espresso'), false, 'registration'),
35
+				'MTP_is_global' => new EE_Boolean_Field('MTP_is_global', __('Flag indicating if Template Group is Global', 'event_espresso'), false, true),
36
+				'MTP_is_override' => new EE_Boolean_Field('MTP_is_override', __('Flag indicating if Template Group overrides any other Templates for the messenger/messagetype combination', 'event_espresso'), false, false),
37
+				'MTP_deleted' => new EE_Trashed_Flag_Field('MTP_deleted', __('Flag indicating whether this has been trashed', 'event_espresso'), false, false),
38
+				'MTP_is_active' => new EE_Boolean_Field('MTP_is_active', __('Flag indicating whether template group is active', 'event_espresso'), false, true)
39
+			)
40
+		);
41
+		$this->_model_relations = array(
42
+			'Message_Template' => new EE_Has_Many_Relation(),
43
+			'Message' => new EE_Has_Many_Relation(),
44
+			'Event' => new EE_HABTM_Relation('Event_Message_Template'),
45
+			'WP_User' => new EE_Belongs_To_Relation()
46
+		);
47
+		foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
48
+			$this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('MTP_is_global');
49
+		}
50
+		$this->_caps_slug = 'messages';
51
+
52
+		parent::__construct($timezone);
53
+	}
54
+
55
+
56
+
57
+	/**
58
+	 * get_all_trashed_message_templates_by_event
59
+	 *
60
+	 * @access public
61
+	 * @param int    $EVT_ID specific event id
62
+	 * @param string $orderby
63
+	 * @param string $order
64
+	 * @param null   $limit
65
+	 * @param bool   $count
66
+	 * @return array message template objects that are attached to a specific event.
67
+	 */
68
+	public function get_all_trashed_message_templates_by_event(
69
+		$EVT_ID,
70
+		$orderby = 'GRP_ID',
71
+		$order = 'ASC',
72
+		$limit = null,
73
+		$count = false
74
+	) {
75
+		$query_params = array( array('Event.EVT_ID' => $EVT_ID), 'order_by' => array($orderby => $order), 'limit' => $limit );
76
+		return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params);
77
+	}
78
+
79
+
80
+
81
+	/**
82
+	 * get_all_message_templates_by_messenger
83
+	 *
84
+	 * @access public
85
+	 * @param        $messenger
86
+	 * @param string $orderby
87
+	 * @param string $order
88
+	 * @return array all (including trashed or inactive) message template group objects for the given messenger
89
+	 */
90
+	public function get_all_message_templates_by_messenger($messenger, $orderby = 'GRP_ID', $order = 'ASC')
91
+	{
92
+		return $this->get_all_deleted_and_undeleted(
93
+			array( array( 'MTP_messenger' => $messenger ), 'order_by' => array( $orderby => $order ) )
94
+		);
95
+	}
96
+
97
+
98
+
99
+	/**
100
+	 * This simply adds on any messenger/message type filters that may be present in the $_POST global
101
+	 * @param  array  $_where any existing where conditions to append these to.
102
+	 * @return array          original where conditions or original with additional filters.
103
+	 */
104
+	protected function _maybe_mtp_filters($_where = array())
105
+	{
106
+		// account for messenger or message type filters
107
+		if (
108
+			isset($_REQUEST['ee_messenger_filter_by'])
109
+			&& $_REQUEST['ee_messenger_filter_by'] != 'none_selected'
110
+			&& $_REQUEST['ee_messenger_filter_by'] != 'all'
111
+		) {
112
+			$_where['MTP_messenger'] =  $_REQUEST['ee_messenger_filter_by'] ;
113
+		}
114
+
115
+		if (
116
+			isset($_REQUEST['ee_message_type_filter_by'])
117
+			&& $_REQUEST['ee_message_type_filter_by'] != 'none_selected'
118
+		) {
119
+			$_where['MTP_message_type'] = $_REQUEST['ee_message_type_filter_by'];
120
+		}
121
+
122
+		return $_where;
123
+	}
124
+
125
+
126
+
127
+	/**
128
+	 * get_all_active_message_templates groups
129
+	 *
130
+	 * @access public
131
+	 * @param string $orderby
132
+	 * @param string $order
133
+	 * @param null   $limit
134
+	 * @param bool   $count
135
+	 * @param bool   $global
136
+	 * @param bool   $user_check
137
+	 * @return array all active (non_trashed, active) message template objects
138
+	 */
139
+	public function get_all_active_message_templates(
140
+		$orderby = 'GRP_ID',
141
+		$order = 'ASC',
142
+		$limit = null,
143
+		$count = false,
144
+		$global = true,
145
+		$user_check = false
146
+	) {
147
+		$_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false );
148
+		$_where['MTP_is_active'] = true;
149
+		$_where = $this->_maybe_mtp_filters($_where);
150
+
151
+		if (
152
+			$user_check
153
+			&& ! $global
154
+			&& ! EE_Registry::instance()->CAP->current_user_can(
155
+				'ee_read_others_messages',
156
+				'get_all_active_message_templates'
157
+			)
158
+		) {
159
+			$_where['MTP_user_id'] = get_current_user_id();
160
+		}
161
+
162
+		$query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
163
+
164
+		return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
165
+	}
166
+
167
+
168
+
169
+	/**
170
+	 *    retrieve ALL message_template groups from db regardless of wht
171
+	 *
172
+	 * @access    public
173
+	 * @param string $orderby
174
+	 * @param string $order
175
+	 * @param null   $limit
176
+	 * @param bool   $count
177
+	 * @return mixed array on success, FALSE on fail
178
+	 */
179
+	public function get_all_message_templates($orderby = 'GRP_ID', $order = 'ASC', $limit = null, $count = false)
180
+	{
181
+		$_where = $this->_maybe_mtp_filters();
182
+
183
+		$query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
184
+
185
+		$r_templates = $count
186
+			? $this->count_deleted_and_undeleted($query_params, 'GRP_ID', true)
187
+			: $this->get_all_deleted_and_undeleted($query_params);
188
+
189
+		return $r_templates;
190
+	}
191
+
192
+
193
+
194
+
195
+	/**
196
+	 * This gets all the custom templates attached to a specific event
197
+	 * @param  int      $EVT_ID         event id
198
+	 * @param  array  $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
199
+	 * @return  EE_Message_Template_Group[]
200
+	 */
201
+	public function get_all_custom_templates_by_event($EVT_ID, $query_params = array())
202
+	{
203
+		$where = array_merge($query_params, array( 'Event.EVT_ID' => $EVT_ID ));
204
+		return $this->get_all(
205
+			array( $where )
206
+		);
207
+	}
208
+
209
+
210
+
211
+	/**
212
+	 * get_all_trashed_grouped_message_templates
213
+	 * this returns ONLY the template groups where ALL contexts are trashed and none of the group are non-trashed
214
+	 *
215
+	 * @access public
216
+	 * @param string $orderby
217
+	 * @param string $order
218
+	 * @param null   $limit
219
+	 * @param bool   $count
220
+	 * @param bool   $global
221
+	 * @return \EE_Message_Template_Group[] message template groups.
222
+	 */
223
+	public function get_all_trashed_grouped_message_templates(
224
+		$orderby = 'GRP_ID',
225
+		$order = 'ASC',
226
+		$limit = null,
227
+		$count = false,
228
+		$global = true
229
+	) {
230
+		$_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false );
231
+		$_where['MTP_is_active'] = true;
232
+		$_where = $this->_maybe_mtp_filters($_where);
233
+
234
+		$query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
235
+
236
+		return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params);
237
+	}
238
+
239
+
240
+
241
+	/**
242
+	 * this returns the message template group(s) for a given event, messenger, and message template
243
+	 *
244
+	 * @param  string             $messenger
245
+	 * @param  string             $message_type
246
+	 * @param                     $evt_id
247
+	 * @param  string             $orderby pointless at this point but still included
248
+	 * @param  string             $order
249
+	 * @param  mixed (array|null) $limit   array($offset, $num)
250
+	 * @param  bool               $count   true = just return count, false = objects
251
+	 * @param  bool               $active  ignore "active" or not. (default only return active)
252
+	 * @return \mixed[]) depending on $count.
253
+	 */
254
+	public function get_event_message_templates_by_m_and_mt_and_evt(
255
+		$messenger,
256
+		$message_type,
257
+		$evt_id,
258
+		$orderby = 'GRP_ID',
259
+		$order = 'ASC',
260
+		$limit = null,
261
+		$count = false,
262
+		$active = true
263
+	) {
264
+		$_where = array(
265
+			'MTP_messenger' => $messenger,
266
+			'MTP_message_type' => $message_type,
267
+			'Event.EVT_ID' => $evt_id,
268
+			'MTP_is_global' => true,
269
+			'MTP_is_active' => $active
270
+		);
271
+
272
+		$query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
273
+
274
+		return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
275
+	}
276
+
277
+
278
+
279
+
280
+	/**
281
+	 * get all GLOBAL message template groups for the given messenger and message type
282
+	 *
283
+	 * @param  string $messenger    slug for messenger
284
+	 * @param  string $message_type slug for message type
285
+	 * @param  string $orderby      what column to orderby
286
+	 * @param  string $order        ASC or DESC
287
+	 * @param  mixed (array|null) $limit array($offset, $num)
288
+	 * @param  bool   $count        true = just return count, false = objects
289
+	 * @param  bool   $active       ignore "active" or not. (default only return active) -
290
+	 *                              'all' means return both inactive AND inactive.
291
+	 * @return array               message template objects that are global (i.e. non-event)
292
+	 */
293
+	public function get_global_message_template_by_m_and_mt(
294
+		$messenger,
295
+		$message_type,
296
+		$orderby = 'GRP_ID',
297
+		$order = 'ASC',
298
+		$limit = null,
299
+		$count = false,
300
+		$active = true
301
+	) {
302
+		$_where = array(
303
+			'MTP_messenger' => $messenger,
304
+			'MTP_message_type' => $message_type,
305
+			'MTP_is_global' => true,
306
+		);
307
+
308
+		if ($active != 'all') {
309
+			$_where['MTP_is_active'] = $active;
310
+		}
311
+
312
+		$query_params = array( $_where, 'order_by' => array( $orderby => $order ), 'limit' => $limit );
313
+
314
+		return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
315
+	}
316
+
317
+
318
+
319
+
320
+	/**
321
+	 * get all custom message template groups for the given messenger and message type
322
+	 * @param  string $messenger    messenger
323
+	 * @param  string $message_type messagetype
324
+	 * @param  array  $query_params same as EEM_Base->get_all()
325
+	 * @return EE_Message_Template_Group[]
326
+	 */
327
+	public function get_custom_message_template_by_m_and_mt($messenger, $message_type, $query_params = array())
328
+	{
329
+		return $this->get_all(
330
+			array_merge(
331
+				$query_params,
332
+				array(
333
+					array(
334
+						'MTP_is_global'    => false,
335
+						'MTP_messenger'    => $messenger,
336
+						'MTP_message_type' => $message_type
337
+					)
338
+				)
339
+			)
340
+		);
341
+	}
342
+
343
+
344
+
345
+	/**
346
+	 * This sends things to the validator for the given messenger and message type.
347
+	 *
348
+	 * @param  array $fields the incoming fields to check.
349
+	 *                       Note this array is in the formatted fields from the form fields setup.
350
+	 *                       So we need to reformat this into an array of expected field refs by the validator.
351
+	 *                       Note also that this is not only the fields for the Message Template Group
352
+	 *                       but ALSO for Message Template.
353
+	 * @param string $context      The context the fields were obtained from.
354
+	 * @param string $messenger    The messenger we are validating
355
+	 * @param string $message_type The message type we are validating.
356
+	 * @return mixed If the fields all check out then we return true otherwise error messages are returned
357
+	 *                       (indexed by field name);
358
+	 * @throws \EE_Error
359
+	 */
360
+	public function validate($fields, $context, $messenger, $message_type)
361
+	{
362
+
363
+		$assembled_fields = array();
364
+
365
+		// let's loop through all the fields and set them up in the right format
366
+		foreach ($fields as $index => $value) {
367
+			// first let's figure out if the value['content'] in the current index is an array.
368
+			//  If it is then this is special fields that are used in parsing special shortcodes (i.e. 'attendee_list').
369
+			if (is_array($value['content'])) {
370
+				$assembled_fields[ $value['name'] ] = $value['content']['main'];
371
+				// loop through the content and get the other fields.
372
+				foreach ($value['content'] as $name => $val) {
373
+					if ($name == 'main') {
374
+						continue;
375
+					}
376
+					$assembled_fields[ $name ] = $val;
377
+				}
378
+				continue;
379
+			}
380
+
381
+			// okay if we're here then this is just a straight field=>$value arrangement
382
+			$assembled_fields[ $value['name'] ] = $value['content'];
383
+		}
384
+
385
+		// now we've got the assembled_fields.
386
+		// We need to setup the string for the appropriate validator class and call that.
387
+		$m_ref = ucwords(str_replace('_', ' ', $messenger));
388
+		$m_ref = str_replace(' ', '_', $m_ref);
389
+		$mt_ref = ucwords(str_replace('_', ' ', $message_type));
390
+		$mt_ref = str_replace(' ', '_', $mt_ref);
391
+
392
+		$classname = 'EE_Messages_' . $m_ref . '_' . $mt_ref . '_Validator';
393
+
394
+		if (!class_exists($classname)) {
395
+			$msg[] = __('The Validator class was unable to load', 'event_espresso');
396
+			$msg[] = sprintf(
397
+				__(
398
+					'The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class',
399
+					'event_espresso'
400
+				),
401
+				$classname
402
+			);
403
+			throw new EE_Error(implode('||', $msg));
404
+		}
405
+
406
+		$a = new ReflectionClass($classname);
407
+		$_VLD = $a->newInstance($assembled_fields, $context);
408
+		$result = $_VLD->validate();
409
+		return $result;
410
+	}
411
+
412
+
413
+
414
+	/**
415
+	 * Updates all message template groups matching the incoming arguments to inactive status.
416
+	 *
417
+	 * @param array $messenger_names    The messenger slugs.
418
+	 *                              If empty then all templates matching the message types are marked inactive.
419
+	 *                              Otherwise only templates matching the messengers and message types.
420
+	 * @param array $message_type_names     The message type slugs.
421
+	 *                              If empty then all templates matching the messengers are marked inactive.
422
+	 *                              Otherwise only templates matching the messengers and message types.
423
+	 *
424
+	 * @return int  count of updated records.
425
+	 */
426
+	public function deactivate_message_template_groups_for($messenger_names = array(), $message_type_names = array())
427
+	{
428
+		$query_args = array();
429
+		if (empty($messenger_names) && empty($message_type_names)) {
430
+			return 0;
431
+		}
432
+		if (! empty($messenger_names)) {
433
+			$query_args[0]['MTP_messenger'] = array( 'IN', (array) $messenger_names );
434
+		}
435
+		if (! empty($message_type_names)) {
436
+			$query_args[0]['MTP_message_type'] = array( 'IN', (array) $message_type_names );
437
+		}
438
+		return $this->update(array( 'MTP_is_active' => false ), $query_args);
439
+	}
440 440
 }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
             'WP_User' => new EE_Belongs_To_Relation()
46 46
         );
47 47
         foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
48
-            $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('MTP_is_global');
48
+            $this->_cap_restriction_generators[$context] = new EE_Restriction_Generator_Global('MTP_is_global');
49 49
         }
50 50
         $this->_caps_slug = 'messages';
51 51
 
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
         $limit = null,
73 73
         $count = false
74 74
     ) {
75
-        $query_params = array( array('Event.EVT_ID' => $EVT_ID), 'order_by' => array($orderby => $order), 'limit' => $limit );
75
+        $query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array($orderby => $order), 'limit' => $limit);
76 76
         return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params);
77 77
     }
78 78
 
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
     public function get_all_message_templates_by_messenger($messenger, $orderby = 'GRP_ID', $order = 'ASC')
91 91
     {
92 92
         return $this->get_all_deleted_and_undeleted(
93
-            array( array( 'MTP_messenger' => $messenger ), 'order_by' => array( $orderby => $order ) )
93
+            array(array('MTP_messenger' => $messenger), 'order_by' => array($orderby => $order))
94 94
         );
95 95
     }
96 96
 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
             && $_REQUEST['ee_messenger_filter_by'] != 'none_selected'
110 110
             && $_REQUEST['ee_messenger_filter_by'] != 'all'
111 111
         ) {
112
-            $_where['MTP_messenger'] =  $_REQUEST['ee_messenger_filter_by'] ;
112
+            $_where['MTP_messenger'] = $_REQUEST['ee_messenger_filter_by'];
113 113
         }
114 114
 
115 115
         if (
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
         $global = true,
145 145
         $user_check = false
146 146
     ) {
147
-        $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false );
147
+        $_where = $global ? array('MTP_is_global' => true) : array('MTP_is_global' => false);
148 148
         $_where['MTP_is_active'] = true;
149 149
         $_where = $this->_maybe_mtp_filters($_where);
150 150
 
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
             $_where['MTP_user_id'] = get_current_user_id();
160 160
         }
161 161
 
162
-        $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
162
+        $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit);
163 163
 
164 164
         return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
165 165
     }
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
     {
181 181
         $_where = $this->_maybe_mtp_filters();
182 182
 
183
-        $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
183
+        $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit);
184 184
 
185 185
         $r_templates = $count
186 186
             ? $this->count_deleted_and_undeleted($query_params, 'GRP_ID', true)
@@ -200,9 +200,9 @@  discard block
 block discarded – undo
200 200
      */
201 201
     public function get_all_custom_templates_by_event($EVT_ID, $query_params = array())
202 202
     {
203
-        $where = array_merge($query_params, array( 'Event.EVT_ID' => $EVT_ID ));
203
+        $where = array_merge($query_params, array('Event.EVT_ID' => $EVT_ID));
204 204
         return $this->get_all(
205
-            array( $where )
205
+            array($where)
206 206
         );
207 207
     }
208 208
 
@@ -227,11 +227,11 @@  discard block
 block discarded – undo
227 227
         $count = false,
228 228
         $global = true
229 229
     ) {
230
-        $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false );
230
+        $_where = $global ? array('MTP_is_global' => true) : array('MTP_is_global' => false);
231 231
         $_where['MTP_is_active'] = true;
232 232
         $_where = $this->_maybe_mtp_filters($_where);
233 233
 
234
-        $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
234
+        $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit);
235 235
 
236 236
         return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params);
237 237
     }
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
             'MTP_is_active' => $active
270 270
         );
271 271
 
272
-        $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
272
+        $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit);
273 273
 
274 274
         return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
275 275
     }
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
             $_where['MTP_is_active'] = $active;
310 310
         }
311 311
 
312
-        $query_params = array( $_where, 'order_by' => array( $orderby => $order ), 'limit' => $limit );
312
+        $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit);
313 313
 
314 314
         return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
315 315
     }
@@ -367,19 +367,19 @@  discard block
 block discarded – undo
367 367
             // first let's figure out if the value['content'] in the current index is an array.
368 368
             //  If it is then this is special fields that are used in parsing special shortcodes (i.e. 'attendee_list').
369 369
             if (is_array($value['content'])) {
370
-                $assembled_fields[ $value['name'] ] = $value['content']['main'];
370
+                $assembled_fields[$value['name']] = $value['content']['main'];
371 371
                 // loop through the content and get the other fields.
372 372
                 foreach ($value['content'] as $name => $val) {
373 373
                     if ($name == 'main') {
374 374
                         continue;
375 375
                     }
376
-                    $assembled_fields[ $name ] = $val;
376
+                    $assembled_fields[$name] = $val;
377 377
                 }
378 378
                 continue;
379 379
             }
380 380
 
381 381
             // okay if we're here then this is just a straight field=>$value arrangement
382
-            $assembled_fields[ $value['name'] ] = $value['content'];
382
+            $assembled_fields[$value['name']] = $value['content'];
383 383
         }
384 384
 
385 385
         // now we've got the assembled_fields.
@@ -389,9 +389,9 @@  discard block
 block discarded – undo
389 389
         $mt_ref = ucwords(str_replace('_', ' ', $message_type));
390 390
         $mt_ref = str_replace(' ', '_', $mt_ref);
391 391
 
392
-        $classname = 'EE_Messages_' . $m_ref . '_' . $mt_ref . '_Validator';
392
+        $classname = 'EE_Messages_'.$m_ref.'_'.$mt_ref.'_Validator';
393 393
 
394
-        if (!class_exists($classname)) {
394
+        if ( ! class_exists($classname)) {
395 395
             $msg[] = __('The Validator class was unable to load', 'event_espresso');
396 396
             $msg[] = sprintf(
397 397
                 __(
@@ -429,12 +429,12 @@  discard block
 block discarded – undo
429 429
         if (empty($messenger_names) && empty($message_type_names)) {
430 430
             return 0;
431 431
         }
432
-        if (! empty($messenger_names)) {
433
-            $query_args[0]['MTP_messenger'] = array( 'IN', (array) $messenger_names );
432
+        if ( ! empty($messenger_names)) {
433
+            $query_args[0]['MTP_messenger'] = array('IN', (array) $messenger_names);
434 434
         }
435
-        if (! empty($message_type_names)) {
436
-            $query_args[0]['MTP_message_type'] = array( 'IN', (array) $message_type_names );
435
+        if ( ! empty($message_type_names)) {
436
+            $query_args[0]['MTP_message_type'] = array('IN', (array) $message_type_names);
437 437
         }
438
-        return $this->update(array( 'MTP_is_active' => false ), $query_args);
438
+        return $this->update(array('MTP_is_active' => false), $query_args);
439 439
     }
440 440
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Price_Type.model.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
     /**
28 28
      * return an array of Base types. Keys are INTs which are used in the database,
29 29
      * values are text-representations of the base type.
30
-     * @return array
30
+     * @return integer
31 31
      */
32 32
     public function get_base_types()
33 33
     {
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
      *      instantiate a new price type object with blank/empty properties
108 108
      *
109 109
      *      @access     public
110
-     *      @return     mixed       array on success, FALSE on fail
110
+     *      @return     EE_Price_Type       array on success, FALSE on fail
111 111
      */
112 112
     public function get_new_price_type()
113 113
     {
Please login to merge, or discard this patch.
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -12,108 +12,108 @@  discard block
 block discarded – undo
12 12
 class EEM_Price_Type extends EEM_Soft_Delete_Base
13 13
 {
14 14
 
15
-    // private instance of the Price Type object
16
-    protected static $_instance = null;
17
-    // An array of the price type objects
18
-    public $type = null;
19
-
20
-    /**
21
-    *   Price Base types
22
-    *
23
-    *   @access private
24
-    *   @var int
25
-    */
26
-    public $base_types = null;
27
-
28
-    /**
29
-     * return an array of Base types. Keys are INTs which are used in the database,
30
-     * values are text-representations of the base type.
31
-     * @return array
32
-     */
33
-    public function get_base_types()
34
-    {
35
-        return $this->base_types;
36
-    }
37
-
38
-    /**
39
-     * Gets the name of the base
40
-     * @param type $base_type_int
41
-     * @return type
42
-     */
43
-    public function get_base_type_name($base_type_int)
44
-    {
45
-        return $this->base_types[ $base_type_int ];
46
-    }
47
-
48
-    /**
49
-     * constants for price base types. In the DB, we decided to store the price base type
50
-     * as an integer. So, to avoid just having magic numbers everwhere (eg, querying for
51
-     * all price types with PBT_ID = 2), we define these constants, to make code more understandable.
52
-     * So, as an example, to query for all price types that are a tax, we'd do
53
-     * EEM_PRice_Type::instance()->get_all(array(array('PBT_ID'=>EEM_Price_Type::base_type_tax)))
54
-     * instead of
55
-     * EEM_Price_Type::instance()->get_all(array(array('PBT_ID'=>2)))
56
-     * Although the 2nd is shorter, it's much less obvious what it's doing. Also, should these magic IDs ever
57
-     * change, we can continue to use the constant, by simply change its value.
58
-     */
59
-    const base_type_base_price = 1;
60
-    const base_type_discount = 2;
61
-    const base_type_surcharge = 3;
62
-    const base_type_tax = 4;
63
-    /**
64
-     *      private constructor to prevent direct creation
65
-     *      @Constructor
66
-     *      @access protected
67
-     *      @return void
68
-     */
69
-    protected function __construct($timezone = null)
70
-    {
71
-        $this->base_types = array(
72
-            EEM_Price_Type::base_type_base_price => __('Price', 'event_espresso'),
73
-            EEM_Price_Type::base_type_discount => __('Discount', 'event_espresso'),
74
-            EEM_Price_Type::base_type_surcharge => __('Surcharge', 'event_espresso'),
75
-            EEM_Price_Type::base_type_tax => __('Tax', 'event_espresso') );
76
-        $this->singular_item = __('Price Type', 'event_espresso');
77
-        $this->plural_item = __('Price Types', 'event_espresso');
78
-
79
-        $this->_tables = array(
80
-            'Price_Type' => new EE_Primary_Table('esp_price_type', 'PRT_ID')
81
-        );
82
-        $this->_fields = array(
83
-            'Price_Type' => array(
84
-                'PRT_ID' => new EE_Primary_Key_Int_Field('PRT_ID', __('Price Type ID', 'event_espresso')),
85
-                'PRT_name' => new EE_Plain_Text_Field('PRT_name', __('Price Type Name', 'event_espresso'), false, ''),
86
-                'PBT_ID' => new EE_Enum_Integer_Field('PBT_ID', __('Price Base type ID, 1 = Price , 2 = Discount , 3 = Surcharge , 4 = Tax', 'event_espresso'), false, EEM_Price_Type::base_type_base_price, $this->base_types),
87
-                'PRT_is_percent' => new EE_Boolean_Field('PRT_is_percent', __('Flag indicating price is a percentage', 'event_espresso'), false, false),
88
-                'PRT_order' => new EE_Integer_Field('PRT_order', __('Order in which price should be applied. ', 'event_espresso'), false, 0),
89
-                'PRT_deleted' => new EE_Trashed_Flag_Field('PRT_deleted', __('Flag indicating price type has been trashed', 'event_espresso'), false, false),
90
-                'PRT_wp_user' => new EE_WP_User_Field('PRT_wp_user', __('Price Type Creator ID', 'event_espresso'), false),
91
-            )
92
-        );
93
-        $this->_model_relations = array(
94
-            'Price' => new EE_Has_Many_Relation(),
95
-            'WP_User' => new EE_Belongs_To_Relation(),
96
-        );
97
-        // this model is generally available for reading
98
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
99
-        // all price types are "default" in terms of capability names
100
-        $this->_caps_slug = 'default_price_types';
101
-        parent::__construct($timezone);
102
-    }
103
-
104
-
105
-
106
-
107
-    /**
108
-     *      instantiate a new price type object with blank/empty properties
109
-     *
110
-     *      @access     public
111
-     *      @return     mixed       array on success, FALSE on fail
112
-     */
113
-    public function get_new_price_type()
114
-    {
115
-        return EE_Price_Type::new_instance();
116
-    }
15
+	// private instance of the Price Type object
16
+	protected static $_instance = null;
17
+	// An array of the price type objects
18
+	public $type = null;
19
+
20
+	/**
21
+	 *   Price Base types
22
+	 *
23
+	 *   @access private
24
+	 *   @var int
25
+	 */
26
+	public $base_types = null;
27
+
28
+	/**
29
+	 * return an array of Base types. Keys are INTs which are used in the database,
30
+	 * values are text-representations of the base type.
31
+	 * @return array
32
+	 */
33
+	public function get_base_types()
34
+	{
35
+		return $this->base_types;
36
+	}
37
+
38
+	/**
39
+	 * Gets the name of the base
40
+	 * @param type $base_type_int
41
+	 * @return type
42
+	 */
43
+	public function get_base_type_name($base_type_int)
44
+	{
45
+		return $this->base_types[ $base_type_int ];
46
+	}
47
+
48
+	/**
49
+	 * constants for price base types. In the DB, we decided to store the price base type
50
+	 * as an integer. So, to avoid just having magic numbers everwhere (eg, querying for
51
+	 * all price types with PBT_ID = 2), we define these constants, to make code more understandable.
52
+	 * So, as an example, to query for all price types that are a tax, we'd do
53
+	 * EEM_PRice_Type::instance()->get_all(array(array('PBT_ID'=>EEM_Price_Type::base_type_tax)))
54
+	 * instead of
55
+	 * EEM_Price_Type::instance()->get_all(array(array('PBT_ID'=>2)))
56
+	 * Although the 2nd is shorter, it's much less obvious what it's doing. Also, should these magic IDs ever
57
+	 * change, we can continue to use the constant, by simply change its value.
58
+	 */
59
+	const base_type_base_price = 1;
60
+	const base_type_discount = 2;
61
+	const base_type_surcharge = 3;
62
+	const base_type_tax = 4;
63
+	/**
64
+	 *      private constructor to prevent direct creation
65
+	 *      @Constructor
66
+	 *      @access protected
67
+	 *      @return void
68
+	 */
69
+	protected function __construct($timezone = null)
70
+	{
71
+		$this->base_types = array(
72
+			EEM_Price_Type::base_type_base_price => __('Price', 'event_espresso'),
73
+			EEM_Price_Type::base_type_discount => __('Discount', 'event_espresso'),
74
+			EEM_Price_Type::base_type_surcharge => __('Surcharge', 'event_espresso'),
75
+			EEM_Price_Type::base_type_tax => __('Tax', 'event_espresso') );
76
+		$this->singular_item = __('Price Type', 'event_espresso');
77
+		$this->plural_item = __('Price Types', 'event_espresso');
78
+
79
+		$this->_tables = array(
80
+			'Price_Type' => new EE_Primary_Table('esp_price_type', 'PRT_ID')
81
+		);
82
+		$this->_fields = array(
83
+			'Price_Type' => array(
84
+				'PRT_ID' => new EE_Primary_Key_Int_Field('PRT_ID', __('Price Type ID', 'event_espresso')),
85
+				'PRT_name' => new EE_Plain_Text_Field('PRT_name', __('Price Type Name', 'event_espresso'), false, ''),
86
+				'PBT_ID' => new EE_Enum_Integer_Field('PBT_ID', __('Price Base type ID, 1 = Price , 2 = Discount , 3 = Surcharge , 4 = Tax', 'event_espresso'), false, EEM_Price_Type::base_type_base_price, $this->base_types),
87
+				'PRT_is_percent' => new EE_Boolean_Field('PRT_is_percent', __('Flag indicating price is a percentage', 'event_espresso'), false, false),
88
+				'PRT_order' => new EE_Integer_Field('PRT_order', __('Order in which price should be applied. ', 'event_espresso'), false, 0),
89
+				'PRT_deleted' => new EE_Trashed_Flag_Field('PRT_deleted', __('Flag indicating price type has been trashed', 'event_espresso'), false, false),
90
+				'PRT_wp_user' => new EE_WP_User_Field('PRT_wp_user', __('Price Type Creator ID', 'event_espresso'), false),
91
+			)
92
+		);
93
+		$this->_model_relations = array(
94
+			'Price' => new EE_Has_Many_Relation(),
95
+			'WP_User' => new EE_Belongs_To_Relation(),
96
+		);
97
+		// this model is generally available for reading
98
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
99
+		// all price types are "default" in terms of capability names
100
+		$this->_caps_slug = 'default_price_types';
101
+		parent::__construct($timezone);
102
+	}
103
+
104
+
105
+
106
+
107
+	/**
108
+	 *      instantiate a new price type object with blank/empty properties
109
+	 *
110
+	 *      @access     public
111
+	 *      @return     mixed       array on success, FALSE on fail
112
+	 */
113
+	public function get_new_price_type()
114
+	{
115
+		return EE_Price_Type::new_instance();
116
+	}
117 117
 
118 118
 
119 119
 
@@ -132,33 +132,33 @@  discard block
 block discarded – undo
132 132
  *
133 133
  * @param type $query_params
134 134
  * @param boolean $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info
135
-     * that blocks it (ie, there' sno other data that depends on this data); if false, deletes regardless of other objects
136
-     * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB
135
+ * that blocks it (ie, there' sno other data that depends on this data); if false, deletes regardless of other objects
136
+ * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB
137 137
  * @return boolean
138 138
  */
139
-    public function delete_permanently($query_params = array(), $allow_blocking = true)
140
-    {
139
+	public function delete_permanently($query_params = array(), $allow_blocking = true)
140
+	{
141 141
 
142
-        $would_be_deleted_price_types = $this->get_all_deleted_and_undeleted($query_params);
143
-        $would_be_deleted_price_type_ids = array_keys($would_be_deleted_price_types);
142
+		$would_be_deleted_price_types = $this->get_all_deleted_and_undeleted($query_params);
143
+		$would_be_deleted_price_type_ids = array_keys($would_be_deleted_price_types);
144 144
 
145
-        $ID = $query_params[0][ $this->get_primary_key_field()->get_name() ];
145
+		$ID = $query_params[0][ $this->get_primary_key_field()->get_name() ];
146 146
 
147
-        // check if any prices use this price type
148
-        $prc_query_params = array(array('PRT_ID' => array('IN',$would_be_deleted_price_type_ids)));
149
-        if ($prices = $this->get_all_related($ID, 'Price', $prc_query_params)) {
150
-            $prices_names_and_ids = array();
151
-            foreach ($prices as $price) {
152
-                /* @var $price EE_Price */
153
-                $prices_names_and_ids[] = $price->name() . "(" . $price->ID() . ")";
154
-            }
155
-            $msg = sprintf(__('The Price Type(s) could not be deleted because there are existing Prices that currently use this Price Type.  If you still wish to delete this Price Type, then either delete those Prices or change them to use other Price Types.The prices are: %s', 'event_espresso'), implode(",", $prices_names_and_ids));
156
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
157
-            return false;
158
-        }
147
+		// check if any prices use this price type
148
+		$prc_query_params = array(array('PRT_ID' => array('IN',$would_be_deleted_price_type_ids)));
149
+		if ($prices = $this->get_all_related($ID, 'Price', $prc_query_params)) {
150
+			$prices_names_and_ids = array();
151
+			foreach ($prices as $price) {
152
+				/* @var $price EE_Price */
153
+				$prices_names_and_ids[] = $price->name() . "(" . $price->ID() . ")";
154
+			}
155
+			$msg = sprintf(__('The Price Type(s) could not be deleted because there are existing Prices that currently use this Price Type.  If you still wish to delete this Price Type, then either delete those Prices or change them to use other Price Types.The prices are: %s', 'event_espresso'), implode(",", $prices_names_and_ids));
156
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
157
+			return false;
158
+		}
159 159
 
160 160
 
161 161
 
162
-        return parent::delete_permanently($query_params);
163
-    }
162
+		return parent::delete_permanently($query_params);
163
+	}
164 164
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
      */
43 43
     public function get_base_type_name($base_type_int)
44 44
     {
45
-        return $this->base_types[ $base_type_int ];
45
+        return $this->base_types[$base_type_int];
46 46
     }
47 47
 
48 48
     /**
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
             'WP_User' => new EE_Belongs_To_Relation(),
96 96
         );
97 97
         // this model is generally available for reading
98
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
98
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
99 99
         // all price types are "default" in terms of capability names
100 100
         $this->_caps_slug = 'default_price_types';
101 101
         parent::__construct($timezone);
@@ -142,15 +142,15 @@  discard block
 block discarded – undo
142 142
         $would_be_deleted_price_types = $this->get_all_deleted_and_undeleted($query_params);
143 143
         $would_be_deleted_price_type_ids = array_keys($would_be_deleted_price_types);
144 144
 
145
-        $ID = $query_params[0][ $this->get_primary_key_field()->get_name() ];
145
+        $ID = $query_params[0][$this->get_primary_key_field()->get_name()];
146 146
 
147 147
         // check if any prices use this price type
148
-        $prc_query_params = array(array('PRT_ID' => array('IN',$would_be_deleted_price_type_ids)));
148
+        $prc_query_params = array(array('PRT_ID' => array('IN', $would_be_deleted_price_type_ids)));
149 149
         if ($prices = $this->get_all_related($ID, 'Price', $prc_query_params)) {
150 150
             $prices_names_and_ids = array();
151 151
             foreach ($prices as $price) {
152 152
                 /* @var $price EE_Price */
153
-                $prices_names_and_ids[] = $price->name() . "(" . $price->ID() . ")";
153
+                $prices_names_and_ids[] = $price->name()."(".$price->ID().")";
154 154
             }
155 155
             $msg = sprintf(__('The Price Type(s) could not be deleted because there are existing Prices that currently use this Price Type.  If you still wish to delete this Price Type, then either delete those Prices or change them to use other Price Types.The prices are: %s', 'event_espresso'), implode(",", $prices_names_and_ids));
156 156
             EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
Please login to merge, or discard this patch.
core/db_models/EEM_System_Status.model.php 3 patches
Doc Comments   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -15,8 +15,6 @@  discard block
 block discarded – undo
15 15
      *      This function is a singleton method used to instantiate the EEM_Attendee object
16 16
      *
17 17
      *      @access public
18
-     *      @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
19
-     *      @return EEM_System_Status
20 18
      */
21 19
     public static function instance()
22 20
     {
@@ -157,7 +155,7 @@  discard block
 block discarded – undo
157 155
 
158 156
     /**
159 157
      *
160
-     * @return array like EE_Config class
158
+     * @return EE_Config like EE_Config class
161 159
      */
162 160
     public function get_ee_config()
163 161
     {
@@ -214,7 +212,7 @@  discard block
 block discarded – undo
214 212
 
215 213
     /**
216 214
      * Checks if site responds ot HTTPS
217
-     * @return boolean
215
+     * @return string
218 216
      */
219 217
     public function get_https_enabled()
220 218
     {
Please login to merge, or discard this patch.
Indentation   +273 added lines, -273 removed lines patch added patch discarded remove patch
@@ -6,79 +6,79 @@  discard block
 block discarded – undo
6 6
 class EEM_System_Status
7 7
 {
8 8
 
9
-    // private instance of the EEM_System_Status object
10
-    protected static $_instance = null;
9
+	// private instance of the EEM_System_Status object
10
+	protected static $_instance = null;
11 11
 
12 12
 
13 13
 
14
-    /**
15
-     *      This function is a singleton method used to instantiate the EEM_Attendee object
16
-     *
17
-     *      @access public
18
-     *      @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
19
-     *      @return EEM_System_Status
20
-     */
21
-    public static function instance()
22
-    {
14
+	/**
15
+	 *      This function is a singleton method used to instantiate the EEM_Attendee object
16
+	 *
17
+	 *      @access public
18
+	 *      @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
19
+	 *      @return EEM_System_Status
20
+	 */
21
+	public static function instance()
22
+	{
23 23
 
24
-        // check if instance of EEM_System_Status already exists
25
-        if (self::$_instance === null) {
26
-            // instantiate EEM_System_Status
27
-            self::$_instance = new self();
28
-        }
29
-        return self::$_instance;
30
-    }
31
-    private function __construct()
32
-    {
33
-    }
34
-    /**
35
-     *
36
-     * @return array where each key is a function name on this class, and each value is SOMETHING--
37
-     * it might be a value, an array, or an object
38
-     */
39
-    public function get_system_stati()
40
-    {
41
-        return apply_filters(
42
-            'FHEE__EEM_System_Status__get_system_stati',
43
-            array(
44
-                'ee_version' => $this->get_ee_version(),
45
-                'ee_activation_history' => $this->get_ee_activation_history(),
46
-                'ee_config' => $this->get_ee_config(),
47
-                'ee_migration_history' => $this->get_ee_migration_history(),
48
-                'active_plugins' => $this->get_active_plugins(),
49
-                'wp_settings' => $this->get_wp_settings(),
50
-                'wp_maintenance_mode' => $this->get_wp_maintenance_mode(),
51
-                'https_enabled' => $this->get_https_enabled(),
52
-                'logging_enabled' => $this->get_logging_enabled(),
53
-                'remote_posting' => $this->get_remote_posting(),
54
-                'php_version' => $this->php_version(),
55
-                'php.ini_settings' => $this->get_php_ini_all(),
56
-                'php_info' => $this->get_php_info(),
57
-            ),
58
-            $this
59
-        );
60
-    }
61
-    /**
62
-     *
63
-     * @return string
64
-     */
65
-    public function get_ee_version()
66
-    {
67
-        return espresso_version();
68
-    }
69
-    /**
70
-     *
71
-     * @return string
72
-     */
73
-    public function php_version()
74
-    {
75
-        return phpversion();
76
-    }
77
-    /**
78
-     *
79
-     * @return array, where each key is a plugin name (lower-cased), values are sub-arrays.
80
-     * Sub-arrays like described in wp function get_plugin_data. Ie,     *
81
-     *  'Name' => 'Plugin Name',
24
+		// check if instance of EEM_System_Status already exists
25
+		if (self::$_instance === null) {
26
+			// instantiate EEM_System_Status
27
+			self::$_instance = new self();
28
+		}
29
+		return self::$_instance;
30
+	}
31
+	private function __construct()
32
+	{
33
+	}
34
+	/**
35
+	 *
36
+	 * @return array where each key is a function name on this class, and each value is SOMETHING--
37
+	 * it might be a value, an array, or an object
38
+	 */
39
+	public function get_system_stati()
40
+	{
41
+		return apply_filters(
42
+			'FHEE__EEM_System_Status__get_system_stati',
43
+			array(
44
+				'ee_version' => $this->get_ee_version(),
45
+				'ee_activation_history' => $this->get_ee_activation_history(),
46
+				'ee_config' => $this->get_ee_config(),
47
+				'ee_migration_history' => $this->get_ee_migration_history(),
48
+				'active_plugins' => $this->get_active_plugins(),
49
+				'wp_settings' => $this->get_wp_settings(),
50
+				'wp_maintenance_mode' => $this->get_wp_maintenance_mode(),
51
+				'https_enabled' => $this->get_https_enabled(),
52
+				'logging_enabled' => $this->get_logging_enabled(),
53
+				'remote_posting' => $this->get_remote_posting(),
54
+				'php_version' => $this->php_version(),
55
+				'php.ini_settings' => $this->get_php_ini_all(),
56
+				'php_info' => $this->get_php_info(),
57
+			),
58
+			$this
59
+		);
60
+	}
61
+	/**
62
+	 *
63
+	 * @return string
64
+	 */
65
+	public function get_ee_version()
66
+	{
67
+		return espresso_version();
68
+	}
69
+	/**
70
+	 *
71
+	 * @return string
72
+	 */
73
+	public function php_version()
74
+	{
75
+		return phpversion();
76
+	}
77
+	/**
78
+	 *
79
+	 * @return array, where each key is a plugin name (lower-cased), values are sub-arrays.
80
+	 * Sub-arrays like described in wp function get_plugin_data. Ie,     *
81
+	 *  'Name' => 'Plugin Name',
82 82
         'PluginURI' => 'Plugin URI',
83 83
         'Version' => 'Version',
84 84
         'Description' => 'Description',
@@ -87,221 +87,221 @@  discard block
 block discarded – undo
87 87
         'TextDomain' => 'Text Domain',
88 88
         'DomainPath' => 'Domain Path',
89 89
         'Network' => 'Network',
90
-     */
91
-    public function get_active_plugins()
92
-    {
93
-        $active_plugins = (array) get_option('active_plugins', array());
94
-        if (is_multisite()) {
95
-            $active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', array()));
96
-        }
97
-        $active_plugins = array_map('strtolower', $active_plugins);
98
-        $plugin_info = array();
99
-        foreach ($active_plugins as $plugin) {
100
-                $plugin_data = @get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin);
90
+	 */
91
+	public function get_active_plugins()
92
+	{
93
+		$active_plugins = (array) get_option('active_plugins', array());
94
+		if (is_multisite()) {
95
+			$active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', array()));
96
+		}
97
+		$active_plugins = array_map('strtolower', $active_plugins);
98
+		$plugin_info = array();
99
+		foreach ($active_plugins as $plugin) {
100
+				$plugin_data = @get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin);
101 101
 
102
-                $plugin_info[ $plugin ] = $plugin_data;
103
-        }
104
-        return $plugin_info;
105
-    }
102
+				$plugin_info[ $plugin ] = $plugin_data;
103
+		}
104
+		return $plugin_info;
105
+	}
106 106
 
107
-    /**
108
-     *
109
-     * @return array with keys 'home_url' and 'site_url'
110
-     */
111
-    public function get_wp_settings()
112
-    {
113
-        $wp_memory_int = $this->let_to_num(WP_MEMORY_LIMIT);
114
-        if ($wp_memory_int < 67108864) {
115
-            $wp_memory_to_display = '<mark class="error">' . sprintf(__('%s - We recommend setting memory to at least 64MB. See: %s Increasing memory allocated to PHP %s', 'event_espresso'), WP_MEMORY_LIMIT, '<a href="http://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP">', '</a>"') . '</mark>';
116
-        } else {
117
-            $wp_memory_to_display = '<mark class="yes">' . size_format($wp_memory_int) . '</mark>';
118
-        }
119
-        return array(
120
-            'name' => get_bloginfo('name', 'display'),
121
-            'is_multisite' => is_multisite(),
122
-            'version' =>  get_bloginfo('version', 'display'),
123
-            'home_url' => home_url(),
124
-            'site_url' => site_url(),
125
-            'WP_DEBUG' => WP_DEBUG,
126
-            'permalink_structure' => get_option('permalink_structure'),
127
-            'theme' => wp_get_theme(),
128
-            'gmt_offset' => get_option('gmt_offset'),
129
-            'timezone_string' => get_option('timezone_string'),
130
-            'admin_email' =>  get_bloginfo('admin_email', 'display'),
131
-            'language' => get_bloginfo('language', 'display'),
132
-            'wp_max_upload_size' => size_format(wp_max_upload_size()),
133
-            'wp_memory' => $wp_memory_to_display
134
-            );
135
-    }
107
+	/**
108
+	 *
109
+	 * @return array with keys 'home_url' and 'site_url'
110
+	 */
111
+	public function get_wp_settings()
112
+	{
113
+		$wp_memory_int = $this->let_to_num(WP_MEMORY_LIMIT);
114
+		if ($wp_memory_int < 67108864) {
115
+			$wp_memory_to_display = '<mark class="error">' . sprintf(__('%s - We recommend setting memory to at least 64MB. See: %s Increasing memory allocated to PHP %s', 'event_espresso'), WP_MEMORY_LIMIT, '<a href="http://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP">', '</a>"') . '</mark>';
116
+		} else {
117
+			$wp_memory_to_display = '<mark class="yes">' . size_format($wp_memory_int) . '</mark>';
118
+		}
119
+		return array(
120
+			'name' => get_bloginfo('name', 'display'),
121
+			'is_multisite' => is_multisite(),
122
+			'version' =>  get_bloginfo('version', 'display'),
123
+			'home_url' => home_url(),
124
+			'site_url' => site_url(),
125
+			'WP_DEBUG' => WP_DEBUG,
126
+			'permalink_structure' => get_option('permalink_structure'),
127
+			'theme' => wp_get_theme(),
128
+			'gmt_offset' => get_option('gmt_offset'),
129
+			'timezone_string' => get_option('timezone_string'),
130
+			'admin_email' =>  get_bloginfo('admin_email', 'display'),
131
+			'language' => get_bloginfo('language', 'display'),
132
+			'wp_max_upload_size' => size_format(wp_max_upload_size()),
133
+			'wp_memory' => $wp_memory_to_display
134
+			);
135
+	}
136 136
 
137
-    /**
138
-     * Gets an array of information about the history of ee versions installed
139
-     * @return array
140
-     */
141
-    public function get_ee_activation_history()
142
-    {
143
-        return get_option('espresso_db_update');
144
-    }
137
+	/**
138
+	 * Gets an array of information about the history of ee versions installed
139
+	 * @return array
140
+	 */
141
+	public function get_ee_activation_history()
142
+	{
143
+		return get_option('espresso_db_update');
144
+	}
145 145
 
146 146
 
147
-    /**
148
-     * Gets an array where keys are ee versions, and their values are arrays indicating all the different times that version was installed
149
-     * @return EE_Data_Migration_Script_Base[]
150
-     */
151
-    public function get_ee_migration_history()
152
-    {
153
-        $options = EE_Data_Migration_Manager::instance()->get_all_migration_script_options();
154
-        $presentable_migration_scripts = array();
155
-        foreach ($options as $option_array) {
156
-            $presentable_migration_scripts[ str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $option_array['option_name']) ] = maybe_unserialize($option_array['option_value']);
157
-        }
158
-        return $presentable_migration_scripts;
147
+	/**
148
+	 * Gets an array where keys are ee versions, and their values are arrays indicating all the different times that version was installed
149
+	 * @return EE_Data_Migration_Script_Base[]
150
+	 */
151
+	public function get_ee_migration_history()
152
+	{
153
+		$options = EE_Data_Migration_Manager::instance()->get_all_migration_script_options();
154
+		$presentable_migration_scripts = array();
155
+		foreach ($options as $option_array) {
156
+			$presentable_migration_scripts[ str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $option_array['option_name']) ] = maybe_unserialize($option_array['option_value']);
157
+		}
158
+		return $presentable_migration_scripts;
159 159
 //      return get_option(EE_Data_Migration_Manager::data_migrations_option_name);//EE_Data_Migration_Manager::instance()->get_data_migrations_ran();
160
-    }
160
+	}
161 161
 
162
-    /**
163
-     *
164
-     * @return array like EE_Config class
165
-     */
166
-    public function get_ee_config()
167
-    {
168
-        return EE_Config::instance();
169
-    }
162
+	/**
163
+	 *
164
+	 * @return array like EE_Config class
165
+	 */
166
+	public function get_ee_config()
167
+	{
168
+		return EE_Config::instance();
169
+	}
170 170
 
171
-    /**
172
-     * Gets an array of php setup info, pilfered from http://www.php.net/manual/en/function.phpinfo.php#87463
173
-     * @return array like the output of phpinfo(), but in an array
174
-     */
175
-    public function get_php_info()
176
-    {
177
-        ob_start();
178
-        phpinfo(-1);
171
+	/**
172
+	 * Gets an array of php setup info, pilfered from http://www.php.net/manual/en/function.phpinfo.php#87463
173
+	 * @return array like the output of phpinfo(), but in an array
174
+	 */
175
+	public function get_php_info()
176
+	{
177
+		ob_start();
178
+		phpinfo(-1);
179 179
 
180
-        $pi = preg_replace(
181
-            array('#^.*<body>(.*)</body>.*$#ms', '#<h2>PHP License</h2>.*$#ms',
182
-            '#<h1>Configuration</h1>#',  "#\r?\n#", "#</(h1|h2|h3|tr)>#", '# +<#',
183
-            "#[ \t]+#", '#&nbsp;#', '#  +#', '# class=".*?"#', '%&#039;%',
184
-            '#<tr>(?:.*?)" src="(?:.*?)=(.*?)" alt="PHP Logo" /></a>'
185
-            . '<h1>PHP Version (.*?)</h1>(?:\n+?)</td></tr>#',
186
-            '#<h1><a href="(?:.*?)\?=(.*?)">PHP Credits</a></h1>#',
187
-            '#<tr>(?:.*?)" src="(?:.*?)=(.*?)"(?:.*?)Zend Engine (.*?),(?:.*?)</tr>#',
188
-            "# +#", '#<tr>#', '#</tr>#'),
189
-            array('$1', '', '', '', '</$1>' . "\n", '<', ' ', ' ', ' ', '', ' ',
190
-            '<h2>PHP Configuration</h2>' . "\n" . '<tr><td>PHP Version</td><td>$2</td></tr>' .
191
-            "\n" . '<tr><td>PHP Egg</td><td>$1</td></tr>',
192
-            '<tr><td>PHP Credits Egg</td><td>$1</td></tr>',
193
-            '<tr><td>Zend Engine</td><td>$2</td></tr>' . "\n" .
194
-            '<tr><td>Zend Egg</td><td>$1</td></tr>', ' ', '%S%', '%E%'),
195
-            ob_get_clean()
196
-        );
180
+		$pi = preg_replace(
181
+			array('#^.*<body>(.*)</body>.*$#ms', '#<h2>PHP License</h2>.*$#ms',
182
+			'#<h1>Configuration</h1>#',  "#\r?\n#", "#</(h1|h2|h3|tr)>#", '# +<#',
183
+			"#[ \t]+#", '#&nbsp;#', '#  +#', '# class=".*?"#', '%&#039;%',
184
+			'#<tr>(?:.*?)" src="(?:.*?)=(.*?)" alt="PHP Logo" /></a>'
185
+			. '<h1>PHP Version (.*?)</h1>(?:\n+?)</td></tr>#',
186
+			'#<h1><a href="(?:.*?)\?=(.*?)">PHP Credits</a></h1>#',
187
+			'#<tr>(?:.*?)" src="(?:.*?)=(.*?)"(?:.*?)Zend Engine (.*?),(?:.*?)</tr>#',
188
+			"# +#", '#<tr>#', '#</tr>#'),
189
+			array('$1', '', '', '', '</$1>' . "\n", '<', ' ', ' ', ' ', '', ' ',
190
+			'<h2>PHP Configuration</h2>' . "\n" . '<tr><td>PHP Version</td><td>$2</td></tr>' .
191
+			"\n" . '<tr><td>PHP Egg</td><td>$1</td></tr>',
192
+			'<tr><td>PHP Credits Egg</td><td>$1</td></tr>',
193
+			'<tr><td>Zend Engine</td><td>$2</td></tr>' . "\n" .
194
+			'<tr><td>Zend Egg</td><td>$1</td></tr>', ' ', '%S%', '%E%'),
195
+			ob_get_clean()
196
+		);
197 197
 
198
-        $sections = explode('<h2>', strip_tags($pi, '<h2><th><td>'));
199
-        unset($sections[0]);
198
+		$sections = explode('<h2>', strip_tags($pi, '<h2><th><td>'));
199
+		unset($sections[0]);
200 200
 
201
-        $pi = array();
202
-        foreach ($sections as $section) {
203
-            $n = substr($section, 0, strpos($section, '</h2>'));
204
-            preg_match_all(
205
-                '#%S%(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?%E%#',
206
-                $section,
207
-                $askapache,
208
-                PREG_SET_ORDER
209
-            );
210
-            foreach ($askapache as $m) {
211
-                $m2 = isset($m[2]) ? $m[2] : null;
212
-            }
213
-              $pi[ $n ][ $m[1] ] = (!isset($m[3]) || $m2 == $m[3]) ? $m2 : array_slice($m, 2);
214
-        }
201
+		$pi = array();
202
+		foreach ($sections as $section) {
203
+			$n = substr($section, 0, strpos($section, '</h2>'));
204
+			preg_match_all(
205
+				'#%S%(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?%E%#',
206
+				$section,
207
+				$askapache,
208
+				PREG_SET_ORDER
209
+			);
210
+			foreach ($askapache as $m) {
211
+				$m2 = isset($m[2]) ? $m[2] : null;
212
+			}
213
+			  $pi[ $n ][ $m[1] ] = (!isset($m[3]) || $m2 == $m[3]) ? $m2 : array_slice($m, 2);
214
+		}
215 215
 
216
-        return $pi;
217
-    }
216
+		return $pi;
217
+	}
218 218
 
219
-    /**
220
-     * Checks if site responds ot HTTPS
221
-     * @return boolean
222
-     */
223
-    public function get_https_enabled()
224
-    {
225
-        $home = str_replace("http://", "https://", home_url());
226
-        $response = wp_remote_get($home);
227
-        if ($response instanceof WP_Error) {
228
-            $error_string = '';
229
-            foreach ($response->errors as $short_name => $description_array) {
230
-                $error_string .= "<b>$short_name</b>: " . implode(", ", $description_array);
231
-            }
232
-            return $error_string;
233
-        }
234
-        return "ok!";
235
-    }
236
-    /**
237
-     * Whether or not a .maintenance file is detected
238
-     * @return string descripting wp_maintenance_mode status
239
-     */
240
-    public function get_wp_maintenance_mode()
241
-    {
242
-        $opened = file_exists(ABSPATH . '.maintenance');
243
-        return $opened ? sprintf(__('%s.maintenance file detected.%s Wordpress may have a failed auto-update which could prevent Event Espresso from updating the database correctly.', 'event_espresso'), '<strong>', '</strong>') : __('.maintenance file not detected. WordPress is not in maintenance mode.', 'event_espresso')  ;
244
-    }
245
-    /**
246
-     * Whether or not logging is enabled
247
-     * @return string descripting logging's status
248
-     */
249
-    public function get_logging_enabled()
250
-    {
251
-            $opened = @fopen(EVENT_ESPRESSO_UPLOAD_DIR . '/logs/espresso_log.txt', 'a');
252
-            return $opened ? __('Log Directory is writable', 'event_espresso') : sprintf(__('%sLog directory is NOT writable%s', 'event_espresso'), '<mark class="error"', '</mark>') ;
253
-    }
254
-    /**
255
-     *  Whether curl ro fsock works
256
-     * @return string describing posting's status
257
-     */
258
-    public function get_remote_posting()
259
-    {
260
-        $fsock_works = function_exists('fsockopen');
261
-        $curl_works = function_exists('curl_init');
262
-        if ($fsock_works && $curl_works) {
263
-            $status = __('Your server has fsockopen and cURL enabled.', 'event_espresso');
264
-        } elseif ($fsock_works) {
265
-            $status = __('Your server has fsockopen enabled, cURL is disabled.', 'event_espresso');
266
-        } elseif ($curl_works) {
267
-            $status = __('Your server has cURL enabled, fsockopen is disabled.', 'event_espresso');
268
-        } else {
269
-            $status = __('Your server does not have fsockopen or cURL enabled - PayPal IPN and other scripts which communicate with other servers will not work. Contact your hosting provider.', 'event_espresso') . '</mark>';
270
-        }
271
-        return $status;
272
-    }
273
-    /**
274
-     * Gets all the php.ini settings
275
-     * @return array
276
-     */
277
-    public function get_php_ini_all()
278
-    {
279
-        return ini_get_all();
280
-    }
281
-    /**
282
-     * Transforms the php.ini notation for numbers (like '2M') to an integer.
283
-     *
284
-     * @param type $size
285
-     * @return int
286
-     */
287
-    public function let_to_num($size)
288
-    {
289
-        $l      = substr($size, -1);
290
-        $ret    = substr($size, 0, -1);
291
-        // phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment
292
-        switch (strtoupper($l)) {
293
-            case 'P':
294
-                $ret *= 1024;
295
-            case 'T':
296
-                $ret *= 1024;
297
-            case 'G':
298
-                $ret *= 1024;
299
-            case 'M':
300
-                $ret *= 1024;
301
-            case 'K':
302
-                $ret *= 1024;
303
-        }
304
-        // phpcs:enable
305
-        return $ret;
306
-    }
219
+	/**
220
+	 * Checks if site responds ot HTTPS
221
+	 * @return boolean
222
+	 */
223
+	public function get_https_enabled()
224
+	{
225
+		$home = str_replace("http://", "https://", home_url());
226
+		$response = wp_remote_get($home);
227
+		if ($response instanceof WP_Error) {
228
+			$error_string = '';
229
+			foreach ($response->errors as $short_name => $description_array) {
230
+				$error_string .= "<b>$short_name</b>: " . implode(", ", $description_array);
231
+			}
232
+			return $error_string;
233
+		}
234
+		return "ok!";
235
+	}
236
+	/**
237
+	 * Whether or not a .maintenance file is detected
238
+	 * @return string descripting wp_maintenance_mode status
239
+	 */
240
+	public function get_wp_maintenance_mode()
241
+	{
242
+		$opened = file_exists(ABSPATH . '.maintenance');
243
+		return $opened ? sprintf(__('%s.maintenance file detected.%s Wordpress may have a failed auto-update which could prevent Event Espresso from updating the database correctly.', 'event_espresso'), '<strong>', '</strong>') : __('.maintenance file not detected. WordPress is not in maintenance mode.', 'event_espresso')  ;
244
+	}
245
+	/**
246
+	 * Whether or not logging is enabled
247
+	 * @return string descripting logging's status
248
+	 */
249
+	public function get_logging_enabled()
250
+	{
251
+			$opened = @fopen(EVENT_ESPRESSO_UPLOAD_DIR . '/logs/espresso_log.txt', 'a');
252
+			return $opened ? __('Log Directory is writable', 'event_espresso') : sprintf(__('%sLog directory is NOT writable%s', 'event_espresso'), '<mark class="error"', '</mark>') ;
253
+	}
254
+	/**
255
+	 *  Whether curl ro fsock works
256
+	 * @return string describing posting's status
257
+	 */
258
+	public function get_remote_posting()
259
+	{
260
+		$fsock_works = function_exists('fsockopen');
261
+		$curl_works = function_exists('curl_init');
262
+		if ($fsock_works && $curl_works) {
263
+			$status = __('Your server has fsockopen and cURL enabled.', 'event_espresso');
264
+		} elseif ($fsock_works) {
265
+			$status = __('Your server has fsockopen enabled, cURL is disabled.', 'event_espresso');
266
+		} elseif ($curl_works) {
267
+			$status = __('Your server has cURL enabled, fsockopen is disabled.', 'event_espresso');
268
+		} else {
269
+			$status = __('Your server does not have fsockopen or cURL enabled - PayPal IPN and other scripts which communicate with other servers will not work. Contact your hosting provider.', 'event_espresso') . '</mark>';
270
+		}
271
+		return $status;
272
+	}
273
+	/**
274
+	 * Gets all the php.ini settings
275
+	 * @return array
276
+	 */
277
+	public function get_php_ini_all()
278
+	{
279
+		return ini_get_all();
280
+	}
281
+	/**
282
+	 * Transforms the php.ini notation for numbers (like '2M') to an integer.
283
+	 *
284
+	 * @param type $size
285
+	 * @return int
286
+	 */
287
+	public function let_to_num($size)
288
+	{
289
+		$l      = substr($size, -1);
290
+		$ret    = substr($size, 0, -1);
291
+		// phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment
292
+		switch (strtoupper($l)) {
293
+			case 'P':
294
+				$ret *= 1024;
295
+			case 'T':
296
+				$ret *= 1024;
297
+			case 'G':
298
+				$ret *= 1024;
299
+			case 'M':
300
+				$ret *= 1024;
301
+			case 'K':
302
+				$ret *= 1024;
303
+		}
304
+		// phpcs:enable
305
+		return $ret;
306
+	}
307 307
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -97,9 +97,9 @@  discard block
 block discarded – undo
97 97
         $active_plugins = array_map('strtolower', $active_plugins);
98 98
         $plugin_info = array();
99 99
         foreach ($active_plugins as $plugin) {
100
-                $plugin_data = @get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin);
100
+                $plugin_data = @get_plugin_data(WP_PLUGIN_DIR.'/'.$plugin);
101 101
 
102
-                $plugin_info[ $plugin ] = $plugin_data;
102
+                $plugin_info[$plugin] = $plugin_data;
103 103
         }
104 104
         return $plugin_info;
105 105
     }
@@ -112,9 +112,9 @@  discard block
 block discarded – undo
112 112
     {
113 113
         $wp_memory_int = $this->let_to_num(WP_MEMORY_LIMIT);
114 114
         if ($wp_memory_int < 67108864) {
115
-            $wp_memory_to_display = '<mark class="error">' . sprintf(__('%s - We recommend setting memory to at least 64MB. See: %s Increasing memory allocated to PHP %s', 'event_espresso'), WP_MEMORY_LIMIT, '<a href="http://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP">', '</a>"') . '</mark>';
115
+            $wp_memory_to_display = '<mark class="error">'.sprintf(__('%s - We recommend setting memory to at least 64MB. See: %s Increasing memory allocated to PHP %s', 'event_espresso'), WP_MEMORY_LIMIT, '<a href="http://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP">', '</a>"').'</mark>';
116 116
         } else {
117
-            $wp_memory_to_display = '<mark class="yes">' . size_format($wp_memory_int) . '</mark>';
117
+            $wp_memory_to_display = '<mark class="yes">'.size_format($wp_memory_int).'</mark>';
118 118
         }
119 119
         return array(
120 120
             'name' => get_bloginfo('name', 'display'),
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
         $options = EE_Data_Migration_Manager::instance()->get_all_migration_script_options();
154 154
         $presentable_migration_scripts = array();
155 155
         foreach ($options as $option_array) {
156
-            $presentable_migration_scripts[ str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $option_array['option_name']) ] = maybe_unserialize($option_array['option_value']);
156
+            $presentable_migration_scripts[str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $option_array['option_name'])] = maybe_unserialize($option_array['option_value']);
157 157
         }
158 158
         return $presentable_migration_scripts;
159 159
 //      return get_option(EE_Data_Migration_Manager::data_migrations_option_name);//EE_Data_Migration_Manager::instance()->get_data_migrations_ran();
@@ -179,18 +179,18 @@  discard block
 block discarded – undo
179 179
 
180 180
         $pi = preg_replace(
181 181
             array('#^.*<body>(.*)</body>.*$#ms', '#<h2>PHP License</h2>.*$#ms',
182
-            '#<h1>Configuration</h1>#',  "#\r?\n#", "#</(h1|h2|h3|tr)>#", '# +<#',
182
+            '#<h1>Configuration</h1>#', "#\r?\n#", "#</(h1|h2|h3|tr)>#", '# +<#',
183 183
             "#[ \t]+#", '#&nbsp;#', '#  +#', '# class=".*?"#', '%&#039;%',
184 184
             '#<tr>(?:.*?)" src="(?:.*?)=(.*?)" alt="PHP Logo" /></a>'
185 185
             . '<h1>PHP Version (.*?)</h1>(?:\n+?)</td></tr>#',
186 186
             '#<h1><a href="(?:.*?)\?=(.*?)">PHP Credits</a></h1>#',
187 187
             '#<tr>(?:.*?)" src="(?:.*?)=(.*?)"(?:.*?)Zend Engine (.*?),(?:.*?)</tr>#',
188 188
             "# +#", '#<tr>#', '#</tr>#'),
189
-            array('$1', '', '', '', '</$1>' . "\n", '<', ' ', ' ', ' ', '', ' ',
190
-            '<h2>PHP Configuration</h2>' . "\n" . '<tr><td>PHP Version</td><td>$2</td></tr>' .
191
-            "\n" . '<tr><td>PHP Egg</td><td>$1</td></tr>',
189
+            array('$1', '', '', '', '</$1>'."\n", '<', ' ', ' ', ' ', '', ' ',
190
+            '<h2>PHP Configuration</h2>'."\n".'<tr><td>PHP Version</td><td>$2</td></tr>'.
191
+            "\n".'<tr><td>PHP Egg</td><td>$1</td></tr>',
192 192
             '<tr><td>PHP Credits Egg</td><td>$1</td></tr>',
193
-            '<tr><td>Zend Engine</td><td>$2</td></tr>' . "\n" .
193
+            '<tr><td>Zend Engine</td><td>$2</td></tr>'."\n".
194 194
             '<tr><td>Zend Egg</td><td>$1</td></tr>', ' ', '%S%', '%E%'),
195 195
             ob_get_clean()
196 196
         );
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
             foreach ($askapache as $m) {
211 211
                 $m2 = isset($m[2]) ? $m[2] : null;
212 212
             }
213
-              $pi[ $n ][ $m[1] ] = (!isset($m[3]) || $m2 == $m[3]) ? $m2 : array_slice($m, 2);
213
+              $pi[$n][$m[1]] = ( ! isset($m[3]) || $m2 == $m[3]) ? $m2 : array_slice($m, 2);
214 214
         }
215 215
 
216 216
         return $pi;
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
         if ($response instanceof WP_Error) {
228 228
             $error_string = '';
229 229
             foreach ($response->errors as $short_name => $description_array) {
230
-                $error_string .= "<b>$short_name</b>: " . implode(", ", $description_array);
230
+                $error_string .= "<b>$short_name</b>: ".implode(", ", $description_array);
231 231
             }
232 232
             return $error_string;
233 233
         }
@@ -239,8 +239,8 @@  discard block
 block discarded – undo
239 239
      */
240 240
     public function get_wp_maintenance_mode()
241 241
     {
242
-        $opened = file_exists(ABSPATH . '.maintenance');
243
-        return $opened ? sprintf(__('%s.maintenance file detected.%s Wordpress may have a failed auto-update which could prevent Event Espresso from updating the database correctly.', 'event_espresso'), '<strong>', '</strong>') : __('.maintenance file not detected. WordPress is not in maintenance mode.', 'event_espresso')  ;
242
+        $opened = file_exists(ABSPATH.'.maintenance');
243
+        return $opened ? sprintf(__('%s.maintenance file detected.%s Wordpress may have a failed auto-update which could prevent Event Espresso from updating the database correctly.', 'event_espresso'), '<strong>', '</strong>') : __('.maintenance file not detected. WordPress is not in maintenance mode.', 'event_espresso');
244 244
     }
245 245
     /**
246 246
      * Whether or not logging is enabled
@@ -248,8 +248,8 @@  discard block
 block discarded – undo
248 248
      */
249 249
     public function get_logging_enabled()
250 250
     {
251
-            $opened = @fopen(EVENT_ESPRESSO_UPLOAD_DIR . '/logs/espresso_log.txt', 'a');
252
-            return $opened ? __('Log Directory is writable', 'event_espresso') : sprintf(__('%sLog directory is NOT writable%s', 'event_espresso'), '<mark class="error"', '</mark>') ;
251
+            $opened = @fopen(EVENT_ESPRESSO_UPLOAD_DIR.'/logs/espresso_log.txt', 'a');
252
+            return $opened ? __('Log Directory is writable', 'event_espresso') : sprintf(__('%sLog directory is NOT writable%s', 'event_espresso'), '<mark class="error"', '</mark>');
253 253
     }
254 254
     /**
255 255
      *  Whether curl ro fsock works
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
         } elseif ($curl_works) {
267 267
             $status = __('Your server has cURL enabled, fsockopen is disabled.', 'event_espresso');
268 268
         } else {
269
-            $status = __('Your server does not have fsockopen or cURL enabled - PayPal IPN and other scripts which communicate with other servers will not work. Contact your hosting provider.', 'event_espresso') . '</mark>';
269
+            $status = __('Your server does not have fsockopen or cURL enabled - PayPal IPN and other scripts which communicate with other servers will not work. Contact your hosting provider.', 'event_espresso').'</mark>';
270 270
         }
271 271
         return $status;
272 272
     }
Please login to merge, or discard this patch.
core/db_models/fields/EE_WP_Post_Status_Field.php 3 patches
Doc Comments   -2 removed lines patch added patch discarded remove patch
@@ -32,8 +32,6 @@
 block discarded – undo
32 32
      *                                    )
33 33
      *                                    )
34 34
      * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info
35
-     * @param boolean $store_in_db_as_int By default, enums are stored as STRINGS in the DB. However, if this var is
36
-     *                                    set to true, it will be stored as an INT
37 35
      */
38 36
     public function __construct($table_column, $nicename, $nullable, $default_value, $new_stati = array())
39 37
     {
Please login to merge, or discard this patch.
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -3,114 +3,114 @@
 block discarded – undo
3 3
 class EE_WP_Post_Status_Field extends EE_Enum_Text_Field
4 4
 {
5 5
 
6
-    protected $_wp_post_stati;
6
+	protected $_wp_post_stati;
7 7
 
8 8
 
9
-    /**
10
-     * constructor
11
-     *
12
-     * @param string  $table_column       column on table
13
-     * @param string  $nicename           nice name for column(field)
14
-     * @param bool    $nullable           is this field nullable
15
-     * @param string  $default_value      default status
16
-     * @param array   $new_stati          If additional stati are to be used other than the default WP statuses then
17
-     *                                    they can be registered via this property.  The format of the array should be
18
-     *                                    as follows: array(
19
-     *                                    'status_reference' => array(
20
-     *                                    'label' => __('Status Reference Label', 'event_espresso')
21
-     *                                    'public' => true, //'Whether posts of this status should be shown on the
22
-     *                                    frontend of the site'
23
-     *                                    'exclude_from_search' => false, //'Whether posts of this status should be
24
-     *                                    excluded from wp searches'
25
-     *                                    'show_in_admin_all_list' => true, //whether posts of this status are included
26
-     *                                    in queries for the admin "all" view in list table views.
27
-     *                                    'show_in_admin_status_list' => true, //Show in the list of statuses with post
28
-     *                                    counts at the top of the admin list tables (i.e. Status Reference(2) )
29
-     *                                    'label_count' => _n_noop( 'Status Reference <span class="count">(%s)</span>',
30
-     *                                    'Status References <span class="count">(%s)</span>' ), //the text to display
31
-     *                                    on the admin screen( or you won't see your status count ).
32
-     *                                    )
33
-     *                                    )
34
-     * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info
35
-     * @param boolean $store_in_db_as_int By default, enums are stored as STRINGS in the DB. However, if this var is
36
-     *                                    set to true, it will be stored as an INT
37
-     */
38
-    public function __construct($table_column, $nicename, $nullable, $default_value, $new_stati = array())
39
-    {
40
-        $this->_register_new_stati($new_stati);
41
-        $this->_set_allowed_enum_values();
42
-        parent::__construct($table_column, $nicename, $nullable, $default_value, $this->_allowed_enum_values);
43
-    }
9
+	/**
10
+	 * constructor
11
+	 *
12
+	 * @param string  $table_column       column on table
13
+	 * @param string  $nicename           nice name for column(field)
14
+	 * @param bool    $nullable           is this field nullable
15
+	 * @param string  $default_value      default status
16
+	 * @param array   $new_stati          If additional stati are to be used other than the default WP statuses then
17
+	 *                                    they can be registered via this property.  The format of the array should be
18
+	 *                                    as follows: array(
19
+	 *                                    'status_reference' => array(
20
+	 *                                    'label' => __('Status Reference Label', 'event_espresso')
21
+	 *                                    'public' => true, //'Whether posts of this status should be shown on the
22
+	 *                                    frontend of the site'
23
+	 *                                    'exclude_from_search' => false, //'Whether posts of this status should be
24
+	 *                                    excluded from wp searches'
25
+	 *                                    'show_in_admin_all_list' => true, //whether posts of this status are included
26
+	 *                                    in queries for the admin "all" view in list table views.
27
+	 *                                    'show_in_admin_status_list' => true, //Show in the list of statuses with post
28
+	 *                                    counts at the top of the admin list tables (i.e. Status Reference(2) )
29
+	 *                                    'label_count' => _n_noop( 'Status Reference <span class="count">(%s)</span>',
30
+	 *                                    'Status References <span class="count">(%s)</span>' ), //the text to display
31
+	 *                                    on the admin screen( or you won't see your status count ).
32
+	 *                                    )
33
+	 *                                    )
34
+	 * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info
35
+	 * @param boolean $store_in_db_as_int By default, enums are stored as STRINGS in the DB. However, if this var is
36
+	 *                                    set to true, it will be stored as an INT
37
+	 */
38
+	public function __construct($table_column, $nicename, $nullable, $default_value, $new_stati = array())
39
+	{
40
+		$this->_register_new_stati($new_stati);
41
+		$this->_set_allowed_enum_values();
42
+		parent::__construct($table_column, $nicename, $nullable, $default_value, $this->_allowed_enum_values);
43
+	}
44 44
 
45 45
 
46
-    /**
47
-     * This registers any new statuses sent via the $new_stati array on construct
48
-     *
49
-     * @access protected
50
-     * @param  array $new_stati statuses
51
-     * @return void
52
-     */
53
-    protected function _register_new_stati($new_stati)
54
-    {
46
+	/**
47
+	 * This registers any new statuses sent via the $new_stati array on construct
48
+	 *
49
+	 * @access protected
50
+	 * @param  array $new_stati statuses
51
+	 * @return void
52
+	 */
53
+	protected function _register_new_stati($new_stati)
54
+	{
55 55
 
56
-        foreach ((array) $new_stati as $status_key => $status_args) {
57
-            $args = array(
58
-                'label'                     => isset($status_args['label']) ? $status_args['label'] : $status_key,
59
-                'public'                    => isset($status_args['public']) && is_bool($status_args['public']) ? $status_args['public'] : true,
60
-                'exclude_from_search'       => isset($status_args['exclude_from_search']) && is_bool($status_args['exclude_from_search']) ? $status_args['exclude_from_search'] : false,
61
-                'show_in_admin_all_list'    => isset($status_args['show_in_admin_all_list']) && is_bool($status_args['show_in_admin_all_list']) ? $status_args['show_in_admin_all_list'] : false,
62
-                'show_in_admin_status_list' => isset($status_args['show_in_admin_status_list']) && is_bool($status_args['show_in_admin_status_list']) ? $status_args['show_in_admin_status_list'] : true,
63
-                'label_count'               => isset($status_args['label_count']) ? $status_args['label_count'] : '',
64
-            );
65
-            register_post_status($status_key, $status_args);
66
-        }
67
-    }
56
+		foreach ((array) $new_stati as $status_key => $status_args) {
57
+			$args = array(
58
+				'label'                     => isset($status_args['label']) ? $status_args['label'] : $status_key,
59
+				'public'                    => isset($status_args['public']) && is_bool($status_args['public']) ? $status_args['public'] : true,
60
+				'exclude_from_search'       => isset($status_args['exclude_from_search']) && is_bool($status_args['exclude_from_search']) ? $status_args['exclude_from_search'] : false,
61
+				'show_in_admin_all_list'    => isset($status_args['show_in_admin_all_list']) && is_bool($status_args['show_in_admin_all_list']) ? $status_args['show_in_admin_all_list'] : false,
62
+				'show_in_admin_status_list' => isset($status_args['show_in_admin_status_list']) && is_bool($status_args['show_in_admin_status_list']) ? $status_args['show_in_admin_status_list'] : true,
63
+				'label_count'               => isset($status_args['label_count']) ? $status_args['label_count'] : '',
64
+			);
65
+			register_post_status($status_key, $status_args);
66
+		}
67
+	}
68 68
 
69 69
 
70
-    /**
71
-     * This sets the _allowed_enum_values property using the $wp_post_stati array
72
-     *
73
-     * @access protected
74
-     * @regurn void
75
-     */
76
-    protected function _set_allowed_enum_values()
77
-    {
78
-        // first let's get the post_statuses
79
-        global $wp_post_statuses;
80
-        $this->_wp_post_stati = $wp_post_statuses;
70
+	/**
71
+	 * This sets the _allowed_enum_values property using the $wp_post_stati array
72
+	 *
73
+	 * @access protected
74
+	 * @regurn void
75
+	 */
76
+	protected function _set_allowed_enum_values()
77
+	{
78
+		// first let's get the post_statuses
79
+		global $wp_post_statuses;
80
+		$this->_wp_post_stati = $wp_post_statuses;
81 81
 
82
-        foreach ($this->_wp_post_stati as $post_status => $args_object) {
83
-            $this->_allowed_enum_values[ $post_status ] = $args_object->label;
84
-        }
85
-    }
82
+		foreach ($this->_wp_post_stati as $post_status => $args_object) {
83
+			$this->_allowed_enum_values[ $post_status ] = $args_object->label;
84
+		}
85
+	}
86 86
 
87
-    /**
88
-     * Before calling parent, first double-checks our list of acceptable post
89
-     * types is up-to-date
90
-     *
91
-     * @param string $value_inputted_for_field_on_model_object
92
-     * @return string
93
-     */
94
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
95
-    {
96
-        $this->_set_allowed_enum_values();
97
-        return parent::prepare_for_set($value_inputted_for_field_on_model_object);
98
-    }
87
+	/**
88
+	 * Before calling parent, first double-checks our list of acceptable post
89
+	 * types is up-to-date
90
+	 *
91
+	 * @param string $value_inputted_for_field_on_model_object
92
+	 * @return string
93
+	 */
94
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
95
+	{
96
+		$this->_set_allowed_enum_values();
97
+		return parent::prepare_for_set($value_inputted_for_field_on_model_object);
98
+	}
99 99
 
100 100
 
101 101
 
102
-    // helper methods for getting various $wp_post_statuses stuff.
102
+	// helper methods for getting various $wp_post_statuses stuff.
103 103
 
104
-    /**
105
-     * This just returns the status object for the given status
106
-     *
107
-     * @access public
108
-     * @see    wp_register_post_status in wp-includes/post.php for a list of properties of the status object
109
-     * @param  string $status What status object you want
110
-     * @return std_object         the status object or FALSE if it doesn't exist.
111
-     */
112
-    public function get_status_object($status)
113
-    {
114
-        return isset($this->_wp_post_stati[ $status ]) ? $this->_wp_post_stati[ $status ] : false;
115
-    }
104
+	/**
105
+	 * This just returns the status object for the given status
106
+	 *
107
+	 * @access public
108
+	 * @see    wp_register_post_status in wp-includes/post.php for a list of properties of the status object
109
+	 * @param  string $status What status object you want
110
+	 * @return std_object         the status object or FALSE if it doesn't exist.
111
+	 */
112
+	public function get_status_object($status)
113
+	{
114
+		return isset($this->_wp_post_stati[ $status ]) ? $this->_wp_post_stati[ $status ] : false;
115
+	}
116 116
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
         $this->_wp_post_stati = $wp_post_statuses;
81 81
 
82 82
         foreach ($this->_wp_post_stati as $post_status => $args_object) {
83
-            $this->_allowed_enum_values[ $post_status ] = $args_object->label;
83
+            $this->_allowed_enum_values[$post_status] = $args_object->label;
84 84
         }
85 85
     }
86 86
 
@@ -111,6 +111,6 @@  discard block
 block discarded – undo
111 111
      */
112 112
     public function get_status_object($status)
113 113
     {
114
-        return isset($this->_wp_post_stati[ $status ]) ? $this->_wp_post_stati[ $status ] : false;
114
+        return isset($this->_wp_post_stati[$status]) ? $this->_wp_post_stati[$status] : false;
115 115
     }
116 116
 }
Please login to merge, or discard this patch.
core/db_models/helpers/EE_Model_Query_Info_Carrier.php 3 patches
Doc Comments   +14 added lines, -1 removed lines patch added patch discarded remove patch
@@ -44,19 +44,33 @@  discard block
 block discarded – undo
44 44
    
45 45
     private $_group_by_sql;
46 46
    
47
+    /**
48
+     * @param string $limit_sql
49
+     */
47 50
     public function set_limit_sql($limit_sql)
48 51
     {
49 52
         $this->_limit_sql = $limit_sql;
50 53
     }
51 54
     
55
+    /**
56
+     * @param string $order_by_sql
57
+     */
52 58
     public function set_order_by_sql($order_by_sql)
53 59
     {
54 60
         $this->_order_by_sql = $order_by_sql;
55 61
     }
62
+
63
+    /**
64
+     * @param string $group_by_sql
65
+     */
56 66
     public function set_group_by_sql($group_by_sql)
57 67
     {
58 68
         $this->_group_by_sql = $group_by_sql;
59 69
     }
70
+
71
+    /**
72
+     * @param string $having_sql
73
+     */
60 74
     public function set_having_sql($having_sql)
61 75
     {
62 76
         $this->_having_sql = $having_sql;
@@ -81,7 +95,6 @@  discard block
 block discarded – undo
81 95
     *
82 96
     * @param type $model_included_name
83 97
     * @param type $join_sql
84
-    * @param type $data_types
85 98
     */
86 99
     public function __construct($model_included_name = array(), $join_sql = '')
87 100
     {
Please login to merge, or discard this patch.
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -14,141 +14,141 @@  discard block
 block discarded – undo
14 14
    /**
15 15
     * @var string SQL for performing joins (Eg, "INNER JOIN blah ON blah=blah INNER JOIN FOO ON foo=foo...")
16 16
     */
17
-    private $_join_sql;
17
+	private $_join_sql;
18 18
    /**
19 19
     *
20 20
     * @var array stating all the models that have been included thus far,so we don't get duplicates.
21 21
     * Keys are the model relation chains to them from the queried model
22 22
     * (eg, "Registration.Transaction.Payment"), and valuesare model names (eg "Payment")
23 23
     */
24
-    private $_models_included;
24
+	private $_models_included;
25 25
    
26 26
    /**
27 27
     * After we've acquired all the data types, we can create this sql.
28 28
     * @var string
29 29
     */
30
-    private $_where_sql;
30
+	private $_where_sql;
31 31
    /**
32 32
     * Full join sql. Eg, in a select query, that's everything after the "FROM", and before the "WHERE", so it includes
33 33
     * the declaration of the main model's tables, and then appends all the joining sql to other models
34 34
     * @var string
35 35
     */
36
-    private $_main_join_sql;
36
+	private $_main_join_sql;
37 37
    
38 38
    
39
-    private $_limit_sql;
39
+	private $_limit_sql;
40 40
    
41
-    private $_order_by_sql;
41
+	private $_order_by_sql;
42 42
    
43
-    private $_having_sql;
43
+	private $_having_sql;
44 44
    
45
-    private $_group_by_sql;
45
+	private $_group_by_sql;
46 46
    
47
-    public function set_limit_sql($limit_sql)
48
-    {
49
-        $this->_limit_sql = $limit_sql;
50
-    }
47
+	public function set_limit_sql($limit_sql)
48
+	{
49
+		$this->_limit_sql = $limit_sql;
50
+	}
51 51
     
52
-    public function set_order_by_sql($order_by_sql)
53
-    {
54
-        $this->_order_by_sql = $order_by_sql;
55
-    }
56
-    public function set_group_by_sql($group_by_sql)
57
-    {
58
-        $this->_group_by_sql = $group_by_sql;
59
-    }
60
-    public function set_having_sql($having_sql)
61
-    {
62
-        $this->_having_sql = $having_sql;
63
-    }
64
-    public function get_limit_sql()
65
-    {
66
-        return $this->_limit_sql;
67
-    }
68
-    public function get_order_by_sql()
69
-    {
70
-        return $this->_order_by_sql;
71
-    }
72
-    public function get_group_by_sql()
73
-    {
74
-        return $this->_group_by_sql;
75
-    }
76
-    public function get_having_sql()
77
-    {
78
-        return $this->_having_sql;
79
-    }
52
+	public function set_order_by_sql($order_by_sql)
53
+	{
54
+		$this->_order_by_sql = $order_by_sql;
55
+	}
56
+	public function set_group_by_sql($group_by_sql)
57
+	{
58
+		$this->_group_by_sql = $group_by_sql;
59
+	}
60
+	public function set_having_sql($having_sql)
61
+	{
62
+		$this->_having_sql = $having_sql;
63
+	}
64
+	public function get_limit_sql()
65
+	{
66
+		return $this->_limit_sql;
67
+	}
68
+	public function get_order_by_sql()
69
+	{
70
+		return $this->_order_by_sql;
71
+	}
72
+	public function get_group_by_sql()
73
+	{
74
+		return $this->_group_by_sql;
75
+	}
76
+	public function get_having_sql()
77
+	{
78
+		return $this->_having_sql;
79
+	}
80 80
    /**
81 81
     *
82 82
     * @param type $model_included_name
83 83
     * @param type $join_sql
84 84
     * @param type $data_types
85 85
     */
86
-    public function __construct($model_included_name = array(), $join_sql = '')
87
-    {
88
-        $this->_models_included = $model_included_name;
89
-        $this->_join_sql = $join_sql;
90
-    }
86
+	public function __construct($model_included_name = array(), $join_sql = '')
87
+	{
88
+		$this->_models_included = $model_included_name;
89
+		$this->_join_sql = $join_sql;
90
+	}
91 91
    
92 92
    /**
93 93
     * Merges info from the other EEM_Related_Model_Info_Carrier into this one.
94 94
     * @param EE_Model_Query_Info_Carrier $other_model_query_info_carrier
95 95
     */
96
-    public function merge($other_model_query_info_carrier)
97
-    {
98
-        if ($other_model_query_info_carrier && ! $this->_have_already_included_one_of_these_models($other_model_query_info_carrier->get_model_names_included())) {
99
-            $model_included_on_other_join_sql_and_data_types_carrier =  $other_model_query_info_carrier->get_model_names_included();
100
-            $this->_models_included = array_merge($this->_models_included, $model_included_on_other_join_sql_and_data_types_carrier);
101
-            $this->_join_sql .= $other_model_query_info_carrier->_join_sql;
102
-        }
103
-        // otherwise don't merge our data.
104
-        // yes, this means that we must immediately merge any model data into our grand list
105
-        // as soon as we get some from ONE model, or else we could reject a EEM_Related_Model_Info_Carrier
106
-        // which is carrying info from two models WHERE one is already included but the other is NOT
107
-    }
96
+	public function merge($other_model_query_info_carrier)
97
+	{
98
+		if ($other_model_query_info_carrier && ! $this->_have_already_included_one_of_these_models($other_model_query_info_carrier->get_model_names_included())) {
99
+			$model_included_on_other_join_sql_and_data_types_carrier =  $other_model_query_info_carrier->get_model_names_included();
100
+			$this->_models_included = array_merge($this->_models_included, $model_included_on_other_join_sql_and_data_types_carrier);
101
+			$this->_join_sql .= $other_model_query_info_carrier->_join_sql;
102
+		}
103
+		// otherwise don't merge our data.
104
+		// yes, this means that we must immediately merge any model data into our grand list
105
+		// as soon as we get some from ONE model, or else we could reject a EEM_Related_Model_Info_Carrier
106
+		// which is carrying info from two models WHERE one is already included but the other is NOT
107
+	}
108 108
    /**
109 109
     * Checks whether or not we have already included all the models mentione din $model_names on the query info varrier
110 110
     * @param array $model_names just like EE_MOdel_QUery_Info_Carrier::_models_included: keys are model chain paths, values are the model names only
111 111
     * @return boolean
112 112
     */
113
-    protected function _have_already_included_one_of_these_models($model_names)
114
-    {
115
-        foreach ($this->_models_included as $model_relation_path => $model_included) {
116
-            if (array_key_exists($model_relation_path, $model_names)) {
117
-                return true;
118
-            }
119
-        }
120
-        return false;
121
-    }
113
+	protected function _have_already_included_one_of_these_models($model_names)
114
+	{
115
+		foreach ($this->_models_included as $model_relation_path => $model_included) {
116
+			if (array_key_exists($model_relation_path, $model_names)) {
117
+				return true;
118
+			}
119
+		}
120
+		return false;
121
+	}
122 122
    /**
123 123
     * Array keys are model names, values are "model relation paths". See EE_Model_Query_Info_Carrier::_models_included for details
124 124
     * @return array like EE_Model_Query_Info_Carrier::_models_included
125 125
     */
126
-    public function get_model_names_included()
127
-    {
128
-        return $this->_models_included;
129
-    }
126
+	public function get_model_names_included()
127
+	{
128
+		return $this->_models_included;
129
+	}
130 130
    /**
131 131
     * sets the $where_sql for later use from client code
132 132
     * @param string $where_sql
133 133
     */
134
-    public function set_where_sql($where_sql)
135
-    {
136
-        $this->_where_sql = $where_sql;
137
-    }
138
-    public function get_where_sql()
139
-    {
140
-        return $this->_where_sql;
141
-    }
134
+	public function set_where_sql($where_sql)
135
+	{
136
+		$this->_where_sql = $where_sql;
137
+	}
138
+	public function get_where_sql()
139
+	{
140
+		return $this->_where_sql;
141
+	}
142 142
 
143 143
    /**
144 144
     * Gets the SQL for joining the main model to other models involves in the query, which was set earlier on
145 145
     * the EE_Model_Query_info_Carrier by calling set_main_model_join_sql()
146 146
     * @return string
147 147
     */
148
-    public function get_main_model_join_sql()
149
-    {
150
-        return $this->_main_join_sql;
151
-    }
148
+	public function get_main_model_join_sql()
149
+	{
150
+		return $this->_main_join_sql;
151
+	}
152 152
 
153 153
 
154 154
    /**
@@ -158,12 +158,12 @@  discard block
 block discarded – undo
158 158
     * after the FROM and before the WHERE.)
159 159
     * @param string $join_sql
160 160
     */
161
-    public function set_main_model_join_sql($join_sql)
162
-    {
163
-        $this->_main_join_sql = $join_sql;
164
-    }
165
-    public function get_full_join_sql()
166
-    {
167
-        return $this->_main_join_sql . $this->_join_sql;
168
-    }
161
+	public function set_main_model_join_sql($join_sql)
162
+	{
163
+		$this->_main_join_sql = $join_sql;
164
+	}
165
+	public function get_full_join_sql()
166
+	{
167
+		return $this->_main_join_sql . $this->_join_sql;
168
+	}
169 169
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
     public function merge($other_model_query_info_carrier)
97 97
     {
98 98
         if ($other_model_query_info_carrier && ! $this->_have_already_included_one_of_these_models($other_model_query_info_carrier->get_model_names_included())) {
99
-            $model_included_on_other_join_sql_and_data_types_carrier =  $other_model_query_info_carrier->get_model_names_included();
99
+            $model_included_on_other_join_sql_and_data_types_carrier = $other_model_query_info_carrier->get_model_names_included();
100 100
             $this->_models_included = array_merge($this->_models_included, $model_included_on_other_join_sql_and_data_types_carrier);
101 101
             $this->_join_sql .= $other_model_query_info_carrier->_join_sql;
102 102
         }
@@ -164,6 +164,6 @@  discard block
 block discarded – undo
164 164
     }
165 165
     public function get_full_join_sql()
166 166
     {
167
-        return $this->_main_join_sql . $this->_join_sql;
167
+        return $this->_main_join_sql.$this->_join_sql;
168 168
     }
169 169
 }
Please login to merge, or discard this patch.