PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'flexiblev2:homepagelayout' for key 'PRIMARY': INSERT INTO {ctools_css_cache} (cid, filename, css, filter) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array ( [:db_insert_placeholder_0] => flexiblev2:homepagelayout [:db_insert_placeholder_1] => public://ctools/css/3ef110ff2247e01ce13c441e9711fc8f.css [:db_insert_placeholder_2] => .panels-flexible-region { padding: 0; } .panels-flexible-region-inside { padding-right: 0.5em; padding-left: 0.5em; } .panels-flexible-region-inside-first { padding-left: 0; } .panels-flexible-region-inside-last { padding-right: 0; } .panels-flexible-column { padding: 0; } .panels-flexible-column-inside { padding-right: 0.5em; padding-left: 0.5em; } .panels-flexible-column-inside-first { padding-left: 0; } .panels-flexible-column-inside-last { padding-right: 0; } .panels-flexible-row { padding: 0 0 0.5em 0; margin: 0; } .panels-flexible-row-last { padding-bottom: 0; } .panels-flexible-column-homepagelayout-main { float: left; width: 99.0000%; } .panels-flexible-homepagelayout-inside { padding-right: 0px; } .panels-flexible-homepagelayout { width: auto; } .panels-flexible-region-homepagelayout-tophomepanel { float: left; width: 99.0000%; } .panels-flexible-row-homepagelayout-2-inside { padding-right: 0px; } .panels-flexible-region-homepagelayout-topleft { float: left; width: 59.3286%; } .panels-flexible-region-homepagelayout-topright { float: left; width: 39.6714%; } .panels-flexible-row-homepagelayout-1-inside { padding-right: 0px; } [:db_insert_placeholder_3] => 0 ) in ctools_css_store() (line 87 of /www/www-live/drupal.sanger.ac.uk/htdocs/sites/all/modules/contrib/ctools/includes/css.inc).

Comments

merlinofchaos’s picture

Status: Active » Closed (won't fix)

As I've said elsewhere, this is almost certainly an issue with your replication setup.

stephenrobinson’s picture

stephenrobinson’s picture

Status: Closed (won't fix) » Needs review

This occurs as when 2 users generate the cache, user 1 can delete the row, user 2 can then insert a row, then user 1 tries to insert the row and then get an error:

  db_delete('ctools_css_cache')
    ->condition('cid', $id)
    ->execute();

  $filename = ctools_css_cache($css, $filter);

  db_insert('ctools_css_cache')
    ->fields(array(
      'cid' => $id,
      'filename' => $filename,
      'css' => $css,
      'filter' => intval($filter),
    ))
    ->execute();

this can be avoided:

function ctools_css_store($id, $css, $filter = TRUE) {
  $filename = db_query('SELECT filename FROM {ctools_css_cache} WHERE cid = :cid', array(':cid' => $id))->fetchField();
  if ($filename) {
    if(file_exists($filename)){
      file_unmanaged_delete($filename);
    }
    $filename = ctools_css_cache($css, $filter);
    db_update('ctools_css_cache')->fields(array('cid' => $id, 'filename' => $filename, 'css' => $css, 'filter' => intval($filter),))->condition('cid', $id)->execute();
  }
  else{
    $filename = ctools_css_cache($css, $filter);
    db_insert('ctools_css_cache')
      ->fields(array(
        'cid' => $id,
        'filename' => $filename,
        'css' => $css,
        'filter' => intval($filter),
      ))
      ->execute(); 
  }
  return $filename;
}
geerlingguy’s picture

Status: Needs review » Active

This needs a patch attached for review :)

japerry’s picture

Status: Active » Closed (outdated)

Drupal 7 is no longer supported, closing.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.