From 8402051a94730c5a9b22d3debcbc0c1fdd3c406b Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Wed, 13 Jun 2018 22:38:32 +0200 Subject: [PATCH] fixed mismatch on field import of JCB packages --- README.md | 6 +- admin/README.txt | 6 +- .../en-GB/en-GB.com_componentbuilder.ini | 3 +- admin/models/import_joomla_components.php | 119 ++++++++++++++++-- admin/sql/install.mysql.utf8.sql | 3 +- componentbuilder.xml | 2 +- 6 files changed, 118 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 3ceaa0e68..2e65c774b 100644 --- a/README.md +++ b/README.md @@ -125,11 +125,11 @@ Watch the [proposed development workflow](https://vdm.bz/proposed-development-wo + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder) + *First Build*: 30th April, 2015 -+ *Last Build*: 12th June, 2018 ++ *Last Build*: 13th June, 2018 + *Version*: 2.8.0 + *Copyright*: Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **185647** ++ *Line count*: **185744** + *Field count*: **1054** + *File count*: **1236** + *Folder count*: **197** @@ -140,6 +140,6 @@ Watch the [proposed development workflow](https://vdm.bz/proposed-development-wo ## Donations Come on buy VDM a coffee :) - * PayPal: [paypal.me/asseblief](https://www.paypal.me/asseblief) + * PayPal: [paypal.me/asseblief](https://www.paypal.me/asseblief) (Asseblief = Please) in Afrikaans * Bitcoin: 18vURxYpPFjvNk8BnUy1ovCAyQmY3MzkSf * Ethereum: 0x9548144662b47327c954f3e214edb96662d51218 \ No newline at end of file diff --git a/admin/README.txt b/admin/README.txt index 3ceaa0e68..2e65c774b 100644 --- a/admin/README.txt +++ b/admin/README.txt @@ -125,11 +125,11 @@ Watch the [proposed development workflow](https://vdm.bz/proposed-development-wo + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder) + *First Build*: 30th April, 2015 -+ *Last Build*: 12th June, 2018 ++ *Last Build*: 13th June, 2018 + *Version*: 2.8.0 + *Copyright*: Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **185647** ++ *Line count*: **185744** + *Field count*: **1054** + *File count*: **1236** + *Folder count*: **197** @@ -140,6 +140,6 @@ Watch the [proposed development workflow](https://vdm.bz/proposed-development-wo ## Donations Come on buy VDM a coffee :) - * PayPal: [paypal.me/asseblief](https://www.paypal.me/asseblief) + * PayPal: [paypal.me/asseblief](https://www.paypal.me/asseblief) (Asseblief = Please) in Afrikaans * Bitcoin: 18vURxYpPFjvNk8BnUy1ovCAyQmY3MzkSf * Ethereum: 0x9548144662b47327c954f3e214edb96662d51218 \ No newline at end of file diff --git a/admin/language/en-GB/en-GB.com_componentbuilder.ini b/admin/language/en-GB/en-GB.com_componentbuilder.ini index 127af19e4..26f222bdd 100644 --- a/admin/language/en-GB/en-GB.com_componentbuilder.ini +++ b/admin/language/en-GB/en-GB.com_componentbuilder.ini @@ -1020,6 +1020,7 @@ COM_COMPONENTBUILDER_BACKUP_FAILED_PLEASE_TRY_AGAIN_IF_THE_ERROR_CONTINUE_PLEASE COM_COMPONENTBUILDER_BACKUP_LOCAL_DATA_FIRST="Backup Local Data First" COM_COMPONENTBUILDER_BACKUP_WAS_DONE_SUCCESSFULLY="Backup was done successfully" COM_COMPONENTBUILDER_BACK_TO_LIBRARIES="Back to Libraries" +COM_COMPONENTBUILDER_BADMIN_FIELDS_RELATIONSB_IDS_MISMATCH_IN_BFIELDSB_AND_WAS_NOT_UPDATED_IN_THE_CUSTOM_CODE="Admin fields relations id:%s mismatch in field:%s, and was not updated in the custom code." COM_COMPONENTBUILDER_BASIC_TUTORIAL_ON_GIT_BSB="Basic Tutorial on git: %s" COM_COMPONENTBUILDER_BBEST_TO_NOT_CONTINUEBBR_THIS_PACKAGE_BFAILEDB_CHECKSUM_VALIDATION_THIS_COULD_BE_A_SERIOUS_SECURITY_BREACH_DO_NOT_CONTINUE="Best to not continue!
This package FAILED checksum validation, this could be a serious security breach! DO NOT CONTINUE!!!" COM_COMPONENTBUILDER_BBEST_TO_NOT_CONTINUEBBR_WE_COULD_NOT_LOAD_THE_CHECKSUM_FOR_THIS_PACKAGE_AND_SO_NO_VALIDATION_WAS_POSSIBLE_THIS_MAY_BE_DUE_TO_YOUR_NETWORK_OR_A_CHANGE_TO_THAT_PACKAGE_NAME="Best to not continue!
We could not load the checksum for this package, and so no validation was possible. This may be due to your network, or a change to that package name." @@ -4707,7 +4708,7 @@ Project duration: **###projectWeekTime### weeks** or **###projectMonthTime### mo ## Donations

If you want to support this project, please consider donating:
- * PayPal: [paypal.me/asseblief](https://www.paypal.me/asseblief)
+ * PayPal: [paypal.me/asseblief](https://www.paypal.me/asseblief) (Asseblief = Please) in Afrikaans
* Bitcoin: 18vURxYpPFjvNk8BnUy1ovCAyQmY3MzkSf
* Ethereum: 0x9548144662b47327c954f3e214edb96662d51218 " diff --git a/admin/models/import_joomla_components.php b/admin/models/import_joomla_components.php index ba1de142a..9ca086665 100644 --- a/admin/models/import_joomla_components.php +++ b/admin/models/import_joomla_components.php @@ -1007,8 +1007,8 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy **/ public function updateAfterAll() { -// update the fields - if (ComponentbuilderHelper::checkArray($this->updateAfter['field'])) + // update the fields + if (isset($this->updateAfter['field']) && ComponentbuilderHelper::checkArray($this->updateAfter['field'])) { // update repeatable foreach ($this->updateAfter['field'] as $field) @@ -1070,7 +1070,7 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy } } // do a after all run on admin views that need it - if (ComponentbuilderHelper::checkArray($this->updateAfter['adminview'])) + if (isset($this->updateAfter['adminview']) && ComponentbuilderHelper::checkArray($this->updateAfter['adminview'])) { // update the addlinked_views foreach ($this->updateAfter['adminview'] as $adminview) @@ -1107,7 +1107,7 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy } } // update the joomla_component dashboard - if (ComponentbuilderHelper::checkArray($this->updateAfter['joomla_component'])) + if (isset($this->updateAfter['joomla_component']) && ComponentbuilderHelper::checkArray($this->updateAfter['joomla_component'])) { // update dashboard of the components foreach ($this->updateAfter['joomla_component'] as $component) @@ -1155,6 +1155,87 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy } } } + // update the admin_fields_relations + if (isset($this->updateAfter['relations']) && ComponentbuilderHelper::checkArray($this->updateAfter['relations'])) + { + // update repeatable + foreach ($this->updateAfter['relations'] as $relation) + { + // check if we must update this relation + $update = false; + if (isset($this->newID['admin_fields_relations'][$relation])) + { + $relation = $this->newID['admin_fields_relations'][$relation]; + } + // get the set relation from db + if ($addrelations = ComponentbuilderHelper::getVar('admin_fields_relations', $relation, 'id', 'addrelations')) + { + if (ComponentbuilderHelper::checkJson($addrelations)) + { + $addrelations = json_decode($addrelations, true); + if (ComponentbuilderHelper::checkArray($addrelations)) + { + foreach ($addrelations as $nr => &$value) + { + // reset the buckets + $bucket = array(); + // get fields + $found = ComponentbuilderHelper::getAllBetween($value['set'], '[field=', ']'); + // if found + if (ComponentbuilderHelper::checkArray($found)) + { + $bucket[] = $found; + } + // get fields + $found = ComponentbuilderHelper::getAllBetween($value['set'], '$item->{', '}'); + // if found + if (ComponentbuilderHelper::checkArray($found)) + { + $bucket[] = $found; + } + // check if we have values + if (ComponentbuilderHelper::checkArray($bucket)) + { + $fields = ComponentbuilderHelper::mergeArrays($bucket); + // reset the buckets + $bucket = array(); + if (ComponentbuilderHelper::checkArray($fields)) + { + foreach ($fields as $field) + { + if (isset($this->newID['field'][(int) $field])) + { + $bucket['[field=' . (int) $field . ']'] = '[field=' . (int) $this->newID['field'][(int) $field] . ']'; + $bucket['$item->{' . (int) $field . '}'] = '$item->{' . (int) $this->newID['field'][(int) $field] . '}'; + } + else + { + $this->app->enqueueMessage(JText::sprintf('COM_COMPONENTBUILDER_BADMIN_FIELDS_RELATIONSB_IDS_MISMATCH_IN_BFIELDSB_AND_WAS_NOT_UPDATED_IN_THE_CUSTOM_CODE', $relation, $field), 'warning'); + } + } + // check if we have a bucket of values to update + if (ComponentbuilderHelper::checkArray($bucket)) + { + $value['set'] = str_replace(array_keys($bucket), array_values($bucket), $value['set']); + $update = true; + } + } + } + } + // update only if needed + if ($update) + { + $object = new stdClass; + $object->id = $relation; + $object->addrelations = json_encode($addrelations, JSON_FORCE_OBJECT); + // update the field + $this->_db->updateObject('#__componentbuilder_admin_fields_relations', $object, 'id'); + } + } + } + } + } + } } /** @@ -2111,7 +2192,9 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy $updaterT = array( // subformfield => field => type_value 'addrelations' => array('listfield' => 'field', 'joinfields' => 'field') - ); + ); + // special fix for custom code + $this->updateAfter['relations'][$item->id] = $item->id; // addrelations->set } // update the repeatable fields @@ -2369,12 +2452,15 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy // load the created and id $query->where($this->_db->quoteName('a.created') . ' = '. $this->_db->quote($item->created)); $query->where($this->_db->quoteName('a.id') .' = '. (int) $item->id); + // set to run query $runQuery = true; } elseif (componentbuilderHelper::checkArray($get)) { foreach ($get as $field) { + // set to run query + $runQuery = true; if (isset($item->{$field})) { // set the value @@ -2399,18 +2485,21 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy } else { - return false; + // do not run query + $runQuery = false; } - $runQuery = true; } else { - return false; + // do not run query + $runQuery = false; } } } elseif (isset($item->{$get})) { + // set to run query + $runQuery = true; // set the value $value = $item->{$get}; // check if we have special value @@ -2433,9 +2522,8 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy } else { - return false; // really not needed but who knows for sure... + $runQuery = false; // really not needed but who knows for sure... } - $runQuery = true; } // since where has been set run the query if ($runQuery) @@ -2486,12 +2574,18 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy // get by name and xml to target correct field if ($retry == 2) { - // get by id name.. + // get by name + xml... $getter = array('name','datatype','store','indexes','null_switch','xml'); + $retryAgain = 3; + } + elseif ($retry == 3) + { + // get by name + created... + $getter = array('name','datatype','created'); } else { - // get by id name.. + // get by name + xml or type.. $getter = array('name','datatype','store','indexes','null_switch'); // lets try to add the fieldtype if (isset($item->fieldtype) && is_numeric($item->fieldtype) && $item->fieldtype > 0 && isset($this->newID['fieldtype'][(int) $item->fieldtype]) && $this->newID['fieldtype'][(int) $item->fieldtype] > 0) @@ -2504,6 +2598,7 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy else { $getter[] = 'xml'; + $retryAgain = 3; } } break; diff --git a/admin/sql/install.mysql.utf8.sql b/admin/sql/install.mysql.utf8.sql index bafe37946..139120b40 100644 --- a/admin/sql/install.mysql.utf8.sql +++ b/admin/sql/install.mysql.utf8.sql @@ -1678,7 +1678,8 @@ INSERT INTO `#__componentbuilder_admin_fields_relations` (`id`, `addrelations`, (1, '', 14, 1, '2018-05-22 01:20:34', '2018-05-23 03:37:27', 9, '', 1), (2, '', 22, 1, '2018-05-23 03:38:52', '2018-05-26 07:37:25', 18, '', 2), (3, '', 13, 1, '2018-05-24 17:04:40', '2018-05-24 17:12:52', 4, '', 3), -(4, '{\"addrelations0\":{\"listfield\":\"913\",\"column_name\":\"Preacher Details\",\"joinfields\":[\"691\"],\"area\":\"2\",\"join_type\":\"1\",\"set\":\"
\"}}', 54, 1, '2018-05-28 07:00:41', '2018-05-28 09:45:25', 7, '', 4); +(4, '{\"addrelations0\":{\"listfield\":\"913\",\"column_name\":\"Preacher Details\",\"joinfields\":[\"691\"],\"area\":\"2\",\"join_type\":\"1\",\"set\":\"
\"}}', 54, 1, '2018-05-28 07:00:41', '2018-05-28 09:45:25', 7, '', 4), +(5, '{\"addrelations0\":{\"listfield\":\"2209\",\"column_name\":\"Member\",\"joinfields\":[\"1004\",\"1207\",\"1302\",\"1005\",\"280\"],\"area\":\"2\",\"join_type\":\"2\",\"set\":\"[field=2209]\\r\\n{1005})): ?>\\r\\n
\\r\\n[field=1005]\\r\\n\\r\\n{1004})): ?>\\r\\n
\\r\\n[field=1004]\\r\\n\\r\\n{1302})): ?>\\r\\n
\\r\\n[field=1302]\\r\\n\\r\\n{1207})): ?>\\r\\n
\\r\\n[field=1207]\\r\\n\\r\\n{280})): ?>\\r\\n
\\r\\n[field=280]\\r\\n\"},\"addrelations1\":{\"listfield\":\"608\",\"column_name\":\"Phone\",\"joinfields\":[\"1160\"],\"area\":\"2\",\"join_type\":\"2\",\"set\":\"{608})): ?>\\r\\n[field=608]\\r\\n\\r\\n{1160})): ?>\\r\\n{608})): ?>
\\r\\n[field=1160]\\r\\n\"}}', 177, 1, '2018-06-12 21:23:39', '0000-00-00 00:00:00', 1, '', 5); -- -- Dumping data for table `#__componentbuilder_component_admin_views` diff --git a/componentbuilder.xml b/componentbuilder.xml index 575132e9f..0dcb0371d 100644 --- a/componentbuilder.xml +++ b/componentbuilder.xml @@ -1,7 +1,7 @@ COM_COMPONENTBUILDER - 12th June, 2018 + 13th June, 2018 Llewellyn van der Merwe llewellyn@joomlacomponentbuilder.com http://www.joomlacomponentbuilder.com