Resolved gh-436 so that the new Joomla plugin builder/feature is fully active, and part of the import and export of JCB packages.

This commit is contained in:
2019-08-12 23:30:31 +02:00
parent ed43b00862
commit 7fed9d7a1c
16 changed files with 519 additions and 127 deletions

View File

@ -2413,10 +2413,11 @@ class ComponentbuilderModelAjax extends JModelList
),
// #__componentbuilder_joomla_plugin (q)
'joomla_plugin' => array(
'search' => array('id', 'name', 'main_class_code'),
'search' => array('id', 'system_name', 'name', 'main_class_code', 'description', 'php_script_construct', 'php_preflight_install', 'php_preflight_update',
'php_preflight_uninstall', 'php_postflight_install', 'php_postflight_update', 'php_method_uninstall'),
'views' => 'joomla_plugins',
'not_base64' => array(),
'name' => 'name'
'not_base64' => array('description' => 'string'),
'name' => 'system_name'
),
// #__componentbuilder_class_extends (r)
'class_extends' => array(

View File

@ -163,15 +163,15 @@ class ComponentbuilderModelCompiler extends JModelList
$set['placeholders'] = $addPlaceholders;
$set['debuglinenr'] = $debugLinenr;
$set['minify'] = $minify;
// start up Compiler
$this->compiler = new Compiler($set);
// run compiler
$this->compiler = new Compiler($set);
if($this->compiler)
{
return true;
}
return false;
}
public function emptyFolder($dir, $removeDir = false)
{
jimport('joomla.filesystem.folder');
@ -210,7 +210,7 @@ class ComponentbuilderModelCompiler extends JModelList
}
return false;
}
public function install($p_file)
{
$this->setState('action', 'install');
@ -238,7 +238,7 @@ class ComponentbuilderModelCompiler extends JModelList
{
return false;
}
$config = JFactory::getConfig();
$tmp_dest = $config->get('tmp_path');
@ -259,7 +259,7 @@ class ComponentbuilderModelCompiler extends JModelList
{
return false;
}
// Was the package unpacked?
if (!$package || !$package['type'])
{
@ -280,7 +280,7 @@ class ComponentbuilderModelCompiler extends JModelList
}
else
{
// Package installed sucessfully.
// Package installed successfully.
$msg = JText::sprintf('COM_INSTALLER_INSTALL_SUCCESS', JText::_('COM_INSTALLER_TYPE_TYPE_' . strtoupper($package['type'])));
$result = true;
$msgType = 'message';

View File

@ -86,7 +86,7 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
protected $specialValue = false;
protected $checksum = null;
protected $checksumURLs = array('vdm' => 'https://raw.githubusercontent.com/vdm-io/JCB-Packages/master/', 'jcb' => 'https://raw.githubusercontent.com/vdm-io/JCB-Community-Packages/master/');
protected $mustMerge = array('validation_rule', 'fieldtype', 'snippet', 'language', 'language_translation');
protected $mustMerge = array('validation_rule', 'fieldtype', 'snippet', 'language', 'language_translation', 'class_extends', 'class_property', 'class_method', 'joomla_plugin_group');
/**
* Import an spreadsheet from either folder, url or upload.
@ -698,12 +698,13 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
}
// the array of tables to store
$tables = array(
'validation_rule','class_extends', 'fieldtype', 'field', 'admin_view', 'snippet', 'dynamic_get', 'custom_admin_view', 'site_view','joomla_plugin_group',
'template', 'layout', 'joomla_component', 'language', 'language_translation', 'custom_code', 'placeholder','class_property','class_method','joomla_plugin',
'validation_rule', 'fieldtype', 'field', 'admin_view', 'snippet', 'dynamic_get', 'custom_admin_view', 'site_view',
'template', 'layout', 'joomla_component', 'language', 'language_translation', 'custom_code', 'placeholder', 'class_extends',
'joomla_plugin_group', 'class_property', 'class_method', 'joomla_plugin', 'joomla_plugin_files_folders_urls', 'joomla_plugin_updates',
'admin_fields', 'admin_fields_conditions', 'admin_fields_relations', 'admin_custom_tabs', 'component_admin_views',
'component_site_views', 'component_custom_admin_views', 'component_updates', 'component_mysql_tweaks',
'component_custom_admin_menus', 'component_config', 'component_dashboard', 'component_files_folders',
'component_placeholders','component_plugins'
'component_placeholders', 'component_plugins'
);
// get prefix
$prefix = $this->_db->getPrefix();
@ -2096,6 +2097,56 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
// update the repeatable fields
$item = ComponentbuilderHelper::convertRepeatableFields($item, $updaterR);
break;
case 'joomla_plugin_group':
// diverged id already updated
if (!$diverged)
{
// update the class_extends ID where needed
$item = $this->setNewID($item, 'class_extends', 'class_extends', $type);
}
break;
case 'class_method':
case 'class_property':
// diverged id already updated
if (!$diverged)
{
// update the joomla_plugin_group ID where needed
$item = $this->setNewID($item, 'joomla_plugin_group', 'joomla_plugin_group', $type);
}
break;
case 'joomla_plugin':
// diverged id already updated
if (!$diverged)
{
// update the class_extends ID where needed
$item = $this->setNewID($item, 'class_extends', 'class_extends', $type);
// update the joomla_plugin_group ID where needed
$item = $this->setNewID($item, 'joomla_plugin_group', 'joomla_plugin_group', $type);
}
// if we can't merge add postfix to name
if ($this->postfix)
{
$item->system_name = $item->system_name.$this->postfix;
}
// subform fields to target
$updaterT = array(
// subformfield => array( field => type_value )
'fields' => array('field' => 'field'),
'property_selection' => array('property' => 'class_property'),
'method_selection' => array('method' => 'class_method')
);
// update the subform ids
$this->updateSubformsIDs($item, 'joomla_plugin', $updaterT);
break;
case 'joomla_plugin_files_folders_urls':
case 'joomla_plugin_updates':
// diverged id already updated
if (!$diverged)
{
// update the joomla_plugin ID where needed
$item = $this->setNewID($item, 'joomla_plugin', 'joomla_plugin', $type);
}
break;
case 'custom_code':
// update the component ID where needed
$item = $this->setNewID($item, 'component', 'joomla_component', $type);
@ -2874,8 +2925,8 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
case 'component_config':
case 'component_dashboard':
case 'component_placeholders':
case 'component_plugins':
case 'component_files_folders':
case 'component_plugins':
// get by joomla_component (since there should only be one of each component)
$getter = array('joomla_component');
$this->specialValue = array();
@ -2903,8 +2954,109 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
}
break;
case 'language':
// get by language tag since there should just be one
$getter = 'langtag';
// get by language tag since there should just be one
$getter = 'langtag';
break;
case 'joomla_plugin':
// get
if ($retry == 3)
{
// get by names, exteneded and group only
$getter = array('name', 'system_name', 'class_extends', 'joomla_plugin_group');
}
elseif ($retry == 2)
{
// get by description
$getter = array('name', 'system_name', 'class_extends', 'joomla_plugin_group', 'description');
$retryAgain = 3;
}
else
{
// get by id
$getter = array('id', 'name', 'system_name', 'class_extends', 'joomla_plugin_group');
$retryAgain = 2;
}
$this->specialValue = array();
// Yet if diverged it makes sense that the ID is updated.
if ($diverged)
{
$this->specialValue['class_extends'] = (int) $item->class_extends;
$this->specialValue['joomla_plugin_group'] = (int) $item->joomla_plugin_group;
}
elseif (isset($this->newID['class_extends'][(int) $item->class_extends]) && isset($this->newID['joomla_plugin_group'][(int) $item->joomla_plugin_group]))
{
$this->specialValue['class_extends'] = $this->newID['class_extends'][(int) $item->class_extends];
$this->specialValue['joomla_plugin_group'] = $this->newID['joomla_plugin_group'][(int) $item->joomla_plugin_group];
}
// (TODO) I have seen this happen, seems dangerous!
else
{
return false;
}
break;
case 'joomla_plugin_files_folders_urls':
case 'joomla_plugin_updates':
// get by admin_view (since there should only be one of each name)
$getter = array('joomla_plugin');
$this->specialValue = array();
// Yet if diverged it makes sense that the ID is updated.
if ($diverged)
{
$this->specialValue['joomla_plugin'] = (int) $item->joomla_plugin;
}
elseif (isset($this->newID['joomla_plugin'][(int) $item->joomla_plugin]))
{
$this->specialValue['joomla_plugin'] = $this->newID['joomla_plugin'][(int) $item->joomla_plugin];
}
// (TODO) I have seen this happen, seems dangerous!
else
{
return false;
}
break;
case 'joomla_plugin_group':
// get by name since there should just be one
$getter = array('name', 'class_extends');
$this->specialValue = array();
// Yet if diverged it makes sense that the ID is updated.
if ($diverged)
{
$this->specialValue['class_extends'] = (int) $item->class_extends;
}
elseif (isset($this->newID['class_extends'][(int) $item->class_extends]))
{
$this->specialValue['class_extends'] = $this->newID['class_extends'][(int) $item->class_extends];
}
// (TODO) I have seen this happen, seems dangerous!
else
{
return false;
}
break;
case 'class_extends':
case 'class_method':
case 'class_property':
// get by name since there should just be one
$getter = array('name', 'extension_type');
// Yet if diverged it makes sense that the ID is updated.
if ('plugins' === $item->extension_type && isset($item->joomla_plugin_group))
{
$getter[] = 'joomla_plugin_group';
$this->specialValue = array();
if ($diverged)
{
$this->specialValue['joomla_plugin_group'] = (int) $item->joomla_plugin_group;
}
elseif (isset($this->newID['joomla_plugin_group'][(int) $item->joomla_plugin_group]))
{
$this->specialValue['joomla_plugin_group'] = $this->newID['joomla_plugin_group'][(int) $item->joomla_plugin_group];
}
// (TODO) I have seen this happen, seems dangerous!
else
{
return false;
}
}
break;
default:
// can't be found so return false

View File

@ -303,7 +303,8 @@ class ComponentbuilderModelJoomla_components extends JModelList
'component_mysql_tweaks' => 'joomla_component',
'component_custom_admin_menus' => 'joomla_component',
'component_dashboard' => 'joomla_component',
'component_placeholders' => 'joomla_component' );
'component_placeholders' => 'joomla_component',
'component_plugins' => 'joomla_component');
// load all tables linked to joomla_component
foreach($linkedTables as $table => $field)
{
@ -317,6 +318,13 @@ class ComponentbuilderModelJoomla_components extends JModelList
$this->setData('admin_fields_relations', array_values($this->smartIDs['admin_view']), 'admin_view');
$this->setData('admin_custom_tabs', array_values($this->smartIDs['admin_view']), 'admin_view');
}
// add joomla plugin
if (isset($this->smartIDs['joomla_plugin']) && ComponentbuilderHelper::checkArray($this->smartIDs['joomla_plugin']))
{
$this->setData('joomla_plugin', array_values($this->smartIDs['joomla_plugin']), 'id');
$this->setData('joomla_plugin_updates', array_values($this->smartIDs['joomla_plugin']), 'joomla_plugin');
$this->setData('joomla_plugin_files_folders_urls', array_values($this->smartIDs['joomla_plugin']), 'joomla_plugin');
}
// add validation rules
if (isset($this->smartIDs['validation_rule']) && ComponentbuilderHelper::checkArray($this->smartIDs['validation_rule']))
{
@ -345,6 +353,26 @@ class ComponentbuilderModelJoomla_components extends JModelList
// only if exporting
if ('clone' !== $this->activeType)
{
// add class_property
if (isset($this->smartIDs['class_property']) && ComponentbuilderHelper::checkArray($this->smartIDs['class_property']))
{
$this->setData('class_property', array_values($this->smartIDs['class_property']), 'id');
}
// add class_method
if (isset($this->smartIDs['class_method']) && ComponentbuilderHelper::checkArray($this->smartIDs['class_method']))
{
$this->setData('class_method', array_values($this->smartIDs['class_method']), 'id');
}
// add joomla_plugin_group
if (isset($this->smartIDs['joomla_plugin_group']) && ComponentbuilderHelper::checkArray($this->smartIDs['joomla_plugin_group']))
{
$this->setData('joomla_plugin_group', array_values($this->smartIDs['joomla_plugin_group']), 'id');
}
// add class_extends
if (isset($this->smartIDs['class_extends']) && ComponentbuilderHelper::checkArray($this->smartIDs['class_extends']))
{
$this->setData('class_extends', array_values($this->smartIDs['class_extends']), 'id');
}
// add snippets
if (isset($this->smartIDs['snippet']) && ComponentbuilderHelper::checkArray($this->smartIDs['snippet']))
{
@ -612,7 +640,7 @@ class ComponentbuilderModelJoomla_components extends JModelList
// set search array
if ('site_view' === $table || 'custom_admin_view' === $table)
{
$searchArray = array('php_view','php_jview','php_jview_display','php_document','js_document','css_document','css');
$searchArray = array('php_view', 'php_jview', 'php_jview_display', 'php_document', 'js_document', 'css_document', 'css');
}
// reset the global array
if ('template' === $table)
@ -683,7 +711,7 @@ class ComponentbuilderModelJoomla_components extends JModelList
// set the placeholder ID's
$this->setCodePlaceholdersIds($item, $table, 'placeholder');
// actions to take if table is component_files_folders
if ('component_files_folders' === $table && 'clone' !== $this->activeType)
if (('component_files_folders' === $table || 'joomla_plugin_files_folders_urls' === $table) && 'clone' !== $this->activeType)
{
// build files
$this->moveIt($this->getValues($item->addfiles, 'subform', 'file', null), 'file');
@ -718,6 +746,12 @@ class ComponentbuilderModelJoomla_components extends JModelList
// add custom admin views
$this->setData('custom_admin_view', $this->getValues($item->addcustom_admin_views, 'subform', 'customadminview'), 'id');
}
// actions to take if table is component_plugins
if ('component_plugins' === $table)
{
// add custom admin views
$this->setData('joomla_plugin', $this->getValues($item->addjoomla_plugins, 'subform', 'plugin'), 'id');
}
// actions to take if table is admin_view
if ('admin_view' === $table)
{
@ -845,6 +879,34 @@ class ComponentbuilderModelJoomla_components extends JModelList
// add dynamic gets
$this->setSmartIDs((int) $item->dynamic_get, 'dynamic_get');
}
// actions to take if table is joomla_plugin
if ('joomla_plugin' === $table)
{
// add the updates and folder stuff
$this->setSmartIDs($item->id, 'joomla_plugin');
// add class_extends
$this->setSmartIDs((int) $item->class_extends, 'class_extends');
// add joomla_plugin_group
$this->setSmartIDs((int) $item->joomla_plugin_group, 'joomla_plugin_group');
// add fields
$this->setData('field', $this->getValues($item->fields, 'subform', 'field'), 'id');
// add property_selection
$this->setData('class_property', $this->getValues($item->property_selection, 'subform', 'property'), 'id');
// add class_method
$this->setData('class_method', $this->getValues($item->method_selection, 'subform', 'method'), 'id');
}
// actions to take if table is joomla_plugin_group
if ('joomla_plugin_group' === $table)
{
// add class_extends
$this->setSmartIDs((int) $item->class_extends, 'class_extends');
}
// actions to take if table is class_method or
if ('class_method' === $table || 'class_property' === $table )
{
// add joomla_plugin_group
$this->setSmartIDs((int) $item->joomla_plugin_group, 'joomla_plugin_group');
}
}
}
}
@ -882,10 +944,11 @@ class ComponentbuilderModelJoomla_components extends JModelList
$tables = array(
'fieldtype', 'field', 'admin_view', 'snippet', 'dynamic_get', 'custom_admin_view', 'site_view',
'template', 'layout', 'joomla_component', 'language', 'language_translation', 'custom_code', 'placeholder',
'joomla_plugin', 'joomla_plugin_files_folders_urls', 'joomla_plugin_updates',
'admin_fields', 'admin_fields_conditions', 'admin_fields_relations', 'admin_custom_tabs', 'component_admin_views',
'component_site_views', 'component_custom_admin_views', 'component_updates', 'component_mysql_tweaks',
'component_custom_admin_menus', 'component_config', 'component_dashboard', 'component_files_folders',
'component_placeholders'
'component_placeholders', 'component_plugins'
);
// smart table loop
foreach ($tables as $table)
@ -1824,10 +1887,11 @@ class ComponentbuilderModelJoomla_components extends JModelList
),
// #__componentbuilder_joomla_plugin (q)
'joomla_plugin' => array(
'search' => array('id', 'name', 'main_class_code'),
'search' => array('id', 'system_name', 'name', 'main_class_code', 'description', 'php_script_construct', 'php_preflight_install', 'php_preflight_update',
'php_preflight_uninstall', 'php_postflight_install', 'php_postflight_update', 'php_method_uninstall'),
'views' => 'joomla_plugins',
'not_base64' => array(),
'name' => 'name'
'not_base64' => array('description' => 'string'),
'name' => 'system_name'
),
// #__componentbuilder_class_extends (r)
'class_extends' => array(

View File

@ -136,17 +136,13 @@ class ComponentbuilderModelJoomla_plugins extends JModelList
// extract the boilerplate class property and methods
if (($classProperiesMethods = ComponentbuilderHelper::extractBoilerplateClassPropertiesMethods($fooClass, $classExtends, 'plugins', $pluginGroupID)) !== false)
{
// create the properties found (TODO just create for now but we could later add a force update)
// create the properties found
if (isset($classProperiesMethods['property']) && ComponentbuilderHelper::checkArray($classProperiesMethods['property']))
{
foreach ($classProperiesMethods['property'] as $_property)
{
// does not exist, so create
if ($_property['id'] == 0)
{
// store the property
$this->storePluginBoilerplate($tables['p'], $models['p'], $_property, $app);
}
// force update by default
$this->storePluginBoilerplate($tables['p'], $models['p'], $_property, $app);
}
}
// create the method found (TODO just create for now but we could later add a force update)
@ -154,12 +150,8 @@ class ComponentbuilderModelJoomla_plugins extends JModelList
{
foreach ($classProperiesMethods['method'] as $_method)
{
// does not exist, so create
if ($_method['id'] == 0)
{
// store the method
$this->storePluginBoilerplate($tables['m'], $models['m'], $_method, $app);
}
// force update by default
$this->storePluginBoilerplate($tables['m'], $models['m'], $_method, $app);
}
}
}