1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the SVN-Buddy library. |
4
|
|
|
* For the full copyright and license information, please view |
5
|
|
|
* the LICENSE file that was distributed with this source code. |
6
|
|
|
* |
7
|
|
|
* @copyright Alexander Obuhovich <[email protected]> |
8
|
|
|
* @link https://github.com/console-helpers/svn-buddy |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
class RefsPlugin extends AbstractDatabaseCollectorPlugin |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Returns plugin name. |
19
|
|
|
* |
20
|
|
|
* @return string |
21
|
|
|
*/ |
22
|
5 |
|
public function getName() |
23
|
|
|
{ |
24
|
5 |
|
return 'refs'; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Defines parsing statistic types. |
29
|
|
|
* |
30
|
|
|
* @return array |
31
|
|
|
*/ |
32
|
12 |
|
public function defineStatisticTypes() |
33
|
|
|
{ |
34
|
12 |
|
return array(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Processes data. |
39
|
|
|
* |
40
|
|
|
* @param integer $from_revision From revision. |
41
|
|
|
* @param integer $to_revision To revision. |
42
|
|
|
* |
43
|
|
|
* @return void |
44
|
|
|
*/ |
45
|
1 |
|
public function doProcess($from_revision, $to_revision) |
46
|
|
|
{ |
47
|
|
|
// Do nothing, because "paths" plugin determines refs as well. |
48
|
1 |
|
$this->setLastRevision($to_revision); |
49
|
1 |
|
$this->advanceProgressBar(); |
50
|
1 |
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Find revisions by collected data. |
54
|
|
|
* |
55
|
|
|
* @param array $criteria Criteria. |
56
|
|
|
* @param string|null $project_path Project path. |
57
|
|
|
* |
58
|
|
|
* @return array |
59
|
|
|
*/ |
60
|
6 |
|
public function find(array $criteria, $project_path) |
61
|
|
|
{ |
62
|
6 |
|
if ( !$criteria ) { |
63
|
1 |
|
return array(); |
64
|
|
|
} |
65
|
|
|
|
66
|
5 |
|
$project_id = $this->getProject($project_path); |
67
|
|
|
|
68
|
4 |
|
if ( reset($criteria) === 'all_refs' ) { |
69
|
|
|
$sql = 'SELECT DISTINCT Name |
70
|
|
|
FROM ProjectRefs |
71
|
1 |
|
WHERE ProjectId = :project_id'; |
72
|
|
|
|
73
|
1 |
|
return $this->database->fetchCol($sql, array('project_id' => $project_id)); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$sql = 'SELECT DISTINCT cr.Revision |
77
|
|
|
FROM ProjectRefs pr |
78
|
|
|
JOIN CommitRefs cr ON cr.RefId = pr.Id |
79
|
3 |
|
WHERE pr.ProjectId = :project_id AND pr.Name IN (:names)'; |
80
|
3 |
|
$ref_revisions = $this->database->fetchCol($sql, array('project_id' => $project_id, 'names' => $criteria)); |
81
|
|
|
|
82
|
3 |
|
sort($ref_revisions, SORT_NUMERIC); |
83
|
|
|
|
84
|
3 |
|
return $ref_revisions; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Returns information about revisions. |
89
|
|
|
* |
90
|
|
|
* @param array $revisions Revisions. |
91
|
|
|
* |
92
|
|
|
* @return array |
93
|
|
|
*/ |
94
|
1 |
|
public function getRevisionsData(array $revisions) |
95
|
|
|
{ |
96
|
1 |
|
$results = array(); |
97
|
|
|
|
98
|
|
|
$sql = 'SELECT cr.Revision, pr.Name |
99
|
|
|
FROM CommitRefs cr |
100
|
|
|
JOIN ProjectRefs pr ON pr.Id = cr.RefId |
101
|
1 |
|
WHERE cr.Revision IN (:revisions)'; |
102
|
1 |
|
$revisions_data = $this->database->fetchAll($sql, array('revisions' => $revisions)); |
103
|
|
|
|
104
|
1 |
|
foreach ( $revisions_data as $revision_data ) { |
105
|
1 |
|
$revision = $revision_data['Revision']; |
106
|
1 |
|
$ref = $revision_data['Name']; |
107
|
|
|
|
108
|
1 |
|
if ( !isset($results[$revision]) ) { |
109
|
1 |
|
$results[$revision] = array(); |
110
|
1 |
|
} |
111
|
|
|
|
112
|
1 |
|
$results[$revision][] = $ref; |
113
|
1 |
|
} |
114
|
|
|
|
115
|
1 |
|
return $this->addMissingResults($revisions, $results); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
} |
119
|
|
|
|