migrate updateFunctions to PDO and fix version_compare2
Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
@@ -15,7 +15,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Function updateToVersion
|
* Function updateToVersion
|
||||||
*
|
*
|
||||||
* updates the panel.version field
|
* updates the panel.version field
|
||||||
@@ -25,40 +25,41 @@
|
|||||||
*
|
*
|
||||||
* @return bool true on success, else false
|
* @return bool true on success, else false
|
||||||
*/
|
*/
|
||||||
function updateToVersion($new_version = null)
|
function updateToVersion($new_version = null) {
|
||||||
{
|
|
||||||
global $db, $settings, $theme;
|
|
||||||
|
|
||||||
if($new_version !== null && $new_version != '')
|
global $settings;
|
||||||
{
|
|
||||||
$query = "UPDATE `".TABLE_PANEL_SETTINGS."` SET `value` = '" . $new_version . "' WHERE `settinggroup` = 'panel' AND `varname` = 'version'";
|
if ($new_version !== null && $new_version != '') {
|
||||||
$db->query($query);
|
$upd_stmt = Database::prepare("
|
||||||
|
UPDATE `".TABLE_PANEL_SETTINGS."` SET `value` = :newversion
|
||||||
|
WHERE `settinggroup` = 'panel' AND `varname` = 'version'"
|
||||||
|
);
|
||||||
|
Database::pexecute($upd_stmt, array('newversion' => $new_version));
|
||||||
$settings['panel']['version'] = $new_version;
|
$settings['panel']['version'] = $new_version;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Function isFroxlor
|
* Function isFroxlor
|
||||||
*
|
*
|
||||||
* checks if the panel is froxlor
|
* checks if the panel is froxlor
|
||||||
*
|
*
|
||||||
* @return bool true if panel is froxlor, else false
|
* @return bool true if panel is froxlor, else false
|
||||||
*/
|
*/
|
||||||
function isFroxlor()
|
function isFroxlor() {
|
||||||
{
|
global $settings;
|
||||||
global $settings, $theme;
|
|
||||||
|
|
||||||
if(isset($settings['panel']['frontend'])
|
if (isset($settings['panel']['frontend'])
|
||||||
&& $settings['panel']['frontend'] == 'froxlor')
|
&& $settings['panel']['frontend'] == 'froxlor'
|
||||||
{
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Function isFroxlorVersion
|
* Function isFroxlorVersion
|
||||||
*
|
*
|
||||||
* checks if a given version is the
|
* checks if a given version is the
|
||||||
@@ -68,19 +69,19 @@ function isFroxlor()
|
|||||||
*
|
*
|
||||||
* @return bool true if version to check matches, else false
|
* @return bool true if version to check matches, else false
|
||||||
*/
|
*/
|
||||||
function isFroxlorVersion($to_check = null)
|
function isFroxlorVersion($to_check = null) {
|
||||||
{
|
|
||||||
global $settings, $theme;
|
|
||||||
|
|
||||||
if($settings['panel']['frontend'] == 'froxlor'
|
global $settings;
|
||||||
&& $settings['panel']['version'] == $to_check)
|
|
||||||
{
|
if ($settings['panel']['frontend'] == 'froxlor'
|
||||||
|
&& $settings['panel']['version'] == $to_check
|
||||||
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Function isFroxlorVersion
|
* Function isFroxlorVersion
|
||||||
*
|
*
|
||||||
* checks if a given version is the
|
* checks if a given version is the
|
||||||
@@ -90,19 +91,19 @@ function isFroxlorVersion($to_check = null)
|
|||||||
*
|
*
|
||||||
* @return bool true if version to check matches, else false
|
* @return bool true if version to check matches, else false
|
||||||
*/
|
*/
|
||||||
function hasUpdates($to_check = null)
|
function hasUpdates($to_check = null) {
|
||||||
{
|
|
||||||
global $settings, $theme;
|
|
||||||
|
|
||||||
if(!isset($settings['panel']['version'])
|
global $settings;
|
||||||
|| $settings['panel']['version'] != $to_check)
|
|
||||||
{
|
if (!isset($settings['panel']['version'])
|
||||||
|
|| $settings['panel']['version'] != $to_check
|
||||||
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Function showUpdateStep
|
* Function showUpdateStep
|
||||||
*
|
*
|
||||||
* outputs and logs the current
|
* outputs and logs the current
|
||||||
@@ -113,65 +114,63 @@ function hasUpdates($to_check = null)
|
|||||||
*
|
*
|
||||||
* @return string formatted output and log-entry
|
* @return string formatted output and log-entry
|
||||||
*/
|
*/
|
||||||
function showUpdateStep($task = null, $needs_status = true)
|
function showUpdateStep($task = null, $needs_status = true) {
|
||||||
{
|
|
||||||
global $updatelog, $filelog, $theme;
|
global $updatelog, $filelog;
|
||||||
|
|
||||||
// output
|
// output
|
||||||
echo $task;
|
echo $task;
|
||||||
|
|
||||||
if(!$needs_status)
|
if (!$needs_status) {
|
||||||
{
|
|
||||||
echo "<br />";
|
echo "<br />";
|
||||||
}
|
}
|
||||||
|
|
||||||
$updatelog->logAction(ADM_ACTION, LOG_WARNING, $task);
|
$updatelog->logAction(ADM_ACTION, LOG_WARNING, $task);
|
||||||
$filelog->logAction(ADM_ACTION, LOG_WARNING, $task);
|
$filelog->logAction(ADM_ACTION, LOG_WARNING, $task);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Function lastStepStatus
|
* Function lastStepStatus
|
||||||
*
|
*
|
||||||
* outputs [OK] (success), [??] (warning) or [!!] (failure)
|
* outputs [OK] (success), [??] (warning) or [!!] (failure)
|
||||||
* of the last update-step
|
* of the last update-step
|
||||||
*
|
*
|
||||||
* @param int status (0 = success, 1 = warning, 2 = failure)
|
* @param int status (0 = success, 1 = warning, 2 = failure)
|
||||||
*
|
*
|
||||||
* @return string formatted output and log-entry
|
* @return string formatted output and log-entry
|
||||||
*/
|
*/
|
||||||
function lastStepStatus($status = -1, $message = '')
|
function lastStepStatus($status = -1, $message = '') {
|
||||||
{
|
|
||||||
global $updatelog, $filelog, $theme;
|
global $updatelog, $filelog;
|
||||||
|
|
||||||
switch($status)
|
switch($status) {
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
$status_sign = ($message != '') ? '['.$message.']' : '[OK]';
|
$status_sign = ($message != '') ? '['.$message.']' : '[OK]';
|
||||||
$status_color = '1dcd00';
|
$status_color = '1dcd00';
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
$status_sign = ($message != '') ? '['.$message.']' : '[??]';
|
$status_sign = ($message != '') ? '['.$message.']' : '[??]';
|
||||||
$status_color = 'db7100';
|
$status_color = 'db7100';
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
$status_sign = ($message != '') ? '['.$message.']' : '[!!]';
|
$status_sign = ($message != '') ? '['.$message.']' : '[!!]';
|
||||||
$status_color = 'ff0000';
|
$status_color = 'ff0000';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$status_sign = '[unknown]';
|
$status_sign = '[unknown]';
|
||||||
$status_color = '000000';
|
$status_color = '000000';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// output
|
// output
|
||||||
echo "<span style=\"margin-left: 5em; font-weight: bold; color: #".$status_color."\">".$status_sign."</span><br />";
|
echo "<span style=\"margin-left: 5em; font-weight: bold; color: #".$status_color."\">".$status_sign."</span><br />";
|
||||||
|
|
||||||
if($status == -1 || $status == 2)
|
if ($status == -1 || $status == 2) {
|
||||||
{
|
|
||||||
$updatelog->logAction(ADM_ACTION, LOG_WARNING, 'Attention - last update task failed!!!');
|
$updatelog->logAction(ADM_ACTION, LOG_WARNING, 'Attention - last update task failed!!!');
|
||||||
$filelog->logAction(ADM_ACTION, LOG_WARNING, 'Attention - last update task failed!!!');
|
$filelog->logAction(ADM_ACTION, LOG_WARNING, 'Attention - last update task failed!!!');
|
||||||
}
|
|
||||||
elseif($status == 0 || $status == 1)
|
} elseif($status == 0 || $status == 1) {
|
||||||
{
|
|
||||||
$filelog->logAction(ADM_ACTION, LOG_WARNING, 'Success');
|
$filelog->logAction(ADM_ACTION, LOG_WARNING, 'Success');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -179,18 +178,16 @@ function lastStepStatus($status = -1, $message = '')
|
|||||||
/**
|
/**
|
||||||
* validate if full path to update.log is sane
|
* validate if full path to update.log is sane
|
||||||
* if not, the update.log is created in /tmp/
|
* if not, the update.log is created in /tmp/
|
||||||
*
|
*
|
||||||
* @param string $filename the file name to validate
|
* @param string $filename the file name to validate
|
||||||
*
|
*
|
||||||
* @return string the full path with filename (can differ if not writeable => /tmp)
|
* @return string the full path with filename (can differ if not writeable => /tmp)
|
||||||
*/
|
*/
|
||||||
function validateUpdateLogFile($filename)
|
function validateUpdateLogFile($filename) {
|
||||||
{
|
|
||||||
if(!is_dir($filename))
|
if (!is_dir($filename)) {
|
||||||
{
|
|
||||||
$fh = @fopen($filename, 'a');
|
$fh = @fopen($filename, 'a');
|
||||||
if($fh)
|
if ($fh) {
|
||||||
{
|
|
||||||
fclose($fh);
|
fclose($fh);
|
||||||
return $filename;
|
return $filename;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,8 +26,8 @@
|
|||||||
function version_compare2($a, $b) {
|
function version_compare2($a, $b) {
|
||||||
|
|
||||||
// split version into pieces and remove trailing .0
|
// split version into pieces and remove trailing .0
|
||||||
$a = explode(".", rtrim($a, ".0"));
|
$a = explode(".", $a);
|
||||||
$b = explode(".", rtrim($b, ".0"));
|
$b = explode(".", $b);
|
||||||
|
|
||||||
_parseVersionArray($a);
|
_parseVersionArray($a);
|
||||||
_parseVersionArray($b);
|
_parseVersionArray($b);
|
||||||
|
|||||||
Reference in New Issue
Block a user