I thought about your previous question regarding the separation of category/forum view and post classes, and I think my reply could be useless depending on the new user class structure that is introduced in v0.8. Will test this out on my test installation and report back later.
Always nice to have a helping hand. I think i'll create a account on some code dropbox, or maybe I could receive access to the svn afterall, so I could publish my code for review?
Whenever I am mostly done with something I could upload it there and get it checked for bugs
Well, I mostly test my code extensivly, but security is important. (Like serializing and stuff?)
In forum_f, having each row containing the following columns; forum_forum_subs <- an array of all the subforums this forum carries. forum_forum_sub <- show if forum IS a subforum or not. (0=no sub, x=id of parentforum)
Then have the code select all rows where forum_forum_sub = '0' (Thus forum is NOT a subforum).
$sql2->db_Select("forum_f", "*", "WHERE forum_parent_id='".$forum_parent_id."' AND forum_forum_sub='0'", false); while($row2 = $sql2->db_Fetch()) { // process $row2 extract($row2) !-- then check if $forum_forum_subs contains an array and for each of these value's db_Select() the corresponding subforum and display them }
OR
forum_forum_sub <- show if forum IS a subforum or not. (0=no sub, x=id of parentforum)
$sql2->db_Select("forum_f", "*", "WHERE forum_parent_id='".$forum_parent_id."' AND forum_forum_sub='0'", false); while($row2 = $sql2->db_Fetch()) { // process $row2 $sql3->db_Select("forum_f", "*", "WHERE forum_forum_sub='".$forum_forum_id."', false); while($row3 = $sql3->db_Fetch()) { // process $row3 } }
The first way is a bit of extra coding, but it will only query the db if the forum does indeed contain an array of subforums, (When deleting or moving a subforum, the parentforum's array must also be edited every time etc).
the second method ALWAYS queries the db for subforums...
I am having difficulty adding a cellspacing when displaying all the Parents/Forums/subforums This is just semantics, but I like to get it right the first time otherwise it will be more work to search exactly where the error is made. I'll make an account on github so I can store all my code there and link to it when I need help on a particular problem.
In case you are interested which method I used to display subforums, here is a snippet of that section:
Basicly, I want you to try to screw up the code by typing in (random) id and sub_id numbers into the URL and see if a wrong redirection is being done
If you could check the code itself aswell, to see if I am missing some things to prevent memory loss, that would be swell. ( Like $sql->db_Close() for example? Is this needed everytime and am I missing it somewhere? )
========================================================== Functions so far: PARENTS:
Creating and deleting of Parents
Creating of Parents with a selfsubmitted ID ( Type the ID behind the url and press enter to submit ID into form ) !! If ID already exists, page will redirect to the editing of said parent
If Parent is removed, next incremental ID nr will not be skipping a number.
If you want to edit a parent with non-existing ID, page will redirect to creating of said parent. If you want to remove a parent with non-existing ID, page will redirect to creating of said parent.
FORUMS:
Creating and deleting of Forums
Creating of Forums with a selfsubmitted ID ( Type the ID behind the url and press enter to submit ID into form ) !! If ID already exists, page will redirect to the editing of said forum
If Forum is removed, next incremental ID nr will not be skipping a number.
If you want to edit a forum with non-existing ID, page will redirect to creating of said forum. If you want to remove a forum with non-existing ID, page will redirect to creating of said forum.
SUBFORUMS:
Creating and deleting of Subforums
Creating of Subforums with a selfsubmitted ID ( Type the (SUB)ID behind the url and press enter to submit (SUB)ID into form ) !! If (SUB)ID already exists, page will redirect to the editing of said subforum
If Subforum is removed, next incremental ID nr will not be skipping a number.
If you want to edit a subforum with non-existing ID, page will redirect to creating of said subforum. If you want to remove a subforum with non-existing ID, page will redirect to creating of said subforum.
=====================================
I can provide a working DB example, images and ofcourse the code files.
Converting forums into subforums (provided they don't have subforums) is now working.
Converting subforums into forums is now working.
What would be the best way to handle deletion of a forum? e.g. should the subforums also be deleted or converted into forums (upon "parent"forum deletion)?
Im going to work on recursivly deleting forums->subforums->threads->posts
If a parent gets deleted, all (sub)forums->threads->posts get deleted.
If a (sub)forum gets deleted, all (subforums->)threads->posts get deleted If a thread gets deleted, all posts get deleted
EDIT: Subforums now also retrieve the forum_parent_id from their parentforum. This will make it easier to loop through when the parent gets deleted.
Not sure if I will keep it this way... might not store a forum_parent_id for subforums. (Might make deletion of a parent a bit harder, but now it's using more memory/db-queries to create and edit subforums...
Otherwise the value will be 0 by default for the forum_parent_id in the subforums. Deleting all forums from a parent then would require another loop to see if those forums themselves have subforums...
I am done with the confirmation functions. Next up will be the recursive deletion functions which shouldn't be too hard
EDIT: How can I test the performance/optimization of my script compared to the current forum? Refresh the page a few times and keep writing down the query info at the bottom? lol
EDIT3: I still have a few unanswered questions; mainly regarding the deletion of a forum. Should the subforum also be deleted or be converted into a real forum?
If no answer is given, Ill go ahead and delete everything. It would be the users own fault for not converting the subforums into forums beforehand.
When changing a forum to another parent, the new parent_id doesn't get updated into the subforums.
This is the kind of errors I am looking for to get found atm.. Any help in this area is appreciated, not only by me, but by every user of e107 who wants to use this forum in v0.8 .
mysql_query("ALTER TABLE e107_forum_f ORDER BY forum_forum_id ASC") or die (mysql_error()); $sql->db_Close(); $sql2->db_Close(); show_message(FORLAN_14); $action = "edit"; }
PS: Anyone know how to replace the mysql_query("ALTER TABLE e107_forum_f ORDER BY forum_forum_id ASC") or die (mysql_error()); with a $sql->db_..... ??
The recursive deletion isn't working as the function code isn't executed. Do I need some sort of return or something?
Here is what I have for deleting a parent: lev.0: Open the parent lev.1: - It first searches if the parent has forums
lev.2:-- It then searches if the forum has subforums lev.3:--- It then searches if the subforum has threads lev.4:---- It then searches if the threads have posts, and deletes them lev.3:--- It then deletes the threads lev.2:-- It then deletes the subforums
lev.1:-- It then searches if the forum has threads lev.2:--- It then searches if the threads have posts, and deletes them lev.2:-- It then deletes the threads lev.1:- It then deletes the forums
lev.0: Delete the parent
// --------------------------------------------------------------------------------------------------+ // ------------------------------------------------------------------------ function del_parents() --+ // --------------------------------------------------------------------------------------------------+
function del_parents($parent_id) { global $sql, $sql2;
$sql2->db_Select("forum_f", "*", "forum_parent_id='$parent_id' AND forum_forum_sub='0'"); while($row2 = $sql2->db_Fetch()) { del_forums($row2['forum_forum_id']); } mysql_query("ALTER TABLE e107_forum_f AUTO_INCREMENT = 1, ORDER BY forum_forum_id ASC") or die (mysql_error()); $sql2->db_Close();
echo "Parent ".$parent_id."";
$sql->db_Delete("forum_p", "forum_parent_id='$parent_id'"); mysql_query("ALTER TABLE e107_forum_p AUTO_INCREMENT = 1, ORDER BY forum_parent_id ASC") or die (mysql_error()); $sql->db_Close(); }
// --------------------------------------------------------------------------------------------------+ // ------------------------------------------------------------------------- function del_forums() --+ // --------------------------------------------------------------------------------------------------+
function del_forums($forum_id) { global $sql2, $sql3, $sql4;
// Recursivly select all sub-forums
$sql3->db_Select("forum_f", "*", "forum_forum_sub='$forum_id'"); while($row3 = $sql3->db_Fetch()) { del_subforums($row3['forum_forum_id']); } mysql_query("ALTER TABLE e107_forum_f AUTO_INCREMENT = 1, ORDER BY forum_forum_id ASC") or die (mysql_error()); $sql3->db_Close();
PS: Anyone know how to replace the mysql_query("ALTER TABLE e107_forum_f ORDER BY forum_forum_id ASC") or die (mysql_error()); with a $sql->db_..... ??
Dont think it's valid to use ORDER BY in ALTER TABLE statement. e107_forum_f should have a primary key index on forum_forum_id. By default the order will be ascending... Use of ORDER BY should really only be needed in SELECT statements, and even then, use sparingly for performance, and ordinarily may not necessarily be a useful field to order data in all functional circumstances. Meaning you may want to order by date, or name or specific order rather than an internal id. This is Oracle DB logic ... am sure MySQL wont be much different.