Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent PHP warning when CacheEntry extension keys are not set #39906

Merged
merged 2 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/private/Files/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function getNumericStorageId() {
* 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();
Expand Down
6 changes: 3 additions & 3 deletions lib/private/Files/Cache/CacheEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ public function isEncrypted() {
}

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() {
Expand Down
25 changes: 25 additions & 0 deletions tests/lib/Files/Cache/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,31 @@ public function testSimple() {
$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';

Expand Down