Files
crm.clientright.ru/crm_extensions/file_storage/update_n8n_script.php

67 lines
2.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* Обновление n8n скрипта для игнорирования очищенных файлов
*/
echo "=== ОБНОВЛЕНИЕ N8N СКРИПТА ===\n";
// Читаем текущий скрипт
$scriptPath = '/var/www/fastuser/data/www/crm.clientright.ru/crm_extensions/file_storage/n8n_s3_migration.php';
$scriptContent = file_get_contents($scriptPath);
// Добавляем фильтр для игнорирования очищенных файлов
$newFilter = "
// Фильтр для игнорирования очищенных файлов
\$ignorePatterns = [
'empty_filename' => 'filename IS NULL OR filename = \'\'',
'zero_size' => 'filesize = 0',
'file_15_series' => 'filename LIKE \'file_15_%\'',
'duplicates_7_zayavlenie' => 'filename = \'7 заявление потребителя\''
];
// Добавляем фильтр в WHERE условие
\$whereConditions = [
\"filelocationtype = 'I'\",
\"(s3_key IS NULL OR s3_key = '')\"
];
// Исключаем очищенные файлы
foreach (\$ignorePatterns as \$pattern => \$condition) {
\$whereConditions[] = \"NOT (\$condition)\";
}
\$whereClause = implode(' AND ', \$whereConditions);
";
// Находим место для вставки (после подключения к БД)
$insertPoint = strpos($scriptContent, '// Поиск локальных файлов без S3 метаданных');
if ($insertPoint !== false) {
$beforeInsert = substr($scriptContent, 0, $insertPoint);
$afterInsert = substr($scriptContent, $insertPoint);
$newScriptContent = $beforeInsert . $newFilter . "\n" . $afterInsert;
// Обновляем SQL запрос
$newScriptContent = str_replace(
"WHERE (s3_key IS NULL OR s3_key = '')
AND filelocationtype = 'I'",
"WHERE $whereClause",
$newScriptContent
);
// Сохраняем обновленный скрипт
file_put_contents($scriptPath, $newScriptContent);
echo "✅ N8n скрипт обновлен!\n";
echo "Добавлены фильтры для игнорирования:\n";
echo " - Файлы с пустыми именами\n";
echo " - Файлы размером 0 байт\n";
echo " - Старые тестовые файлы (file_15_*)\n";
echo " - Дубликаты '7 заявление потребителя'\n";
} else {
echo "Не удалось найти место для вставки фильтра\n";
}
echo "\n=== ОБНОВЛЕНИЕ ЗАВЕРШЕНО ===\n";
?>