From a6413da67a4579866f0fd0323ddb23a7b6b9654a Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Fri, 18 Sep 2026 17:00:53 +0000
Subject: [PATCH] =Cleaning up the Integrations setup a bit, started the Helcim integration work too

---
 inc/managers/CustomTable.php |   31 ++++++++-----------------------
 1 files changed, 8 insertions(+), 23 deletions(-)

diff --git a/inc/managers/CustomTable.php b/inc/managers/CustomTable.php
index d86a631..3bb0114 100644
--- a/inc/managers/CustomTable.php
+++ b/inc/managers/CustomTable.php
@@ -2,6 +2,7 @@
 namespace JVBase\managers;
 
 use Exception;
+use JVBase\inc\managers\ErrorHelper;
 use wpdb;
 
 if (!defined('ABSPATH')) {
@@ -20,7 +21,7 @@
  */
 class CustomTable
 {
-
+	use ErrorHelper;
 	private static ?wpdb $wpdb = null;
 	private static string $prefix;
 	protected string $tableName;
@@ -507,7 +508,7 @@
 		);
 
 		if ($result === false) {
-			$this->logError('insert', $data);
+			$this->logError(self::$wpdb->last_error, 'insert', $data);
 			return false;
 		}
 
@@ -608,7 +609,7 @@
 		$result = self::$wpdb->query(self::$wpdb->prepare($query, $values));
 
 		if ($result === false) {
-			$this->logError('bulkInsert', ['rows' => count($rows)]);
+			$this->logError(self::$wpdb->last_error, 'bulkInsert', ['rows' => count($rows)]);
 			return false;
 		}
 
@@ -755,7 +756,7 @@
 			$key,
 			function() use ($column, $where, $orderby, $order, $limit) {
 				if (!empty($this->columns) && !array_key_exists($column, $this->columns)) {
-					$this->logError('pluck', ['reason' => "Column '{$column}' not in definition"]);
+					$this->logError("Column '{$column}' not in definition", 'pluck');
 					return [];
 				}
 				$args = ['where' => $where];
@@ -851,7 +852,7 @@
 		);
 
 		if ($result === false) {
-			$this->logError('update', ['data' => $data, 'where' => $where]);
+			$this->logError(self::$wpdb->last_error,'update', ['data' => $data, 'where' => $where]);
 		}
 		$this->cache->flush();
 
@@ -881,7 +882,7 @@
 		);
 
 		if ($result === false) {
-			$this->logError('delete', ['where' => $where]);
+			$this->logError(self::$wpdb->last_error, 'delete', ['where' => $where]);
 		}
 		$this->cache->flush();
 
@@ -1005,7 +1006,7 @@
 			return $result;
 		} catch (Exception $e) {
 			$this->rollback();
-			$this->logError('transaction', ['error' => $e->getMessage()]);
+			$this->logError(self::$wpdb->last_error,'transaction', ['error' => $e->getMessage()]);
 			return false;
 		}
 	}
@@ -1192,22 +1193,6 @@
 		return isset($cache[$this->tableName][$column]);
 	}
 
-	/**
-	 * Log database errors
-	 */
-	private function logError(string $operation, array $context = []): void
-	{
-		if (function_exists('JVB')) {
-			Errors::getInstance()->log(
-				$this->tableName,
-				"CustomTable {$operation} failed: " . self::$wpdb->last_error,
-				$context
-			);
-		} else {
-			error_log("[CustomTable:{$this->tableName}] {$operation} failed: " . self::$wpdb->last_error);
-		}
-	}
-
 	public function sum(string $column, array $where):float
 	{
 		$rows = $this->pluck($column, $where);

--
Gitblit v1.10.0