Skip to content

Commit 1406eec

Browse files
authored
Merge pull request nextcloud#39906 from nextcloud/fix/prevent-warnings-if-attr-unset
Prevent PHP warning when CacheEntry extension keys are not set
2 parents daf3b29 + 9c04c07 commit 1406eec

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

lib/private/Files/Cache/Cache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function getNumericStorageId() {
149149
* get the stored metadata of a file or folder
150150
*
151151
* @param string | int $file either the path of a file or folder or the file id for a file or folder
152-
* @return ICacheEntry|false the cache entry as array of false if the file is not found in the cache
152+
* @return ICacheEntry|false the cache entry as array or false if the file is not found in the cache
153153
*/
154154
public function get($file) {
155155
$query = $this->getQueryBuilder();

lib/private/Files/Cache/CacheEntry.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,15 @@ public function isEncrypted() {
114114
}
115115

116116
public function getMetadataEtag(): ?string {
117-
return $this->data['metadata_etag'];
117+
return $this->data['metadata_etag'] ?? null;
118118
}
119119

120120
public function getCreationTime(): ?int {
121-
return $this->data['creation_time'];
121+
return $this->data['creation_time'] ?? null;
122122
}
123123

124124
public function getUploadTime(): ?int {
125-
return $this->data['upload_time'];
125+
return $this->data['upload_time'] ?? null;
126126
}
127127

128128
public function getData() {

tests/lib/Files/Cache/CacheTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,31 @@ public function testSimple() {
9898
$this->assertEquals($cacheData1, $this->cache->get($id1));
9999
}
100100

101+
public function testCacheEntryGetters() {
102+
$file1 = 'foo';
103+
$data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/file'];
104+
105+
$id1 = $this->cache->put($file1, $data1);
106+
$entry = $this->cache->get($file1);
107+
108+
$this->assertEquals($entry->getId(), $id1);
109+
$this->assertEquals($entry->getStorageId(), $this->cache->getNumericStorageId());
110+
$this->assertEquals($entry->getPath(), 'foo');
111+
$this->assertEquals($entry->getName(), 'foo');
112+
$this->assertEquals($entry->getMimeType(), 'foo/file');
113+
$this->assertEquals($entry->getMimePart(), 'foo');
114+
$this->assertEquals($entry->getSize(), 100);
115+
$this->assertEquals($entry->getMTime(), 50);
116+
$this->assertEquals($entry->getStorageMTime(), 50);
117+
$this->assertEquals($entry->getEtag(), null);
118+
$this->assertEquals($entry->getPermissions(), 0);
119+
$this->assertEquals($entry->isEncrypted(), false);
120+
$this->assertEquals($entry->getMetadataEtag(), null);
121+
$this->assertEquals($entry->getCreationTime(), null);
122+
$this->assertEquals($entry->getUploadTime(), null);
123+
$this->assertEquals($entry->getUnencryptedSize(), 100);
124+
}
125+
101126
public function testPartial() {
102127
$file1 = 'foo';
103128

0 commit comments

Comments
 (0)