• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 1.5 Query To Soft Delete All Posts Containing Term

Brent W

Well-known member
#1
We have someone who has been sending us DMCA notices for content that was created before we acquired the site. I simply want to soft delete all posts that contain the domain name of this persons site in it. Is that possible with a query?

I did a select query with LIKE and came up with over 500 posts that can be deleted.
 

Temery

Active member
#2
If you do a search and then click mod tools (top right), and click thread, you'll get the inline selection box for each thread with that search criteria. You'll have to manually check each thread, then delete.

Alternately, depending on what you can to accomplish, you can copy the text you want removed from those posts, and use the censoring feature to remove the text from all posts with one action.

I'm not sure if this helps, or if will even work with 2.0, but it works for me on my sites.
 

Chris D

XenForo developer
Staff member
#4
1) Set the "search results per page" option to 100.

2) Enable "Post" moderation under "Moderator Tools"

3) Click "Selected: X" from the top of the list.

4) Click "Select All"

5) Scan down the list to ensure there's no false positives and deselect any.

6) Click next page. Repeat steps 3-5.

7) Once you've selected all of the posts, open the inline mod overlay and select Delete.

It's a bit boring and repetitive but, really, this is going to be less painful in the long run as you won't have issues with orphaned data, you won't need to rebuild your search index, you won't need to rebuild your thread and post information. Even so, ~5 pages worth of results shouldn't take more than a few minutes.

5000? 50000? Might need something more :) But, even then, I'd have suggested having a script written to delete them properly with the XF framework rather than just deleting them in a basic query.
 

Xon

Well-known member
#5
Change "$term" to whatever you need (The % is a wildcard match). Warning; this may take a real long time.

PHP:
<?php

$term = '%example.com%';
$reason= 'DMCA Takedown';
$userId = 1;

$startTime = microtime(true);
$fileDir = dirname(__FILE__);

require($fileDir . '/library/XenForo/Autoloader.php');
XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');

XenForo_Application::initialize($fileDir . '/library', $fileDir);
XenForo_Application::set('page_start_time', $startTime);

$dependencies = new XenForo_Dependencies_Public();
$dependencies->preLoadData();

$db = XenForo_Application::getDb();

XenForo_Visitor::setup($userId);

$s = microtime(true);
$postIds = $db->fetchCol("select post_id from xf_post where message like ? and message_state = 'visible'", $term);
echo "Found ".count($postIds)." posts in ". (microtime(true) - $s)." seconds";

foreach($postIds as $postId)
{
  $dw = XenForo_DataWriter::create('XenForo_DataWriter_DiscussionMessage_Post');
  $sq->setExistingData($postId);
  $dw->setExtraData(XenForo_DataWriter_DiscussionMessage::DATA_DELETE_REASON, $reason);
  $dw->set('message_state', 'deleted');
  $dw->save();
}
 
Last edited: