mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-28 04:20:32 +02:00
okie, using array_merge. :D
fixed: admin_prune added: prune topics last viewed at... (only admin_prune ATM) moved: delete_attachments to functions_admin git-svn-id: file:///svn/phpbb/trunk@4482 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
@@ -407,9 +407,9 @@ function delete_posts($where_type, $where_ids, $auto_sync = TRUE)
|
||||
}
|
||||
unset($table_ary);
|
||||
|
||||
$db->sql_transaction('commit');
|
||||
delete_attachments($post_ids);
|
||||
|
||||
// delete_attachment($post_ids);
|
||||
$db->sql_transaction('commit');
|
||||
|
||||
if ($auto_sync)
|
||||
{
|
||||
@@ -438,6 +438,217 @@ function delete_posts($where_type, $where_ids, $auto_sync = TRUE)
|
||||
return count($post_ids);
|
||||
}
|
||||
|
||||
// Delete Attachments
|
||||
function delete_attachments($post_id_array = -1, $attach_id_array = -1, $page = 'post', $user_id = -1)
|
||||
{
|
||||
global $db;
|
||||
|
||||
if ($post_id_array == -1 && $attach_id_array == -1 && $page == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Generate Array, if it's not an array
|
||||
if ($post_id_array == -1 && $attach_id_array != -1)
|
||||
{
|
||||
$post_id_array = array();
|
||||
|
||||
if (!is_array($attach_id_array))
|
||||
{
|
||||
$attach_id_array = (strstr($attach_id_array, ',')) ? explode(',', str_replace(', ', ',', $attach_id_array)) : array((int) $attach_id_array);
|
||||
}
|
||||
|
||||
// Get the post_ids to fill the array
|
||||
$sql = 'SELECT ' . (($page == 'privmsgs') ? 'privmsgs_id' : 'post_id') . ' as id
|
||||
FROM ' . ATTACHMENTS_TABLE . '
|
||||
WHERE attach_id IN (' . implode(', ', $attach_id_array) . ')
|
||||
GROUP BY id';
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
if (!($row = $db->sql_fetchrow($result)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
$post_id_array[] = $row['id'];
|
||||
}
|
||||
while ($row = $db->sql_fetchrow($result));
|
||||
$db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
if (!is_array($post_id_array))
|
||||
{
|
||||
if (trim($post_id_array) == '')
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$post_id_array = (strstr($post_id_array, ',')) ? explode(',', str_replace(', ', ',', $attach_id_array)) : array((int) $post_id_array);
|
||||
}
|
||||
|
||||
if (!count($post_id_array))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// First of all, determine the post id and attach_id
|
||||
if ($attach_id_array == -1)
|
||||
{
|
||||
$attach_id_array = array();
|
||||
|
||||
// Get the attach_ids to fill the array
|
||||
$sql = 'SELECT attach_id
|
||||
FROM ' . ATTACHMENTS_TABLE . '
|
||||
WHERE ' . (($page == 'privmsgs') ? 'privmsgs_id' : 'post_id') . ' IN (' . implode(', ', $post_id_array) . ')
|
||||
GROUP BY attach_id';
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
if (!($row = $db->sql_fetchrow($result)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
$attach_id_array[] = $row['attach_id'];
|
||||
}
|
||||
while ($row = $db->sql_fetchrow($result));
|
||||
$db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
if (!is_array($attach_id_array))
|
||||
{
|
||||
$attach_id_array = (strstr($post_id_array, ',')) ? explode(',', str_replace(', ', ',', $attach_id_array)) : array((int) $attach_id_array);
|
||||
}
|
||||
|
||||
if (!count($attach_id_array))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . '
|
||||
WHERE attach_id IN (' . implode(', ', $attach_id_array) . ')
|
||||
AND post_id IN (' . implode(', ', $post_id_array) . ')';
|
||||
$db->sql_query($sql);
|
||||
|
||||
foreach ($attach_id_array as $attach_id)
|
||||
{
|
||||
$sql = 'SELECT attach_id
|
||||
FROM ' . ATTACHMENTS_TABLE . "
|
||||
WHERE attach_id = $attach_id";
|
||||
$select_result = $db->sql_query($sql);
|
||||
|
||||
if (!is_array($db->sql_fetchrow($select_result)))
|
||||
{
|
||||
$sql = 'SELECT attach_id, physical_filename, thumbnail
|
||||
FROM ' . ATTACHMENTS_DESC_TABLE . "
|
||||
WHERE attach_id = $attach_id";
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
// delete attachments
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
phpbb_unlink($row['physical_filename'], 'file', $config['use_ftp_upload']);
|
||||
if ($row['thumbnail'])
|
||||
{
|
||||
phpbb_unlink($row['physical_filename'], 'thumbnail', $config['use_ftp_upload']);
|
||||
}
|
||||
|
||||
$sql = 'DELETE FROM ' . ATTACHMENTS_DESC_TABLE . '
|
||||
WHERE attach_id = ' . $row['attach_id'];
|
||||
$db->sql_query($sql);
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
}
|
||||
$db->sql_freeresult($select_result);
|
||||
}
|
||||
|
||||
// Now Sync the Topic/PM
|
||||
if ($page == 'privmsgs')
|
||||
{
|
||||
foreach ($post_id_array as $privmsgs_id)
|
||||
{
|
||||
$sql = 'SELECT attach_id
|
||||
FROM ' . ATTACHMENTS_TABLE . '
|
||||
WHERE privmsgs_id = ' . $privmsgs_id;
|
||||
$select_result = $db->sql_query($sql);
|
||||
|
||||
if (!is_array($db->sql_fetchrow($select_result)))
|
||||
{
|
||||
$sql = 'UPDATE ' . PRIVMSGS_TABLE . '
|
||||
SET privmsgs_attachment = 0
|
||||
WHERE privmsgs_id = ' . $privmsgs_id;
|
||||
$db->sql_query($sql);
|
||||
}
|
||||
$db->sql_freeresult($select_result);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = 'SELECT topic_id
|
||||
FROM ' . POSTS_TABLE . '
|
||||
WHERE post_id IN (' . implode(', ', $post_id_array) . ')
|
||||
GROUP BY topic_id';
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
$topic_id = $row['topic_id'];
|
||||
|
||||
$sql = 'SELECT post_id
|
||||
FROM ' . POSTS_TABLE . "
|
||||
WHERE topic_id = $topic_id
|
||||
GROUP BY post_id";
|
||||
$result2 = $db->sql_query($sql);
|
||||
|
||||
$post_ids = array();
|
||||
|
||||
while ($post_row = $db->sql_fetchrow($result2))
|
||||
{
|
||||
$post_ids[] = $post_row['post_id'];
|
||||
}
|
||||
$db->sql_freeresult($result2);
|
||||
|
||||
if (count($post_ids))
|
||||
{
|
||||
$post_id_sql = implode(', ', $post_ids);
|
||||
|
||||
$sql = 'SELECT attach_id
|
||||
FROM ' . ATTACHMENTS_TABLE . "
|
||||
WHERE post_id IN ($post_id_sql)";
|
||||
$select_result = $db->sql_query_limit($sql, 1);
|
||||
$set_id = (!is_array($db->sql_fetchrow($select_result))) ? 0 : 1;
|
||||
$db->sql_freeresult($select_result);
|
||||
|
||||
$sql = 'UPDATE ' . TOPICS_TABLE . "
|
||||
SET topic_attachment = $set_id
|
||||
WHERE topic_id = $topic_id";
|
||||
$db->sql_query($sql);
|
||||
|
||||
foreach ($post_ids as $post_id)
|
||||
{
|
||||
$sql = 'SELECT attach_id
|
||||
FROM ' . ATTACHMENTS_TABLE . "
|
||||
WHERE post_id = $post_id";
|
||||
$select_result = $db->sql_query_limit($sql, 1);
|
||||
$set_id = (!is_array($db->sql_fetchrow($select_result))) ? 0 : 1;
|
||||
$db->sql_freeresult($select_result);
|
||||
|
||||
$sql = 'UPDATE ' . POSTS_TABLE . "
|
||||
SET post_attachment = $set_id
|
||||
WHERE post_id = $post_id";
|
||||
$db->sql_query($sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
// TODO - Return number of deleted attachments
|
||||
}
|
||||
|
||||
// All-encompasing sync function
|
||||
//
|
||||
// Usage:
|
||||
@@ -1120,7 +1331,7 @@ function verify_data($type, $fieldname, &$need_update, &$data)
|
||||
}
|
||||
}
|
||||
|
||||
function prune($forum_id, $prune_date, $prune_flags = 0, $auto_sync = true)
|
||||
function prune($forum_id, $prune_mode, $prune_date, $prune_flags = 0, $auto_sync = true)
|
||||
{
|
||||
global $db;
|
||||
|
||||
@@ -1136,10 +1347,18 @@ function prune($forum_id, $prune_date, $prune_flags = 0, $auto_sync = true)
|
||||
$sql_and .= ' AND topic_type <> ' . POST_STICKY;
|
||||
}
|
||||
|
||||
if ($prune_mode == 'posted')
|
||||
{
|
||||
$sql_and .= " AND topic_last_post_time < $prune_date";
|
||||
}
|
||||
if ($prune_mode == 'viewed')
|
||||
{
|
||||
$sql_and .= " AND topic_last_view_time < $prune_date";
|
||||
}
|
||||
|
||||
$sql = 'SELECT topic_id
|
||||
FROM ' . TOPICS_TABLE . "
|
||||
WHERE forum_id $sql_forum
|
||||
AND topic_last_post_time < $prune_date
|
||||
AND poll_start = 0
|
||||
$sql_and";
|
||||
$result = $db->sql_query($sql);
|
||||
@@ -1158,7 +1377,6 @@ function prune($forum_id, $prune_date, $prune_flags = 0, $auto_sync = true)
|
||||
WHERE forum_id $sql_forum
|
||||
AND poll_start > 0
|
||||
AND poll_last_vote < $prune_date
|
||||
AND topic_last_post_time < $prune_date
|
||||
$sql_and";
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
@@ -1175,7 +1393,7 @@ function prune($forum_id, $prune_date, $prune_flags = 0, $auto_sync = true)
|
||||
}
|
||||
|
||||
// Function auto_prune(), this function now relies on passed vars
|
||||
function auto_prune($forum_id, $prune_flags, $prune_days, $prune_freq)
|
||||
function auto_prune($forum_id, $prune_mode, $prune_flags, $prune_days, $prune_freq)
|
||||
{
|
||||
global $db;
|
||||
|
||||
@@ -1189,7 +1407,7 @@ function auto_prune($forum_id, $prune_flags, $prune_days, $prune_freq)
|
||||
$prune_date = time() - ($prune_days * 86400);
|
||||
$next_prune = time() + ($prune_freq * 86400);
|
||||
|
||||
prune($forum_id, $prune_date, $prune_flags, true);
|
||||
prune($forum_id, $prune_mode, $prune_date, $prune_flags, true);
|
||||
|
||||
$sql = 'UPDATE ' . FORUMS_TABLE . "
|
||||
SET prune_next = $next_prune
|
||||
|
Reference in New Issue
Block a user