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\DatabaseCollectorPlugin; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\AbstractPlugin; |
15
|
|
|
use Symfony\Component\Console\Helper\ProgressBar; |
16
|
|
|
|
17
|
|
|
abstract class AbstractDatabaseCollectorPlugin extends AbstractPlugin implements IDatabaseCollectorPlugin |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Progress bar. |
22
|
|
|
* |
23
|
|
|
* @var ProgressBar |
24
|
|
|
*/ |
25
|
|
|
private $_progressBar; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Processes data. |
29
|
|
|
* |
30
|
|
|
* @param integer $from_revision From revision. |
31
|
|
|
* @param integer $to_revision To revision. |
32
|
|
|
* @param ProgressBar $progress_bar Progress bar. |
33
|
|
|
* |
34
|
|
|
* @return void |
35
|
|
|
*/ |
36
|
20 |
|
public function process($from_revision, $to_revision, ProgressBar $progress_bar = null) |
37
|
|
|
{ |
38
|
20 |
|
$this->_progressBar = $progress_bar; |
39
|
|
|
|
40
|
20 |
|
$this->database->beginTransaction(); |
41
|
20 |
|
$this->doProcess($from_revision, $to_revision); |
42
|
20 |
|
$this->database->commit(); |
43
|
|
|
|
44
|
20 |
|
$this->freeMemoryAutomatically(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Processes data. |
49
|
|
|
* |
50
|
|
|
* @param integer $from_revision From revision. |
51
|
|
|
* @param integer $to_revision To revision. |
52
|
|
|
* |
53
|
|
|
* @return void |
54
|
|
|
*/ |
55
|
|
|
abstract public function doProcess($from_revision, $to_revision); |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Advanced progress bar. |
59
|
|
|
* |
60
|
|
|
* @return void |
61
|
|
|
*/ |
62
|
20 |
|
protected function advanceProgressBar() |
63
|
|
|
{ |
64
|
20 |
|
if ( isset($this->_progressBar) ) { |
65
|
|
|
$this->_progressBar->advance(); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Returns projects. |
71
|
|
|
* |
72
|
|
|
* @param string $where_clause Where clause. |
73
|
|
|
* @param array $values Values. |
74
|
|
|
* |
75
|
|
|
* @return array |
76
|
|
|
*/ |
77
|
19 |
|
protected function getProjects($where_clause = '', array $values = array()) |
78
|
|
|
{ |
79
|
19 |
|
$sql = 'SELECT * |
80
|
19 |
|
FROM Projects'; |
81
|
|
|
|
82
|
19 |
|
if ( $where_clause ) { |
83
|
13 |
|
$sql .= ' WHERE ' . $where_clause; |
84
|
|
|
} |
85
|
|
|
|
86
|
19 |
|
$projects = $this->database->fetchAll($sql, $values); |
87
|
|
|
|
88
|
19 |
|
if ( !$projects ) { |
|
|
|
|
89
|
12 |
|
return array(); |
90
|
|
|
} |
91
|
|
|
|
92
|
14 |
|
$path_hashes = array_map( |
93
|
14 |
|
array($this->repositoryFiller, 'getPathChecksum'), |
94
|
14 |
|
$this->getField('Path', $projects) |
95
|
14 |
|
); |
96
|
|
|
|
97
|
14 |
|
$sql = 'SELECT Path, Id AS PathId, RevisionAdded, RevisionDeleted, RevisionLastSeen |
98
|
|
|
FROM Paths |
99
|
14 |
|
WHERE PathHash IN (:path_hashes)'; |
100
|
14 |
|
$paths = $this->database->fetchAssoc($sql, array('path_hashes' => $path_hashes)); |
101
|
|
|
|
102
|
14 |
|
foreach ( $projects as $index => $project_data ) { |
103
|
14 |
|
$project_path = $project_data['Path']; |
104
|
14 |
|
$projects[$index] = array_merge($projects[$index], $paths[$project_path]); |
105
|
|
|
} |
106
|
|
|
|
107
|
14 |
|
return $projects; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Returns given column value from each array entry. |
112
|
|
|
* |
113
|
|
|
* @param string $field Field. |
114
|
|
|
* @param array $records Records. |
115
|
|
|
* |
116
|
|
|
* @return array |
117
|
|
|
*/ |
118
|
14 |
|
protected function getField($field, array $records) |
119
|
|
|
{ |
120
|
14 |
|
$ret = array(); |
121
|
|
|
|
122
|
14 |
|
foreach ( $records as $row ) { |
123
|
14 |
|
$ret[] = $row[$field]; |
124
|
|
|
} |
125
|
|
|
|
126
|
14 |
|
return $ret; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
} |
130
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.