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\RepositoryCollectorPlugin; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\AbstractPlugin; |
15
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\IOverwriteAwarePlugin; |
16
|
|
|
|
17
|
|
|
abstract class AbstractRepositoryCollectorPlugin extends AbstractPlugin implements IRepositoryCollectorPlugin |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Parse log entries. |
22
|
|
|
* |
23
|
|
|
* @param \SimpleXMLElement $log Log. |
24
|
|
|
* |
25
|
|
|
* @return void |
26
|
|
|
*/ |
27
|
31 |
|
public function parse(\SimpleXMLElement $log) |
28
|
|
|
{ |
29
|
31 |
|
$this->database->beginTransaction(); |
30
|
|
|
|
31
|
31 |
|
$last_processed_revision = null; |
32
|
31 |
|
$last_revision = $this->getLastRevision(); |
33
|
|
|
|
34
|
31 |
|
if ( $this instanceof IOverwriteAwarePlugin && $this->isOverwriteMode() ) { |
35
|
4 |
|
foreach ( $log->logentry as $log_entry ) { |
36
|
4 |
|
$revision = (int)$log_entry['revision']; |
37
|
|
|
|
38
|
4 |
|
$this->remove($revision); |
39
|
4 |
|
$this->doParse($revision, $log_entry); |
|
|
|
|
40
|
|
|
|
41
|
|
|
// When revision appeared only after overwrite parsing process. |
42
|
4 |
|
if ( $revision > $last_revision ) { |
43
|
|
|
$last_processed_revision = $revision; |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
else { |
48
|
27 |
|
foreach ( $log->logentry as $log_entry ) { |
49
|
27 |
|
$revision = (int)$log_entry['revision']; |
50
|
|
|
|
51
|
|
|
// Don't handle same revision twice. |
52
|
27 |
|
if ( $revision <= $last_revision ) { |
53
|
3 |
|
continue; |
54
|
|
|
} |
55
|
|
|
|
56
|
24 |
|
$this->doParse($revision, $log_entry); |
57
|
24 |
|
$last_processed_revision = $revision; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
31 |
|
if ( isset($last_processed_revision) ) { |
62
|
24 |
|
$this->setLastRevision($last_processed_revision); |
63
|
|
|
} |
64
|
|
|
|
65
|
31 |
|
$this->database->commit(); |
66
|
|
|
|
67
|
31 |
|
$this->freeMemoryAutomatically(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Does actual parsing. |
72
|
|
|
* |
73
|
|
|
* @param integer $revision Revision. |
74
|
|
|
* @param \SimpleXMLElement $log_entry Log Entry. |
75
|
|
|
* |
76
|
|
|
* @return void |
77
|
|
|
*/ |
78
|
|
|
abstract protected function doParse($revision, \SimpleXMLElement $log_entry); |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Removes changes plugin made based on a given revision. |
82
|
|
|
* |
83
|
|
|
* @param integer $revision Revision. |
84
|
|
|
* |
85
|
|
|
* @return void |
86
|
|
|
*/ |
87
|
|
|
abstract protected function remove($revision); |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Returns revision query flags. |
91
|
|
|
* |
92
|
|
|
* @return array |
93
|
|
|
*/ |
94
|
1 |
|
public function getRevisionQueryFlags() |
95
|
|
|
{ |
96
|
1 |
|
return array(); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
} |
100
|
|
|
|