Added the table and field validation to avoid import breakages due to new table or fields not found in the older local install of JCB.

This commit is contained in:
Llewellyn van der Merwe 2018-07-07 02:12:13 +02:00
parent 9fd59f2353
commit 3a4a0e613b
No known key found for this signature in database
GPG Key ID: CAD7B16D27AF28C5
7 changed files with 78 additions and 10 deletions

View File

@ -125,11 +125,11 @@ 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*: 6th July, 2018 + *Last Build*: 7th July, 2018
+ *Version*: 2.8.2 + *Version*: 2.8.2
+ *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
+ *Line count*: **186219** + *Line count*: **186287**
+ *Field count*: **1058** + *Field count*: **1058**
+ *File count*: **1238** + *File count*: **1238**
+ *Folder count*: **197** + *Folder count*: **197**

View File

@ -125,11 +125,11 @@ 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*: 6th July, 2018 + *Last Build*: 7th July, 2018
+ *Version*: 2.8.2 + *Version*: 2.8.2
+ *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
+ *Line count*: **186219** + *Line count*: **186287**
+ *Field count*: **1058** + *Field count*: **1058**
+ *File count*: **1238** + *File count*: **1238**
+ *Folder count*: **197** + *Folder count*: **197**

View File

@ -3896,6 +3896,7 @@ COM_COMPONENTBUILDER_FIELD_ADD_JAVASCRIPT_VIEW_FOOTER_LABEL="Add JavaScript (vie
COM_COMPONENTBUILDER_FIELD_BASESIXTY_FOUR="base64" COM_COMPONENTBUILDER_FIELD_BASESIXTY_FOUR="base64"
COM_COMPONENTBUILDER_FIELD_BASIC_ENCRYPTION_LOCALDBKEY="Basic Encryption (local-DB-key)" COM_COMPONENTBUILDER_FIELD_BASIC_ENCRYPTION_LOCALDBKEY="Basic Encryption (local-DB-key)"
COM_COMPONENTBUILDER_FIELD_BIGINT="BIGINT" COM_COMPONENTBUILDER_FIELD_BIGINT="BIGINT"
COM_COMPONENTBUILDER_FIELD_BSB_NOT_FOUND_IN_LOCAL_DATABASE_TABLE_S_SO_IMPORTED_OF_ITS_VALUES_FAILED_PLEASE_UPDATE_YOUR_JCB_INSTALL_AND_TRY_AGAIN="Field <b>%s</b> not found in local database table (%s) so imported of its values failed, please update your JCB install and try again."
COM_COMPONENTBUILDER_FIELD_CATID_DESCRIPTION="select one of the following categories" COM_COMPONENTBUILDER_FIELD_CATID_DESCRIPTION="select one of the following categories"
COM_COMPONENTBUILDER_FIELD_CATID_LABEL="Category" COM_COMPONENTBUILDER_FIELD_CATID_LABEL="Category"
COM_COMPONENTBUILDER_FIELD_CHAR="CHAR" COM_COMPONENTBUILDER_FIELD_CHAR="CHAR"
@ -6416,6 +6417,7 @@ COM_COMPONENTBUILDER_S_BEING_IMPORTED="%s Being Imported"
COM_COMPONENTBUILDER_S_NOT_LINKED="%s Not Linked" COM_COMPONENTBUILDER_S_NOT_LINKED="%s Not Linked"
COM_COMPONENTBUILDER_S_PLEASE_WAIT_THE_COMPONENT_IS_BEING_COMPILED="%s, please wait! The component is being compiled" COM_COMPONENTBUILDER_S_PLEASE_WAIT_THE_COMPONENT_IS_BEING_COMPILED="%s, please wait! The component is being compiled"
COM_COMPONENTBUILDER_TAB="Tab" COM_COMPONENTBUILDER_TAB="Tab"
COM_COMPONENTBUILDER_TABLE_BSB_NOT_FOUND_IN_THE_LOCAL_DATABASE_SO_ITS_VALUES_COULD_NOT_BE_IMPORTED_PLEASE_UPDATE_YOUR_JCB_INSTALL_AND_TRY_AGAIN="Table <b>%s</b> not found in the local database so its values could not be imported, please update your JCB install and try again."
COM_COMPONENTBUILDER_TARGET_BEHAVIOUR="Target Behaviour" COM_COMPONENTBUILDER_TARGET_BEHAVIOUR="Target Behaviour"
COM_COMPONENTBUILDER_TARGET_FIELDS="Target Field/s" COM_COMPONENTBUILDER_TARGET_FIELDS="Target Field/s"
COM_COMPONENTBUILDER_TARGET_PATH="Target Path" COM_COMPONENTBUILDER_TARGET_PATH="Target Path"

View File

@ -2117,7 +2117,7 @@ class ComponentbuilderModelAjax extends JModelList
'php_after_delete','php_after_publish','php_ajaxmethod','php_allowedit','php_batchcopy', 'php_after_delete','php_after_publish','php_ajaxmethod','php_allowedit','php_batchcopy',
'php_batchmove','php_before_delete','php_before_publish','php_before_save','php_controller', 'php_batchmove','php_before_delete','php_before_publish','php_before_save','php_controller',
'php_controller_list','php_document','php_getitem','php_getitems','php_getitems_after_all', 'php_controller_list','php_document','php_getitem','php_getitems','php_getitems_after_all',
'php_getlistquery','php_import','php_import_display','php_import_ext','php_import_headers', 'php_getlistquery','php_import','php_import_display','php_import_ext','php_import_headers','php_getform',
'php_import_save','php_import_setdata','php_model','php_model_list','php_postsavehook','php_save'); 'php_import_save','php_import_setdata','php_model','php_model_list','php_postsavehook','php_save');
$targets['admin_view']['view'] = 'admin_views'; $targets['admin_view']['view'] = 'admin_views';
$targets['admin_view']['not_base64'] = array(); $targets['admin_view']['not_base64'] = array();

View File

@ -81,6 +81,8 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
protected $divergedDataMover = array(); protected $divergedDataMover = array();
protected $fieldTypes = array(); protected $fieldTypes = array();
protected $isMultiple = array(); protected $isMultiple = array();
protected $tableColumns = array();
protected $fieldImportErrors = array();
protected $specialValue = false; protected $specialValue = false;
protected $checksum = null; 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 $checksumURLs = array('vdm' => 'https://raw.githubusercontent.com/vdm-io/JCB-Packages/master/', 'jcb' => 'https://raw.githubusercontent.com/vdm-io/JCB-Community-Packages/master/');
@ -702,13 +704,25 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
'component_custom_admin_views', 'component_updates', 'component_mysql_tweaks', 'component_custom_admin_views', 'component_updates', 'component_mysql_tweaks',
'component_custom_admin_menus', 'component_config', 'component_dashboard', 'component_files_folders' 'component_custom_admin_menus', 'component_config', 'component_dashboard', 'component_files_folders'
); );
// get prefix
$prefix = $this->_db->getPrefix();
// get local tables
$localTables = $this->_db->getTableList();
// smart table loop // smart table loop
foreach ($tables as $table) foreach ($tables as $table)
{ {
// save the table to database // only continue the import if the table is available locally
if (!$this->saveSmartItems($table)) if (in_array($prefix . 'componentbuilder_' . $table, $localTables))
{ {
return false; // save the table to database
if (!$this->saveSmartItems($table))
{
return false;
}
}
else
{
$this->app->enqueueMessage(JText::sprintf('COM_COMPONENTBUILDER_TABLE_BSB_NOT_FOUND_IN_THE_LOCAL_DATABASE_SO_ITS_VALUES_COULD_NOT_BE_IMPORTED_PLEASE_UPDATE_YOUR_JCB_INSTALL_AND_TRY_AGAIN', '#__componentbuilder_' . $table), 'warning');
} }
} }
// do a after all run on all items that need it // do a after all run on all items that need it
@ -2205,6 +2219,8 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
// update the subform ids // update the subform ids
$this->updateSubformsIDs($item, $type, $updaterT); $this->updateSubformsIDs($item, $type, $updaterT);
} }
// remove all fields/columns not part of the current table
$this->removingFields($type, $item);
// final action prep // final action prep
switch($action) switch($action)
{ {
@ -2236,6 +2252,56 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
return false; return false;
} }
/**
* remove all fields/columns not part of the current table
*
* @param string $type The table this item belongs to
* @param object $item The item to clean
*
* @return viod
*/
protected function removingFields($type, &$item)
{
// get the columns
$columns = $this->getTableColumns("#__componentbuilder_" . $type);
if (ComponentbuilderHelper::checkArray($columns))
{
foreach ($item as $name => $value)
{
if (!isset($columns[$name]))
{
// we must show a warning that this field was not imported (but just once)
if (!isset($this->fieldImportErrors[$type.$name]))
{
$this->app->enqueueMessage(JText::sprintf('COM_COMPONENTBUILDER_FIELD_BSB_NOT_FOUND_IN_LOCAL_DATABASE_TABLE_S_SO_IMPORTED_OF_ITS_VALUES_FAILED_PLEASE_UPDATE_YOUR_JCB_INSTALL_AND_TRY_AGAIN', $name, '#__componentbuilder_' . $type), 'warning');
// make sure the message is not loaded again
$this->fieldImportErrors[$type.$name] = true;
}
// remove the field & value
unset($item->{$name});
}
}
}
}
/**
* get table columns
*
* @param string $table The table
*
* @return array
*/
protected function getTableColumns($table)
{
// check if the columns are in memory
if (!isset($this->tableColumns[$table]))
{
// get the columns
$this->tableColumns[$table] = $this->_db->getTableColumns($table);
}
return $this->tableColumns[$table];
}
/** /**
* Set the data that should be moved * Set the data that should be moved
* *

View File

@ -1607,7 +1607,7 @@ class ComponentbuilderModelJoomla_components extends JModelList
'php_after_delete','php_after_publish','php_ajaxmethod','php_allowedit','php_batchcopy', 'php_after_delete','php_after_publish','php_ajaxmethod','php_allowedit','php_batchcopy',
'php_batchmove','php_before_delete','php_before_publish','php_before_save','php_controller', 'php_batchmove','php_before_delete','php_before_publish','php_before_save','php_controller',
'php_controller_list','php_document','php_getitem','php_getitems','php_getitems_after_all', 'php_controller_list','php_document','php_getitem','php_getitems','php_getitems_after_all',
'php_getlistquery','php_import','php_import_display','php_import_ext','php_import_headers', 'php_getlistquery','php_import','php_import_display','php_import_ext','php_import_headers','php_getform',
'php_import_save','php_import_setdata','php_model','php_model_list','php_postsavehook','php_save'); 'php_import_save','php_import_setdata','php_model','php_model_list','php_postsavehook','php_save');
$targets['admin_view']['view'] = 'admin_views'; $targets['admin_view']['view'] = 'admin_views';
$targets['admin_view']['not_base64'] = array(); $targets['admin_view']['not_base64'] = array();

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>6th July, 2018</creationDate> <creationDate>7th July, 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>