Saturday 12 December 2015

Testing a patch

Description:  Test patches submitted to drupal.org for issues awaiting review. 


Drupal Ladder Lesson : http://drupalladder.org/lesson/93887717-c398-2434-394c-cf10851b4f1c

Prerequisites :

This post is for people using Windows.

1. First of all I will recommend you to install Github. It is a software which we use to work on Drupal Projects. To install Github for Windows(I am using Windows). Go to GitHub Desktop. Click on the download icon in the middle of the page. A downloader will be downloaded. Open the setup and it will prompt you to download the whole Github Desktop. Install it according to your comfort.
A typical GitHub start-up page.

2. You will need to have a local server up and running. A php, database manager and the server of course. For all these I used Xampp. It will install php, Mysql database and Apache server,it also has a ftp client(Filezilla). After installing Xampp go to its install directory and open the xampp-control.exe .

xampp-control.exe frontview
Click on the start button given in front of Apache and Mysql. Your server is now up and good to go.

*Pro tip-Install Xampp in C: rather than in C:\Program Files. This way it works better.
Close Skype from the Task Manager otherwise it will create clashes. 

3. Now we will clone Drupal Sandbox repository . For this open GitHub desktop which you downloaded in the first place. On the top-right corner there is a settings icon. Click on it and select 'Open in GitShell' a command line window will appear. Go to C:\xampp\htdocs using command prompt by typing  cd C:\xampp\htdocs . Create a folder 'sandbox' there by using the command md sandbox . Now we will clone the Drupal Sandbox directory here by giving the command git clone --branch 8.x http://git.drupal.org/sandbox/bhirsch/1388780.git. Now a download will get started.(I cloned the repository in D:\Sandbox and then had to move it to C:\xampp\htdocs, so you should clone it in firsthand to C:\xampp\htdocs).

Sandbox Clone Downloaded.
4. After the download is completed open localhost/phpmyadmin in your browser window. On the front page Click on the database tab. Make sure that both Apache server and Mysql are running.
Database tab of phpmyadmin.
In the 'Create Database' field type the name as 'sandbox' and click on create. In my case I named it as 'bax'. I don't why I named it so but it happened by impulse. Although I would recommend you to add a password to your profile by clicking on the 'User Accounts Tab' but is not required.

5. Now we will install Drupal Sandbox locally on your pc. Make sure Apache server and Mysql are up. Go to localhost/sandbox/core/install.php. Opt for the standard installation. Follow the on-screen instructions and go with the default settings. In the 'setup database' tab enter username as 'root', database name as 'sandbox'(If you followed what I said), and leave the password field blank.(If you did not add a password to your profile or otherwise enter the password.)  
Database configuration
After the installation is complete your local Drupal Sandbox site should be up and running and should look like this.6.Now

*Note-My site name is Lord_of_codes_Sandbox

6. Now we will add some commands to the .gitconfig file to make your coding experience more colorful and interesting.Enter the following commands:
git config --global color.status auto 
git config --global color.branch auto git config --global color.interactive auto git config --global color.diff auto
Configuring .gitconfig file

Steps for testing a patch:


1. First, lets rectify the issue that we have to clone. Open your browser and go to localhost/sandbox and click on Content(Present on left pane)>Add Content >Article (node/add/article) and scroll down below and click on URL path settings. Check out the help text. Did it mean anything to you ? Did you understand it? No na, the text is uninterpretable and quite misleading. This the problem we have to tackle by applying the patch.
The problem

2. Open GitHub Desktop. Click on the half-filled small rectangular in the top-left corner of the application.  Now click on the '+' icon whic appears after the menu slides to the left and click on 'add' tab and enter the address C:\xampp\htdocs\sandbox. Finally click on 'add repository'.

Ignore the code in background.
3. Now again open Git Shell. You will be in your sandbox directory. If not 'cd' to it.

4. Check the branch you are in by typing : git branch. If there's a green(green because we edited the .gitconfig file) asterisk next to 8.x, you are fine otherwise type : git checkout 8.x

I am in the 8.x branch
5Download the patch in comment 2 as it is the tried and tested patch.(Remember always to download the latest patch, we are not doing so here because it would be easier for you all match up with me and all the patch are same). Place the patch in your sandbox directory.

6. Now apply the patch by using the following command : git apply 1326088-rewrite-description-for-url-alias.patch
If the command prompt does not return anything. It means the patch applied cleanly.If returned an error, try clearing your cache by typing : git reset --hard

7. Lets check whether the issue is resolved or not. Refresh your browser page Again scroll to the part where the bug appeared. The 'help' text should now have changed to a more understandable phrase.
It makes sense now, isn't it?
8. Once tests are completed delete all the files modified by the patch by the command: git hard --reset.

9. Congratulations! You now know how to test a patch.

Conclusion :

After completing this task, you and me both now know how to test a patch submitted by core contributors of Drupal. Now you and I should pledge to contribute to Drupal in this specific field.
My special thanks to my mentors, Palashvijay4O & taditayar_af, the Google Code-In team and the whole Drupal community. Now I feel like a developer. :)

The most powerful CMS in the world.
Thank you.

Learn to submit suggested changes to Drupal as patch files


Description: 

Patch files are an integral part of any Project. In the process of development, few errors or bugs are always left behind even by the best team of developers such as Drupal. Patch files are never very large in size(Until they tackle non program data,such as multimedia). Although they are used in every field of the project, they have particularly the role of fixing security holes. Creating patch files is one of the best methods of contributing to a project. Lets walk through a summary on 'How to create Patch Files' .

Prerequisites: 

This post is for people using Windows.

1. First of all I will recommend you to install Github(Its only recommended, you can also work on Drupal projects without it). GitHub is a web-based repository service. In general, it is a software which is used by team of developers to work on their projects simultaneously. To install Github for Windows(I am using Windows). Go to GitHub Desktop. Click on the download icon in the middle of the page. A downloader will be downloaded. Open the setup and it will prompt you to download the whole Github Desktop. Install it according to your comfort.
A typical GitHub start-up page.
Now open the GitHub Desktop, click on the small 'settings' icon on the top-right corner and select GitShell from the drop down menu which will appear. Login with your GitHub username and mail by typing the commands: 
git config --global.username USERNAME
git config --global.email EMAIL
Replace the above 'USERNAME' and 'EMAIL' with your own. Don't have one ? Go create one at Github.

2. You will need to have a local server up and running. A php, database manager and the server of course. For all these I used Xampp. It will install php, Mysql database and Apache server,it also has a ftp client(Filezilla). After installing Xampp go to its install directory and open the xampp-control.exe .

xampp-control.exe frontview
Click on the start button given in front of Apache and Mysql. Your server is now up and good to go.

*Pro tip-Install Xampp in C: rather than in C:\Program Files. This way it works better.
Close Skype from the Task Manager otherwise it will create clashes. 

3. Now we will clone Drupal Sandbox repository . For this open GitHub desktop which you downloaded in the first place. On the top-right corner there is a settings icon. Click on it and select 'Open in GitShell' a command line window will appear. Go to C:\xampp\htdocs using command prompt by typing  cd C:\xampp\htdocs . Create a folder 'sandbox' there by using the command md sandbox . Now we will clone the Drupal Sandbox directory here by giving the command: git clone --branch 8.x http://git.drupal.org/sandbox/bhirsch/1388780.git . Now a download will get started.(I cloned the repository in D:\Sandbox and then had to move it to C:\xampp\htdocs, so you should clone it in firsthand to C:\xampp\htdocs).

Sandbox Clone Downloaded.
4. After the download is completed open localhost/phpmyadmin in your browser window. On the front page Click on the database tab. Make sure that both Apache server and Mysql are running.
Database tab of phpmyadmin.
In the 'Create Database' field type the name as 'sandbox' and click on create. In my case I named it as 'bax'. I don't why I named it so but it happened by impulse. Although I would recommend you to add a password to your profile by clicking on the 'User Accounts Tab' but is not required.

5. Now we will install Drupal Sandbox locally on your pc. Make sure Apache server and Mysql are up. Go to localhost/sandbox/core/install.php. Opt for the standard installation. Follow the on-screen instructions and go with the default settings. In the 'setup database' tab enter username as 'root', database name as 'sandbox'(If you followed what I said), and leave the password field blank.(If you did not add a password to your profile or otherwise enter the password.)  
Database configuration
After the installation is complete your local Drupal Sandbox site should be up and running and should look like this.

*Note-My site name is Lord_of_codes_Sandbox

6. Now we will add some commands to the .gitconfig file to make your coding experience more colorful and interesting. Open Git Shell and enter the following commands:

git config --global color.status auto
git config --global color.branch auto 
git config --global color.interactive auto
git config color.diff auto

Configuring .gitconfig file


Issue ID : 1681300

Steps:

Creating a branch for development:

1. First, lets rectify the issue that we have to clone. Open your browser and go to localhost/sandbox and click on Content(Present on left pane)>Add Content >Article (node/add/article) and scroll down below and click on URL path settings. Check out the help text. Did it mean anything to you ? Did you understand it? No na, the text is uninterpretable and quite misleading. This the problem we have to tackle by applying the patch.


The problem

2. Open GitHub Desktop. Click on the half-filled small rectangular in the top-left corner of the application.  Now click on the '+' icon which appears after the menu slides to the left and click on 'add' tab and enter the address C:\xampp\htdocs\sandbox. Finally click on 'add repository'.

Ignore the code in background.
3. Now again open Git Shell. You will be in your sandbox directory. If not 'cd' to it.

4. Check in which you currently are by typing : git branch . For creating a new branch where the patch development will take place, type: git branch 1681300-rewrite-description-for-URL-alias

5Checkout the branch you just created by typing git checkout 1681300-rewrite-description-for-url-alias. Type: git branch to confirm you are on the branch you just created.

Creating a branch for development.

6. Now open Notepad, click on File>Open.  The open dialog box will appear. Change the file type from .txt to 'All Files' from the drop down menu present right next to the file name field. Now, browse to C:\xampp\htdocs\sandbox\modules\path\path.module . Open the file. Use Ctrl+f to find this line :
Optionally specify an alternative URL by which this content can be accessed. For example, type "about" when writing an about page. Use a relative path and don't add a trailing slash or the URL alias won't work.
 and replace it with this line :
The alternative URL for this content. For example, type "about" when creating an about page.Use a relative path without a trailing slash.



Commiting changes to path.module

7. Lets check whether the issue is resolved or not. Refresh your browser page Again scroll to the part where the bug appeared. The 'help' text should now have changed to a more understandable phrase.
It makes sense now, isn't it?

8. Now its time to save the whole progress by committing the changes. To commit type git commit -am "1681300-Updated-description for URL on node form."
*Note - My node ID is 1681300 so I am using it as it is, you may use your own.

commiting changes
9. Now its time to create the patch file but first you have to comply the name of your patch with Drupal patch name standards. Which is this Description-NodeID-CommentNumber.patch.
For the comment number part you will manually have to visit that issue and find out the comment number your patch will be attached to. In my case the node ID is 1681300, Description is rewrite-description-for-url-alias and the comment number was supposed to be 29.
Hence my patch name : rewrite-description-for-url-alias-1681300-29.patch

creating patch
*The patch file submitted by me is available at : https://www.drupal.org/node/1681300#comment-10662674

10. Caution : Before uploading always test the patch file. To test the file type: git apply --check  rewrite-description-for-url-alias-1681300-29.patch . If nothing returns in reply from the Command Prompt, your patch successfully worked.

Applying patch
11. You successfully created a patch, now go upload it to the issue queue or share it with your friends or whatever you like.



Conclusion:

First of all I would like to thank my mentor tadityar & Chandan Singh, the Google Code-In team and the whole Drupal Community. After completing this task I have learnt how to write and apply patches for Drupal Core issues and every contrib module or project, basically any element of the Drupal project. So go to Drupal.org search for issues requiring patch and provide them with it. You and I will now be able to contribute to Drupal in this specific category. 
All hail Drupal!

The world's most powerful CMS.
Thank You.