@@ -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 %d', $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 %d', $table, $condition, $batchSize)); |
|
| 135 | + } while ($db->affectedRows() > 0); |
|
| 136 | 136 | } |
| 137 | 137 | } |
| 138 | 138 | |