Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto upgrade feature #220

Open
wants to merge 17 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
1 change: 1 addition & 0 deletions Version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Version: 1.0
1 change: 1 addition & 0 deletions db/update.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;
Expand Down
Empty file added db/upgrade_01.sql
Empty file.
55 changes: 52 additions & 3 deletions includes/controller/user_settings_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Copy link
Author

@DishantK1807 DishantK1807 Aug 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly we can create upgrade_XX.sql for every release and compare the version numbers of the of the local system.

I'll add in the documentation too, how to upgrade the database(with a sample code explaining everything) so that users who'll be working on it in future can integrate the changes in the database.

Eg. If the current version in the local system is 3.0 and on GitHub it is 5.0 then in the if statement both Upgrade_04.sql and upgrade_05.sql will run.
Will update the documentation for the same

}
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'];
Expand Down Expand Up @@ -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!"))
)),
))
))
));
Expand Down
16 changes: 16 additions & 0 deletions includes/model/Settings_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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);
}

?>
11 changes: 11 additions & 0 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('<a href="' . page_link_to("user_settings") . '">' . _('There is an Update available on GitHub! Go to settings and update') . '</a>', true);
}
}

if ($p == "api") {
require_once realpath(__DIR__ . '/../includes/controller/api.php');
error("Api disabled temporily.");
Expand Down