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; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
use ConsoleHelpers\ConsoleKit\ConsoleIO; |
15
|
|
|
use ConsoleHelpers\SVNBuddy\Database\DatabaseCache; |
16
|
|
|
use ConsoleHelpers\SVNBuddy\Database\StatementProfiler; |
17
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\Connector\Connector; |
18
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\Parser\LogMessageParserFactory; |
19
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\DatabaseCollectorPlugin\BugsPlugin; |
20
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\DatabaseCollectorPlugin\ProjectsPlugin; |
21
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\DatabaseCollectorPlugin\RefsPlugin; |
22
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\RepositoryCollectorPlugin\MergesPlugin; |
23
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\RepositoryCollectorPlugin\PathsPlugin; |
24
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\RepositoryCollectorPlugin\SummaryPlugin; |
25
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\RevisionUrlBuilder; |
26
|
|
|
|
27
|
|
|
class RevisionLogFactory |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Repository connector. |
32
|
|
|
* |
33
|
|
|
* @var Connector |
34
|
|
|
*/ |
35
|
|
|
private $_repositoryConnector; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Database manager. |
39
|
|
|
* |
40
|
|
|
* @var DatabaseManager |
41
|
|
|
*/ |
42
|
|
|
private $_databaseManager; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Log message parser factory |
46
|
|
|
* |
47
|
|
|
* @var LogMessageParserFactory |
48
|
|
|
*/ |
49
|
|
|
private $_logMessageParserFactory; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Revision logs by url |
53
|
|
|
* |
54
|
|
|
* @var RevisionLog[] |
55
|
|
|
*/ |
56
|
|
|
private $_cache = array(); |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Create revision log. |
60
|
|
|
* |
61
|
|
|
* @param Connector $repository_connector Repository connector. |
62
|
|
|
* @param DatabaseManager $database_manager Database manager. |
63
|
|
|
* @param LogMessageParserFactory $log_message_parser_factory Log message parser factory. |
64
|
|
|
*/ |
65
|
3 |
|
public function __construct( |
66
|
|
|
Connector $repository_connector, |
67
|
|
|
DatabaseManager $database_manager, |
68
|
|
|
LogMessageParserFactory $log_message_parser_factory |
69
|
|
|
) { |
70
|
3 |
|
$this->_repositoryConnector = $repository_connector; |
71
|
3 |
|
$this->_databaseManager = $database_manager; |
72
|
3 |
|
$this->_logMessageParserFactory = $log_message_parser_factory; |
73
|
3 |
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Returns revision log for url. |
77
|
|
|
* |
78
|
|
|
* @param string $repository_url Repository url. |
79
|
|
|
* @param ConsoleIO $io Console IO. |
80
|
|
|
* |
81
|
|
|
* @return RevisionLog |
82
|
|
|
*/ |
83
|
1 |
|
public function getRevisionLog($repository_url, ConsoleIO $io = null) |
84
|
|
|
{ |
85
|
1 |
|
$repository_url = $this->_repositoryConnector->removeCredentials($repository_url); |
86
|
|
|
|
87
|
1 |
|
if ( !isset($this->_cache[$repository_url]) ) { |
88
|
1 |
|
$this->_cache[$repository_url] = $this->createRevisionLog($repository_url, $io); |
89
|
1 |
|
} |
90
|
|
|
|
91
|
1 |
|
return $this->_cache[$repository_url]; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Returns revision log for url. |
96
|
|
|
* |
97
|
|
|
* @param string $repository_url Repository url. |
98
|
|
|
* @param ConsoleIO $io Console IO. |
99
|
|
|
* |
100
|
|
|
* @return RevisionLog |
101
|
|
|
*/ |
102
|
1 |
|
protected function createRevisionLog($repository_url, ConsoleIO $io = null) |
103
|
|
|
{ |
104
|
|
|
// Gets database for given repository url. |
105
|
1 |
|
$root_url = $this->_repositoryConnector->getRootUrl($repository_url); |
106
|
1 |
|
$database = $this->_databaseManager->getDatabase($root_url, $io); |
107
|
|
|
|
108
|
|
|
// Create dependencies. |
109
|
1 |
|
$database_cache = new DatabaseCache($database); |
110
|
1 |
|
$repository_filler = new RepositoryFiller($database, $database_cache); |
111
|
|
|
|
112
|
1 |
|
$revision_url_builder = new RevisionUrlBuilder($this->_repositoryConnector, $repository_url); |
113
|
|
|
|
114
|
|
|
// Create blank revision log. |
115
|
1 |
|
$revision_log = new RevisionLog($repository_url, $revision_url_builder, $this->_repositoryConnector, $io); |
116
|
|
|
|
117
|
|
|
// Add plugins to revision log. |
118
|
1 |
|
$revision_log->registerPlugin(new SummaryPlugin($database, $repository_filler)); |
119
|
1 |
|
$revision_log->registerPlugin(new PathsPlugin( |
120
|
1 |
|
$database, |
121
|
1 |
|
$repository_filler, |
122
|
1 |
|
$database_cache, |
123
|
1 |
|
$this->_repositoryConnector, |
124
|
1 |
|
new PathCollisionDetector() |
125
|
1 |
|
)); |
126
|
1 |
|
$revision_log->registerPlugin(new ProjectsPlugin($database, $repository_filler)); |
127
|
1 |
|
$revision_log->registerPlugin(new BugsPlugin( |
128
|
1 |
|
$database, |
129
|
1 |
|
$repository_filler, |
130
|
1 |
|
$root_url, |
131
|
1 |
|
$this->_repositoryConnector, |
132
|
1 |
|
$this->_logMessageParserFactory |
133
|
1 |
|
)); |
134
|
1 |
|
$revision_log->registerPlugin(new MergesPlugin($database, $repository_filler)); |
135
|
1 |
|
$revision_log->registerPlugin(new RefsPlugin($database, $repository_filler)); |
136
|
|
|
|
137
|
|
|
// Run migrations (includes initial schema creation). |
138
|
1 |
|
$context = new MigrationContext($database, clone $revision_log); |
139
|
1 |
|
$this->_databaseManager->runMigrations($context); |
140
|
|
|
|
141
|
1 |
|
$profiler = $database->getProfiler(); |
142
|
|
|
|
143
|
1 |
|
if ( $profiler instanceof StatementProfiler ) { |
144
|
|
|
$profiler->trackDuplicates(true); |
145
|
|
|
} |
146
|
|
|
|
147
|
1 |
|
$revision_log->refresh(false); |
148
|
|
|
|
149
|
1 |
|
if ( $profiler instanceof StatementProfiler ) { |
150
|
|
|
$profiler->trackDuplicates(false); |
151
|
|
|
} |
152
|
|
|
|
153
|
1 |
|
return $revision_log; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
} |
157
|
|
|
|