Category: Tips & Tricks

Drupal CRON – access denied when Apache Solr module is installed

headIn one of our Drupal projects, when the CRON URL was accessed it was showing the Access Denied page. After doing some R&D we found that the issue was due to the Apache Solr module. The Apache Solr module’s CRON function was failing to index nodes. Finally we found the reason why this was failing and redirecting to Access Denied page. The reason was we had implemented the hook_node_view() to check permission when content of a particular type was accessed. So, when Apache Solr tried to index content of this type, it was failing to do so due to the permission required to view the content. It then redirected the call to access denied page. After bypassing the code in hook_node_view() with the following condition it started working.

'search_index' != $view_mode

FYI, $view_mode is the second parameter of hook_node_view().

The following link gave us an idea about the issue.

http://www.blinkreaction.com/blog/be-aware-nodes-with-php-code-and-drupal-search-index

Share

OpenERP: Module showing in Windows installation but not in Linux installation

logo_openerpA few days back I was working on an OpenERP project. I had to develop a module for it. I created a module and it was working fine is my Windows machine. When I uploaded the module to Linux installation, I could not find the module in the module list. I double checked if it is uploaded in correct directory or not… it’s in the right place. Tried with updating the module list several times… no luck!

Then one thought came in my mind. In one of my previous projects I faced an issue (though that was not an OpenERP project). It was related to end of line (EOL) character. I checked the module files and found that it was using Windows EOL characters CRLF. I changed the character to Unix EOL character LF. Uploaded the files again on Linux server, restarted server, updated module list and found the module in the list.

How I changed the character?

I have used Notepad++ to do this task. You may follow the following steps to do this:

  • Download and install Notepad++ if you do not have it.
  • Open the module file.
  • To view the EOL character go to View menu > Show symbol > Show End of Line.
  • If the EOl is CRLF then proceed to next steps. If the character is LF then no need to change.
  • To change the EOL to Unix format, go to Edit > EOL Conversion > Unix format. You will see the EOL changed from CRLF to LF.

That’s it!

Share

SSL (HTTPS) URLs and CodeIgniter (Extending the core)

CodeIgniterIn one of my previous post I have shown how we can use both secure and non-secure URLs. Now I am going to show how we can do this, extending native libraries.
What we are going to do…
We will create secure version of some functions. For this we will create a helper file ‘my_url_helper.php’ and save it in ‘system/application/helpers’. We will be creating secure version of following functions:
  • site_url()
  • base_url()
  • anchor()
  • redirect()
Lets’ start…
First we will add the following config element in the config file:
$config['secure_base_url'] = 'https://example.com';
Then, open the my_url_helper.php file (system/application/helpers/my_url_helper.php) and add the following codes.
if( ! function_exists('secure_site_url') )
{
    function secure_site_url($uri = '')
    {
        $CI =& get_instance();
        return $CI->config->secure_site_url($uri);
    }
}
 
if( ! function_exists('secure_base_url') )
{
    function secure_base_url()
    {
        $CI =& get_instance();
        return $CI->config->slash_item('secure_base_url');
    }
}
 
if ( ! function_exists('secure_anchor'))
{
    function secure_anchor($uri = '', $title = '', $attributes = '')
    {
        $title = (string) $title;
 
        if ( ! is_array($uri))
        {
            $secure_site_url = ( ! preg_match('!^\w+://! i', $uri)) ? secure_site_url($uri) : $uri;
        }
        else
        {
            $secure_site_url = secure_site_url($uri);
        }
 
        if ($title == '')
        {
            $title = $secure_site_url;
        }
 
        if ($attributes != '')
        {
            $attributes = _parse_attributes($attributes);
        }
 
        return '<a href="'.$secure_site_url.'" ' . $attributes . '>'.$title.'</a>';
    }
}
 
if ( ! function_exists('secure_redirect'))
{
    function secure_redirect($uri = '', $method = 'location', $http_response_code = 302)
    {
        switch($method)
        {
            case 'refresh'    : header("Refresh:0;url=".secure_site_url($uri));
                                break;
            default           : header("Location: ".secure_site_url($uri), TRUE, $http_response_code);
                                break;
        }
        exit;
    }
}
Now, I will extend the Config library (system/libraries/Config.php). I assume that the sub class prefix is set as ‘MY_’ in config file (system/application/config/config.php). Create a file ‘MY_Config.php’ in ‘system/application/libraries’ folder and save the file with following code.
class MY_Config extends CI_Config
{
    function MY_Config()
    {
        parent::CI_Config();
    }
 
    function secure_site_url($uri = '')
    {
        if (is_array($uri))
        {
            $uri = implode('/', $uri);
        }
 
        if ($uri == '')
        {
            return $this-&gt;slash_item('secure_base_url').$this-&gt;item('index_page');
        }
        else
        {
            $suffix = ($this-&gt;item('url_suffix') == FALSE) ? '' : $this-&gt;item('url_suffix');
            return $this-&gt;slash_item('secure_base_url').$this-&gt;slash_item('index_page').preg_replace("|^/*(.+?)/*$|", "\\1", $uri).$suffix;
        }
    }
}
Now what we have…
Now we have secured versions of those function. You may now use them as their insecured version. Enjoy coding ;).
Share
blog