where('operation', self::OPERATION_PREFIX . $serviceId) ->orderBy('id', 'desc') ->first(); if ($row === null || empty($row->metadata)) { return []; } $decoded = json_decode((string) $row->metadata, true); return is_array($decoded) ? $decoded : []; } catch (Throwable) { return []; } } public static function save(string $serviceId, array $data): void { $payload = json_encode($data, JSON_THROW_ON_ERROR); try { $existing = Capsule::table('mod_hexagamecloud_operations') ->where('operation', self::OPERATION_PREFIX . $serviceId) ->orderBy('id', 'desc') ->first(); if ($existing !== null) { Capsule::table('mod_hexagamecloud_operations') ->where('id', $existing->id) ->update([ 'metadata' => $payload, 'status' => 'saved', ]); return; } Capsule::table('mod_hexagamecloud_operations')->insert([ 'operation' => self::OPERATION_PREFIX . $serviceId, 'status' => 'saved', 'metadata' => $payload, 'created_at' => gmdate('Y-m-d H:i:s'), ]); } catch (Throwable $exception) { logActivity('HexaGameCloud admin metadata save failed: ' . $exception->getMessage()); } } }