Migrations.php
8.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<?php if ( ! defined( 'ABSPATH' ) ) exit;
class NF_Database_Migrations
{
protected $migrations = array();
/**
* Constructor method for the NF_Database_Migrations class.
*
* @since 3.0.0
*
* @updated 3.3.8
*/
public function __construct()
{
$this->migrations[ 'forms' ] = new NF_Database_Migrations_Forms();
$this->migrations[ 'form_meta' ] = new NF_Database_Migrations_FormMeta();
$this->migrations[ 'fields' ] = new NF_Database_Migrations_Fields();
$this->migrations[ 'field_meta' ] = new NF_Database_Migrations_FieldMeta();
$this->migrations[ 'actions' ] = new NF_Database_Migrations_Actions();
$this->migrations[ 'action_meta' ] = new NF_Database_Migrations_ActionMeta();
$this->migrations[ 'objects' ] = new NF_Database_Migrations_Objects();
$this->migrations[ 'object_meta' ] = new NF_Database_Migrations_ObjectMeta();
$this->migrations[ 'relationships' ] = new NF_Database_Migrations_Relationships();
$this->migrations[ 'settings' ] = new NF_Database_Migrations_Settings();
$this->migrations[ 'upgrades' ] = new NF_Database_Migrations_Upgrades();
$this->migrations[ 'chunks' ] = new NF_Database_Migrations_Chunks();
}
/**
* Function to run each migration on the stack.
*
* @since 3.0.0
*/
public function migrate()
{
foreach( $this->migrations as $migration ){
$migration->_run();
}
}
/**
* Function to run any required database upgrades.
*
* @param $callback (String) The method this upgrade will call from individual migration files.
*
* @since 3.4.0
*/
public function do_upgrade( $callback )
{
foreach( $this->migrations as $migration ) {
$migration->_do_upgrade( $callback );
}
}
/**
* This function drops ninja forms tables and options
*
* @param $areYouSure (Boolean)
* @param $areYouReallySure (Boolean)
* @param $nuke_multisite (Boolean)
*
* @since 2.9.34
* @updated 3.3.16
*/
public function nuke( $areYouSure = FALSE, $areYouReallySure = FALSE, $nuke_multisite = TRUE )
{
if( ! $areYouSure || ! $areYouReallySure ) return;
global $wpdb;
if( ! function_exists( 'is_multisite' ) || ! is_multisite() ){
$this->_nuke();
return;
}
// adding this to make sure we don't nuke ALL subsites when upgrading one subsite
if ( $nuke_multisite ) {
$blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
foreach( $blog_ids as $blog_id ){
switch_to_blog( $blog_id );
$this->_nuke();
restore_current_blog(); // Call after EVERY switch_to_blog().
}
} else {
$this->_nuke();
return;
}
}
/**
* Function to handle the actual deletion of tables and caches.
*
* @since 3.1.0
*/
private function _nuke()
{
global $wpdb;
/* Drop THREE Tables */
foreach( $this->migrations as $migration ){
$migration->_drop();
}
/* Delete form caches */
$wpdb->query( "DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE 'nf_form_%'" );
$wpdb->query( "DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE '_transient_nf_form_%'" );
$wpdb->query( "DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE '_transient_timeout_nf_form_%'" );
}
/**
* Function to nuke our 3.0 settings.
*
* @param $areYouSure (Boolean)
* @param $areYouReallySure (Boolean)
*
* @since 3.1.0
*/
public function nuke_settings( $areYouSure = FALSE, $areYouReallySure = FALSE )
{
if( ! $areYouSure || ! $areYouReallySure ) return;
global $wpdb;
if( ! function_exists( 'is_multisite' ) || ! is_multisite() ){
$this->_nuke_settings();
return;
}
$blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
foreach( $blog_ids as $blog_id ){
switch_to_blog( $blog_id );
$this->_nuke_settings();
restore_current_blog(); // Call after EVERY switch_to_blog().
}
}
/**
* Function to handle the actual deletion of our 3.0 settings.
*
* @since 3.1.0
*/
private function _nuke_settings()
{
global $wpdb;
/* Delete known options */
delete_option( 'nf_admin_notice' );
delete_option( 'nf_form_tel_data' );
delete_option( 'nf_form_tel_sent' );
delete_option( 'nf_tel_collate' );
delete_option( 'ninja_forms_allow_tracking' );
delete_option( 'ninja_forms_db_version' );
delete_option( 'ninja_forms_do_not_allow_tracking' );
delete_option( 'ninja_forms_load_deprecated' );
delete_option( 'ninja_forms_mailchimp_interests' );
delete_option( 'ninja_forms_oauth_client_secret' );
delete_option( 'ninja_forms_optin_reported' );
delete_option( 'ninja_forms_settings' );
delete_option( 'ninja_forms_transactional_email_enabled' );
delete_option( 'ninja_forms_version' );
/* Delete possible options */
$wpdb->query( "DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE 'wp_nf_%'" );
$wpdb->query( "DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE 'ninja_forms_%'" );
/* Delete background processing flags */
$wpdb->query( "DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE 'wp_nf_update_fields_%'" );
}
/**
* Function to nuke our 2.9 database tables.
*
* @param $areYouSure (Boolean)
* @param $areYouReallySure (Boolean)
*
* @since 3.1.0
*/
public function nuke_deprecated( $areYouSure = FALSE, $areYouReallySure = FALSE )
{
if( ! $areYouSure || ! $areYouReallySure ) return;
global $wpdb;
if( ! function_exists( 'is_multisite' ) || ! is_multisite() ){
$this->_nuke_deprecated();
return;
}
$blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
foreach( $blog_ids as $blog_id ){
switch_to_blog( $blog_id );
$this->_nuke_deprecated();
restore_current_blog(); // Call after EVERY switch_to_blog().
}
}
/**
* Function to handle the actual deletion of deprecated tables and options.
*
* @since 3.1.0
*/
private function _nuke_deprecated()
{
global $wpdb;
/* Drop Deprecated Tables (v2.9.x) */
$wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->prefix}nf_objectmeta`" );
$wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->prefix}nf_objects`" );
$wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->prefix}nf_relationships`" );
$wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->prefix}ninja_forms_fav_fields`" );
$wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->prefix}ninja_forms_fields`" );
/* Delete Deprecated Options (v2.9.x) */
delete_option( 'nf_upgrade_notice' );
delete_option( 'nf_converted_subs' );
delete_option( 'nf_converted_forms' );
delete_option( 'nf_convert_subs_num' );
delete_option( 'nf_convert_subs_step' );
delete_option( 'nf_convert_subs_step' );
delete_option( 'nf_email_fav_updated' );
delete_option( 'nf_database_migrations' );
delete_option( 'nf_converted_form_reset' );
delete_option( 'nf_version_upgraded_from' );
delete_option( 'nf_convert_forms_complete' );
delete_option( 'nf_convert_notifications_forms' );
delete_option( 'nf_convert_notifications_complete' );
delete_option( 'nf_update_email_settings_complete' );
/* Delete Deprecarted Upgrade Options (v2.9.x) */
$wpdb->query( "DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE 'nf_upgrade_%'" );
/* Maybe Remove Deprecated Scheduled Cron (v2.9.x) */
if( $timestamp = wp_next_scheduled( 'ninja_forms_daily_action' ) ){
wp_unschedule_event( $timestamp, 'ninja_forms_daily_action' );
}
}
}