query($select_courses);
while($course = mysql_fetch_assoc($courses_result)) {
$courses_count++;
//$message .= 'Course: ' . $course['title'] . '
';
// Get gidden posts, old style
$select_posts = "SELECT id, c.link as link, title FROM ".DB_PREFIX."posts c LEFT JOIN ".DB_PREFIX."course_rels_posts r ON c.link=r.link WHERE r.course_guid=".$course['course_guid']." AND c.hidden";
$posts_result = $db->query($select_posts);
$posts = array();
if ($posts_result) {
while($pst = mysql_fetch_assoc($posts_result)) {
$posts[] = $pst;
}
}
foreach ($posts as $post) {
$message .= 'Hidden post: ' . $post['title'] . ' ';
$posts_count++;
$post_hid = $db->hidePostById($post['id'], $course['course_guid']);
if ($post_hid) {
$message .= 'SUCCESS
';
$success_posts_count++;
} else {
$message .= 'FAILED ';
$message .= 'ALTERNATE TRY: ';
$alternate_post_update = 'UPDATE '.DB_PREFIX.'course_rels_posts SET hidden=1 WHERE course_guid='.$course['course_guid'].' AND link="'.$post['link'].'";';
$post_updated = $db->query($alternate_post_update);
if ($post_updated) {
$message .= 'SUCCEED
';
} else {
$message .= 'FAILED [ '.$alternate_post_update.' ]
';
}
}
}
// Get hidden comments, old style
$query = "SELECT id, c.link as link, title FROM ".DB_PREFIX."comments c LEFT JOIN ".DB_PREFIX."course_rels_comments r ON c.link=r.link WHERE r.course_guid=".$course['course_guid']." AND c.hidden";
$result = $db->query($query);
$comments = array();
if ($result) {
while($res = mysql_fetch_assoc($result)) {
$comments[] = $res;
}
}
foreach ($comments as $comment) {
$message .= 'Hidden comment: ' . $comment['title'] . ' ';
$comments_count++;
$comment_hid = $db->hideCommentById($comment['id'], $course['course_guid']);
if ($comment_hid) {
$message .= 'SUCCESS
';
$success_comments_count++;
} else {
$message .= 'FAILED ';
$message .= 'ALTERNATE TRY: ';
$alternate_comment_update = 'UPDATE '.DB_PREFIX.'course_rels_comments SET hidden=1 WHERE course_guid='.$course['course_guid'].' AND link="'.$comment['link'].'";';
$comment_updated = $db->query($alternate_comment_update);
if ($comment_updated) {
$message .= 'SUCCEED
';
} else {
$message .= 'FAILED [ '.$alternate_comment_update.' ]
';
}
}
}
}
$message .= '
All courses: ' . $courses_count . '
';
$message .= 'Hidden posts success: ' . $success_posts_count . ' out of ' .$posts_count . '
';
$message .= 'Hidden comments success: ' . $success_comments_count . ' out of '. $comments_count . '
';
return $message;
}
// Run migraton
//echo suckr_upgrade_hidden_to_rels();
?>