Agreed that is the extensions job how it handles data and tables created by the component. Closing it because all what is needed to do it in one way or another is there for extensions developers.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2016-08-06 10:33:52 |
Closed_By | ⇒ | rdeutz |
Title |
|
Title |
|
Looks like issue reported is about not removing data. I have observed this too - all extensions using Joomla's category manager face this issue.
Uninstalling that extension (for whatever reasons) results into Joomla deleting all related categories.
Consider a case - you installed some e-commerce extensions, created 100 categories. Uninstalled component for some reason, reinstall it, and you loose all category data. This could be the very frustrating experience.
@brianteeman @rdeutz Is there a way to prevent this?
As it is a script in the extension doing that you would need to speak to
the developer of the extension. Personally I can't see a logical reason why
you would uninstall and extension and then reinstall it.
Extensions use Joomla's category manager. When uninstalling extension Joomla removes all category data -
This is the Joomla code doing category removal -
File
libraries/cms/installer/adapter/component.php
Function
public function uninstall($id)
Code
// Remove categories for this component
$query->clear()
->delete('#__categories')
->where('extension=' . $db->quote($this->element), 'OR')
->where('extension LIKE ' . $db->quote($this->element . '.%'));
$db->setQuery($query);
$db->execute();
For extension using Joomla category manager and which want to keep data after un-installation, this is a problem.
I confirm the code being there
Removing data is the role of the extension
Agreed that is the extensions job how it handles data and tables created by the component
So according to comments from both of you
the existing behaviour that Joomla deletes the categories is not proper,
so this should be reopened,
we need a way to set a flag for removing or not categories,
which by default it will be: "Yes, remove" to avoid a B/C break, since current code of extensions assumes that Joomla will do the part of removing components categories
I think we should reopen this and discuss it.
Status | Closed | ⇒ | New |
Closed_Date | 2016-08-06 10:33:57 | ⇒ | |
Closed_By | rdeutz | ⇒ |
Learned something new today. Tracked it back to 2013 and deleting categories when uninstalling a component is implemented since then. I am pretty sure that this wasn't the case at some point in history. I still think a component should be in control what data gets deleted when it get's uninstalled. As a extension developer I am in control of the database tables but as learned today not about the categories. I agree there should be an option but I think the right place is the manifest file.
Surprised and reopened
I have made a PR, we can close this and continue discussion there,
and see if my proposed way is more best choce
(i argue it is because it is more flexible than a flag at manifest file)
[EDIT]
i closed my PR, this issue should remain open
mbabker
spoke of making a PR with a more consistent solution
The category manager is a 'horizontal' infrastructure component.. The categories in there are 'owned' by components.. so it's only logical that the owner of the categories decide on its deletion.. I don't think this should be a default behavior at all. We can provide a method that the component can use in its uninstall script if it needs to do a clean up
I think the same of parthlawate.
Anyway JInstallerAdapterComponent::uninstall() has a bug. It deletes the categories but it doesn't delete the related assets.
I written a workaround. Before uninstall the component, the script renames the extension field into the table #__categories, so JInstallerAdapterComponent::uninstall() doesn't delete the categories.
Before install the component, the script restores the extension field into the table #__categories, so the component finds the old categories.
class Com_MycomponentInstallerScript
{
public function uninstall(JAdapterInstance $adapter)
{
$db = JFactory::getDbo();
// Preserve categories for this component issue #11490
$db->setQuery(
$db->getQuery(true)
->update('#__categories')
->set('extension=CONCAT('.$db->q('!').',extension,'.$db->q('!').')')
->where('extension='.$db->q('com_mycomponent'))
)->execute();
}
function preflight($type, $parent)
{
if ($type == 'install')
{
$db = JFactory::getDbo();
// Recovery categories for this component issue #11490
$db->setQuery(
$db->getQuery(true)
->update('#__categories')
->set('extension=SUBSTR(extension, 2, CHAR_LENGTH(extension) -2)')
->where('extension='.$db->q('!com_mycomponent!'))
)->execute();
}
}
}
@eshiol can you make a PR to resolve this Issue?
Status | New | ⇒ | Information Required |
Status | Information Required | ⇒ | Closed - No Reply |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2017-05-27 10:22:49 |
Closed_By | ⇒ | franz-wohlkoenig |
Status | Closed - No Reply | ⇒ | Information Required |
Status | Information Required | ⇒ | Closed |
Closed_Date | 2017-05-27 10:22:49 | ⇒ | 2017-05-27 10:22:50 |
Closed_By | franz-wohlkoenig | ⇒ | joomla-cms-bot |
Set to "closed" on behalf of @franz-wohlkoenig by The JTracker Application at issues.joomla.org/joomla-cms/11490
This has been closed due to lack of response to the requests above – it can always be reopened in the future if it is updated.
Removingg data is the role of the extension. Some extensions do, some dont