Fixed gh-301 to insure the sql dump of tables will build new fields and views using the new subform method

This commit is contained in:
Llewellyn van der Merwe 2018-06-09 23:11:04 +02:00
parent 01149bfb7c
commit ffbd380b10
No known key found for this signature in database
GPG Key ID: CAD7B16D27AF28C5
6 changed files with 145 additions and 166 deletions

View File

@ -125,7 +125,7 @@ Watch the [proposed development workflow](https://vdm.bz/proposed-development-wo
+ *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com)
+ *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder) + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder)
+ *First Build*: 30th April, 2015 + *First Build*: 30th April, 2015
+ *Last Build*: 31st May, 2018 + *Last Build*: 9th June, 2018
+ *Version*: 2.8.0 + *Version*: 2.8.0
+ *Copyright*: Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved. + *Copyright*: Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved.
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt + *License*: GNU General Public License version 2 or later; see LICENSE.txt

View File

@ -125,7 +125,7 @@ Watch the [proposed development workflow](https://vdm.bz/proposed-development-wo
+ *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com)
+ *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder) + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder)
+ *First Build*: 30th April, 2015 + *First Build*: 30th April, 2015
+ *Last Build*: 31st May, 2018 + *Last Build*: 9th June, 2018
+ *Version*: 2.8.0 + *Version*: 2.8.0
+ *Copyright*: Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved. + *Copyright*: Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved.
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt + *License*: GNU General Public License version 2 or later; see LICENSE.txt

View File

@ -55,32 +55,33 @@ class Mapping
/** /**
* The needed set of keys needed to set * The needed set of keys needed to set
*/ */
protected $setting = array('id' => 'default', 'buildcompsql' => 'base64', 'addadmin_views' => 'json', 'name_code' => 'safeString'); protected $setting = array('id' => 'default', 'buildcompsql' => 'base64', 'name_code' => 'safeString');
/** /**
* The needed set of keys needed to set * The needed set of keys needed to set
*/ */
protected $notRequiered = array('id', 'asset_id', 'published', protected $notRequiered = array('id', 'asset_id', 'published',
'created_by', 'modified_by', 'created', 'modified', 'checked_out','checked_out_time', 'created_by', 'modified_by', 'created', 'modified', 'checked_out','checked_out_time',
'version', 'hits', 'access', 'ordering', 'version', 'hits', 'access', 'ordering',
'metakey', 'metadesc', 'metadata', 'params'); 'metakey', 'metadesc', 'metadata', 'params');
/** /**
* The datatypes and it linked field types (basic) * The datatypes and it linked field types (basic)
* (TODO) We may need to set this dynamicly * (TODO) We may need to set this dynamicly
*/ */
protected $dataTypes = array( 'VARCHAR' => 'Text', 'CHAR' => 'Text', protected $dataTypes = array( 'VARCHAR' => 'Text', 'CHAR' => 'Text',
'MEDIUMTEXT' => 'Textarea', 'LONGTEXT' => 'Textarea', 'MEDIUMTEXT' => 'Textarea', 'LONGTEXT' => 'Textarea',
'TEXT' => 'Textarea', 'DATETIME' => 'Calendar', 'TEXT' => 'Textarea', 'DATETIME' => 'Calendar',
'DATE' => 'Text', 'TIME' => 'Text', 'TINYINT' => 'Text', 'DATE' => 'Text', 'TIME' => 'Text', 'TINYINT' => 'Text',
'BIGINT' => 'Text', 'INT' => 'Text', 'FLOAT' => 'Text', 'BIGINT' => 'Text', 'INT' => 'Text', 'FLOAT' => 'Text',
'DECIMAL' => 'Text', 'DOUBLE' => 'Text'); 'DECIMAL' => 'Text', 'DOUBLE' => 'Text');
/** /**
* The datasize identifiers * The datasize identifiers
*/ */
protected $dataSize = array( 'CHAR', 'VARCHAR', 'INT', 'TINYINT', protected $dataSize = array(
'BIGINT', 'FLOAT', 'DECIMAL', 'DOUBLE'); 'CHAR', 'VARCHAR', 'INT', 'TINYINT',
'BIGINT', 'FLOAT', 'DECIMAL', 'DOUBLE');
/** /**
* The default identifiers * The default identifiers
@ -101,7 +102,7 @@ class Mapping
// set the app to insure messages can be set // set the app to insure messages can be set
$this->app = JFactory::getApplication(); $this->app = JFactory::getApplication();
if ($data) if (ComponentbuilderHelper::checkArray($data))
{ {
if (isset($data['buildcomp']) && 1 == $data['buildcomp'] && isset($data['buildcompsql'])) if (isset($data['buildcomp']) && 1 == $data['buildcomp'] && isset($data['buildcompsql']))
{ {
@ -129,6 +130,12 @@ class Mapping
} }
} }
} }
// get linked admin views
$addadmin_views = ComponentbuilderHelper::getVar('component_admin_views', $data['id'], 'joomla_component', 'addadmin_views');
if (ComponentbuilderHelper::checkJson($addadmin_views))
{
$this->addadmin_views = json_decode($addadmin_views, true);
}
// set the map of the views needed // set the map of the views needed
if ($this->setMap()) if ($this->setMap())
{ {

View File

@ -37,12 +37,13 @@ class Builder extends Mapping
public $user; public $user;
public $today; public $today;
public $db; public $db;
public $views = array(); public $views = array();
protected $fields = array(); public $admin_fields = array();
protected $title = array(); protected $fields = array();
protected $description = array(); protected $title = array();
protected $alias = array(); protected $description = array();
protected $list = array(); protected $alias = array();
protected $list = array();
/** /**
* Field that should not be used in name, alias, disc, and list view * Field that should not be used in name, alias, disc, and list view
@ -62,10 +63,10 @@ class Builder extends Mapping
$data['buildcomp'] = 0; $data['buildcomp'] = 0;
$data['buildcompsql'] = ''; $data['buildcompsql'] = '';
// set some globals // set some globals
$this->db = JFactory::getDbo(); $this->db = JFactory::getDbo();
$this->user = JFactory::getUser(); $this->user = JFactory::getUser();
$this->today = JFactory::getDate()->toSql(); $this->today = JFactory::getDate()->toSql();
// no start the building of the views and fields // no start the building of the views and fields
if ($this->setBuild()) if ($this->setBuild())
{ {
@ -100,22 +101,21 @@ class Builder extends Mapping
protected function setView(&$name) protected function setView(&$name)
{ {
// set the view object // set the view object
$object = new stdClass(); $object = new stdClass();
$object->system_name = ComponentbuilderHelper::safeString($name, 'W') . ' (dynamic build)'; $object->system_name = ComponentbuilderHelper::safeString($name, 'W') . ' (dynamic build)';
$object->name_single = $name; $object->name_single = $name;
$object->name_list = $name. 's'; $object->name_list = $name. 's';
$object->short_description = $name. ' view (dynamic build)'; $object->short_description = $name. ' view (dynamic build)';
$object->type = 1; $object->type = 1;
$object->description = $name. ' view (dynamic build)'; $object->description = $name. ' view (dynamic build)';
$object->add_fadein = 1; $object->add_fadein = 1;
$object->add_sql = (isset($this->addSql[$name])) ? $this->addSql[$name]: 0; $object->add_sql = (isset($this->addSql[$name])) ? $this->addSql[$name]: 0;
$object->source = (isset($this->source[$name])) ? $this->source[$name]: 0; $object->source = (isset($this->source[$name])) ? $this->source[$name]: 0;
$object->sql = (isset($this->sql[$name])) ? base64_encode($this->sql[$name]): ''; $object->sql = (isset($this->sql[$name])) ? base64_encode($this->sql[$name]): '';
$object->addpermissions = '{"action":["view.edit","view.edit.own","view.edit.state","view.create","view.delete","view.access"],"implementation":["3","3","3","3","3","3"]}'; $object->addpermissions = '{"action":["view.edit","view.edit.own","view.edit.state","view.create","view.delete","view.access"],"implementation":["3","3","3","3","3","3"]}';
$object->addfields = $this->addFields($name); $object->created = $this->today;
$object->created = $this->today; $object->created_by = $this->user->id;
$object->created_by = $this->user->id; $object->published = 1;
$object->published = 1;
// add to data base // add to data base
if ($this->db->insertObject('#__componentbuilder_admin_view', $object)) if ($this->db->insertObject('#__componentbuilder_admin_view', $object))
{ {
@ -124,7 +124,8 @@ class Builder extends Mapping
ComponentbuilderHelper::setAsset($id, 'admin_view'); ComponentbuilderHelper::setAsset($id, 'admin_view');
// load the views // load the views
$this->views[] = $id; $this->views[] = $id;
return true; // load the admin view fields
return $this->addFields($name, $id);
} }
return false; return false;
} }
@ -132,26 +133,12 @@ class Builder extends Mapping
/** /**
* Add the fields to the view * Add the fields to the view
*/ */
protected function addFields(&$view) protected function addFields(&$view, &$view_id)
{ {
if (isset($this->fields[$view])) if (isset($this->fields[$view]))
{ {
// set some defaults // set some defaults
$addField = array ( $addField = array ();
'field' => array(),
'list' => array(),
'order_list' => array(),
'title' => array(),
'alias' => array(),
'sort' => array(),
'search' => array(),
'filter' => array(),
'link' => array(),
'tab' => array(),
'alignment' => array(),
'order_edit' => array(),
'permission' => array()
);
$fixLink = (isset($this->title[$view])) ? 0 : 1; $fixLink = (isset($this->title[$view])) ? 0 : 1;
// build the field data... hmmm // build the field data... hmmm
foreach ($this->fields[$view] as $nr => $id) foreach ($this->fields[$view] as $nr => $id)
@ -171,23 +158,32 @@ class Builder extends Mapping
$fixLink = 0; $fixLink = 0;
} }
// load the field values // load the field values
$addField['field'][] = $id; $addField['addfields'.$nr]['field'] = $id;
$addField['list'][] = $isList; $addField['addfields'.$nr]['list'] = $isList;
$addField['order_list'][] = ($key) ? $key : 0; $addField['addfields'.$nr]['order_list'] = ($key) ? $key : 0;
$addField['title'][] = $isTitle; $addField['addfields'.$nr]['title'] = $isTitle;
$addField['alias'][] = $isAlias; $addField['addfields'.$nr]['alias'] = $isAlias;
$addField['sort'][] = $isList; $addField['addfields'.$nr]['sort'] = $isList;
$addField['search'][] = $isList; $addField['addfields'.$nr]['search'] = $isList;
$addField['filter'][] = $isList; $addField['addfields'.$nr]['filter'] = $isList;
$addField['link'][] = $isLink; $addField['addfields'.$nr]['link'] = $isLink;
$addField['tab'][] = 1; $addField['addfields'.$nr]['tab'] = 1;
$addField['alignment'][] = ($isTitle || $isAlias) ? 4 : $alignment; $addField['addfields'.$nr]['alignment'] = ($isTitle || $isAlias) ? 4 : $alignment;
$addField['order_edit'][] = $nr; $addField['addfields'.$nr]['order_edit'] = $nr;
$addField['permission'][] = 0; $addField['addfields'.$nr]['permission'] = 0;
} }
return json_encode($addField);
// set the field object
$object = new stdClass();
$object->admin_view = $view_id;
$object->addfields = json_encode($addField, JSON_FORCE_OBJECT);
$object->created = $this->today;
$object->created_by = $this->user->id;
$object->published = 1;
// add to data base
return $this->db->insertObject('#__componentbuilder_admin_fields', $object);
} }
return ''; return false;
} }
/** /**
@ -198,21 +194,21 @@ class Builder extends Mapping
if ($fieldType = $this->getFieldType($field['fieldType'])) if ($fieldType = $this->getFieldType($field['fieldType']))
{ {
// set the field object // set the field object
$object = new stdClass(); $object = new stdClass();
$object->name = $field['label'] . ' (dynamic build)'; $object->name = $field['label'] . ' (dynamic build)';
$object->fieldtype = $fieldType; $object->fieldtype = $fieldType;
$object->datatype = $field['dataType']; $object->datatype = $field['dataType'];
$object->indexes = $field['key']; $object->indexes = $field['key'];
$object->null_switch = $field['null']; $object->null_switch = $field['null'];
$object->datalenght = $field['size']; $object->datalenght = $field['size'];
$object->datalenght_other = $field['sizeOther']; $object->datalenght_other = $field['sizeOther'];
$object->datadefault = $field['default']; $object->datadefault = $field['default'];
$object->datadefault_other = $field['defaultOther']; $object->datadefault_other = $field['defaultOther'];
$object->created = $this->today; $object->created = $this->today;
$object->created_by = $this->user->id; $object->created_by = $this->user->id;
$object->published = 1; $object->published = 1;
$object->store = 0; $object->store = 0;
$object->xml = $this->setFieldXML($field, $fieldType); $object->xml = $this->setFieldXML($field, $fieldType);
// add to data base // add to data base
if ($this->db->insertObject('#__componentbuilder_field', $object)) if ($this->db->insertObject('#__componentbuilder_field', $object))
{ {

View File

@ -36,106 +36,82 @@ class Extrusion extends Builder
*/ */
public function __construct(&$data) public function __construct(&$data)
{ {
// first we run the perent constructor // make sure we have an id
if (parent::__construct($data)) if (isset($data['id']) && $data['id'] > 0)
{ {
// link the view data to the component // first we run the perent constructor
$data['addadmin_views'] = $this->linkAdminViews(); if (parent::__construct($data))
if (ComponentbuilderHelper::checkJson($data['addadmin_views']))
{ {
$this->app->enqueueMessage( // link the view data to the component
JText::_('All the fields and views from your sql dump has been created and linked to this component.'), if ($this->setAdminViews($data['id']))
'Success' {
); $this->app->enqueueMessage(
return true; JText::_('All the fields and views from your sql dump has been created and linked to this component.'),
'Success'
);
return true;
}
} }
return false;
} }
$this->app->enqueueMessage(
JText::_('Please try again, this error usualy happens if it is a new component, beacues we need a component ID to do this build with your sql dump.'),
'Error'
);
return false; return false;
} }
/** /**
* link the build views to the component * link the build views to the component
*/ */
protected function linkAdminViews() protected function setAdminViews(&$component_id)
{ {
// check if views were set // check if views were set
if (ComponentbuilderHelper::checkArray($this->views)) if (ComponentbuilderHelper::checkArray($this->views))
{ {
// insure arrays are set $count = 0;
if (!isset($this->addadmin_views['adminview'])) if (ComponentbuilderHelper::checkArray($this->addadmin_views))
{ {
$this->addadmin_views['adminview'] = array(); $count = (int) count((array)$this->addadmin_views) + 3;
}
if (!isset($this->addadmin_views['icomoon']))
{
$this->addadmin_views['icomoon'] = array();
}
if (!isset($this->addadmin_views['mainmenu']))
{
$this->addadmin_views['mainmenu'] = array();
}
if (!isset($this->addadmin_views['dashboard_add']))
{
$this->addadmin_views['dashboard_add'] = array();
}
if (!isset($this->addadmin_views['dashboard_list']))
{
$this->addadmin_views['dashboard_list'] = array();
}
if (!isset($this->addadmin_views['submenu']))
{
$this->addadmin_views['submenu'] = array();
}
if (!isset($this->addadmin_views['checkin']))
{
$this->addadmin_views['checkin'] = array();
}
if (!isset($this->addadmin_views['history']))
{
$this->addadmin_views['history'] = array();
}
if (!isset($this->addadmin_views['metadata']))
{
$this->addadmin_views['metadata'] = array();
}
if (!isset($this->addadmin_views['access']))
{
$this->addadmin_views['access'] = array();
}
if (!isset($this->addadmin_views['port']))
{
$this->addadmin_views['port'] = array();
}
if (!isset($this->addadmin_views['edit_create_site_view']))
{
$this->addadmin_views['edit_create_site_view'] = array();
}
if (!isset($this->addadmin_views['order']))
{
$this->addadmin_views['order'] = array();
} }
// set the admin view data linking // set the admin view data linking
foreach ($this->views as $id) foreach ($this->views as $nr => $id)
{ {
$this->addadmin_views['adminview'][] = $id; $pointer = $count + $nr;
$this->addadmin_views['icomoon'][] = 'joomla'; $this->addadmin_views['addadmin_views'.$pointer]['adminview'] = $id;
$this->addadmin_views['mainmenu'][] = 1; $this->addadmin_views['addadmin_views'.$pointer]['icomoon'] = 'joomla';
$this->addadmin_views['dashboard_add'][] = 1; $this->addadmin_views['addadmin_views'.$pointer]['mainmenu'] = 1;
$this->addadmin_views['dashboard_list'][] = 1; $this->addadmin_views['addadmin_views'.$pointer]['dashboard_add'] = 1;
$this->addadmin_views['submenu'][] = 1; $this->addadmin_views['addadmin_views'.$pointer]['dashboard_list'] = 1;
$this->addadmin_views['checkin'][] = 1; $this->addadmin_views['addadmin_views'.$pointer]['submenu'] = 1;
$this->addadmin_views['history'][] = 1; $this->addadmin_views['addadmin_views'.$pointer]['checkin'] = 1;
$this->addadmin_views['metadata'][] = 1; $this->addadmin_views['addadmin_views'.$pointer]['history'] = 1;
$this->addadmin_views['access'][] = 1; $this->addadmin_views['addadmin_views'.$pointer]['metadata'] = 1;
$this->addadmin_views['port'][] = 1; $this->addadmin_views['addadmin_views'.$pointer]['access'] = 1;
$this->addadmin_views['edit_create_site_view'][] = 0; $this->addadmin_views['addadmin_views'.$pointer]['port'] = 1;
$this->addadmin_views['order'][] = count($this->addadmin_views['order']) + 1; $this->addadmin_views['addadmin_views'.$pointer]['edit_create_site_view'] = 0;
$this->addadmin_views['addadmin_views'.$pointer]['order'] = $pointer + 1;
} }
} }
if (isset($this->addadmin_views) && ComponentbuilderHelper::checkArray($this->addadmin_views)) if (isset($this->addadmin_views) && ComponentbuilderHelper::checkArray($this->addadmin_views))
{ {
return json_encode($this->addadmin_views); // set the field object
$object = new stdClass();
$object->joomla_component = $component_id;
$object->addadmin_views = json_encode($this->addadmin_views, JSON_FORCE_OBJECT);
$object->created = $this->today;
$object->created_by = $this->user->id;
$object->published = 1;
// check if it is already set
if ($item_id = ComponentbuilderHelper::getVar('component_admin_views', $component_id, 'joomla_component', 'id'))
{
// set ID
$object->id = (int) $item_id;
return $this->db->updateObject('#__componentbuilder_component_admin_views', $object, 'id');
}
// add to data base
return $this->db->insertObject('#__componentbuilder_component_admin_views', $object);
} }
return ''; return false;
} }
} }

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="3.2" method="upgrade"> <extension type="component" version="3.2" method="upgrade">
<name>COM_COMPONENTBUILDER</name> <name>COM_COMPONENTBUILDER</name>
<creationDate>31st May, 2018</creationDate> <creationDate>9th June, 2018</creationDate>
<author>Llewellyn van der Merwe</author> <author>Llewellyn van der Merwe</author>
<authorEmail>llewellyn@joomlacomponentbuilder.com</authorEmail> <authorEmail>llewellyn@joomlacomponentbuilder.com</authorEmail>
<authorUrl>http://www.joomlacomponentbuilder.com</authorUrl> <authorUrl>http://www.joomlacomponentbuilder.com</authorUrl>