Skip to content

Commit

Permalink
Handle non-unique typeIds across SEO Elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Welch committed Jun 1, 2020
1 parent 32f3a31 commit a886785
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/controllers/ContentSeoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,35 +101,44 @@ public function actionMetaBundles(

// Query the db table
$offset = ($page - 1) * $per_page;
$subQuery = (new Query())
->from(['{{%seomatic_metabundles}}'])
->where(['!=', 'sourceBundleType', Seomatic::$plugin->metaBundles::GLOBAL_META_BUNDLE]);

$currentSiteHandle = '';
if ((int)$siteId !== 0) {
$subQuery->andWhere(['sourceSiteId' => $siteId]);
$site = Craft::$app->getSites()->getSiteById($siteId);
if ($site !== null) {
$currentSiteHandle = $site->handle;
}
}
if ($filter !== '') {
$subQuery->andWhere(['like', 'sourceName', $filter]);
}
$bundleQuery = (new Query())
->select(['mb.*'])
->from(['mb' => $subQuery])
->leftJoin(['mb2' => $subQuery], [
'and',
'[[mb.sourceId]] = [[mb2.sourceId]]',
'[[mb.id]] < [[mb2.id]]'
])
->where(['mb2.id' => null])
->offset($offset)
->limit($per_page)
->orderBy($sortParams)
;

// Since sectionIds, CategoryIds, etc. are not unique, we need to special case for them
$seoElements = Seomatic::$plugin->seoElements->getAllSeoElementTypes();
$tableIndex = 1;
foreach ($seoElements as $seoElement) {
$tableIndex++;
$subQuery = (new Query())
->from(['{{%seomatic_metabundles}}'])
->where(['=', 'sourceBundleType', $seoElement::META_BUNDLE_TYPE]);
if ((int)$siteId !== 0) {
$subQuery->andWhere(['sourceSiteId' => $siteId]);
}
if ($filter !== '') {
$subQuery->andWhere(['like', 'sourceName', $filter]);
}
$bundleQuery
->where(['mb'.$tableIndex.'.id' => null])
->from(['mb' => $subQuery])
->leftJoin(['mb'.$tableIndex => $subQuery], [
'and',
'[[mb.sourceId]] = [[mb'.$tableIndex.'.sourceId]]',
'[[mb.id]] < [[mb'.$tableIndex.'.id]]'
]);
}
$bundles = $bundleQuery->all();
if ($bundles) {
$dataArray = [];
Expand Down

0 comments on commit a886785

Please sign in to comment.