public function import(array $groupDefinitions, $force = false)
{
Craft::log(Craft::t('Importing Fields'));
if (!empty($groupDefinitions)) {
$contentService = $this->getContentService();
$contentService->fieldContext = 'global';
$contentService->contentTable = 'content';
$this->resetCraftFieldsServiceGroupsCache();
$this->groups = $this->getFieldsService()->getAllGroups('name');
$this->fields = $this->getFieldsService()->getAllFields('handle');
foreach ($groupDefinitions as $name => $fieldDefinitions) {
try {
$this->beginTransaction();
$group = $this->createFieldGroupModel($name);
$this->importFields($fieldDefinitions, $group);
$this->commitTransaction();
} catch (\Exception $e) {
$this->rollbackTransaction();
$this->addError($e->getMessage());
}
$this->unsetData($name, $fieldDefinitions);
}
if ($force) {
// Remove not imported data
$this->deleteFieldsAndGroups();
}
$this->resetCraftFieldsServiceFieldsCache();
}
return $this->getResultModel();
}