Repository navigation
Expand file tree
/
Copy pathIssue.php
More file actions
96 lines (86 loc) · 2.68 KB
/
Copy pathIssue.php
File metadata and controls
96 lines (86 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
namespace EntityPopulator\Entities;
use \Config\Config;
/**
* As EntityPopulatr thinks these are Doctrine1.X's DoctrineRecords, and redmine's api
* uses only arrays I wrap issue values in an ArrayAccess instance that also implements
* DoctrineRecord's fromArray() method.
*
* @author Juan Manuel Fernandez <juanmf@gmail.com>
*/
class Issue extends Entity
{
/**
* The Redmin API this entity encapsulates {@see \Redmine\Client::api()}
*/
const API = 'issue';
const CUSTOM_FIELDS_CONFIG_KEY = 'issue';
public static $createdIds = array();
/**
* Holds the array of customFields ids. {@see Config/config.yml}
*
* @var array
*/
private static $customFieldsConfig = array();
/**
* Initializes, only the 1st instance, the static $customFields for this entity.
*
* @return void
*/
public function __construct()
{
if (! empty(self::$customFieldsConfig)) {
return;
}
$config = Config::get('custom_fields');
self::$customFieldsConfig = $config[self::CUSTOM_FIELDS_CONFIG_KEY];
}
/**
* Send the create rest reqest to redmine host after adapting customFields to the
* expected format
*
* @return void
*/
public function save()
{
parent::adaptCustomFields($this);
if (isset($this['id'])) {
return $this->update();
}
$importService = \ImportService::getInstance();
$api = $importService->getClient()->api(self::API);
/* @var $api \Redmine\Api\Issue */
$return = $api->create($this->toArray());
$this->checkErrors($return);
$this->addIdToCreatedIds($return, $importService);
}
/**
* stores last created Id in self::$createdIds. these id are used for issue deletion
* while testing our imports until we configure it right.
*
* @param type $param
*
* @return void
*/
private function addIdToCreatedIds($return, $importService)
{
$currentProject = $importService->getCurrentProject();
self::$createdIds[$currentProject]['issues'][] = array('id' => (string) $return->id);
}
/**
* {@inheritdoc}
*/
public function getCustomFieldsConfig()
{
return self::$customFieldsConfig;
}
public function update()
{
$this['notes'] = 'Actualización Automatica, desde planilla.';
$importService = \ImportService::getInstance();
$api = $importService->getClient()->api(self::API);
/* @var $api \Redmine\Api\Issue */
$return = $api->update($this['id'], $this->toArray());
$this->checkErrors($return, true);
}
}