From 1377b3972d1b8ea683190b52149f7d356524c9b3 Mon Sep 17 00:00:00 2001 From: Osma Suominen Date: Wed, 27 Sep 2023 11:32:47 +0300 Subject: [PATCH 1/2] reformat query to make it more readable --- model/sparql/GenericSparql.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/model/sparql/GenericSparql.php b/model/sparql/GenericSparql.php index 2d82bb404..1745821bd 100644 --- a/model/sparql/GenericSparql.php +++ b/model/sparql/GenericSparql.php @@ -2262,13 +2262,17 @@ private function generateChangeListQuery($prop, $lang, $offset, $limit=200, $sho $deprecatedVars = ''; if ($showDeprecated) { $deprecatedVars = '?replacedBy ?deprecated ?replacingLabel'; - $deprecatedOptions = - 'UNION {'. - '?concept dc:isReplacedBy ?replacedBy ; dc:modified ?date2 .'. - 'BIND(COALESCE(?date2, ?date) AS ?date)'. - 'OPTIONAL { ?replacedBy skos:prefLabel ?replacingLabel .'. - 'FILTER (langMatches(lang(?replacingLabel), \''.$lang.'\')) }}'. - 'OPTIONAL { ?concept owl:deprecated ?deprecated . }'; + $deprecatedOptions = << Date: Wed, 27 Sep 2023 12:50:37 +0300 Subject: [PATCH 2/2] show deprecated concepts in change list even if they have no isReplacedBy relationship --- model/sparql/GenericSparql.php | 16 ++++++++++++---- tests/GenericSparqlTest.php | 9 +++++++-- tests/RestControllerTest.php | 6 ++++++ tests/VocabularyTest.php | 4 ++-- tests/WebControllerTest.php | 2 +- tests/test-vocab-data/changes.ttl | 6 ++++++ view/changes.twig | 2 +- 7 files changed, 35 insertions(+), 10 deletions(-) diff --git a/model/sparql/GenericSparql.php b/model/sparql/GenericSparql.php index 1745821bd..fb705686b 100644 --- a/model/sparql/GenericSparql.php +++ b/model/sparql/GenericSparql.php @@ -2264,14 +2264,17 @@ private function generateChangeListQuery($prop, $lang, $offset, $limit=200, $sho $deprecatedVars = '?replacedBy ?deprecated ?replacingLabel'; $deprecatedOptions = <<deprecated)) { + $concept['deprecated'] = $row->deprecated->getValue(); + } else { + $concept['deprecated'] = false; + } if (isset($row->replacedBy)) { $concept['replacedBy'] = $row->replacedBy->getURI(); } diff --git a/tests/GenericSparqlTest.php b/tests/GenericSparqlTest.php index dae9b5881..54718d7ae 100644 --- a/tests/GenericSparqlTest.php +++ b/tests/GenericSparqlTest.php @@ -1151,8 +1151,13 @@ public function testQueryCreatedListWithDeprecated() foreach($actual as $concept) { array_push($order, $concept['prefLabel']); } - $this->assertEquals(4, sizeof($actual)); - $this->assertEquals(array('Fourth date', 'Hurr Durr', 'Second date', 'A date'), $order); + $this->assertEquals(5, sizeof($actual)); + $this->assertEquals(array('No replacement', 'Fourth date', 'Hurr Durr', 'Second date', 'A date'), $order); + + // check that deprecated status is correct + $this->assertTrue($actual[0]['deprecated']); // 'No replacement' + $this->assertTrue($actual[1]['deprecated']); // 'Fourth date' + $this->assertFalse($actual[2]['deprecated']); // 'Hurr Durr' } diff --git a/tests/RestControllerTest.php b/tests/RestControllerTest.php index 8b90c3dff..73c941b5a 100644 --- a/tests/RestControllerTest.php +++ b/tests/RestControllerTest.php @@ -780,6 +780,11 @@ public function testNewConcepts() { }, "changeList": [ { + "uri": "http://www.skosmos.skos/changes/d5", + "prefLabel": "No replacement", + "date": "2021-02-04T12:46:33+0000" + }, + { "uri": "http://www.skosmos.skos/changes/d4", "prefLabel": "Fourth date", "date": "2021-01-03T12:46:33+0000", @@ -867,6 +872,7 @@ public function testDeprecatedChanges() { "date": { "@id":"http://purl.org/dc/terms/date","@type":"http://www.w3.org/2001/XMLSchema#dateTime" } }, "changeList": [ + { "date": "2021-02-04T12:46:33+0000", "prefLabel": "No replacement", "uri": "http://www.skosmos.skos/changes/d5" }, { "date": "2021-01-03T12:46:30+0000", "prefLabel": "A date", "uri": "http://www.skosmos.skos/changes/d1" }, { "date": "2021-01-03T12:46:33+0000", "prefLabel": "Fourth date", "replacedBy": "http://www.skosmos.skos/changes/d3", "replacingLabel": "Hurr Durr", "uri": "http://www.skosmos.skos/changes/d4" }, { "date": "2021-01-03T12:46:32+0000", "prefLabel": "Hurr Durr", "uri": "http://www.skosmos.skos/changes/d3" }, diff --git a/tests/VocabularyTest.php b/tests/VocabularyTest.php index e6ac028cb..9a1b2ffb5 100644 --- a/tests/VocabularyTest.php +++ b/tests/VocabularyTest.php @@ -438,8 +438,8 @@ public function testGetTopConcepts() { public function testGetChangeList() { $vocab = $this->model->getVocabulary('changes'); $changeList = $vocab->getChangeList('dc:created','en', 0, 5); - $expected = array ('uri' => 'http://www.skosmos.skos/changes/d3', 'prefLabel' => 'Hurr Durr', 'date' => DateTime::__set_state(array('date' => '2010-02-12 10:26:39.000000', 'timezone_type' => 3, 'timezone' => 'UTC'))); - $this->assertEquals($expected, $changeList[1]); + $expected = array ('uri' => 'http://www.skosmos.skos/changes/d3', 'prefLabel' => 'Hurr Durr', 'date' => DateTime::__set_state(array('date' => '2010-02-12 10:26:39.000000', 'timezone_type' => 3, 'timezone' => 'UTC')), 'deprecated' => false); + $this->assertEquals($expected, $changeList[2]); } /** diff --git a/tests/WebControllerTest.php b/tests/WebControllerTest.php index ae38bd087..5fe1e4fb4 100644 --- a/tests/WebControllerTest.php +++ b/tests/WebControllerTest.php @@ -223,7 +223,7 @@ public function testFormatChangeList() { $changeList = $this->webController->getChangeList($request, 'dc:created'); $months =$this->webController->formatChangeList($changeList, 'en'); - $expected = array ('hurr durr' => array ('uri' => 'http://www.skosmos.skos/changes/d3', 'prefLabel' => 'Hurr Durr', 'date' => DateTime::__set_state(array('date' => '2010-02-12 10:26:39.000000', 'timezone_type' => 3, 'timezone' => 'UTC')), 'datestring' => 'Feb 12, 2010'), 'second date' => array ('uri' => 'http://www.skosmos.skos/changes/d2', 'prefLabel' => 'Second date', 'date' => DateTime::__set_state(array('date' => '2010-02-12 15:26:39.000000', 'timezone_type' => 3, 'timezone' => 'UTC')), 'datestring' => 'Feb 12, 2010')); + $expected = array ('hurr durr' => array ('uri' => 'http://www.skosmos.skos/changes/d3', 'prefLabel' => 'Hurr Durr', 'date' => DateTime::__set_state(array('date' => '2010-02-12 10:26:39.000000', 'timezone_type' => 3, 'timezone' => 'UTC')), 'datestring' => 'Feb 12, 2010', 'deprecated' => false), 'second date' => array ('uri' => 'http://www.skosmos.skos/changes/d2', 'prefLabel' => 'Second date', 'date' => DateTime::__set_state(array('date' => '2010-02-12 15:26:39.000000', 'timezone_type' => 3, 'timezone' => 'UTC')), 'datestring' => 'Feb 12, 2010', 'deprecated' => false)); $this->assertEquals($expected, $months['February 2010']); } diff --git a/tests/test-vocab-data/changes.ttl b/tests/test-vocab-data/changes.ttl index c98542686..ac1f4666f 100644 --- a/tests/test-vocab-data/changes.ttl +++ b/tests/test-vocab-data/changes.ttl @@ -30,3 +30,9 @@ changes:d4 a skos:Concept ; dc:created "2011-12-12T09:26:39"^^xsd:dateTime ; dc:modified "2021-01-03T12:46:33"^^xsd:dateTime ; skos:prefLabel "Fourth date"@en . + +changes:d5 a skos:Concept ; + owl:deprecated true ; + dc:created "2012-12-12T09:26:39"^^xsd:dateTime ; + dc:modified "2021-02-04T12:46:33"^^xsd:dateTime ; + skos:prefLabel "No replacement"@en . diff --git a/view/changes.twig b/view/changes.twig index 722b95ccc..ade8cf1cc 100644 --- a/view/changes.twig +++ b/view/changes.twig @@ -42,7 +42,7 @@
{{day}}
{% for concept in concepts %}
  • - {% if concept.replacedBy is defined %} + {% if concept.deprecated %} {{ concept.prefLabel }} {% else %} {{ concept.prefLabel }}