/
lefin17
/
maps
Обзор
Документация
Войти
/
lefin17
/
maps
Код
Запросы
0
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
private/app/pull.php
36 строк
1 KB
lefin17
create private/app/pull.php
09 апр 2024, 00:22
09 апр 2024, 00:22
856bfbd
Код
Авторство
О чём код?
<?php include(__DIR__."/../connect_dbi.php"); //part one take all info from json and put it into base or update, do not delete $tables = array("issues", "custom_fields", "attachments", "issue_relations"); $ds = __DIR__."/../my2maps/"; define("_NULLS_", array('due_date', 'category_id', 'parent_id', 'closed_on')); //may be nulls in issues table foreach($tables as $table) { $tmp = json_decode(file_get_contents($ds.$table.".json")); if (empty($tmp)) continue; // print_r($tmp); // die(); foreach($tmp as $line => $arr) { $keys_insert = ''; $values_insert = ''; $update = ''; print_r($arr); print "+"; foreach($arr as $key => $value) { $keys_insert.= ((!empty($keys_insert)) ? ", " : "" )."`".$key."`"; if (empty($value) && (in_array($key, _NULLS_ ))) { $values_insert .= ", NULL"; $update .= ",`$key` = NULL"; continue; } //due_date fixer $values_insert.= ((!empty($values_insert)) ? ", " : "" )."'".mysqli_escape_string($mysqli, $value)."'"; if ($key != 'id') $update .= (!empty($update) ? ", " : "")."`$key` = '".mysqli_escape_string($mysqli, $value)."'"; } //end second foreach $q = "INSERT INTO md_".$table." ($keys_insert) VALUES($values_insert) ON DUPLICATE KEY UPDATE $update"; mysqli_query($mysqli, $q); print $q."\n"; } //end foreach for all lines } //end tables array