Skip to content

Commit

Permalink
ensure block namespaces, import block group closes #1431
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar committed Sep 3, 2017
1 parent 78a9729 commit 30e0cb2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
17 changes: 12 additions & 5 deletions modules/cms/src/admin/importers/BlockImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public function run()
*/
protected function saveBlock($fullClassName)
{
// ensure all classes start with trailing slash class name definition like `\foo\bar\Class`
$fullClassName = '\\' . ltrim($fullClassName, '\\');
$model = Block::find()->where(['class' => $fullClassName])->one();

$blockObject = $this->createBlockObject($fullClassName);
Expand Down Expand Up @@ -112,15 +114,20 @@ protected function getBlockGroupId(BlockInterface $blockObject)
{
$groupClassName = $blockObject->blockGroup();

$identifier = Yii::createObject(['class' => $groupClassName])->identifier();

$group = BlockGroup::findOne(['identifier' => $identifier]);

// @TODO if not found, add group to database
$groupObject = Yii::createObject(['class' => $groupClassName]);

$group = BlockGroup::findOne(['identifier' => $groupObject->identifier()]);

if ($group) {
return $group->id;
} else {
$model = new BlockGroup();
$model->name = $groupObject->label();
$model->identifier = $groupObject->identifier();
$model->created_timestamp = time();
if ($model->save()) {
return $model->id;
}
}

return 0;
Expand Down
8 changes: 0 additions & 8 deletions modules/cms/src/models/BlockGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,4 @@ public function rules()
['identifier', 'unique'],
];
}

public function scenarios()
{
return [
'restcreate' => ['name', 'identifier'],
'restupdate' => ['name', 'identifier'],
];
}
}

0 comments on commit 30e0cb2

Please sign in to comment.