Improved the JCB package export/import feature to insure that the new full paths are also moved, also made a few bug fixes in this area to better deal with divergent data id managment

This commit is contained in:
Llewellyn van der Merwe 2018-03-02 03:37:04 +02:00
parent 593a4c7c89
commit 836df43fcc
No known key found for this signature in database
GPG Key ID: CAD7B16D27AF28C5
10 changed files with 403 additions and 138 deletions

View File

@ -126,11 +126,11 @@ Component Builder is mapped as a component in itself on my local development env
+ *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com)
+ *Name*: [Component Builder](http://joomlacomponentbuilder.com) + *Name*: [Component Builder](http://joomlacomponentbuilder.com)
+ *First Build*: 30th April, 2015 + *First Build*: 30th April, 2015
+ *Last Build*: 1st March, 2018 + *Last Build*: 2nd March, 2018
+ *Version*: 2.6.17 + *Version*: 2.6.17
+ *Copyright*: Copyright (C) 2015. All Rights Reserved + *Copyright*: Copyright (C) 2015. All Rights Reserved
+ *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html + *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
+ *Line count*: **183106** + *Line count*: **183421**
+ *Field count*: **1641** + *Field count*: **1641**
+ *File count*: **1169** + *File count*: **1169**
+ *Folder count*: **189** + *Folder count*: **189**

View File

@ -126,11 +126,11 @@ Component Builder is mapped as a component in itself on my local development env
+ *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com)
+ *Name*: [Component Builder](http://joomlacomponentbuilder.com) + *Name*: [Component Builder](http://joomlacomponentbuilder.com)
+ *First Build*: 30th April, 2015 + *First Build*: 30th April, 2015
+ *Last Build*: 1st March, 2018 + *Last Build*: 2nd March, 2018
+ *Version*: 2.6.17 + *Version*: 2.6.17
+ *Copyright*: Copyright (C) 2015. All Rights Reserved + *Copyright*: Copyright (C) 2015. All Rights Reserved
+ *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html + *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
+ *Line count*: **183106** + *Line count*: **183421**
+ *Field count*: **1641** + *Field count*: **1641**
+ *File count*: **1169** + *File count*: **1169**
+ *Folder count*: **189** + *Folder count*: **189**

View File

@ -320,56 +320,6 @@ class Structure extends Get
*/ */
protected $lastModifiedDate = array(); protected $lastModifiedDate = array();
/**
* The array of dynamic paths
*
* JPATH_SITE is meant to represent the root path of the JSite application, just as JPATH_ADMINISTRATOR is mean to represent the root path of the JAdministrator application.
*
* JPATH_BASE is the root path for the current requested application.... so if you are in the administrator application:
*
* JPATH_BASE == JPATH_ADMINISTRATOR
*
* If you are in the site application:
*
* JPATH_BASE == JPATH_SITE
*
* If you are in the installation application:
*
* JPATH_BASE == JPATH_INSTALLATION.
*
* JPATH_ROOT is the root path for the Joomla install and does not depend upon any application.
*
* @var array
*/
protected $constantPaths = array(
// The path to the administrator folder.
'JPATH_ADMINISTRATOR' => JPATH_ADMINISTRATOR,
// The path to the installed Joomla! site, or JPATH_ROOT/administrator if executed from the backend.
'JPATH_BASE' => JPATH_BASE,
// The path to the cache folder.
'JPATH_CACHE' => JPATH_CACHE,
// The path to the administration folder of the current component being executed.
'JPATH_COMPONENT_ADMINISTRATOR' => JPATH_COMPONENT_ADMINISTRATOR,
// The path to the site folder of the current component being executed.
'JPATH_COMPONENT_SITE' => JPATH_COMPONENT_SITE,
// The path to the current component being executed.
'JPATH_COMPONENT' => JPATH_COMPONENT,
// The path to folder containing the configuration.php file.
'JPATH_CONFIGURATION' => JPATH_CONFIGURATION,
// The path to the installation folder.
'JPATH_INSTALLATION' => JPATH_INSTALLATION,
// The path to the libraries folder.
'JPATH_LIBRARIES' => JPATH_LIBRARIES,
// The path to the plugins folder.
'JPATH_PLUGINS' => JPATH_PLUGINS,
// The path to the installed Joomla! site.
'JPATH_ROOT' => JPATH_ROOT,
// The path to the installed Joomla! site.
'JPATH_SITE' => JPATH_SITE,
// The path to the templates folder.
'JPATH_THEMES' => JPATH_THEMES
);
/** /**
* Constructor * Constructor
*/ */
@ -1403,7 +1353,7 @@ class Structure extends Get
*/ */
protected function updateDynamicPath($path) protected function updateDynamicPath($path)
{ {
return $this->setPlaceholders($path, $this->constantPaths); return $this->setPlaceholders($path, ComponentbuilderHelper::$constantPaths);
} }
/** /**

View File

@ -987,6 +987,57 @@ abstract class ComponentbuilderHelper
public static $snippetPath = 'https://raw.githubusercontent.com/vdm-io/Joomla-Component-Builder-Snippets/master/'; public static $snippetPath = 'https://raw.githubusercontent.com/vdm-io/Joomla-Component-Builder-Snippets/master/';
public static $snippetsPath = 'https://api.github.com/repos/vdm-io/Joomla-Component-Builder-Snippets/git/trees/master'; public static $snippetsPath = 'https://api.github.com/repos/vdm-io/Joomla-Component-Builder-Snippets/git/trees/master';
/**
* The array of constant paths
*
* JPATH_SITE is meant to represent the root path of the JSite application,
* just as JPATH_ADMINISTRATOR is mean to represent the root path of the JAdministrator application.
*
* JPATH_BASE is the root path for the current requested application.... so if you are in the administrator application:
*
* JPATH_BASE == JPATH_ADMINISTRATOR
*
* If you are in the site application:
*
* JPATH_BASE == JPATH_SITE
*
* If you are in the installation application:
*
* JPATH_BASE == JPATH_INSTALLATION.
*
* JPATH_ROOT is the root path for the Joomla install and does not depend upon any application.
*
* @var array
*/
public static $constantPaths = array(
// The path to the administrator folder.
'JPATH_ADMINISTRATOR' => JPATH_ADMINISTRATOR,
// The path to the installed Joomla! site, or JPATH_ROOT/administrator if executed from the backend.
'JPATH_BASE' => JPATH_BASE,
// The path to the cache folder.
'JPATH_CACHE' => JPATH_CACHE,
// The path to the administration folder of the current component being executed.
'JPATH_COMPONENT_ADMINISTRATOR' => JPATH_COMPONENT_ADMINISTRATOR,
// The path to the site folder of the current component being executed.
'JPATH_COMPONENT_SITE' => JPATH_COMPONENT_SITE,
// The path to the current component being executed.
'JPATH_COMPONENT' => JPATH_COMPONENT,
// The path to folder containing the configuration.php file.
'JPATH_CONFIGURATION' => JPATH_CONFIGURATION,
// The path to the installation folder.
'JPATH_INSTALLATION' => JPATH_INSTALLATION,
// The path to the libraries folder.
'JPATH_LIBRARIES' => JPATH_LIBRARIES,
// The path to the plugins folder.
'JPATH_PLUGINS' => JPATH_PLUGINS,
// The path to the installed Joomla! site.
'JPATH_ROOT' => JPATH_ROOT,
// The path to the installed Joomla! site.
'JPATH_SITE' => JPATH_SITE,
// The path to the templates folder.
'JPATH_THEMES' => JPATH_THEMES
);
/** /**
* Get the snippet contributor details * Get the snippet contributor details
* *

View File

@ -3831,8 +3831,10 @@ COM_COMPONENTBUILDER_FIELD_XML_LABEL="XML field definition (Please set the field
COM_COMPONENTBUILDER_FIELD_YES="Yes" COM_COMPONENTBUILDER_FIELD_YES="Yes"
COM_COMPONENTBUILDER_FIELD_ZERO="0" COM_COMPONENTBUILDER_FIELD_ZERO="0"
COM_COMPONENTBUILDER_FILE="File" COM_COMPONENTBUILDER_FILE="File"
COM_COMPONENTBUILDER_FILE_BSB_WAS_NOT_MOVE_TO_S="File <b>%s</b> was not move to (%s)!"
COM_COMPONENTBUILDER_FILTER="Filter" COM_COMPONENTBUILDER_FILTER="Filter"
COM_COMPONENTBUILDER_FOLDER="Folder" COM_COMPONENTBUILDER_FOLDER="Folder"
COM_COMPONENTBUILDER_FOLDER_BSB_WAS_NOT_MOVE_TO_S="Folder <b>%s</b> was not move to (%s)!"
COM_COMPONENTBUILDER_FORCE_LOCAL_UPDATE="Force Local Update" COM_COMPONENTBUILDER_FORCE_LOCAL_UPDATE="Force Local Update"
COM_COMPONENTBUILDER_FULL_WIDTH_IN_TAB="Full Width in Tab" COM_COMPONENTBUILDER_FULL_WIDTH_IN_TAB="Full Width in Tab"
COM_COMPONENTBUILDER_GENERAL_OVERVIEW_OF_HOW_THINGS_WORK_BSB="General overview of how things work: <b>%s</b>" COM_COMPONENTBUILDER_GENERAL_OVERVIEW_OF_HOW_THINGS_WORK_BSB="General overview of how things work: <b>%s</b>"

View File

@ -767,7 +767,7 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
protected function moveSmartStuff() protected function moveSmartStuff()
{ {
// make sure to first unlock files // make sure to first unlock files
$this->unLockFiles($this->dir); $this->unLockFiles();
// set params // set params
$params = JComponentHelper::getParams('com_componentbuilder'); $params = JComponentHelper::getParams('com_componentbuilder');
// set custom folder path // set custom folder path
@ -796,6 +796,43 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
$success = false; $success = false;
} }
} }
// now move the dynamic files if found
$dynamicDir = str_replace('//', '/', $this->dir . '/dynamic');
if (JFolder::exists($dynamicDir))
{
// get a list of folders
$folders = JFolder::folders($dynamicDir);
// check if we have files
if(ComponentbuilderHelper::checkArray($folders))
{
foreach ($folders as $folder)
{
$destination = $this->setDynamicPath($folder);
$fullPath = str_replace('//', '/', $dynamicDir . '/' . $folder);
if (!JFolder::exists($fullPath) || !JFolder::copy($fullPath, $destination,'',true))
{
$this->app->enqueueMessage(JText::sprintf('COM_COMPONENTBUILDER_FOLDER_BSB_WAS_NOT_MOVE_TO_S', $folder, $destination), 'error');
$success = false;
}
}
}
// get a list of files
$files = JFolder::files($dynamicDir);
// check if we have files
if(ComponentbuilderHelper::checkArray($files))
{
foreach ($files as $file)
{
$destination = $this->setDynamicPath($file);
$fullPath = str_replace('//', '/', $dynamicDir . '/' . $file);
if (!JFile::exists($fullPath) || !JFile::copy($fullPath, $destination))
{
$this->app->enqueueMessage(JText::sprintf('COM_COMPONENTBUILDER_FILE_BSB_WAS_NOT_MOVE_TO_S', $file, $destination), 'error');
$success = false;
}
}
}
}
return $success; return $success;
} }
@ -812,19 +849,17 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
$unlocker = new FOFEncryptAes($this->sleutle, 128); $unlocker = new FOFEncryptAes($this->sleutle, 128);
// we must first store the current working directory // we must first store the current working directory
$joomla = getcwd(); $joomla = getcwd();
// setup the type path // to avoid that it decrypt the db and info file again we must move per/folder
$customPath = str_replace('//', '/', $this->dir . '/custom'); $folders = array('images', 'custom', 'dynamic');
// go to the custom folder if found // loop the folders
if (JFolder::exists($customPath)) foreach ($folders as $folder)
{ {
$this->unlock($customPath, $unlocker); $subPath = str_replace('//', '/', $this->dir . '/' . $folder);
// go to the package sub folder if found
if (JFolder::exists($subPath))
{
$this->unlock($subPath, $unlocker);
} }
// setup the type path
$imagesPath = str_replace('//', '/', $this->dir . '/images');
// go to the custom folder if found
if (JFolder::exists($imagesPath))
{
$this->unlock($imagesPath, $unlocker);
} }
// change back to working dir // change back to working dir
chdir($joomla); chdir($joomla);
@ -983,10 +1018,10 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
foreach($values as $value) foreach($values as $value)
{ {
// first check if exist (only add if it does not) // first check if exist (only add if it does not)
if (!$this->getLocalItem($value, $table, 1)) if (!$this->getLocalItem($value, $table, 1, 1, true))
{ {
// add the diverged data // add the diverged data
$this->addLocalItem($value, $table); $this->addLocalItem($value, $table, true);
} }
} }
} }
@ -1226,12 +1261,13 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
* @param object $item The item to prep * @param object $item The item to prep
* @param string $type The type of values * @param string $type The type of values
* @param string $action The action (add/update) * @param string $action The action (add/update)
* @param bool $diverged The diverged data switch
* *
* @return mixed false on failure * @return mixed false on failure
* object on success * object on success
* *
**/ **/
protected function prepItem($item, &$type, $action) protected function prepItem($item, &$type, $action, $diverged = false)
{ {
// remove access // remove access
if (isset($item->access)) if (isset($item->access))
@ -1528,8 +1564,12 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
$item = ComponentbuilderHelper::convertRepeatableFields($item, $updaterR); $item = ComponentbuilderHelper::convertRepeatableFields($item, $updaterR);
break; break;
case 'component_admin_views': case 'component_admin_views':
// diverged id already updated
if (!$diverged)
{
// update the joomla_component ID where needed // update the joomla_component ID where needed
$item = $this->setNewID($item, 'joomla_component', 'joomla_component', $type); $item = $this->setNewID($item, 'joomla_component', 'joomla_component', $type);
}
// repeatable fields to update // repeatable fields to update
$updaterR = array( $updaterR = array(
// repeatablefield => checker // repeatablefield => checker
@ -1546,8 +1586,12 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
$this->updateSubformsIDs($item, 'component_admin_views', $updaterT); $this->updateSubformsIDs($item, 'component_admin_views', $updaterT);
break; break;
case 'component_site_views': case 'component_site_views':
// diverged id already updated
if (!$diverged)
{
// update the joomla_component ID where needed // update the joomla_component ID where needed
$item = $this->setNewID($item, 'joomla_component', 'joomla_component', $type); $item = $this->setNewID($item, 'joomla_component', 'joomla_component', $type);
}
// repeatable fields to update // repeatable fields to update
$updaterR = array( $updaterR = array(
// repeatablefield => checker // repeatablefield => checker
@ -1564,8 +1608,12 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
$this->updateSubformsIDs($item, 'component_site_views', $updaterT); $this->updateSubformsIDs($item, 'component_site_views', $updaterT);
break; break;
case 'component_custom_admin_views': case 'component_custom_admin_views':
// diverged id already updated
if (!$diverged)
{
// update the joomla_component ID where needed // update the joomla_component ID where needed
$item = $this->setNewID($item, 'joomla_component', 'joomla_component', $type); $item = $this->setNewID($item, 'joomla_component', 'joomla_component', $type);
}
// repeatable fields to update // repeatable fields to update
$updaterR = array( $updaterR = array(
// repeatablefield => checker // repeatablefield => checker
@ -1582,8 +1630,12 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
$this->updateSubformsIDs($item, 'component_custom_admin_views', $updaterT); $this->updateSubformsIDs($item, 'component_custom_admin_views', $updaterT);
break; break;
case 'component_updates': case 'component_updates':
// diverged id already updated
if (!$diverged)
{
// update the joomla_component ID where needed // update the joomla_component ID where needed
$item = $this->setNewID($item, 'joomla_component', 'joomla_component', $type); $item = $this->setNewID($item, 'joomla_component', 'joomla_component', $type);
}
// repeatable fields to update // repeatable fields to update
$updaterR = array( $updaterR = array(
// repeatablefield => checker // repeatablefield => checker
@ -1593,8 +1645,12 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
$item = ComponentbuilderHelper::convertRepeatableFields($item, $updaterR); $item = ComponentbuilderHelper::convertRepeatableFields($item, $updaterR);
break; break;
case 'component_mysql_tweaks': case 'component_mysql_tweaks':
// diverged id already updated
if (!$diverged)
{
// update the joomla_component ID where needed // update the joomla_component ID where needed
$item = $this->setNewID($item, 'joomla_component', 'joomla_component', $type); $item = $this->setNewID($item, 'joomla_component', 'joomla_component', $type);
}
// repeatable fields to update // repeatable fields to update
$updaterR = array( $updaterR = array(
// repeatablefield => checker // repeatablefield => checker
@ -1611,8 +1667,12 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
$this->updateSubformsIDs($item, 'component_mysql_tweaks', $updaterT); $this->updateSubformsIDs($item, 'component_mysql_tweaks', $updaterT);
break; break;
case 'component_custom_admin_menus': case 'component_custom_admin_menus':
// diverged id already updated
if (!$diverged)
{
// update the joomla_component ID where needed // update the joomla_component ID where needed
$item = $this->setNewID($item, 'joomla_component', 'joomla_component', $type); $item = $this->setNewID($item, 'joomla_component', 'joomla_component', $type);
}
// repeatable fields to update // repeatable fields to update
$updaterR = array( $updaterR = array(
// repeatablefield => checker // repeatablefield => checker
@ -1629,8 +1689,12 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
$this->updateSubformsIDs($item, 'component_custom_admin_menus', $updaterT); $this->updateSubformsIDs($item, 'component_custom_admin_menus', $updaterT);
break; break;
case 'component_config': case 'component_config':
// diverged id already updated
if (!$diverged)
{
// update the joomla_component ID where needed // update the joomla_component ID where needed
$item = $this->setNewID($item, 'joomla_component', 'joomla_component', $type); $item = $this->setNewID($item, 'joomla_component', 'joomla_component', $type);
}
// repeatable fields to update // repeatable fields to update
$updaterR = array( $updaterR = array(
// repeatablefield => checker // repeatablefield => checker
@ -1647,8 +1711,12 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
$this->updateSubformsIDs($item, 'component_config', $updaterT); $this->updateSubformsIDs($item, 'component_config', $updaterT);
break; break;
case 'component_dashboard': case 'component_dashboard':
// diverged id already updated
if (!$diverged)
{
// update the joomla_component ID where needed // update the joomla_component ID where needed
$item = $this->setNewID($item, 'joomla_component', 'joomla_component', $type); $item = $this->setNewID($item, 'joomla_component', 'joomla_component', $type);
}
// repeatable fields to update // repeatable fields to update
$updaterR = array( $updaterR = array(
// repeatablefield => checker // repeatablefield => checker
@ -1658,8 +1726,12 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
$item = ComponentbuilderHelper::convertRepeatableFields($item, $updaterR); $item = ComponentbuilderHelper::convertRepeatableFields($item, $updaterR);
break; break;
case 'component_files_folders': case 'component_files_folders':
// diverged id already updated
if (!$diverged)
{
// update the joomla_component ID where needed // update the joomla_component ID where needed
$item = $this->setNewID($item, 'joomla_component', 'joomla_component', $type); $item = $this->setNewID($item, 'joomla_component', 'joomla_component', $type);
}
// repeatable fields to update // repeatable fields to update
$updaterR = array( $updaterR = array(
// repeatablefield => checker // repeatablefield => checker
@ -1784,8 +1856,12 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
break; break;
case 'admin_fields': case 'admin_fields':
case 'admin_fields_conditions': case 'admin_fields_conditions':
// diverged id already updated
if (!$diverged)
{
// update the admin_view ID where needed // update the admin_view ID where needed
$item = $this->setNewID($item, 'admin_view', 'admin_view', $type); $item = $this->setNewID($item, 'admin_view', 'admin_view', $type);
}
// set the updater // set the updater
if ('admin_fields' === $type) if ('admin_fields' === $type)
{ {
@ -2008,15 +2084,16 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
* *
* @param object $item The item to update * @param object $item The item to update
* @param string $type The type of values * @param string $type The type of values
* @param bool $diverged The diverged data switch
* *
* @return mixed false on failure * @return mixed false on failure
* ID int on success * ID int on success
* *
**/ **/
protected function addLocalItem(&$item, &$type) protected function addLocalItem(&$item, &$type, $diverged = false)
{ {
// prep the item // prep the item
if ($add = $this->prepItem($item, $type, 'add')) if ($add = $this->prepItem($item, $type, 'add', $diverged))
{ {
// insert/add the item // insert/add the item
if ($result = $this->_db->insertObject('#__componentbuilder_' . $type, $add)) if ($result = $this->_db->insertObject('#__componentbuilder_' . $type, $add))
@ -2038,12 +2115,13 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
* @param string $type The type of values * @param string $type The type of values
* @param bool $retry The retry switch * @param bool $retry The retry switch
* @param bool $get The query get switch * @param bool $get The query get switch
* @param bool $diverged The diverged data switch
* *
* @return mixed false on failure * @return mixed false on failure
* ID int on success * ID int on success
* *
**/ **/
protected function getLocalItem(&$item, &$type, $retry = false, $get = 1) protected function getLocalItem(&$item, &$type, $retry = false, $get = 1, $diverged = false)
{ {
$query = $this->_db->getQuery(true); $query = $this->_db->getQuery(true);
$query->select('a.*'); $query->select('a.*');
@ -2154,7 +2232,15 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
// get by admin_view (since there should only be one of each name) // get by admin_view (since there should only be one of each name)
$getter = array('admin_view'); $getter = array('admin_view');
$this->specialValue = array(); $this->specialValue = array();
// Yet if diverged it makes sense that the ID is updated.
if ($diverged)
{
$this->specialValue['admin_view'] = (int) $item->admin_view;
}
elseif (isset($this->newID['admin_view'][(int) $item->admin_view]))
{
$this->specialValue['admin_view'] = $this->newID['admin_view'][(int) $item->admin_view]; $this->specialValue['admin_view'] = $this->newID['admin_view'][(int) $item->admin_view];
}
break; break;
case 'fieldtype': case 'fieldtype':
// get by name (since there should only be one of each name) // get by name (since there should only be one of each name)
@ -2304,10 +2390,23 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
case 'component_config': case 'component_config':
case 'component_dashboard': case 'component_dashboard':
case 'component_files_folders': case 'component_files_folders':
// get by admin_view (since there should only be one of each name) // get by joomla_component (since there should only be one of each component)
$getter = array('joomla_component'); $getter = array('joomla_component');
$this->specialValue = array(); $this->specialValue = array();
// Yet if diverged it makes sense that the ID is updated.
if ($diverged)
{
$this->specialValue['joomla_component'] = (int) $item->joomla_component;
}
elseif (isset($this->newID['joomla_component'][(int) $item->joomla_component]))
{
$this->specialValue['joomla_component'] = $this->newID['joomla_component'][(int) $item->joomla_component]; $this->specialValue['joomla_component'] = $this->newID['joomla_component'][(int) $item->joomla_component];
}
// (TODO) I have seen this happen, seems dangerous!
else
{
return false;
}
break; break;
case 'language_translation': case 'language_translation':
// get by English translation since there should just be one // get by English translation since there should just be one
@ -2545,6 +2644,34 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
return false; return false;
} }
/**
* Update constant path with real full path value
*
* @param string $path The full path
*
* @return string The updated path
*
*/
protected function setFullPath($path)
{
return str_replace(array_keys(ComponentbuilderHelper::$constantPaths), array_values(ComponentbuilderHelper::$constantPaths), $path);
}
/**
* Convert the name to a path
*
* @param string $path The path name
*
* @return string The full path *
*/
protected function setDynamicPath($path)
{
// now convert to path
$path = str_replace('__v_d_m__', '/', $path);
// add the full path if possible
return str_replace('//', '/', $this->setFullPath($path));
}
protected function getAlias($name,$type = false) protected function getAlias($name,$type = false)
{ {
// sanitize the name to an alias // sanitize the name to an alias

View File

@ -273,17 +273,24 @@ class ComponentbuilderModelJoomla_components extends JModelList
// add to pks // add to pks
$pks[] = $item->id; $pks[] = $item->id;
} }
// array of tables linked to joomla_component
$linkedTables = array(
'custom_code' => 'component',
'component_files_folders' => 'joomla_component',
'component_admin_views' => 'joomla_component',
'component_config' => 'joomla_component',
'component_site_views' => 'joomla_component',
'component_custom_admin_views' => 'joomla_component',
'component_updates' => 'joomla_component',
'component_mysql_tweaks' => 'joomla_component',
'component_custom_admin_menus' => 'joomla_component',
'component_dashboard' => 'joomla_component' );
// load all tables linked to joomla_component // load all tables linked to joomla_component
$this->setData('custom_code', $pks, 'component'); foreach($linkedTables as $table => $field)
$this->setData('component_files_folders', $pks, 'joomla_component'); {
$this->setData('component_admin_views', $pks, 'joomla_component'); $this->setData($table, $pks, $field);
$this->setData('component_config', $pks, 'joomla_component'); }
$this->setData('component_site_views', $pks, 'joomla_component');
$this->setData('component_custom_admin_views', $pks, 'joomla_component');
$this->setData('component_updates', $pks, 'joomla_component');
$this->setData('component_mysql_tweaks', $pks, 'joomla_component');
$this->setData('component_custom_admin_menus', $pks, 'joomla_component');
$this->setData('component_dashboard', $pks, 'joomla_component');
// add fields and conditions // add fields and conditions
if (isset($this->exportIDs['admin_view']) && ComponentbuilderHelper::checkArray($this->exportIDs['admin_view'])) if (isset($this->exportIDs['admin_view']) && ComponentbuilderHelper::checkArray($this->exportIDs['admin_view']))
{ {
@ -320,7 +327,8 @@ class ComponentbuilderModelJoomla_components extends JModelList
{ {
$this->setData('custom_code', array_values($this->exportIDs['custom_code']), 'id'); $this->setData('custom_code', array_values($this->exportIDs['custom_code']), 'id');
} }
// has any data been set
// has any data been set for this component
if (isset($this->smartExport['joomla_component']) && ComponentbuilderHelper::checkArray($this->smartExport['joomla_component'])) if (isset($this->smartExport['joomla_component']) && ComponentbuilderHelper::checkArray($this->smartExport['joomla_component']))
{ {
// set the folder and move the files of each component to the folder // set the folder and move the files of each component to the folder
@ -553,6 +561,10 @@ class ComponentbuilderModelJoomla_components extends JModelList
$this->moveIt($this->getValues($item->addfiles, 'subform', 'file', null), 'file'); $this->moveIt($this->getValues($item->addfiles, 'subform', 'file', null), 'file');
// build folders // build folders
$this->moveIt($this->getValues($item->addfolders, 'subform', 'folder', null), 'folder'); $this->moveIt($this->getValues($item->addfolders, 'subform', 'folder', null), 'folder');
// build full path files
$this->moveIt($this->getValues($item->addfilesfullpath, 'subform', 'filepath', null), 'file', true);
// build full path folders
$this->moveIt($this->getValues($item->addfoldersfullpath, 'subform', 'folderpath', null), 'folder', true);
} }
// actions to take if table is component_config // actions to take if table is component_config
if ('component_config' === $table) if ('component_config' === $table)
@ -777,19 +789,18 @@ class ComponentbuilderModelJoomla_components extends JModelList
$locker = new FOFEncryptAes($this->key, 128); $locker = new FOFEncryptAes($this->key, 128);
// we must first store the current working directory // we must first store the current working directory
$joomla = getcwd(); $joomla = getcwd();
// setup the type path // to avoid that it encrypt the db and info file again we must move per/folder
$customPath = $this->packagePath . '/custom'; $folders = array('images', 'custom', 'dynamic');
// go to the custom folder if found // loop the folders
if (JFolder::exists($customPath)) foreach ($folders as $folder)
{ {
$this->lock($customPath, $locker); // the sub path
$subPath = $this->packagePath.'/'.$folder;
// go to the package sub folder if found
if (JFolder::exists($subPath))
{
$this->lock($subPath, $locker);
} }
// setup the type path
$imagesPath = $this->packagePath . '/images';
// go to the custom folder if found
if (JFolder::exists($imagesPath))
{
$this->lock($imagesPath, $locker);
} }
// change back to working dir // change back to working dir
chdir($joomla); chdir($joomla);
@ -823,7 +834,7 @@ class ComponentbuilderModelJoomla_components extends JModelList
* *
* @return bool * @return bool
*/ */
protected function moveIt($paths, $type) protected function moveIt($paths, $type, $dynamic = false)
{ {
// make sure we have an array // make sure we have an array
if (!ComponentbuilderHelper::checkArray($paths)) if (!ComponentbuilderHelper::checkArray($paths))
@ -834,11 +845,20 @@ class ComponentbuilderModelJoomla_components extends JModelList
if ('file' === $type || 'folder' === $type) if ('file' === $type || 'folder' === $type)
{ {
$folderName = 'custom'; $folderName = 'custom';
// if these are full paths use dynamic folder
if ($dynamic)
{
$folderName = 'dynamic';
} }
if ('image' === $type) }
elseif ('image' === $type)
{ {
$folderName = 'images'; $folderName = 'images';
} }
else
{
return false;
}
// setup the type path // setup the type path
$tmpPath = str_replace('//', '/', $this->packagePath . '/' . $folderName); $tmpPath = str_replace('//', '/', $this->packagePath . '/' . $folderName);
// create type path if not set // create type path if not set
@ -850,19 +870,31 @@ class ComponentbuilderModelJoomla_components extends JModelList
// now move it // now move it
foreach ($paths as $item) foreach ($paths as $item)
{ {
// make sure we have a string
if (ComponentbuilderHelper::checkString($item)) if (ComponentbuilderHelper::checkString($item))
{ {
// if the file type
if ('file' === $type) if ('file' === $type)
{ {
// TODO we must add the new all over files to this... will be a little tricky. // if dynamic paths
if ($dynamic)
{
$tmpFilePath = $tmpPath.'/'.$this->setDynamicPathName($item);
$customFilePath = str_replace('//', '/', $this->setFullPath($item));
}
else
{
$tmpFilePath = str_replace('//', '/', $tmpPath.'/'.$item); $tmpFilePath = str_replace('//', '/', $tmpPath.'/'.$item);
$customFilePath = str_replace('//', '/', $this->customPath.'/'.$item); $customFilePath = str_replace('//', '/', $this->customPath.'/'.$item);
}
// now check if file exist
if (!JFile::exists($tmpFilePath) && JFile::exists($customFilePath)) if (!JFile::exists($tmpFilePath) && JFile::exists($customFilePath))
{ {
// move the file to its place // move the file to its place
JFile::copy($customFilePath, $tmpFilePath); JFile::copy($customFilePath, $tmpFilePath);
} }
} }
// if the image type
if ('image' === $type) if ('image' === $type)
{ {
$imageName = basename($item); $imageName = basename($item);
@ -882,10 +914,20 @@ class ComponentbuilderModelJoomla_components extends JModelList
JFile::copy($customImagePath, $tmpImagePath); JFile::copy($customImagePath, $tmpImagePath);
} }
} }
// if the folder type
if ('folder' === $type) if ('folder' === $type)
{
// if dynamic paths
if ($dynamic)
{
$tmpFolderPath = $tmpPath.'/'.$this->setDynamicPathName($item);
$customFolderPath = str_replace('//', '/', $this->setFullPath($item));
}
else
{ {
$tmpFolderPath = str_replace('//', '/', $tmpPath.'/'.$item); $tmpFolderPath = str_replace('//', '/', $tmpPath.'/'.$item);
$customFolderPath = str_replace('//', '/', $this->customPath.'/'.$item); $customFolderPath = str_replace('//', '/', $this->customPath.'/'.$item);
}
if (!JFolder::exists($tmpFolderPath) && JFolder::exists($customFolderPath)) if (!JFolder::exists($tmpFolderPath) && JFolder::exists($customFolderPath))
{ {
// move the folder to its place // move the folder to its place
@ -1253,6 +1295,48 @@ class ComponentbuilderModelJoomla_components extends JModelList
} }
} }
/**
* Convert the path to a name
*
* @param string $path The full path
*
* @return string The path name
*
*/
protected function setDynamicPathName($path)
{
// remove the full path if possible
$path = str_replace('//', '/', $this->setConstantPath($path));
// now convert to string
return str_replace('/', '__v_d_m__', $path);
}
/**
* Update real full path value with constant path string
*
* @param string $path The full path
*
* @return string The updated path
*
*/
protected function setConstantPath($path)
{
return str_replace(array_values(ComponentbuilderHelper::$constantPaths), array_keys(ComponentbuilderHelper::$constantPaths), $path);
}
/**
* Update constant path with real full path value
*
* @param string $path The full path
*
* @return string The updated path
*
*/
protected function setFullPath($path)
{
return str_replace(array_keys(ComponentbuilderHelper::$constantPaths), array_values(ComponentbuilderHelper::$constantPaths), $path);
}
/** /**
* Get the keys of the values to search custom code in * Get the keys of the values to search custom code in
* *

View File

@ -138,7 +138,7 @@ class ComponentbuilderViewImport_joomla_components extends JViewLegacy
$text1 = JFormHelper::loadFieldType('text',true); $text1 = JFormHelper::loadFieldType('text',true);
// add the key // add the key
$xml = '<field type="password" label="'.JText::_('COM_COMPONENTBUILDER_KEY').'" description="'.JText::_('COM_COMPONENTBUILDER_THE_KEY_OF_THIS_PACKAGE').'" name="sleutle" class="text_area" filter="STRING" hint="add key here" '.$required.' />'; $xml = '<field type="password" label="'.JText::_('COM_COMPONENTBUILDER_KEY').'" description="'.JText::_('COM_COMPONENTBUILDER_THE_KEY_OF_THIS_PACKAGE').'" name="sleutle" autocomplete="false" class="text_area" filter="STRING" hint="add key here" '.$required.' />';
// prepare the xml // prepare the xml
$sleutle = new SimpleXMLElement($xml); $sleutle = new SimpleXMLElement($xml);
// set components to form // set components to form

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>1st March, 2018</creationDate> <creationDate>2nd March, 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://joomlacomponentbuilder.com</authorUrl> <authorUrl>http://joomlacomponentbuilder.com</authorUrl>

View File

@ -53,6 +53,57 @@ abstract class ComponentbuilderHelper
public static $snippetPath = 'https://raw.githubusercontent.com/vdm-io/Joomla-Component-Builder-Snippets/master/'; public static $snippetPath = 'https://raw.githubusercontent.com/vdm-io/Joomla-Component-Builder-Snippets/master/';
public static $snippetsPath = 'https://api.github.com/repos/vdm-io/Joomla-Component-Builder-Snippets/git/trees/master'; public static $snippetsPath = 'https://api.github.com/repos/vdm-io/Joomla-Component-Builder-Snippets/git/trees/master';
/**
* The array of constant paths
*
* JPATH_SITE is meant to represent the root path of the JSite application,
* just as JPATH_ADMINISTRATOR is mean to represent the root path of the JAdministrator application.
*
* JPATH_BASE is the root path for the current requested application.... so if you are in the administrator application:
*
* JPATH_BASE == JPATH_ADMINISTRATOR
*
* If you are in the site application:
*
* JPATH_BASE == JPATH_SITE
*
* If you are in the installation application:
*
* JPATH_BASE == JPATH_INSTALLATION.
*
* JPATH_ROOT is the root path for the Joomla install and does not depend upon any application.
*
* @var array
*/
public static $constantPaths = array(
// The path to the administrator folder.
'JPATH_ADMINISTRATOR' => JPATH_ADMINISTRATOR,
// The path to the installed Joomla! site, or JPATH_ROOT/administrator if executed from the backend.
'JPATH_BASE' => JPATH_BASE,
// The path to the cache folder.
'JPATH_CACHE' => JPATH_CACHE,
// The path to the administration folder of the current component being executed.
'JPATH_COMPONENT_ADMINISTRATOR' => JPATH_COMPONENT_ADMINISTRATOR,
// The path to the site folder of the current component being executed.
'JPATH_COMPONENT_SITE' => JPATH_COMPONENT_SITE,
// The path to the current component being executed.
'JPATH_COMPONENT' => JPATH_COMPONENT,
// The path to folder containing the configuration.php file.
'JPATH_CONFIGURATION' => JPATH_CONFIGURATION,
// The path to the installation folder.
'JPATH_INSTALLATION' => JPATH_INSTALLATION,
// The path to the libraries folder.
'JPATH_LIBRARIES' => JPATH_LIBRARIES,
// The path to the plugins folder.
'JPATH_PLUGINS' => JPATH_PLUGINS,
// The path to the installed Joomla! site.
'JPATH_ROOT' => JPATH_ROOT,
// The path to the installed Joomla! site.
'JPATH_SITE' => JPATH_SITE,
// The path to the templates folder.
'JPATH_THEMES' => JPATH_THEMES
);
/** /**
* Get the snippet contributor details * Get the snippet contributor details
* *