- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/classes/general/file.php
- Класс: CFile
- Вызов: CFile::processDuplicates
static function processDuplicates($ID)
{
$result = self::DELETE_ALL;
//Part 1: the file is a duplicate of another file, including referenses to itself
$original = InternalFileDuplicateTable::query()
->addSelect("*")
->where("DUPLICATE_ID", $ID)
->fetch();
//Part 2: find duplicates of the file
$duplicates = InternalFileDuplicateTable::query()
->where("ORIGINAL_ID", $ID)
->setLimit(1)
->fetch();
//Part 1
if($original)
{
if($original["COUNTER"] > 1)
{
//decrease references counter
InternalFileDuplicateTable::update(
[
"DUPLICATE_ID" => $ID,
"ORIGINAL_ID" => $original["ORIGINAL_ID"],
],
[
"COUNTER" => new MainDBSqlExpression("?# - 1", "COUNTER"),
]
);
//there are references still
$result = self::DELETE_NONE;
}
else
{
//delete referense
InternalFileDuplicateTable::delete([
"DUPLICATE_ID" => $ID,
"ORIGINAL_ID" => $original["ORIGINAL_ID"],
]);
//delete only if the file is a duplicate of *another* file
if($original["DUPLICATE_ID"] <> $original["ORIGINAL_ID"])
{
if($original["ORIGINAL_DELETED"] === "Y")
{
//try and delete the original
static::Delete($original["ORIGINAL_ID"]);
}
//there is the original somewhere, we shouldn't delete its file
$result = self::DELETE_DB;
}
}
}
//Part 2
if($duplicates)
{
//mark the original as deleted for future deletion
InternalFileDuplicateTable::markDeleted($ID);
//duplicates found, should keep the original
$result = self::DELETE_NONE;
}
return $result;
}