diff --git a/src/elements/Category.php b/src/elements/Category.php index c0631e5f..4e126be7 100644 --- a/src/elements/Category.php +++ b/src/elements/Category.php @@ -132,7 +132,7 @@ public function afterSave($data, $settings): void * @throws ElementNotFoundException * @throws Exception */ - protected function parseParent($feedData, $fieldInfo): ?int + protected function parseParentId($feedData, $fieldInfo): ?int { $value = $this->fetchSimpleValue($feedData, $fieldInfo); $default = DataHelper::fetchDefaultArrayValue($fieldInfo); diff --git a/src/elements/Entry.php b/src/elements/Entry.php index 4463fe58..1905d8d6 100644 --- a/src/elements/Entry.php +++ b/src/elements/Entry.php @@ -224,7 +224,7 @@ protected function parseExpiryDate($feedData, $fieldInfo): DateTime|bool|array|C * @throws ElementNotFoundException * @throws Exception */ - protected function parseParent($feedData, $fieldInfo): ?int + protected function parseParentId($feedData, $fieldInfo): ?int { $value = $this->fetchSimpleValue($feedData, $fieldInfo); $default = DataHelper::fetchDefaultArrayValue($fieldInfo); diff --git a/src/migrations/m231025_081246_rename_parent_to_parentid_for_feedme_imports.php b/src/migrations/m231025_081246_rename_parent_to_parentid_for_feedme_imports.php new file mode 100644 index 00000000..61d0e854 --- /dev/null +++ b/src/migrations/m231025_081246_rename_parent_to_parentid_for_feedme_imports.php @@ -0,0 +1,70 @@ +select(['id', 'fieldMapping']) + ->from('{{%feedme_feeds}}') + ->all(); + + foreach ($rows as $row) { + $fieldMapping = \json_decode($row['fieldMapping']); + + // Rename the `parent` argument into `parentId` if it exists + if (isset($fieldMapping->parent)) { + $fieldMapping->parentId = $fieldMapping->parent; + unset($fieldMapping->parent); + + $this->update( + '{{%feedme_feeds}}', + ['fieldMapping' => \json_encode($fieldMapping)], + ['id' => $row['id']] + ); + } + } + + return true; + } + + /** + * @inheritdoc + */ + public function safeDown() + { + $rows = (new Query()) + ->select(['id', 'fieldMapping']) + ->from('{{%feedme_feeds}}') + ->all(); + + foreach ($rows as $row) { + $fieldMapping = \json_decode($row['fieldMapping']); + + // Rename the `parentId` argument back into `parent` if it exists + if (isset($fieldMapping->parentId)) { + $fieldMapping->parent = $fieldMapping->parentId; + unset($fieldMapping->parentId); + + $this->update( + '{{%feedme_feeds}}', + ['fieldMapping' => \json_encode($fieldMapping)], + ['id' => $row['id']] + ); + } + } + + return true; + } +} diff --git a/src/templates/_includes/elements/categories/map.html b/src/templates/_includes/elements/categories/map.html index 60d40800..45479715 100644 --- a/src/templates/_includes/elements/categories/map.html +++ b/src/templates/_includes/elements/categories/map.html @@ -23,7 +23,7 @@ }, { type: 'categories', name: 'Parent', - handle: 'parent', + handle: 'parentId', instructions: 'Select a parent category to import these categories under.'|t('feed-me'), default: { type: 'elementselect', diff --git a/src/templates/_includes/elements/entries/map.html b/src/templates/_includes/elements/entries/map.html index cb7cd06a..1b77c59b 100644 --- a/src/templates/_includes/elements/entries/map.html +++ b/src/templates/_includes/elements/entries/map.html @@ -30,7 +30,7 @@ {% set fields = fields|push({ type: 'entries', name: 'Parent', - handle: 'parent', + handle: 'parentId', instructions: 'Select a parent entry to import these entries under.'|t('feed-me'), default: { type: 'elementselect',