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