<?php
namespace Bitrix\Catalog;
use Bitrix\Main\Config\Option;
use Bitrix\Main\Application;
class CatalogViewedProductTable{
public static function clearAgent()
{
self::clear((int)Option::get('catalog', 'viewed_time'));
return '\Bitrix\Catalog\CatalogViewedProductTable::clearAgent();';
}
public static function clear($liveTime = 10)
{
$connection = Application::getConnection();
$helper = $connection->getSqlHelper();
$liveTime = (int)$liveTime;
$liveTo = $helper->addSecondsToDateTime($liveTime * 24 * 3600, "DATE_VISIT");
$now = $helper->getCurrentDateTimeFunction();
$deleteSql = "delete from b_catalog_viewed_product where ".$now." > ".$liveTo;
$connection->query($deleteSql);
}
}
?>