Error Duplicate entry 'page' when creating a site from profile
| Project: | Profile Generator |
| Version: | 5.x-1.1 |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Every time I use a profile I get this error. When I select the profile and then fill in the db info it always returns me to the select the profile page and I just select it again. And this is what it gives me but then the site works.
user warning: Duplicate entry 'page' for key 1 query: INSERT INTO khayavnode_type (type, name, module, description, help, has_title, title_label, has_body, body_label, min_word_count, custom, modified, locked, orig_type) VALUES ('page', 'Page', 'node', 'If you want to add a static page, like a contact page or an about page, use a page.', '', '1', 'Title', '1', 'Body', '0', '1', '1', '0', 'page') in /home/litebulb/public_html/drupal/includes/database.mysql.inc on line 172.

#1
It's true the site works but it is missing all of the default node content types aside from the page. Opening the generated .profile file one can see that in the
* NODE TYPES *
section there is two INSERT queries for 'page' and nothing for the other types.
Looking inside profile_generator.module the query is constructed around line 190:
// node types
if ($form_values['export_nodetypes']) {
$code .= "/************************************************************\n";
$code .= "* NODE TYPES *\n";
$code .= "************************************************************/\n";
$query_result = db_query('SELECT * FROM {node_type} WHERE custom = 1');
$fields = array('type', 'name', 'module', 'description', 'help', 'has_title', 'title_label', 'has_body', 'body_label', 'min_word_count', 'custom', 'modified', 'locked', 'orig_type');
while ($nodetype = db_fetch_object($query_result)) {
$code .= ' db_query("INSERT INTO {node_type} ('. join(', ', $fields) .")\n";
$code .= ' VALUES ('. join(', ', array_pad(array(), count($fields), "'%s'")) .")\",\n";
foreach ($fields as $field) {
$params[] = profile_generator_serialize($nodetype->$field);
}
$code .= ' '. join(',', $params) ."\n";
$code .= ' );';
}
$code .= "\n";
}
So for some reason the above does not correctly pick up the two content types enabled by default (Page and Story, both have custom=1).
I tried adding these lines just before the while:
$mynodecount_result =db_query('SELECT count(custom) FROM {node_type} WHERE custom = 1');
$mynodecount = db_fetch_object($mynodecount_result);
watchdog('node_type_count', print($mynodecount));
The above outputs 1 into the logs (which is BS as going to phpMyAdmin and executing the same query on the node_type table returns 2).
Not sure what's going on here as this is as far as I got and now I gotta run... :)
#2
A fix for this problem is to re-initialize the $params array before every foreach ($fields as $field) loop:
$params = array();foreach ($fields as $field) {
$params[] = profile_generator_serialize($nodetype->$field);
}
$code .= ' '. join(',', $params) ."\n";
$code .= ' );' . "\n";
There's also one more small correction in the above code - note the ."\n"; added at the end of the
$code .= ' );' . "\n";This will add a missing newline char so the generated file is properly formatted.
I guess I should educate myself on how to create a patch file... one of these days... :) damn day job...