1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) Enalean, 2016. All Rights Reserved. |
4
|
|
|
* |
5
|
|
|
* This file is a part of Tuleap. |
6
|
|
|
* |
7
|
|
|
* Tuleap is free software; you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU General Public License as published by |
9
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* Tuleap is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License |
18
|
|
|
* along with Tuleap. If not, see <http://www.gnu.org/licenses/>. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
class DefaultProjectMirrorDao extends DataAccessObject { |
22
|
|
|
|
23
|
|
|
public function removeAllToProject($project_id) { |
24
|
|
|
$project_id = $this->da->escapeInt($project_id); |
25
|
|
|
|
26
|
|
|
$sql = "DELETE FROM plugin_git_default_project_mirrors |
27
|
|
|
WHERE project_id = $project_id"; |
28
|
|
|
|
29
|
|
|
return $this->update($sql); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function addDefaultMirrorsToProject($project_id, array $selected_mirror_ids) { |
33
|
|
|
$project_id = $this->da->escapeInt($project_id); |
34
|
|
|
|
35
|
|
|
$sql = "INSERT INTO plugin_git_default_project_mirrors (project_id, mirror_id) |
36
|
|
|
VALUES "; |
37
|
|
|
|
38
|
|
|
$values = array(); |
39
|
|
|
foreach ($selected_mirror_ids as $mirror_id) { |
40
|
|
|
$mirror_id = $this->da->escapeInt($mirror_id); |
41
|
|
|
$values[] = "($project_id, $mirror_id)"; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$sql .= implode(', ', $values); |
45
|
|
|
|
46
|
|
|
return $this->update($sql); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function getDefaultMirrorIdsForProject($project_id) { |
50
|
|
|
$project_id = $this->da->escapeInt($project_id); |
51
|
|
|
|
52
|
|
|
$sql = "SELECT mirror_id AS id |
53
|
|
|
FROM plugin_git_default_project_mirrors |
54
|
|
|
WHERE project_id = $project_id"; |
55
|
|
|
|
56
|
|
|
return $this->retrieveIds($sql); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function deleteFromDefaultMirrors($deleted_mirror_id) { |
60
|
|
|
$deleted_mirror_id = $this->da->escapeInt($deleted_mirror_id); |
61
|
|
|
|
62
|
|
|
$sql = "DELETE FROM plugin_git_default_project_mirrors |
63
|
|
|
WHERE mirror_id = $deleted_mirror_id"; |
64
|
|
|
|
65
|
|
|
return $this->update($sql); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function deleteFromDefaultMirrorsInProjects($mirror_id, array $project_ids) { |
69
|
|
|
$mirror_id = $this->da->escapeInt($mirror_id); |
70
|
|
|
$project_ids = $this->da->escapeIntImplode($project_ids); |
71
|
|
|
|
72
|
|
|
$sql = "DELETE FROM plugin_git_default_project_mirrors |
73
|
|
|
WHERE mirror_id = $mirror_id |
74
|
|
|
AND project_id IN ($project_ids)"; |
75
|
|
|
|
76
|
|
|
return $this->update($sql); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return boolean |
81
|
|
|
*/ |
82
|
|
|
public function duplicate($template_project_id, $new_project_id) { |
83
|
|
|
$template_project_id = $this->da->escapeInt($template_project_id); |
84
|
|
|
$new_project_id = $this->da->escapeInt($new_project_id); |
85
|
|
|
|
86
|
|
|
$sql = "INSERT INTO plugin_git_default_project_mirrors (project_id, mirror_id) |
87
|
|
|
SELECT $new_project_id, plugin_git_default_project_mirrors.mirror_id |
88
|
|
|
FROM plugin_git_default_project_mirrors |
89
|
|
|
LEFT JOIN plugin_git_restricted_mirrors |
90
|
|
|
ON (plugin_git_default_project_mirrors.mirror_id = plugin_git_restricted_mirrors.mirror_id) |
91
|
|
|
WHERE project_id = $template_project_id |
92
|
|
|
AND plugin_git_restricted_mirrors.mirror_id IS NULL"; |
93
|
|
|
|
94
|
|
|
return $this->update($sql); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
} |