Install Postgres On Ubuntu

Start with Installing PostgreSQL
sudo apt-get install postgresql postgresql-contrib

Next step: Login with admin user    sudo -u postgres psql

\du : to check user available in PostgreSQL

Then change the user Password with Alter user commend.

ALTER USER postgres WITH PASSWORD ‘newpassword’;
you can add a new user with commend :
createuser [connection-option…] [option…] [username]
Likewise you can add user and change there attributes and Password too.
To exit form PostgresSQL use this commend  postgres=#\q ;

Dealing with core Cache in Drupal 8

At this point, if you try to login in the Drupal 8 website you will be rejected, it’s because the login system doesn’t read directly the table users_field_data instead of a cache for entities is used.

To flush the cache for a specific user entity with compromise the rest of cache of your system you can use the following SQL statement.

DELETE FROM cache_entity WHERE cid = ‘values:user:1’;

Now you can grab a cup of coffee/tea and enjoy your Drupal 8 website.

Hope this will help you.

 

Resetting the administrator password with SQL-query in Drupal 8

It’s has been happening, that we tend to forget password on local as well for the live site. When it’s come to Drupal 8 all things has things changed from the prior version of Drupal.

Here we go with some of the tricks for Drupal 8.

The Solution
Generate a new password
First, you have to generate a password hash that is valid for your site.

Execute the following commands from the command line, in the Drupal 8 root directory:

$ php core/scripts/password-hash.sh ‘your-new-pass-here’

password: your-new-pass-here    hash: $S$EV4QAYSIc9XNZD9GMNDwMpMJXPJzz1J2dkSH6KIGiAVXvREBy.9E

Update the user password.

Now you need to update the user password, in our case, we need to update the Administrator password, fortunately, the UID for Administrator is 1 equal to previous versions of Drupal.

With the new password, we need run the following SQL statement.

UPDATE users_field_data SET pass=’$S$E5j59pCS9kjQ8P/M1aUCKuF4UUIp.dXjrHyvnE4PerAVJ93bIu4U’ WHERE uid = 1;

We all set with password update and go… log in!

Page Rendering and Altering in Drupal

Step 1: The Router Item
After Drupal has been bootstrapped, the last thing index.php does is call
menu_execute_active_handler(). This retrieves the router item from the menu_router based on the
current path. There is an important chance here to intervene, hook_menu_item_alter()

Step 2: The Page Callback Is Fired
For example, the default home page returns this:
$build[‘default_message’] = array(
  ‘#markup’ => “<p>No front page content has been created yet.</p>”,
  ‘#prefix’ => ‘ ‘,
  ‘#suffix’ => ‘ ‘,
);

Step 3: The Delivery Callback

Now you are back in menu_execute_active_handler(). The next callback to fire is the delivery callback,
which defaults to drupal_deliver_html_page(). As the name suggests, by default you are delivering the
page callback results in HTML.

function overlay_deliver_empty_page() {
  $empty_page = ‘<html><head><title></title>’ . drupal_get_css() . drupal_get_js() .
  ‘</head><body class=”overlay”></body></html>’;
  print $empty_page;
  drupal_exit();
}

Step 4: drupal_render_page()

First, hook_page_build() is called, which allows other modules to add to the page array—because
here you build that. Your modules can add to the page array, also. Second, hook_page_alter() is fired.

Step 5. hook_page_alter()

Perform alterations before a page is rendered.

Use this hook when you want to remove or alter elements at the page level, or add elements at the page level that depend on an other module’s elements (this hook runs after hook_page_build().
For Example Page rendar hook :

function dgd7_page_alter(&$page) {
 if ($node = menu_get_object()) {
  $comments = &$page[‘content’][‘system_main’][‘nodes’][$node->nid][‘comments’][‘comments’];
  $comments[‘ad’] = dgd7_get_ad();
  // The first comment weight is 0, the second is 1, go between them.
  unset($comments[‘#sorted’]);
  $comments[‘ad’][‘#weight’] = 0.5;
 }
}
function dgd7_get_ad() {
  return array(‘#markup’ => t(‘Hello I am an ad!’));
}

Step 6. drupal_render()
This is a recursive function called on every child of the page array. So you start with running
drupal_render($page), then continue with drupal_render($page[‘content’]), then with
drupal_render($page[‘content’][‘system_main’]), and finally with
drupal_render($page[‘content’][‘system_main’][‘default_message’]).

So for example:
$element[‘#cache’] = array(
  ‘cid’ => ‘foo:bar’,
  ‘bin’ => ‘cache_something’,
  ‘expire” => 900,
);

Vim Plugin for Drupal on Linux

Indentation

The following commands will indent your code the right amount, using spaces rather than tabs and automatically indent after you start. The commands should be added to a .vimrc file in your home directory (~/.vimrc), you may need to create this.
set expandtab
set tabstop=2
set shiftwidth=2
set autoindent
set smartindent

Syntax highlighting

If you enjoy syntax highlighting, it may be worth remembering that many of Drupal’s PHP files are *.module or *.inc, among others.

Vim seems to syntax highlight *.inc files properly by default but doesn’t know that some other files are PHP content. For *.module and *.install, use this snippet in .vimrc:
if has(“autocmd”)
” Drupal *.module and *.install files.
augroup module
autocmd BufRead,BufNewFile *.module set filetype=php
autocmd BufRead,BufNewFile *.install set filetype=php
autocmd BufRead,BufNewFile *.test set filetype=php
autocmd BufRead,BufNewFile *.inc set filetype=php
autocmd BufRead,BufNewFile *.profile set filetype=php
autocmd BufRead,BufNewFile *.view set filetype=php
augroup END
endif
syntax on

more can be done its all open source.. it’s upto you 🙂

Getting Rid Of Magento ReIndexing Errors

If even after trying multiple times Magento Indexer fails to respond or keep throwing same errors you can take the following steps resolve Magento ReIndexing errors.

1. Locate var/locks directory and remove all files under this directory. This will clear all the locks for re-indexing to take place again.

2. Now, login to your MysQSL/phpMyAdmin to run the following MySQL query (Ensure that your have taken full backup before committing this MySQL que

DELETE cpop.* FROM catalog_product_option_price AS cpop
INNER JOIN catalog_product_option AS cpo
ON cpo.option_id = cpop.option_id
WHERE
cpo.type = ‘checkbox’ OR
cpo.type = ‘radio’ OR
cpo.type = ‘drop_down’;

DELETE cpotp.* FROM catalog_product_option_type_price AS cpotp
INNER JOIN catalog_product_option_type_value AS cpotv
ON cpotv.option_type_id = cpotp.option_type_id
INNER JOIN catalog_product_option AS cpo
ON cpotv.option_id = cpo.option_id
WHERE

*hope above will helps 🙂

Programmatically Adding a Field Collection Item to a exiting Node in Drupal

In such case where you need to add field item to a node like text,link field's in a node for drupal 7


function my_custom_module_field_collection($nid, $fid){
   // Load target node
   $node = node_load($nid);

   // Create a new field collection 
   $fieldCollectionItem = entity_create('field_collection_item', array('field_name' => 'my_field_collection_item_name'));

   // Prepare link field
   $link = array(
      'title' => "",
      'url' => "",
      'attributes' => array(
         'title' => "",
      ),
   );

   // Prepare file 
   $file = (array)file_load($fid);
   $file['display'] = "1";

   // Load items into field collection
$fieldCollectionItem->field_image[LANGUAGE_NONE][] = $file;

$fieldCollectionItem->field_link[LANGUAGE_NONE][] = $link; // Save field collection item

$fieldCollectionItem->setHostEntity('node', $node);

$fieldCollectionItem->save(TRUE); node_save($node);
 
}

 

Disable Outgoing Mail in Drupal 7

/**
* Implements hook_mail_alter
*/
function yourmodule_mail_alter(&$message) {
// set ‘To’ field to nothing, so Drupal won’t have any address
$message[‘to’] = ‘ ‘;
}

Other Way you can do

If using devel with drupal 6, add to settings.php
$conf[‘smtp_library’] = ‘sites/all/modules/devel/devel.module’;

and all outgoing emails get logged in watchdog.

If using devel with in drupal 7, if you add
$conf[‘mail_system’] = array(‘default-system’ => ‘DevelMailLog’);

emails get written to files in the drupal temporary directory.


Re-route All Emails Using Reroute Email Module

Download and install the Reroute Email module.

Go to Configuration-> Reroute Email (admin/config/development/reroute_email).

And  than Check the Enable rerouting checkbox and enter in an email address into the Email addresses text field.

 

 

 

Steps to follow for query tuning

Few steps for query tuning.

1)  Check for if any sub query or exists or not exists is there if yes then try to change it in the joins .

2)  Try to check the way joins had been written try to put it in format to follow one to many relation ship and joins are in primary to foreign keys.

3)  if dead locks are happening due try to implement the serialization or try to use hint with (nolock) with select statement and with (rowlock) with insert update and delete statement.

There are many more way to do.

File system and mysql backup on shared hosting

Create two php files and upload to server. Following script will compress your files and able to take mysql backup in gzip format.

Before this create phpinfo.php file and add following code.

<?php

phpinfo();

?>

gzipfile.php
<?php
$Command = 'tar -czf /public_html/content/html/website.tgz /public_html/content/html';
exec($Command, $output, $result);
if($result > 0) {
echo 'Command not executed. ';
echo 'Error Details:'.$output;
} else {
echo 'Command executed sucesfully.';
}
?>

create mysqlbackup.php  file and add following lines.

<?php
$Command = 'mysqldump -udbusername -pdbpassword -hyour_database_hostname DBname | gzip > DBname.gz';

exec($Command, $output, $result);
if($result > 0) {
echo 'Command not executed. ';
echo 'Error Details:'.$output;
} else {
echo 'Command executed sucesfully.';
}
?>