/
lefin17
/
maps
Обзор
Документация
Войти
/
lefin17
/
maps
Код
Запросы
0
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
exchange/pull_and_push.php
130 строк
6 KB
lefin17
update exchange/pull_and_push.php
09 апр 2024, 00:40
09 апр 2024, 00:40
cac0ac9
Код
Авторство
О чём код?
<?php // transfer issues from marked projects from redmine based on postgreSQL include(__DIR__."/connectdb.php"); // include(__DIR__."/connect_maps.php"); //possible not worked -> sync to sql folder - put & upload to internal folder & execute // use external API with token to get needed info and send queries to maps.bmstu.ru // generate json with position values and keys put to transfer folder (as RabbitMQ message system) // take id & update_time from maps api define("_ALLOW_FF_", //allow file formats, not used yet array("image/svg+xml") //svg files with pathes ); define("_SKIP_OBJ_", array("REL" => array("delay"), "ISS" => array("lft", "assigned_to_id", "priority_id", "fixed_version_id", "author_id", "lock_version", "done_ratio", "estimated_hours", "rgt"))); define("_RF_", __DIR__."/../redmine/files/"); //define redmine files define("_DF_", __DIR__."/uploads/"); //upload file directory define("_DT_", __DIR__."/transfer/my2maps/"); //json data transfer directory // define("_PREFIX_", "md_"); //mysql table prefix when update from source - maps data function getRelations($conn, $arr) { //getLinks print "start getRelaions \n"; if (empty($arr)) return false; $links = array(); foreach($arr as $i) { //take relations from task $q = "SELECT * FROM issue_relations WHERE relation_type = 'relates' and issue_from_id = $i"; print $q."\n"; $r = pg_query($conn, $q); while($row = pg_fetch_object($r)) { $link = null; foreach($row as $key => $value) if (!in_array($key, _SKIP_OBJ_["REL"])) $link->$key = $value; $links[] = $link; print_r($row); } //end while $data = json_encode($links, JSON_UNESCAPED_UNICODE); file_put_contents(_DT_."issue_relations.json", $data); } //end foreach } //end funciton function getAttachment($conn, $arr) { //get attachment from issue to make issues flow if (empty($arr)) return false; $att = array(); print "\n\n*** START ATT WORKER *** \n\n"; foreach($arr as $i) { //take attachment from new issues $q = "SELECT * FROM attachments WHERE container_type = 'Issue' and container_id = $i"; $r = pg_query($conn, $q); while($row = pg_fetch_object($r)) { print_r($row); if (!in_array($row->content_type, _ALLOW_FF_)) { print "not allowed"; continue; } $fn = _RF_.$row->disk_directory."/".$row->disk_filename; if (!is_dir(_DF_.$row->disk_directory)) mkdir(_DF_.$row->disk_directory, 0777, true); $to = _DF_.$row->disk_directory."/".$row->disk_filename; if (!file_exists($to) || filemtime($to) < filemtime($fn)) if (copy($fn, $to)) { // $att[] = $row; print "+"; } else print "-"; $att[] = $row; } //end while $data = json_encode($att, JSON_UNESCAPED_UNICODE); file_put_contents(_DT_."attachments.json", $data); } //end of foreach } //end function get Attachment function getCF ($conn, $arr) { //get Custom Fields name + value if (empty($arr)) return false; foreach($arr as $i) { $q = "SELECT cv.id, cv.custom_field_id, cv.customized_type, cv.customized_id, cf.name, cv.value FROM custom_values as cv INNER JOIN custom_fields as cf on cf.id = cv.custom_field_id and cv.customized_id = $i"; $r = pg_query($q); while($row = pg_fetch_object($r)) { $cf[] = $row; print_r($row); } //end while $data = json_encode($cf, JSON_UNESCAPED_UNICODE); file_put_contents(_DT_."custom_fields.json", $data); } //end foreach } //end function function getIssues($conn, $arr) { if (empty($arr)) return false; foreach($arr as $p) { $q = "SELECT * FROM issues as i WHERE i.project_id = $p"; $r = pg_query($q); $issues = array(); //all issues without filter by update time $i = array(); while($row = pg_fetch_object($r)) { $issue = null; foreach($row as $key => $value) if (!in_array($key, _SKIP_OBJ_["ISS"])) $issue["$key"] = $value; $issues[] = $issue; $i[] = $row->id; print_r($row); getCF($conn, $i); //turn me on getAttachment($conn, $i); //take all attachment to all uploaded issues getRelations($conn, $i); //take all links (relations) to all issues to update } // end while query $data = json_encode($issues, JSON_UNESCAPED_UNICODE); file_put_contents(_DT_."/issues.json", $data); } // end foreache project_id } //end function $q = "SELECT * FROM custom_fields WHERE type like 'Proj%'"; $q = "SELECT * FROM custom_values"; //SELECT needed projects $q = "SELECT p.id FROM projects as p INNER JOIN custom_values as cv on (p.id = cv.customized_id and cv.value = '1' and cv.customized_type = 'Project')"; $r = pg_query($conn, $q); $prj = array(); //print values of return from query while($row = pg_fetch_object($r)) { print_r($row); $prj[] = $row->id; print "\n"; } if (!empty($prj)) getIssues($conn, $prj); //getIssuesFROM Projects