redmine

Updated scripts

... ... @@ -10,7 +10,7 @@ require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Client.php";
require_once "config.php";
$redmine = new Redmine\Client('https://redmine.ut.mephi.ru', REDMINE_LOGIN, REDMINE_PASSWORD);
$redmine = new Redmine\Client('https://redmine.ut.mephi.ru', REDMINE_API);
/* NRNU Auto-report */
... ... @@ -31,7 +31,7 @@ foreach ($answer['issues'] as &$issue) {
$have_memo = 0;
if (isset($issue_full['attachments']))
foreach ($issue_full['attachments'] as &$attachment)
if ($attachment['description'] == 'Memorandum') {
if ($attachment['description'] == 'Memorandum' || $attachment['description'] == 'Служебная записка') {
$have_memo = 1;
break;
}
... ...
... ... @@ -10,7 +10,27 @@ require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Client.php";
require_once "config.php";
$redmine = new Redmine\Client('https://redmine.ut.mephi.ru', REDMINE_LOGIN, REDMINE_PASSWORD);
function tempdir_cleanup($dir) {
system('rm -rf "'.$dir.'"');
}
function tempdir($dir=FALSE, $prefix='php') {
$tempfile = tempnam(sys_get_temp_dir(),'');
if (file_exists($tempfile))
unlink($tempfile);
mkdir($tempfile);
if (is_dir($tempfile)) {
// register_shutdown_function("tempdir_cleanup", $tempfile);
return $tempfile;
}
return FALSE;
}
$redmine = new Redmine\Client('https://redmine.ut.mephi.ru', REDMINE_API);
/* NRNU Auto-report */
... ... @@ -25,6 +45,7 @@ if (!isset($answer['issues']))
$time = time();
foreach ($answer['issues'] as &$issue) {
if ($issue['status']['id'] == STATUSID_SOLVED) {
$redmine->api('issue')->addWatcher ($issue['id'], USERID_NVMALYH);
$redmine->api('issue')->addWatcher ($issue['id'], USERID_AATITOV);
... ... @@ -32,19 +53,65 @@ foreach ($answer['issues'] as &$issue) {
continue;
}
$timediff = $time-strtotime($issue['created_on']);
$timediff_c = $time-strtotime($issue['created_on']);
$timediff_u = $time-strtotime($issue['updated_on']);
$changes = array();
if ($timediff < 3600)
if ($timediff_c < 3600) {
$assigned_to_new = USERID_NVMALYH;
elseif ($timediff < 7200)
if ($issue['assigned_to']['id'] != $assigned_to_new) {
$issues_full = $redmine->api('issue')->show($issue['id'], array('include' => 'attachments'));
$issue_full = reset($issues_full);
$attachment_count = 0;
$dir = tempdir();
chdir($dir);
foreach ($issue_full['attachments'] as &$attachment_info) {
if ($attachment_info['filename'] == 'allfiles.zip') {
$attachment_count = 0;
break;
}
system('wget --no-check-certificate "'.str_replace('"', "'", $attachment_info['content_url']).'?key='.REDMINE_API.'" -O "'.$attachment_info['filename'].'"');
$attachment_count++;
}
if ($attachment_count) {
@unlink('allfiles.zip');
system('zip allfiles.zip *');
$archive_content = file_get_contents('allfiles.zip');
$archive_upload = json_decode($redmine->api('attachment')->upload($archive_content));
print_r($archive_upload);
$attachment_info = array(
'token' => $archive_upload->upload->token,
'filename' => 'allfiles.zip',
'description' => 'An archive with all files',
'content_type' => 'application/zip',
);
$redmine->api('issue')->attach($issue['id'], $attachment_info);
}
tempdir_cleanup($dir);
}
}
elseif ($timediff_c < 7200)
$assigned_to_new = USERID_AATITOV;
else
elseif ($timediff_c < 10800) {
$assigned_to_new = USERID_NNROMANOV;
$redmine->api('issue')->addWatcher ($issue['id'], USERID_SVSOLOVYEV);
} else
if ($timediff_u < 3600)
$changes['notes'] = ((int)($timediff_c / 3600))." hours elapsed";
if ($issue['assigned_to']['id'] != $assigned_to_new)
$redmine->api('issue')->update($issue['id'], array('assigned_to_id' => $assigned_to_new));
$changes['assigned_to_id'] = $assigned_to_new;
if (count($changes) > 0)
$redmine->api('issue')->update($issue['id'], $changes);
}
?>
... ...