| | |
| | | */ |
| | | 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)) { |
| | |
| | | ]); |
| | | } |
| | | |
| | | $this->queue = JVB()->queue(); |
| | | |
| | | $operation_id = $data['id']; |
| | | unset($data['id']); |
| | | |
| | | $fields = JVB()->getFields('user'); |
| | | $meta = new MetaSanitizer(); |
| | |
| | | //Sanitize values |
| | | $data[$name] = $meta->sanitize($value, $fields[$name]); |
| | | if ($name === 'notify') { |
| | | $cache = new CacheManager('usernames'); |
| | | $cache->invalidate($user_id); |
| | | CacheManager::for('usernames')->delete($user_id); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | $this->queue->queueOperation( |
| | | $this->type, |
| | | 'user_settings', |
| | | $user_id, |
| | | $data, |
| | | [ |
| | | 'count' => 1, |
| | | 'operation_id' => $operation_id |
| | | ] |
| | | ); |
| | | |
| | |
| | | return new WP_REST_Response([ |
| | | 'success' =>true, |
| | | 'message' => 'Request received and queued', |
| | | 'operation_id' => $operation_id, |
| | | 'status' => 'queued' |
| | | ]); |
| | | } |
| | |
| | | } |
| | | |
| | | } |
| | | CacheManager::invalidateGroup($this->cache_name); |
| | | CacheManager::for($this->cache_name)->invalidate(); |
| | | } |
| | | return [ |
| | | 'success' => true, |
| | |
| | | // Success - commit transaction |
| | | $wpdb->query('COMMIT'); |
| | | |
| | | CacheManager::invalidateGroup($this->cache_name); |
| | | CacheManager::for($this->cache_name)->invalidate(); |
| | | return [ |
| | | 'success' => true, |
| | | 'result' => 'Notification preferences updated successfully' |