@@ -24,23 +24,23 @@ discard block |
||
| 24 | 24 | * @param PropertyId[] $propertyIds |
| 25 | 25 | * @return array |
| 26 | 26 | */ |
| 27 | - public function getExternalData( array $dumpIds, array $externalIds, array $propertyIds ) { |
|
| 28 | - Assert::parameterElementType( 'string', $dumpIds, '$dumpIds' ); |
|
| 29 | - Assert::parameterElementType( 'string', $externalIds, '$externalIds' ); |
|
| 30 | - Assert::parameterElementType( PropertyId::class, $propertyIds, '$propertyIds' ); |
|
| 31 | - Assert::parameter( count( $dumpIds ) > 0, '$dumpIds', '$dumpIds has to contain at least one element.' ); |
|
| 32 | - Assert::parameter( count( $externalIds ) > 0, '$externalIds', '$externalIds has to contain at least one element.' ); |
|
| 27 | + public function getExternalData(array $dumpIds, array $externalIds, array $propertyIds) { |
|
| 28 | + Assert::parameterElementType('string', $dumpIds, '$dumpIds'); |
|
| 29 | + Assert::parameterElementType('string', $externalIds, '$externalIds'); |
|
| 30 | + Assert::parameterElementType(PropertyId::class, $propertyIds, '$propertyIds'); |
|
| 31 | + Assert::parameter(count($dumpIds) > 0, '$dumpIds', '$dumpIds has to contain at least one element.'); |
|
| 32 | + Assert::parameter(count($externalIds) > 0, '$externalIds', '$externalIds has to contain at least one element.'); |
|
| 33 | 33 | |
| 34 | 34 | $conditions = array( |
| 35 | 35 | 'dump_id' => $dumpIds, |
| 36 | 36 | 'external_id' => $externalIds |
| 37 | 37 | ); |
| 38 | - if ( $propertyIds ) { |
|
| 38 | + if ($propertyIds) { |
|
| 39 | 39 | $conditions['pid'] = $propertyIds; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | $externalData = array(); |
| 43 | - $db = wfGetDB( DB_REPLICA ); |
|
| 43 | + $db = wfGetDB(DB_REPLICA); |
|
| 44 | 44 | $result = $db->select( |
| 45 | 45 | self::TABLE_NAME, |
| 46 | 46 | array( |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | $conditions |
| 53 | 53 | ); |
| 54 | 54 | |
| 55 | - foreach ( $result as $row ) { |
|
| 55 | + foreach ($result as $row) { |
|
| 56 | 56 | $externalData[$row->dump_id][$row->external_id][$row->pid][] = $row->external_value; |
| 57 | 57 | } |
| 58 | 58 | |
@@ -68,13 +68,13 @@ discard block |
||
| 68 | 68 | * @param string $externalValue |
| 69 | 69 | * @return bool |
| 70 | 70 | */ |
| 71 | - public function insert( $dumpId, $externalId, PropertyId $propertyId, $externalValue ) { |
|
| 72 | - Assert::parameterType( 'string', $dumpId, '$dumpId' ); |
|
| 73 | - Assert::parameterType( 'string', $externalId, '$externalId' ); |
|
| 74 | - Assert::parameterType( 'string', $externalValue, '$externalValue' ); |
|
| 71 | + public function insert($dumpId, $externalId, PropertyId $propertyId, $externalValue) { |
|
| 72 | + Assert::parameterType('string', $dumpId, '$dumpId'); |
|
| 73 | + Assert::parameterType('string', $externalId, '$externalId'); |
|
| 74 | + Assert::parameterType('string', $externalValue, '$externalValue'); |
|
| 75 | 75 | |
| 76 | - $externalDataBatch = array( func_get_args() ); |
|
| 77 | - return $this->insertBatch( $externalDataBatch ); |
|
| 76 | + $externalDataBatch = array(func_get_args()); |
|
| 77 | + return $this->insertBatch($externalDataBatch); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
@@ -84,10 +84,10 @@ discard block |
||
| 84 | 84 | * @throws DBError |
| 85 | 85 | * @return bool |
| 86 | 86 | */ |
| 87 | - public function insertBatch( array $externalDataBatch ) { |
|
| 88 | - $db = wfGetDB( DB_MASTER ); |
|
| 87 | + public function insertBatch(array $externalDataBatch) { |
|
| 88 | + $db = wfGetDB(DB_MASTER); |
|
| 89 | 89 | $accumulator = array_map( |
| 90 | - function ( $externalData ) use ( $db ) { |
|
| 90 | + function($externalData) use ($db) { |
|
| 91 | 91 | return array( |
| 92 | 92 | 'dump_id' => $externalData[0], |
| 93 | 93 | 'external_id' => $externalData[1], |
@@ -100,10 +100,10 @@ discard block |
||
| 100 | 100 | |
| 101 | 101 | try { |
| 102 | 102 | $db->begin(); |
| 103 | - $result = $db->insert( self::TABLE_NAME, $accumulator ); |
|
| 103 | + $result = $db->insert(self::TABLE_NAME, $accumulator); |
|
| 104 | 104 | $db->commit(); |
| 105 | 105 | } |
| 106 | - catch( DBError $ex ) { |
|
| 106 | + catch (DBError $ex) { |
|
| 107 | 107 | $db->rollback(); |
| 108 | 108 | throw $ex; |
| 109 | 109 | } |
@@ -118,21 +118,21 @@ discard block |
||
| 118 | 118 | * @param int $batchSize |
| 119 | 119 | * @throws \DBUnexpectedError |
| 120 | 120 | */ |
| 121 | - public function deleteOfDump( $dumpId, $batchSize = 1000 ) { |
|
| 122 | - Assert::parameterType( 'string', $dumpId, '$dumpId' ); |
|
| 123 | - Assert::parameterType( 'integer', $batchSize, 'batchSize' ); |
|
| 121 | + public function deleteOfDump($dumpId, $batchSize = 1000) { |
|
| 122 | + Assert::parameterType('string', $dumpId, '$dumpId'); |
|
| 123 | + Assert::parameterType('integer', $batchSize, 'batchSize'); |
|
| 124 | 124 | |
| 125 | - $db = wfGetDB( DB_MASTER ); |
|
| 126 | - if ( $db->getType() === 'sqlite' ) { |
|
| 127 | - $db->delete( self::TABLE_NAME, array( 'dump_id' => $dumpId ) ); |
|
| 125 | + $db = wfGetDB(DB_MASTER); |
|
| 126 | + if ($db->getType() === 'sqlite') { |
|
| 127 | + $db->delete(self::TABLE_NAME, array('dump_id' => $dumpId)); |
|
| 128 | 128 | } else { |
| 129 | 129 | do { |
| 130 | - $db->commit( __METHOD__, 'flush' ); |
|
| 130 | + $db->commit(__METHOD__, 'flush'); |
|
| 131 | 131 | wfGetLBFactory()->waitForReplication(); |
| 132 | - $table = $db->tableName( self::TABLE_NAME ); |
|
| 133 | - $condition = 'dump_id = ' . $db->addQuotes( $dumpId ); |
|
| 134 | - $db->query( sprintf( 'DELETE FROM %s WHERE %s LIMIT %s', $table, $condition, $batchSize ) ); |
|
| 135 | - } while ( $db->affectedRows() > 0 ); |
|
| 132 | + $table = $db->tableName(self::TABLE_NAME); |
|
| 133 | + $condition = 'dump_id = '.$db->addQuotes($dumpId); |
|
| 134 | + $db->query(sprintf('DELETE FROM %s WHERE %s LIMIT %s', $table, $condition, $batchSize)); |
|
| 135 | + } while ($db->affectedRows() > 0); |
|
| 136 | 136 | } |
| 137 | 137 | } |
| 138 | 138 | |
@@ -29,15 +29,15 @@ discard block |
||
| 29 | 29 | * @return DumpMetaInformation[] |
| 30 | 30 | * @throws InvalidArgumentException |
| 31 | 31 | */ |
| 32 | - public function getWithIds( array $dumpIds ) { |
|
| 33 | - foreach ( $dumpIds as $dumpId ) { |
|
| 34 | - if ( !is_string( $dumpId ) ) { |
|
| 35 | - throw new InvalidArgumentException( '$dumpIds must contain only strings.' ); |
|
| 32 | + public function getWithIds(array $dumpIds) { |
|
| 33 | + foreach ($dumpIds as $dumpId) { |
|
| 34 | + if (!is_string($dumpId)) { |
|
| 35 | + throw new InvalidArgumentException('$dumpIds must contain only strings.'); |
|
| 36 | 36 | } |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - if( count( $dumpIds ) > 0 ) { |
|
| 40 | - $db = wfGetDB( DB_REPLICA ); |
|
| 39 | + if (count($dumpIds) > 0) { |
|
| 40 | + $db = wfGetDB(DB_REPLICA); |
|
| 41 | 41 | $result = $db->select( |
| 42 | 42 | array( |
| 43 | 43 | self::META_TABLE_NAME, |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | ) |
| 58 | 58 | ); |
| 59 | 59 | |
| 60 | - return $this->buildDumpMetaInformationFromResult( $result ); |
|
| 60 | + return $this->buildDumpMetaInformationFromResult($result); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | return array(); |
@@ -72,17 +72,17 @@ discard block |
||
| 72 | 72 | * @throws InvalidArgumentException |
| 73 | 73 | * @return DumpMetaInformation[] |
| 74 | 74 | */ |
| 75 | - public function getWithIdentifierProperties( array $identifierPropertyIds ) { |
|
| 76 | - foreach ( $identifierPropertyIds as $propertyId ) { |
|
| 77 | - if ( !( $propertyId instanceof PropertyId ) ) { |
|
| 78 | - throw new InvalidArgumentException( '$identifierProperties must contain only PropertyIds.' ); |
|
| 75 | + public function getWithIdentifierProperties(array $identifierPropertyIds) { |
|
| 76 | + foreach ($identifierPropertyIds as $propertyId) { |
|
| 77 | + if (!($propertyId instanceof PropertyId)) { |
|
| 78 | + throw new InvalidArgumentException('$identifierProperties must contain only PropertyIds.'); |
|
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - if( count( $identifierPropertyIds ) > 0 ) { |
|
| 83 | - $db = wfGetDB( DB_REPLICA ); |
|
| 82 | + if (count($identifierPropertyIds) > 0) { |
|
| 83 | + $db = wfGetDB(DB_REPLICA); |
|
| 84 | 84 | $identifierPropertyIds = array_map( |
| 85 | - function( PropertyId $id ) { |
|
| 85 | + function(PropertyId $id) { |
|
| 86 | 86 | return $id->getSerialization(); |
| 87 | 87 | }, |
| 88 | 88 | $identifierPropertyIds |
@@ -95,13 +95,13 @@ discard block |
||
| 95 | 95 | ) |
| 96 | 96 | ); |
| 97 | 97 | $dumpIds = array(); |
| 98 | - foreach ( $result as $row ) { |
|
| 99 | - if ( !in_array( $row->dump_id, $dumpIds ) ) { |
|
| 98 | + foreach ($result as $row) { |
|
| 99 | + if (!in_array($row->dump_id, $dumpIds)) { |
|
| 100 | 100 | $dumpIds[] = $row->dump_id; |
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - return $this->getWithIds( $dumpIds ); |
|
| 104 | + return $this->getWithIds($dumpIds); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | return array(); |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | * @return DumpMetaInformation[] |
| 115 | 115 | */ |
| 116 | 116 | public function getAll() { |
| 117 | - $db = wfGetDB( DB_REPLICA ); |
|
| 117 | + $db = wfGetDB(DB_REPLICA); |
|
| 118 | 118 | $result = $db->select( |
| 119 | 119 | array( |
| 120 | 120 | self::META_TABLE_NAME, |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | ) |
| 133 | 133 | ); |
| 134 | 134 | |
| 135 | - return $this->buildDumpMetaInformationFromResult( $result ); |
|
| 135 | + return $this->buildDumpMetaInformationFromResult($result); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -140,34 +140,34 @@ discard block |
||
| 140 | 140 | * @return null|array |
| 141 | 141 | * @throws UnexpectedValueException |
| 142 | 142 | */ |
| 143 | - private function buildDumpMetaInformationFromResult( ResultWrapper $result ) { |
|
| 143 | + private function buildDumpMetaInformationFromResult(ResultWrapper $result) { |
|
| 144 | 144 | $aggregatedRows = array(); |
| 145 | - foreach ( $result as $row ) { |
|
| 146 | - if ( array_key_exists( $row->id, $aggregatedRows ) ) { |
|
| 147 | - $propertyId = new PropertyId( $row->identifier_pid ); |
|
| 145 | + foreach ($result as $row) { |
|
| 146 | + if (array_key_exists($row->id, $aggregatedRows)) { |
|
| 147 | + $propertyId = new PropertyId($row->identifier_pid); |
|
| 148 | 148 | $aggregatedRows[$row->id]->identifier_pid[] = $propertyId; |
| 149 | 149 | } else { |
| 150 | - if ( $row->identifier_pid !== null ) { |
|
| 151 | - $propertyId = new PropertyId( $row->identifier_pid ); |
|
| 152 | - $row->identifier_pid = array( $propertyId ); |
|
| 150 | + if ($row->identifier_pid !== null) { |
|
| 151 | + $propertyId = new PropertyId($row->identifier_pid); |
|
| 152 | + $row->identifier_pid = array($propertyId); |
|
| 153 | 153 | } |
| 154 | 154 | $aggregatedRows[$row->id] = $row; |
| 155 | 155 | } |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | $dumpMetaInformation = array(); |
| 159 | - foreach ( $aggregatedRows as $row ) { |
|
| 159 | + foreach ($aggregatedRows as $row) { |
|
| 160 | 160 | $dumpId = $row->id; |
| 161 | - $sourceItemId = new ItemId( $row->source_qid ); |
|
| 162 | - $importDate = wfTimestamp( TS_MW, $row->import_date ); |
|
| 161 | + $sourceItemId = new ItemId($row->source_qid); |
|
| 162 | + $importDate = wfTimestamp(TS_MW, $row->import_date); |
|
| 163 | 163 | $language = $row->language; |
| 164 | 164 | $sourceUrl = $row->source_url; |
| 165 | 165 | $size = (int)$row->size; |
| 166 | - $licenseItemId = new ItemId( $row->license_qid ); |
|
| 166 | + $licenseItemId = new ItemId($row->license_qid); |
|
| 167 | 167 | $identifierPropertyIds = $row->identifier_pid; |
| 168 | 168 | |
| 169 | 169 | $dumpMetaInformation[$row->dump_id] = |
| 170 | - new DumpMetaInformation( $dumpId, |
|
| 170 | + new DumpMetaInformation($dumpId, |
|
| 171 | 171 | $sourceItemId, |
| 172 | 172 | $identifierPropertyIds, |
| 173 | 173 | $importDate, |
@@ -186,22 +186,22 @@ discard block |
||
| 186 | 186 | * |
| 187 | 187 | * @param DumpMetaInformation $dumpMetaInformation |
| 188 | 188 | */ |
| 189 | - public function save( DumpMetaInformation $dumpMetaInformation ) { |
|
| 190 | - $db = wfGetDB( DB_REPLICA ); |
|
| 189 | + public function save(DumpMetaInformation $dumpMetaInformation) { |
|
| 190 | + $db = wfGetDB(DB_REPLICA); |
|
| 191 | 191 | $dumpId = $dumpMetaInformation->getDumpId(); |
| 192 | - $accumulator = $this->getDumpInformationFields( $db, $dumpMetaInformation ); |
|
| 192 | + $accumulator = $this->getDumpInformationFields($db, $dumpMetaInformation); |
|
| 193 | 193 | |
| 194 | 194 | $existing = $db->selectRow( |
| 195 | 195 | self::META_TABLE_NAME, |
| 196 | - array( 'id' ), |
|
| 197 | - array( 'id' => $dumpId ) |
|
| 196 | + array('id'), |
|
| 197 | + array('id' => $dumpId) |
|
| 198 | 198 | ); |
| 199 | 199 | |
| 200 | - if ( $existing ) { |
|
| 200 | + if ($existing) { |
|
| 201 | 201 | $db->update( |
| 202 | 202 | self::META_TABLE_NAME, |
| 203 | 203 | $accumulator, |
| 204 | - array( 'id' => $dumpId ) |
|
| 204 | + array('id' => $dumpId) |
|
| 205 | 205 | ); |
| 206 | 206 | } else { |
| 207 | 207 | $db->insert( |
@@ -212,12 +212,12 @@ discard block |
||
| 212 | 212 | |
| 213 | 213 | $db->delete( |
| 214 | 214 | self::IDENTIFIER_PROPERTIES_TABLE_NAME, |
| 215 | - array( 'dump_id' => $dumpId ) |
|
| 215 | + array('dump_id' => $dumpId) |
|
| 216 | 216 | ); |
| 217 | 217 | $db->insert( |
| 218 | 218 | self::IDENTIFIER_PROPERTIES_TABLE_NAME, |
| 219 | 219 | array_map( |
| 220 | - function ( PropertyId $identifierPropertyId ) use ( $dumpId ) { |
|
| 220 | + function(PropertyId $identifierPropertyId) use ($dumpId) { |
|
| 221 | 221 | return array( |
| 222 | 222 | 'dump_id' => $dumpId, |
| 223 | 223 | 'identifier_pid' => $identifierPropertyId->getSerialization() |
@@ -233,11 +233,11 @@ discard block |
||
| 233 | 233 | * @param DumpMetaInformation $dumpMetaInformation |
| 234 | 234 | * @return array |
| 235 | 235 | */ |
| 236 | - private function getDumpInformationFields( Database $db, DumpMetaInformation $dumpMetaInformation ) { |
|
| 236 | + private function getDumpInformationFields(Database $db, DumpMetaInformation $dumpMetaInformation) { |
|
| 237 | 237 | return array( |
| 238 | 238 | 'id' => $dumpMetaInformation->getDumpId(), |
| 239 | 239 | 'source_qid' => $dumpMetaInformation->getSourceItemId()->getSerialization(), |
| 240 | - 'import_date' => $db->timestamp( $dumpMetaInformation->getImportDate() ), |
|
| 240 | + 'import_date' => $db->timestamp($dumpMetaInformation->getImportDate()), |
|
| 241 | 241 | 'language' => $dumpMetaInformation->getLanguageCode(), |
| 242 | 242 | 'source_url' => $dumpMetaInformation->getSourceUrl(), |
| 243 | 243 | 'size' => $dumpMetaInformation->getSize(), |