151 lines
4.1 KiB
PHP
151 lines
4.1 KiB
PHP
|
|
<?php
|
|||
|
|
require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
|
|||
|
|
|
|||
|
|
set_time_limit(0);
|
|||
|
|
|
|||
|
|
ini_set('display_errors', 1);
|
|||
|
|
error_reporting(E_ALL);
|
|||
|
|
|
|||
|
|
$dirPath = $_SERVER['DOCUMENT_ROOT']."/server/php/files/docs";
|
|||
|
|
|
|||
|
|
$countAll = 0;
|
|||
|
|
$countDel = 0;
|
|||
|
|
|
|||
|
|
$sum = 0;
|
|||
|
|
|
|||
|
|
for($num = 0; $num <= 10000; $num++) {
|
|||
|
|
|
|||
|
|
$tempDir = $dirPath . "/" . $num;
|
|||
|
|
|
|||
|
|
$userActive = true;
|
|||
|
|
|
|||
|
|
if (is_dir($tempDir)) {
|
|||
|
|
|
|||
|
|
$sqlUser = "SELECT user_id FROM `agency_folders` WHERE `id` = " . $num;
|
|||
|
|
|
|||
|
|
$rezUser = mysql_query($sqlUser);
|
|||
|
|
|
|||
|
|
$user = mysql_fetch_assoc($rezUser);
|
|||
|
|
|
|||
|
|
$userId = $user['user_id'];
|
|||
|
|
|
|||
|
|
if ($userId) {
|
|||
|
|
|
|||
|
|
$agencyId = User::getAgencyIdForUser($userId);
|
|||
|
|
|
|||
|
|
if ($agencyId) {
|
|||
|
|
$agency = new User();
|
|||
|
|
$agency->get($agencyId);
|
|||
|
|
|
|||
|
|
if ($agency) {
|
|||
|
|
$tarif = new \Tarif;
|
|||
|
|
$tarif->get($agency->id_tarif);
|
|||
|
|
$date_tarif = strtotime($agency->date_tarif);
|
|||
|
|
$date_end = $date_tarif + $tarif->period * 3600 * 24;
|
|||
|
|
$date_end_f = date("d.m.Y H:i", $date_end);
|
|||
|
|
$dney = ceil(($date_end - time()) / 24 / 3600);
|
|||
|
|
|
|||
|
|
echo " Удаляем файлы агентства " . $agencyId . " <br/>";
|
|||
|
|
echo $dney . " <br/>";;
|
|||
|
|
|
|||
|
|
if ($dney < -90) {
|
|||
|
|
$userActive = false;
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
echo "Не найдено агентство " . $agencyId . " <br/>";
|
|||
|
|
$userActive = false;
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
echo "Не найдено агентство для пользователя " . $userId . " <br/>";
|
|||
|
|
|
|||
|
|
$agency = new User();
|
|||
|
|
$agency->get($userId);
|
|||
|
|
|
|||
|
|
if ($agency && isset($agency->id_tarif)) {
|
|||
|
|
$tarif = new \Tarif;
|
|||
|
|
$tarif->get($agency->id_tarif);
|
|||
|
|
$date_tarif = strtotime($agency->date_tarif);
|
|||
|
|
$date_end = $date_tarif + $tarif->period * 3600 * 24;
|
|||
|
|
$date_end_f = date("d.m.Y H:i", $date_end);
|
|||
|
|
$dney = ceil(($date_end - time()) / 24 / 3600);
|
|||
|
|
|
|||
|
|
echo " Удаляем файлы агента " . $userId . " <br/>";
|
|||
|
|
echo $dney . " <br/>";;
|
|||
|
|
|
|||
|
|
if ($dney < -90) {
|
|||
|
|
$userActive = false;
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
echo "Не найден агент " . $userId . " <br/>";
|
|||
|
|
$userActive = false;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (!$userActive) {
|
|||
|
|
|
|||
|
|
$countDel++;
|
|||
|
|
echo " Удаляем файлы из папки " . $num . " <br/>";
|
|||
|
|
|
|||
|
|
checkFiles($tempDir, $sum);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
echo "<br/>".formatSizeUnits($sum);
|
|||
|
|
|
|||
|
|
function checkFiles($dirPath, &$sum) {
|
|||
|
|
if (!is_dir($dirPath)) {
|
|||
|
|
throw new InvalidArgumentException("$dirPath must be a directory");
|
|||
|
|
}
|
|||
|
|
if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
|
|||
|
|
$dirPath .= '/';
|
|||
|
|
}
|
|||
|
|
$files = glob($dirPath . '*', GLOB_MARK);
|
|||
|
|
|
|||
|
|
foreach ($files as $file) {
|
|||
|
|
if (is_dir($file)) {
|
|||
|
|
checkFiles($file, $sum);
|
|||
|
|
} else {
|
|||
|
|
|
|||
|
|
if (file_exists($file)) {
|
|||
|
|
|
|||
|
|
$size = filesize($file);
|
|||
|
|
$sum = $sum + $size;
|
|||
|
|
|
|||
|
|
echo $file . " " . date("d.m.Y H:i:s.", filemtime($file)) . " size: " . formatSizeUnits($size) . "<br/>";
|
|||
|
|
//unlink($file);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function formatSizeUnits($bytes)
|
|||
|
|
{
|
|||
|
|
if ($bytes >= 1073741824)
|
|||
|
|
{
|
|||
|
|
$bytes = number_format($bytes / 1073741824, 2) . ' GB';
|
|||
|
|
}
|
|||
|
|
elseif ($bytes >= 1048576)
|
|||
|
|
{
|
|||
|
|
$bytes = number_format($bytes / 1048576, 2) . ' MB';
|
|||
|
|
}
|
|||
|
|
elseif ($bytes >= 1024)
|
|||
|
|
{
|
|||
|
|
$bytes = number_format($bytes / 1024, 2) . ' kB';
|
|||
|
|
}
|
|||
|
|
elseif ($bytes > 1)
|
|||
|
|
{
|
|||
|
|
$bytes = $bytes . ' bytes';
|
|||
|
|
}
|
|||
|
|
elseif ($bytes == 1)
|
|||
|
|
{
|
|||
|
|
$bytes = $bytes . ' byte';
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
$bytes = '0 bytes';
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return $bytes;
|
|||
|
|
}
|