Quantcast
Channel: phpBB.com
Viewing all articles
Browse latest Browse all 2802

phpBB Custom Coding • Re: post_subject = topic_title

$
0
0
I have custom script for various maintenance tasks like this and execute it with cron job once a day. There is probably a more efficient way to do this but you can just use a loop.
Thanks

Code:

<?php//set a high time limit, 300 is 5 minutesset_time_limit(300);//DB credentials$dbhost = '';$dbname = '';$dbuser = '';$dbpasswd = '';$link = mysqli_connect($dbhost, $dbuser, $dbpasswd, $dbname);//Query to find diff among post_subjects and first post subject (= topic_title) in all topics and all posts$sql1 = 'SELECT phplm_topics.topic_id, phplm_topics.topic_title, phplm_posts.post_id, phplm_posts.post_subjectFROM phplm_topicsLEFT JOIN phplm_postsON phplm_topics.topic_id=phplm_posts.topic_idWHERE phplm_topics.topic_title<>phplm_posts.post_subjectAND CONCAT("Re: ", phplm_topics.topic_title)<>phplm_posts.post_subject';$result1 = mysqli_query($link, $sql1);$topics = array();while($row = mysqli_fetch_assoc($result1)){$topics[] = $row;}mysqli_free_result($result1);$num = 0;foreach ($topics as $topic){$num = $num + 1;echo $topic['topic_id'] . ' - ' . $topic['topic_title'] . ' - ' . $topic['post_id'] . ' - ' . $topic['post_subject'] . '<br>';echo '<br>';$topic_ID = $topic['topic_id'];$new_topic_title = $topic['topic_title'];//SQL to update posts table.$sql2 = "UPDATE phplm_topics SET topic_title = '$new_topic_title' WHERE topic_id ='$topic_ID'";$result2 = mysqli_query($link, $sql2);$sql3 = "UPDATE phplm_topics SET topic_last_post_subject = CONCAT('Re: ', '$new_topic_title') WHERE topic_id = '$topic_ID'";$result3 = mysqli_query($link, $sql3);$sql4 = "UPDATE phplm_posts SET post_subject = CONCAT('Re: ', '$new_topic_title') WHERE topic_id = '$topic_ID'";$result4 = mysqli_query($link, $sql4);// Change first post subject (removes Re:)$sql5 = "UPDATE phplm_posts pLEFT JOIN phplm_topics tON p.topic_id = t.topic_id AND p.topic_id = '$topic_ID'SET p.post_subject = t.topic_titleWHERE p.post_id = t.topic_first_post_id";$result5 = mysqli_query($link, $sql5);}echo 'Total changes = ' . $num;?>

Statistics: Posted by gvp9000 — Wed Apr 23, 2025 8:40 am



Viewing all articles
Browse latest Browse all 2802

Trending Articles