11 $connection = \Bitrix\Main\Application::getConnection();
12 $helper = $connection->getSqlHelper();
13 $queryResult = $connection->query(
'
14 select doc_files.ID, FILE_ID from b_catalog_store_document_file doc_files
15 left outer join b_catalog_store_docs docs
16 on docs.ID = doc_files.DOCUMENT_ID
20 $documentFiles = $queryResult->fetchAll();
22 if (empty($documentFiles))
27 $filesToRemove = array_column($documentFiles,
'FILE_ID');
28 $entriesToRemove = array_column($documentFiles,
'ID');
30 foreach ($filesToRemove as $fileId)
32 \CFile::Delete($fileId);
35 $entriesForQuery = implode(
',', $entriesToRemove);
37 $connection->queryExecute(
39 .
' where ' . $helper->quote(
'ID') .
' in (' . $entriesForQuery .
')'
42 $isCleanupOver = !(bool)$connection->query(
'
43 select doc_files.ID, FILE_ID from b_catalog_store_document_file doc_files
44 left outer join b_catalog_store_docs docs
45 on docs.ID = doc_files.DOCUMENT_ID
55 return '\Bitrix\Catalog\Update\DocumentFilesCleanup::execAgent();';