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

143 lines
4.1 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
/**
* Analyze Remaining Internal Files - анализирует оставшиеся 316 Internal файлов
*/
ini_set('memory_limit', '512M');
set_time_limit(0);
date_default_timezone_set('Europe/Moscow');
$ROOT = '/var/www/fastuser/data/www/crm.clientright.ru/';
require_once $ROOT . 'config.inc.php';
// Database connection
$mysqli = new mysqli($dbconfig['db_server'], $dbconfig['db_username'], $dbconfig['db_password'], $dbconfig['db_name']);
if ($mysqli->connect_error) {
die("Connection failed: " . $mysqli->connect_error);
}
$mysqli->set_charset("utf8");
echo "=== Analysis of Remaining 316 Internal Files ===\n\n";
// Get all remaining internal files
$query = "SELECT notesid, filename, filesize, filetype, s3_key
FROM vtiger_notes
WHERE filelocationtype = 'I'
ORDER BY notesid DESC";
$result = $mysqli->query($query);
if (!$result) {
die("Query failed: " . $mysqli->error);
}
$categories = [
'empty_filename' => [],
'duplicate_applications' => [],
'file_15_series' => [],
'evidence_files' => [],
'recent_files' => [], // ID > 390000
'old_files' => [], // ID < 100000
'other' => []
];
$stats = [
'total' => 0,
'with_s3_key' => 0,
'without_s3_key' => 0,
'zero_size' => 0,
'has_size' => 0
];
while ($row = $result->fetch_assoc()) {
$stats['total']++;
$notesid = (int)$row['notesid'];
$filename = trim($row['filename']);
$filesize = (int)$row['filesize'];
$s3_key = $row['s3_key'];
// Stats
if (!empty($s3_key)) {
$stats['with_s3_key']++;
} else {
$stats['without_s3_key']++;
}
if ($filesize == 0) {
$stats['zero_size']++;
} else {
$stats['has_size']++;
}
// Categorize
if (empty($filename)) {
$categories['empty_filename'][] = $row;
} elseif (strpos($filename, '7 заявление потребителя') !== false) {
$categories['duplicate_applications'][] = $row;
} elseif (strpos($filename, 'file_15_') !== false) {
$categories['file_15_series'][] = $row;
} elseif (strpos($filename, оказательство_') !== false) {
$categories['evidence_files'][] = $row;
} elseif ($notesid > 390000) {
$categories['recent_files'][] = $row;
} elseif ($notesid < 100000) {
$categories['old_files'][] = $row;
} else {
$categories['other'][] = $row;
}
}
$mysqli->close();
// Print analysis
echo "STATISTICS:\n";
echo "Total Internal files: {$stats['total']}\n";
echo "With S3 key: {$stats['with_s3_key']}\n";
echo "Without S3 key: {$stats['without_s3_key']}\n";
echo "Zero size: {$stats['zero_size']}\n";
echo "Has size: {$stats['has_size']}\n\n";
echo "CATEGORIES:\n";
foreach ($categories as $category => $files) {
$count = count($files);
echo "$category: $count files\n";
if ($count > 0 && $count <= 10) {
// Show all if 10 or less
foreach ($files as $file) {
echo " - ID {$file['notesid']}: {$file['filename']} ({$file['filesize']} bytes)\n";
}
} elseif ($count > 10) {
// Show first 5 and last 5
echo " First 5:\n";
for ($i = 0; $i < 5; $i++) {
$file = $files[$i];
echo " - ID {$file['notesid']}: {$file['filename']} ({$file['filesize']} bytes)\n";
}
echo " Last 5:\n";
for ($i = $count - 5; $i < $count; $i++) {
$file = $files[$i];
echo " - ID {$file['notesid']}: {$file['filename']} ({$file['filesize']} bytes)\n";
}
}
echo "\n";
}
// Save detailed report
$report = [
'timestamp' => date('Y-m-d H:i:s'),
'statistics' => $stats,
'categories' => []
];
foreach ($categories as $category => $files) {
$report['categories'][$category] = [
'count' => count($files),
'files' => $files
];
}
file_put_contents($ROOT . 'crm_extensions/file_storage/remaining_internal_analysis.json',
json_encode($report, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
echo "Detailed report saved to: remaining_internal_analysis.json\n";