Просмотр файла includes/prune.php

Размер файла: 3.97Kb
  1. <?php
  2. /***************************************************************************
  3. * mides.ru
  4. * -------------------
  5. ***************************************************************************/
  6. if ( !defined('IN_PHPBB') )
  7. {
  8. die("Hacking attempt");
  9. }
  10.  
  11. require($phpbb_root_path . 'includes/functions_search.'.$phpEx);
  12.  
  13. function prune($forum_id, $prune_date, $prune_all = false)
  14. {
  15. global $db, $lang;
  16.  
  17. $sql = 'SELECT topic_id FROM ' . TOPICS_TABLE . '
  18. WHERE topic_last_post_id = 0';
  19. if ( !($result = $db->sql_query($sql)) )
  20. {
  21. message_die(GENERAL_ERROR, 'Could not obtain lists of topics to sync', '', __LINE__, __FILE__, $sql);
  22. }
  23.  
  24. while( $row = $db->sql_fetchrow($result) )
  25. {
  26. sync('topic', $row['topic_id']);
  27. }
  28.  
  29. $db->sql_freeresult($result);
  30.  
  31. $prune_all = ($prune_all) ? '' : 'AND t.topic_vote = 0 AND t.topic_type <> ' . POST_ANNOUNCE;
  32.  
  33. $sql = "SELECT t.topic_id
  34. FROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t
  35. WHERE t.forum_id = $forum_id
  36. $prune_all
  37. AND p.post_id = t.topic_last_post_id";
  38. if ( $prune_date != '' )
  39. {
  40. $sql .= " AND p.post_time < $prune_date";
  41. }
  42.  
  43. if ( !($result = $db->sql_query($sql)) )
  44. {
  45. message_die(GENERAL_ERROR, 'Could not obtain lists of topics to prune', '', __LINE__, __FILE__, $sql);
  46. }
  47.  
  48. $sql_topics = '';
  49. while( $row = $db->sql_fetchrow($result) )
  50. {
  51. $sql_topics .= ( ( $sql_topics != '' ) ? ', ' : '' ) . $row['topic_id'];
  52. }
  53. $db->sql_freeresult($result);
  54. if( $sql_topics != '' )
  55. {
  56. $sql = "SELECT post_id
  57. FROM " . POSTS_TABLE . "
  58. WHERE forum_id = $forum_id
  59. AND topic_id IN ($sql_topics)";
  60. if ( !($result = $db->sql_query($sql)) )
  61. {
  62. message_die(GENERAL_ERROR, 'Could not obtain list of posts to prune', '', __LINE__, __FILE__, $sql);
  63. }
  64.  
  65. $sql_post = '';
  66. while ( $row = $db->sql_fetchrow($result) )
  67. {
  68. $sql_post .= ( ( $sql_post != '' ) ? ', ' : '' ) . $row['post_id'];
  69. }
  70. $db->sql_freeresult($result);
  71.  
  72. if ( $sql_post != '' )
  73. {
  74. $sql = "DELETE FROM " . TOPICS_WATCH_TABLE . "
  75. WHERE topic_id IN ($sql_topics)";
  76. if ( !$db->sql_query($sql, BEGIN_TRANSACTION) )
  77. {
  78. message_die(GENERAL_ERROR, 'Could not delete watched topics during prune', '', __LINE__, __FILE__, $sql);
  79. }
  80.  
  81. $sql = "DELETE FROM " . TOPICS_TABLE . "
  82. WHERE topic_id IN ($sql_topics)";
  83. if ( !$db->sql_query($sql) )
  84. {
  85. message_die(GENERAL_ERROR, 'Could not delete topics during prune', '', __LINE__, __FILE__, $sql);
  86. }
  87.  
  88. $pruned_topics = $db->sql_affectedrows();
  89.  
  90. $sql = "DELETE FROM " . POSTS_TABLE . "
  91. WHERE post_id IN ($sql_post)";
  92. if ( !$db->sql_query($sql) )
  93. {
  94. message_die(GENERAL_ERROR, 'Could not delete post_text during prune', '', __LINE__, __FILE__, $sql);
  95. }
  96.  
  97. $pruned_posts = $db->sql_affectedrows();
  98.  
  99. $sql = "DELETE FROM " . POSTS_TEXT_TABLE . "
  100. WHERE post_id IN ($sql_post)";
  101. if ( !$db->sql_query($sql) )
  102. {
  103. message_die(GENERAL_ERROR, 'Could not delete post during prune', '', __LINE__, __FILE__, $sql);
  104. }
  105.  
  106. remove_search_post($sql_post);
  107. prune_attachments($sql_post);
  108.  
  109. return array ('topics' => $pruned_topics, 'posts' => $pruned_posts);
  110. }
  111. }
  112.  
  113. return array('topics' => 0, 'posts' => 0);
  114. }
  115.  
  116. function auto_prune($forum_id = 0)
  117. {
  118. global $db, $lang;
  119.  
  120. $sql = "SELECT *
  121. FROM " . PRUNE_TABLE . "
  122. WHERE forum_id = $forum_id";
  123. if ( !($result = $db->sql_query($sql)) )
  124. {
  125. message_die(GENERAL_ERROR, 'Could not read auto_prune table', '', __LINE__, __FILE__, $sql);
  126. }
  127.  
  128. if ( $row = $db->sql_fetchrow($result) )
  129. {
  130. if ( $row['prune_freq'] && $row['prune_days'] )
  131. {
  132. $prune_date = time() - ( $row['prune_days'] * 86400 );
  133. $next_prune = time() + ( $row['prune_freq'] * 86400 );
  134.  
  135. prune($forum_id, $prune_date);
  136. sync('forum', $forum_id);
  137.  
  138. $sql = "UPDATE " . FORUMS_TABLE . "
  139. SET prune_next = $next_prune
  140. WHERE forum_id = $forum_id";
  141. if ( !$db->sql_query($sql) )
  142. {
  143. message_die(GENERAL_ERROR, 'Could not update forum table', '', __LINE__, __FILE__, $sql);
  144. }
  145. }
  146. }
  147.  
  148. return;
  149. }
  150.  
  151. ?>