redmine

autocloser

<?php
require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/AbstractApi.php";
require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/SimpleXMLElement.php";
require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/IssueStatus.php";
require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/User.php";
require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/Issue.php";
require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/Attachment.php";
require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Client.php";
require_once "config.php";
$redmine = new Redmine\Client('https://tasks.mephi.ru', REDMINE_API);
/* NRNU Auto-report */
$answer = $redmine->api('issue')->all(array(
'status_id' => STATUSID_SOLVED,
'sort' => 'updated_on',
'limit' => 10000,
));
if (!isset($answer['issues']))
exit(0);
$curts = time();
$toooldts = $curts - ISSUERESPONSE_TIMEOUT;
foreach ($answer['issues'] as &$issue) {
$updated_on = strtotime($issue['updated_on']);
if ($updated_on < $toooldts) {
//print_r($issue);
$changes['status_id'] = STATUSID_CLOSED;
$changes['notes'] = "Задача переведена из статуса «Решена» в статус «Закрыта» в связи с отсутствием активности более двух недель.";
$redmine->api('issue')->update($issue['id'], $changes);
//print $issue['id']." ".print_r($changes, 1);
}
continue;
}
?>
... ...
... ... @@ -8,11 +8,14 @@ require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/Issue.php";
require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/Attachment.php";
require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Client.php";
require_once "lib/3rdparty/Inflect/Inflect.php";
require_once "config.php";
define('IMG_SCALE', 0.3);
$redmine = new Redmine\Client('https://redmine.ut.mephi.ru', REDMINE_API);
$inflect = new Inflect();
$answer = $redmine->api('issue')->all(array(
'project_id' => '15971', // project "hpc-request"
... ... @@ -38,7 +41,7 @@ function tempdir() {
}
*/
function sendConfirmationRequest($issueId, $recipient, $authorName, $pdf) {
function sendConfirmationRequest($issueId, $recipient, $toName, $authorName, $pdf) {
//// CONVERTING PDF -> PNG ////
... ... @@ -59,7 +62,7 @@ function sendConfirmationRequest($issueId, $recipient, $authorName, $pdf) {
//// HEADERS ////
$headers = str_replace("\n", "\r\n",
'From: tasks@mephi.ru
'From: =?utf-8?B?'.base64_encode('Система «Задачи»').'?= <tasks@mephi.ru>
Mime-Version: 1.0
Content-Type: multipart/related; boundary="'.$boundary.'"; type="text/html"
');
... ... @@ -74,8 +77,13 @@ Content-Type: text/html; charset="UTF-8"
<br>
<br>
<div style="width:740px">
<div style="font-size:80px;display:inline-block;text-align:center"><a style="text-decoration:none;color:green" href="http://ut.mephi.ru/decide-note.php?issueId='.$issueId.'&action=agree&signature='.$signature.'">&#10003;<br><span style="font-size:10px">(подтвердить)</span></a></div>
<div style="font-size:80px;display:inline-block;text-align:center"><a style="text-decoration:none;color:red" href="http://ut.mephi.ru/decide-note.php?issueId='.$issueId.'&action=decline&signature='.$signature.'">✗<br><span style="font-size:10px">(отклонить)</span></a></div>
<img style="border:1px dotted #aaa;margin:0;padding:0" src="cid:note-'.$issueId.'@tasks.mephi.ru" alt="Проект служебной записки"><br>
<a href="http://ut.mephi.ru/decide-note.php?issueId='.$issueId.'&action=decline&signature='.$signature.'" style="text-decoration:none;font-size:100px;display:inline-block;text-align:center">✗<br><span style="font-size:10px">(отклонить)</span></a><a href="http://ut.mephi.ru/decide-note.php?issueId='.$issueId.'&action=agree&signature='.$signature.'" style="text-decoration:none;font-size:100px;display:inline-block;text-align:center">&#10003;<br><span style="font-size:10px">(подтвердить)</span></a><br><br>
<div style="font-size:80px;display:inline-block;text-align:center"><a style="text-decoration:none;color:green" href="http://ut.mephi.ru/decide-note.php?issueId='.$issueId.'&action=agree&signature='.$signature.'">&#10003;<br><span style="font-size:10px">(подтвердить)</span></a></div>
<div style="font-size:80px;display:inline-block;text-align:center"><a style="text-decoration:none;color:red" href="http://ut.mephi.ru/decide-note.php?issueId='.$issueId.'&action=decline&signature='.$signature.'">✗<br><span style="font-size:10px">(отклонить)</span></a></div>
</div>
<hr style="width:100%;padding-top:10px;border:none;border-bottom:1px solid #aaa">
Служба технической поддержки: <a href="tasks@mephi.ru">tasks@mephi.ru</a>
... ... @@ -93,7 +101,7 @@ Content-Transfer-Encoding: BASE64
//// SENDING ////
//print_r(array($recipient, "Проект служебной записки №".$issueId, $body, $headers));die();
mail($recipient, "Проект служебной записки №".$issueId, $body, $headers);
mail($recipient, "Проект служебной записки ".$toName." №".$issueId.' (на согласование)', $body, $headers);
}
/*$tmp = tempdir();
... ... @@ -125,6 +133,31 @@ foreach ($answer['issues'] as &$issue) {
if ($have_memo != 1)
continue;
$recipientId = NULL;
foreach ( $issue['custom_fields'] as $cf) {
if ($cf['id'] == 95) {
$recipientId = $cf['value'];
break;
}
}
if (is_null($recipientId) || ($recipientId == $assignedTo['id'])) {
continue;
}
$recipient = $redmine->api('user')->show($recipientId);
if (empty($recipient['user'])) {
mail('admin@ut.mephi.ru', 'Got error on cron-unconfirmednotes.php (1) #'.$issue['id'], print_r($_GET, 1).print_r($recipient ,1));
continue;
}
$recipient = $recipient['user'];
if (empty($recipient['mail'])) {
mail('admin@ut.mephi.ru', 'Got error on cron-unconfirmednotes.php #'.$issue['id'], print_r($_GET, 1));
continue;
}
/*
$fname = 'note-'.$issue['id'].'.pdf';
... ... @@ -150,10 +183,11 @@ foreach ($answer['issues'] as &$issue) {
curl_close($c);
//sendConfirmationRequest($issue['id'], $assignedTo['mail'], $note);
//sendConfirmationRequest($issue['id'], 'dyokunev@ut.mephi.ru', '<a href="http://new.voip.mephi.ru/subscribers/?q='.explode('@', $author['mail'])[0].'" target="_blank">'.$author['firstname'].' '.$author['lastname'].'</a>', $note);
//sendConfirmationRequest($issue['id'], 'dyokunev@mephi.ru', '<a href="http://new.voip.mephi.ru/subscribers/?q='.explode('@', $author['mail'])[0].'" target="_blank">'.$author['firstname'].' '.$author['lastname'].'</a>', $note);
sendConfirmationRequest($issue['id'], $assignedTo['mail'], '<a href="http://new.voip.mephi.ru/subscribers/?q='.explode('@', $author['mail'])[0].'" target="_blank">'.$author['firstname'].' '.$author['lastname'].'</a>', $note);
$toNameWords = explode(' ', $inflect->getInflectName($recipient['lastname'].' '.$recipient['firstname'], 1));
$toName = $toNameWords[0].' '.mb_substr($toNameWords[1], 0, 1).'. '.mb_substr($toNameWords[2], 0, 1).'.';
//$assignedTo['mail'] = 'dyokunev@mephi.ru';
sendConfirmationRequest($issue['id'], $assignedTo['mail'], $toName, '<a href="http://new.voip.mephi.ru/subscribers/?q='.explode('@', $author['mail'])[0].'" target="_blank">'.$author['firstname'].' '.$author['lastname'].'</a>', $note);
$redmine->api('issue')->update($issue['id'], array('status_id' => STATUSID_QUEUED));
}
... ...