Integration with Schema API to facilitate importing new kinds of things
| Project: | Migrate |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
I've been adding migrate support to a host of UberCart related things:
#620812: Support importing UberCart product fields with migrate.module
#625866: Support importing uc address records with migrate.module
#626380: Add migrate.module support for uc_order (orders, order product details, etc)
The bulk of this work is mostly cut+paste coding to copy nearly identical functions around, and then fill in data that's already declared in hook_schema(). :(
Instead of this:
<?php
function uc_order_migrate_types() {
return array(
'uc_order' => t('UberCart order'),
'uc_order_product' => t('UberCart order product'),
);
}
function uc_order_migrate_fields_uc_order($type) {
return array(
'order_id' => t('UC Order: Order ID'),
'uid' => t('UC Order: User ID'),
'order_status' => t('UC Order: Order status'),
'order_total' => t('UC Order: Order total'),
'primary_email' => t('UC Order: Primary email'),
'delivery_first_name' => t('UC Order: Delivery: First name'),
'delivery_last_name' => t('UC Order: Delivery: Last name'),
'delivery_phone' => t('UC Order: Delivery: Phone'),
'delivery_company' => t('UC Order: Delivery: Company'),
'delivery_street1' => t('UC Order: Delivery: Street 1'),
'delivery_street2' => t('UC Order: Delivery: Street 2'),
'delivery_city' => t('UC Order: Delivery: City'),
'delivery_zone' => t('UC Order: Delivery: Zone code'),
'delivery_postal_code' => t('UC Order: Delivery: Postal Code'),
'delivery_country' => t('UC Order: Delivery: Country'),
'billing_first_name' => t('UC Order: Billing: First name'),
'billing_last_name' => t('UC Order: Billing: Last name'),
'billing_phone' => t('UC Order: Billing: Phone'),
'billing_company' => t('UC Order: Billing: Company'),
'billing_street1' => t('UC Order: Billing: Street 1'),
'billing_street2' => t('UC Order: Billing: Street 2'),
'billing_city' => t('UC Order: Billing: City'),
'billing_zone' => t('UC Order: Billing: Zone code'),
'billing_postal_code' => t('UC Order: Billing: Postal Code'),
'billing_country' => t('UC Order: Billing: Country'),
'payment_method' => t('UC Order: Payment method'),
'data' => t('UC Order: Data (serialized array of extra info)'),
'created' => t('UC Order: Created timestamp'),
'modified' => t('UC Order: Last modified timestamp'),
'host' => t('UC Order: Host IP address'),
);
}
...
function uc_order_migrate_fields_uc_order_product($type) {
return array(
'order_product_id' => t('UC Order: Product: Order Product ID'),
'order_id' => t('UC Order: Product: Order ID'),
'nid' => t('UC Order: Product: Node ID'),
'title' => t('UC Order: Product: Title'),
'manufacturer' => t('UC Order: Product: Manufacturer'),
'model' => t('UC Order: Product: Module (SKU)'),
'qty' => t('UC Order: Product: Quantity'),
'cost' => t('UC Order: Product: Cost'),
'price' => t('UC Order: Product: Price'),
'weight' => t('UC Order: Product: Weight'),
'data' => t('UC Order: Product: Data (serialized array of extra info)'),
);
}
...
?>It'd be incredibly slick to be able to just say something like this:
<?php
function uc_order_migrate_type_tables() {
return array(
'uc_order' => array(
'name' => t('UberCart order'),
'table' => 'uc_orders',
'module' => 'uc_order', // If undefined, defaults to the module implementing hook_migrate_types()
),
'uc_order_product' => array(
'name' => t('UberCart order product'),
'table' => 'uc_order_products',
),
);
}
?>and then migrate.module can just invoke hook_schema for the appropriate module, harvest the data for the declared table (including field names, types, descriptions, etc), and do the right thing. In fact, via drupal_write_record(), we could almost completely automate these functions the same way:
hook_migrate_import_[type]()
hook_migrate_delete_[type]()
...
We could still support the current approach for people who like doing it manually. But, in cases where you basically just want a direct drupal_write_record mapping into the Schema API table definition, this would save a *LOT* of busy work and duplicate effort.
Thoughts?
-Derek
