Fixed some collusion issue in the dynamic get build process when custom query is used. Fixed the issue found in the import of JCB packages that caused custom code to be imported in duplication, also added the option to turn off (unpublish) custom code no longer in use.

This commit is contained in:
Llewellyn van der Merwe 2018-08-30 18:33:30 +02:00
parent be0d61ceae
commit b3c4414320
No known key found for this signature in database
GPG Key ID: CAD7B16D27AF28C5
12 changed files with 412 additions and 281 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*: 25th August, 2018 + *Last Build*: 30th August, 2018
+ *Version*: 2.9.0 + *Version*: 2.9.0
+ *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*: **192685** + *Line count*: **192775**
+ *Field count*: **1081** + *Field count*: **1081**
+ *File count*: **1273** + *File count*: **1273**
+ *Folder count*: **201** + *Folder count*: **201**

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*: 25th August, 2018 + *Last Build*: 30th August, 2018
+ *Version*: 2.9.0 + *Version*: 2.9.0
+ *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*: **192685** + *Line count*: **192775**
+ *Field count*: **1081** + *Field count*: **1081**
+ *File count*: **1273** + *File count*: **1273**
+ *Folder count*: **201** + *Folder count*: **201**

View File

@ -1554,7 +1554,7 @@ class Get
// set the view name // set the view name
$tab['view'] = $name_single; $tab['view'] = $name_single;
// load the dynamic data // load the dynamic data
$tab['html'] = $this->setDynamicValues($tab['html']); $tab['html'] = $this->setPlaceholders($this->setDynamicValues($tab['html']), $this->placeholders);
// set the tab name // set the tab name
$tab['name'] = (isset($tab['name']) && ComponentbuilderHelper::checkString($tab['name'])) ? $tab['name'] : 'Tab'; $tab['name'] = (isset($tab['name']) && ComponentbuilderHelper::checkString($tab['name'])) ? $tab['name'] : 'Tab';
// set lang // set lang
@ -2927,10 +2927,30 @@ class Get
unset($result->db_selection); unset($result->db_selection);
break; break;
case 3: case 3:
// get the custom query
$customQueryString = $this->setDynamicValues(base64_decode($result->php_custom_get));
// get the table name
$_searchQuery = ComponentbuilderHelper::getBetween($customQueryString, '$query->from(', ')');
if (ComponentbuilderHelper::checkString($_searchQuery) && strpos($_searchQuery, '#__') !== false)
{
$_queryName = ComponentbuilderHelper::getBetween($_searchQuery, '#__', "'");
if (!ComponentbuilderHelper::checkString($_queryName))
{
$_queryName = ComponentbuilderHelper::getBetween($_searchQuery, '#__', '"');
}
}
// set to blank if not found
if (!isset($_queryName) || !ComponentbuilderHelper::checkString($_queryName))
{
$_queryName = '';
}
// set custom script // set custom script
$result->main_get[0]['selection'] = array( $result->main_get[0]['selection'] = array(
'select' => $this->setDynamicValues(base64_decode($result->php_custom_get)), 'select' => $customQueryString,
'from' => '', 'table' => '', 'type' => ''); 'from' => '', 'table' => '', 'type' => '', 'name' => $_queryName);
$result->main_get[0]['as'] = 'a';
$result->main_get[0]['key'] = $result->key;
$result->main_get[0]['context'] = $context;
break; break;
} }
// set join_view_table details // set join_view_table details

View File

@ -1608,7 +1608,8 @@ class Interpretation extends Fields
} }
// set the method defaults // set the method defaults
$default = $this->setCustomViewMethodDefaults($the_get, $code); if (($default = $this->setCustomViewMethodDefaults($the_get, $code)) !== false)
{
if (isset($this->siteDynamicGet[$this->target][$default['code']][$default['as']][$default['join_field']]) && ComponentbuilderHelper::checkString($this->siteDynamicGet[$this->target][$default['code']][$default['as']][$default['join_field']]) && !in_array($check, $mainAsArray)) if (isset($this->siteDynamicGet[$this->target][$default['code']][$default['as']][$default['join_field']]) && ComponentbuilderHelper::checkString($this->siteDynamicGet[$this->target][$default['code']][$default['as']][$default['join_field']]) && !in_array($check, $mainAsArray))
{ {
// load to other query // load to other query
@ -1626,6 +1627,7 @@ class Interpretation extends Fields
} }
} }
} }
}
return $query; return $query;
} }
@ -1886,7 +1888,8 @@ class Interpretation extends Fields
foreach ($gets as $get) foreach ($gets as $get)
{ {
// set the value name $default // set the value name $default
$default = $this->setCustomViewMethodDefaults($get, $code); if (($default = $this->setCustomViewMethodDefaults($get, $code)) !== false)
{
if ($this->checkJoint($default, $get, $asBucket)) if ($this->checkJoint($default, $get, $asBucket))
{ {
// build custom join string // build custom join string
@ -1906,6 +1909,7 @@ class Interpretation extends Fields
$customJoin .= PHP_EOL . $this->_t(1) . $tab . $this->_t(1) . $string . "->" . $default['valueName'] . " = \$this->get" . $default['methodName'] . "(" . $string . "->" . $this->getAsLookup[$get['key']][$get['on_field']] . ");"; $customJoin .= PHP_EOL . $this->_t(1) . $tab . $this->_t(1) . $string . "->" . $default['valueName'] . " = \$this->get" . $default['methodName'] . "(" . $string . "->" . $this->getAsLookup[$get['key']][$get['on_field']] . ");";
} }
} }
}
return $customJoin; return $customJoin;
} }
return ''; return '';
@ -2349,6 +2353,8 @@ class Interpretation extends Fields
{ {
$asBucket = array(); $asBucket = array();
foreach ($get->main_get as $main_get) foreach ($get->main_get as $main_get)
{
if (isset($main_get['key']) && isset($main_get['as']))
{ {
if (isset($this->siteFieldData['decode'][$code][$main_get['key']][$main_get['as']])) if (isset($this->siteFieldData['decode'][$code][$main_get['key']][$main_get['as']]))
{ {
@ -2392,6 +2398,7 @@ class Interpretation extends Fields
$asBucket[] = $main_get['as']; $asBucket[] = $main_get['as'];
} }
} }
}
// set the scripts // set the scripts
$Component = $this->fileContentStatic[$this->hhh . 'Component' . $this->hhh]; $Component = $this->fileContentStatic[$this->hhh . 'Component' . $this->hhh];
$script = ''; $script = '';
@ -2705,7 +2712,8 @@ class Interpretation extends Fields
$this->siteDecrypt[$cryptionType][$code] = false; $this->siteDecrypt[$cryptionType][$code] = false;
} }
// set the method defaults // set the method defaults
$default = $this->setCustomViewMethodDefaults($get, $code); if (($default = $this->setCustomViewMethodDefaults($get, $code)) !== false)
{
// build custom method // build custom method
$methods .= PHP_EOL . PHP_EOL . $this->_t(1) . "/**"; $methods .= PHP_EOL . PHP_EOL . $this->_t(1) . "/**";
$methods .= PHP_EOL . $this->_t(1) . " * Method to get an array of " . $default['name'] . " Objects."; $methods .= PHP_EOL . $this->_t(1) . " * Method to get an array of " . $default['name'] . " Objects.";
@ -2896,10 +2904,14 @@ class Interpretation extends Fields
} }
$methods = str_replace($this->hhh . 'CRYPT' . $this->hhh, $script, $methods); $methods = str_replace($this->hhh . 'CRYPT' . $this->hhh, $script, $methods);
} }
}
// insure the crypt placeholder is removed // insure the crypt placeholder is removed
if (ComponentbuilderHelper::checkString($methods))
{
$methods = str_replace($this->hhh . 'CRYPT' . $this->hhh, '', $methods); $methods = str_replace($this->hhh . 'CRYPT' . $this->hhh, '', $methods);
} }
} }
}
// only update if dispacher placholder is found // only update if dispacher placholder is found
if (strpos($methods, $this->hhh . 'DISPATCHER' . $this->hhh) !== false) if (strpos($methods, $this->hhh . 'DISPATCHER' . $this->hhh) !== false)
{ {
@ -2910,10 +2922,17 @@ class Interpretation extends Fields
} }
$methods = str_replace(array_keys($this->JEventDispatcher), array_values($this->JEventDispatcher), $methods); $methods = str_replace(array_keys($this->JEventDispatcher), array_values($this->JEventDispatcher), $methods);
} }
// insure the crypt placeholder is removed
if (ComponentbuilderHelper::checkString($methods))
{
return $methods . PHP_EOL; return $methods . PHP_EOL;
} }
return '';
}
public function setCustomViewMethodDefaults($get, $code) public function setCustomViewMethodDefaults($get, $code)
{
if (isset($get['key']) && isset($get['as']))
{ {
$key = substr(ComponentbuilderHelper::safeString(preg_replace('/[0-9]+/', '', md5($get['key'])), 'F'), 0, 4); $key = substr(ComponentbuilderHelper::safeString(preg_replace('/[0-9]+/', '', md5($get['key'])), 'F'), 0, 4);
$method['on_field'] = (isset($get['on_field'])) ? $this->removeAsDot($get['on_field']) : null; $method['on_field'] = (isset($get['on_field'])) ? $this->removeAsDot($get['on_field']) : null;
@ -2928,6 +2947,8 @@ class Interpretation extends Fields
// return // return
return $method; return $method;
} }
return false;
}
/** /**
* get the a script from the custom script builder * get the a script from the custom script builder

View File

@ -2228,7 +2228,7 @@ abstract class ComponentbuilderHelper
} }
$display[] = '</ul>'; $display[] = '</ul>';
// if we have a source link we add it // if we have a source link we add it
if (isset($info['joomla_source_link']) && self::checkArray($info['joomla_source_link']) && self::checkString($info['joomla_source_link'][$key])) if (isset($info['joomla_source_link']) && self::checkArray($info['joomla_source_link']) && isset($info['joomla_source_link'][$key]) && self::checkString($info['joomla_source_link'][$key]))
{ {
$display[] = '<a class="uk-button uk-button-mini uk-width-1-1 uk-margin-small-bottom " href="'.$info['joomla_source_link'][$key].'" target="_blank" title="Source Code for Joomla Component ('.$name.')">source code</a>'; $display[] = '<a class="uk-button uk-button-mini uk-width-1-1 uk-margin-small-bottom " href="'.$info['joomla_source_link'][$key].'" target="_blank" title="Source Code for Joomla Component ('.$name.')">source code</a>';
} }
@ -3686,6 +3686,44 @@ abstract class ComponentbuilderHelper
return self::$CRYPT[$TYPE]; return self::$CRYPT[$TYPE];
} }
/**
* set subform type table
*
* @param array $head The header names
* @param array $rows The row values
* @param string $idName The prefix to the table id
*
* @return string
*
*/
public static function setSubformTable($head, $rows, $idName)
{
$table[] = "<div class=\"row-fluid\" id=\"vdm_table_display_".$idName."\">";
$table[] = "\t<div class=\"subform-repeatable-wrapper subform-table-layout subform-table-sublayout-section-byfieldsets\">";
$table[] = "\t\t<div class=\"subform-repeatable\">";
$table[] = "\t\t\t<table class=\"adminlist table table-striped table-bordered\">";
$table[] = "\t\t\t\t<thead>";
$table[] = "\t\t\t\t\t<tr>";
$table[] = "\t\t\t\t\t\t<th>" . implode("</th><th>", $head) . "</th>";
$table[] = "\t\t\t\t\t</tr>";
$table[] = "\t\t\t\t</thead>";
$table[] = "\t\t\t\t<tbody>";
foreach ($rows as $row)
{
$table[] = "\t\t\t\t\t<tr class=\"subform-repeatable-group\">";
$table[] = "\t\t\t\t\t\t" . $row;
$table[] = "\t\t\t\t\t</tr>";
}
$table[] = "\t\t\t\t</tbody>";
$table[] = "\t\t\t</table>";
$table[] = "\t\t</div>";
$table[] = "\t</div>";
$table[] = "</div>";
// return the table
return implode("\n", $table);
}
/** /**
* Load the Component xml manifest. * Load the Component xml manifest.
**/ **/

View File

@ -594,39 +594,12 @@ class ComponentbuilderModelAjax extends JModelList
// set the number of rows // set the number of rows
$this->rowNumber = count($rows); $this->rowNumber = count($rows);
// return the table // return the table
return $this->setSubformTable($head, $rows, $idName); return ComponentbuilderHelper::setSubformTable($head, $rows, $idName);
} }
} }
return false; return false;
} }
protected function setSubformTable($head, $rows, $idName)
{
$table[] = "<div class=\"row-fluid\" id=\"vdm_table_display_".$idName."\">";
$table[] = "\t<div class=\"subform-repeatable-wrapper subform-table-layout subform-table-sublayout-section-byfieldsets\">";
$table[] = "\t\t<div class=\"subform-repeatable\">";
$table[] = "\t\t\t<table class=\"adminlist table table-striped table-bordered\">";
$table[] = "\t\t\t\t<thead>";
$table[] = "\t\t\t\t\t<tr>";
$table[] = "\t\t\t\t\t\t<th>" . implode("</th><th>", $head) . "</th>";
$table[] = "\t\t\t\t\t</tr>";
$table[] = "\t\t\t\t</thead>";
$table[] = "\t\t\t\t<tbody>";
foreach ($rows as $row)
{
$table[] = "\t\t\t\t\t<tr class=\"subform-repeatable-group\">";
$table[] = "\t\t\t\t\t\t" . $row;
$table[] = "\t\t\t\t\t</tr>";
}
$table[] = "\t\t\t\t</tbody>";
$table[] = "\t\t\t</table>";
$table[] = "\t\t</div>";
$table[] = "\t</div>";
$table[] = "</div>";
// return the table
return implode("\n", $table);
}
protected function setSubformValue($header, $value) protected function setSubformValue($header, $value)
{ {
if (array_key_exists($header, $this->functionArray) && method_exists($this, $this->functionArray[$header])) if (array_key_exists($header, $this->functionArray) && method_exists($this, $this->functionArray[$header]))

View File

@ -119,7 +119,6 @@ class ComponentbuilderModelCompiler extends JModelList
return $items; return $items;
} }
/** /**
* Get the uikit needed components * Get the uikit needed components
* *

View File

@ -115,7 +115,6 @@ class ComponentbuilderModelGet_snippets extends JModelList
return $items; return $items;
} }
/** /**
* Get the uikit needed components * Get the uikit needed components
* *

View File

@ -749,6 +749,8 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
{ {
if (isset($this->data[$table]) && ComponentbuilderHelper::checkArray($this->data[$table])) if (isset($this->data[$table]) && ComponentbuilderHelper::checkArray($this->data[$table]))
{ {
// add pre import event
$this->preImportEvent($table);
// get global action permissions // get global action permissions
$canDo = ComponentbuilderHelper::getActions($table); $canDo = ComponentbuilderHelper::getActions($table);
$canEdit = $canDo->get('core.edit'); $canEdit = $canDo->get('core.edit');
@ -836,6 +838,38 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
return true; return true;
} }
/**
* Check if this table needs some house cleaning before we import the data
*
* @return void
*
**/
protected function preImportEvent($table)
{
// if this is custom code table
// remove all custom code linked to these components
// since some code may have been removed and changed
// best unpublish all and let the import publish those still active
if ('custom_code' === $table && isset($this->newID['joomla_component']) && ComponentbuilderHelper::checkArray($this->newID['joomla_component']))
{
$query = $this->_db->getQuery(true);
// Field to update.
$fields = array(
$this->_db->quoteName('published') . ' = 0'
);
// Conditions for which records should be updated.
$conditions = array(
$this->_db->quoteName('component') . ' IN (' . implode(', ', array_values($this->newID['joomla_component'])) . ')'
);
$query->update($this->_db->quoteName('#__componentbuilder_custom_code'))->set($fields)->where($conditions);
$this->_db->setQuery($query);
$this->_db->execute();
}
}
/** /**
* Check if we should allow merge for this table * Check if we should allow merge for this table
* *
@ -2706,28 +2740,38 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
case 'custom_code': case 'custom_code':
// search for custom code // search for custom code
$getter = array('comment_type', 'target'); $getter = array('comment_type', 'target');
// add some more advanced search $this->specialValue = array();
if (isset($item->path) && ComponentbuilderHelper::checkString($item->path)) // search for Hash (automation)
if (isset($item->target) && $item->target == 1)
{ {
$getter[] = 'path'; $getter[] = 'path';
$getter[] = 'hashtarget';
$getter[] = 'component';
// Yet if diverged it makes sense that the ID is updated.
if ($diverged)
{
// set a special value
$this->specialValue['component'] = (int) $item->component;
} }
// add function name search elseif (isset($this->newID['joomla_component'][(int) $item->component]))
if (isset($item->function_name) && ComponentbuilderHelper::checkString($item->function_name)) {
// set a special value
$this->specialValue['component'] = $this->newID['joomla_component'][(int) $item->component];
}
// (TODO) I have seen this happen, seems dangerous!
else
{
return false;
}
}
// search for JCB (manual)
elseif (isset($item->target) && $item->target == 2)
{ {
$getter[] = 'function_name'; $getter[] = 'function_name';
// remove path
if (($key = array_search('path', $getter)) !== false) {
unset($getter[$key]);
} }
} else
// add hash target search
elseif (isset($item->hashtarget) && ComponentbuilderHelper::checkString($item->hashtarget))
{ {
$getter[] = 'hashtarget'; return false;
// remove function name
if (($key = array_search('function_name', $getter)) !== false) {
unset($getter[$key]);
}
} }
break; break;
case 'dynamic_get': case 'dynamic_get':

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>25th August, 2018</creationDate> <creationDate>30th August, 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>

View File

@ -2228,7 +2228,7 @@ abstract class ComponentbuilderHelper
} }
$display[] = '</ul>'; $display[] = '</ul>';
// if we have a source link we add it // if we have a source link we add it
if (isset($info['joomla_source_link']) && self::checkArray($info['joomla_source_link']) && self::checkString($info['joomla_source_link'][$key])) if (isset($info['joomla_source_link']) && self::checkArray($info['joomla_source_link']) && isset($info['joomla_source_link'][$key]) && self::checkString($info['joomla_source_link'][$key]))
{ {
$display[] = '<a class="uk-button uk-button-mini uk-width-1-1 uk-margin-small-bottom " href="'.$info['joomla_source_link'][$key].'" target="_blank" title="Source Code for Joomla Component ('.$name.')">source code</a>'; $display[] = '<a class="uk-button uk-button-mini uk-width-1-1 uk-margin-small-bottom " href="'.$info['joomla_source_link'][$key].'" target="_blank" title="Source Code for Joomla Component ('.$name.')">source code</a>';
} }
@ -3687,6 +3687,44 @@ abstract class ComponentbuilderHelper
} }
/**
* set subform type table
*
* @param array $head The header names
* @param array $rows The row values
* @param string $idName The prefix to the table id
*
* @return string
*
*/
public static function setSubformTable($head, $rows, $idName)
{
$table[] = "<div class=\"row-fluid\" id=\"vdm_table_display_".$idName."\">";
$table[] = "\t<div class=\"subform-repeatable-wrapper subform-table-layout subform-table-sublayout-section-byfieldsets\">";
$table[] = "\t\t<div class=\"subform-repeatable\">";
$table[] = "\t\t\t<table class=\"adminlist table table-striped table-bordered\">";
$table[] = "\t\t\t\t<thead>";
$table[] = "\t\t\t\t\t<tr>";
$table[] = "\t\t\t\t\t\t<th>" . implode("</th><th>", $head) . "</th>";
$table[] = "\t\t\t\t\t</tr>";
$table[] = "\t\t\t\t</thead>";
$table[] = "\t\t\t\t<tbody>";
foreach ($rows as $row)
{
$table[] = "\t\t\t\t\t<tr class=\"subform-repeatable-group\">";
$table[] = "\t\t\t\t\t\t" . $row;
$table[] = "\t\t\t\t\t</tr>";
}
$table[] = "\t\t\t\t</tbody>";
$table[] = "\t\t\t</table>";
$table[] = "\t\t</div>";
$table[] = "\t</div>";
$table[] = "</div>";
// return the table
return implode("\n", $table);
}
public static function jsonToString($value, $sperator = ", ", $table = null, $id = 'id', $name = 'name') public static function jsonToString($value, $sperator = ", ", $table = null, $id = 'id', $name = 'name')
{ {
// do some table foot work // do some table foot work

View File

@ -141,7 +141,6 @@ class ComponentbuilderModelApi extends JModelItem
return $this->_item[$pk]; return $this->_item[$pk];
} }
/** /**
* Get the uikit needed components * Get the uikit needed components
* *