aboutsummaryrefslogtreecommitdiffhomepage
path: root/Digitigrade
diff options
context:
space:
mode:
authorwinter2024-12-17 15:42:44 +0000
committerwinter2024-12-17 15:42:44 +0000
commitbc2cd99b108b8755a648c3915714e7c0e0771548 (patch)
tree3e762a283176c5e0c881bdd46eba3e38eab86a5a /Digitigrade
parent8cbb7f7c632961f615f9b5f9bd51984b9a929340 (diff)
send auth header when fetching objects (untested again)
Diffstat (limited to 'Digitigrade')
-rw-r--r--Digitigrade/Model.php4
-rw-r--r--Digitigrade/Model/FetchableModel.php5
2 files changed, 6 insertions, 3 deletions
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);