mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 10:24:14 +00:00
updater frontend
This commit is contained in:
@@ -166,6 +166,10 @@ class Debug extends CI_Controller
|
||||
redirect('debug');
|
||||
}
|
||||
|
||||
public function wavelog_version() {
|
||||
$version_tag = $this->optionslib->get_option('version');
|
||||
echo $version_tag;
|
||||
}
|
||||
|
||||
public function migrate_userdata() {
|
||||
// Check if users logged in
|
||||
|
||||
@@ -204,7 +204,7 @@
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<?php if (file_exists(realpath(APPPATH.'../').'/.git')) { ?>
|
||||
<?php if (file_exists(realpath(APPPATH . '../') . '/.git')) { ?>
|
||||
<?php
|
||||
//Below is a failsafe where git commands fail
|
||||
try {
|
||||
@@ -217,7 +217,7 @@
|
||||
$commitDate = trim(exec('git log --pretty="%ci" -n1 HEAD'));
|
||||
$line = trim(exec('git log -n 1 --pretty=%D HEAD'));
|
||||
$pieces = explode(', ', $line);
|
||||
$lastFetch = trim(exec('stat -c %Y '.realpath(APPPATH.'../').'/.git/FETCH_HEAD'));
|
||||
$lastFetch = trim(exec('stat -c %Y ' . realpath(APPPATH . '../') . '/.git/FETCH_HEAD'));
|
||||
//Below is a failsafe for systems without the stat command
|
||||
try {
|
||||
$dt = new DateTime("@$lastFetch");
|
||||
@@ -283,18 +283,17 @@
|
||||
<?php } ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Last Fetch</td>
|
||||
<td>
|
||||
<?php echo ($dt == null ? '' : $dt->format(\DateTime::RFC850)); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Update Wavelog</td>
|
||||
<td><a class="btn btn-sm btn-primary" href="debug/selfupdate" onClick='this.classList.add("disabled");'>Update</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
</table>
|
||||
<div class="border-bottom border-top pt-2 pb-2 mt-2 mb-2" id="version_check">
|
||||
<p id="version_check_result"></p>
|
||||
<small id="last_version_check"></small>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<button class="btn btn-primary me-3 ld-ext-right" onClick="update_version_check();" id="version_check_button">Check for new Version<div class="ld ld-ring ld-spin"></div></button>
|
||||
<a class="btn btn-primary" style="display: none;" id="version_update_button" href="debug/selfupdate" onClick='this.classList.add("disabled");'>Update now</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php }
|
||||
@@ -460,4 +459,4 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@@ -44,3 +44,65 @@ function updateCallsign(item) {
|
||||
document.getElementById("station_call").innerHTML = call;
|
||||
}
|
||||
|
||||
function version_check(callback) {
|
||||
var latest_tag;
|
||||
$('#version_check_button').prop("disabled", true).addClass("running");
|
||||
$.ajax({
|
||||
url: base_url + 'index.php/debug/wavelog_version',
|
||||
success: function(database_version) {
|
||||
$.ajax({
|
||||
url: 'https://api.github.com/repos/wavelog/wavelog/tags',
|
||||
type: 'GET',
|
||||
success: function(tags) {
|
||||
// Extract the latest tag
|
||||
latest_tag = tags[0].name;
|
||||
|
||||
// Compare database version with the latest tag
|
||||
var is_latest_version = (database_version === latest_tag);
|
||||
|
||||
// Call the callback function with the result
|
||||
callback(is_latest_version, latest_tag);
|
||||
$('#version_check_button').prop("disabled", false).removeClass("running");
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('ERROR fetching Git tags:', error);
|
||||
callback(null, null);
|
||||
$('#version_check_button').prop("disabled", false).removeClass("running");
|
||||
}
|
||||
});
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('ERROR fetching database version:', error);
|
||||
callback(null, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function update_version_check() {
|
||||
version_check(function(is_latest_version, latest_tag) {
|
||||
$('#version_check_result').removeClass('alert alert-success alert-warning alert-danger').text('');
|
||||
$('#version_update_button').hide();
|
||||
var timestamp = Date.now();
|
||||
|
||||
if (is_latest_version !== null) {
|
||||
if (is_latest_version) {
|
||||
$('#version_check_result').addClass('alert alert-success');
|
||||
$('#version_check_result').text("Wavelog is up to date!");
|
||||
} else {
|
||||
$('#version_check_result').addClass('alert alert-warning');
|
||||
$('#version_check_result').text("There is a newer version available: " + latest_tag);
|
||||
$('#version_update_button').show();
|
||||
}
|
||||
} else {
|
||||
$('#version_check_result').addClass('alert alert-danger');
|
||||
$('#version_check_result').text("Failed to determine the latest version.");
|
||||
}
|
||||
|
||||
$('#last_version_check').text("Last version check: " + new Date(timestamp).toUTCString());
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
update_version_check();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user