@@ -21,23 +21,23 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @return Constraint[] |
23 | 23 | */ |
24 | - public function queryConstraintsForProperty( PropertyId $propertyId ) { |
|
25 | - $db = wfGetDB( DB_REPLICA ); |
|
24 | + public function queryConstraintsForProperty(PropertyId $propertyId) { |
|
25 | + $db = wfGetDB(DB_REPLICA); |
|
26 | 26 | |
27 | 27 | $results = $db->select( |
28 | 28 | 'wbqc_constraints', |
29 | 29 | '*', |
30 | - [ 'pid' => $propertyId->getNumericId() ] |
|
30 | + ['pid' => $propertyId->getNumericId()] |
|
31 | 31 | ); |
32 | 32 | |
33 | - return $this->convertToConstraints( $results ); |
|
33 | + return $this->convertToConstraints($results); |
|
34 | 34 | } |
35 | 35 | |
36 | - private function encodeConstraintParameters( array $constraintParameters ) { |
|
37 | - $json = json_encode( $constraintParameters, JSON_FORCE_OBJECT ); |
|
36 | + private function encodeConstraintParameters(array $constraintParameters) { |
|
37 | + $json = json_encode($constraintParameters, JSON_FORCE_OBJECT); |
|
38 | 38 | |
39 | - if ( strlen( $json ) > 50000 ) { |
|
40 | - $json = json_encode( [ '@error' => [ 'toolong' => true ] ] ); |
|
39 | + if (strlen($json) > 50000) { |
|
40 | + $json = json_encode(['@error' => ['toolong' => true]]); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | return $json; |
@@ -49,21 +49,21 @@ discard block |
||
49 | 49 | * @throws DBUnexpectedError |
50 | 50 | * @return bool |
51 | 51 | */ |
52 | - public function insertBatch( array $constraints ) { |
|
52 | + public function insertBatch(array $constraints) { |
|
53 | 53 | $accumulator = array_map( |
54 | - function ( Constraint $constraint ) { |
|
54 | + function(Constraint $constraint) { |
|
55 | 55 | return [ |
56 | 56 | 'constraint_guid' => $constraint->getConstraintId(), |
57 | 57 | 'pid' => $constraint->getPropertyId()->getNumericId(), |
58 | 58 | 'constraint_type_qid' => $constraint->getConstraintTypeItemId(), |
59 | - 'constraint_parameters' => $this->encodeConstraintParameters( $constraint->getConstraintParameters() ) |
|
59 | + 'constraint_parameters' => $this->encodeConstraintParameters($constraint->getConstraintParameters()) |
|
60 | 60 | ]; |
61 | 61 | }, |
62 | 62 | $constraints |
63 | 63 | ); |
64 | 64 | |
65 | - $db = wfGetDB( DB_MASTER ); |
|
66 | - return $db->insert( 'wbqc_constraints', $accumulator ); |
|
65 | + $db = wfGetDB(DB_MASTER); |
|
66 | + return $db->insert('wbqc_constraints', $accumulator); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -71,13 +71,13 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @return string[] |
73 | 73 | */ |
74 | - private function uuidPattern( LikeMatch $any ) { |
|
74 | + private function uuidPattern(LikeMatch $any) { |
|
75 | 75 | return array_merge( |
76 | - array_fill( 0, 8, $any ), [ '-' ], |
|
77 | - array_fill( 0, 4, $any ), [ '-' ], |
|
78 | - array_fill( 0, 4, $any ), [ '-' ], |
|
79 | - array_fill( 0, 4, $any ), [ '-' ], |
|
80 | - array_fill( 0, 12, $any ) |
|
76 | + array_fill(0, 8, $any), ['-'], |
|
77 | + array_fill(0, 4, $any), ['-'], |
|
78 | + array_fill(0, 4, $any), ['-'], |
|
79 | + array_fill(0, 4, $any), ['-'], |
|
80 | + array_fill(0, 12, $any) |
|
81 | 81 | ); |
82 | 82 | } |
83 | 83 | |
@@ -89,14 +89,14 @@ discard block |
||
89 | 89 | * |
90 | 90 | * @throws DBUnexpectedError |
91 | 91 | */ |
92 | - public function deleteForPropertyWhereConstraintIdIsStatementId( PropertyId $propertyId ) { |
|
93 | - $db = wfGetDB( DB_MASTER ); |
|
92 | + public function deleteForPropertyWhereConstraintIdIsStatementId(PropertyId $propertyId) { |
|
93 | + $db = wfGetDB(DB_MASTER); |
|
94 | 94 | $db->delete( |
95 | 95 | 'wbqc_constraints', |
96 | 96 | [ |
97 | 97 | 'pid' => $propertyId->getNumericId(), |
98 | 98 | // AND constraint_guid LIKE %$________-____-____-____-____________ |
99 | - 'constraint_guid ' . $db->buildLike( array_merge( [ $db->anyString(), '$' ], $this->uuidPattern( $db->anyChar() ) ) ) |
|
99 | + 'constraint_guid '.$db->buildLike(array_merge([$db->anyString(), '$'], $this->uuidPattern($db->anyChar()))) |
|
100 | 100 | ] |
101 | 101 | ); |
102 | 102 | } |
@@ -107,21 +107,21 @@ discard block |
||
107 | 107 | * @throws InvalidArgumentException |
108 | 108 | * @throws DBUnexpectedError |
109 | 109 | */ |
110 | - public function deleteAll( $batchSize = 1000 ) { |
|
111 | - if ( !is_int( $batchSize ) ) { |
|
110 | + public function deleteAll($batchSize = 1000) { |
|
111 | + if (!is_int($batchSize)) { |
|
112 | 112 | throw new InvalidArgumentException(); |
113 | 113 | } |
114 | 114 | $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); |
115 | - $db = $lbFactory->getMainLB()->getConnection( DB_MASTER ); |
|
116 | - if ( $db->getType() === 'sqlite' ) { |
|
117 | - $db->delete( 'wbqc_constraints', '*' ); |
|
115 | + $db = $lbFactory->getMainLB()->getConnection(DB_MASTER); |
|
116 | + if ($db->getType() === 'sqlite') { |
|
117 | + $db->delete('wbqc_constraints', '*'); |
|
118 | 118 | } else { |
119 | 119 | do { |
120 | - $db->commit( __METHOD__, 'flush' ); |
|
120 | + $db->commit(__METHOD__, 'flush'); |
|
121 | 121 | $lbFactory->waitForReplication(); |
122 | - $table = $db->tableName( 'wbqc_constraints' ); |
|
123 | - $db->query( sprintf( 'DELETE FROM %s LIMIT %d', $table, $batchSize ) ); |
|
124 | - } while ( $db->affectedRows() > 0 ); |
|
122 | + $table = $db->tableName('wbqc_constraints'); |
|
123 | + $db->query(sprintf('DELETE FROM %s LIMIT %d', $table, $batchSize)); |
|
124 | + } while ($db->affectedRows() > 0); |
|
125 | 125 | } |
126 | 126 | } |
127 | 127 | |
@@ -130,26 +130,26 @@ discard block |
||
130 | 130 | * |
131 | 131 | * @return Constraint[] |
132 | 132 | */ |
133 | - private function convertToConstraints( IResultWrapper $results ) { |
|
133 | + private function convertToConstraints(IResultWrapper $results) { |
|
134 | 134 | $constraints = []; |
135 | - foreach ( $results as $result ) { |
|
135 | + foreach ($results as $result) { |
|
136 | 136 | $constraintTypeItemId = $result->constraint_type_qid; |
137 | - $constraintParameters = json_decode( $result->constraint_parameters, true ); |
|
137 | + $constraintParameters = json_decode($result->constraint_parameters, true); |
|
138 | 138 | |
139 | - if ( $constraintParameters === null ) { |
|
139 | + if ($constraintParameters === null) { |
|
140 | 140 | // T171295 |
141 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' ) |
|
142 | - ->warning( 'Constraint {constraintId} has invalid constraint parameters.', [ |
|
141 | + LoggerFactory::getInstance('WikibaseQualityConstraints') |
|
142 | + ->warning('Constraint {constraintId} has invalid constraint parameters.', [ |
|
143 | 143 | 'method' => __METHOD__, |
144 | 144 | 'constraintId' => $result->constraint_guid, |
145 | 145 | 'constraintParameters' => $result->constraint_parameters, |
146 | - ] ); |
|
147 | - $constraintParameters = [ '@error' => [ /* unknown */ ] ]; |
|
146 | + ]); |
|
147 | + $constraintParameters = ['@error' => [/* unknown */]]; |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | $constraints[] = new Constraint( |
151 | 151 | $result->constraint_guid, |
152 | - PropertyId::newFromNumber( $result->pid ), |
|
152 | + PropertyId::newFromNumber($result->pid), |
|
153 | 153 | $constraintTypeItemId, |
154 | 154 | $constraintParameters |
155 | 155 | ); |