PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.7.31.4
Pods – Custom Content Types and Fields v2.7.31.4
2.7.31.4 2.8.23.5 2.9.19.5 3.0.10.5 3.1.4.3 3.2.8.4 3.3.9.2 2.8.23.4 2.9.19.4 3.0.10.4 3.1.4.2 3.2.8.3 3.3.9.1 trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / sql / upgrade / PodsUpgrade.php
pods / sql / upgrade Last commit date
PodsUpgrade.php 4 days ago PodsUpgrade_2_0_0.php 4 days ago PodsUpgrade_2_1_0.php 4 days ago
PodsUpgrade.php
266 lines
1 <?php
2
3 /**
4 * @package Pods\Upgrade
5 */
6 class PodsUpgrade {
7
8 /**
9 * @var array
10 */
11 public $tables = array();
12
13 /**
14 * @var array
15 */
16 protected $progress = array();
17
18 /**
19 * @var PodsAPI
20 */
21 protected $api = null;
22
23 /**
24 * @var string
25 */
26 protected $version = null;
27
28 /**
29 *
30 */
31 public function __construct() {
32
33 $this->api = pods_api();
34
35 $this->get_tables();
36 $this->get_progress();
37 }
38
39 /**
40 * @param null $_blog_id Blog ID to install.
41 */
42 public function install( $_blog_id = null ) {
43
44 /**
45 * @var $wpdb WPDB
46 */
47 global $wpdb;
48
49 // Switch DB table prefixes
50 if ( null !== $_blog_id && $_blog_id !== $wpdb->blogid ) {
51 switch_to_blog( pods_absint( $_blog_id ) );
52 } else {
53 $_blog_id = null;
54 }
55
56 $pods_version = get_option( 'pods_version' );
57
58 do_action( 'pods_install', PODS_VERSION, $pods_version, $_blog_id );
59
60 if ( ( ! pods_tableless() ) && false !== apply_filters( 'pods_install_run', null, PODS_VERSION, $pods_version, $_blog_id ) && 0 === (int) pods_v( 'pods_bypass_install' ) ) {
61 $sql = file_get_contents( PODS_DIR . 'sql/dump.sql' );
62 $sql = apply_filters( 'pods_install_sql', $sql, PODS_VERSION, $pods_version, $_blog_id );
63
64 $charset_collate = 'DEFAULT CHARSET utf8';
65
66 if ( ! empty( $wpdb->charset ) ) {
67 $charset_collate = "DEFAULT CHARSET {$wpdb->charset}";
68 }
69
70 if ( ! empty( $wpdb->collate ) ) {
71 $charset_collate .= " COLLATE {$wpdb->collate}";
72 }
73
74 if ( 'DEFAULT CHARSET utf8' !== $charset_collate ) {
75 $sql = str_replace( 'DEFAULT CHARSET utf8', $charset_collate, $sql );
76 }
77
78 $sql = explode( ";\n", str_replace( array( "\r", 'wp_' ), array( "\n", $wpdb->prefix ), $sql ) );
79
80 $z = count( $sql );
81 for ( $i = 0; $i < $z; $i ++ ) {
82 $query = trim( $sql[ $i ] );
83
84 if ( empty( $query ) ) {
85 continue;
86 }
87
88 pods_query( $query, 'Cannot setup SQL tables' );
89 }
90
91 // Auto activate component.
92 if ( ! PodsInit::$components ) {
93 if ( ! pods_light() ) {
94 PodsInit::$components = pods_components();
95 }
96 }
97
98 if ( PodsInit::$components ) {
99 PodsInit::$components->activate_component( 'templates' );
100 }
101 }//end if
102
103 do_action( 'pods_install_post', PODS_VERSION, $pods_version, $_blog_id );
104 }
105
106 /**
107 *
108 */
109 public function get_tables() {
110
111 /**
112 * @var $wpdb WPDB
113 */
114 global $wpdb;
115
116 $tables = $wpdb->get_results( "SHOW TABLES LIKE '{$wpdb->prefix}pod%'", ARRAY_N );
117
118 if ( ! empty( $tables ) ) {
119 foreach ( $tables as $table ) {
120 $this->tables[] = $table[0];
121 }
122 }
123 }
124
125 /**
126 *
127 */
128 public function get_progress() {
129
130 $methods = get_class_methods( $this );
131
132 foreach ( $methods as $method ) {
133 if ( 0 === strpos( $method, 'migrate_' ) ) {
134 $this->progress[ str_replace( 'migrate_', '', $method ) ] = false;
135 }
136 }
137
138 $progress = (array) get_option( 'pods_framework_upgrade_' . str_replace( '.', '_', $this->version ), array() );
139
140 if ( ! empty( $progress ) ) {
141 $this->progress = array_merge( $this->progress, $progress );
142 }
143 }
144
145 /**
146 * @param $params
147 *
148 * @return mixed|void
149 */
150 public function ajax( $params ) {
151
152 if ( ! isset( $params->step ) ) {
153 return pods_error( __( 'Invalid upgrade process.', 'pods' ) );
154 }
155
156 if ( ! isset( $params->type ) ) {
157 return pods_error( __( 'Invalid upgrade method.', 'pods' ) );
158 }
159
160 if ( ! method_exists( $this, $params->step . '_' . $params->type ) ) {
161 return pods_error( __( 'Upgrade method not found.', 'pods' ) );
162 }
163
164 return call_user_func( array( $this, $params->step . '_' . $params->type ), $params );
165 }
166
167 /**
168 * @param $method
169 * @param $v
170 * @param null $x
171 */
172 public function update_progress( $method, $v, $x = null ) {
173
174 if ( empty( $this->version ) ) {
175 return;
176 }
177
178 $method = str_replace( 'migrate_', '', $method );
179
180 if ( null !== $x ) {
181 $this->progress[ $method ][ $x ] = (boolean) $v;
182 } else {
183 $this->progress[ $method ] = $v;
184 }
185
186 update_option( 'pods_framework_upgrade_' . str_replace( '.', '_', $this->version ), $this->progress );
187 }
188
189 /**
190 * @param $method
191 * @param null $x
192 *
193 * @return bool
194 */
195 public function check_progress( $method, $x = null ) {
196
197 $method = str_replace( 'migrate_', '', $method );
198
199 if ( isset( $this->progress[ $method ] ) ) {
200 if ( null === $x ) {
201 return $this->progress[ $method ];
202 } elseif ( isset( $this->progress[ $method ][ $x ] ) ) {
203 return (boolean) $this->progress[ $method ][ $x ];
204 }
205 }
206
207 return false;
208 }
209
210 /**
211 *
212 */
213 public function upgraded() {
214
215 if ( empty( $this->version ) ) {
216 return;
217 }
218
219 $upgraded = get_option( 'pods_framework_upgraded' );
220
221 if ( empty( $upgraded ) || ! is_array( $upgraded ) ) {
222 $upgraded = array();
223 }
224
225 delete_option( 'pods_framework_upgrade_' . str_replace( '.', '_', $this->version ) );
226
227 if ( ! in_array( $this->version, $upgraded, true ) ) {
228 $upgraded[] = $this->version;
229 }
230
231 update_option( 'pods_framework_upgraded', $upgraded );
232 }
233
234 /**
235 *
236 */
237 public function cleanup() {
238
239 /**
240 * @var $wpdb WPDB
241 */
242 global $wpdb;
243
244 foreach ( $this->tables as $table ) {
245 if ( false !== strpos( $table, "{$wpdb->prefix}pod_" ) || "{$wpdb->prefix}pod" === $table ) {
246 pods_query( "DROP TABLE `{$table}`", false );
247 }
248 }
249
250 delete_option( 'pods_roles' );
251 delete_option( 'pods_version' );
252 delete_option( 'pods_framework_upgrade_2_0' );
253 delete_option( 'pods_framework_upgrade_2_0_sister_ids' );
254 delete_option( 'pods_framework_upgraded_1_x' );
255
256 delete_option( 'pods_disable_file_browser' );
257 delete_option( 'pods_files_require_login' );
258 delete_option( 'pods_files_require_login_cap' );
259 delete_option( 'pods_disable_file_upload' );
260 delete_option( 'pods_upload_require_login' );
261 delete_option( 'pods_upload_require_login_cap' );
262
263 pods_query( "DELETE FROM `@wp_postmeta` WHERE `meta_key` LIKE '_pods_1x_%'" );
264 }
265 }
266