After updating our website to Drupal 6.9 we decided to use a new theme: Amor Azul. Everything works fine, except the display of 8 user warnings for every new or refreshed page. Better: if template.php is run. This is one of the warnings:

Duplicate entry 'Amor_Azul-block-1' for key 2 query: INSERT INTO blocks (module,delta,theme,status,weight,region,custom,throttle,visibility,pages,title) VALUES ('block', '1', 'Amor_Azul', 1, 0, 'footer_links', 0, 0, 0, '', '') in /home/httpd/vhosts/al-om.nl/httpdocs/sites/all/themes/Amor_Azul/template.php on line 239.

The problem is that template.php tries to insert the blocks content top, header images, header text and footer links into the table blocks and the corresponding boxes into the table boxes. These entries already exist. (I can see them, they were inserted the first time I used Amor Azul as a theme.)

With the litte knowledge I have of php I tried to find out if the function check_block is working. I think it is not: if I copy the SQL-statement to PhpMyAdmin I get the correct result (one row existing), but the function check_block always is true.

I fixed it by changing the >0 to >=0, but I doubt if this is the solution to the underlying problem...

Anyone recognizing this? Any other solutions?

CommentFileSizeAuthor
#2 New Picture.jpg200.98 KBedegids

Comments

info@zrix.com’s picture

We have checked at our end and have found that we are not getting any user warnings. To get to the root of the problem please send us the URL of your website, the admin login details of it. Alternatively you can send us a screenshot of the page.

edegids’s picture

StatusFileSize
new200.98 KB

A screendump of the user warnings on our website www.al-om.nl is attached. However, not all warnings (there are 8 of them) fit on one screendump. I can post a full list, but I don't think that is necessary because they all have the same structure.

I want to describe what we did to test the function check_block, maybe that helps. We changed the function to:

function check_block($bid,$theme)
{
$result = db_query("SELECT * FROM {blocks} WHERE delta = %d and theme = '%s' and module = 'block'", $bid, $theme);
$test = db_result($result);
print("
test $test");
if(db_result($result)>0)
{
return false;
}
else
{
return true;
}
}

The result is
test
block
test
block
test
block
test
block
on the top of the page, so db_result of the SQL-statement is 'block'? Is it possibly the reason for the user warning, that 'block'>0 is not a correct statement?

info@zrix.com’s picture

Thank you for getting back to us with the required information. Kindly replace the following code in template.php file:

if(check_block(3,'Amor_Azul'))
{
db_query(
        "INSERT INTO {blocks} (module,delta,theme,status,weight,region,custom,throttle,visibility,pages,title)
        VALUES ('%s', '%s', '%s', %d, %d, '%s', %d, %d, %d, '%s', '%s')",
        'block', '3', 'Amor_Azul', '1', '0', 'header_text', '0', '0', '0', '', ''
    );
    db_query("INSERT INTO {boxes} (bid, body, info, format) VALUES (%d, '%s', '%s', '%s')",
        '3',
        '<h1 class="header-title">Leo eu adipiscing eleifend</h1>

              Leo eu adipiscing eleifend, magna urna mattis nibh, sed consequat nisi nibh sit amet nunc. Nam neque. Nam a odio sed tellus mattis posuere. Cras mattis viverra metus. Fusce feugiat elementum metus. Maecenas euismod dignissim diam. Aliquam felis. Nulla augue turpis, euismod id, dictum sed, mollis et, quam. Pellentesque nisl. Cras faucibus ante in sem. Aenean porta diam molestie urna',
        'header text',
        '2'
    );
} 
if(check_block(4,'Amor_Azul'))
{

    db_query(
        "INSERT INTO {blocks} (module,delta,theme,status,weight,region,custom,throttle,visibility,pages,title)
        VALUES ('%s', '%s', '%s', %d, %d, '%s', %d, %d, %d, '%s', '%s')",
        'block', '4', 'Amor_Azul', '1', '0', 'header_image', '0', '0', '0', '', ''
    );
    db_query("INSERT INTO {boxes} (bid, body, info, format) VALUES (%d, '%s', '%s', '%s')",
        '4',
        '<img src="'.base_path().path_to_theme().'/images/header-image.jpg" alt="Girl" />',
        'header images',
        '2'
    );
}
if(check_block(1,'Amor_Azul'))
{
 
    db_query(
        "INSERT INTO {blocks} (module,delta,theme,status,weight,region,custom,throttle,visibility,pages,title)
        VALUES ('%s', '%s', '%s', %d, %d, '%s', %d, %d, %d, '%s', '%s')",
        'block', '1', 'Amor_Azul', '1', '0', 'footer_links', '0', '0', '0', '', ''
    );
    db_query("INSERT INTO {boxes} (bid, body, info, format) VALUES (%d, '%s', '%s', '%s')",
        '1',
        '<a href="#">Home</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#">About Us</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#">Services</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#">Contact Us</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
        'Footer Links',
        '2'
    );
}
if(check_block(2,'Amor_Azul'))
{
 
    db_query(
        "INSERT INTO {blocks} (module,delta,theme,status,weight,region,custom,throttle,visibility,pages,title)
        VALUES ('%s', '%s', '%s', %d, %d, '%s', %d, %d, %d, '%s', '%s')",
        'block', '2', 'Amor_Azul', '1', '0', 'content_top', '0', '0', '1', '<front>', ''
    );
    db_query("INSERT INTO {boxes} (bid, body, info, format) VALUES (%d, '%s', '%s', '%s')",
        '2',
        '<div class="cont-top1">

                    <h3>Cum sociis natoque penatibus</h3>

                    <img src="'.base_path().path_to_theme().'/images/home-top-img1.jpg" align="right"  alt="image" />Nunc nisi elit, sollicitudin volutpat, adipiscing eu, rutrum sed, ligula.

                </div>

                <div class="cont-top2">

                    <h3>Cum sociis natoque penatibus</h3>

                    <img src="'.base_path().path_to_theme().'/images/home-top-img2.jpg" align="right" alt="image" />Nunc nisi elit, sollicitudin volutpat, adipiscing eu, rutrum sed, ligula.

                </div>

                <div class="cont-top2">

                    <h3>Cum sociis natoque penatibus</h3>

                    <img src="'.base_path().path_to_theme().'/images/home-top-img3.jpg" align="right" alt="image" />Nunc nisi elit, sollicitudin volutpat, adipiscing eu, rutrum sed, ligula.

                </div>',
        'content top',
        '2'
    );
} 
function check_block($bid,$theme)
{
    $result = db_query("SELECT * FROM {blocks} WHERE delta = %d and theme = '%s' and module = 'block'", $bid, $theme);
 if(db_result($result)>0)
 {
  return false;
 }
 else
 {
  return true;
 }
}

with this:

$allthem_blocks = check_block('Amor_Azul');

if(in_array(3,$allthem_blocks))
{
db_query(
        "INSERT INTO {blocks} (module,delta,theme,status,weight,region,custom,throttle,visibility,pages,title)
        VALUES ('%s', '%s', '%s', %d, %d, '%s', %d, %d, %d, '%s', '%s')",
        'block', '3', 'Amor_Azul', '1', '0', 'header_text', '0', '0', '0', '', ''
    );
    db_query("INSERT INTO {boxes} (bid, body, info, format) VALUES (%d, '%s', '%s', '%s')",
        '3',
        '<h1 class="header-title">Leo eu adipiscing eleifend</h1>

              Leo eu adipiscing eleifend, magna urna mattis nibh, sed consequat nisi nibh sit amet nunc. Nam neque. Nam a odio sed tellus mattis posuere. Cras mattis viverra metus. Fusce feugiat elementum metus. Maecenas euismod dignissim diam. Aliquam felis. Nulla augue turpis, euismod id, dictum sed, mollis et, quam. Pellentesque nisl. Cras faucibus ante in sem. Aenean porta diam molestie urna',
        'header text',
        '2'
    );
} 
if(in_array(4,$allthem_blocks))
{

    db_query(
        "INSERT INTO {blocks} (module,delta,theme,status,weight,region,custom,throttle,visibility,pages,title)
        VALUES ('%s', '%s', '%s', %d, %d, '%s', %d, %d, %d, '%s', '%s')",
        'block', '4', 'Amor_Azul', '1', '0', 'header_image', '0', '0', '0', '', ''
    );
    db_query("INSERT INTO {boxes} (bid, body, info, format) VALUES (%d, '%s', '%s', '%s')",
        '4',
        '<img src="'.base_path().path_to_theme().'/images/header-image.jpg" alt="Girl" />',
        'header images',
        '2'
    );
}
if(in_array(1,$allthem_blocks))
{
 
    db_query(
        "INSERT INTO {blocks} (module,delta,theme,status,weight,region,custom,throttle,visibility,pages,title)
        VALUES ('%s', '%s', '%s', %d, %d, '%s', %d, %d, %d, '%s', '%s')",
        'block', '1', 'Amor_Azul', '1', '0', 'footer_links', '0', '0', '0', '', ''
    );
    db_query("INSERT INTO {boxes} (bid, body, info, format) VALUES (%d, '%s', '%s', '%s')",
        '1',
        '<a href="#">Home</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#">About Us</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#">Services</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#">Contact Us</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
        'Footer Links',
        '2'
    );
}
if(in_array(2,$allthem_blocks))
{
 
    db_query(
        "INSERT INTO {blocks} (module,delta,theme,status,weight,region,custom,throttle,visibility,pages,title)
        VALUES ('%s', '%s', '%s', %d, %d, '%s', %d, %d, %d, '%s', '%s')",
        'block', '2', 'Amor_Azul', '1', '0', 'content_top', '0', '0', '1', '<front>', ''
    );
    db_query("INSERT INTO {boxes} (bid, body, info, format) VALUES (%d, '%s', '%s', '%s')",
        '2',
        '<div class="cont-top1">

                    <h3>Cum sociis natoque penatibus</h3>

                    <img src="'.base_path().path_to_theme().'/images/home-top-img1.jpg" align="right"  alt="image" />Nunc nisi elit, sollicitudin volutpat, adipiscing eu, rutrum sed, ligula.

                </div>

                <div class="cont-top2">

                    <h3>Cum sociis natoque penatibus</h3>

                    <img src="'.base_path().path_to_theme().'/images/home-top-img2.jpg" align="right" alt="image" />Nunc nisi elit, sollicitudin volutpat, adipiscing eu, rutrum sed, ligula.

                </div>

                <div class="cont-top2">

                    <h3>Cum sociis natoque penatibus</h3>

                    <img src="'.base_path().path_to_theme().'/images/home-top-img3.jpg" align="right" alt="image" />Nunc nisi elit, sollicitudin volutpat, adipiscing eu, rutrum sed, ligula.

                </div>',
        'content top',
        '2'
    );
} 
function check_block($theme) {
 // $result = db_query("SELECT * FROM {blocks} WHERE delta = %d and theme = '%s' and module = 'block'", $bid, $theme);
 static $blockdata;
 $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s' and module = '%s'", $theme,'block');
 $test = db_result($result);
 if(!is_array($blockdata)) {
  static $blockdata = array();
  while($rowblock = db_fetch_object($result)) {
   $blockdata[$rowblock->delta] = $rowblock->delta;
  }
 }
 return $blockdata;
}

This will fix the problem.

edegids’s picture

Thanx! You were right, it fixed the problem!

May I ask if this was a general issue or specific problem on our website?

info@zrix.com’s picture

Glad to know your problem got resolved. This is not a specific problem but can be faced by anyone who will try to print in this manner.

edegids’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.