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
define('THIS_SCRIPT', 'ft_story_cleanup');
require_once('./global.php');

$secret = 'CHANGE_ME_STRONG_KEY';

$key = isset($_GET['key']) ? (string)$_GET['key'] : '';
if ($key !== $secret)
{
	header('HTTP/1.1 403 Forbidden');
	echo "forbidden";
	exit;
}

$now = TIMENOW;
$limit = 300; // bir çalışmada kaç story temizlensin

// expire olanları al (state=1 ama expire geçmiş)
$res = $db->query_read("
	SELECT storyid
	FROM ft_story
	WHERE expiretime <= $now
	LIMIT $limit
");

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

while ($s = $db->fetch_array($res))
{
	$storyid = intval($s['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++;
}

echo "ok\n";
echo "deleted_stories=$deletedStories\n";
echo "deleted_files=$deletedFiles\n";

 

Revise this Paste

Your Name: Code Language: