Skip to content

Commit 4081ffa

Browse files
authored
Merge pull request #6128 from 3liz/backport-6113-to-release_3_10
[Backport release_3_10] Provide default values for *very* old qgs files with missing attributes
2 parents e3a3e52 + b1bf474 commit 4081ffa

File tree

4 files changed

+2575
-10
lines changed

4 files changed

+2575
-10
lines changed

lizmap/modules/lizmap/lib/Project/Qgis/ProjectInfo.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
* @property string $version
2323
* @property string $projectname
2424
* @property string $title
25-
* @property null|string $saveDateTime
26-
* @property null|string $saveUser
27-
* @property null|string $saveUserFull
25+
* @property string $saveDateTime
26+
* @property string $saveUser
27+
* @property string $saveUserFull
2828
* @property SpatialRefSys $projectCrs
2929
* @property ProjectProperties $properties
3030
* @property LayerTreeRoot $layerTreeRoot
@@ -456,11 +456,11 @@ public function getLayoutsAsKeyArray()
456456
protected static function getAttributes($oXmlReader)
457457
{
458458
return array(
459-
'version' => $oXmlReader->getAttribute('version'),
460-
'projectname' => $oXmlReader->getAttribute('projectname'),
461-
'saveDateTime' => $oXmlReader->getAttribute('saveDateTime'),
462-
'saveUser' => $oXmlReader->getAttribute('saveUser'),
463-
'saveUserFull' => $oXmlReader->getAttribute('saveUserFull'),
459+
'version' => $oXmlReader->getAttribute('version') ?? '',
460+
'projectname' => $oXmlReader->getAttribute('projectname') ?? '',
461+
'saveDateTime' => $oXmlReader->getAttribute('saveDateTime') ?? '',
462+
'saveUser' => $oXmlReader->getAttribute('saveUser') ?? '',
463+
'saveUserFull' => $oXmlReader->getAttribute('saveUserFull') ?? '',
464464
);
465465
}
466466

lizmap/modules/lizmap/lib/Project/QgisProject.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,8 +1190,8 @@ protected function readXmlProject($qgs_path)
11901190
$this->allProj4 = $project->getProjAsKeyArray();
11911191
$this->themes = $project->getVisibilityPresetsAsKeyArray();
11921192
$this->customProjectVariables = $project->properties->Variables !== null ? $project->properties->Variables->getVariablesAsKeyArray() : array();
1193-
$this->useLayerIDs = $project->properties->WMSUseLayerIDs !== null ? $project->properties->WMSUseLayerIDs : false;
1194-
$this->wfsLayerIds = $project->properties->WFSLayers !== null ? $project->properties->WFSLayers : array();
1193+
$this->useLayerIDs = $project->properties->WMSUseLayerIDs ?? false;
1194+
$this->wfsLayerIds = $project->properties->WFSLayers ?? array();
11951195
$this->layers = $project->getLayersAsKeyArray();
11961196
$this->relations = $project->getRelationsAsKeyArray();
11971197
$this->relationsFields = $project->getRelationFieldsAsKeyArray();

tests/units/classes/Project/Qgis/ProjectInfoTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,23 @@ public function testJsonEncode(): void
262262
$this->assertNotNull($json);
263263
$this->assertStringStartsWith('{"version":', $json);
264264
}
265+
266+
public function testProjetWithMissingProjetInfo(): void
267+
{
268+
$xml_path_invalid = __DIR__.'/../../Project/Ressources/project_empty_qgis_tag.qgs';
269+
270+
$oXml = App\XmlTools::xmlReaderFromFile($xml_path_invalid);
271+
$project = Qgis\ProjectInfo::fromXmlReader($oXml);
272+
// missing values on XML will be empty string
273+
$emptyProps = array(
274+
'version',
275+
'projectname',
276+
'saveDateTime',
277+
'saveUser',
278+
'saveUserFull',
279+
);
280+
foreach ($emptyProps as $prop ) {
281+
$this->assertEmpty($project->{$prop});
282+
}
283+
}
265284
}

0 commit comments

Comments
 (0)