Posts

Showing posts from April, 2017

Difference between hook_boot and hook_init Drupal

HOOK_BOOT Even cached page executes this hook This hook is called before modules or most include files are loaded into memory. It happens while Drupal is still in bootstrap mode. HOOK_INIT Cached page doesn’t run this hook. When this hook is called, all modules are already loaded in memory. It happens after bootstrap mode.

Use of template.php

The template.php file contains your sub-theme's functions to manipulate Drupal's default markup. It is one of the most useful files when creating or modifying Drupal themes. With this file you can do three things: Modify any theme hooks variables or add your own variables, using preprocess or process functions. Override any theme function. That is, replace a module's default theme function with one you write. Call  hook_ * _alter ( )  functions which allow you to alter various parts of Drupal's internals, including the render elements in forms. The most useful of which include  hook_form_alter ( ) ,  hook_form_FORM_ID_alter ( ) , and  hook_page_alter ( ) . See  api.drupal.org  for more information about _alter functions.

Install Varnish in Drupal 7

Learn Installation of Varnish Cache Server for Drupal 7 in few Steps.  1. Update Apt-get  sudo apt-get update 2.Install Varnish  sudo apt-get install varnish 3.Edit your Varnish Page sudo vi /etc/default/varnish Add this to the top of the file to start varnishd at boot: START=yes Then look for these settings and edit to match: DAEMON_OPTS="-a :80 \ -T localhost:6082 \ -f /etc/varnish/default.vcl \ -S /etc/varnish/secret \ -s file,/var/lib/varnish/$INSTANCE/varnish_storage.bin,128M" 4. Now Edit ports.conf file  sudo vi /etc/apache2/ports.conf Update settings to match: NameVirtualHost *:8080 Listen 8080 4. Also Edit default file sudo vi /etc/apache2/sites-availbable/default Update settings to match: <VirtualHost *:8080> 5. Restart Apache2 and Varnish Servers sudo service apache2 restart sudo service varnish restart 6. Update default.vcl file  sudo vi /etc/varnish/default.vcl backend default { .host = "127.0.0.1"; .port = ...

How to create custom module in Drupal 8

In Drupal 8, we should keep the custom or contributed modules under modules folder in the root directory. First of all I am going to create a folder for custom module that is "Custom Module" with a machine name of custom_module. Start the module by creating a folder within the Drupal installation and path is: /modules/custom/custom_module or /sites/all/modules/custom/custom_module. custom_module.info.yml  : Now Creating the "custom_module.info.yml" in the root of the custom_module directory. 1. File: modules/custom/custom_module/custom_module.info.yml: File: modules/custom/custom_module/custom_module.info. yml:  name: My custom module name description: Creates a page showing "Hello World" . package: Custom type: module core: 8 .x 2. File: modules/custom/custom_module/custom_module.module: This file is required but can be empty. <?php /**  * @file  * Hello module.  */ 3. File: modules/custom/custom_module/custom_module...

Difference between DBMS and RDBMS?

No. DBMS RDBMS 1) DBMS applications store  data as file . RDBMS applications store  data in a tabular form . 2) In DBMS, data is generally stored in either a hierarchical form or a navigational form. In RDBMS, the tables have an identifier called primary key and the data values are stored in the form of tables. 3) Normalization is not  present in DBMS. Normalization is  present in RDBMS. 4) DBMS does  not apply any security  with regards to data manipulation. RDBMS  defines the integrity constraint  for the purpose of ACID (Atomocity, Consistency, Isolation and Durability) property. 5) DBMS uses file system to store data, so there will be  no relation between the tables . in RDBMS, data values are stored in the form of tables, so a  relationship  between these data values will be stored in the form of a table as well. 6) DBMS has to provide some uniform methods to access the stored information. RDBMS system supports a tabula...

What's the difference between MyISAM and InnoDB?

MYISAM: MYISAM supports Table-level Locking MyISAM designed for need of speed MyISAM does not support foreign keys hence we call MySQL with MYISAM is DBMS MyISAM stores its tables, data and indexes in diskspace using separate three different files. (tablename.FRM, tablename.MYD, tablename.MYI) MYISAM not supports transaction. You cannot commit and rollback with MYISAM. Once you issue a command it’s done. MYISAM supports fulltext search You can use MyISAM, if the table is more static with lots of select and less update and delete. INNODB: InnoDB supports Row-level Locking InnoDB designed for maximum performance when processing high volume of data InnoDB support foreign keys hence we call MySQL with InnoDB is RDBMS InnoDB stores its tables and indexes in a tablespace InnoDB supports transaction. You can commit and rollback with InnoDB

Update node in Drupal 7

update node // Return all nids of nodes of type "page". $nids = db_select('node', 'n') ->fields('n', array('nid')) ->fields('n', array('type')) ->condition('n.type', 'type') ->execute() ->fetchCol(); // returns an indexed array foreach($nids as $nids){ $node = node_load($nids); if (isset($node)) { $node->field_external_program_id_['und'][0]['value'] = $nids; node_save($node); } } 

Cut string in php

function getlastWords($string, $words = 1) {     $string = explode(' ', $string);     if (count($string) > $words)     {         return implode(' ', array_slice($string, 518, $words));     }     return implode(' ', $string); } ----------------------------------------------------------------------------------------------------------- function getFirstWords($string, $words = 1) {     $string = explode(' ', $string);     if (count($string) > $words)     {         return implode(' ', array_slice($string, 0, $words));     }     return implode(' ', $string); }

Connect Amazon sever

Connect with AWS server ssh -i h4h.pem ubuntu@partners.holidaysforhumanity.com Make Zip folder zip -r compressed_filename.zip foldername Add folder Mkdir folder name Remove file rm file-name Rename file mv payment.module payment.modulebkkkk Copy file local to remote server scp -r -i h4h.pem sites/all/themes/h4h/img/Simple-Plans.jpg.zip  ubuntu@partners.holidaysforhumanity.com:/tmp Copy file remote server to local scp -r -i h4h.pem ubuntu@partners.holidaysforhumanity.com:/tmp/default.zip  /var/www/html/h4h-live