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

Rename mapping from parent to parentId #1313

Open
wants to merge 1 commit into
base: 5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/elements/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/elements/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace craft\feedme\migrations;

use craft\db\Migration;
use craft\db\Query;

/**
* m231025_081246_rename_parent_to_parentid_for_feedme_imports migration.
*/
class m231025_081246_rename_parent_to_parentid_for_feedme_imports extends Migration
{
/**
* @inheritdoc
*/
public function safeUp()
{
$rows = (new Query())
->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;
}
}
2 changes: 1 addition & 1 deletion src/templates/_includes/elements/categories/map.html
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion src/templates/_includes/elements/entries/map.html
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading