I'm still trying to track this beast of an issue down but by the glory of the dprint_r function, you can see what is happening.
my dprint_rs in wordpress_import_process_post_link()
function wordpress_import_process_post_link($wordpress_import, $context) {
$path = $context['sandbox']['post']['link'];
$path = substr($path, strlen($wordpress_import->data['baseurl']));
$path = rtrim($path, '/');
dprint_r('pre function $path: '. $path);
path_set_alias('node/'. $context['sandbox']['node']->nid, $path);
dprint_r('end of func');
}
my overwrite w/ dprint_rs of path_set_alias()
function path_set_alias($path = NULL, $alias = NULL, $pid = NULL, $language = '') {
dprint_r('path: '. $path);
dprint_r(' alias: '. $alias);
$path = urldecode($path);
$alias = urldecode($alias);
// First we check if we deal with an existing alias and delete or modify it based on pid.
if ($pid) {
// An existing alias.
if (!$path || !$alias) {
// Delete the alias based on pid.
db_query('DELETE FROM {url_alias} WHERE pid = %d', $pid);
}
else {
// Update the existing alias.
db_query("UPDATE {url_alias} SET src = '%s', dst = '%s', language = '%s' WHERE pid = %d", $path, $alias, $language, $pid);
}
}
else if ($path && $alias) {
dprint_r('made it');
// Check for existing aliases.
if ($alias == drupal_get_path_alias($path, $language)) {
dprint_r(' get alias: '. $alias);
// There is already such an alias, neutral or in this language.
// Update the alias based on alias; setting the language if not yet done.
db_query("UPDATE {url_alias} SET src = '%s', dst = '%s', language = '%s' WHERE dst = '%s'", $path, $alias, $language, $alias);
}
else {
dprint_r(' else ');
// A new alias. Add it to the database.
db_query("INSERT INTO {url_alias} (src, dst, language) VALUES ('%s', '%s', '%s')", $path, $alias, $language);
}
}
else {
dprint_r('delete some shit');die;
// Delete the alias.
if ($alias) {
db_query("DELETE FROM {url_alias} WHERE dst = '%s'", $alias);
}
else {
db_query("DELETE FROM {url_alias} WHERE src = '%s'", $path);
}
}
drupal_clear_path_cache();
}
I suspected that the "DELETE FROM"s were being called, so I put a DIE; in there to break batch api, this is what was returned:
<pre>pre function $path: 2009/07/17/portrait-paste-up</pre><pre>path: node/1220</pre><pre> alias: 2009/07/17/portrait-paste-up</pre><pre>made it</pre><pre> else </pre><pre>end of func</pre><pre>path: node/1220</pre><pre> alias: </pre><pre>delete some shit</pre>
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | wordpress_import-645432.patch | 821 bytes | kmonty |
Comments
Comment #1
kmontyOkay, I believe I figured this one out. The second call to path_set_alias() happens in the second node_save in the function "wordpress_import_process_post()" is called.
line 1077
This is what happens: path_set_alias() is both called by wordpress_import and by hook_nodeapi. Because wordpress_import calls path_set_alias() but does not save it to the node object ($node->path), when hook_nodeapi is called in the path.module, it believes the $path == null and therefore deletes the alias. Rather than calling this function twice, wordpress_import should just put the alias into the $node object and let hook_nodeapi do its thing.
Please review the patch.
Comment #2
lavamind commentedFixed in latest 6.x-2.x-dev.
Thanks!
Comment #3
lavamind commented