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

Conversation

DishantK1807
Copy link

Issue : #162

update01
Enable disable update in the UI

update02
System updated to latest version

update03
Check for updates enabled

$ok = false;
$msg .= error(_("The system is already Up-to date with the version on GitHub."), true);
}
if($ok) {
Copy link
Member

Choose a reason for hiding this comment

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

Coding style error

Copy link
Author

Choose a reason for hiding this comment

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

I'll add a blank line before the if($ok)

Copy link
Author

Choose a reason for hiding this comment

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

I guess only that's the error, or did I missed something else?

Copy link
Member

Choose a reason for hiding this comment

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

@@ -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
Copy link
Member

Choose a reason for hiding this comment

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

Do you notice that "origin" is also "http://www.github.com/fossasia/engelsystem.git"?
No need to define a "remote" with the same URL as "origin".

Copy link
Author

Choose a reason for hiding this comment

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

If a person Forks the project and makes some minor changes to it and uses it on his/her system, then remote would be required.
In the case of forked repositories, "remote" will be different from "origin"

Copy link
Member

Choose a reason for hiding this comment

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

If he forks the project and make somes changes, he should update from his repo, not FOSSASIA repo, because who can guarantee that new change in FOSSASIA won't break his system? The code update in FOSSASIA repo is only tested against the code in FOSSASIA repo, not against code of someone else. And who guarantee that new update from FOSSASIA won't have conflict with the change he made in his repo?

Copy link
Author

Choose a reason for hiding this comment

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

I'll remove "remote" and pull from "origin"
Thank you.

@hongquan
Copy link
Member

Why do you still let this happen:

selection_136

when I told you to config your code editor to fix it automatically?

(You don't need to make a commit to fix it right now. Don't repeat this error in the future)

@hongquan
Copy link
Member

I can make and upgrade.sql file which will contain the changes in the database scheme

Where in this PR that you run the upgrade.sql file, if that file exists?

Show me the screenshot that you have tested this feature in your localhost (with and without database change)

Can you explain this line:

echo shell_exec("sudo sh ./update.sh");

Why echo? Are you aware that in the "controller" PHP scripts, the content to return to browser is always wrapped in the functions like div, page_link_to and never returned by echo?

Why shell_exec comes with sh? Quoted from http://php.net/manual/en/function.shell-exec.php:

shell_exec — Execute command via shell...

The path ./update.sh won't work with new URL of engelsystem (changed from http://example.com/engelsystem/public/ to http://example.com/). Talk with @kamishettysreeja25 how she implemented the change and hope you will understand why that path will not work.

What if sudo ask for password? How user pass the password in?

@DishantK1807
Copy link
Author

DishantK1807 commented Aug 20, 2016

I'll remove sudo and sh.

Why shell_exec comes with sh?

I found this on stackoverflow.com . Will find that again and post it here

@hongquan
Copy link
Member

hongquan commented Aug 20, 2016

I found this on stackoverflow.com

Don't just copy and paste from stackoverflow. You have to understand what you are doing. This is not the first time I remind you to read documentation and understand the command you are using.

--- Update ---
Can you explain why you added sudo in the past, and why you will remove sudo next? If you remove sudo, will it conflict with the reason you added in the past?

@@ -187,12 +188,48 @@ function user_settings() {
$display_message=strip_request_item('display_message');
else
$ok = false;
if($ok){

if ($ok){

Choose a reason for hiding this comment

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

Indentation error: It should be if ($ok) {

Copy link
Member

Choose a reason for hiding this comment

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

Good. Thanks!

@DishantK1807
Copy link
Author

DishantK1807 commented Aug 20, 2016

No
removing sudo won't cause any problems. I just added it for the system which won't perform any operations without superuser permissions.
the script is running fine even without sudo.

The screenshots(without database change) are there shown above.

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

@hongquan
Copy link
Member

Now the update.sh script contains only 1 command. Let's get rid of that file.

By creating upgrade_XX.sql, you are repeating the work done by the "database migration" feature. Please look for a way to reuse that feature.

@DishantK1807
Copy link
Author

By creating upgrade_XX.sql, you are repeating the work done by the "database migration" feature. Please look for a way to reuse that feature.

@hongquan: can we implement that as a Fix/Improvement and merge this PR? I am looking for a way to reuse that feature.

Now the update.sh script contains only 1 command. Let's get rid of that file.

I suggest not to get rid of that file because we will require that while running the migrations.

@hongquan
Copy link
Member

hongquan commented Aug 21, 2016

I suggest not to get rid of that file because we will require that while running the migrations

What is required is the commands in that file. Because it has only 1 command, you should pass that command to your shell_exec, instead of creating 1 more script for just that command and pass the script to shell_exec.

can we implement that as a Fix/Improvement and merge this PR

The PR is merged after it is tested to show that it is stable and not break the system. You still don't provide the screenshots to show that you have tested with update + database. It is not proved to be ready for merge yet!

--- Update ---
Don't just put an empty upgrade_01.sql and say that you already tested with database change! There has to be a real database change when you test! Include also the Apache error log here. Look into @kamishettysreeja25's PR to learn how to strip old log.

Btw, there still be whitespace error in your code.

@DishantK1807
Copy link
Author

The Apache log:
https://cryptbin.com/hUAN#369ff3ad86f47434ca748077dfc6773e

Contents of upgrade_01.sql:

 INSERT INTO `Privileges` (`id`, `name`, `desc`) VALUES (45, 'install23', 'Install Engelsystem');

Tested the system for a random database upgrade.

upgraded
System Upgraded successfully

@DishantK1807
Copy link
Author

Will update the documentation.
Thank you.

@hongquan
Copy link
Member

Read my #220 (comment) again:

upgrade which includes change in database schema

Change in database schema. Inserting data to database is not a change in schema.

@hongquan
Copy link
Member

When you get the Apache error log, did you look into it to discover error and try to fix?

@DishantK1807
Copy link
Author

When you get the Apache error log, did you look into it to discover error and try to fix?

I will be working on fixing those errors, most of them are not because of this feature.

Change in database schema. Inserting data to database is not a change in schema.

I'll test for change in schema as well

@DishantK1807
Copy link
Author

The Apache log:
http://cryptb.in/NEowIW#ad4eed3bf192e327e1c31fed2df8e234

content of upgrade_01.sql

ALTER TABLE `Room`
  ADD `e_id` int(11) NOT NULL; 

upgraded

System Upgraded successfully.

@hongquan
Copy link
Member

I reminded you to look into Apache error log, but you still ignore this:

[Tue Aug 23 09:26:00.998777 2016] [:error] [pid 3074] [client 127.0.0.1:41481] PHP Warning: file_get_contents(raw.githubusercontent.com/fossasia/engelsystem/master/Version.txt): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found\r\n in /var/www/html/engelsystem/public/index.php on line 34
[Tue Aug 23 09:26:00.998832 2016] [:error] [pid 3074] [client 127.0.0.1:41481] PHP Warning: file_get_contents( ../Version.txt): failed to open stream: No such file or directory in /var/www/html/engelsystem/public/index.php on line 35

Look into kamishettysreeja25 PR about "Wordpress-like installation" to learn how to prevent the other errors. And also you can merge "development" branch to your branch to update with the fix she has done.

@hongquan
Copy link
Member

      if(strcmp($current_ver, "Version: 1.0") == 0){
        $upgrade_table = '../db/upgrade_01.sql';
        upgrade_tables($upgrade_table);
      }

If Version.txt contains higher number, like Version: 2.0, the database migration won't happen, right? And then the system will break?

@DishantK1807
Copy link
Author

If Version.txt contains higher number, like Version: 2.0, the database migration won't happen, right? And then the system will break?

I explained that in the Line comment, https://github.com/fossasia/engelsystem/pull/220/files#r75583290
That we would need to update code the similar way.

I'll add that to the documentation/wiki

@DishantK1807
Copy link
Author

DishantK1807 commented Aug 23, 2016

Apache log:
http://cryptb.in/C7hr#10db833189ee8869546c86359431e522

Fixed the mentioned error. the error was due to the wrong link in index.php
Changed the link in local repo and tested.

upgraded

I'll look into Kamishettysreeja PR for solving the other errors

@hongquan
Copy link
Member

hongquan commented Aug 23, 2016

What? You ask user to modify source code? He/she has to find which version his/her website is, and which version the new update is, and has to implement the whole if code block? Then how come this feature is called "auto upgrade"? This feature has been existed in many PHP web system like Wordpress, Drupal, Piwik but I have never seen one asking user to modify source code to upgrade.

Needless to say that user doesn't know when to change, because:

  • If user modifies before the upgrade process happens, the "git pull" command will stop if the new update contains update for the file user has modified. And just finding out the version number is already headache for user.
  • If user modifies after "git pull", no chance. The process won't pause for user to intervene.

@DishantK1807
Copy link
Author

DishantK1807 commented Aug 23, 2016

What? You ask user to modify source code? He/she has to find which version his/her website is, and which version the new update is, and has to implement the whole if code block? Then how come this feature is called "auto upgrade"? This feature has been existed in many PHP web system like Wordpress, Drupal, Piwik but I have never seen one asking user to modify source code to upgrade.
Needless to say that user doesn't know when to change, because:
If user modify before the upgrade process happen, the "git pull" command will stop if the new update contains update for the file user has modified. Just find out the version number is already headache for user.
If user modify after "git pull", no chance. The process won't pause for user to intervene.

No. not the user. User won't work on the code.
The person contributing the code.
Will add this to the wiki as a condition when the PR by the contributor is merged.

@hongquan
Copy link
Member

hongquan commented Aug 23, 2016

The person contributing the code.
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

Then how the developer know which version the local system is? Assume you are releasing v5, but Mario has a website with v4, and sister Phuc has a website with v1. How the developer implement that if block to satisfy both?

--- Update ---
Second time to remind you about coding style error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants