jenkins-bot has submitted this change and it was merged.

Change subject: Parse standard date formats with wfTimestamp()
......................................................................


Parse standard date formats with wfTimestamp()

Attempt to use wfTimestamp() in DateCollector to normalize DateTime and
DateTimeOriginal from the metadata. Add a new test for the normalization.

Also update a test that was slightly out of date.

Bug: T66014
Change-Id: I1bf9581a527c6033213c095a667e92d13c673c6e
---
M DataCollector.php
M tests/data/File_Dala_Kyrka.JPG.php
M tests/html/File_Dala_Kyrka.JPG.html
M tests/phpunit/DataCollectorTest.php
4 files changed, 30 insertions(+), 2 deletions(-)

Approvals:
  Gergő Tisza: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/DataCollector.php b/DataCollector.php
index 00daa90..b81c111 100644
--- a/DataCollector.php
+++ b/DataCollector.php
@@ -89,6 +89,8 @@
         * @param File $file
         */
        public function collect( array &$previousMetadata, File $file ) {
+               $this->normalizeMetadataTimestamps( $previousMetadata );
+
                $descriptionText = $this->getDescriptionText( $file, 
$this->language );
 
                $categories = $this->getCategories( $file, $previousMetadata );
@@ -398,4 +400,20 @@
                }
                return $deletions[0];
        }
+
+       /**
+        * Normalizes the metadata to wfTimestamp()'s TS_DB format
+        * @param array $metadata
+        */
+       protected function normalizeMetadataTimestamps( array &$metadata ) {
+               $fieldsToNormalize = array( 'DateTime', 'DateTimeOriginal' );
+               foreach( $fieldsToNormalize as $field ) {
+                       if ( isset( $metadata[$field] ) && isset( 
$metadata[$field]['value'] ) ) {
+                               $parsedTs = wfTimestamp( TS_DB, 
$metadata[$field]['value'] );
+                               if ( $parsedTs ) {
+                                       $metadata[$field]['value'] = $parsedTs;
+                               }
+                       }
+               }
+       }
 }
diff --git a/tests/data/File_Dala_Kyrka.JPG.php 
b/tests/data/File_Dala_Kyrka.JPG.php
index a69dac2..5dcd704 100644
--- a/tests/data/File_Dala_Kyrka.JPG.php
+++ b/tests/data/File_Dala_Kyrka.JPG.php
@@ -7,7 +7,7 @@
 return array (
        'DateTimeOriginal' =>
                array (
-                       'value' => '2013-10-27',
+                       'value' => '2013-10-27 10:27:44',
                        'source' => 'commons-desc-page',
                ),
        'License' =>
diff --git a/tests/html/File_Dala_Kyrka.JPG.html 
b/tests/html/File_Dala_Kyrka.JPG.html
index 706476d..db3bb8d 100644
--- a/tests/html/File_Dala_Kyrka.JPG.html
+++ b/tests/html/File_Dala_Kyrka.JPG.html
@@ -9,7 +9,7 @@
 </tr>
 <tr style="vertical-align: top">
 <td id="fileinfotpl_date" class="fileinfo-paramfield">Date</td>
-<td><time class="dtstart" datetime="2013-10-27">27 October 2013</time>, 
10:27:44</td>
+<td><time class="dtstart" datetime="2013-10-27 10:27:44">27 October 2013, 
10:27:44</time></td>
 </tr>
 <tr style="vertical-align: top">
 <td id="fileinfotpl_src" class="fileinfo-paramfield">Source</td>
diff --git a/tests/phpunit/DataCollectorTest.php 
b/tests/phpunit/DataCollectorTest.php
index 37dffd5..e7cc411 100644
--- a/tests/phpunit/DataCollectorTest.php
+++ b/tests/phpunit/DataCollectorTest.php
@@ -116,6 +116,16 @@
                $this->assertMetadataValue( 'UsageTerms', 'foo', $metadata );
        }
 
+       public function testMetadataTimestampNormalization() {
+               $metadata = array( 'DateTime' => array( 'value' => '2014:12:08 
16:04:26' ),
+                       'DateTimeOriginal' => array( 'value' => '2014:12:08 
16:04:26' ) );
+
+               $this->dataCollector->collect( $metadata, $this->file );
+
+               $this->assertMetadataValue( 'DateTime', '2014-12-08 16:04:26', 
$metadata );
+               $this->assertMetadataValue( 'DateTimeOriginal', '2014-12-08 
16:04:26', $metadata );
+       }
+
        /*------------------------------- Logic tests 
--------------------------*/
 
        public function testGetCategoryMetadata() {

-- 
To view, visit https://gerrit.wikimedia.org/r/182061
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I1bf9581a527c6033213c095a667e92d13c673c6e
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/CommonsMetadata
Gerrit-Branch: master
Gerrit-Owner: Unicodesnowman <[email protected]>
Gerrit-Reviewer: GergÅ‘ Tisza <[email protected]>
Gerrit-Reviewer: Unicodesnowman <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to