forked from mantisbt/mantisbt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProjectHierarchyUpdateCommand.php
126 lines (111 loc) · 3.65 KB
/
ProjectHierarchyUpdateCommand.php
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
# MantisBT - A PHP based bugtracking system
#
# MantisBT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# MantisBT is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
require_api( 'constant_inc.php' );
require_api( 'config_api.php' );
require_api( 'helper_api.php' );
require_api( 'project_api.php' );
require_api( 'project_hierarchy_api.php' );
use Mantis\Exceptions\ClientException;
/**
* A command that updates a project in the project hierarchy (subproject).
*/
class ProjectHierarchyUpdateCommand extends Command {
/**
* @var integer
*/
private $project_id;
/**
* @var integer
*/
private $subproject_id;
/**
* @var boolean
*/
private $inherit_parent;
/**
* Constructor
*
* $p_data['query'] is expected to contain:
* - project_id (integer)
* - subproject_id (integer)
*
* $p_data['payload'] is expected to contain:
* - inherit_parent (boolean)
*
* @param array $p_data The command data.
*/
function __construct( array $p_data ) {
parent::__construct( $p_data );
}
/**
* Validate the data.
*/
function validate() {
if ( config_get( 'subprojects_enabled' ) == OFF ) {
throw new ClientException(
'Project hierarchy (subprojects) is disabled',
ERROR_PROJECT_HIERARCHY_DISABLED );
}
$this->project_id = helper_parse_id( $this->query( 'project_id' ), 'project_id' );
if( !project_exists( $this->project_id ) ) {
throw new ClientException(
"Project '$this->project_id' not found",
ERROR_PROJECT_NOT_FOUND,
array( $this->project_id ) );
}
$this->subproject_id = helper_parse_id( $this->query( 'subproject_id' ), 'subproject_id' );
if( !project_exists( $this->subproject_id ) ) {
throw new ClientException(
"Project '$this->subproject_id' not found",
ERROR_PROJECT_NOT_FOUND,
array( $this->subproject_id ) );
}
if( !access_has_project_level( config_get( 'manage_project_threshold' ), $this->project_id ) ||
!access_has_project_level( config_get( 'manage_project_threshold' ), $this->subproject_id ) ) {
throw new ClientException(
'Access denied to delete subprojects',
ERROR_ACCESS_DENIED );
}
if( !in_array( $this->subproject_id, project_hierarchy_get_subprojects( $this->project_id, true ) ) ) {
throw new ClientException(
"Project '$this->subproject_id' is not a subproject of '$this->project_id'",
ERROR_PROJECT_SUBPROJECT_NOT_FOUND,
array( $this->subproject_id, $this->project_id ) );
}
$this->inherit_parent = $this->payload( 'inherit_parent' );
if( !isset( $this->inherit_parent ) ) {
throw new ClientException( 'inherit_parent must be supplied',
ERROR_EMPTY_FIELD,
array( 'inherit_parent' ) );
}
}
/**
* Process the command.
*
* @returns array Command response
*/
protected function process() {
if( $this->project_id != helper_get_current_project() ) {
# in case the current project is not the same project of the bug we are
# viewing, override the current project. This to avoid problems with
# categories and handlers lists etc.
global $g_project_override;
$g_project_override = $this->project_id;
}
project_hierarchy_update( $this->subproject_id, $this->project_id, $this->inherit_parent );
return array();
}
}