Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-06-29 13:34:45

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,446
Website GitHub

Deleting categories

When deleting a category it is removed from txp_category but the name still remains in the article/image/file/link tables until individually edited; at which point the category dropdown is displayed empty because the entry no longer exists. Until each affected item is revisited and saved, both the admin and public sides (e.g. file_download_category) display the deleted category. Not sure on the impact of missing categories on the URL; haven’t tried it. Maybe it just returns an empty list.

Question: should deleting a category also remove its name from affected articles/image/links/files or is there a reason (aside from a lot of code!) that it is desirable to leave the non-existent category names in their respective places? Or should the possible introduction of category safeguards be the simpler way to circumvent this?

I guess this is all made awkward because the articles/images etc are not back-referenced by ID from txp_category; hard-coded instead into the relevant tables by name. Saves a join I suppose, but causes minor referential integrity issues in this case.

I’d vote for preventing deletion of used categories, if that’s still planned, but I don’t know what others feel about this. Perhaps it’s a non-issue.

Last edited by Bloke (2008-06-29 13:36:24)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#2 2008-06-29 16:15:20

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Deleting categories

For 4.0.7, I’ll work on preventing the removal of categories that are still in use. It was already done for style sheets, pages and sections, but back then I guess I accidentally forgot to do this for categories as well.

Offline

#3 2008-06-29 16:21:52

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,446
Website GitHub

Re: Deleting categories

Brilliant! Thank you, kind sir.

Last edited by Bloke (2008-06-29 16:22:02)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#4 2008-06-29 19:21:08

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Deleting categories

Should be fixed in SVN changeset 2921

Offline

#5 2008-06-29 20:13:20

masa
Member
From: Asturias, Spain
Registered: 2005-11-25
Posts: 1,091

Re: Deleting categories

Just wondering, would that also prevent deletion of parent categories that have no children and aren’t assigned to any articles etc.?

I once had an incident with a user, who accidentally deleted a parent cat thereby zapping an entire category menu from the site.

Last edited by masa (2008-06-29 20:14:10)

Offline

#6 2008-06-29 20:29:47

thebombsite
Archived Plugin Author
From: Exmouth, England
Registered: 2004-08-24
Posts: 3,251
Website

Re: Deleting categories

Ruud – I know it’s Sunday and you probably have nothing better to do but that was too quick. ;)


Stuart

In a Time of Universal Deceit
Telling the Truth is Revolutionary.

Offline

#7 2008-06-29 20:49:06

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Deleting categories

masa wrote:

Just wondering, would that also prevent deletion of parent categories that have no children and aren’t assigned to any articles etc.?

If you delete a parent category that is not used, the child categories will still exist, but they’ll have ‘root’ as parent category (top-level category). In an older TXP version (before 4.0.4, I think) deleting a parent could in some cases corrupt the category table and child categories could disappear, but that has been fixed long ago.

Last edited by ruud (2008-06-29 20:50:22)

Offline

#8 2008-06-29 22:37:56

masa
Member
From: Asturias, Spain
Registered: 2005-11-25
Posts: 1,091

Re: Deleting categories

ruud wrote:

If you delete a parent category that is not used, the child categories will still exist, but they’ll have ‘root’ as parent category (top-level category).

That was exactly what made my category menu disappear as decribed above.
I use the following code to build the menu:

<txp:category_list parent="category-1" exclude="category-1" break="li" label="Price Range" labeltag="h3" this_section="1" type="article" wraptag="ul" />

Once the parent, category-1 (Price Range), got accidentally deleted the children were still there, but the menu showed up empty.
Is it possible to check for this and prevent the deletion of a parent even though it isn’t assigned to anything else?

Offline

#9 2008-06-29 22:48:35

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,446
Website GitHub

Re: Deleting categories

masa wrote:

Once the parent, category-1 (Price Range), got accidentally deleted the children were still there, but the menu showed up empty.
Is it possible to check for this and prevent the deletion of a parent even though it isn’t assigned to anything else?

I’m not sure. That’s a usage issue, not necessarily a database ‘keeping-things-in-line’ issue.

As far as the DB is concerned, the parent category has no items associated with it so would get deleted and the orphaned children live on with a new parent: “root”. However, I can see your logic. The parent can indeed be regarded as having “content” because it has children categories assigned to it.

The number of children each parent has is registered so I think it would be possible to check for this. But whether this is something that should be on by default (or an ‘allow parents to be deleted if they have children’ option?) I couldn’t say.

Last edited by Bloke (2008-06-29 22:49:42)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#10 2008-06-29 23:07:03

masa
Member
From: Asturias, Spain
Registered: 2005-11-25
Posts: 1,091

Re: Deleting categories

Bloke wrote:

The number of children each parent has is registered so I think it would be possible to check for this. But whether this is something that should be on by default (or an ‘allow parents to be deleted if they have children’ option?) I couldn’t say.

This isn’t an area I know much about, but the parent-child relations must be stored somehwere in the db, so it should be possible to check for. It’s not a big issue for me since I worked around it using ied_hide_in_admin to remove the category listings I don’t want to be messed with.

However I still think that safety could be improved here.

Offline

#11 2008-06-30 17:17:10

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Deleting categories

It’s possible (and easy, I think) to prevent parent categories from being deleted… so the only question now is… is the current behavior desirable or should it be changed and are there any downsides to changing it?

Offline

#12 2008-06-30 19:23:07

masa
Member
From: Asturias, Spain
Registered: 2005-11-25
Posts: 1,091

Re: Deleting categories

To be honest, I can’t think of a situation where the current behaviour would be preferable. Even if you use parents for organisational purposes only, it would be lost, which could be annoying/disastrous.

If others vote for the current behaviour, I would suggest to at least implement a warning dialogue as a compromise:

You are about to delete a parent category that is in use. Deleting it might affect how your site displays on the web.
Are you sure you want to continue?
(Cancel) | (Continue)

Makes sense?

PS: I’m a bit surprised not more people chime in here as this is IMHO a crucial area, if you’re building sites for others to maintain

Last edited by masa (2008-06-30 19:30:26)

Offline

Board footer

Powered by FluxBB