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

This commit is contained in:
2018-03-30 11:32:22 +02:00
parent af1e76d21e
commit 0a4b8f067f
5 changed files with 40 additions and 14 deletions

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)