Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so dont bother with any of their useless mail servers here and just use oauth login instead. Thank the nice Russians for causing that. :)

Paste

Pasted as PHP by registered user atmaca ( 3 months ago )
<?php
/**
 * FT Story Cleanup (vBulletin Scheduled Task)
 */

if (!defined('VB_AREA'))
{
	exit;
}

global $vbulletin;

if (!is_object($vbulletin) || !is_object($vbulletin->db))
{
	// cron ortamı hazır değilse sessiz çık
	return;
}

$db  = $vbulletin->db;
$now = TIMENOW;

$limit = 200; // tek çalışmada kaç story temizlensin

$base = @realpath(DIR . '/ft_story_uploads');
$deletedStories = 0;
$deletedFiles   = 0;

// expire olanları al
$res = $db->query_read("
	SELECT storyid
	FROM ft_story
	WHERE expiretime <= $now
	LIMIT $limit
");

while ($row = $db->fetch_array($res))
{
	$storyid = intval($row['storyid']);
	if ($storyid <= 0) { continue; }

	$mres = $db->query_read("
		SELECT filepath, thumbpath
		FROM ft_story_media
		WHERE storyid = $storyid
	");

	$paths = array();
	while ($m = $db->fetch_array($mres))
	{
		if (!empty($m['filepath']))  { $paths[] = $m['filepath']; }
		if (!empty($m['thumbpath'])) { $paths[] = $m['thumbpath']; }
	}

	foreach ($paths as $rel)
	{
		$rel = ltrim((string)$rel, '/');

		// sadece bizim klasör
		if (strpos($rel, 'ft_story_uploads/') !== 0)
		{
			continue;
		}

		$abs  = DIR . '/' . $rel;
		$real = @realpath($abs);

		if ($real && $base && strpos($real, $base) === 0 && file_exists($real))
		{
			if (@unlink($real))
			{
				$deletedFiles++;
			}
		}
	}

	// DB temizliği
	$db->query_write("DELETE FROM ft_story_view  WHERE storyid = $storyid");
	$db->query_write("DELETE FROM ft_story_media WHERE storyid = $storyid");
	$db->query_write("DELETE FROM ft_story       WHERE storyid = $storyid LIMIT 1");

	$deletedStories++;
}

if (function_exists('log_cron_action'))
{
	log_cron_action("FT Story cleanup: deleted_stories=$deletedStories deleted_files=$deletedFiles", 0);
}

 

Revise this Paste

Your Name: Code Language: