| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | <?php |
| 2 | - | |
| 2 | +// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared | |
| 3 | 3 | if (!defined('ABSPATH')) exit; |
| 4 | 4 | if (!class_exists('WPRWPDb')) : |
| 5 | 5 | |
| 6 | 6 | class WPRWPDb { |
| @@ -39,8 +39,23 @@ | ||
| 39 | 39 | global $wpdb; |
| 40 | 40 | return $wpdb->get_col($query, $col); |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | + public function getLastRowId($col_name, $table_name) { | |
| 44 | + $query = "SELECT MAX($col_name) AS last_id FROM $table_name"; | |
| 45 | + $results = $this->getResult($query); | |
| 46 | + if (empty($results) || !is_array($results) || !is_array($results[0]) || | |
| 47 | + !array_key_exists("last_id", $results[0])) { | |
| 48 | + return null; | |
| 49 | + } | |
| 50 | + $last_id = $results[0]['last_id']; | |
| 51 | + if ($last_id === null) { | |
| 52 | + return 0; | |
| 53 | + } else if (is_numeric($last_id) === true) { | |
| 54 | + return (int) $last_id; | |
| 55 | + } | |
| 56 | + } | |
| 57 | + | |
| 43 | 58 | public function tableName($table) { |
| 44 | 59 | return $table[0]; |
| 45 | 60 | } |
| 46 | 61 | |
| @@ -69,9 +84,9 @@ | ||
| 69 | 84 | |
| 70 | 85 | public function describeTable($table) { |
| 71 | 86 | return $this->getResult("DESCRIBE $table;"); |
| 72 | 87 | } |
| 73 | - | |
| 88 | + | |
| 74 | 89 | public function showTableIndex($table) { |
| 75 | 90 | return $this->getResult("SHOW INDEX FROM $table"); |
| 76 | 91 | } |
| 77 | 92 | |
| @@ -96,9 +111,9 @@ | ||
| 96 | 111 | $table = $this->getBVTable($name); |
| 97 | 112 | if (!$this->isTablePresent($table)) { |
| 98 | 113 | if ($usedbdelta) { |
| 99 | 114 | if (!function_exists('dbDelta')) |
| 100 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); | |
| 115 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); | |
| 101 | 116 | dbDelta($query); |
| 102 | 117 | } else { |
| 103 | 118 | $this->query($query); |
| 104 | 119 | } |
| @@ -165,9 +180,9 @@ | ||
| 165 | 180 | } else { |
| 166 | 181 | return false; |
| 167 | 182 | } |
| 168 | 183 | } |
| 169 | - | |
| 184 | + | |
| 170 | 185 | public function deleteBVTableContent($name, $filter = "") { |
| 171 | 186 | $table = $this->getBVTable($name); |
| 172 | 187 | if ($this->isTablePresent($table)) { |
| 173 | 188 | return $this->query("DELETE FROM $table $filter;"); |
| @@ -213,9 +228,15 @@ | ||
| 213 | 228 | global $wpdb; |
| 214 | 229 | $table = $this->getBVTable($name); |
| 215 | 230 | return $wpdb->replace($table, $value); |
| 216 | 231 | } |
| 217 | - | |
| 232 | + | |
| 233 | + public function insertIntoBVTable($name, $value) { | |
| 234 | + global $wpdb; | |
| 235 | + $table = $this->getBVTable($name); | |
| 236 | + return $wpdb->insert($table, $value); | |
| 237 | + } | |
| 238 | + | |
| 218 | 239 | public function tinfo($name) { |
| 219 | 240 | $result = array(); |
| 220 | 241 | $table = $this->getBVTable($name); |
| 221 | 242 | |