← All changes
|
WPDataAccess/Plugin_Table_Models/WPDA_App_Container_Model.php
+59
-44
5.5.76
→
5.5.84
View file →
| @@ -8,58 +8,50 @@ | ||
| 8 | 8 | |
| 9 | 9 | public static function select( $app_id, $cnt_seq_nr ) { |
| 10 | 10 | global $wpdb; |
| 11 | 11 | if ( 0 === $cnt_seq_nr ) { |
| 12 | - return $wpdb->get_results( | |
| 13 | - $wpdb->prepare( | |
| 14 | - 'SELECT * FROM `%1s` WHERE app_id = %d and cnt_seq_nr = 0 order by cnt_id', | |
| 15 | - // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders | |
| 16 | - array(WPDA::remove_backticks( self::get_base_table_name() ), $app_id) | |
| 17 | - ), | |
| 12 | + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQLPlaceholders -- plugin table | |
| 13 | + $dataset = $wpdb->get_results( | |
| 14 | + $wpdb->prepare( 'SELECT * FROM `%1s` WHERE app_id = %d and cnt_seq_nr = 0 order by cnt_id', array(WPDA::remove_backticks( self::get_base_table_name() ), $app_id) ), | |
| 18 | 15 | // db call ok; no-cache ok. |
| 19 | 16 | 'ARRAY_A' |
| 20 | 17 | ); |
| 21 | - // phpcs:ignore Standard.Category.SniffName.ErrorCode | |
| 18 | + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQLPlaceholders | |
| 19 | + return $dataset; | |
| 22 | 20 | } else { |
| 23 | - return $wpdb->get_results( | |
| 24 | - $wpdb->prepare( | |
| 25 | - 'SELECT * FROM `%1s` WHERE app_id = %d and cnt_seq_nr > 0 order by cnt_seq_nr, cnt_id', | |
| 26 | - // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders | |
| 27 | - array(WPDA::remove_backticks( self::get_base_table_name() ), $app_id) | |
| 28 | - ), | |
| 21 | + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQLPlaceholders -- plugin table | |
| 22 | + $dataset = $wpdb->get_results( | |
| 23 | + $wpdb->prepare( 'SELECT * FROM `%1s` WHERE app_id = %d and cnt_seq_nr > 0 order by cnt_seq_nr, cnt_id', array(WPDA::remove_backticks( self::get_base_table_name() ), $app_id) ), | |
| 29 | 24 | // db call ok; no-cache ok. |
| 30 | 25 | 'ARRAY_A' |
| 31 | 26 | ); |
| 32 | - // phpcs:ignore Standard.Category.SniffName.ErrorCode | |
| 27 | + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQLPlaceholders | |
| 28 | + return $dataset; | |
| 33 | 29 | } |
| 34 | 30 | } |
| 35 | 31 | |
| 36 | 32 | public static function select_all( $app_id ) { |
| 37 | 33 | global $wpdb; |
| 38 | - return $wpdb->get_results( | |
| 39 | - $wpdb->prepare( | |
| 40 | - 'SELECT * FROM `%1s` WHERE app_id = %d order by cnt_seq_nr', | |
| 41 | - // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders | |
| 42 | - array(WPDA::remove_backticks( self::get_base_table_name() ), $app_id) | |
| 43 | - ), | |
| 34 | + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQLPlaceholders -- plugin table | |
| 35 | + $dataset = $wpdb->get_results( | |
| 36 | + $wpdb->prepare( 'SELECT * FROM `%1s` WHERE app_id = %d order by cnt_seq_nr', array(WPDA::remove_backticks( self::get_base_table_name() ), $app_id) ), | |
| 44 | 37 | // db call ok; no-cache ok. |
| 45 | 38 | 'ARRAY_A' |
| 46 | 39 | ); |
| 47 | - // phpcs:ignore Standard.Category.SniffName.ErrorCode | |
| 40 | + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQLPlaceholders | |
| 41 | + return $dataset; | |
| 48 | 42 | } |
| 49 | 43 | |
| 50 | 44 | public static function get_container( $app_id, $cnt_id ) { |
| 51 | 45 | global $wpdb; |
| 52 | - return $wpdb->get_results( | |
| 53 | - $wpdb->prepare( | |
| 54 | - 'SELECT * FROM `%1s` WHERE app_id = %d AND cnt_id = %d', | |
| 55 | - // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders | |
| 56 | - array(WPDA::remove_backticks( self::get_base_table_name() ), $app_id, $cnt_id) | |
| 57 | - ), | |
| 46 | + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQLPlaceholders -- plugin table | |
| 47 | + $dataset = $wpdb->get_results( | |
| 48 | + $wpdb->prepare( 'SELECT * FROM `%1s` WHERE app_id = %d AND cnt_id = %d', array(WPDA::remove_backticks( self::get_base_table_name() ), $app_id, $cnt_id) ), | |
| 58 | 49 | // db call ok; no-cache ok. |
| 59 | 50 | 'ARRAY_A' |
| 60 | 51 | ); |
| 61 | - // phpcs:ignore Standard.Category.SniffName.ErrorCode | |
| 52 | + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQLPlaceholders | |
| 53 | + return $dataset; | |
| 62 | 54 | } |
| 63 | 55 | |
| 64 | 56 | public static function create( |
| 65 | 57 | $app_id, |
| @@ -73,23 +65,21 @@ | ||
| 73 | 65 | $cnt_query = null |
| 74 | 66 | ) { |
| 75 | 67 | global $wpdb; |
| 76 | 68 | if ( 1 === $cnt_seq_nr ) { |
| 69 | + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQLPlaceholders -- plugin table | |
| 77 | 70 | $max_seq_nr = $wpdb->get_results( |
| 78 | - $wpdb->prepare( | |
| 79 | - 'SELECT max(cnt_seq_nr) FROM `%1s` WHERE app_id = %d', | |
| 80 | - // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders | |
| 81 | - array(WPDA::remove_backticks( self::get_base_table_name() ), $app_id) | |
| 82 | - ), | |
| 71 | + $wpdb->prepare( 'SELECT max(cnt_seq_nr) FROM `%1s` WHERE app_id = %d', array(WPDA::remove_backticks( self::get_base_table_name() ), $app_id) ), | |
| 83 | 72 | // db call ok; no-cache ok. |
| 84 | 73 | 'ARRAY_N' |
| 85 | 74 | ); |
| 86 | - // phpcs:ignore Standard.Category.SniffName.ErrorCode | |
| 75 | + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQLPlaceholders | |
| 87 | 76 | if ( isset( $max_seq_nr[0][0] ) ) { |
| 88 | 77 | $cnt_seq_nr = $max_seq_nr[0][0] + 1; |
| 89 | 78 | } |
| 90 | 79 | } |
| 91 | - if ( 1 === $wpdb->insert( static::get_base_table_name(), array( | |
| 80 | + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- plugin table | |
| 81 | + $rows = $wpdb->insert( static::get_base_table_name(), array( | |
| 92 | 82 | 'cnt_dbs' => $app_dbs, |
| 93 | 83 | 'cnt_tbl' => $app_tbl, |
| 94 | 84 | 'cnt_cls' => $app_cls, |
| 95 | 85 | 'cnt_title' => $cnt_title, |
| @@ -97,9 +87,11 @@ | ||
| 97 | 87 | 'cnt_seq_nr' => $cnt_seq_nr, |
| 98 | 88 | 'cnt_table' => $cnt_table, |
| 99 | 89 | 'cnt_relation' => $cnt_relation, |
| 100 | 90 | 'cnt_query' => $cnt_query, |
| 101 | - ) ) ) { | |
| 91 | + ) ); | |
| 92 | + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery | |
| 93 | + if ( 1 === $rows ) { | |
| 102 | 94 | // Return new container |
| 103 | 95 | $cnt_id = $wpdb->insert_id; |
| 104 | 96 | return array( |
| 105 | 97 | 'cnt_id' => $wpdb->insert_id, |
| @@ -122,8 +114,9 @@ | ||
| 122 | 114 | $cnt_title, |
| 123 | 115 | $cnt_relation = null |
| 124 | 116 | ) { |
| 125 | 117 | global $wpdb; |
| 118 | + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- plugin table | |
| 126 | 119 | $wpdb->update( static::get_base_table_name(), array( |
| 127 | 120 | 'cnt_dbs' => $app_dbs, |
| 128 | 121 | 'cnt_tbl' => $app_tbl, |
| 129 | 122 | 'cnt_cls' => $app_cls, |
| @@ -132,23 +125,30 @@ | ||
| 132 | 125 | ), array( |
| 133 | 126 | 'app_id' => $app_id, |
| 134 | 127 | 'cnt_id' => $app_cnt, |
| 135 | 128 | ) ); |
| 129 | + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 136 | 130 | return $wpdb->last_error; |
| 137 | 131 | } |
| 138 | 132 | |
| 139 | 133 | public static function delete( $app_id ) { |
| 140 | 134 | global $wpdb; |
| 141 | - return $wpdb->delete( static::get_base_table_name(), array( | |
| 135 | + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- plugin table | |
| 136 | + $delete = $wpdb->delete( static::get_base_table_name(), array( | |
| 142 | 137 | 'app_id' => $app_id, |
| 143 | 138 | ) ); |
| 139 | + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 140 | + return $delete; | |
| 144 | 141 | } |
| 145 | 142 | |
| 146 | 143 | public static function delete_container( $cnt_id ) { |
| 147 | 144 | global $wpdb; |
| 148 | - return $wpdb->delete( static::get_base_table_name(), array( | |
| 145 | + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- plugin table | |
| 146 | + $delete = $wpdb->delete( static::get_base_table_name(), array( | |
| 149 | 147 | 'cnt_id' => $cnt_id, |
| 150 | 148 | ) ); |
| 149 | + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 150 | + return $delete; | |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | public static function update_master( |
| 154 | 154 | $app_id, |
| @@ -157,8 +157,9 @@ | ||
| 157 | 157 | $app_cls, |
| 158 | 158 | $app_query |
| 159 | 159 | ) { |
| 160 | 160 | global $wpdb; |
| 161 | + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- plugin table | |
| 161 | 162 | $wpdb->update( static::get_base_table_name(), array( |
| 162 | 163 | 'cnt_dbs' => $app_dbs, |
| 163 | 164 | 'cnt_tbl' => $app_tbl, |
| 164 | 165 | 'cnt_cls' => $app_cls, |
| @@ -166,68 +167,81 @@ | ||
| 166 | 167 | ), array( |
| 167 | 168 | 'app_id' => $app_id, |
| 168 | 169 | 'cnt_seq_nr' => 0, |
| 169 | 170 | ) ); |
| 171 | + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 170 | 172 | return $wpdb->last_error; |
| 171 | 173 | } |
| 172 | 174 | |
| 173 | 175 | public static function update_table_settings( $cnt_id, $cnt_table_settings ) { |
| 174 | 176 | global $wpdb; |
| 177 | + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- plugin table | |
| 175 | 178 | $wpdb->update( static::get_base_table_name(), array( |
| 176 | 179 | 'cnt_table' => $cnt_table_settings, |
| 177 | 180 | ), array( |
| 178 | 181 | 'cnt_id' => $cnt_id, |
| 179 | 182 | ) ); |
| 183 | + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 180 | 184 | return $wpdb->last_error; |
| 181 | 185 | } |
| 182 | 186 | |
| 183 | 187 | public static function update_rform_settings( $cnt_id, $cnt_form_settings ) { |
| 184 | 188 | global $wpdb; |
| 189 | + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- plugin table | |
| 185 | 190 | $wpdb->update( static::get_base_table_name(), array( |
| 186 | 191 | 'cnt_rform' => $cnt_form_settings, |
| 187 | 192 | ), array( |
| 188 | 193 | 'cnt_id' => $cnt_id, |
| 189 | 194 | ) ); |
| 195 | + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 190 | 196 | return $wpdb->last_error; |
| 191 | 197 | } |
| 192 | 198 | |
| 193 | 199 | public static function update_form_settings( $cnt_id, $cnt_form_settings ) { |
| 194 | 200 | global $wpdb; |
| 201 | + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- plugin table | |
| 195 | 202 | $wpdb->update( static::get_base_table_name(), array( |
| 196 | 203 | 'cnt_form' => $cnt_form_settings, |
| 197 | 204 | ), array( |
| 198 | 205 | 'cnt_id' => $cnt_id, |
| 199 | 206 | ) ); |
| 207 | + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 200 | 208 | return $wpdb->last_error; |
| 201 | 209 | } |
| 202 | 210 | |
| 203 | 211 | public static function update_chart_settings( $cnt_id, $cnt_chart_settings ) { |
| 204 | 212 | global $wpdb; |
| 213 | + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- plugin table | |
| 205 | 214 | $wpdb->update( static::get_base_table_name(), array( |
| 206 | 215 | 'cnt_chart' => $cnt_chart_settings, |
| 207 | 216 | ), array( |
| 208 | 217 | 'cnt_id' => $cnt_id, |
| 209 | 218 | ) ); |
| 219 | + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 210 | 220 | return $wpdb->last_error; |
| 211 | 221 | } |
| 212 | 222 | |
| 213 | 223 | public static function update_dashboard_settings( $cnt_id, $cnt_dashboard_settings ) { |
| 214 | 224 | global $wpdb; |
| 225 | + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- plugin table | |
| 215 | 226 | $wpdb->update( static::get_base_table_name(), array( |
| 216 | 227 | 'cnt_dashboard' => $cnt_dashboard_settings, |
| 217 | 228 | ), array( |
| 218 | 229 | 'cnt_id' => $cnt_id, |
| 219 | 230 | ) ); |
| 231 | + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 220 | 232 | return $wpdb->last_error; |
| 221 | 233 | } |
| 222 | 234 | |
| 223 | 235 | public static function update_map_settings( $cnt_id, $cnt_map_settings ) { |
| 224 | 236 | global $wpdb; |
| 237 | + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- plugin table | |
| 225 | 238 | $wpdb->update( static::get_base_table_name(), array( |
| 226 | 239 | 'cnt_map' => $cnt_map_settings, |
| 227 | 240 | ), array( |
| 228 | 241 | 'cnt_id' => $cnt_id, |
| 229 | 242 | ) ); |
| 243 | + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 230 | 244 | return $wpdb->last_error; |
| 231 | 245 | } |
| 232 | 246 | |
| 233 | 247 | public static function container_move( $app_id, $cnt_id_from, $cnt_id_to ) { |
| @@ -236,24 +250,23 @@ | ||
| 236 | 250 | } |
| 237 | 251 | |
| 238 | 252 | public static function copy( $app_id_old, $app_id_new ) { |
| 239 | 253 | global $wpdb; |
| 254 | + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQLPlaceholders -- plugin table | |
| 240 | 255 | $containers = $wpdb->get_results( |
| 241 | - $wpdb->prepare( | |
| 242 | - 'SELECT * FROM `%1s` WHERE app_id = %d order by cnt_seq_nr', | |
| 243 | - // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders | |
| 244 | - array(WPDA::remove_backticks( self::get_base_table_name() ), $app_id_old) | |
| 245 | - ), | |
| 256 | + $wpdb->prepare( 'SELECT * FROM `%1s` WHERE app_id = %d order by cnt_seq_nr', array(WPDA::remove_backticks( self::get_base_table_name() ), $app_id_old) ), | |
| 246 | 257 | // db call ok; no-cache ok. |
| 247 | 258 | 'ARRAY_A' |
| 248 | 259 | ); |
| 249 | - // phpcs:ignore Standard.Category.SniffName.ErrorCode | |
| 260 | + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQLPlaceholders | |
| 250 | 261 | $cnt_id_conversion = array(); |
| 251 | 262 | foreach ( $containers as $container ) { |
| 252 | 263 | $cnt_id = $container['cnt_id']; |
| 253 | 264 | $container['app_id'] = $app_id_new; |
| 254 | 265 | unset($container['cnt_id']); |
| 266 | + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- plugin table | |
| 255 | 267 | $wpdb->insert( static::get_base_table_name(), $container ); |
| 268 | + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery | |
| 256 | 269 | $cnt_id_conversion[$cnt_id] = $wpdb->insert_id; |
| 257 | 270 | } |
| 258 | 271 | foreach ( $cnt_id_conversion as $cnt_id_old => $cnt_id_new ) { |
| 259 | 272 | $container = self::get_container( $app_id_new, $cnt_id_new ); |
| @@ -271,8 +284,9 @@ | ||
| 271 | 284 | } else { |
| 272 | 285 | // Master no longer available |
| 273 | 286 | $relation = null; |
| 274 | 287 | } |
| 288 | + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- plugin table | |
| 275 | 289 | $wpdb->update( static::get_base_table_name(), array( |
| 276 | 290 | 'cnt_relation' => $relation, |
| 277 | 291 | ), array( |
| 278 | 292 | 'app_id' => $app_id_new, |
| @@ -277,8 +291,9 @@ | ||
| 277 | 291 | ), array( |
| 278 | 292 | 'app_id' => $app_id_new, |
| 279 | 293 | 'cnt_id' => $cnt_id_new, |
| 280 | 294 | ) ); |
| 295 | + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 281 | 296 | } |
| 282 | 297 | } |
| 283 | 298 | } |
| 284 | 299 | } |