diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2023-08-17 15:59:41 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-17 15:59:41 +0200 |
commit | 362acd93aaffdb1271c8d5356cd2d6ea4ffaf9e1 (patch) | |
tree | 4255dd0193616f917f0d9325000bb71a0338e212 | |
parent | c3108e52fe08a438fe7836a8e340428f897b8171 (diff) | |
parent | 752523f874cdb63f8488f90889f650df35eca1ea (diff) | |
download | nextcloud-server-362acd93aaffdb1271c8d5356cd2d6ea4ffaf9e1.tar.gz nextcloud-server-362acd93aaffdb1271c8d5356cd2d6ea4ffaf9e1.zip |
Merge pull request #39930 from nextcloud/backport/39906/stable27
[stable27] Prevent PHP warning when CacheEntry extension keys are not set
-rw-r--r-- | lib/private/Files/Cache/Cache.php | 2 | ||||
-rw-r--r-- | lib/private/Files/Cache/CacheEntry.php | 6 | ||||
-rw-r--r-- | tests/lib/Files/Cache/CacheTest.php | 25 |
3 files changed, 29 insertions, 4 deletions
diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index 76b2fa942cc..949729925b5 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -149,7 +149,7 @@ class Cache implements ICache { * get the stored metadata of a file or folder * * @param string | int $file either the path of a file or folder or the file id for a file or folder - * @return ICacheEntry|false the cache entry as array of false if the file is not found in the cache + * @return ICacheEntry|false the cache entry as array or false if the file is not found in the cache */ public function get($file) { $query = $this->getQueryBuilder(); diff --git a/lib/private/Files/Cache/CacheEntry.php b/lib/private/Files/Cache/CacheEntry.php index 3c93296ff62..ce9df2823c8 100644 --- a/lib/private/Files/Cache/CacheEntry.php +++ b/lib/private/Files/Cache/CacheEntry.php @@ -114,15 +114,15 @@ class CacheEntry implements ICacheEntry { } public function getMetadataEtag(): ?string { - return $this->data['metadata_etag']; + return $this->data['metadata_etag'] ?? null; } public function getCreationTime(): ?int { - return $this->data['creation_time']; + return $this->data['creation_time'] ?? null; } public function getUploadTime(): ?int { - return $this->data['upload_time']; + return $this->data['upload_time'] ?? null; } public function getData() { diff --git a/tests/lib/Files/Cache/CacheTest.php b/tests/lib/Files/Cache/CacheTest.php index 7f8e1af1577..97be67e06f6 100644 --- a/tests/lib/Files/Cache/CacheTest.php +++ b/tests/lib/Files/Cache/CacheTest.php @@ -97,6 +97,31 @@ class CacheTest extends \Test\TestCase { $this->assertEquals($cacheData1, $this->cache->get($id1)); } + public function testCacheEntryGetters() { + $file1 = 'foo'; + $data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/file']; + + $id1 = $this->cache->put($file1, $data1); + $entry = $this->cache->get($file1); + + $this->assertEquals($entry->getId(), $id1); + $this->assertEquals($entry->getStorageId(), $this->cache->getNumericStorageId()); + $this->assertEquals($entry->getPath(), 'foo'); + $this->assertEquals($entry->getName(), 'foo'); + $this->assertEquals($entry->getMimeType(), 'foo/file'); + $this->assertEquals($entry->getMimePart(), 'foo'); + $this->assertEquals($entry->getSize(), 100); + $this->assertEquals($entry->getMTime(), 50); + $this->assertEquals($entry->getStorageMTime(), 50); + $this->assertEquals($entry->getEtag(), null); + $this->assertEquals($entry->getPermissions(), 0); + $this->assertEquals($entry->isEncrypted(), false); + $this->assertEquals($entry->getMetadataEtag(), null); + $this->assertEquals($entry->getCreationTime(), null); + $this->assertEquals($entry->getUploadTime(), null); + $this->assertEquals($entry->getUnencryptedSize(), 100); + } + public function testPartial() { $file1 = 'foo'; |