Library Save to Copy does not copy folders accurately #1003

Closed
opened 2023-07-31 15:55:40 +00:00 by gaelicwinter · 1 comment

Steps to reproduce the issue

  1. Start with a relatively fresh install of JCB. I have my one component I'm working with.
  2. Create a library pointing to a folder. The id of my library is 7, since there are 6 previous libraries existing in JCB.
  3. Add a folder to the new library, which of course points to ADMIN/com_componentbuilder/custom/myfolder. Save this new library, test it and see that it compiles into the component properly.
  4. Edit the new library, and click the Save As Copy button.
  5. See that the new library is saved, but the Files, Folders & URLs tab contains data from one or more of the previous libraries that come with JCB, not from the library with id = 7.

Expected result

Save As Copy function should copy all the for data correctly.

Actual result

As described above.

System information (as much as possible)

  • OS Name & Version:
    Win 11
  • MySql Version:
    10.4.28-MariaDB
  • Apache Version:
    Apache/2.4.56 (Win64) OpenSSL/1.1.1t PHP/8.0.28
  • PHP Version:
    8.0.28
  • Joomla Version:
    3.10.12
  • JCB Version:
    3.1.24
  • Browser:
    Chrome 115.0.5790.110

Additional comments

I can do a record dump of the tables

#__componentbuilder_library
#__componentbuilder_library_files_folders_urls

which I think might be the most useful. You can see that in the newest #__componentbuilder_library_files_folders_urls record, the library field actually points to the wrong record in #__componentbuilder_library. I've traced the code but I've been unable to see where the mixup occurs.

### Steps to reproduce the issue 1. Start with a relatively fresh install of JCB. I have my one component I'm working with. 2. Create a library pointing to a folder. The id of my library is 7, since there are 6 previous libraries existing in JCB. 3. Add a folder to the new library, which of course points to ADMIN/com_componentbuilder/custom/myfolder. Save this new library, test it and see that it compiles into the component properly. 4. Edit the new library, and click the Save As Copy button. 5. See that the new library is saved, but the Files, Folders & URLs tab contains data from one or more of the previous libraries that come with JCB, not from the library with id = 7. ### Expected result Save As Copy function should copy all the for data correctly. ### Actual result As described above. ### System information (as much as possible) - OS Name & Version: Win 11 - MySql Version: 10.4.28-MariaDB - Apache Version: Apache/2.4.56 (Win64) OpenSSL/1.1.1t PHP/8.0.28 - PHP Version: 8.0.28 - Joomla Version: 3.10.12 - JCB Version: 3.1.24 - Browser: Chrome 115.0.5790.110 ### Additional comments I can do a record dump of the tables #__componentbuilder_library #__componentbuilder_library_files_folders_urls which I think might be the most useful. You can see that in the newest #__componentbuilder_library_files_folders_urls record, the library field actually points to the wrong record in #__componentbuilder_library. I've traced the code but I've been unable to see where the mixup occurs.
Owner

This is currently the code we are looking at:

// get the state object (Joomla\CMS\Object\CMSObject)
$state = $model->get('state');
// if we save2copy we need to also copy linked tables found!
if ($state->task === 'save2copy' && $state->{'library.new'})
{
	// get new ID
	$newID = $state->{'library.id'};
	// get old ID
	$oldID = $this->input->get('id', 0, 'INT');
	// linked tables to update
	$_tablesArray = array(
		'library_config',
		'library_files_folders_urls'
	);
	foreach($_tablesArray as $_updateTable)
	{
		// get the linked ID
		if ($_value = [[[Component]]]Helper::getVar($_updateTable, $oldID, 'library', 'id'))
		{
			// copy fields to new linked table
			[[[Component]]]Helper::copyItem(/*id->*/ $_value, /*table->*/ $_updateTable, /*change->*/ array('library' => $newID));
		}
	}
}

Which is converted to:

// get the state object (Joomla\CMS\Object\CMSObject)
$state = $model->get('state');
// if we save2copy we need to also copy linked tables found!
if ($state->task === 'save2copy' && $state->{'library.new'})
{
	// get new ID
	$newID = $state->{'library.id'};
	// get old ID
	$oldID = $this->input->get('id', 0, 'INT');
	// linked tables to update
	$_tablesArray = array(
		'library_config',
		'library_files_folders_urls'
	);
	foreach($_tablesArray as $_updateTable)
	{
		// get the linked ID
		if ($_value = ComponentbuilderHelper::getVar($_updateTable, $oldID, 'library', 'id'))
		{
			// copy fields to new linked table
			ComponentbuilderHelper::copyItem(/*id->*/ $_value, /*table->*/ $_updateTable, /*change->*/ array('library' => $newID));
		}
	}
}

If you can see where my logic is breaking down... we can add a fix.

The copyItem code is found here.

This is currently the code we are looking at: ``` // get the state object (Joomla\CMS\Object\CMSObject) $state = $model->get('state'); // if we save2copy we need to also copy linked tables found! if ($state->task === 'save2copy' && $state->{'library.new'}) { // get new ID $newID = $state->{'library.id'}; // get old ID $oldID = $this->input->get('id', 0, 'INT'); // linked tables to update $_tablesArray = array( 'library_config', 'library_files_folders_urls' ); foreach($_tablesArray as $_updateTable) { // get the linked ID if ($_value = [[[Component]]]Helper::getVar($_updateTable, $oldID, 'library', 'id')) { // copy fields to new linked table [[[Component]]]Helper::copyItem(/*id->*/ $_value, /*table->*/ $_updateTable, /*change->*/ array('library' => $newID)); } } } ``` Which is [converted to](https://git.vdm.dev/joomla/Component-Builder/src/branch/staging/admin/controllers/library.php#L319): ``` // get the state object (Joomla\CMS\Object\CMSObject) $state = $model->get('state'); // if we save2copy we need to also copy linked tables found! if ($state->task === 'save2copy' && $state->{'library.new'}) { // get new ID $newID = $state->{'library.id'}; // get old ID $oldID = $this->input->get('id', 0, 'INT'); // linked tables to update $_tablesArray = array( 'library_config', 'library_files_folders_urls' ); foreach($_tablesArray as $_updateTable) { // get the linked ID if ($_value = ComponentbuilderHelper::getVar($_updateTable, $oldID, 'library', 'id')) { // copy fields to new linked table ComponentbuilderHelper::copyItem(/*id->*/ $_value, /*table->*/ $_updateTable, /*change->*/ array('library' => $newID)); } } } ``` If you can see where my logic is breaking down... we can add a fix. The [copyItem code is found here](https://git.vdm.dev/joomla/Component-Builder/src/branch/staging/admin/helpers/componentbuilder.php#L1250).
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: joomla/Component-Builder#1003
No description provided.