Skip to content
This repository was archived by the owner on Jan 10, 2022. It is now read-only.

Commit cca40e0

Browse files
committed
Fixed Manager::getMetaData() produces E_WARNING for the item, which is not present at source storage
1 parent ed514df commit cca40e0

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Yii 2 Content Management extension Change Log
44
1.0.1 under development
55
-----------------------
66

7+
- Bug #1: Fixed `Manager::getMetaData()` produces E_WARNING for the item, which is not present at source storage (klimov-paul)
78
- Enh: Usage of deprecated `yii\base\InvalidParamException` replaced by `yii\base\InvalidArgumentException` (klimov-paul)
89

910

src/Manager.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,19 @@ public function getMetaData($id)
228228
if (empty($this->metaDataContentParts)) {
229229
return [];
230230
}
231+
231232
$data = $this->getSourceStorage()->find($id);
233+
if ($data === null) {
234+
return [];
235+
}
236+
232237
$metaData = [];
233238
foreach ($data as $key => $value) {
234239
if (in_array($key, $this->metaDataContentParts, true)) {
235240
$metaData[$key] = $value;
236241
}
237242
}
243+
238244
return $metaData;
239245
}
240246

tests/ManagerTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,5 +170,10 @@ public function testMetaData()
170170
$this->assertFalse($items['item1']->has('body'));
171171

172172
$this->assertEquals(['body' => 'Item 1 Body'], $manager->getMetaData('item1'));
173+
174+
$manager->save('new-item', [
175+
'title' => 'new item'
176+
]);
177+
$this->assertEquals([], $manager->getMetaData('new-item'));
173178
}
174179
}

0 commit comments

Comments
 (0)