- Модуль: disk
- Путь к файлу: ~/bitrix/modules/disk/lib/internals/objectpath.php
- Класс: BitrixDiskInternalsObjectPathTable
- Вызов: ObjectPathTable::recalculate
static function recalculate()
{
set_time_limit(0);
$maxInnerJoinDepth = 32;
$currentDepth = 0;
$emptyInsert = false;
$connection = Application::getConnection();
$connection->queryExecute("TRUNCATE TABLE b_disk_object_path");
$connection->queryExecute("
INSERT INTO b_disk_object_path (PARENT_ID, OBJECT_ID, DEPTH_LEVEL)
SELECT ID, ID, 0 FROM b_disk_object
");
while($currentDepth < $maxInnerJoinDepth && !$emptyInsert)
{
$query = "
INSERT INTO b_disk_object_path (OBJECT_ID, PARENT_ID, DEPTH_LEVEL)
SELECT b.ID, t.ID, " . ($currentDepth+1) . " FROM b_disk_object t
";
$finalQuery = $query;
for($i = 0;$i < $currentDepth;$i++)
{
$finalQuery .= " INNER JOIN b_disk_object t" . ($i+1) . " ON t" . ($i?: '') . ".ID=t" . ($i+1) . ".PARENT_ID ";
}
$lastJoin = " INNER JOIN b_disk_object b ON t" . ($currentDepth?:'' ) . ".ID=b.PARENT_ID ";
$finalQuery = $finalQuery .$lastJoin;
$connection->queryExecute($finalQuery);
$emptyInsert = $connection->getAffectedRowsCount() <= 0;
$currentDepth++;
}
}