mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 10:24:14 +00:00
tweaked selfupdater
This commit is contained in:
@@ -167,21 +167,75 @@ class Debug extends CI_Controller
|
||||
}
|
||||
|
||||
public function selfupdate() {
|
||||
|
||||
$stashfile = realpath(APPPATH.'../').'/.updater';
|
||||
$maintenancefile = realpath(APPPATH.'../').'/.maintenance';
|
||||
|
||||
if (file_exists('.git')) {
|
||||
try {
|
||||
$st=exec('touch '.realpath(APPPATH.'../').'/.maintenance');
|
||||
$st=exec('git stash push --include-untracked');
|
||||
$st=exec('git fetch');
|
||||
$st=exec('git pull');
|
||||
$st=exec('git stash pop');
|
||||
$st=exec('rm '.realpath(APPPATH.'../').'/.maintenance');
|
||||
} catch (\Throwable $th) {
|
||||
// enter maintenance mode
|
||||
exec('touch '.$maintenancefile);
|
||||
log_message('debug', 'Updater: Entered Maintenance mode by creating .maintenance file');
|
||||
|
||||
/**
|
||||
* to stay compatible with old installations and don't break them during updated to the lastest version
|
||||
* we have to take care of some old files, we stash everything else
|
||||
*/
|
||||
$this->discard_deprecated();
|
||||
|
||||
// we need atleast one file which gets stashed. this file should NOT be in .gitignore
|
||||
exec('touch '.$stashfile);
|
||||
log_message('debug', 'Updater: Created stashfile');
|
||||
|
||||
// stash everything else
|
||||
exec('git stash push --include-untracked');
|
||||
log_message('debug', 'Updater: Stash everything');
|
||||
|
||||
// perform the pull
|
||||
exec('git fetch');
|
||||
exec('git pull');
|
||||
log_message('debug', 'Updater: git fetch and git pull');
|
||||
|
||||
// due the fact we discarded the other files we can now pop all other changes
|
||||
exec('git stash pop');
|
||||
log_message('debug', 'Updater: Pop stashed changes');
|
||||
|
||||
// Show success message
|
||||
$this->session->set_flashdata('success', __("Wavelog was updated successfully!"));
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
log_message("Error","Error at selfupdating");
|
||||
}
|
||||
}
|
||||
// delete the stash file
|
||||
if(file_exists($stashfile)) {
|
||||
exec('rm '.$stashfile);
|
||||
log_message('debug', 'Updater: Delete stashfile');
|
||||
}
|
||||
// exit maintenance mode
|
||||
if(file_exists($maintenancefile)) {
|
||||
exec('rm '.$maintenancefile);
|
||||
log_message('debug', 'Updater: Delete .maintenance file to exit Maintenance Mode');
|
||||
}
|
||||
redirect('debug');
|
||||
}
|
||||
|
||||
private function discard_deprecated() {
|
||||
$files = array('assets/json/dok.txt', 'assets/json/pota.txt', 'assets/json/sota.txt', 'assets/json/wwff.txt', 'updates/clublog_scp.txt');
|
||||
|
||||
// unstage all files
|
||||
exec('git restore --staged .');
|
||||
log_message('debug', 'Updater: Unstage changes to stash them');
|
||||
|
||||
// and restore the deprecated files (discard changes)
|
||||
foreach($files as $file) {
|
||||
if (file_exists($file)) {
|
||||
exec('git restore ' . $file);
|
||||
log_message('debug', 'Updater: Discard changes in: '.$file. ' because this file is deprecated');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function wavelog_fetch() {
|
||||
$a_versions=[];
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user