@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * |
| 19 | 19 | * @return bool |
| 20 | 20 | */ |
| 21 | - public function canCompare( DataValue $value, DataValue $comparativeValue ); |
|
| 21 | + public function canCompare(DataValue $value, DataValue $comparativeValue); |
|
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | 24 | * Runs the comparison of two DataValues. |
@@ -28,6 +28,6 @@ discard block |
||
| 28 | 28 | * |
| 29 | 29 | * @return string One of the ComparisonResult::STATUS_... constants. |
| 30 | 30 | */ |
| 31 | - public function compare( DataValue $value, DataValue $comparativeValue ); |
|
| 31 | + public function compare(DataValue $value, DataValue $comparativeValue); |
|
| 32 | 32 | |
| 33 | 33 | } |
@@ -23,9 +23,9 @@ discard block |
||
| 23 | 23 | * @throws InvalidArgumentException |
| 24 | 24 | * @return string One of the ComparisonResult::STATUS_... constants. |
| 25 | 25 | */ |
| 26 | - public function compare( DataValue $value, DataValue $comparativeValue ) { |
|
| 27 | - if ( !$this->canCompare( $value, $comparativeValue ) ) { |
|
| 28 | - throw new InvalidArgumentException( 'Given values can not be compared using this comparer.' ); |
|
| 26 | + public function compare(DataValue $value, DataValue $comparativeValue) { |
|
| 27 | + if (!$this->canCompare($value, $comparativeValue)) { |
|
| 28 | + throw new InvalidArgumentException('Given values can not be compared using this comparer.'); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
@@ -39,14 +39,14 @@ discard block |
||
| 39 | 39 | $extLat = $comparativeValue->getLatitude(); |
| 40 | 40 | $extLong = $comparativeValue->getLongitude(); |
| 41 | 41 | |
| 42 | - $diffLat = abs( $locLat - $extLat ); |
|
| 43 | - $diffLong = abs( $locLong - $extLong ); |
|
| 44 | - if ( ( $diffLat <= $precision ) && ( $diffLong <= $precision ) ) { |
|
| 42 | + $diffLat = abs($locLat - $extLat); |
|
| 43 | + $diffLong = abs($locLong - $extLong); |
|
| 44 | + if (($diffLat <= $precision) && ($diffLong <= $precision)) { |
|
| 45 | 45 | return ComparisonResult::STATUS_MATCH; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | $daumen = $precision; |
| 49 | - if ( ( $diffLat <= pi() * $daumen ) && ( $diffLong <= pi() * $daumen ) ) { |
|
| 49 | + if (($diffLat <= pi() * $daumen) && ($diffLong <= pi() * $daumen)) { |
|
| 50 | 50 | return ComparisonResult::STATUS_PARTIAL_MATCH; |
| 51 | 51 | } |
| 52 | 52 | |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * @param DataValue $comparativeValue |
| 61 | 61 | * @return bool |
| 62 | 62 | */ |
| 63 | - public function canCompare( DataValue $value, DataValue $comparativeValue ) { |
|
| 63 | + public function canCompare(DataValue $value, DataValue $comparativeValue) { |
|
| 64 | 64 | return $value instanceof GlobeCoordinateValue && $comparativeValue instanceof GlobeCoordinateValue; |
| 65 | 65 | } |
| 66 | 66 | |
@@ -15,6 +15,6 @@ |
||
| 15 | 15 | * |
| 16 | 16 | * @param DumpMetaInformation $dumpMetaInformation |
| 17 | 17 | */ |
| 18 | - public function save( DumpMetaInformation $dumpMetaInformation ); |
|
| 18 | + public function save(DumpMetaInformation $dumpMetaInformation); |
|
| 19 | 19 | |
| 20 | 20 | } |
@@ -20,8 +20,8 @@ discard block |
||
| 20 | 20 | * @param array &$arr |
| 21 | 21 | * @param string $tag |
| 22 | 22 | */ |
| 23 | - protected function setIndexedTagName( array &$arr, $tag ) { |
|
| 24 | - ApiResult::setIndexedTagName( $arr, $tag ); |
|
| 23 | + protected function setIndexedTagName(array &$arr, $tag) { |
|
| 24 | + ApiResult::setIndexedTagName($arr, $tag); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | /** |
@@ -33,9 +33,9 @@ discard block |
||
| 33 | 33 | * @param string $tagName |
| 34 | 34 | * @param string $idAttribute |
| 35 | 35 | */ |
| 36 | - protected function setKeyAttributeName( array &$arr, $tagName, $idAttribute ) { |
|
| 37 | - ApiResult::setArrayType( $arr, 'kvp', $idAttribute ); |
|
| 38 | - ApiResult::setIndexedTagName( $arr, $tagName ); |
|
| 36 | + protected function setKeyAttributeName(array &$arr, $tagName, $idAttribute) { |
|
| 37 | + ApiResult::setArrayType($arr, 'kvp', $idAttribute); |
|
| 38 | + ApiResult::setIndexedTagName($arr, $tagName); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | } |
@@ -43,11 +43,11 @@ |
||
| 43 | 43 | * @param int $batchSize |
| 44 | 44 | * @param bool $quiet |
| 45 | 45 | */ |
| 46 | - public function __construct( $externalValuesFilePath, $dumpInformationFilePath, $batchSize, $quiet = false ) { |
|
| 47 | - Assert::parameterType( 'string', $externalValuesFilePath, '$externalValuesFilePath' ); |
|
| 48 | - Assert::parameterType( 'string', $dumpInformationFilePath, '$dumpInformationFilePath' ); |
|
| 49 | - Assert::parameterType( 'integer', $batchSize, '$batchSize' ); |
|
| 50 | - Assert::parameterType( 'boolean', $quiet, '$quiet' ); |
|
| 46 | + public function __construct($externalValuesFilePath, $dumpInformationFilePath, $batchSize, $quiet = false) { |
|
| 47 | + Assert::parameterType('string', $externalValuesFilePath, '$externalValuesFilePath'); |
|
| 48 | + Assert::parameterType('string', $dumpInformationFilePath, '$dumpInformationFilePath'); |
|
| 49 | + Assert::parameterType('integer', $batchSize, '$batchSize'); |
|
| 50 | + Assert::parameterType('boolean', $quiet, '$quiet'); |
|
| 51 | 51 | |
| 52 | 52 | $this->externalValuesFilePath = $externalValuesFilePath; |
| 53 | 53 | $this->dumpInformationFilePath = $dumpInformationFilePath; |
@@ -7,16 +7,16 @@ |
||
| 7 | 7 | * |
| 8 | 8 | * @return bool |
| 9 | 9 | */ |
| 10 | - public static function onCreateSchema( DatabaseUpdater $updater ) { |
|
| 11 | - $updater->addExtensionTable( 'wbqev_dump_information', __DIR__ . '/sql/create_wbqev_dump_information.sql' ); |
|
| 12 | - $updater->addExtensionTable( 'wbqev_external_data', __DIR__ . '/sql/create_wbqev_external_data.sql' ); |
|
| 13 | - $updater->addExtensionTable( 'wbqev_identifier_properties', __DIR__ . '/sql/create_wbqev_identifier_properties.sql' ); |
|
| 10 | + public static function onCreateSchema(DatabaseUpdater $updater) { |
|
| 11 | + $updater->addExtensionTable('wbqev_dump_information', __DIR__.'/sql/create_wbqev_dump_information.sql'); |
|
| 12 | + $updater->addExtensionTable('wbqev_external_data', __DIR__.'/sql/create_wbqev_external_data.sql'); |
|
| 13 | + $updater->addExtensionTable('wbqev_identifier_properties', __DIR__.'/sql/create_wbqev_identifier_properties.sql'); |
|
| 14 | 14 | |
| 15 | 15 | return true; |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | - public static function onUnitTestsList( &$paths ) { |
|
| 19 | - $paths[] = __DIR__ . '/tests/phpunit'; |
|
| 18 | + public static function onUnitTestsList(&$paths) { |
|
| 19 | + $paths[] = __DIR__.'/tests/phpunit'; |
|
| 20 | 20 | return true; |
| 21 | 21 | } |
| 22 | 22 | |
@@ -30,9 +30,9 @@ discard block |
||
| 30 | 30 | * @throws InvalidArgumentException |
| 31 | 31 | * @return string One of the ComparisonResult::STATUS_... constants. |
| 32 | 32 | */ |
| 33 | - public function compare( DataValue $value, DataValue $comparativeValue ) { |
|
| 34 | - if ( !$this->canCompare( $value, $comparativeValue ) ) { |
|
| 35 | - throw new InvalidArgumentException( 'Given values can not be compared using this comparer.' ); |
|
| 33 | + public function compare(DataValue $value, DataValue $comparativeValue) { |
|
| 34 | + if (!$this->canCompare($value, $comparativeValue)) { |
|
| 35 | + throw new InvalidArgumentException('Given values can not be compared using this comparer.'); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | /** |
@@ -42,38 +42,38 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | $result = ComparisonResult::STATUS_MISMATCH; |
| 44 | 44 | |
| 45 | - if ( !preg_match( '/^([-+]?)(\d*)((\d{4}\b).*)/', $value->getTime(), $localMatches ) |
|
| 46 | - || !preg_match( '/^([-+]?)(\d*)((\d{4}\b).*)/', $comparativeValue->getTime(), $externalMatches ) |
|
| 45 | + if (!preg_match('/^([-+]?)(\d*)((\d{4}\b).*)/', $value->getTime(), $localMatches) |
|
| 46 | + || !preg_match('/^([-+]?)(\d*)((\d{4}\b).*)/', $comparativeValue->getTime(), $externalMatches) |
|
| 47 | 47 | ) { |
| 48 | 48 | return ComparisonResult::STATUS_MISMATCH; |
| 49 | 49 | } |
| 50 | - list( , $localSign, $localYearHigh, $localMwTime, $localYearLow ) = $localMatches; |
|
| 51 | - list( , $externalSign, $externalYearHigh, $externalMwTime, $externalYearLow ) = $externalMatches; |
|
| 52 | - if ( $localSign !== $externalSign && ( $localYearHigh . $localYearLow !== '0000' |
|
| 53 | - || $externalYearHigh . $externalYearLow !== '0000' ) |
|
| 50 | + list(, $localSign, $localYearHigh, $localMwTime, $localYearLow) = $localMatches; |
|
| 51 | + list(, $externalSign, $externalYearHigh, $externalMwTime, $externalYearLow) = $externalMatches; |
|
| 52 | + if ($localSign !== $externalSign && ($localYearHigh.$localYearLow !== '0000' |
|
| 53 | + || $externalYearHigh.$externalYearLow !== '0000') |
|
| 54 | 54 | ) { |
| 55 | 55 | return ComparisonResult::STATUS_MISMATCH; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | try { |
| 59 | - $localTimestamp = new MWTimestamp( $localMwTime ); |
|
| 60 | - $externalTimestamp = new MWTimestamp( $externalMwTime ); |
|
| 61 | - $diff = $localTimestamp->diff( $externalTimestamp ); |
|
| 62 | - $diff->y += abs( $localYearHigh - $externalYearHigh ) * 10000; |
|
| 59 | + $localTimestamp = new MWTimestamp($localMwTime); |
|
| 60 | + $externalTimestamp = new MWTimestamp($externalMwTime); |
|
| 61 | + $diff = $localTimestamp->diff($externalTimestamp); |
|
| 62 | + $diff->y += abs($localYearHigh - $externalYearHigh) * 10000; |
|
| 63 | 63 | |
| 64 | - if ( $value->getPrecision() === $comparativeValue->getPrecision() |
|
| 65 | - && $this->resultOfDiffWithPrecision( $diff, $value->getPrecision() ) |
|
| 64 | + if ($value->getPrecision() === $comparativeValue->getPrecision() |
|
| 65 | + && $this->resultOfDiffWithPrecision($diff, $value->getPrecision()) |
|
| 66 | 66 | ) { |
| 67 | 67 | $result = ComparisonResult::STATUS_MATCH; |
| 68 | 68 | } elseif ( |
| 69 | 69 | $this->resultOfDiffWithPrecision( |
| 70 | 70 | $diff, |
| 71 | - min( $value->getPrecision(), $comparativeValue->getPrecision() ) |
|
| 71 | + min($value->getPrecision(), $comparativeValue->getPrecision()) |
|
| 72 | 72 | ) |
| 73 | 73 | ) { |
| 74 | 74 | $result = ComparisonResult::STATUS_PARTIAL_MATCH; |
| 75 | 75 | } |
| 76 | - } catch ( TimestampException $ex ) { |
|
| 76 | + } catch (TimestampException $ex) { |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | return $result; |
@@ -87,10 +87,10 @@ discard block |
||
| 87 | 87 | * |
| 88 | 88 | * @return bool |
| 89 | 89 | */ |
| 90 | - private function resultOfDiffWithPrecision( DateInterval $diff, $precision ) { |
|
| 90 | + private function resultOfDiffWithPrecision(DateInterval $diff, $precision) { |
|
| 91 | 91 | $result = true; |
| 92 | 92 | |
| 93 | - switch ( $precision ) { |
|
| 93 | + switch ($precision) { |
|
| 94 | 94 | case TimeValue::PRECISION_SECOND: |
| 95 | 95 | $result = $diff->s === 0; |
| 96 | 96 | // Fall through with no break/return. This is critical for this algorithm. |
@@ -134,10 +134,10 @@ discard block |
||
| 134 | 134 | * |
| 135 | 135 | * @return ValueParser |
| 136 | 136 | */ |
| 137 | - protected function getExternalValueParser( DumpMetaInformation $dumpMetaInformation ) { |
|
| 137 | + protected function getExternalValueParser(DumpMetaInformation $dumpMetaInformation) { |
|
| 138 | 138 | $parserOptions = new ParserOptions(); |
| 139 | - $parserOptions->setOption( ValueParser::OPT_LANG, $dumpMetaInformation->getLanguageCode() ); |
|
| 140 | - $timeParserFactory = new TimeParserFactory( $parserOptions ); |
|
| 139 | + $parserOptions->setOption(ValueParser::OPT_LANG, $dumpMetaInformation->getLanguageCode()); |
|
| 140 | + $timeParserFactory = new TimeParserFactory($parserOptions); |
|
| 141 | 141 | |
| 142 | 142 | return $timeParserFactory->getTimeParser(); |
| 143 | 143 | } |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | * |
| 151 | 151 | * @return bool |
| 152 | 152 | */ |
| 153 | - public function canCompare( DataValue $value, DataValue $comparativeValue ) { |
|
| 153 | + public function canCompare(DataValue $value, DataValue $comparativeValue) { |
|
| 154 | 154 | return $value instanceof TimeValue && $comparativeValue instanceof TimeValue; |
| 155 | 155 | } |
| 156 | 156 | |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * @return DumpMetaInformation[] |
| 21 | 21 | * @throws \InvalidArgumentException |
| 22 | 22 | */ |
| 23 | - public function getWithIds( array $dumpIds ); |
|
| 23 | + public function getWithIds(array $dumpIds); |
|
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * Gets DumpMetaInformation for specific identifier properties from database |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * |
| 31 | 31 | * @return DumpMetaInformation[] |
| 32 | 32 | */ |
| 33 | - public function getWithIdentifierProperties( array $identifierPropertyIds ); |
|
| 33 | + public function getWithIdentifierProperties(array $identifierPropertyIds); |
|
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | 36 | * Gets all DumpMetaInformation from database |
@@ -7,10 +7,10 @@ discard block |
||
| 7 | 7 | use WikibaseQuality\ExternalValidation\UpdateExternalData\CsvImportSettings; |
| 8 | 8 | use WikibaseQuality\ExternalValidation\UpdateExternalData\ExternalDataImporter; |
| 9 | 9 | |
| 10 | -$basePath = getenv( 'MW_INSTALL_PATH' ) !== false |
|
| 11 | - ? getenv( 'MW_INSTALL_PATH' ) |
|
| 12 | - : __DIR__ . '/../../..'; |
|
| 13 | -require_once $basePath . '/maintenance/Maintenance.php'; |
|
| 10 | +$basePath = getenv('MW_INSTALL_PATH') !== false |
|
| 11 | + ? getenv('MW_INSTALL_PATH') |
|
| 12 | + : __DIR__.'/../../..'; |
|
| 13 | +require_once $basePath.'/maintenance/Maintenance.php'; |
|
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | 16 | * Maintenance script that evokes updates of wbqev_external_data, wbqev_dump_information, wbqev_identifier_properties |
@@ -25,17 +25,17 @@ discard block |
||
| 25 | 25 | public function __construct() { |
| 26 | 26 | parent::__construct(); |
| 27 | 27 | |
| 28 | - $this->addDescription( 'Imports external entities from given CSV files into the local ' |
|
| 29 | - . 'database. CSV files can be generated using the DumpConverter.' ); |
|
| 30 | - $this->addOption( 'external-values-file', 'CSV file containing external values for import.', true, true ); |
|
| 31 | - $this->addOption( 'dump-information-file', 'CSV file containing dump meta information for import.', true, true ); |
|
| 32 | - $this->setBatchSize( 1000 ); |
|
| 28 | + $this->addDescription('Imports external entities from given CSV files into the local ' |
|
| 29 | + . 'database. CSV files can be generated using the DumpConverter.'); |
|
| 30 | + $this->addOption('external-values-file', 'CSV file containing external values for import.', true, true); |
|
| 31 | + $this->addOption('dump-information-file', 'CSV file containing dump meta information for import.', true, true); |
|
| 32 | + $this->setBatchSize(1000); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | public function execute() { |
| 36 | 36 | $context = new CsvImportSettings( |
| 37 | - $this->getOption( 'external-values-file' ), |
|
| 38 | - $this->getOption( 'dump-information-file' ), |
|
| 37 | + $this->getOption('external-values-file'), |
|
| 38 | + $this->getOption('dump-information-file'), |
|
| 39 | 39 | $this->mBatchSize, |
| 40 | 40 | $this->isQuiet() |
| 41 | 41 | ); |