Skip to content

Commit

Permalink
Drop xml backup; check new versions from config
Browse files Browse the repository at this point in the history
closes #7182
  • Loading branch information
trasher committed Apr 28, 2020
1 parent 7093bde commit ad748d5
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 809 deletions.
700 changes: 0 additions & 700 deletions front/backup.php

This file was deleted.

7 changes: 7 additions & 0 deletions front/config.form.php
Expand Up @@ -33,6 +33,13 @@
include ('../inc/includes.php');
Session::checkRight("config", READ);

if (isset($_GET['check_version'])) {
Session::addMessageAfterRedirect(
Toolbox::checkNewVersionAvailable()
);
Html::back();
}

$config = new Config();
$_POST['id'] = 1;
if (!empty($_POST["update_auth"])) {
Expand Down
3 changes: 3 additions & 0 deletions inc/config.class.php
Expand Up @@ -1779,6 +1779,9 @@ function showSystemInformations() {

echo "<table class='tab_cadre_fixe'>";
echo "<tr><th>". __('Information about system installation and configuration')."</th></tr>";
echo "<tr class='tab_bg_1'><td>";
echo "<a class='vsubmit' href='?check_version'>".__('Check if a new version is available')."</a>";
echo "</td></tr>";

$oldlang = $_SESSION['glpilanguage'];
// Keep this, for some function call which still use translation (ex showAllReplicateDelay)
Expand Down
4 changes: 2 additions & 2 deletions inc/console/database/updatecommand.class.php
Expand Up @@ -170,8 +170,8 @@ protected function execute(InputInterface $input, OutputInterface $output) {
} else if ($force) {
// Replay last update script even if there is no schema change.
// It can be used in dev environment when update script has been updated/fixed.
include_once(GLPI_ROOT . '/install/update_943_945.php');
update943to945();
include_once(GLPI_ROOT . '/install/update_945_946.php');
update945to946();

$output->writeln('<info>' . __('Last migration replayed.') . '</info>');
}
Expand Down
2 changes: 1 addition & 1 deletion inc/crontask.class.php
Expand Up @@ -1654,7 +1654,7 @@ static function cronLogs($task) {
**/
static function cronCheckUpdate($task) {

$result = Toolbox::checkNewVersionAvailable(1);
$result = Toolbox::checkNewVersionAvailable();
$task->log($result);

return 1;
Expand Down
2 changes: 1 addition & 1 deletion inc/html.class.php
Expand Up @@ -1414,7 +1414,7 @@ static function getMenuInfos() {

$menu['admin']['title'] = __('Administration');
$menu['admin']['types'] = ['User', 'Group', 'Entity', 'Rule',
'Profile', 'QueuedNotification', 'Backup', 'Glpi\\Event'];
'Profile', 'QueuedNotification', 'Glpi\\Event'];

$menu['config']['title'] = __('Setup');
$menu['config']['types'] = ['CommonDropdown', 'CommonDevice', 'Notification',
Expand Down
3 changes: 0 additions & 3 deletions inc/profile.class.php
Expand Up @@ -1321,9 +1321,6 @@ function showFormAdmin($openform = true, $closeform = true) {
['itemtype' => 'QueuedNotification',
'label' => __('Notification queue'),
'field' => 'queuednotification'],
['itemtype' => 'Backup',
'label' => __('Maintenance'),
'field' => 'backup'],
['itemtype' => 'Log',
'label' => _n('Log', 'Logs', Session::getPluralNumber()),
'field' => 'logs']];
Expand Down
67 changes: 5 additions & 62 deletions inc/toolbox.class.php
Expand Up @@ -1407,25 +1407,11 @@ static function resizePicture($source_path, $dest_path, $new_width = 71, $new_he
/**
* Check if new version is available
*
* @param $auto boolean: check done autically ? (if not display result)
* (true by default)
* @param $messageafterredirect boolean: use message after redirect instead of display
* (false by default)
*
* @return string explaining the result
* @return string
**/
static function checkNewVersionAvailable($auto = true, $messageafterredirect = false) {
static function checkNewVersionAvailable() {
global $CFG_GLPI;

if (!$auto
&& !Session::haveRight('backup', Backup::CHECKUPDATE)) {
return false;
}

if (!$auto && !$messageafterredirect) {
echo "<br>";
}

//parse github releases (get last version number)
$error = "";
$json_gh_releases = self::getURLContent("https://api.github.com/repos/glpi-project/glpi/releases", $error);
Expand All @@ -1440,56 +1426,13 @@ static function checkNewVersionAvailable($auto = true, $messageafterredirect = f
$latest_version = array_pop($released_tags);

if (strlen(trim($latest_version)) == 0) {
if (!$auto) {
if ($messageafterredirect) {
Session::addMessageAfterRedirect($error, true, ERROR);
} else {
echo "<div class='center'>$error</div>";
}
} else {
return $error;
}

return $error;
} else {
if (version_compare($CFG_GLPI["version"], $latest_version, '<')) {
Config::setConfigurationValues('core', ['founded_new_version' => $latest_version]);

if (!$auto) {
if ($messageafterredirect) {
Session::addMessageAfterRedirect(sprintf(__('A new version is available: %s.'),
$latest_version));
Session::addMessageAfterRedirect(__('You will find it on the GLPI-PROJECT.org site.'));
} else {
echo "<div class='center'>".sprintf(__('A new version is available: %s.'),
$latest_version)."</div>";
echo "<div class='center'>".__('You will find it on the GLPI-PROJECT.org site.').
"</div>";
}

} else {
if ($messageafterredirect) {
Session::addMessageAfterRedirect(sprintf(__('A new version is available: %s.'),
$latest_version));
} else {
return sprintf(__('A new version is available: %s.'), $latest_version);
}
}

return sprintf(__('A new version is available: %s.'), $latest_version);
} else {
if (!$auto) {
if ($messageafterredirect) {
Session::addMessageAfterRedirect(__('You have the latest available version'));
} else {
echo "<div class='center'>".__('You have the latest available version')."</div>";
}

} else {
if ($messageafterredirect) {
Session::addMessageAfterRedirect(__('You have the latest available version'));
} else {
return __('You have the latest available version');
}
}
return __('You have the latest available version');
}
}
return 1;
Expand Down
4 changes: 4 additions & 0 deletions inc/update.class.php
Expand Up @@ -458,6 +458,10 @@ public function doUpdates($current_version = null) {
case "9.4.4":
include_once "{$updir}update_943_945.php";
update943to945();

case "9.4.5":
include_once "{$updir}update_945_946.php";
update945to946();
break;

case GLPI_VERSION:
Expand Down
2 changes: 1 addition & 1 deletion install/update_084_085.php
Expand Up @@ -893,7 +893,7 @@ function update084to085() {
"`name` = 'check_update' AND `rights` = '1'") as $profrights) {

$query = "UPDATE `glpi_profilerights`
SET `rights` = `rights` | " . Backup::CHECKUPDATE ."
SET `rights` = `rights` | " . 1024 /*Backup::CHECKUPDATE*/ ."
WHERE `profiles_id` = '".$profrights['profiles_id']."'
AND `name` = 'backup'";
$DB->queryOrDie($query, "0.85 update backup with check_update");
Expand Down
55 changes: 17 additions & 38 deletions inc/backup.class.php → install/update_945_946.php
Expand Up @@ -30,50 +30,29 @@
* ---------------------------------------------------------------------
*/

if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access this file directly");
}

/**
* Backup class
* Update from 9.4.5 to 9.4.6
*
* @since 0.85
* @return bool for success (will die for most error)
**/
function update945to946() {
global $DB, $migration;

$updateresult = true;

class Backup extends CommonGLPI {

static $rightname = 'backup';

const CHECKUPDATE = 1024;



/**
* @since 0.85.3
**/
static function canView() {
return Session::haveRight(self::$rightname, READ);
}


static function getTypeName($nb = 0) {
return __('Maintenance');
}

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

/**
* @since 0.85
*
* @see commonDBTM::getRights()
**/
function getRights($interface = 'central') {
$DB->deleteOrDie(
'glpi_profilerights',
[
'name' => 'backup'
]
);

$values = [READ => __('Read'),
CREATE => __('Create'),
PURGE => _x('button', 'Delete permanently'),
self::CHECKUPDATE => __('Check for upgrade')];
return $values;
}
// ************ Keep it at the end **************
$migration->executeMigration();

return $updateresult;
}
1 change: 0 additions & 1 deletion tests/units/Html.php
Expand Up @@ -379,7 +379,6 @@ public function testGetMenuInfos() {
'Rule',
'Profile',
'QueuedNotification',
'Backup',
'Glpi\\Event'
];
$this->string($menu['admin']['title'])->isIdenticalTo('Administration');
Expand Down

0 comments on commit ad748d5

Please sign in to comment.