Posted in : Hacks
This is a fix to move a categories children when you move the category. It should work in all 1.8/1.9 versions and is already fixed in 2.0
inc/model/collectons/_category.funcs.php, find this bit of code :-
Code:
/** | |
* Update a category | |
* | |
* This funtion has to handle all needed DB dependencies! | |
*/ | |
function cat_update( | |
$cat_ID, | |
$cat_name, | |
$cat_parent_ID = 0, | |
$cat_blog_ID = '' ) | |
{ | |
global $DB; | |
| |
if( $cat_parent_ID == 0 ) $cat_parent_ID = 'NULL'; | |
| |
return $DB->query( "UPDATE T_categories | |
SET cat_name = ".$DB->quote($cat_name).", | |
cat_parent_ID = $cat_parent_ID ". | |
(!empty($cat_blog_ID) ? ", cat_blog_ID = $cat_blog_ID" : '')." | |
WHERE cat_ID = $cat_ID" ); | |
} |
and replace it with this :-
Code:
/** | |
* Update a category | |
* | |
* This funtion has to handle all needed DB dependencies! | |
*/ | |
function cat_update( | |
$cat_ID, | |
$cat_name, | |
$cat_parent_ID = 0, | |
$cat_blog_ID = '' ) | |
{ | |
global $DB; | |
| |
if ( !empty( $cat_blog_ID ) ) | |
{// lets move any/all children | |
cat_movechildren( $cat_ID, $cat_blog_ID ); | |
} | |
| |
if( $cat_parent_ID == 0 ) $cat_parent_ID = 'NULL'; | |
| |
return $DB->query( "UPDATE T_categories | |
SET cat_name = ".$DB->quote($cat_name).", | |
cat_parent_ID = $cat_parent_ID ". | |
(!empty($cat_blog_ID) ? ", cat_blog_ID = $cat_blog_ID" : '')." | |
WHERE cat_ID = $cat_ID" ); | |
} | |
| |
| |
/** | |
* Recursively move a categories children | |
*/ | |
function cat_movechildren( $cat_ID, $cat_blog_ID ) | |
{ | |
global $DB; | |
$sql = 'select cat_ID from T_categories where cat_parent_ID = '.$cat_ID; | |
$results = $DB->get_results( $sql, ARRAY_A ); | |
if( $results ) | |
{ | |
foreach( $results as $record ) | |
{ | |
// first lets move the category | |
$sql = 'update T_categories | |
set cat_blog_ID = '.$cat_blog_ID.' | |
where cat_ID = '.$record[ 'cat_ID' ]; | |
$DB->query( $sql ); | |
// now lets move any children of this child | |
cat_movechildren( $record[ 'cat_ID' ], $cat_blog_ID ); | |
} | |
} | |
} |
¥
Trackback URL (right click and copy shortcut/link location)
Trackback url for this post
Note : This trackback url is time limited so use it within 30 minutes or the SpamHound will snarl at you.
http://waffleson.co.uk/z/?k=3173260263310323840a90857572ca919e65be5b69ab33b53
Comments are closed for this post.