Files

39 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Jinove\Vinoteca;
use Bitrix\Iblock\ElementTable;
use Bitrix\Iblock\IblockTable;
use Bitrix\Main\Loader;
use Bitrix\Main\Type\DateTime;
final class Retention
{
private const QUESTIONS_CODE = "sommelier_questions";
private const MONTHS = 12;
private const BATCH = 200;
public static function purge(): string
{
if (Loader::includeModule("iblock")) {
$iblock = IblockTable::getRow(["select" => ["ID"], "filter" => ["=CODE" => self::QUESTIONS_CODE]]);
if ($iblock !== null) {
$before = new DateTime();
$before->add("-" . self::MONTHS . " months");
$rows = ElementTable::getList([
"select" => ["ID"],
"filter" => ["=IBLOCK_ID" => (int)$iblock["ID"], "<DATE_CREATE" => $before],
"limit" => self::BATCH,
]);
while ($row = $rows->fetch()) {
\CIBlockElement::Delete((int)$row["ID"]);
}
}
}
return __METHOD__ . "();";
}
}