Skip to content

Commit

Permalink
Merge branch 'release/5.1.3' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Apr 28, 2023
2 parents 540c335 + fb4d5ee commit fd8d065
Show file tree
Hide file tree
Showing 19 changed files with 496 additions and 1,570 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Create Release
run-name: Create release for ${{ github.event.client_payload.version }}

on:
repository_dispatch:
types:
- craftcms/new-release

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: ncipollo/release-action@v1
with:
body: ${{ github.event.client_payload.notes }}
makeLatest: ${{ github.event.client_payload.latest }}
name: ${{ github.event.client_payload.version }}
prerelease: ${{ github.event.client_payload.prerelease }}
tag: ${{ github.event.client_payload.tag }}
1,427 changes: 20 additions & 1,407 deletions CHANGELOG.md

Large diffs are not rendered by default.

281 changes: 164 additions & 117 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static function config(): array
];
}

public string $minVersionRequired = '4.4.0';
public string $minVersionRequired = '4.4.8';
public string $schemaVersion = '5.1.0.0';
public bool $hasCpSettings = true;
public bool $hasCpSection = true;
Expand Down
4 changes: 4 additions & 0 deletions src/base/DataType.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace craft\feedme\base;

use Cake\Utility\Hash;
use Craft;
use craft\base\Component;
use craft\helpers\UrlHelper;

Expand Down Expand Up @@ -47,6 +48,9 @@ public function setupPaginationUrl($array, $feed): void
$flatten = Hash::flatten($array, '/');
$url = Hash::get($flatten, $feed->paginationNode);

// resolve any aliases in the pagination URL
$url = Craft::getAlias($url);

// if the feed provides a root relative URL, make it whole again based on the feed.
if ($url && UrlHelper::isRootRelativeUrl($url)) {
$url = UrlHelper::hostInfo($feed->feedUrl) . $url;
Expand Down
12 changes: 9 additions & 3 deletions src/elements/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,11 @@ public function afterSave($data, $settings): void
$parent = Hash::get($data, 'parent');

if ($parent && $parent !== $this->element->id) {
$parentCategory = CategoryElement::findOne(['id' => $parent]);
$parentCategory = CategoryElement::find()->status(null)->id($parent)->one();

Craft::$app->getStructures()->append($this->element->group->structureId, $this->element, $parentCategory);
if ($parentCategory) {
Craft::$app->getStructures()->append($this->element->group->structureId, $this->element, $parentCategory);
}
}
}

Expand Down Expand Up @@ -144,10 +146,14 @@ protected function parseParent($feedData, $fieldInfo): ?int
return null;
}

if ($node === 'usedefault') {
if ($node === 'usedefault' || $value === $default) {
$match = 'elements.id';
}

if (is_array($value)) {
$value = $value[0];
}

$query = CategoryElement::find()
->status(null)
->andWhere(['=', $match, $value]);
Expand Down
69 changes: 62 additions & 7 deletions src/elements/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use craft\feedme\helpers\DataHelper;
use craft\feedme\models\ElementGroup;
use craft\feedme\Plugin;
use craft\helpers\ElementHelper;
use craft\helpers\Json;
use craft\models\Section;
use DateTime;
Expand Down Expand Up @@ -96,11 +97,24 @@ public function getGroups(): array
*/
public function getQuery($settings, array $params = []): mixed
{
$targetSiteId = Hash::get($settings, 'siteId') ?: Craft::$app->getSites()->getPrimarySite()->id;
if ($this->element !== null) {
$section = $this->element->getSection();
}

$query = EntryElement::find()
->status(null)
->sectionId($settings['elementGroup'][EntryElement::class]['section'])
->typeId($settings['elementGroup'][EntryElement::class]['entryType'])
->siteId(Hash::get($settings, 'siteId') ?: Craft::$app->getSites()->getPrimarySite()->id);
->typeId($settings['elementGroup'][EntryElement::class]['entryType']);

if (isset($section) && $section->propagationMethod === Section::PROPAGATION_METHOD_CUSTOM) {
$query->site('*')
->preferSites([$targetSiteId])
->unique();
} else {
$query->siteId($targetSiteId);
}

Craft::configure($query, $params);
return $query;
}
Expand Down Expand Up @@ -136,6 +150,41 @@ public function setModel($settings): ElementInterface
return $this->element;
}

/**
* Checks if $existingElement should be propagated to the target site.
*
* @param $existingElement
* @param array $feed
* @return ElementInterface|null
* @throws Exception
* @throws \craft\errors\SiteNotFoundException
* @throws \craft\errors\UnsupportedSiteException
* @since 5.1.3
*/
public function checkPropagation($existingElement, array $feed)
{
$targetSiteId = Hash::get($feed, 'siteId') ?: Craft::$app->getSites()->getPrimarySite()->id;

// Did the entry come back in a different site?
if ($existingElement->siteId != $targetSiteId) {
// Skip it if its section doesn't use the `custom` propagation method
if ($existingElement->getSection()->propagationMethod !== Section::PROPAGATION_METHOD_CUSTOM) {
return $existingElement;
}

// Give the entry a status for the import's target site
// (This is how the `custom` propagation method knows which sites the entry should support.)
$siteStatuses = ElementHelper::siteStatusesForElement($existingElement);
$siteStatuses[$targetSiteId] = $existingElement->getEnabledForSite();
$existingElement->setEnabledForSite($siteStatuses);

// Propagate the entry, and swap $entry with the propagated copy
return Craft::$app->getElements()->propagateElement($existingElement, $targetSiteId);
}

return $existingElement;
}

// Protected Methods
// =========================================================================

Expand Down Expand Up @@ -189,10 +238,14 @@ protected function parseParent($feedData, $fieldInfo): ?int
return null;
}

if ($node === 'usedefault') {
if ($node === 'usedefault' || $value === $default) {
$match = 'elements.id';
}

if (is_array($value)) {
$value = $value[0];
}

$query = EntryElement::find()
->status(null)
->andWhere(['=', $match, $value]);
Expand Down Expand Up @@ -253,6 +306,8 @@ protected function parseParent($feedData, $fieldInfo): ?int
protected function parseAuthorId($feedData, $fieldInfo): ?int
{
$value = $this->fetchSimpleValue($feedData, $fieldInfo);
$default = DataHelper::fetchDefaultArrayValue($fieldInfo);

$match = Hash::get($fieldInfo, 'options.match');
$create = Hash::get($fieldInfo, 'options.create');
$node = Hash::get($fieldInfo, 'node');
Expand All @@ -262,12 +317,12 @@ protected function parseAuthorId($feedData, $fieldInfo): ?int
return null;
}

if (is_array($value)) {
$value = $value[0];
if ($node === 'usedefault' || $value === $default) {
$match = 'elements.id';
}

if ($node === 'usedefault') {
$match = 'elements.id';
if (is_array($value)) {
$value = $value[0];
}

if ($match === 'fullName') {
Expand Down
23 changes: 23 additions & 0 deletions src/elements/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,29 @@ protected function parseGroups($feedData, $fieldInfo): array
return $groupIds;
}

/**
* Get and validate Preferred Locale attribute
*
* @param $feedData
* @param $fieldInfo
* @return array|\ArrayAccess|mixed|string|null
* @throws \yii\base\Exception
*/
protected function parsePreferredLocale($feedData, $fieldInfo)
{
$value = $this->fetchSimpleValue($feedData, $fieldInfo);

if ($value === "") {
return $value;
}

if ($value !== null && in_array($value, Craft::$app->getI18n()->getAppLocaleIds(), true)) {
return $value;
}

return null;
}

/**
* @param $feedData
* @param $fieldInfo
Expand Down
4 changes: 4 additions & 0 deletions src/fields/Matrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ public function parseField(): mixed
// Prepare an array that's ready for Matrix to import it
$preppedData[$blockIndex . '.type'] = $blockHandle;
$preppedData[$blockIndex . '.enabled'] = !$disabled;
// because of PR 1284 and enhanced matrix data comparison in PR 1291,
// we need to add "collapsed => false" to the matrix data from the feed;
// otherwise enhanced matrix data comparison will always think the data has changed
$preppedData[$blockIndex . '.collapsed'] = false;
$preppedData[$blockIndex . '.fields.' . $subFieldHandle] = $value;
}

Expand Down
23 changes: 17 additions & 6 deletions src/fields/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ public function parseField(): mixed
}
}

// fill out default values
foreach ($parsedData as $rowCounter => $row) {
foreach ($columns as $columnHandle => $columnInfo) {
$node = Hash::get($columnInfo, 'node');
$type = Hash::get($columnInfo, 'type');

if ($node === 'usedefault') {
if (!isset($parsedData[$rowCounter][$columnHandle]) && !empty($columnInfo['default'])) {
$parsedValue = $this->_handleSubField($type, $columnInfo['default']);
$parsedData[$rowCounter][$columnHandle] = $parsedValue;
}
}
}
}

$dataDelimiter = Plugin::$plugin->service->getConfig('dataDelimiter', $this->feed['id']);

foreach ($parsedData as $rowKey => $row) {
Expand Down Expand Up @@ -146,9 +161,7 @@ private function _handleSubField($type, $value)
}

if ($type == 'date') {
$parsedValue = DateTimeHelper::toDateTime($value) ?: null;

return $this->field->serializeValue($parsedValue);
return DateTimeHelper::toDateTime($value) ?: null;
}

if ($type == 'lightswitch') {
Expand All @@ -160,9 +173,7 @@ private function _handleSubField($type, $value)
}

if ($type == 'time') {
$parsedValue = DateTimeHelper::toDateTime($value) ?: null;

return $this->field->serializeValue($parsedValue);
return DateTimeHelper::toDateTime($value) ?: null;
}

// Protect against array values
Expand Down
Loading

0 comments on commit fd8d065

Please sign in to comment.