From 2127b1bdd73ecd2423e443992da4b442f5a3c1a3 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Wed, 04 Feb 2026 21:19:25 +0000
Subject: [PATCH] =Major overhaul of MetaManager.php -> Meta.php and RestRouteManager.php -> Rest.php. Seems to work for JakeVan

---
 inc/rest/routes/SettingsRoutes.php |   71 +++++++++++++++--------------------
 1 files changed, 30 insertions(+), 41 deletions(-)

diff --git a/inc/rest/routes/SettingsRoutes.php b/inc/rest/routes/SettingsRoutes.php
index f02fad9..f49c2bd 100644
--- a/inc/rest/routes/SettingsRoutes.php
+++ b/inc/rest/routes/SettingsRoutes.php
@@ -2,10 +2,12 @@
 namespace JVBase\rest\routes;
 
 use JVBase\JVB;
-use JVBase\rest\RestRouteManager;
-use JVBase\managers\CacheManager;
-use JVBase\meta\MetaManager;
-use JVBase\meta\MetaSanitizer;
+use JVBase\rest\PermissionHandler;
+use JVBase\rest\Rest;
+use JVBase\managers\Cache;
+use JVBase\meta\Meta;
+use JVBase\meta\Sanitizer;
+use JVBase\rest\Route;
 use WP_REST_Request;
 use WP_REST_Response;
 use WP_Error;
@@ -14,15 +16,15 @@
 if (!defined('ABSPATH')) {
     exit; // Exit if accessed directly
 }
-class SettingsRoutes extends RestRouteManager
+class SettingsRoutes extends Rest
 {
     protected int $count;
     public function __construct()
     {
-        $this->cache_name = 'user_settings';
+        $this->cacheName = 'user_settings';
         parent::__construct();
-        $this->action = 'dash-';
-        $this->operation_type = 'user_settings';
+//        $this->action = 'dash-';
+//        $this->operation_type = 'user_settings';
         $this->count = 1;
         add_filter(BASE.'handle_bulk_operation', [$this, 'processOperation'], 10, 3);
     }
@@ -33,12 +35,10 @@
      */
     public function registerRoutes():void
     {
-        register_rest_route($this->namespace, '/settings', [
-            [
-                'methods' => 'POST',
-                'callback' => [$this, 'saveSettings'],
-                'permission_callback' => [$this, 'checkPermission']
-            ]]);
+		Route::for('settings')
+			->post([$this, 'saveSettings'])
+			->auth(PermissionHandler::combine(['admin', ['actionNonce' => 'dash-']]))
+			->rateLimit(20);
     }
 
     /**
@@ -48,25 +48,18 @@
      */
     public function saveSettings(WP_REST_Request $request):WP_REST_Response
     {
-        $this->queue = JVB()->queue();
 
         $data = $request->get_params();
-
+		error_log('User: '.print_r($data['user'], true));
         error_log('Settings routes data: '.print_r($data, true));
-        $user_id = (int)$data['user'];
-        if (!$this->userCheck($user_id)) {
-            return new WP_REST_Response([
-                'success'   => false,
-                'message'   => 'Looks like you are not who you say you are. Bot?'
-            ]);
+        $user_id = absint($data['user']??0);
+        if ($user_id === 0) {
+            return $this->unauthorized();
         }
 
 
-        $operation_id = $data['id'];
-        unset($data['id']);
-
         $fields = JVB()->getFields('user');
-        $meta = new MetaSanitizer();
+        $meta = new Sanitizer();
         $add = [];
         global $types;
         foreach ($data as $name => $value) {
@@ -83,8 +76,7 @@
                 //Sanitize values
                 $data[$name] = $meta->sanitize($value, $fields[$name]);
                 if ($name === 'notify') {
-                    $cache = new CacheManager('usernames');
-                    $cache->invalidate($user_id);
+                    Cache::for('usernames')->forget($user_id);
                 }
             }
         }
@@ -92,21 +84,17 @@
             $data['notification_preferences'] = $add;
         }
 
-        $this->queue->queueOperation(
-            $this->type,
+        JVB()->queue()->queueOperation(
+            'user_settings',
             $user_id,
             $data,
             [
                 'count'   => 1,
-                'operation_id'      => $operation_id
             ]
         );
 
-        // Return standardized response
-        return new WP_REST_Response([
-            'success' =>true,
+        return $this->success([
             'message' => 'Request received and queued',
-            'operation_id' => $operation_id,
             'status' => 'queued'
         ]);
     }
@@ -126,9 +114,9 @@
 
 
         $user_id = $operation->user_id;
-        $meta = new MetaManager($user_id, 'user');
+        $meta = Meta::forUser($user_id);
         $results = [];
-		$tempMeta = new MetaManager(null, 'options');
+		$tempMeta = Meta::forOptions('options');
         foreach ($data as $name => $value) {
             if ($name == 'notification_preferences') {
                 return $this->saveNotificationPreferences($user_id, $value);
@@ -148,13 +136,13 @@
 
             if ($name !== 'digest_override') { // digest_override should always reset to 'off'
 				if(array_key_exists($name, JVB_OPTIONS)) {
-					$results[] = $tempMeta->updateValue($name, $value);
+					$results[] = $tempMeta->set($name, $value);
 				} else {
-					$results[] = $meta->updateValue($name, $value);
+					$results[] = $meta->set($name, $value);
 				}
 
             }
-            CacheManager::invalidateGroup($this->cache_name);
+            $this->cache->flush();
         }
         return [
             'success'   => true,
@@ -170,6 +158,7 @@
      */
     protected function saveNotificationPreferences(int $user_id, array $data):array|WP_Error
     {
+		//TODO: This should be in with Notifications.php manager
         //TODO: Check what cache we are using to store user's preferences for the daily/weekly/monthly sendouts
         global $wpdb;
         $table = $wpdb->prefix . BASE . 'notification_preferences';
@@ -223,7 +212,7 @@
             // Success - commit transaction
             $wpdb->query('COMMIT');
 
-            CacheManager::invalidateGroup($this->cache_name);
+            $this->cache->flush();
             return [
                 'success' => true,
                 'result' => 'Notification preferences updated successfully'

--
Gitblit v1.10.0