function wordpress_migrate_update_7007 in WordPress Migrate 7.2
Key blogs with a serial field; add parent_nid tracking for attachments.
File
- ./
wordpress_migrate.install, line 289 - WordPress migration module installation
Code
function wordpress_migrate_update_7007() {
// Add a serial ID field to be the PK for blogs
if (!db_field_exists('wordpress_migrate', 'blog_id')) {
db_drop_primary_key('wordpress_migrate');
db_add_field('wordpress_migrate', 'blog_id', array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'Unique blog ID',
), array(
'primary key' => array(
'blog_id',
),
));
db_add_unique_key('wordpress_migrate', 'blog_url', array(
'blog_url',
));
}
// Attachments now will reference the integer ID instead of the filename.
if (!db_field_exists('wordpress_migrate_attachment', 'blog_id')) {
db_add_field('wordpress_migrate_attachment', 'blog_id', array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'ID of parent blog',
));
$query = db_select('wordpress_migrate_attachment', 'a')
->fields('a', array(
'filename',
));
$query
->innerJoin('wordpress_migrate', 'wm', 'a.filename=wm.filename');
$result = $query
->fields('wm', array(
'blog_id',
))
->execute();
foreach ($result as $row) {
db_update('wordpress_migrate_attachment')
->fields(array(
'blog_id' => $row->blog_id,
))
->condition('filename', $row->filename)
->execute();
}
db_drop_primary_key('wordpress_migrate_attachment');
db_drop_field('wordpress_migrate_attachment', 'filename');
db_add_primary_key('wordpress_migrate_attachment', array(
'blog_id',
'original_url',
));
}
// Track the attachment parent nodes
if (!db_field_exists('wordpress_migrate_attachment', 'parent_nid')) {
db_add_field('wordpress_migrate_attachment', 'parent_nid', array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
'description' => 'ID of parent blog',
));
}
return t('Added blog_id key, parent node tracking for attachments.');
}