diff --git a/README.md b/README.md index 7fb1fc856..46721145c 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,9 @@ To install with Docker please refer to the [Docker installation readme](/docs/IN Please read how to deploy to [Heroku here](/docs/HEROKU.md) +## Updates? + +Automatic Updates are enabled in the system and a notification will appear in the alert box. If you'd like to check for the updates manually, you can go to settings and click on "Update System Now!" to check for available updates. ## How do I install Engelsystem on my local machine from bash script Please check out [the documentation here](/docs/INSTALLATION_BASH_SCRIPT.md). diff --git a/Version.txt b/Version.txt new file mode 100644 index 000000000..d010c46e9 --- /dev/null +++ b/Version.txt @@ -0,0 +1 @@ +Version: 1.0 diff --git a/db/update.sql b/db/update.sql index 85e257719..cba35c808 100644 --- a/db/update.sql +++ b/db/update.sql @@ -68,6 +68,7 @@ CREATE TABLE IF NOT EXISTS `Settings` ( `event_start_date` int(11) DEFAULT NULL, `event_end_date` int(11) DEFAULT NULL, `teardown_end_date` int(11) DEFAULT NULL, + `autoupdate` tinyint(1) NOT NULL DEFAULT '0', `event_welcome_msg` varchar(255) DEFAULT NULL, `table_migrated` int(11) DEFAULT '0' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ; diff --git a/db/upgrade_01.sql b/db/upgrade_01.sql new file mode 100644 index 000000000..e69de29bb diff --git a/includes/controller/user_settings_controller.php b/includes/controller/user_settings_controller.php index 19b827021..f93a67eeb 100644 --- a/includes/controller/user_settings_controller.php +++ b/includes/controller/user_settings_controller.php @@ -35,6 +35,7 @@ function user_settings() { $current_city = $user['current_city']; $native_lang = $user['native_lang']; $other_langs = $user['other_langs']; + $auto_update = false; if (isset($_REQUEST['submit'])) { $ok = true; if (isset($_REQUEST['mail']) && strlen(strip_request_item('mail')) > 0) { @@ -181,18 +182,59 @@ function user_settings() { success("Language changed."); redirect(page_link_to('user_settings')); } - }elseif (isset($_REQUEST['submit_message'])){ + } elseif (isset($_REQUEST['submit_message'])) { $ok=true; if(isset($_REQUEST['display_message'])) $display_message=strip_request_item('display_message'); else $ok = false; - if($ok){ + + if ($ok) { update_display_msg($display_message); success("Message Changed"); redirect(page_link_to('user_settings')); } } + elseif (isset($_REQUEST['update'])) { + $ok = true; + + $online_ver = file_get_contents("https://raw.githubusercontent.com/fossasia/engelsystem/master/Version.txt"); + $current_ver = file_get_contents(" ../Version.txt"); + if (strcmp($current_ver, $online_ver) != 0) { + shell_exec("git pull origin master"); + + if(strcmp($current_ver, "Version: 1.0") == 0){ + $upgrade_table = '../db/upgrade_01.sql'; + upgrade_tables($upgrade_table); + } + } + else { + $ok = false; + $msg .= error(_("The system is already Up-to date with the version on GitHub."), true); + } + if ($ok) { + success(_("System Updated to the latest Version!")); + redirect(page_link_to('user_settings')); + } + } + elseif (isset($_REQUEST['autoupdate_check'])) { + $ok = true; + + if (isset($_REQUEST['auto_update'])) + $auto_update = true; + else { + $ok = false; + $auto_update = false; + $msg .= error(_("Disabled the Automatic Updates."), true); + } + + if ($ok) { + autoupdater($auto_update); + success("Enabled Automatic Updates!"); + redirect(page_link_to('user_settings')); + } + } + if ($ok) { $_SESSION['uid'] = $login_user['UID']; $_SESSION['locale'] = $login_user['Sprache']; @@ -248,7 +290,14 @@ function user_settings() { form_info(_("Here you can write your display message for registration:")), form_text('display_message', _("Message"), $display_message), form_submit('submit_message', _("Save")) - )) + )), + form(array( + form_info(_("Here you can set for Auto updates and check for updates:")), + form_checkbox('auto_update', _("Do you want to enable AutoUpdate for the system"), $auto_update), + form_info('', _("Checking the box will enable the autoupdate for the system")), + form_submit('autoupdate_check', _("Save")), + form_submit('update', _("Update System Now!")) + )), )) )) )); diff --git a/includes/model/Settings_model.php b/includes/model/Settings_model.php index 5da351268..f97988e43 100644 --- a/includes/model/Settings_model.php +++ b/includes/model/Settings_model.php @@ -47,6 +47,15 @@ function Settings() { return sql_select("SELECT * FROM `Settings`"); } +function autoupdater($auto_update) { + return sql_select("INSERT INTO `Settings` SET + `autoupdate`='" . sql_bool($auto_update) . "' "); +} + +function check_AutoUpdate() { + return sql_select("SELECT `autoupdate` FROM `Settings`"); +} + /** * Migrate Update tables. * @@ -63,4 +72,11 @@ function insert_table_migrated($value) { return sql_query("INSERT INTO `Settings` SET `table_migrated`='" . sql_escape($value) . "'"); } +function upgrade_tables($upgrade_table) { + global $DB_HOST, $DB_PASSWORD, $DB_NAME, $DB_USER; + $command_upgrade = 'mysql -h' . $DB_HOST . ' -u' . $DB_USER . ' -p' . $DB_PASSWORD . ' ' . $DB_NAME . ' < ' . $upgrade_table; + $output = array(); + exec($command_upgrade, $output, $worked_upgrade); +} + ?> diff --git a/public/index.php b/public/index.php index c83fa1339..4ff2b3685 100644 --- a/public/index.php +++ b/public/index.php @@ -28,6 +28,17 @@ $title = $p; $content = ""; + $check_autoupdate_enable = check_AutoUpdate(); + + if ($check_autoupdate_enable == true) { + $online_ver = file_get_contents("https://raw.githubusercontent.com/fossasia/engelsystem/master/Version.txt"); + $current_ver = file_get_contents(" ../Version.txt"); + + if (strcmp($current_ver, $online_ver) != 0) { + return info('' . _('There is an Update available on GitHub! Go to settings and update') . '', true); + } + } + if ($p == "api") { require_once realpath(__DIR__ . '/../includes/controller/api.php'); error("Api disabled temporily.");