chg: [dbSchemaDiagnostic] show remaining time before update unlock and

columns that should not be there
pull/5002/head
mokaddem 2019-10-01 15:22:29 +02:00
parent 39644802ff
commit 0f6f5d6291
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
4 changed files with 54 additions and 17 deletions

View File

@ -1701,6 +1701,7 @@ class AppModel extends Model
if (!empty($job)) {
$job['Job']['message'] = __('Update done');
}
$this->__changeLockState(false);
$this->__queueCleanDB();
} else {
if (!empty($job)) {
@ -1717,7 +1718,6 @@ class AppModel extends Model
if ($requiresLogout) {
$this->updateDatabase('destroyAllSessions');
}
$this->__changeLockState(false);
return true;
}
@ -1820,7 +1820,7 @@ class AppModel extends Model
return is_null($locked) ? false : $locked;
}
public function isUpdateLocked()
public function getLockRemainingTime()
{
$lockState = $this->getUpdateLockState();
if ($lockState !== false && $lockState !== '') {
@ -1833,11 +1833,17 @@ class AppModel extends Model
$this->Server = ClassRegistry::init('Server');
$updateWaitThreshold = intval($this->Server->serverSettings['MISP']['updateTimeThreshold']['value']);
}
if ($diffSec < $updateWaitThreshold) {
return true;
}
$remainingTime = $updateWaitThreshold - $diffSec;
return $remainingTime > 0 ? $remainingTime : 0;
} else {
return 0;
}
return false;
}
public function isUpdateLocked()
{
$remainingTime = $this->getLockRemainingTime();
return $remainingTime > 0;
}
private function __queueCleanDB()

View File

@ -4266,7 +4266,8 @@ class Server extends AppModel
'checked_table_column' => array(),
'diagnostic' => array(),
'expected_db_version' => '?',
'error' => ''
'error' => '',
'remaining_lock_time' => $this->getLockRemainingTime()
);
if ($data_source == 'Database/Mysql') {
$db_actual_schema = $this->getActualDBSchema();
@ -4357,23 +4358,44 @@ class Server extends AppModel
'column_name' => $table_name,
);
} else {
// perform schema copmarison for table's columns
foreach ($columns as $i => $column) {
if (isset($db_actual_schema[$table_name][$i])) {
$col_diff = array_diff($column, $db_actual_schema[$table_name][$i]);
// perform schema comparison for table's columns
$expected_column_keys = array();
$keyed_expected_column = array();
foreach($columns as $column) {
$expected_column_keys[] = $column[0];
$keyed_expected_column[$column[0]] = $column;
}
$existing_column_keys = array();
$keyed_actual_column = array();
foreach($db_actual_schema[$table_name] as $column) {
$existing_column_keys[] = $column[0];
$keyed_actual_column[$column[0]] = $column;
}
$additional_keys_in_actual_schema = array_diff($existing_column_keys, $expected_column_keys);
foreach($additional_keys_in_actual_schema as $additional_keys) {
$db_diff[$table_name][] = array(
'description' => sprintf(__('Column `%s` exists but should not'), $additional_keys),
'column_name' => $additional_keys
);
}
foreach ($keyed_expected_column as $column_name => $column) {
if (isset($keyed_actual_column[$column_name])) {
$col_diff = array_diff($column, $keyed_actual_column[$column_name]);
if (count($col_diff) > 0) {
$db_diff[$table_name][] = array(
'description' => sprintf(__('Column `%s` is different'), $column[0]),
'description' => sprintf(__('Column `%s` is different'), $column_name),
'column_name' => $column[0],
'actual' => $db_actual_schema[$table_name][$i],
'actual' => $keyed_actual_column[$column_name],
'expected' => $column
);
}
} else {
$db_diff[$table_name][] = array(
'description' => sprintf(__('Column `%s` does not exist'), $column[0]),
'column_name' => $column[0],
'actual' => array('None'),
'description' => sprintf(__('Column `%s` does not exist but should'), $column_name),
'column_name' => $column_name,
'actual' => array(),
'expected' => $column
);
}

View File

@ -115,6 +115,14 @@
__('Actual DB_version: ') . h($actualDbVersion)
);
}
echo '<br/>';
$humanReadableTime = sprintf('%smin %ssec', floor($remainingLockTime / 60), $remainingLockTime % 60);
echo sprintf('<span class="label label-%s" style="margin-left: 5px;" title="%s">%s <i class="fas fa-%s"></i></span>',
$remainingLockTime > 0 ? 'important' : 'success',
$remainingLockTime > 0 ? __('Update are locked') : __('Update are not locked'),
$remainingLockTime > 0 ? sprintf(__('Update unlocked in %s'), h($humanReadableTime)) : __('Update are not locked'),
$remainingLockTime > 0 ? 'times' : 'check'
)
?>
<script>
var db_schema_diagnostics = <?php echo json_encode($dbSchemaDiagnostics); ?>;

View File

@ -233,7 +233,8 @@
'dbSchemaDiagnostics' => $dbSchemaDiagnostics['diagnostic'],
'expectedDbVersion' => $dbSchemaDiagnostics['expected_db_version'],
'actualDbVersion' => $dbSchemaDiagnostics['actual_db_version'],
'error' => $dbSchemaDiagnostics['error']
'error' => $dbSchemaDiagnostics['error'],
'remainingLockTime' => $dbSchemaDiagnostics['remaining_lock_time']
)); ?>
</div>
<h3><?= __("Redis info") ?></h3>