diff options
| author | Nils Adermann <naderman@naderman.de> | 2010-03-02 01:05:39 +0100 |
|---|---|---|
| committer | Nils Adermann <naderman@naderman.de> | 2010-03-02 01:05:39 +0100 |
| commit | 25052e1f673383f888c907e1b8ddf43236d2ad8e (patch) | |
| tree | 53dbead2e129183e6f01297c4d9468f712c666e5 /phpBB/includes/functions_admin.php | |
| parent | 4cc06650d4e74339d3680666323660120093b693 (diff) | |
| parent | b0e185e7dbaaf119578e75563c2fb5973bb2914c (diff) | |
| download | forums-25052e1f673383f888c907e1b8ddf43236d2ad8e.tar forums-25052e1f673383f888c907e1b8ddf43236d2ad8e.tar.gz forums-25052e1f673383f888c907e1b8ddf43236d2ad8e.tar.bz2 forums-25052e1f673383f888c907e1b8ddf43236d2ad8e.tar.xz forums-25052e1f673383f888c907e1b8ddf43236d2ad8e.zip | |
Merge commit 'release-3.0.3-RC1'
Diffstat (limited to 'phpBB/includes/functions_admin.php')
| -rw-r--r-- | phpBB/includes/functions_admin.php | 247 |
1 files changed, 109 insertions, 138 deletions
diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 028456c246..0349cbc6a8 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -97,7 +97,7 @@ function recalc_btree($sql_id, $sql_table, $module_class = '') $item_data['left_id'] = $row['right_id'] + 1; $item_data['right_id'] = $row['right_id'] + 2; } - + $sql = "UPDATE $sql_table SET left_id = {$item_data['left_id']}, right_id = {$item_data['right_id']} WHERE $sql_id = " . $item_data[$sql_id]; @@ -551,7 +551,7 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s 'posts' => ($call_delete_posts) ? delete_posts($where_type, $where_ids, false, true, $post_count_sync, false) : 0, ); - $sql = 'SELECT topic_id, forum_id, topic_approved + $sql = 'SELECT topic_id, forum_id, topic_approved, topic_moved_id FROM ' . TOPICS_TABLE . ' WHERE ' . $where_clause; $result = $db->sql_query($sql); @@ -561,7 +561,7 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s $forum_ids[] = $row['forum_id']; $topic_ids[] = $row['topic_id']; - if ($row['topic_approved']) + if ($row['topic_approved'] && !$row['topic_moved_id']) { $approved_topics++; } @@ -670,7 +670,7 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = $topic_ids[] = $row['topic_id']; $forum_ids[] = $row['forum_id']; - if ($row['post_postcount'] && $post_count_sync) + if ($row['post_postcount'] && $post_count_sync && $row['post_approved']) { $post_counts[$row['poster_id']] = (!empty($post_counts[$row['poster_id']])) ? $post_counts[$row['poster_id']] + 1 : 1; } @@ -709,6 +709,7 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = WHERE user_id = ' . $poster_id . ' AND user_posts < ' . $substract; $db->sql_query($sql); + $sql = 'UPDATE ' . USERS_TABLE . ' SET user_posts = user_posts - ' . $substract . ' WHERE user_id = ' . $poster_id . ' @@ -790,8 +791,8 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = /** * Delete Attachments * -* @param string $mode can be: post|topic|attach|user -* @param mixed $ids can be: post_ids, topic_ids, attach_ids, user_ids +* @param string $mode can be: post|message|topic|attach|user +* @param mixed $ids can be: post_ids, message_ids, topic_ids, attach_ids, user_ids * @param bool $resync set this to false if you are deleting posts or topics */ function delete_attachments($mode, $ids, $resync = true) @@ -813,42 +814,55 @@ function delete_attachments($mode, $ids, $resync = true) return false; } - $sql_id = ($mode == 'user') ? 'poster_id' : (($mode == 'post') ? 'post_msg_id' : (($mode == 'topic') ? 'topic_id' : 'attach_id')); + switch ($mode) + { + case 'post': + case 'message': + $sql_id = 'post_msg_id'; + break; - $post_ids = $topic_ids = $physical = array(); + case 'topic': + $sql_id = 'topic_id'; + break; - // Collect post and topics ids for later use - if ($mode == 'attach' || $mode == 'user' || ($mode == 'topic' && $resync)) - { - $sql = 'SELECT post_msg_id as post_id, topic_id, physical_filename, thumbnail, filesize - FROM ' . ATTACHMENTS_TABLE . ' - WHERE ' . $db->sql_in_set($sql_id, $ids); - $result = $db->sql_query($sql); + case 'user': + $sql_id = 'poster_id'; + break; - while ($row = $db->sql_fetchrow($result)) - { - $post_ids[] = $row['post_id']; - $topic_ids[] = $row['topic_id']; - $physical[] = array('filename' => $row['physical_filename'], 'thumbnail' => $row['thumbnail'], 'filesize' => $row['filesize']); - } - $db->sql_freeresult($result); + case 'attach': + default: + $sql_id = 'attach_id'; + $mode = 'attach'; + break; } - if ($mode == 'post') - { - $sql = 'SELECT topic_id, physical_filename, thumbnail, filesize + $post_ids = $message_ids = $topic_ids = $physical = array(); + + // Collect post and topic ids for later use if we need to touch remaining entries (if resync is enabled) + $sql = 'SELECT post_msg_id, topic_id, in_message, physical_filename, thumbnail, filesize, is_orphan FROM ' . ATTACHMENTS_TABLE . ' - WHERE ' . $db->sql_in_set('post_msg_id', $ids) . ' - AND in_message = 0'; - $result = $db->sql_query($sql); + WHERE ' . $db->sql_in_set($sql_id, $ids); + $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + while ($row = $db->sql_fetchrow($result)) + { + // We only need to store post/message/topic ids if resync is enabled and the file is not orphaned + if ($resync && !$row['is_orphan']) { - $topic_ids[] = $row['topic_id']; - $physical[] = array('filename' => $row['physical_filename'], 'thumbnail' => $row['thumbnail'], 'filesize' => $row['filesize']); + if (!$row['in_message']) + { + $post_ids[] = $row['post_msg_id']; + $topic_ids[] = $row['topic_id']; + } + else + { + $message_ids[] = $row['post_msg_id']; + } } - $db->sql_freeresult($result); + + $physical[] = array('filename' => $row['physical_filename'], 'thumbnail' => $row['thumbnail'], 'filesize' => $row['filesize'], 'is_orphan' => $row['is_orphan']); } + $db->sql_freeresult($result); // Delete attachments $sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . ' @@ -865,8 +879,9 @@ function delete_attachments($mode, $ids, $resync = true) $space_removed = $files_removed = 0; foreach ($physical as $file_ary) { - if (phpbb_unlink($file_ary['filename'], 'file', true)) + if (phpbb_unlink($file_ary['filename'], 'file', true) && !$file_ary['is_orphan']) { + // Only non-orphaned files count to the file size $space_removed += $file_ary['filesize']; $files_removed++; } @@ -876,121 +891,71 @@ function delete_attachments($mode, $ids, $resync = true) phpbb_unlink($file_ary['filename'], 'thumbnail', true); } } - set_config('upload_dir_size', $config['upload_dir_size'] - $space_removed, true); - set_config('num_files', $config['num_files'] - $files_removed, true); - if ($mode == 'topic' && !$resync) + if ($space_removed || $files_removed) { - return $num_deleted; + set_config('upload_dir_size', $config['upload_dir_size'] - $space_removed, true); + set_config('num_files', $config['num_files'] - $files_removed, true); } - if ($mode == 'post') + // If we do not resync, we do not need to adjust any message, post, topic or user entries + if (!$resync) { - $post_ids = $ids; + return $num_deleted; } + + // No more use for the original ids unset($ids); + // Now, we need to resync posts, messages, topics. We go through every one of them $post_ids = array_unique($post_ids); + $message_ids = array_unique($message_ids); $topic_ids = array_unique($topic_ids); - // Update post indicators + // Update post indicators for posts now no longer having attachments if (sizeof($post_ids)) { - if ($mode == 'post' || $mode == 'topic') - { - $sql = 'UPDATE ' . POSTS_TABLE . ' - SET post_attachment = 0 - WHERE ' . $db->sql_in_set('post_id', $post_ids); - $db->sql_query($sql); - } - - if ($mode == 'user' || $mode == 'attach') - { - $remaining = array(); - - $sql = 'SELECT post_msg_id - FROM ' . ATTACHMENTS_TABLE . ' - WHERE ' . $db->sql_in_set('post_msg_id', $post_ids) . ' - AND in_message = 0'; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - $remaining[] = $row['post_msg_id']; - } - $db->sql_freeresult($result); - - $unset_ids = array_diff($post_ids, $remaining); - - if (sizeof($unset_ids)) - { - $sql = 'UPDATE ' . POSTS_TABLE . ' - SET post_attachment = 0 - WHERE ' . $db->sql_in_set('post_id', $unset_ids); - $db->sql_query($sql); - } - - $remaining = array(); - - $sql = 'SELECT post_msg_id - FROM ' . ATTACHMENTS_TABLE . ' - WHERE ' . $db->sql_in_set('post_msg_id', $post_ids) . ' - AND in_message = 1'; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - $remaining[] = $row['post_msg_id']; - } - $db->sql_freeresult($result); - - $unset_ids = array_diff($post_ids, $remaining); + $sql = 'UPDATE ' . POSTS_TABLE . ' + SET post_attachment = 0 + WHERE ' . $db->sql_in_set('post_id', $post_ids); + $db->sql_query($sql); + } - if (sizeof($unset_ids)) - { - $sql = 'UPDATE ' . PRIVMSGS_TABLE . ' - SET message_attachment = 0 - WHERE ' . $db->sql_in_set('msg_id', $unset_ids); - $db->sql_query($sql); - } - } + // Update message table if messages are affected + if (sizeof($message_ids)) + { + $sql = 'UPDATE ' . PRIVMSGS_TABLE . ' + SET message_attachment = 0 + WHERE ' . $db->sql_in_set('msg_id', $message_ids); + $db->sql_query($sql); } + // Now update the topics. This is a bit trickier, because there could be posts still having attachments within the topic if (sizeof($topic_ids)) { - // Update topic indicator - if ($mode == 'topic') + // Just check which topics are still having an assigned attachment not orphaned by querying the attachments table (much less entries expected) + $sql = 'SELECT topic_id + FROM ' . ATTACHMENTS_TABLE . ' + WHERE ' . $db->sql_in_set('topic_id', $topic_ids) . ' + AND is_orphan = 0'; + $result = $db->sql_query($sql); + + $remaining_ids = array(); + while ($row = $db->sql_fetchrow($result)) { - $sql = 'UPDATE ' . TOPICS_TABLE . ' - SET topic_attachment = 0 - WHERE ' . $db->sql_in_set('topic_id', $topic_ids); - $db->sql_query($sql); + $remaining_ids[] = $row['topic_id']; } + $db->sql_freeresult($result); - if ($mode == 'post' || $mode == 'user' || $mode == 'attach') - { - $remaining = array(); + // Now only unset those ids remaining + $topic_ids = array_diff($topic_ids, $remaining_ids); - $sql = 'SELECT topic_id - FROM ' . ATTACHMENTS_TABLE . ' + if (sizeof($topic_ids)) + { + $sql = 'UPDATE ' . TOPICS_TABLE . ' + SET topic_attachment = 0 WHERE ' . $db->sql_in_set('topic_id', $topic_ids); - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - $remaining[] = $row['topic_id']; - } - $db->sql_freeresult($result); - - $unset_ids = array_diff($topic_ids, $remaining); - - if (sizeof($unset_ids)) - { - $sql = 'UPDATE ' . TOPICS_TABLE . ' - SET topic_attachment = 0 - WHERE ' . $db->sql_in_set('topic_id', $unset_ids); - $db->sql_query($sql); - } + $db->sql_query($sql); } } @@ -1015,7 +980,7 @@ function delete_topic_shadows($max_age, $forum_id = '', $auto_sync = true) . $where; $db->sql_query($sql); break; - + default: $sql = 'SELECT t.topic_id FROM ' . TOPICS_TABLE . ' t, ' . TOPICS_TABLE . ' t2 @@ -1213,7 +1178,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, AND t1.forum_id = t2.forum_id"; $db->sql_query($sql); break; - + default: $sql = 'SELECT t1.topic_id FROM ' .TOPICS_TABLE . ' t1, ' . TOPICS_TABLE . " t2 @@ -2369,7 +2334,7 @@ function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id $log_type = LOG_USERS; $sql_forum = 'AND l.reportee_id = ' . (int) $user_id; break; - + case 'users': $log_type = LOG_USERS; $sql_forum = ''; @@ -2379,7 +2344,7 @@ function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id $log_type = LOG_CRITICAL; $sql_forum = ''; break; - + default: return; } @@ -2433,8 +2398,14 @@ function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id if (isset($user->lang[$row['log_operation']])) { - // We supress the warning about inappropriate number of passed parameters here due to possible changes within LOG strings from one version to another. - $log[$i]['action'] = @vsprintf($log[$i]['action'], $log_data_ary); + // Check if there are more occurrences of % than arguments, if there are we fill out the arguments array + // It doesn't matter if we add more arguments than placeholders + if (substr_count($log[$i]['action'], '%') - sizeof($log_data_ary)) + { + $log_data_ary = array_merge($log_data_ary, array_fill(0, substr_count($log[$i]['action'], '%') - sizeof($log_data_ary), '')); + } + + $log[$i]['action'] = vsprintf($log[$i]['action'], $log_data_ary); // If within the admin panel we do not censor text out if (defined('IN_ADMIN')) @@ -2615,7 +2586,7 @@ function update_foes($group_id = false, $user_id = false) { case 'mysqli': case 'mysql4': - $sql = 'DELETE ' . (($db->sql_layer === 'mysqli' || version_compare($db->mysql_version, '4.1', '>=')) ? 'z.*' : ZEBRA_TABLE) . ' + $sql = 'DELETE ' . (($db->sql_layer === 'mysqli' || version_compare($db->sql_server_info(true), '4.1', '>=')) ? 'z.*' : ZEBRA_TABLE) . ' FROM ' . ZEBRA_TABLE . ' z, ' . USER_GROUP_TABLE . ' ug WHERE z.zebra_id = ug.user_id AND z.foe = 1 @@ -2637,7 +2608,7 @@ function update_foes($group_id = false, $user_id = false) $db->sql_freeresult($result); if (sizeof($users)) - { + { $sql = 'DELETE FROM ' . ZEBRA_TABLE . ' WHERE ' . $db->sql_in_set('zebra_id', $users) . ' AND foe = 1'; @@ -2717,7 +2688,7 @@ function view_inactive_users(&$users, &$user_count, $limit = 0, $offset = 0, $li $row['inactive_reason'] = $user->lang['INACTIVE_REASON_REMIND']; break; } - + $users[] = $row; } @@ -2897,7 +2868,7 @@ function get_remote_file($host, $directory, $filename, &$errstr, &$errno, $port @fputs($fsock, "GET $directory/$filename HTTP/1.1\r\n"); @fputs($fsock, "HOST: $host\r\n"); @fputs($fsock, "Connection: close\r\n\r\n"); - + $file_info = ''; $get_info = false; @@ -2936,7 +2907,7 @@ function get_remote_file($host, $directory, $filename, &$errstr, &$errno, $port return false; } } - + return $file_info; } @@ -2972,7 +2943,7 @@ function tidy_warnings() $sql = 'DELETE FROM ' . WARNINGS_TABLE . ' WHERE ' . $db->sql_in_set('warning_id', $warning_list); $db->sql_query($sql); - + foreach ($user_list as $user_id => $value) { $sql = 'UPDATE ' . USERS_TABLE . " SET user_warnings = user_warnings - $value @@ -3034,7 +3005,7 @@ function add_permission_language() // Now search in acp and mods folder for permissions_ files. foreach (array('acp/', 'mods/') as $path) { - $dh = @opendir($user->lang_path . $path); + $dh = @opendir($user->lang_path . $user->lang_name . '/' . $path); if ($dh) { |
