Joywork/cron/move_req_doers.php

54 lines
1.6 KiB
PHP
Raw Permalink Normal View History

2026-05-22 20:21:54 +02:00
<?php
set_time_limit(0);
require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
ini_set('display_errors', 1);
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Перенос совместной работы с заявками</title>
</head>
<body>
<?php
$sql = "SELECT * FROM requisitions WHERE doers IS NOT NULL AND doers <> '' AND doers <> '[]'";
$rez = mysql_query($sql);
while($req = mysql_fetch_assoc($rez)) {
$req_id = $req['id'];
echo "Работаем с заявкой " . $req_id;
if(!empty($req['doers'])){
$doers = json_decode(html_entity_decode($req['doers']), true);
var_dump($doers);
foreach($doers as $key => $agent){
$sql_s = "SELECT id FROM requisition_doers WHERE requisition_id = {$req_id} AND user_id = {$key}";
$q_s = mysql_query($sql_s);
if(mysql_num_rows($q_s) > 0) {
echo "Нашли, обновляем ";
$sql_u = "UPDATE requisition_doers SET confirm = {$agent} WHERE requisition_id = {$req_id} AND user_id = {$key}";
if (!mysql_query($sql_u)) {
echo mysql_error();
}
} else {
echo "Не нашли, вставляем";
$sql_i = "INSERT INTO requisition_doers (requisition_id, user_id, confirm) VALUES (" . $req_id . ", " . $key . ", " . $agent . ")";
if (!mysql_query($sql_i)) {
echo mysql_error();
}
}
}
}
}
?>
</body>
</html>