Added the validation rules to the export and import of JCB packages

This commit is contained in:
Llewellyn van der Merwe 2018-03-30 11:32:22 +02:00
parent af1e76d21e
commit 0a4b8f067f
No known key found for this signature in database
GPG Key ID: CAD7B16D27AF28C5
5 changed files with 40 additions and 14 deletions

View File

@ -130,7 +130,7 @@ Component Builder is mapped as a component in itself on my local development env
+ *Version*: 2.7.1
+ *Copyright*: Copyright (C) 2015. All Rights Reserved
+ *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
+ *Line count*: **188511**
+ *Line count*: **188537**
+ *Field count*: **1011**
+ *File count*: **1197**
+ *Folder count*: **193**

View File

@ -130,7 +130,7 @@ Component Builder is mapped as a component in itself on my local development env
+ *Version*: 2.7.1
+ *Copyright*: Copyright (C) 2015. All Rights Reserved
+ *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
+ *Line count*: **188511**
+ *Line count*: **188537**
+ *Field count*: **1011**
+ *File count*: **1197**
+ *Folder count*: **193**

View File

@ -697,7 +697,7 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
$this->today = JFactory::getDate()->toSql();
// the array of tables to store
$tables = array(
'fieldtype', 'field', 'admin_view', 'snippet', 'dynamic_get', 'custom_admin_view', 'site_view',
'validation_rule', 'fieldtype', 'field', 'admin_view', 'snippet', 'dynamic_get', 'custom_admin_view', 'site_view',
'template', 'layout', 'joomla_component', 'language', 'language_translation', 'custom_code',
'admin_fields', 'admin_fields_conditions', 'component_admin_views', 'component_site_views',
'component_custom_admin_views', 'component_updates', 'component_mysql_tweaks',
@ -2336,6 +2336,7 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
$this->specialValue['admin_view'] = $this->newID['admin_view'][(int) $item->admin_view];
}
break;
case 'validation_rule':
case 'fieldtype':
// get by name (since there should only be one of each name)
$getter = 'name';

View File

@ -302,13 +302,17 @@ class ComponentbuilderModelJoomla_components extends JModelList
{
$this->setData($table, $pks, $field);
}
// add fields and conditions
if (isset($this->exportIDs['admin_view']) && ComponentbuilderHelper::checkArray($this->exportIDs['admin_view']))
{
$this->setData('admin_fields', array_values($this->exportIDs['admin_view']), 'admin_view');
$this->setData('admin_fields_conditions', array_values($this->exportIDs['admin_view']), 'admin_view');
}
// add validation rules
if (isset($this->exportIDs['validation_rule']) && ComponentbuilderHelper::checkArray($this->exportIDs['validation_rule']))
{
$this->setData('validation_rule', array_values($this->exportIDs['validation_rule']), 'name');
}
// add field types
if (isset($this->exportIDs['fieldtype']) && ComponentbuilderHelper::checkArray($this->exportIDs['fieldtype']))
{
@ -357,7 +361,7 @@ class ComponentbuilderModelJoomla_components extends JModelList
*
* @return void.
*/
protected function setExportIDs($value, $table)
protected function setExportIDs($value, $table, $int = true)
{
// check if table has been set
if (!isset($this->exportIDs[$table]))
@ -374,16 +378,24 @@ class ComponentbuilderModelJoomla_components extends JModelList
{
foreach ($value as $id)
{
if ((ComponentbuilderHelper::checkString($id) || is_numeric($id)) && 0 !== (int) $id)
if ($int && (ComponentbuilderHelper::checkString($id) || is_numeric($id)) && 0 !== (int) $id)
{
$this->exportIDs[$table][(int) $id] = (int) $id;
}
elseif (!$int && ComponentbuilderHelper::checkString($id))
{
$this->exportIDs[$table][$id] = $this->_db->quote($id);
}
}
elseif ((ComponentbuilderHelper::checkString($value) || is_numeric($value)) && 0 !== (int) $value)
}
elseif ($int && (ComponentbuilderHelper::checkString($value) || is_numeric($value)) && 0 !== (int) $value)
{
$this->exportIDs[$table][(int) $value] = (int) $value;
}
elseif (!$int && ComponentbuilderHelper::checkString($value))
{
$this->exportIDs[$table][$value] = $this->_db->quote($value);
}
}
/**
@ -467,7 +479,7 @@ class ComponentbuilderModelJoomla_components extends JModelList
*
* @return mixed An array of data items on success, false on failure.
*/
protected function setData($table, $values, $key)
protected function setData($table, $values, $key, $string = false)
{
// make sure we have an array of values
if (!ComponentbuilderHelper::checkArray($values) || !ComponentbuilderHelper::checkString($table) || !ComponentbuilderHelper::checkString($key))
@ -476,10 +488,8 @@ class ComponentbuilderModelJoomla_components extends JModelList
}
// start the query
$query = $this->_db->getQuery(true);
// Select some fields
$query->select(array('a.*'));
// From the componentbuilder_ANY table
$query->from($this->_db->quoteName('#__componentbuilder_'. $table, 'a'));
// set the where query
@ -490,10 +500,8 @@ class ComponentbuilderModelJoomla_components extends JModelList
$groups = implode(',', $this->user->getAuthorisedViewLevels());
$query->where('a.access IN (' . $groups . ')');
}
// Order the results by ordering
$query->order('a.ordering ASC');
// Load the items
$this->_db->setQuery($query);
$this->_db->execute();
@ -653,6 +661,23 @@ class ComponentbuilderModelJoomla_components extends JModelList
$this->setData('field', $fieldsSets, 'id');
}
}
// check if validation rule is found
$validationRule = ComponentbuilderHelper::getBetween(json_decode($item->xml), 'validate="', '"');
if (ComponentbuilderHelper::checkString($validationRule))
{
// make sure it is lowercase
$validationRule = ComponentbuilderHelper::safeString($validationRule);
// get core validation rules
if ($coreValidationRules = ComponentbuilderHelper::getExistingValidationRuleNames(true))
{
// make sure this rule is not a core validation rule
if (!in_array($validationRule, (array) $coreValidationRules))
{
// okay load the rule
$this->setExportIDs($validationRule, 'validation_rule', false);
}
}
}
}
// actions to take if table is site_view and custom_admin_view
if ('site_view' === $table || 'custom_admin_view' === $table)

View File

@ -1287,7 +1287,7 @@ INSERT INTO `#__componentbuilder_joomla_component` (`id`, `add_license`, `licens
--
INSERT INTO `#__componentbuilder_admin_view` (`id`, `add_css_view`, `add_css_views`, `add_custom_button`, `add_custom_import`, `add_fadein`, `add_javascript_view_file`, `add_javascript_view_footer`, `add_javascript_views_file`, `add_javascript_views_footer`, `add_php_ajax`, `add_php_allowedit`, `add_php_batchcopy`, `add_php_batchmove`, `add_php_getitem`, `add_php_getitems`, `add_php_getitems_after_all`, `add_php_getlistquery`, `add_php_postsavehook`, `add_php_save`, `add_sql`, `addlinked_views`, `addpermissions`, `addtables`, `addtabs`, `add_php_before_delete`, `add_php_before_publish`, `add_php_document`, `add_php_after_delete`, `add_php_after_publish`, `php_before_delete`, `php_before_publish`, `php_controller`, `php_document`, `php_after_delete`, `php_after_publish`, `ajax_input`, `css_view`, `css_views`, `custom_button`, `description`, `html_import_view`, `icon`, `icon_add`, `icon_category`, `javascript_view_file`, `javascript_view_footer`, `javascript_views_file`, `javascript_views_footer`, `name_list`, `system_name`, `name_single`, `not_required`, `php_ajaxmethod`, `php_allowedit`, `php_batchcopy`, `php_batchmove`, `php_getitem`, `php_getitems`, `php_getitems_after_all`, `php_getlistquery`, `php_import`, `php_import_display`, `php_import_save`, `php_import_setdata`, `php_model`, `php_postsavehook`, `php_save`, `short_description`, `source`, `sql`, `type`, `params`, `published`, `created`, `modified`, `version`, `hits`, `ordering`) VALUES
(109, '', '', '', '', 1, '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '{\"addpermissions0\":{\"action\":\"view.edit\",\"implementation\":\"3\"},\"addpermissions1\":{\"action\":\"view.edit.own\",\"implementation\":\"3\"},\"addpermissions2\":{\"action\":\"view.edit.state\",\"implementation\":\"3\"},\"addpermissions3\":{\"action\":\"view.edit.created_by\",\"implementation\":\"3\"},\"addpermissions4\":{\"action\":\"view.edit.created\",\"implementation\":\"3\"},\"addpermissions5\":{\"action\":\"view.create\",\"implementation\":\"3\"},\"addpermissions6\":{\"action\":\"view.delete\",\"implementation\":\"3\"},\"addpermissions7\":{\"action\":\"view.access\",\"implementation\":\"3\"}}', '', '{\"addtabs0\":{\"name\":\"Details\"},\"addtabs1\":{\"name\":\"More\"}}', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'images/WoodMannequin-icon.png', 'images/WoodMannequin-icon-plus.png', '', '', '', '', '', 'Looks', 'Look', 'Look', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'The demo view', '', '', 1, '', 1, '2016-10-18 11:44:46', '2016-10-20 19:23:57', 12, '', 16);
(109, '', '', '', '', 1, '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '{\"addpermissions0\":{\"action\":\"view.edit\",\"implementation\":\"3\"},\"addpermissions1\":{\"action\":\"view.edit.own\",\"implementation\":\"3\"},\"addpermissions2\":{\"action\":\"view.edit.state\",\"implementation\":\"3\"},\"addpermissions3\":{\"action\":\"view.edit.created_by\",\"implementation\":\"3\"},\"addpermissions4\":{\"action\":\"view.edit.created\",\"implementation\":\"3\"},\"addpermissions5\":{\"action\":\"view.create\",\"implementation\":\"3\"},\"addpermissions6\":{\"action\":\"view.delete\",\"implementation\":\"3\"},\"addpermissions7\":{\"action\":\"view.access\",\"implementation\":\"3\"}}', '', '{\"addtabs0\":{\"name\":\"Details\"},\"addtabs1\":{\"name\":\"More\"}}', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'images/WoodMannequin-icon.png', 'images/WoodMannequin-icon-plus.png', '', '', '', '', '', 'Looks', 'Look', 'Look', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'The demo view', '', '', 1, '', 1, '2016-10-18 11:44:46', '2018-03-30 09:30:48', 14, '', 16);
@ -1485,7 +1485,7 @@ INSERT INTO `#__componentbuilder_field` (`id`, `add_css_view`, `add_css_views`,
(199, '', '', '', '', '', '', '', '', '', 255, '', 'VARCHAR', 2, '', '', 'Name', 'NOT NULL', '', 24, '\"<field\\r\\n\\ttype=\\\"text\\\" \\r\\n\\tname=\\\"name\\\" \\r\\n\\tlabel=\\\"Name\\\" \\r\\n\\tsize=\\\"40\\\" \\r\\n\\tmaxlength=\\\"150\\\" \\r\\n\\tdescription=\\\"Enter Name Here\\\" \\r\\n\\tclass=\\\"text_area\\\" \\r\\n\\treadonly=\\\"false\\\" \\r\\n\\tdisabled=\\\"false\\\" \\r\\n\\trequired=\\\"true\\\"\\r\\n\\tfilter=\\\"STRING\\\" \\r\\n\\tmessage=\\\"Error! Please add name here.\\\" \\r\\n\\thint=\\\"Name Here\\\" \\r\\n\\/>\"', 1, '2015-03-19 17:30:59', '2017-10-25 20:26:02', 8, '', 4),
(203, '', '', '', '', '', '', '', '', '', 1, '', 'INT', '', '', '', 'Not Required', 'NOT NULL', '', 9, '\"<field \\r\\n\\ttype=\\\"hidden\\\" \\r\\n\\tname=\\\"not_required\\\" \\r\\n\\tdefault=\\\"[]\\\" \\r\\n\\/>\"', 1, '2015-05-08 16:19:16', '2015-08-25 21:15:22', 1, '', 19),
(280, '', '', '', '', '', '', '', '', '', 255, '', 'VARCHAR', '', '', '', 'Website', 'NOT NULL', '', 27, '\"<field \\r\\n\\ttype=\\\"url\\\" \\r\\n\\tname=\\\"website\\\" \\r\\n\\tlabel=\\\"Website\\\" \\r\\n\\tsize=\\\"60\\\" \\r\\n\\tmaxlength=\\\"150\\\" \\r\\n\\tdefault=\\\"\\\" \\r\\n\\tdescription=\\\"Enter website address\\\" \\r\\n\\tclass=\\\"text_area\\\" \\r\\n\\treadonly=\\\"\\\" \\r\\n\\tdisabled=\\\"\\\" \\r\\n\\trequired=\\\"\\\" \\r\\n\\tfilter=\\\"url\\\" \\r\\n\\tvalidated=\\\"url\\\" \\r\\n\\tmessage=\\\"Error! Please add website here.\\\" \\r\\n\\thint=\\\"http:\\/\\/www.example.com\\\" \\r\\n\\/>\"', 1, '2015-04-08 00:36:16', '2015-08-25 21:15:22', 1, '', 105),
(682, '', '', '', '', '', '', '', '', '', 1, '', 'TINYINT', 2, '', '', 'Add More', 'NOT NULL', '', 17, '\"<field \\r\\n\\ttype=\\\"radio\\\" \\r\\n\\tname=\\\"add\\\" \\r\\n\\tlabel=\\\"Add More\\\" \\r\\n\\tdescription=\\\"\\\" \\r\\n\\tclass=\\\"btn-group btn-group-yesno\\\" \\r\\n\\toption=\\\"1|Yes,0|No\\\" \\r\\n\\tdefault=\\\"0\\\" \\r\\n\\trequired=\\\"true\\\" \\r\\n\\/>\"', 1, '2015-08-05 01:18:20', '2016-10-18 12:16:27', 2, '', 196),
(682, '', '', '', '', '', '', '', '', '', 1, '', 'TINYINT', 2, '', '', 'Add More', 'NOT NULL', '', 17, '\"<field \\r\\n\\ttype=\\\"radio\\\" \\r\\n\\tname=\\\"add\\\" \\r\\n\\tlabel=\\\"Add More\\\" \\r\\n\\tdescription=\\\"\\\" \\r\\n\\tclass=\\\"btn-group btn-group-yesno\\\" \\r\\n\\toption=\\\"1|Yes,0|No\\\" \\r\\n\\tdefault=\\\"0\\\" \\r\\n\\trequired=\\\"true\\\" \\r\\n\\/>\"', 1, '2015-08-05 01:18:20', '2018-03-30 09:30:45', 4, '', 196),
(1011, '', '', '', '', '', '', '', 'Other', '0000-00-00', '', '', 'DATE', '', '', '', 'Date of Birth', 'NOT NULL', '', 1, '\"<field \\r\\n\\ttype=\\\"calendar\\\" \\r\\n\\tname=\\\"dateofbirth\\\" \\r\\n\\tlabel=\\\"Date of Birth\\\" \\r\\n\\tdefault=\\\"1970-01-01\\\" \\r\\n\\tdescription=\\\"Your date of birth\\\" \\r\\n\\tclass=\\\"\\\" \\r\\n\\tformat=\\\"%Y-%m-%d\\\" \\r\\n\\tfilter=\\\"\\\" \\r\\n\\trequired=\\\"\\\" \\r\\n\\/>\"', 1, '2015-12-07 01:47:32', '2015-12-07 02:15:24', 3, '', 649);
--