Update File Path in Drupal

We have a site that we had been migrating since Drupal 4. Few days back when we tried to migrate the same from Drupal 6 to Drupal 7. There was an issue with respect to file location that was present since previous upgrades. To resolve that a symlink was created called "files" with linked to sites/default/files during D6 upgrade. This led to first loss of many files as Drupal does not handle symlink based file saving well. Secondly the files created were saved under public://files/filename.ext instead of public:://filename.ext which caused created files not being accessible.

Saving Form Selection using Form API

During custom form submission we would want to remember the previous selection. There are many ways to do that, which includes using Sessions and variable_set to set the default value but this is an overkill if you wanted to simply preserve/remember the selection in the next page or after submission. The best way is to use $form_state['storage'] in your submit handler to hoard values between steps.

Consider an example:
function custom_form_submit($form, &$form_state) {
$start_date = $form_state['values']['startdate'];
$end_date = $form_state['values']['enddate'];

Executing PHP in command line


There are times when one needs to execute PHP in command like, for example trying the date command output or a one line execution. For trivial tasks, executing the same at the command line without the need for writing and executing at a file level is a great tool for time saving.

The argument to be used is : -r


php -r '
$a = range(0,2);
foreach($a as $b) {
   echo "entry: $b\n";

The output is:
entry: 0
entry: 1
entry: 2

Another example:
php -r '
> echo date("d-m-Y");
> echo "\n";
> '

Add www to URL using Apache mod_rewrite

For sites belonging to a domain name(Not Subdomain), one can access the site using the domain name with www, Ex: www.example.com or without it: example.com

Both ways the site can be accessed when a ServerAlias is created in the config. However this is confusing as session information for both is different, which means if one is accessing the site with www preceded and logs in, on accessing the site without www preceded - the server would have no information saved.

To redirect any domain name to use www by default, the following mod_rewrite condition can be used:

Executing Views Bulk Operations Using Drush

Many times we use Views Buk Operations with Batch Api for doing a big set of operations. When the count of operations is huge, even Batch API gets short. A faster and more efficient way to do that is using drush to do the heavy backlifting.

The commands are:

vbo-execute      Execute a bulk operation based on a Views Bulk Operations (VBO) view.                                                   
vbo-list             List all Views Bulk Operations (VBO) views, along with the operations associated with each.


SVN: Creating a Repository and Migration


Creating a Repository
There are loads of documentation in creating a Repository. Provided below is an example VHOST config file for SVN:

<VirtualHost *:80>
ServerName svn.example.com
DocumentRoot /home/svn/
<Location /svn/example>
  DAV svn
  SVNPath /home/svn/reponame
#  SVNParentPath /var/svn/
  AuthType Basic
  AuthName "Example Repository"
  AuthUserFile /etc/subversion/passwd
  Require valid-user
ErrorLog /home/svn/logs/error.log
CustomLog /home/svn/logs/access.log combined

Handling Unwanted Stuff


This is not a post for handling SPAM.

Please find the following Softwares you would need to install.
1. ModSecurity supplies an array of request filtering and other security features to the Apache HTTP Server, IIS and NGINX. ModSecurity is a web application layer firewall.
2. Mod_evasive prevents against ddos and scripted bots which can hammer a website. Mod_evasive is the Web Denial of Service module used in ASL. It is designed to throttle http and https connections when they reach above a specified threshold.

Disabling Munin and Awstats

Munin is a server and network monitoring tool. AWStats is a free powerful and featureful tool that generates advanced web, streaming, ftp or mail server statistics, graphically. This log analyzer works as a CGI or from command line and shows you all possible information your log contains, in few graphical web pages.

Sometimes both can result in High Server i/o due to its periodic cron tasks. Uninstalling via command line wont help as you may see cron based tasks for Munin and Awstats running in logs.