Added getRevision() helper function, refactored revision constant
This commit is contained in:
@@ -159,4 +159,11 @@ class CloudObject {
|
||||
return $this->retriever->getObjectNode($coid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the revision of the object.
|
||||
*/
|
||||
public function getRevision() : string {
|
||||
return $this->getString(Constants::PROPERTY_REVISION);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
13
CloudObjects/SDK/Constants.php
Normal file
13
CloudObjects/SDK/Constants.php
Normal 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';
|
||||
|
||||
}
|
||||
@@ -33,8 +33,6 @@ class ObjectRetriever implements CustomCacheAndLogInterface {
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user