Skip to content

Commit

Permalink
Merge branch '10.0/bugfixes'
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-anne committed Feb 12, 2025
2 parents 75bc160 + 9389461 commit 3698d65
Show file tree
Hide file tree
Showing 32 changed files with 1,041 additions and 180 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ The present file will list all changes made to the project; according to the
- Handling of the `delegate` right in `User::getSqlSearchResult()`.


## [10.0.18] unreleased
## [10.0.18] 2025-02-12

### Added

Expand Down
1 change: 1 addition & 0 deletions install/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ function update1($dbname)
footer_html();
} else {
$from_install = true;
$_SESSION['can_process_update'] = true;
include_once(GLPI_ROOT . "/install/update.php");
}
}
Expand Down
72 changes: 72 additions & 0 deletions install/migrations/update_10.0.17_to_10.0.18.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

/**
* ---------------------------------------------------------------------
*
* GLPI - Gestionnaire Libre de Parc Informatique
*
* http://glpi-project.org
*
* @copyright 2015-2025 Teclib' and contributors.
* @copyright 2003-2014 by the INDEPNET Development Team.
* @licence https://www.gnu.org/licenses/gpl-3.0.html
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ---------------------------------------------------------------------
*/

/**
* Update from 10.0.17 to 10.0.18
*
* @return bool for success (will die for most error)
**/
function update10017to10018()
{
/**
* @var \DBmysql $DB
* @var \Migration $migration
*/
global $DB, $migration;

$updateresult = true;
$ADDTODISPLAYPREF = [];
$DELFROMDISPLAYPREF = [];
$update_dir = __DIR__ . '/update_10.0.17_to_10.0.18/';

//TRANS: %s is the number of new version
$migration->displayTitle(sprintf(__('Update to %s'), '10.0.18'));
$migration->setVersion('10.0.18');

$update_scripts = scandir($update_dir);
foreach ($update_scripts as $update_script) {
if (preg_match('/\.php$/', $update_script) !== 1) {
continue;
}
require $update_dir . $update_script;
}

// ************ Keep it at the end **************
$migration->updateDisplayPrefs($ADDTODISPLAYPREF, $DELFROMDISPLAYPREF);

$migration->executeMigration();

return $updateresult;
}
69 changes: 69 additions & 0 deletions install/migrations/update_10.0.17_to_10.0.18/configs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

/**
* ---------------------------------------------------------------------
*
* GLPI - Gestionnaire Libre de Parc Informatique
*
* http://glpi-project.org
*
* @copyright 2015-2025 Teclib' and contributors.
* @copyright 2003-2014 by the INDEPNET Development Team.
* @licence https://www.gnu.org/licenses/gpl-3.0.html
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ---------------------------------------------------------------------
*/

/**
* @var \DBmysql $DB
* @var \Migration $migration
*/

// Remove unexpected values for `pdffont` config and user preference
$migration->addPostQuery(
$DB->buildUpdate(
'glpi_configs',
[
'value' => 'dejavusans',
],
[
'name' => 'pdffont',
[
'value' => ['REGEXP', '[^a-z0-9]+'],
],
]
)
);
$migration->addPostQuery(
$DB->buildUpdate(
'glpi_users',
[
'pdffont' => null,
],
[
[
['pdffont' => ['REGEXP', '[^a-z0-9]+']],
['NOT' => ['pdffont' => null]],
],
]
)
);
50 changes: 24 additions & 26 deletions install/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

$update = new Update($DB);

if (isset($_POST['update_end'])) {
if (($_SESSION['can_process_update'] ?? false) && isset($_POST['update_end'])) {
if (isset($_POST['send_stats'])) {
Telemetry::enable();
}
Expand Down Expand Up @@ -168,32 +168,30 @@ function showSecurityKeyCheckForm()
echo "<h2>" . __s('GLPI setup') . "</h2>";
echo "<br><h3>" . __s('Upgrade') . "</h3>";

// step 1 avec bouton de confirmation

if (empty($_POST["continuer"]) && empty($_POST["from_update"])) {
if (empty($from_install) && !isset($_POST["from_update"])) {
echo "<div class='center'>";
echo "<h3><span class='migred'>" . __s('Impossible to accomplish an update by this way!') . "</span>";
echo "<p>";
echo "<a class='btn btn-primary' href='../index.php'>
" . __s('Go back to GLPI') . "
</a></p>";
echo "</div>";
} else {
echo "<div class='center'>";
echo "<h3 class='my-4'><span class='migred p-2'>" . sprintf(__s('Caution! You will update the GLPI database named: %s'), htmlescape($DB->dbdefault)) . "</h3>";

echo "<form action='update.php' method='post'>";
if (!VersionParser::isStableRelease(GLPI_VERSION)) {
echo Config::agreeUnstableMessage(VersionParser::isDevVersion(GLPI_VERSION));
}
echo "<button type='submit' class='btn btn-primary' name='continuer' value='1'>
" . __s('Continue') . "
<i class='fas fa-chevron-right ms-1'></i>
</button>";
Html::closeForm();
echo "</div>";
if (($_SESSION['can_process_update'] ?? false) === false) {
// Unexpected direct access to the form
echo "<div class='center'>";
echo "<h3><span class='migred'>" . __s('Impossible to accomplish an update by this way!') . "</span>";
echo "<p>";
echo "<a class='btn btn-primary' href='../index.php'>
" . __s('Go back to GLPI') . "
</a></p>";
echo "</div>";
} elseif (empty($_POST["continuer"]) && empty($_POST["from_update"])) {
// step 1 avec bouton de confirmation
echo "<div class='center'>";
echo "<h3 class='my-4'><span class='migred p-2'>" . sprintf(__s('Caution! You will update the GLPI database named: %s'), htmlescape($DB->dbdefault)) . "</h3>";

echo "<form action='update.php' method='post'>";
if (!VersionParser::isStableRelease(GLPI_VERSION)) {
echo Config::agreeUnstableMessage(VersionParser::isDevVersion(GLPI_VERSION));
}
echo "<button type='submit' class='btn btn-primary' name='continuer' value='1'>
" . __s('Continue') . "
<i class='fas fa-chevron-right ms-1'></i>
</button>";
Html::closeForm();
echo "</div>";
} else {
// Step 2
if ($DB->connected) {
Expand Down
34 changes: 28 additions & 6 deletions phpunit/functional/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -894,12 +894,7 @@ public function testConfigLogNotEmpty()
$this->assertGreaterThan(0, $total_number);
}

/**
* Test the `prepareInputForUpdate` method.
*
* @return void
*/
public function testPrepareInputForUpdate(): void
public function testPrepareInputForUpdateLockProfile(): void
{
/** @var array $CFG_GLPI */
global $CFG_GLPI;
Expand Down Expand Up @@ -936,4 +931,31 @@ public function testPrepareInputForUpdate(): void
]);
$this->assertEquals($super_admin, (int) $CFG_GLPI['lock_lockprofile_id']);
}

public function testPrepareInputForUpdatePdfFont(): void
{
/** @var array $CFG_GLPI */
global $CFG_GLPI;

$this->login();

$config = new \Config();
$default_font = $CFG_GLPI['pdffont'];

// Invalid font
$config->prepareInputForUpdate([
'pdffont' => 'notavalidfont',
]);
$this->assertEquals($default_font, $CFG_GLPI['pdffont']);
$this->hasSessionMessages(ERROR, [
'The following field has an incorrect value: &quot;PDF export font&quot;.'
]);

// Valid font
$this->assertNotEquals('freesans', $CFG_GLPI['pdffont']);
$config->prepareInputForUpdate([
'pdffont' => 'freesans',
]);
$this->assertEquals('freesans', $CFG_GLPI['pdffont']);
}
}
Loading

0 comments on commit 3698d65

Please sign in to comment.