Added getRevision() helper function, refactored revision constant

This commit is contained in:
2026-05-15 14:06:15 +00:00
parent 06df8b0be1
commit d5d766cbf4
3 changed files with 24 additions and 6 deletions

View File

@@ -157,6 +157,13 @@ class CloudObject {
}
return $this->retriever->getObjectNode($coid);
}
}
/**
* Get the revision of the object.
*/
public function getRevision() : string {
return $this->getString(Constants::PROPERTY_REVISION);
}
}

View File

@@ -0,0 +1,13 @@
<?php
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
namespace CloudObjects\SDK;
class Constants {
const PROPERTY_REVISION = 'coid://cloudobjects.io/isAtRevision';
}

View File

@@ -32,9 +32,7 @@ class ObjectRetriever implements CustomCacheAndLogInterface {
private $defaultReader;
const CO_API_URL = 'https://od.coid.link/';
const REVISION_PROPERTY = 'coid://cloudobjects.io/isAtRevision';
public function __construct($options = []) {
// Merge options with defaults
$this->options = array_merge([
@@ -479,7 +477,7 @@ class ObjectRetriever implements CustomCacheAndLogInterface {
}
if (!isset($fileData)
|| $fileRevision!=$object->getProperty(self::REVISION_PROPERTY)->getValue()) {
|| $fileRevision !== $object->getProperty(Constants::PROPERTY_REVISION)->getValue()) {
// Does not exist in cache or is outdated, fetch from CloudObjects
try {
@@ -487,7 +485,7 @@ class ObjectRetriever implements CustomCacheAndLogInterface {
.'/'.basename($filename));
$fileContent = $response->getBody()->getContents();
$fileData = $object->getProperty(self::REVISION_PROPERTY)->getValue().'#'.$fileContent;
$fileData = $object->getProperty(Constants::PROPERTY_REVISION)->getValue().'#'.$fileContent;
$this->putIntoCache($cacheId, $fileData, 0);
$this->logInfoWithTime('Fetched attachment <'.$filename.'> for <'.$object->getId().'> from Core API ['.$response->getStatusCode().'].', $ts);