This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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; |
||
0 ignored issues
–
show
|
|||
48 | |||
49 | // Switch DB table prefixes |
||
50 | if ( null !== $_blog_id && $_blog_id !== $wpdb->blogid ) { |
||
51 | switch_to_blog( pods_absint( $_blog_id ) ); |
||
0 ignored issues
–
show
|
|||
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' ); |
||
0 ignored issues
–
show
|
|||
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 | for ( $i = 0, $z = count( $sql ); $i < $z; $i ++ ) { |
||
81 | $query = trim( $sql[ $i ] ); |
||
82 | |||
83 | if ( empty( $query ) ) { |
||
84 | continue; |
||
85 | } |
||
86 | |||
87 | pods_query( $query, 'Cannot setup SQL tables' ); |
||
88 | } |
||
89 | |||
90 | // Auto activate component. |
||
91 | if ( ! PodsInit::$components ) { |
||
92 | if ( ! defined( 'PODS_LIGHT' ) || ! PODS_LIGHT ) { |
||
93 | PodsInit::$components = pods_components(); |
||
94 | } |
||
95 | } |
||
96 | |||
97 | if ( PodsInit::$components ) { |
||
98 | PodsInit::$components->activate_component( 'templates' ); |
||
99 | } |
||
100 | }//end if |
||
101 | |||
102 | do_action( 'pods_install_post', PODS_VERSION, $pods_version, $_blog_id ); |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * |
||
107 | */ |
||
108 | public function get_tables() { |
||
109 | |||
110 | /** |
||
111 | * @var $wpdb WPDB |
||
112 | */ |
||
113 | global $wpdb; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
114 | |||
115 | $tables = $wpdb->get_results( "SHOW TABLES LIKE '{$wpdb->prefix}pod%'", ARRAY_N ); |
||
0 ignored issues
–
show
|
|||
116 | |||
117 | if ( ! empty( $tables ) ) { |
||
118 | foreach ( $tables as $table ) { |
||
119 | $this->tables[] = $table[0]; |
||
120 | } |
||
121 | } |
||
122 | } |
||
123 | |||
124 | /** |
||
125 | * |
||
126 | */ |
||
127 | public function get_progress() { |
||
128 | |||
129 | $methods = get_class_methods( $this ); |
||
130 | |||
131 | foreach ( $methods as $method ) { |
||
132 | if ( 0 === strpos( $method, 'migrate_' ) ) { |
||
133 | $this->progress[ str_replace( 'migrate_', '', $method ) ] = false; |
||
134 | } |
||
135 | } |
||
136 | |||
137 | $progress = (array) get_option( 'pods_framework_upgrade_' . str_replace( '.', '_', $this->version ), array() ); |
||
138 | |||
139 | if ( ! empty( $progress ) ) { |
||
140 | $this->progress = array_merge( $this->progress, $progress ); |
||
141 | } |
||
142 | } |
||
143 | |||
144 | /** |
||
145 | * @param $params |
||
146 | * |
||
147 | * @return mixed|void |
||
148 | */ |
||
149 | public function ajax( $params ) { |
||
150 | |||
151 | if ( ! isset( $params->step ) ) { |
||
152 | return pods_error( __( 'Invalid upgrade process.', 'pods' ) ); |
||
153 | } |
||
154 | |||
155 | if ( ! isset( $params->type ) ) { |
||
156 | return pods_error( __( 'Invalid upgrade method.', 'pods' ) ); |
||
157 | } |
||
158 | |||
159 | if ( ! method_exists( $this, $params->step . '_' . $params->type ) ) { |
||
160 | return pods_error( __( 'Upgrade method not found.', 'pods' ) ); |
||
161 | } |
||
162 | |||
163 | return call_user_func( array( $this, $params->step . '_' . $params->type ), $params ); |
||
164 | } |
||
165 | |||
166 | /** |
||
167 | * @param $method |
||
168 | * @param $v |
||
169 | * @param null $x |
||
170 | */ |
||
171 | public function update_progress( $method, $v, $x = null ) { |
||
0 ignored issues
–
show
|
|||
172 | |||
173 | if ( empty( $this->version ) ) { |
||
174 | return; |
||
175 | } |
||
176 | |||
177 | $method = str_replace( 'migrate_', '', $method ); |
||
178 | |||
179 | if ( null !== $x ) { |
||
180 | $this->progress[ $method ][ $x ] = (boolean) $v; |
||
181 | } else { |
||
182 | $this->progress[ $method ] = $v; |
||
183 | } |
||
184 | |||
185 | update_option( 'pods_framework_upgrade_' . str_replace( '.', '_', $this->version ), $this->progress ); |
||
186 | } |
||
187 | |||
188 | /** |
||
189 | * @param $method |
||
190 | * @param null $x |
||
191 | * |
||
192 | * @return bool |
||
193 | */ |
||
194 | public function check_progress( $method, $x = null ) { |
||
0 ignored issues
–
show
|
|||
195 | |||
196 | $method = str_replace( 'migrate_', '', $method ); |
||
197 | |||
198 | if ( isset( $this->progress[ $method ] ) ) { |
||
199 | if ( null === $x ) { |
||
200 | return $this->progress[ $method ]; |
||
201 | } elseif ( isset( $this->progress[ $method ][ $x ] ) ) { |
||
202 | return (boolean) $this->progress[ $method ][ $x ]; |
||
203 | } |
||
204 | } |
||
205 | |||
206 | return false; |
||
207 | } |
||
208 | |||
209 | /** |
||
210 | * |
||
211 | */ |
||
212 | public function upgraded() { |
||
213 | |||
214 | if ( empty( $this->version ) ) { |
||
215 | return; |
||
216 | } |
||
217 | |||
218 | $upgraded = get_option( 'pods_framework_upgraded' ); |
||
219 | |||
220 | if ( empty( $upgraded ) || ! is_array( $upgraded ) ) { |
||
221 | $upgraded = array(); |
||
222 | } |
||
223 | |||
224 | delete_option( 'pods_framework_upgrade_' . str_replace( '.', '_', $this->version ) ); |
||
225 | |||
226 | if ( ! in_array( $this->version, $upgraded, true ) ) { |
||
227 | $upgraded[] = $this->version; |
||
228 | } |
||
229 | |||
230 | update_option( 'pods_framework_upgraded', $upgraded ); |
||
231 | } |
||
232 | |||
233 | /** |
||
234 | * |
||
235 | */ |
||
236 | public function cleanup() { |
||
237 | |||
238 | /** |
||
239 | * @var $wpdb WPDB |
||
240 | */ |
||
241 | global $wpdb; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
242 | |||
243 | foreach ( $this->tables as $table ) { |
||
244 | if ( false !== strpos( $table, "{$wpdb->prefix}pod_" ) || "{$wpdb->prefix}pod" === $table ) { |
||
245 | pods_query( "DROP TABLE `{$table}`", false ); |
||
246 | } |
||
247 | } |
||
248 | |||
249 | delete_option( 'pods_roles' ); |
||
250 | delete_option( 'pods_version' ); |
||
251 | delete_option( 'pods_framework_upgrade_2_0' ); |
||
252 | delete_option( 'pods_framework_upgrade_2_0_sister_ids' ); |
||
253 | delete_option( 'pods_framework_upgraded_1_x' ); |
||
254 | |||
255 | delete_option( 'pods_disable_file_browser' ); |
||
256 | delete_option( 'pods_files_require_login' ); |
||
257 | delete_option( 'pods_files_require_login_cap' ); |
||
258 | delete_option( 'pods_disable_file_upload' ); |
||
259 | delete_option( 'pods_upload_require_login' ); |
||
260 | delete_option( 'pods_upload_require_login_cap' ); |
||
261 | |||
262 | pods_query( "DELETE FROM `@wp_postmeta` WHERE `meta_key` LIKE '_pods_1x_%'" ); |
||
263 | } |
||
264 | } |
||
265 |
Instead of relying on
global
state, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state