Skip to content

Commit

Permalink
Update Feed Me integration
Browse files Browse the repository at this point in the history
  • Loading branch information
engram-design committed Mar 26, 2024
1 parent b4baf96 commit 0125efb
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/integrations/NodeFeedMeElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,23 +119,22 @@ protected function parseElementId($feedData, $fieldInfo): ?int

$elementId = null;

// Because we can match on element attributes and custom fields, AND we're directly using SQL
// queries in our `where` below, we need to check if we need a prefix for custom fields accessing
// the content table.
$columnName = $match;
$query = (new Query())
->select(['elements.id', 'elements_sites.elementId', 'elements_sites.title', 'elements_sites.slug', 'elements_sites.uri', 'elements_sites.content'])
->from(['{{%elements}} elements'])
->innerJoin('{{%elements_sites}} elements_sites', '[[elements_sites.elementId]] = [[elements.id]]')
->andWhere(['dateDeleted' => null]);

// Check if we're query a column or a custom field
if (in_array($match, ['title', 'slug', 'uri'])) {
$query->andWhere(['=', $match, $value]);
} else {
$contentQuery = Craft::$app->getDb()->getQueryBuilder()->jsonContains('content', [$match => $value]);

if (Craft::$app->getFields()->getFieldByHandle($match)) {
$columnName = Craft::$app->getFields()->oldFieldColumnPrefix . $match;
$query->andWhere($contentQuery);
}

$result = (new Query())
->select(['elements.id', 'elements_sites.elementId'])
->from(['{{%elements}} elements'])
->innerJoin('{{%elements_sites}} elements_sites', '[[elements_sites.elementId]] = [[elements.id]]')
->innerJoin('{{%content}} content', '[[content.elementId]] = [[elements.id]]')
->where(['=', $columnName, $value])
->andWhere(['dateDeleted' => null])
->one();
$result = $query->one();

if ($result) {
$elementId = $result['id'];
Expand Down

0 comments on commit 0125efb

Please sign in to comment.