?
avatar vijaykhollam
vijaykhollam
6 Aug 2016

Steps to reproduce the issue

  1. Install 3rd party extension that uses Joomla category manager.
  2. Create category using that extesnsion.
  3. Uninstall extension.
  4. Install same extension again.
  5. We can see that Category gets deleted with that extension.

Expected result

  1. Joomla can have config at com_categories like Delete categories on uninstalling component
    i.e Yes / No. By default, we can set it to YES.
avatar vijaykhollam vijaykhollam - open - 6 Aug 2016
avatar vijaykhollam vijaykhollam - change - 6 Aug 2016
The description was changed
avatar vijaykhollam vijaykhollam - edited - 6 Aug 2016
avatar brianteeman
brianteeman - comment - 6 Aug 2016

Removingg data is the role of the extension. Some extensions do, some dont

avatar rdeutz
rdeutz - comment - 6 Aug 2016

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.

avatar rdeutz rdeutz - change - 6 Aug 2016
Status New Closed
Closed_Date 0000-00-00 00:00:00 2016-08-06 10:33:52
Closed_By rdeutz
avatar rdeutz rdeutz - close - 6 Aug 2016
avatar rdeutz rdeutz - close - 6 Aug 2016
avatar vijaykhollam vijaykhollam - change - 6 Aug 2016
The description was changed
avatar vijaykhollam vijaykhollam - edited - 6 Aug 2016
avatar vijaykhollam vijaykhollam - change - 6 Aug 2016
Title
Delete category after uninstalling extension
Do not delete category on uninstalling extension
avatar vijaykhollam vijaykhollam - edited - 6 Aug 2016
avatar vijaykhollam vijaykhollam - edited - 6 Aug 2016
avatar vijaykhollam vijaykhollam - change - 6 Aug 2016
Title
Delete category after uninstalling extension
Do not delete category on uninstalling extension
avatar manojLondhe
manojLondhe - comment - 6 Aug 2016

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.

avatar manojLondhe
manojLondhe - comment - 6 Aug 2016

@brianteeman @rdeutz Is there a way to prevent this?

avatar brianteeman
brianteeman - comment - 6 Aug 2016

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.

avatar manojLondhe
manojLondhe - comment - 6 Aug 2016

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.

avatar ggppdk
ggppdk - comment - 6 Aug 2016

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,

  • indeed if an extension asks you to keep data, and you say yes , and then you reinstall, all data of the extension is there but extension's categories are gone,

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

avatar vijaykhollam
vijaykhollam - comment - 6 Aug 2016

I think we should reopen this and discuss it.

avatar brianteeman brianteeman - reopen - 6 Aug 2016
avatar brianteeman brianteeman - change - 6 Aug 2016
Status Closed New
Closed_Date 2016-08-06 10:33:57
Closed_By rdeutz
avatar brianteeman brianteeman - reopen - 6 Aug 2016
avatar rdeutz
rdeutz - comment - 6 Aug 2016

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.

avatar brianteeman
brianteeman - comment - 6 Aug 2016

Surprised and reopened

avatar ggppdk
ggppdk - comment - 6 Aug 2016

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

avatar parthlawate
parthlawate - comment - 6 Aug 2016

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

avatar eshiol
eshiol - comment - 25 Oct 2016

I think the same of parthlawate.
Anyway JInstallerAdapterComponent::uninstall() has a bug. It deletes the categories but it doesn't delete the related assets.

avatar eshiol
eshiol - comment - 25 Oct 2016

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();
        }
    }
}
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 6 Apr 2017

@eshiol can you make a PR to resolve this Issue?


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/11490.

avatar joomla-cms-bot joomla-cms-bot - change - 6 Apr 2017
The description was changed
avatar joomla-cms-bot joomla-cms-bot - edited - 6 Apr 2017
avatar franz-wohlkoenig franz-wohlkoenig - change - 6 Apr 2017
Status New Information Required
avatar franz-wohlkoenig franz-wohlkoenig - change - 27 May 2017
The description was changed
Status Information Required Closed - No Reply
Closed_Date 0000-00-00 00:00:00 2017-05-27 10:22:49
Closed_By franz-wohlkoenig
avatar joomla-cms-bot joomla-cms-bot - change - 27 May 2017
The description was changed
Status Closed - No Reply Information Required
avatar joomla-cms-bot joomla-cms-bot - edited - 27 May 2017
avatar joomla-cms-bot joomla-cms-bot - change - 27 May 2017
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
avatar joomla-cms-bot joomla-cms-bot - close - 27 May 2017
avatar joomla-cms-bot
joomla-cms-bot - comment - 27 May 2017
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 27 May 2017

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.

Add a Comment

Login with GitHub to post a comment