Vinoteca: модуль, шаблон и компоненты интернет-магазина вина на 1С-Битрикс
This commit is contained in:
commit
bb7d8af290
469 files changed
+26426
No files matched your search
@@ -0,0 +1,38 @@
|
||||
<?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__ . "();";
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user