-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename mapping from parent to parentId
The attribute `parentId` is used in Craft to signify the value of the parent element, if any. Therefore, the mapping handle should also be `parentId`. This patch changes the mapping handle from `parent` into `parentId`. This allows the comparison code to properly verify that an existing parent already exists. Without this patch the current comparison will use the `parent` property that does not exist in a Craft entry. This should have been `parentId` which does exist.
- Loading branch information
1 parent
eaac8e3
commit e74d28f
Showing
5 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/migrations/m231025_081246_rename_parent_to_parentid_for_feedme_imports.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters