function prn() { if (!DBG_USER) { return; } foreach (func_get_args() as $var) { prn_r($var); } }
} // Check post_attachment markers $sql = "SELECT p.post_id\n\t\tFROM " . BB_POSTS . " p\n\t\tLEFT JOIN " . BB_ATTACHMENTS . " a USING(post_id)\n\t\tWHERE p.post_attachment = 1\n\t\tAND a.post_id IS NULL"; foreach (DB()->fetch_rowset($sql) as $row) { $posts_without_attach[] = $row['post_id']; } if ($posts_sql = join(',', $posts_without_attach)) { if ($fix_errors) { DB()->query("UPDATE " . BB_POSTS . " SET post_attachment = 0 WHERE post_id IN({$posts_sql})"); } } // Check topic_attachment markers $sql = "SELECT t.topic_id\n\t\tFROM " . BB_POSTS . " p, " . BB_TOPICS . " t\n\t\tWHERE t.topic_id = p.topic_id\n\t\t\tAND t.topic_attachment = 1\n\t\tGROUP BY p.topic_id\n\t\tHAVING SUM(p.post_attachment) = 0"; foreach (DB()->fetch_rowset($sql) as $row) { $topics_without_attach[] = $row['topic_id']; } if ($topics_sql = join(',', $topics_without_attach)) { if ($fix_errors) { DB()->query("UPDATE " . BB_TOPICS . " SET topic_attachment = 0 WHERE topic_id IN({$topics_sql})"); } } } if ($debug_mode) { prn_r($orphan_files, '$orphan_files'); prn_r($orphan_db_attach, '$orphan_db_attach'); prn_r($orphan_tor, '$orphan_tor'); prn_r($posts_without_attach, '$posts_without_attach'); prn_r($topics_without_attach, '$topics_without_attach'); } DB()->query("DROP TEMPORARY TABLE {$tmp_attach_tbl}"); unset($fix_errors, $debug_mode);