Skip to content

Commit

Permalink
Fix an error when migrating from 2.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
engram-design committed Oct 28, 2022
1 parent d87cb34 commit 53b17b9
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions src/services/Navs.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,29 @@ public function handleChangedNav(ConfigEvent $event): void
$navRecord->handle = $data['handle'];
$navRecord->instructions = $data['instructions'];
$navRecord->maxNodes = $data['maxNodes'] ?? '';
$navRecord->maxNodesSettings = $data['maxNodesSettings'] ?? [];
$navRecord->permissions = $data['permissions'] ?? [];
$navRecord->sortOrder = $data['sortOrder'];
$navRecord->propagationMethod = $data['propagationMethod'] ?? NavModel::PROPAGATION_METHOD_ALL;
$navRecord->defaultPlacement = $data['defaultPlacement'] ?? NavModel::DEFAULT_PLACEMENT_END;

$schemaVersion = Craft::$app->getProjectConfig()->get('plugins.navigation.schemaVersion', true);

if (version_compare($schemaVersion, '2.0.2', '>=')) {
$navRecord->permissions = $data['permissions'] ?? [];
}

if (version_compare($schemaVersion, '2.0.5', '>=')) {
$navRecord->propagationMethod = $data['propagationMethod'] ?? NavModel::PROPAGATION_METHOD_ALL;
}

if (version_compare($schemaVersion, '2.0.6', '>=')) {
$navRecord->maxNodesSettings = $data['maxNodesSettings'] ?? [];
}

$navRecord->uid = $navUid;
$propagationMethodChanged = false;

$propagationMethodChanged = $navRecord->propagationMethod != $navRecord->getOldAttribute('propagationMethod');
if (version_compare($schemaVersion, '2.0.5', '>=')) {
$propagationMethodChanged = $navRecord->propagationMethod != $navRecord->getOldAttribute('propagationMethod');
}

// Structure
$structuresService = Craft::$app->getStructures();
Expand Down Expand Up @@ -675,7 +689,7 @@ private function _navs(): MemoizableArray

private function _createNavQuery(): Query
{
return (new Query())
$query = (new Query())
->select([
'navs.id',
'navs.structureId',
Expand All @@ -684,10 +698,7 @@ private function _createNavQuery(): Query
'navs.handle',
'navs.instructions',
'navs.sortOrder',
'navs.propagationMethod',
'navs.maxNodes',
'navs.maxNodesSettings',
'navs.permissions',
'navs.defaultPlacement',
'navs.uid',
'structures.maxLevels',
Expand All @@ -700,6 +711,22 @@ private function _createNavQuery(): Query
->from(['navs' => '{{%navigation_navs}}'])
->where(['navs.dateDeleted' => null])
->orderBy(['sortOrder' => SORT_ASC]);

$schemaVersion = Craft::$app->getProjectConfig()->get('plugins.navigation.schemaVersion', true);

if (version_compare($schemaVersion, '2.0.2', '>=')) {
$query->addSelect('navs.permissions');
}

if (version_compare($schemaVersion, '2.0.5', '>=')) {
$query->addSelect('navs.propagationMethod');
}

if (version_compare($schemaVersion, '2.0.6', '>=')) {
$query->addSelect('navs.maxNodesSettings');
}

return $query;
}

private function _createNavSiteSettingsQuery(): Query
Expand Down

0 comments on commit 53b17b9

Please sign in to comment.