Batch remove tags

Biarritz64

Active member
I found this script by @Xon to remove tags
when run it will delete all tags with less than 10 uses
can someone make it compatible with xf2

Code:
<?php
exit();

$startTime = microtime(true);

@set_time_limit(0);
ignore_user_abort(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::get('db');

$tags = $db->fetchAll("
select *
from xf_tag
where xf_tag.use_count < 10;
");

print count($tags) . " about to delete in 2 seconds\n";
sleep(2);
print "Now deleting\n";

foreach($tags as $tag)
{
    $dw = XenForo_DataWriter::create('XenForo_DataWriter_Tag');
    $dw->setExistingData($tag);
    $dw->delete();
}

$threads = $db->fetchAll("
    SELECT thread_id
    FROM xf_thread
    WHERE xf_thread.tags <> 'a:0:{}' and xf_thread.tags <> ''
");

/** @var XenForo_Model_Tag $tagModel */
$tagModel = XenForo_Model::create('XenForo_Model_Tag');

foreach ($threads AS $thread)
{
XenForo_Db::beginTransaction($db);
    $tagModel->rebuildTagCache('thread', $thread['thread_id']);
XenForo_Db::commit($db);
}
 

DWilly

Member
Surprised there's no follow up to this. A little tag clean-up when importing from other forum software should be included in the importer. Or, at the very least, post a quick and dirty little script for Xenforo 2.x to accomplish it.

Like others have said, I don't want to spend $ for something I'm only using once after importing.
 
Top