From 5e7b399ef74e78656ffc2d389c996e878f03c04a Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Sun, 14 Jul 2024 19:56:33 +0200 Subject: [PATCH] tweaked selfupdater --- application/controllers/Debug.php | 68 +++++++++++++++++++++++++++---- 1 file changed, 61 insertions(+), 7 deletions(-) diff --git a/application/controllers/Debug.php b/application/controllers/Debug.php index bff26bba2..a45a4227c 100644 --- a/application/controllers/Debug.php +++ b/application/controllers/Debug.php @@ -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 {