From 3597801676f08061f4a630dc4218b525975e6194 Mon Sep 17 00:00:00 2001 From: Dishant Khanna Date: Sun, 7 Aug 2016 22:31:54 +0530 Subject: [PATCH 01/15] Created Update script --- update.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 update.sh diff --git a/update.sh b/update.sh new file mode 100644 index 000000000..dfe095392 --- /dev/null +++ b/update.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +# Authors: +# Dishant Khanna [FOSSASIA] + +# Description: +# An update bash script for engelsystem + +# Add upstream +git remote add upstream http://www.github.com/fossasia/engelsystem.git + +# Pull the updates +git pull upstream development From 867c6d280037760be64105453b5488e97f2c0cbd Mon Sep 17 00:00:00 2001 From: Dishant Khanna Date: Sun, 7 Aug 2016 22:33:29 +0530 Subject: [PATCH 02/15] Created version file --- Version.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 Version.txt 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 From 92204d78a3b493559e2ac8114b061643b2f674d4 Mon Sep 17 00:00:00 2001 From: Dishant Khanna Date: Thu, 11 Aug 2016 12:55:36 +0530 Subject: [PATCH 03/15] Update update.sql --- db/update.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/db/update.sql b/db/update.sql index f0cb1dfd6..de03820be 100644 --- a/db/update.sql +++ b/db/update.sql @@ -66,6 +66,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 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ; From dd482c8e2303008a66db86f8b472ec1c0a5c02e7 Mon Sep 17 00:00:00 2001 From: dishantk1807 Date: Thu, 11 Aug 2016 15:25:26 +0530 Subject: [PATCH 04/15] Added update feature --- .../controller/user_settings_controller.php | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/includes/controller/user_settings_controller.php b/includes/controller/user_settings_controller.php index 19b827021..466c522a6 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) { @@ -193,6 +194,40 @@ function user_settings() { redirect(page_link_to('user_settings')); } } + elseif (isset($_REQUEST['update'])) { + $ok = true; + + $online_ver = file_get_contents("https://raw.githubusercontent.com/DishantK1807/engelsystem/auto-update/Version.txt"); + $current_ver = file_get_contents(" ./Version.txt"); + if (strcmp($current_ver, $online_ver) != 0) { + echo shell_exec("sudo sh ./update.sh"); + } + else { + $ok = false; + $msg .= error(_("The system is already Up-to date with the version on GitHub."), true); + } + if($ok) { + success(_("System Updated")); + 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; + } + + if($ok) { + autoupdater($auto_update); + success("System Updated to the latest Version!"); + redirect(page_link_to('user_settings')); + } + } + if ($ok) { $_SESSION['uid'] = $login_user['UID']; $_SESSION['locale'] = $login_user['Sprache']; @@ -248,7 +283,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!")) + )), )) )) )); From c6af9669bc8f114ca60e2b900e2fdac872dc78f3 Mon Sep 17 00:00:00 2001 From: dishantk1807 Date: Thu, 11 Aug 2016 15:25:33 +0530 Subject: [PATCH 05/15] Updated setting_model for auto_update --- includes/model/Settings_model.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/includes/model/Settings_model.php b/includes/model/Settings_model.php index a42442d92..892e9634f 100644 --- a/includes/model/Settings_model.php +++ b/includes/model/Settings_model.php @@ -43,4 +43,12 @@ 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`"); +} ?> From 1fbc9a55834e6821e1d643ac01bbbb7ffa2c6fd6 Mon Sep 17 00:00:00 2001 From: dishantk1807 Date: Thu, 11 Aug 2016 15:25:36 +0530 Subject: [PATCH 06/15] Implemented automatic check for updates --- public/index.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/public/index.php b/public/index.php index 8d9971b7d..41c2d03e8 100644 --- a/public/index.php +++ b/public/index.php @@ -27,6 +27,16 @@ $title = $p; $content = ""; + $check_autoupdate_enable = check_AutoUpdate(); + + if ($check_autoupdate_enable == true) { + $online_ver = file_get_contents("https://raw.githubusercontent.com/DishantK1807/engelsystem/auto-update/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."); From 011157a92686e753863615fe718e73f3db41288b Mon Sep 17 00:00:00 2001 From: Dishant Khanna Date: Thu, 11 Aug 2016 21:37:36 +0530 Subject: [PATCH 07/15] changed the messages displayed --- includes/controller/user_settings_controller.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/includes/controller/user_settings_controller.php b/includes/controller/user_settings_controller.php index 466c522a6..766cd540b 100644 --- a/includes/controller/user_settings_controller.php +++ b/includes/controller/user_settings_controller.php @@ -207,7 +207,7 @@ function user_settings() { $msg .= error(_("The system is already Up-to date with the version on GitHub."), true); } if($ok) { - success(_("System Updated")); + success(_("System Updated to the latest Version!")); redirect(page_link_to('user_settings')); } } @@ -219,11 +219,12 @@ function user_settings() { else { $ok = false; $auto_update = false; + $msg .= error(_("Disabled the Automatic Updates."), true); } if($ok) { autoupdater($auto_update); - success("System Updated to the latest Version!"); + success("Enabled Automatic Updates!"); redirect(page_link_to('user_settings')); } } From 5170996c7d13ea333f2bc4c2b4e46600b902d83b Mon Sep 17 00:00:00 2001 From: Dishant Khanna Date: Fri, 12 Aug 2016 14:50:36 +0530 Subject: [PATCH 08/15] Updated documentation for AutoUpdates --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 799259f0f..52a6af4ca 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,10 @@ To install loklak with Docker please refer to the loklak [Docker installation re 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. + ## Report Bugs Please report bugs and feature requests here https://github.com/engelsystem/engelsystem/issues From ff8b0a31a210aa889c19c90167edea769ee68ce5 Mon Sep 17 00:00:00 2001 From: Dishant Khanna Date: Wed, 17 Aug 2016 08:53:46 +0530 Subject: [PATCH 09/15] Fix: Coding Style errors --- includes/controller/user_settings_controller.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/includes/controller/user_settings_controller.php b/includes/controller/user_settings_controller.php index 766cd540b..60e82a0ba 100644 --- a/includes/controller/user_settings_controller.php +++ b/includes/controller/user_settings_controller.php @@ -188,7 +188,8 @@ function user_settings() { $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')); @@ -206,7 +207,7 @@ function user_settings() { $ok = false; $msg .= error(_("The system is already Up-to date with the version on GitHub."), true); } - if($ok) { + if ($ok) { success(_("System Updated to the latest Version!")); redirect(page_link_to('user_settings')); } @@ -222,7 +223,7 @@ function user_settings() { $msg .= error(_("Disabled the Automatic Updates."), true); } - if($ok) { + if ($ok) { autoupdater($auto_update); success("Enabled Automatic Updates!"); redirect(page_link_to('user_settings')); From 25dbca9a0cee3d8492932cec811760425d648b1f Mon Sep 17 00:00:00 2001 From: dishantk1807 Date: Wed, 17 Aug 2016 14:14:49 +0530 Subject: [PATCH 10/15] Changed links --- includes/controller/user_settings_controller.php | 2 +- update.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/controller/user_settings_controller.php b/includes/controller/user_settings_controller.php index 60e82a0ba..b531cc9d9 100644 --- a/includes/controller/user_settings_controller.php +++ b/includes/controller/user_settings_controller.php @@ -198,7 +198,7 @@ function user_settings() { elseif (isset($_REQUEST['update'])) { $ok = true; - $online_ver = file_get_contents("https://raw.githubusercontent.com/DishantK1807/engelsystem/auto-update/Version.txt"); + $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) { echo shell_exec("sudo sh ./update.sh"); diff --git a/update.sh b/update.sh index dfe095392..211da8bcf 100644 --- a/update.sh +++ b/update.sh @@ -6,8 +6,8 @@ # Description: # An update bash script for engelsystem -# Add upstream +# Add upstream git remote add upstream http://www.github.com/fossasia/engelsystem.git # Pull the updates -git pull upstream development +git pull upstream master From ce8c6685aeb3ce78ea07415d47bd0d43b695f951 Mon Sep 17 00:00:00 2001 From: dishantk1807 Date: Fri, 19 Aug 2016 01:19:31 +0530 Subject: [PATCH 11/15] change upstream to origin --- public/index.php | 2 +- update.sh | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/public/index.php b/public/index.php index 41c2d03e8..cf94b1012 100644 --- a/public/index.php +++ b/public/index.php @@ -30,7 +30,7 @@ $check_autoupdate_enable = check_AutoUpdate(); if ($check_autoupdate_enable == true) { - $online_ver = file_get_contents("https://raw.githubusercontent.com/DishantK1807/engelsystem/auto-update/Version.txt"); + $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); diff --git a/update.sh b/update.sh index 211da8bcf..350210f18 100644 --- a/update.sh +++ b/update.sh @@ -6,8 +6,5 @@ # Description: # An update bash script for engelsystem -# Add upstream -git remote add upstream http://www.github.com/fossasia/engelsystem.git - # Pull the updates -git pull upstream master +git pull origin master \ No newline at end of file From d65cffaefca54ee35720758c5fdaa1732010ca6a Mon Sep 17 00:00:00 2001 From: dishantk1807 Date: Sun, 21 Aug 2016 00:35:41 +0530 Subject: [PATCH 12/15] changed links --- includes/controller/user_settings_controller.php | 9 +++++++-- public/index.php | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/includes/controller/user_settings_controller.php b/includes/controller/user_settings_controller.php index b531cc9d9..5c46431cf 100644 --- a/includes/controller/user_settings_controller.php +++ b/includes/controller/user_settings_controller.php @@ -199,9 +199,14 @@ function user_settings() { $ok = true; $online_ver = file_get_contents("https://raw.githubusercontent.com/fossasia/engelsystem/master/Version.txt"); - $current_ver = file_get_contents(" ./Version.txt"); + $current_ver = file_get_contents(" ../Version.txt"); if (strcmp($current_ver, $online_ver) != 0) { - echo shell_exec("sudo sh ./update.sh"); + shell_exec("../update.sh"); + + if(strcmp($current_ver, "Version: 1.0") == 0){ + $upgrade_table = '../db/upgrade_01.sql'; + upgrade_tables($upgrade_table); + } } else { $ok = false; diff --git a/public/index.php b/public/index.php index 9a5cea7f7..468fcdf60 100644 --- a/public/index.php +++ b/public/index.php @@ -32,7 +32,7 @@ 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"); + $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); } From 060232bd6376bf5404198260beeb24a54db82dd8 Mon Sep 17 00:00:00 2001 From: dishantk1807 Date: Sun, 21 Aug 2016 00:36:17 +0530 Subject: [PATCH 13/15] Fix: upgrade procedure --- db/upgrade_01.sql | 0 includes/model/Settings_model.php | 7 +++++++ 2 files changed, 7 insertions(+) create mode 100644 db/upgrade_01.sql diff --git a/db/upgrade_01.sql b/db/upgrade_01.sql new file mode 100644 index 000000000..e69de29bb diff --git a/includes/model/Settings_model.php b/includes/model/Settings_model.php index 776d0eb69..d6d7ba1da 100644 --- a/includes/model/Settings_model.php +++ b/includes/model/Settings_model.php @@ -60,4 +60,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); +} + ?> From 3fb9cd1ea8710208970f9c9f0701136c7e961744 Mon Sep 17 00:00:00 2001 From: dishantk1807 Date: Sun, 21 Aug 2016 11:58:14 +0530 Subject: [PATCH 14/15] Fix: Indentataion errors --- includes/controller/user_settings_controller.php | 4 ++-- public/index.php | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/includes/controller/user_settings_controller.php b/includes/controller/user_settings_controller.php index 5c46431cf..4427fec5e 100644 --- a/includes/controller/user_settings_controller.php +++ b/includes/controller/user_settings_controller.php @@ -182,14 +182,14 @@ 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')); diff --git a/public/index.php b/public/index.php index 468fcdf60..d550577a6 100644 --- a/public/index.php +++ b/public/index.php @@ -31,12 +31,13 @@ $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); + $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'); From 657ff027a4898a516b746cf5cfd4a5fee04def0c Mon Sep 17 00:00:00 2001 From: dishantk1807 Date: Tue, 23 Aug 2016 08:17:35 +0530 Subject: [PATCH 15/15] Removed the Shell file --- includes/controller/user_settings_controller.php | 2 +- update.sh | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) delete mode 100644 update.sh diff --git a/includes/controller/user_settings_controller.php b/includes/controller/user_settings_controller.php index 4427fec5e..f93a67eeb 100644 --- a/includes/controller/user_settings_controller.php +++ b/includes/controller/user_settings_controller.php @@ -201,7 +201,7 @@ function user_settings() { $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("../update.sh"); + shell_exec("git pull origin master"); if(strcmp($current_ver, "Version: 1.0") == 0){ $upgrade_table = '../db/upgrade_01.sql'; diff --git a/update.sh b/update.sh deleted file mode 100644 index 350210f18..000000000 --- a/update.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -# Authors: -# Dishant Khanna [FOSSASIA] - -# Description: -# An update bash script for engelsystem - -# Pull the updates -git pull origin master \ No newline at end of file