redmine

Fixed autoclose script

@@ -4,41 +4,64 @@ require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/AbstractApi.php"; @@ -4,41 +4,64 @@ require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/AbstractApi.php";
4 require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/SimpleXMLElement.php"; 4 require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/SimpleXMLElement.php";
5 require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/IssueStatus.php"; 5 require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/IssueStatus.php";
6 require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/User.php"; 6 require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/User.php";
  7 +require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/Project.php";
7 require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/Issue.php"; 8 require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/Issue.php";
8 require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/Attachment.php"; 9 require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Api/Attachment.php";
9 require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Client.php"; 10 require_once "lib/3rdparty/php-redmine-api/lib/Redmine/Client.php";
10 11
11 require_once "config.php"; 12 require_once "config.php";
12 13
13 -$redmine = new Redmine\Client('https://tasks.mephi.ru', REDMINE_API); 14 +function autoclose($user_id = null) {
  15 + global $redmine;
  16 +
  17 + $redmine_user = $redmine;
  18 +
  19 + if (!empty($user_id)) {
  20 + $user = $redmine->api('user')->show($user_id)['user'];
  21 + $redmine_user = new Redmine\Client('https://tasks.mephi.ru', $user['api_key']);
  22 + }
14 23
15 -/* NRNU Auto-report */ 24 + $issues_search = array(
  25 + 'status_id' => STATUSID_SOLVED,
  26 + 'sort' => 'updated_on',
  27 + 'limit' => 100000,
  28 + );
16 29
17 -$answer = $redmine->api('issue')->all(array( 30 + $answer = $redmine_user->api('issue')->all($issues_search);
18 - 'status_id' => STATUSID_SOLVED,  
19 - 'sort' => 'updated_on',  
20 - 'limit' => 10000,  
21 - ));  
22 31
23 -if (!isset($answer['issues'])) 32 + if (!isset($answer['issues']))
24 - exit(0); 33 + return;
25 34
26 -$curts = time(); 35 + $curts = time();
27 36
28 -$toooldts = $curts - ISSUERESPONSE_TIMEOUT; 37 + $toooldts = $curts - ISSUERESPONSE_TIMEOUT;
29 38
30 -foreach ($answer['issues'] as &$issue) { 39 + foreach ($answer['issues'] as &$issue) {
31 - $updated_on = strtotime($issue['updated_on']); 40 + $updated_on = strtotime($issue['updated_on']);
32 41
33 - if ($updated_on < $toooldts) {  
34 //print_r($issue); 42 //print_r($issue);
35 - $changes['status_id'] = STATUSID_CLOSED;  
36 - $changes['notes'] = "Задача переведена из статуса «Решена» в статус «Закрыта» в связи с отсутствием активности более двух недель.";  
37 43
38 - $redmine->api('issue')->update($issue['id'], $changes); 44 + if ($updated_on < $toooldts) {
39 - //print $issue['id']." ".print_r($changes, 1); 45 + //print_r($issue);
  46 + $changes['status_id'] = STATUSID_CLOSED;
  47 + $changes['notes'] = "Задача переведена из статуса «Решена» в статус «Закрыта» в связи с отсутствием активности более двух недель.";
  48 +
  49 + //print $issue['id']." ".print_r($changes, 1);
  50 + $redmine->api('issue')->update($issue['id'], $changes);
  51 + }
  52 + continue;
40 } 53 }
41 - continue;  
42 } 54 }
43 55
  56 +$redmine = new Redmine\Client('https://tasks.mephi.ru', REDMINE_API);
  57 +
  58 +$answer = $redmine->api('user')->all(array('limit' => 1000));
  59 +
  60 +autoclose(null);
  61 +
  62 +foreach ($answer['users'] as $user) {
  63 + autoclose($user['id']);
  64 +}
  65 +
  66 +
44 ?> 67 ?>
  1 +#!/bin/sh
  2 +
  3 +cd /home/redmine-sched/redmine-scheduler > /dev/null
  4 +for file in daily-*.php; do
  5 + (
  6 + lockfile-check /run/redmine-schred-d-"$file".lock && exit 0
  7 + lockfile-create /run/redmine-schred-d-"$file".lock
  8 + php ./"$file"
  9 + lockfile-remove /run/redmine-schred-d-"$file".lock
  10 + ) &
  11 +done
  12 +cd - > /dev/null
  13 +
  14 +exit 0
  1 +#!/bin/sh
  2 +
  3 +cd /home/redmine-sched/redmine-scheduler > /dev/null
  4 +for file in weekly-*.php; do
  5 + (
  6 + lockfile-check /run/redmine-schred-w-"$file".lock && exit 0
  7 + lockfile-create /run/redmine-schred-w-"$file".lock
  8 + php ./"$file"
  9 + lockfile-remove /run/redmine-schred-w-"$file".lock
  10 + ) &
  11 +done
  12 +cd - > /dev/null
  13 +
  14 +exit 0