Thursday, 19 January 2017

Finish Entire Drupal Ladder [Git Basics]









Thursday, 22 December 2016

Finish Drupal Ladder [Drupal Core Ladder] — Write a patch




Hola! Here we are yet again to review a rung of the Drupal core ladder. This time, we are seeing the Write a patch rung. This rung teaches you how to create a patch to solve the issue created in the previous rung.

Prerequisites

Here are some of the stuff you must already know/have in order to continue with this tutorial:
  1. Have Git installed. If you haven’t already, you can follow this link to install it on your OS.
  2. You’ll be working with a sandbox version of Drupal in this exercise. It has been built with a known issue for you to patch. For this lesson, download and install Drupal 8 from the Drupal 8 Sandbox for Drupal Ladder
  3. Have a basic knowledge of Git. You can go to this link and this one to understand Git better. (This is optional and not required. It’s better to do it though.)
  4. Have a way to capture screenshots. To provide a screenshot of the bug, you should have a way to capture screen shots. Popular options include Skitch, Jing and Awesome Screenshot.
  5. An issue in the sandbox issue queue, as created in the Getting started in the issue queue lesson. You will need to know your issue number, which is the node ID for the issue on Drupal.org. You can easily find this by going to the issue page and then select the node ID from the page URL. E.g. if the issue page URL is http://drupal.org/node/1681300, the node ID, and therefore the issue ID is 1681300. Make note of this for reference in this lesson. Here is my issue queue: https://www.drupal.org/node/2836315
Note: Before we start, I’d like to mention that despite the fact that I ran everything as root, many of these commands don’t require root. I do it because I’m a forgetful person and I don’t like screenshot-ruining errors popping up.

1 - Create a branch for development

This is the first part of this rung, where you are asked to create a branch where we will be making our changes.
Note: you have to replace the stuff in brackets with your own details.For example, if your issue number is 1234567, you have to enter 1234567 instead of [issue-number].
  1. Go to your sandbox directory. In my case, it was:
cd ~/capsandbox/drupal_8_sandbox_for_drupal_ladder
2. Check what branch you’re in and make sure you are in 8.x.
git branch
3. Create a branch where you will work on your patch.
git branch [issue-number]-rewrite-description-for-url-alias
4. Now check out the branch you just created.
git checkout [issue-number]-rewrite-description-for-url-alias
5. Confirm you’re on the branch you just created.
git branch
Creating a new branch

2- Make your edits.

This section of this ladder asks you to edit your path.module file, and then to review and screenshot the change in your browser. You are then required to review the changes made to path.module by using Git.
  1. Open the path.module file (e.g. my-sandbox/core/modules/path/path.module) with your favorite text editor.
  2. Go to line 139 and replace this:
    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.
    with this:
    The alternative URL for this content. Use a relative path without a trailing slash. For example, type "about" for the about page.
  3. In your browser, go to Content > + Add content > Article (node/add/article), scroll down and click the URL path settings tab. Confirm your edit worked by seeing that the help text as changed, and confirm you didn’t accidentally introduce an error.
  4. Take a screen shot. Using your screenshot program, call out the changed text with an arrow or highlight. (You will upload this along with your patch.)
  5. See which files have changes pending.
    git status
  6. Review your changes in Git with a standard diff. (Note to exit the patch display, type the letter q on your command line to quit viewing.)
    git diff
    You can also review your changes word-by-word.
    git diff --word-diff
  7. Commit your changes on your local development branch. The “-am” flag in this command is adding (a) the modified file to the local git repository with the message (m) that you provide being added to the git log.
    git commit -am "Issue #[issue-number]. Updated description for URL alias on node form."
    (When you commit your changes, git may generate and display a commit ID. The commit ID is a 40 character code, e.g. bc584d4ff96d434706211e2bef45613dd32d3c16. You can use this ID to refer to and review your commit.)
  8. Review your commit.
    git log
    git show
    Or
    git show [commit ID]
Note: If you made a mistake, you can undo all of your changes.
git reset --hard
proof 1

3- Create and submit a patch

This part of the rung requires you to create the patch, to test it, add a comment with the patch in the issue queue and then to edit your issue queue to change its status to ‘needs review’.
  1. Figure out which comment number your patch will be attached to. Go to the issue and scroll down through the comments. Note the comment number for the last comment. Your patch will be attached to the next comment, so you will use that next sequential number for your patch. E.g. if the issue has 3 existing comments, your patch will be attached to comment 4. You will use the number 4 as part of your patch name in the next step.
  2. Generate a patch file using the following naming convention. Note that the patch filename cannot contain any spaces, so use dashes or underscores to separate words and numbers. This is taking the output of the git diff, which shows the changes between your branch and 8.x, and creating a file with that text, which ends in .patch
    git diff 8.x > [description]-[issue-number]-[comment-number].patch
  3. Test your patch by applying it to a branch before uploading in an issue queue, you can use the 8.x branch for this:
    Checkout to the 8.x branch
    git checkout 8.x
    Apply the patch
    git apply -v [description]-[issue-number]-[comment-number].patch
    If the patch applies successfully, you can now upload your patch to the issue, but first, undo the changes done by the patch in the 8.x branch.
    git reset --hard
  4. Go to your issue on Drupal.org.
  5. Post a comment on the issue and upload your patch and screenshot.
  6. Change status settings of the issue to “Needs Review”
Changing the status to ‘needs review’ will trigger the testbot, which will then automatically review the patch and will display the results. Patch Reviewers also use this status to find patches that need to be reviewed and evaluated. With sufficient positive feedback, the patch may be promoted to the status “Reviewed & Tested by the Community” [see next definition]. If a reviewer, either human or Bot, finds a problem with the patch, it will then be marked as “Needs Work”. Note that if a patch is not required in order to complete the idea described in the issue, then it is the idea itself that needs review. You can see what other statuses do on this page.
* Note: Normally you would now wait for the testbot to test your patch. This is a sandbox issue queue, so the testbot WILL NOT test your patch here. When you do post in a regular issue queue, the testbot will check your patch to make sure it doesn’t break anything. If your patch turns green, the patch applied cleanly and passed Drupal’s tests. Now if your patch passes tests by other members of the community, it can be committed. If your patch turns red, tests failed. Click the link for View details to see what’s going wrong, then re-write and re-submit your patch.

Bonus: Re-roll the patch

This last section of this guide teaches how to re-roll the patch in order for it to be compatible with newer versions of Drupal.
In the real patch to this issue, http://drupal.org/node/1326088#comment-5188202, the word ‘type’ was changed to ‘enter’ before it was finally committed. This means the patch can no longer be applied to the updated code base. The patch must thus be updated, or “re-rolled” to be compatible with the current version.
  1. Checkout your development branch.
    git checkout my-branch
  2. Make your edit, by changing the word ‘type’ to ‘enter.’
  3. Commit.
    git commit -am "Issue #[issue-number]. [Description]."
  4. Create a new patch with the updates.
    git diff 8.x > [description]-[issue-number]-[comment-number].patch
proof 2

Final Thoughts

This Drupal ladder taught me how to create a branch in Git for development, how to create a patch for a bug, how to submit the patch to drupal.org, and as a bonus, it also taught me how to re-roll the patch. This is a knowledge that will definitely be useful to me for future contributions to Drupal.

Friday, 9 December 2016

What is Drupal ?



Every program/application is a solution to a problem in the technological world. Drupal is no exception to this rule.It is the Swiss army knife of web development. Drupal is a free open source(Source code is the "recipe" used to make the program. Open source means that anyone can view,change and share their modified version of this "recipe". KFC is definitely not "open source"!) Content Management System (CMS) that makes building, editing and managing any type of website easy for users who are not in the tech world.

So, what is a Content Management System? It is a software application that allows users who are not familiar with technology to create and edit digital content. A CMS serves as a store for information resources such as text, image databases and so on(Source: PublicLife). A CMS is made up of two major parts: A content management application,that can be further broken down into two sections: Content(your writing,images and some HTML for customising the look of the text.) and Creative Design(themes or page layout that affect the appearance of your website.), and a content delivery application, that compiles and updates the website.

The reason Drupal is such a popular CMS (millions of sites run Drupal!) is because of its flexibility and because it is highly scalable. It can be used as web content management platform for nearly any type of website of any size and shape. This feature makes Drupal favorable if you know that your website is going to grow. For example,both www.australia.gov.au and http://beaubebe.mu/ run Drupal. However,the former is a large website that is accessed by a lot of people every day, whereas the latter is a small website that has very little incoming traffic. The appearances of the websites are also very different. So,you have come to the end of my explanation of Drupal. I hope that you have understood.

Monday, 5 December 2016

How to install Drupal on Ubuntu 16.10

Hi there, I'm writing this post to explain the process of installing and configuring Drupal 8.2.4 on Ubuntu 16.10 Desktop.  

STEPS

STEP 1

Before installing Drupal,we first need to install LAMP(Linux,apache2,MySQL,PHP). For that, the following commands were used:


sudo su (for allowing root permission)
apt-get update(update list of available packages)
apt-get upgrade (updating repositories)
Then we run the following command to install :

apache: the web server that we are going to use
php: a server-side scripting language
php-mysql: the php extension for mysql
MySQL-client: the program that we are going to use to send commands to the MySQL server
Mysql-server: will install the MySQL database server that is an open source Relational Database Management System (RDBMS) that uses Structured Query Language (SQL).
libapache2-mod-php: the PHP extension for apache
PHP gd,PHP curl,PHP-XML: extensions that drupal requires.The list can be found using the apt-cache command.Besides, drupal will alert you if they aren't installed during drupal's configuration.
adding -y at the end will make it so that you are not prompted again and again for confirming the installation.
apt-get install apache2 php php-mysql mysql-client mysql-server libapache2-mod-php php-gd php-curl php-xml   -y  (installing LAMP manually)

         Note: I initially had used tasks to install the lamp server, where you only have to type two commands.However, it didn't work properly for me, so I restarted using the above command where each component of  LAMP is installed manually. I think I may have had a problem because tasksel trying to install php5 instead of PHP 7.0, but I'm not sure.If you want to try the easy way, type the following command:

apt-get install tasksel(install tasksel tool)
tasksel install lamp-server (tell tasksel tool to install lamp)





STEP2

Now that we have installed LAMP, we need to setup the database for Drupal for in Mysql and configure the php.ini file.Use the following commands to connect to the MySQL shell and run the following commands to create the database, database user and to set permission for database user:-

mysql -u root -p (start mysql)
CREATE USER drupal@localhost IDENTIFIED BY "123";(create user named drupal with password 123)
create database drupal;(create database named drupal )

GRANT ALL ON drupal.* TO drupal@localhost;(grant all priveleges on the drupal database to the user named drupal)

FLUSH PRIVILEGES;(reload privelages)

exit    (exit mysql)



Now edit the php.ini file located in the path /etc/php/7.0/apache2 and search for the expose_php and allow_url_fopen parameter inside the php.ini file and set it ‘off ‘ for both option. Then remove the semicolon(;) before the parameter ‘extension=msql.so’

 vim /etc/php/7.0/apache2/php.ini(open php.ini file in vim editor)
expose_php=off( This is not a command!. This and the other two lines are fields you have to edit.)
allow_url_fopen=off
extension=msql.so
When you have finished editing, press the Esc key, then press the colon (:) key to enter command mode. Then press x and press the Enter key.This will save the file and close it at the same time.


STEP 3

Now Open the apache2.conf file located in /etc/apache2 and change AllowOverride None to AllowOverride all for all the parameters.


vim /etc/apache2/apache2.conf(open apache.conf file in vim editor)
AllowOverride all
After that, we have to enable the rewrite functionality for the Apache server. After enabling we have to restart the service for apache.

a2enmod rewrite(activate mod rewrite module)
service apache2 restart(restart apache's service)


STEP 4
Use the following link to download drupal by using the wget command
https://www.drupal.org/project/drupal


wget https://ftp.drupal.org/files/projects/drupal-8.2.4.tar.gz download the drupal zip)
After that use the following command to extract the files:

tar -zxf drupal-8.2.4.tar.gz(extract drupal zip)


 STEP 5


Now we have to create a directory for drupal.Then we have to copy the extracted files and .htaccess files into it. The file ‘.htaccess’ is responsible for redirecting the links to our website.

mkdir /var/www/html/drupal (make directory named drupal)
cp -R drupal-8.2.4/* drupal-8.2.4/.htaccess /var/www/html/drupal/(copy files to our new directory)
We are required to create a subdirectory in the default site installation directory. It is used by the files such as custom logos, site photos and other media associated with our new site.

mkdir /var/www/html/drupal/sites/default/files(make directory named files)

chown www-data:www-data /var/www/html/drupal/sites/default/files
(change owner of files)

We are also required to create the initial configuration files for the default site and to restart the services.

cp /var/www/html/drupal/sites/default/default.settings.php /var/www/html/drupal/sites/default/settings.php(copy files)

chown www-data:www-data /var/www/html/drupal/sites/default/settings.php(change owner of file)


 STEP 6



Now we have to navigate to either  http://yourdomain.com/drupal or HTTP://<your-ip-address>/drupal
select your language


 Now select the installation profile that suits you and click save and continue.


select your preferred installation profile.

At this point, I encountered two errors.One, my PHPextensions were disabled.Two, clearurls were disabled.

To solve the first error, I ran the following commands:


 apt-get install php-xml(enable xml extension)

 apt-get install php-gd(enable GD extensiom)

To solve the clear URLs problem, I opened the apache.conf file using the following command:

vim /etc/apache2/apache2.conf(open apache.conf in vim editor)

then edited the following fields:

<Directory /usr/share/drupal8/>
 Options +FollowSymLinks
 AllowOverride All
 order allow,deny
 allow from all
</Directory>
 everywhere where there is 'none' in your file in that field, replace by 'all'.

save and exit using the following key sequence:  {Esc},{:},{x},{Enter}



after that we have to restart apache, run another command, and restart again:

service apache2 restart(restart apache's service)

a2enmod rewrite(enable mod rewrite module)

service apache2 restart(restart apache's service)

Next, re-open HTTP://<your-ip-address>/drupal and continue like before, then you will see the following page, where you have to fill out the fields.


enter your details


 After that, configure your site as needed, and you're done.
Hooray!


Thank you for following along through-out my blog, hopefully it helped you install and configure drupal.