Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 75 additions & 31 deletions migrations/install/20180220023217_create_roles_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ public function change()
'null' => true,
'default' => null
]);
$table->addColumn('nav_override', 'text', [
$table->addColumn('module_listing', 'text', [
'null' => true,
'default' => null
]);
$table->addColumn('collection_listing', 'text', [
'null' => true,
'default' => null
]);
Expand Down Expand Up @@ -120,41 +124,81 @@ public function change()
],
[
'collection' => 'directus_roles',
'field' => 'nav_override',
'field' => 'module_listing',
'type' => \Directus\Database\Schema\DataTypes::TYPE_JSON,
'interface' => 'repeater',
'locked' => 1,
'options' => '{
"fields": [
{
"field": "name",
"interface": "text-input",
"type": "string",
"width": "half"
},
{
"field": "link",
"interface": "text-input",
"type": "string",
"width": "half"
},
{
"field": "icon",
"interface": "icon",
"type": "string",
"width": "full"
}
]
}'
],
[
'collection' => 'directus_roles',
'field' => 'collection_listing',
'type' => \Directus\Database\Schema\DataTypes::TYPE_JSON,
'interface' => 'json',
'interface' => 'repeater',
'locked' => 1,
'options' => '[
{
"title": "$t:collections",
"include": "collections"
},
{
"title": "$t:bookmarks",
"include": "bookmarks"
},
{
"title": "$t:extensions",
"include": "extensions"
},
{
"title": "Custom Links",
"links": [
{
"name": "RANGER Studio",
"path": "https://rangerstudio.com",
"icon": "star"
},
{
"name": "Movies",
"path": "/collections/movies"
}
]
}
]'
'options' => '{
"fields": [
{
"field": "collection",
"interface": "collections",
"type": "string",
"width": "full"
}
]
}'
],
];

"fields": [
{
"field": "groups",
"width": "full",
"interface": "repeater",
"type": "JSON",
"options": {
"template": "{{ label }}",
"fields": [
{
"field": "label",
"interface": "text-input",
"type": "string"
},
{
"field": "value",
"interface": "text-input",
"type": "string"
},
{
"field": "icon",
"width": "full",
"interface": "icon",
"type": "string"
}
]
}
}

foreach($data as $value){
if(!$this->checkFieldExist($value['collection'], $value['field'])){
$fileds = $this->table('directus_fields');
Expand Down
191 changes: 191 additions & 0 deletions migrations/upgrades/20191126180400_update_nav_override.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
<?php


use Phinx\Migration\AbstractMigration;

class UpdateNavOverride extends AbstractMigration
{
/**
* Version: v8.0.0
*
* Change:
* Removes the nav_override column in favor of two new ones: module_listing
* and collection_listing. These two JSON fields control the navigation
* as displayed in the app
*/
public function change() {
$rolesTable = $this->table('directus_roles');

/* Remove the old nav_override column
----------------------------------------------------- */
if ($rolesTable->hasColumn('nav_override')) {
$rolesTable->removeColumn('nav_override');
}
/* -------------------------------------------------- */

/* Add module_listing and collection_listing columns
----------------------------------------------------- */
if ($rolesTable->hasColumn('module_listing') === false) {
$rolesTable->addColumn('module_listing', 'text', [
'null' => true,
'default' => null
])->save();
}

if ($rolesTable->hasColumn('collection_listing') === false) {
$rolesTable->addColumn('collection_listing', 'text', [
'null' => true,
'default' => null
])->save();
}
/* -------------------------------------------------- */

/* Configure field options for two new columns
----------------------------------------------------- */
$fieldsTable = $this->table('directus_fields');

if ($this->checkFieldExist('directus_roles', 'module_listing')) {
$this->execute(\Directus\phinx_update(
$this->getAdapter(),
'directus_fields',
[
'interface' => 'repeater',
'options' => '{
"template": "{{ name }}",
"fields": [
{
"field": "name",
"interface": "text-input",
"type": "string",
"width": "half"
},
{
"field": "link",
"interface": "text-input",
"type": "string",
"width": "half"
},
{
"field": "icon",
"interface": "icon",
"type": "string",
"width": "full"
}
]
}',
],
['collection' => 'directus_roles', 'field' => 'module_listing']
));
} else {
$fieldsTable->insert([
'collection' => 'directus_roles',
'field' => 'module_listing',
'type' => \Directus\Database\Schema\DataTypes::TYPE_JSON,
'interface' => 'repeater',
'locked' => 1,
'options' => '{
"template": "{{ name }}",
"fields": [
{
"field": "name",
"interface": "text-input",
"type": "string",
"width": "half"
},
{
"field": "link",
"interface": "text-input",
"type": "string",
"width": "half"
},
{
"field": "icon",
"interface": "icon",
"type": "string",
"width": "full"
}
]
}'
])->save();
}

if ($this->checkFieldExist('directus_roles', 'collection_listing')) {
$this->execute(\Directus\phinx_update(
$this->getAdapter(),
'directus_fields',
[
'interface' => 'repeater',
'options' => '{
"template": "{{ group_name }}",
"fields": [
{
"field": "group_name",
"interface": "text-input",
"type": "string",
"width": "full"
},
{
"field": "collections",
"interface": "repeater",
"type": "json",
"width": "full",
"options": {
"fields": [
{
"field": "collection",
"interface": "collections",
"type": "string",
"width": "full"
}
]
}
}
]
}'
],
['collection' => 'directus_roles', 'field' => 'collection_listing']
));
} else {
$fieldsTable->insert([
'collection' => 'directus_roles',
'field' => 'collection_listing',
'type' => \Directus\Database\Schema\DataTypes::TYPE_JSON,
'interface' => 'repeater',
'locked' => 1,
'options' => '{
"template": "{{ group_name }}",
"fields": [
{
"field": "group_name",
"interface": "text-input",
"type": "string",
"width": "full"
},
{
"field": "collections",
"interface": "repeater",
"type": "json",
"width": "full",
"options": {
"fields": [
{
"field": "collection",
"interface": "collections",
"type": "string",
"width": "full"
}
]
}
}
]
}'
])->save();
}
/* -------------------------------------------------- */
}

public function checkFieldExist($collection,$field){
$checkSql = sprintf('SELECT 1 FROM `directus_fields` WHERE `collection` = "%s" AND `field` = "%s";', $collection, $field);
return $this->query($checkSql)->fetch();
}
}