Joywork/cron/archiveNonPaidObjects.php
2026-05-22 21:21:54 +03:00

93 lines
3.4 KiB
PHP

<?php
set_time_limit(0);
require_once($_SERVER['DOCUMENT_ROOT'] . "/config.php");
ini_set('display_errors', 1);
error_reporting(E_ALL);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Архивация объектов пользователей, кто не оплатил</title>
</head>
<body>
<?php
//запрос за неактивными агентами и агентствами
$sqlUpdate = "update objects set archive = 1, is_main = 0, date_add = NOW() where archive = 0 and id_add_user in (SELECT id from users where (now() >= DATE_ADD(date_tarif, INTERVAL (select t.period+4 FROM tariffs t where t.id=id_tarif LIMIT 1) DAY)) or (id_manager in (SELECT id from users where (now() >= DATE_ADD(date_tarif, INTERVAL (select t.period+4 FROM tariffs t where t.id=id_tarif LIMIT 1) DAY)))) or (id_manager in (select id from users where id_manager in (SELECT id from users where (now() >= DATE_ADD(date_tarif, INTERVAL (select t.period+4 FROM tariffs t where t.id=id_tarif LIMIT 1) DAY))))))";
mysql_query($sqlUpdate, $mdb);
$sum = 0;
$dirPath = $_SERVER['DOCUMENT_ROOT'] . "/av_feeds";
deleteDir($dirPath, $sum);
$dirPath = $_SERVER['DOCUMENT_ROOT'] . "/av_feeds_free";
deleteDir($dirPath, $sum);
$dirPath = $_SERVER['DOCUMENT_ROOT'] . "/bn_ya_feeds";
deleteDir($dirPath, $sum);
$dirPath = $_SERVER['DOCUMENT_ROOT'] . "/cian_feed_jcat";
deleteDir($dirPath, $sum);
$dirPath = $_SERVER['DOCUMENT_ROOT'] . "/cian_feed_v2";
deleteDir($dirPath, $sum);
$dirPath = $_SERVER['DOCUMENT_ROOT'] . "/dom_feeds";
deleteDir($dirPath, $sum);
$dirPath = $_SERVER['DOCUMENT_ROOT'] . "/feeds";
deleteDir($dirPath, $sum);
function deleteDir($dirPath, &$sum) {
$now = time();
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 (stripos(basename($file), "pdf_temp") === false &&
stripos(basename($file), "agency") === false &&
stripos(basename($file), "get-photo.jpg") === false &&
stripos(basename($file), "builder") === false &&
stripos(basename($file), "bank") === false &&
stripos(basename($file), "no-photo.jpg") === false &&
stripos(basename($file), "vk_temp") === false) {
if (is_dir($file)) {
deleteDir($file, $sum);
} else {
if ($now - filemtime($file) >= 60 * 60 * 24 * 4) { //4 дня давности
$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;
}