daily-autoclose.php 1.93 KB
<?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/Project.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";

function autoclose($user_id = null) {
	global $redmine;

	$redmine_user = $redmine;

	if (!empty($user_id)) {
		$user    = $redmine->api('user')->show($user_id)['user'];
		$redmine_user = new Redmine\Client('https://tasks.mephi.ru', $user['api_key']);
	}

	$issues_search = array(
			'status_id'		=> STATUSID_SOLVED,
			'sort'			=> 'updated_on',
			'limit'			=> 100000,
		);

	$answer = $redmine_user->api('issue')->all($issues_search);

	if (!isset($answer['issues']))
		return;

	$curts = time();

	$toooldts = $curts - ISSUERESPONSE_TIMEOUT;

	foreach ($answer['issues'] as &$issue) {
		$updated_on = strtotime($issue['updated_on']);

		//print_r($issue);

		if ($updated_on < $toooldts) {
			//print_r($issue);
			$changes['status_id'] = STATUSID_CLOSED;
			$changes['notes']     = "Задача переведена из статуса «Решена» в статус «Закрыта» в связи с отсутствием активности более двух недель.";

			//print $issue['id']." ".print_r($changes, 1);
			$redmine->api('issue')->update($issue['id'], $changes);
		}
		continue;
	}
}

$redmine = new Redmine\Client('https://tasks.mephi.ru', REDMINE_API);

$answer = $redmine->api('user')->all(array('limit' => 1000));

autoclose(null);

foreach ($answer['users'] as $user) {
	autoclose($user['id']);
}


?>