Skip to content

Commit

Permalink
Update xml files with the version bump (#89)
Browse files Browse the repository at this point in the history
* Update xml files with the version bump if

Only if root xml element name extension

* jorobo.ini needs xml file extension in header for version update and simplexml

* cs
  • Loading branch information
HLeithner authored Aug 24, 2024
1 parent dced72c commit 0c3a8aa
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 10 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

"require" : {
"php": ">=7.2.5|~8",
"ext-simplexml": "*",
"consolidation/robo": "~3",
"joomla/github": "~2|~3"
},
Expand Down
2 changes: 1 addition & 1 deletion jorobo.dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ target = /

; Adds / replaces copyright headers at the beginning of files
[header]
files = php,js
files = php,js,xml
exclude =
text = "
/**
Expand Down
2 changes: 1 addition & 1 deletion jorobo.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ssl = false
target = /

[header]
files = php,js
files = php,js,xml
exclude =
text = "
/**
Expand Down
55 changes: 47 additions & 8 deletions src/Tasks/BumpVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,59 @@ public function run()
}
}

// Load the file
$fileContents = file_get_contents($file->getRealPath());

if (preg_match('#__DEPLOY_VERSION__#', $fileContents)) {
$fileContents = preg_replace('#__DEPLOY_VERSION__#', $this->getJConfig()->version, $fileContents);

$this->printTaskInfo('Updating file: ' . $file->getRealPath());
if ($file->getExtension() === 'xml') {
if ($this->updateXML($file)) {
$changedFiles++;
}

file_put_contents($file->getRealPath(), $fileContents);
continue;
}

if ($this->updatePlain($file)) {
$changedFiles++;
}
}

return Result::success($this, 'Updated ' . $changedFiles . ' files');
}

protected function updatePlain($file): bool
{
$fileContents = file_get_contents($file->getRealPath());

if (preg_match('#__DEPLOY_VERSION__#', $fileContents)) {
$fileContents = preg_replace('#__DEPLOY_VERSION__#', $this->getJConfig()->version, $fileContents);

$this->printTaskInfo('Updating file: ' . $file->getRealPath());

file_put_contents($file->getRealPath(), $fileContents);

return true;
}

return false;
}

protected function updateXML($file): bool
{
$xml = simplexml_load_file($file->getRealPath());

if ($xml->getName() !== 'extension') {
return false;
}

$newVersion = $this->getJConfig()->version;

if ((string)$xml->version === $newVersion) {
return false;
}

$xml->version = $newVersion;

$this->printTaskInfo('Updating file: ' . $file->getRealPath());

$xml->asXML($file->getRealPath());

return true;
}
}

0 comments on commit 0c3a8aa

Please sign in to comment.