-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Navee migration + add panels to settings
- Loading branch information
1 parent
8b58185
commit 409c0d1
Showing
8 changed files
with
252 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
<?php | ||
namespace verbb\navigation\migrations; | ||
|
||
use verbb\navigation\Navigation; | ||
use verbb\navigation\elements\Node; | ||
use verbb\navigation\models\Nav as NavModel; | ||
|
||
use Craft; | ||
use craft\db\Migration; | ||
use craft\db\Query; | ||
use craft\helpers\Json; | ||
|
||
class NaveePlugin extends Migration | ||
{ | ||
public $propagate = true; | ||
public $assignToDefaultSite = false; | ||
|
||
private $processedNodes = []; | ||
|
||
// Public Methods | ||
// ========================================================================= | ||
|
||
public function safeUp() | ||
{ | ||
try { | ||
if (!$this->db->tableExists('{{%navee_navigations}}')) { | ||
return true; | ||
} | ||
|
||
$NaveeNavs = (new Query()) | ||
->select(['*']) | ||
->from(['{{%navee_navigations}}']) | ||
->all(); | ||
|
||
foreach ($NaveeNavs as $key => $NaveeNav) { | ||
$nav = Navigation::$plugin->navs->getNavByHandle($NaveeNav['handle']); | ||
|
||
echo "\n > Migrating nav `{$NaveeNav['handle']}` ...\n"; | ||
|
||
if (!$nav) { | ||
$nav = new NavModel(); | ||
} | ||
|
||
$nav->name = $NaveeNav['name']; | ||
$nav->handle = $NaveeNav['handle']; | ||
$nav->maxLevels = $NaveeNav['maxLevels']; | ||
$nav->structureId = $NaveeNav['structureId']; | ||
|
||
if (!Navigation::$plugin->navs->saveNav($nav)) { | ||
echo " > ERROR: Unable to migrate nav `{$NaveeNav['handle']}` ...\n"; | ||
|
||
Craft::dump($nav->getErrors()); | ||
|
||
continue; | ||
} | ||
|
||
foreach (Craft::$app->getSites()->getAllSites() as $site) { | ||
$NaveeNodes = (new Query()) | ||
->select(['*']) | ||
->from(['{{%navee_nodes}}']) | ||
->leftJoin('{{%elements_sites}} elements_sites', '[[elements_sites.elementId]] = [[navee_nodes.id]]') | ||
->where(['navigationId' => $NaveeNav['id'], 'siteId' => $site['id']]) | ||
->all(); | ||
|
||
foreach ($NaveeNodes as $key => $NaveeNode) { | ||
try { | ||
$node = new Node(); | ||
|
||
$NaveeElement = (new Query()) | ||
->select(['*']) | ||
->from(['{{%elements}}']) | ||
->leftJoin('{{%content}} content', '[[content.elementId]] = [[elements.id]]') | ||
->where(['elements.id' => $NaveeNode['elementId'], 'type' => 'Navee_Node', 'siteId' => $site['id']]) | ||
->one(); | ||
|
||
if (!$NaveeElement) { | ||
echo " > ERROR: Unable to find element for node `{$NaveeNode['id']}` ...\n"; | ||
|
||
continue; | ||
} | ||
|
||
$node->title = $NaveeElement['title']; | ||
$node->enabled = $NaveeElement['enabled']; | ||
$node->siteId = $site->id; | ||
$node->navId = $nav->id; | ||
$node->url = $NaveeNode['customUri']; | ||
$node->classes = $NaveeNode['class']; | ||
|
||
if ($NaveeNode['target'] === '_blank') { | ||
$node->newWindow = true; | ||
} | ||
|
||
if ($NaveeNode['entryId']) { | ||
$node->type = \craft\elements\Entry::class; | ||
$node->elementId = $NaveeNode['entryId']; | ||
} else if ($NaveeNode['categoryId']) { | ||
$node->type = \craft\elements\Category::class; | ||
$node->elementId = $NaveeNode['categoryId']; | ||
} else if ($NaveeNode['assetId']) { | ||
$node->type = \craft\elements\Asset::class; | ||
$node->elementId = $NaveeNode['assetId']; | ||
} | ||
|
||
if (Craft::$app->getElements()->saveElement($node, true, $this->propagate)) { | ||
|
||
|
||
} else { | ||
echo " > ERROR: Unable to save node `{$NaveeNode['title']}` ...\n"; | ||
|
||
Craft::dump($node->getErrors()); | ||
} | ||
} catch (\Throwable $e) { | ||
echo " > ERROR: Unable to save node `{$NaveeNode['id']}` ...\n"; | ||
|
||
Craft::dump($e->getMessage()); | ||
|
||
continue; | ||
} | ||
} | ||
} | ||
} | ||
|
||
} catch (\Throwable $e) { | ||
Craft::dump($e->getMessage()); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public function safeDown() | ||
{ | ||
return false; | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,13 @@ | ||
{% import '_includes/forms' as forms %} | ||
{% import 'navigation/_macros' as macros %} | ||
|
||
{{ forms.textField({ | ||
id: 'pluginName', | ||
name: 'pluginName', | ||
label: 'Plugin Name' | t('app'), | ||
value: settings.pluginName, | ||
first: true, | ||
autofocus: true, | ||
instructions: 'Plugin name for the end user.' | t('navigation'), | ||
warning: macros.configWarning('pluginName', 'navigation'), | ||
}) }} |
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,9 @@ | ||
<a class="btn submit btn-migrate" href="#" data-action="navigation/base/navee-migrate">{{ 'Migrate' | t('navigation') }}</a> | ||
|
||
{% if output is defined %} | ||
|
||
<hr> | ||
|
||
<code>{{ output | raw }}</code> | ||
|
||
{% endif %} |
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,55 @@ | ||
{% extends 'navigation/_layouts' %} | ||
{% import '_includes/forms' as forms %} | ||
{% import 'navigation/_macros' as macros %} | ||
|
||
{% set crumbs = [ | ||
{ label: craft.navigation.getPluginName(), url: url('navigation/settings') }, | ||
{ label: 'Settings' | t('app'), url: url('navigation/settings') } | ||
] %} | ||
|
||
{% set fullPageForm = true %} | ||
|
||
{% set navItems = { | ||
'general': { title: 'General Settings' | t('navigation') }, | ||
'am-nav': { title: 'A&M Nav Migration' | t('navigation') }, | ||
'navee': { title: 'Navee Migration' | t('navigation') }, | ||
} %} | ||
|
||
{% set selectedItem = 'general' %} | ||
|
||
{% block sidebar %} | ||
<nav class="navigation-settings-tabs" id="tabs"> | ||
<ul> | ||
{% for id, item in navItems %} | ||
{% if item.heading is defined %} | ||
<li class="heading"><span>{{ item.heading }}</span></li> | ||
{% else %} | ||
<li> | ||
<a id="tab-{{ loop.index }}" href="#tab-{{ id }}" class="tab {% if id == selectedItem %}sel{% endif %}"> | ||
{{ item.title }} | ||
</a> | ||
</li> | ||
{% endif %} | ||
{% endfor %} | ||
</ul> | ||
</nav> | ||
{% endblock %} | ||
|
||
{% block blockContent %} | ||
|
||
<input type="hidden" name="action" value="plugins/save-plugin-settings"> | ||
<input type="hidden" name="pluginHandle" value="navigation"> | ||
|
||
{% for id, item in navItems %} | ||
{% if item.title is defined %} | ||
<div id="tab-{{ id }}" {% if not loop.first %}class="hidden"{% endif %}> | ||
<h2>{{ item.title }}</h2> | ||
|
||
{% namespace 'settings' %} | ||
{% include 'navigation/settings/_panes/' ~ id ignore missing %} | ||
{% endnamespace %} | ||
</div> | ||
{% endif %} | ||
{% endfor %} | ||
|
||
{% endblock %} |