Moving categories

In this board you can talk about general questions about phpMyFAQ

Moderator: Thorsten

Post Reply
bram
Posts: 19
Joined: Mon Aug 16, 2010 12:54 pm

Moving categories

Post by bram »

This is not a real bug reports just some remarks about the moving categories code.

Currently the swapCategories code in inc/Category.php / inc/PMF_Category/Helper.php does:
a) create a random id between 200000 and 400000
b) update the id1 in faqcategories with the random id
c) update the id2 in faqcategories with id1
d) update the random id in faqcategories with id2
e) repeat for all the other tables and columns that use faqcategories id

I can see several 'problems' with this:
a) if a query fails then some id's are updated while others are not. This means that some data can now be shown in the wrong category and fixing this requires manual work on the database and some good thinking on determing what queries succeeeded, which one failed and which queries were not executed.
b) if the web server or the database crashes then it also requires manual work in the database (same as a)
c) the swapCategories function need to know every place where the category is used. In most designs the code that uses faqcategories knows it and the faqcategories code does not know where it is used.
d) swapping the id's like this will prevent referential integrity (on the database layer) from ever being used


Possible solutions;
a) execute the queries in a transaction (if this is possible on all support database backends?). This will fix 'a' and 'b'
b) add an extra 'order' column and always sort on this column. When a category is moved then only faqcategories.order needs to be updated and all other tables not. This wil fix 'c' and 'd'.
c) ...?
Thorsten
Posts: 15562
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Re: Moving categories

Post by Thorsten »

Hi,

I know, this is a shitty implementation. I already rewrote the whole category stuff in the master branch using SPL but the moving of categories is still using this old piece of code.

The master branch will be version 3.0 and currently I'm working on 2.7 with the old category stuff but I'm removing e.g. support for MySQL 4.1, which was the last blocker using transactions.

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
Post Reply