<?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();
}