From bc2cd99b108b8755a648c3915714e7c0e0771548 Mon Sep 17 00:00:00 2001 From: winter Date: Tue, 17 Dec 2024 15:42:44 +0000 Subject: send auth header when fetching objects (untested again) --- Digitigrade/Model.php | 4 ++++ Digitigrade/Model/FetchableModel.php | 5 ++--- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'Digitigrade') diff --git a/Digitigrade/Model.php b/Digitigrade/Model.php index b5c9e99..a065154 100644 --- a/Digitigrade/Model.php +++ b/Digitigrade/Model.php @@ -71,6 +71,10 @@ abstract class Model { } elseif (is_array($value)) { // arrays ought to be handled separately when saving (different db table) $discarded = true; + } elseif ($value == null && $pName == 'id') { + // don't overwrite an existing primary key with null .. + // this is kinda janky but it hopefully will work + $discarded = true; } if (!$discarded) $result[self::mangleName($pName)] = $value; diff --git a/Digitigrade/Model/FetchableModel.php b/Digitigrade/Model/FetchableModel.php index e091a87..bd25d39 100644 --- a/Digitigrade/Model/FetchableModel.php +++ b/Digitigrade/Model/FetchableModel.php @@ -15,9 +15,8 @@ abstract class FetchableModel extends Model implements RemoteFetchable { protected static function fetchFromRemote(string $uri, bool $autoSave): ?static { // fetch the object - $data = @file_get_contents($uri, context: stream_context_create(['http' => [ - 'header' => 'Accept: application/json' - ]])); + // janky hack: if this is an Instance then avoid recursively fetching itself + $data = @get_remote_object_authenticated($uri, static::class == Instance::class); if ($data === false) return null; $data = json_decode($data); -- cgit v1.3