Showing posts with label Drupal. Show all posts
Showing posts with label Drupal. Show all posts

Tuesday, March 25, 2014

PDOException: Invalid text representation

Error:
The website encountered an unexpected error. Please try again later. [PDOException: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "as" LINE 5: WHERE (base.nid IN ('as')) ^: ..... (line 191 of/var/www/html/drupal/includes/entity.inc).]

Solution: 
Drupal throws PDO exception error like above while giving url patterns like,
localhost/drupal/node/abc
localhost/drupal/node/1.
localhost/drupal/node/1.23
localhost/drupal/node/<any special characters like *&^%$#@!>
This because of invalid input for select query while it is expecting integer. This is core level bug and the wrong input needs to be filtered in entity.inc of core module.
//add the below lines inside function load() in entity.inc.
//Patch to avoid non numeric node id's which causes pdo exceptions
if (is_array($ids)) {
        // Remove all non numeric ids.
        $ids = array_filter($ids, function($x){
                return preg_match('/^[0-9]+$/', $x);
        });
}

Thursday, August 8, 2013

Drupal PDO error : Invalid input syntax for integer

Error:

        PDOException: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer:

Reason:

Drupal will not recognize the node URL when the node id is not an integer. This will happens when URL like node/abc instead of node/12. It fails to get the desired node URL location from the database. It's bug of Drupal Core.

Solution:

To filter out the non numeric node id's from the URL from executing use the below patch in Drupal core file called includes/entity.inc. Add the lines as first in function called load().

    public function load($ids = array(), $conditions = array()) {
        //Add the below code patch

        //-----Patch Start----

        if (is_array($ids)) {
        // Removes all non numeric ids.
        $ids = array_filter($ids, function($x){
                return preg_match('/^[0-9]+$/', $x);
                });
        }

        //-----Patch End----
        $entities = array();


Tuesday, July 3, 2012

Postgresql 9.x to 8.x restore issue with bytea field contains hex values

Error:
  • Warning: Invalid argument supplied for foreach() in list_themes() (line 780 of /var/www/html/drupal/includes/theme.inc).
  • Warning: Invalid argument supplied for foreach() in system_region_list() (line 2709 of /var/www/html/drupal/modules/system/system.module).
  • PHP Notice:  unserialize(): Error at offset 0 of 1009 bytes in /var/www/html/drupal/includes/cache.inc on line 447
  • PHP Notice:  unserialize(): Error at offset 0 of 296805 bytes in /var/www/html/drupal/includes/cache.inc on line 447
  • PHP Warning:  Invalid argument supplied for foreach() in /var/www/html/drupal/includes/module.inc on line 185
  • PHP Warning:  array_keys() expects parameter 1 to be array, null given in /var/www/html/drupal/includes/module.inc on line 89
  • PHP Notice:  unserialize(): Error at offset 0 of 296805 bytes in /var/www/html/drupal/includes/cache.inc on line 447
  • PHP Warning:  Invalid argument supplied for foreach() in /var/www/html/drupal/includes/module.inc on line 185
  • PHP Warning:  array_keys() expects parameter 1 to be array, null given in /var/www/html/drupal/includes/module.inc on line 89
  • PHP Fatal error:  Call to undefined function system_run_automated_cron() in /var/www/html/drupal/includes/common.inc on line 2614
Reason:
This will occurs when we try to host our project in a new location.  In that time, we take backup of code and database to relocate. This makes the problem.

In the case of PostgreSQL, version 9.x has two output formats called 'hex' and 'escape'. This is the setting to decide the output format of our raw data's stored in database. In case of bytea, the values are in binary format and that should be exported properly to understand by others (either it may be PHP or PostgreSQL server).

Restoring in same PostgreSQL version is not a problem. If it is lower version compared to source, then it makes issue. Because the 'hex' format used by 9.x can't understand by lower versions some time. So these should be exported properly.

Solution:
Note : Do this in server machine from where you going to take PostgreSQL backup.


The output format can be set by editing "postgresql.conf" file located in PostgreSQL installation directory. In that, add the line like,
bytea_output = 'escape'
 and restart the PostgreSQL service once.

This will give us the escaped output of bytea data's while backing up as well as querying from programming languages like PHP.

Now take the backup and restore it in lower version as follows

For plain backup use console import using the command '\i' and 
for tar backup user higher version of PG ADMIN to restore it.

For Drupal applications,
Clear the cache tables to remove the existing cached values by executing the following,
truncate cache;
truncate cache_block;
truncate cache_bootstrap;
truncate cache_field;
truncate cache_filter;
truncate cache_form;
truncate cache_image;
truncate cache_menu;
truncate cache_page;
truncate cache_path;
truncate cache_update;
truncate cache_views;
truncate cache_views_data;
Additional workaround:
Even if it is not working then do the following. This is optional only not mandatory one.
Edit the sites/default/settings.php and make the setting as 
$update_free_access = TRUE;
and then run following the commands in console like
$ cd /var/www/drupal/
$ php update.php
$ php cron.php
and run the application again. Still error persist, then repeat the steps from scratch once.

Note: This is tested under Ubuntu 10.04 and Cent OS 6.

Thursday, September 22, 2011

Timeout error while signup new user in Drupal 6

Error:
           No response from the server side and time out error comes after 3 to 5 min after submitting the signup form in Drupal 6. But the user were created correctly without the response.


Reason:  
           I have configured Postfix and Stunnel4 in my system (Redhat) for mailing purpose. But the host name was not configured correctly. So that the Drupal script waits long time for the response from the Postfix server. This was caused the timeout error.


Solution:
          Check and make sure the '/etc/hosts' and Postfix server configuration file (normally in /etc/postfix) for valid host name or IP of your server.  Default configuration of Postfix doesn't make any problem. If you have changed anything in '/etc/hosts' file or or Postfix config file will make errors like this.



Tuesday, August 9, 2011

Div tag alignment problem in Drupal

Problem:


While editing template files in Drupal, div tags that contains footer links may not be displayed in order (ie. expected location where that div tag should be).


Solution:


Add this line of code  in between the footer and main-container tags <div class="clr"></div>


Note : 
           This may vary to theme by theme.

Friday, June 17, 2011

Multi-site configuration


Example 1:
  1. Create dns entries for the sites ( or use hosts file for testing)
  2. Create vhosts in Apache configuration file and restart Apache:
            Listen 80

            DocumentRoot "C:/Program Files/xampp/htdocs"
            ServerName localhost:80

            DocumentRoot "C:/Program Files/xampp/htdocs"
            ServerName www.site1.local:80

            DocumentRoot "C:/Program Files/xampp/htdocs"
            ServerName www.site2.local:80
  1. Create folder sites under drupal/sites
    www.site1.local www.site2.local
        Note: Each site folder can have a file, tmp, modules and themes subfolders.
  1. Copy settings.php from drupal/sites/default to each site folder. Modify $db_url and $db_prefix in settings.php in each site folder.
        For www.site1.local: Single database and db user.
        $db_url = 'mysql://drupal:drupal@localhost/drupal';        
        $db_prefix = 'site1_';
        For www.site2.local: Single database and single db user.
        $db_url = 'mysql://drupal:drupal@localhost/drupal';        
        $db_prefix = 'site2_';
        For www.site1.local: Multiple databases and single db user.
        $db_url = 'mysql://drupal:drupal@localhost/site1';        
        $db_prefix = '';
        For www.site2.local: Multiple databases and single db user.
        $db_url = 'mysql://drupal:drupal@localhost/site2';        
        $db_prefix = '';
        Note: Always use the same db user (the one that you used to install drupal for the first time) independently if you want to have a single or multiples db’s.
  1. Open your web browser and point to the install.php file for each site
        http://www.site1.local/drupal/install.php
        http://www.site2.local/drupal/install.php
  1. Edit the /etc/hosts and add the following lines
        10.123.11.61 www.site1.local
        10.123.11.61 www.site2.local
  1. Your new sites are ready using a single code base, single db user and single or multiple db’s.
        http://www.site1.local/drupal/
        http://www.site2.local/drupal/


Example 2:
    1. Create folder sites under drupal/sites
          www.site1.local www.site2.local
    2. /etc/apache2/sites-available/site1.local will be
                                DocumentRoot /var/www/drupal613multisite
                                ServerName www.site1.local
                                ErrorLog /var/log/apache2/error.log
    1. Make link to ln -s /etc/apache2/sites-available/site1.local /etc/apache2/sites-enabled/site1.local
    2. /etc/apache2/sites-available/site2.local will be
                                DocumentRoot /var/www/drupal613multisite               
                                ServerName www.site2.local
                                ErrorLog /var/log/apache2/error.log               
    1. Make link to ln -s /etc/apache2/sites-available/site2.local /etc/apache2/sites-enabled/site2.local
    2. Edit the /etc/hosts and add the following lines
                10.123.11.61 www.site1.local
                10.123.11.61 www.site2.local
    1. In /etc/apache2/sites-available/default add the following line in top of the file
                NameVirtualHost *
    1. Restart apache server.
    2. Run http://www.site1.local and http://www.site2.local

Tuesday, June 2, 2009

Err: Page never gets redirected to main page after save/update has been done in Drupal



  1. $form_state['redirect'] has to be set
  2. Return statement is must
  3. form_state argument should be given as call by reference

Err: Retaining/populating of the value does not change in Drupal while edit form

While: Editing the form


Error:
    Retaining/populating of the value does not change

Reason and Solution: 
        #value property means that final value. So while edit, to populate the values in respective boxes use #default_value.


Tuesday, May 19, 2009

Err: Cannot unset string offsets in /form.inc on line 485


Error:
    Fatal error: Cannot unset string offsets in /var/www/drupal6/includes/form.inc on line 485

Solution:
    Using of 'page callback' => 'drupal_get_form' while no form is required will throw this error. Remove that line and run.