class WineWineMigration in Migrate 6.2
Same name and namespace in other branches
- 7.2 migrate_example/wine.inc \WineWineMigration
Hierarchy
- class \MigrationBase
- class \Migration
- class \DynamicMigration
- class \AdvancedExampleMigration
- class \WineWineMigration
- class \AdvancedExampleMigration
- class \DynamicMigration
- class \Migration
Expanded class hierarchy of WineWineMigration
1 string reference to 'WineWineMigration'
- migrate_example_migrate_api in migrate_example/
migrate_example.module
File
- migrate_example/
wine.inc, line 543 - Advanced migration examples. These serve two purposes:
View source
class WineWineMigration extends AdvancedExampleMigration {
public function __construct() {
parent::__construct();
$this->description = t('Wines of the world');
$this->dependencies = array(
'WineVariety',
'WineRegion',
'WineBestWith',
'WineUser',
'WineProducer',
);
// You can add a 'track_last_imported' option to the map, to record the
// timestamp of when each item was last imported in the map table.
$this->map = new MigrateSQLMap($this->machineName, array(
'wineid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Wine ID',
'alias' => 'w',
),
), MigrateDestinationNode::getKeySchema(), 'default', array(
'track_last_imported' => TRUE,
));
$query = db_select('migrate_example_wine', 'w')
->fields('w', array(
'wineid',
'name',
'body',
'excerpt',
'accountid',
'posted',
'last_changed',
'variety',
'region',
'rating',
'last_reviewed',
));
$query
->leftJoin('migrate_example_wine_category_wine', 'cwbw', "w.wineid = cwbw.wineid");
$query
->leftJoin('migrate_example_wine_categories', 'bw', "cwbw.categoryid = bw.categoryid AND bw.type = 'best_with'");
// Gives a single comma-separated list of related terms
$query
->groupBy('w.wineid');
$query
->addExpression('GROUP_CONCAT(bw.categoryid)', 'best_with');
$count_query = db_select('migrate_example_wine', 'w');
$count_query
->addExpression('COUNT(wineid)', 'cnt');
// TIP: By passing an array of source fields to the MigrateSourceSQL constructor,
// we can modify the descriptions of source fields (which just default, for
// SQL migrations, to table_alias.column_name), as well as add additional fields
// (which may be populated in prepareRow()).
$source_fields = array(
'wineid' => t('Wine ID in the old system'),
'name' => t('The name of the wine'),
'best_vintages' => t('What years were best for this wine?'),
'images' => t('Images attached to this wine; populated in prepareRow()'),
);
// TIP: By default, each time a migration is run, any previously unimported source items
// are imported (along with any previously-imported items marked for update). If the
// source data contains a timestamp that is set to the creation time of each new item,
// as well as set to the update time for any existing items that are updated, then
// you can have those updated items automatically reimported by setting the field as
// your highwater field.
$this->highwaterField = array(
'name' => 'last_changed',
// Column to be used as highwater mark
'alias' => 'w',
// Table alias containing that column
'type' => 'int',
);
// Note that it is important to process rows in the order of the highwater mark
$query
->orderBy('last_changed');
$this->source = new MigrateSourceSQL($query, $source_fields, $count_query);
$this->destination = new MigrateDestinationNode('migrate_example_wine');
// Mapped fields
$this
->addFieldMapping('title', 'name')
->description(t('Mapping wine name in source to node title'));
$this
->addFieldMapping('uid', 'accountid')
->sourceMigration('WineUser')
->defaultValue(1);
// TIP: By default, term relationship are assumed to be passed by name.
// In this case, the source values are IDs, so we specify the relevant
// migration (so the tid can be looked up in the map), and tell the term
// field handler that it is receiving tids instead of names
$this
->addFieldMapping('Migrate Example Wine Varieties', 'variety')
->sourceMigration('WineVariety')
->arguments(array(
'source_type' => 'tid',
));
$this
->addFieldMapping('Migrate Example Wine Regions', 'region')
->sourceMigration('WineRegion')
->arguments(array(
'source_type' => 'tid',
));
$this
->addFieldMapping('Migrate Example Wine Best With', 'best_with')
->separator(',')
->sourceMigration('WineBestWith')
->arguments(array(
'source_type' => 'tid',
));
$this
->addFieldMapping('field_migrate_example_wine_ratin', 'rating');
$this
->addFieldMapping('field_migrate_example_wine_rvw', 'last_reviewed');
$this
->addFieldMapping('field_migrate_example_top_vintag', 'best_vintages');
// TIP: You can apply one or more functions to a source value using ->callbacks().
// The function must take a single argument and return a value which is a
// transformation of the argument. As this example shows, you can have multiple
// callbacks, and they can either be straight functions or class methods. In
// this case, our custom method prepends 'review: ' to the body, and then we
// call a standard Drupal function to uppercase the whole body.
$this
->addFieldMapping('body', 'body')
->callbacks(array(
$this,
'addTitlePrefix',
), 'drupal_strtoupper');
$this
->addFieldMapping('teaser', 'excerpt');
// We will get the image data from a related table in prepareRow()
$arguments = MigrateFileFieldHandler::arguments(NULL, 'file_copy', FILE_EXISTS_REPLACE);
$this
->addFieldMapping('field_migrate_example_image', 'images')
->arguments($arguments);
$this
->addFieldMapping('sticky')
->defaultValue(0);
// These are already UNIX timestamps, so just pass through
$this
->addFieldMapping('created', 'posted');
$this
->addFieldMapping('changed', 'last_changed');
// No unmapped source fields
// Unmapped destination fields
$this
->addUnmigratedDestinations(array(
'is_new',
'status',
'promote',
'revision',
'language',
));
}
protected function addTitlePrefix($source_title) {
return t('review: ') . $source_title;
}
// TIP: Implement a prepareRow() method to manipulate the source row between
// retrieval from the database and the automatic applicaton of mappings
public function prepareRow($current_row) {
// We used the MySQL GROUP_CONCAT function above to handle a multi-value source
// field - more portably, we query the related table with multiple values here,
// so the values can run through the mapping process
$source_id = $current_row->wineid;
$result = db_select('migrate_example_wine_vintages', 'v')
->fields('v', array(
'vintage',
))
->condition('wineid', $source_id)
->execute();
foreach ($result as $row) {
$current_row->best_vintages[] = $row->vintage;
}
// An advanced feature of the file field handler is that in addition to the
// path to the image itself, we can add image properties like ALT text,
// encapsulating them as JSON
/*
* This is disabled - see http://drupal.org/node/1679798. To demonstrate
* remote file migration, edit the migrate_example_wine_files table and enter
* the URLs of known remote image files, then enable this code.
$result = db_select('migrate_example_wine_files', 'f')
->fields('f', array('url', 'image_alt', 'image_title'))
->condition('wineid', $source_id)
->execute();
$current_row->images = array();
foreach ($result as $row) {
$image_data = array(
'path' => $row->url,
'alt' => $row->image_alt,
'title' => $row->image_title,
);
$current_row->images[] = drupal_to_js($image_data);
}
*/
// We could also have used this function to decide to skip a row, in cases
// where that couldn't easy be done through the original query. Simply
// return FALSE in such cases.
return TRUE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AdvancedExampleMigration:: |
public | property | ||
DynamicMigration:: |
public static | function |
Overrides default of FALSE Overrides MigrationBase:: |
|
Migration:: |
protected | property | An array of counts. Initially used for cache hit/miss tracking. | |
Migration:: |
protected | property | ||
Migration:: |
protected | property | The default rollback action for this migration. Can be overridden on a per-row basis by setting $row->rollbackAction in prepareRow(). | |
Migration:: |
protected | property | Destination object for the migration, derived from MigrateDestination. | |
Migration:: |
protected | property | The object currently being constructed | |
Migration:: |
protected | property | Simple mappings between destination fields (keys) and source fields (values). | |
Migration:: |
protected | property | If present, an array with keys name and alias (optional). Name refers to the source columns used for tracking highwater marks. alias is an optional table alias. | |
Migration:: |
protected | property | Map object tracking relationships between source and destination data | |
Migration:: |
public | property | Specify value of needs_update for current map row. Usually set by MigrateFieldHandler implementations. | |
Migration:: |
public | property | The rollback action to be saved for the current row. | |
Migration:: |
protected | property | When performing a bulkRollback(), the maximum number of items to pass in a single call. Can be overridden in derived class constructor. | |
Migration:: |
protected | property | Source object for the migration, derived from MigrateSource. | |
Migration:: |
protected | property | The current data row retrieved from the source. | |
Migration:: |
protected | property | ||
Migration:: |
public | function | Add a mapping for a destination field, specifying a source field and/or a default value. | 1 |
Migration:: |
public | function | Shortcut for adding several fields which have the same name on both source and destination sides. | |
Migration:: |
public | function | Shortcut for adding several destination fields which are to be explicitly not migrated. | |
Migration:: |
public | function | Shortcut for adding several source fields which are to be explicitly not migrated. | |
Migration:: |
public | function | Perform an analysis operation - report on field values in the source. | |
Migration:: |
protected | function | Apply field mappings to a data row received from the source, returning a populated destination object. | 1 |
Migration:: |
protected | function |
Override MigrationBase::beginProcess, to make sure the map/message tables
are present. Overrides MigrationBase:: |
|
Migration:: |
protected | function | Standard top-of-loop stuff, common between rollback and import - check for exceptional conditions, and display feedback. | |
Migration:: |
protected | function | If stub creation is enabled, try to create a stub and save the mapping. | |
Migration:: |
public static | function |
Deregister a migration - remove all traces of it from the database (without
touching any content which was created by this migration). Overrides MigrationBase:: |
|
Migration:: |
constant | |||
Migration:: |
public | function |
Override MigrationBase::endProcess, to call post hooks. Note that it must
be public to be callable as the shutdown function. Overrides MigrationBase:: |
|
Migration:: |
public | function | Get the number of source records which failed to import. TODO: Doesn't yet account for informationals, or multiple errors for a source record. | |
Migration:: |
public | function | ||
Migration:: |
public | function | ||
Migration:: |
public | function | ||
Migration:: |
public | function | ||
Migration:: |
public | function | ||
Migration:: |
public | function | ||
Migration:: |
protected | function | For fields which require uniqueness, assign a new unique value if necessary. | |
Migration:: |
protected | function | Look up a value migrated in another migration. | |
Migration:: |
protected | function | Perform an import operation - migrate items from source to destination. | |
Migration:: |
public | function | Get the number of records successfully imported. | |
Migration:: |
public | function |
Reports whether this migration process is complete (i.e., all available
source rows have been processed). Overrides MigrationBase:: |
|
Migration:: |
protected | function | Test whether we've exceeded the designated item limit. | |
Migration:: |
public | function | Get the number of messages associated with this migration | |
Migration:: |
protected | function | ||
Migration:: |
protected | function | ||
Migration:: |
protected | function | Default implementations of pre/post import/rollback methods. These call the destination methods (if they exist) - when overriding, always call parent::preImport() etc. | |
Migration:: |
public | function | Default implementation of prepareKey. This method is called from the source plugin immediately after retrieving the raw data from the source - by default, it simply assigns the key values based on the field names passed to MigrateSQLMap(). Override… | |
Migration:: |
public | function | Prepares this migration to run as an update - that is, in addition to unmigrated content (source records not in the map table) being imported, previously-migrated content will also be updated in place. | |
Migration:: |
protected | function | ||
Migration:: |
public | function | Get the number of source records processed. | |
Migration:: |
protected | function | Outputs a progress message, reflecting the current status of a migration process. | |
Migration:: |
public | function | Remove any existing mappings for a given destination or source field. | |
Migration:: |
protected | function | Perform a rollback operation - remove migrated items from the destination. | |
Migration:: |
public | function |
Pass messages through to the map class Overrides MigrationBase:: |
|
Migration:: |
public | function | Set the specified row to be updated, if it exists. | |
Migration:: |
constant | Indicate whether the primary system of record for this migration is the source, or the destination (Drupal). In the source case, migration of an existing object will completely replace the Drupal object with data from the source side. In the… | ||
Migration:: |
public | function | Convenience function to return count of total source records | |
Migration:: |
public | function | Get the number of records marked as needing update. | |
MigrationBase:: |
protected static | property | Track the migration currently running, so handlers can easily determine it without having to pass a Migration object everywhere. | |
MigrationBase:: |
protected | property | List of other Migration classes which should be imported before this one. E.g., a comment migration class would typically have node and user migrations as dependencies. | |
MigrationBase:: |
protected | property | Detailed information describing the migration. | |
MigrationBase:: |
protected static | property | Name of a function for displaying feedback. It must take the message to display as its first argument, and a (string) message type as its second argument (see drush_log()). | |
MigrationBase:: |
protected | property | Disabling a migration prevents it from running with --all, or individually without --force | |
MigrationBase:: |
protected | property | The name of a migration group, used to collect related migrations. | |
MigrationBase:: |
protected | property | If provided, an URL for an issue tracking system containing :id where the issue number will go (e.g., 'http://example.com/project/ticket/:id'). | |
MigrationBase:: |
protected | property | Whether to maintain a history of migration processes in migrate_log | |
MigrationBase:: |
protected | property | Primary key of the current history record (inserted at the beginning of a process, to be updated at the end) | |
MigrationBase:: |
protected | property | The machine name of this Migration object, derived by removing the 'Migration' suffix from the class name. Used to construct default map/message table names, displayed in drush migrate-status, key to migrate_status table... | |
MigrationBase:: |
protected | property | The PHP memory_limit expressed in bytes. | |
MigrationBase:: |
protected | property | The fraction of the memory limit at which an operation will be interrupted. Can be overridden by a Migration subclass if one would like to push the envelope. Defaults to 85%. | |
MigrationBase:: |
protected static | property | ||
MigrationBase:: |
protected | property | Save options passed to current operation | |
MigrationBase:: |
protected | property | If we set an error handler (during import), remember the previous one so it can be restored. | |
MigrationBase:: |
protected | property | Indicates that we are processing a rollback or import - used to avoid excess writes in endProcess() | |
MigrationBase:: |
protected | property | When the current operation started. | |
MigrationBase:: |
protected | property | Are we importing, rolling back, or doing nothing? | |
MigrationBase:: |
protected | property | MigrateTeamMember objects representing people involved with this migration. | |
MigrationBase:: |
protected | property | The PHP max_execution_time. | |
MigrationBase:: |
protected | property | The fraction of the time limit at which an operation will be interrupted. Can be overridden by a Migration subclass if one would like to push the envelope. Defaults to 90%. | |
MigrationBase:: |
protected | property | Number of "items" processed in the current migration process (whatever that means for the type of process) | |
MigrationBase:: |
public static | function | ||
MigrationBase:: |
protected | function | Reports whether all (hard) dependencies have completed migration | |
MigrationBase:: |
public static | function | Output the given message appropriately (drush_print/drupal_set_message/etc.) | |
MigrationBase:: |
public | function | Custom PHP error handler. TODO: Redundant with hook_watchdog? | |
MigrationBase:: |
protected | function | By default, the migration machine name is the class name (with the Migration suffix, if present, stripped). | |
MigrationBase:: |
public | function | ||
MigrationBase:: |
public | function | ||
MigrationBase:: |
public | function | ||
MigrationBase:: |
public | function | ||
MigrationBase:: |
public | function | ||
MigrationBase:: |
public | function | Fetch the current highwater mark for updated content. | |
MigrationBase:: |
public static | function | Return the single instance of the given migration. | |
MigrationBase:: |
public | function | ||
MigrationBase:: |
public | function | ||
MigrationBase:: |
public | function | Retrieve the last time an import operation completed successfully. | |
MigrationBase:: |
public | function | Retrieve the last throughput for current Migration (items / minute). | |
MigrationBase:: |
public | function | ||
MigrationBase:: |
public | function | Get human readable name for a message constant. | |
MigrationBase:: |
public | function | ||
MigrationBase:: |
public | function | ||
MigrationBase:: |
public | function | Check the current status of a migration. | |
MigrationBase:: |
public | function | ||
MigrationBase:: |
public | function | ||
MigrationBase:: |
public | function | Takes an Exception object and both saves and displays it, pulling additional information on the location triggering the exception. | |
MigrationBase:: |
public | function | Returns an array of the migration's dependencies that are incomplete. | |
MigrationBase:: |
public | function | Database logging callback - called when there's a database error. We log non-critical stuff, and throw an exception otherwise TODO: Eliminate in favor of hook_watchdog()? | |
MigrationBase:: |
protected static | function | ||
MigrationBase:: |
protected | function | Test whether we've exceeded the desired memory threshold. If so, output a message. | |
MigrationBase:: |
constant | Message types to be passed to saveMessage() and saved in message tables. MESSAGE_INFORMATIONAL represents a condition that did not prevent the operation from succeeding - all others represent different severities of conditions resulting in a source… | ||
MigrationBase:: |
constant | |||
MigrationBase:: |
constant | |||
MigrationBase:: |
constant | |||
MigrationBase:: |
public | function | Perform an operation during the import phase | |
MigrationBase:: |
public | function | Perform an operation during the rollback phase. | |
MigrationBase:: |
public static | function | Register a new migration process in the migrate_status table. This will generally be used in two contexts - by the class detection code for static (one instance per class) migrations, and by the module implementing dynamic (parameterized class)… | |
MigrationBase:: |
public static | function | Clear the cached list of migration objects. | |
MigrationBase:: |
public | function | Reset the status of the migration to IDLE (to be used when the status gets stuck, e.g. if a process core-dumped) | |
MigrationBase:: |
constant | Codes representing the result of a rollback or import process. | ||
MigrationBase:: |
constant | |||
MigrationBase:: |
constant | |||
MigrationBase:: |
constant | |||
MigrationBase:: |
constant | |||
MigrationBase:: |
constant | |||
MigrationBase:: |
protected | function | Save the highwater mark for this migration (but not when using an idlist). | |
MigrationBase:: |
public static | function | ||
MigrationBase:: |
public static | function | Initialize static members, before any class instances are created. | |
MigrationBase:: |
constant | |||
MigrationBase:: |
constant | Codes representing the current status of a migration, and stored in the migrate_status table. | ||
MigrationBase:: |
constant | |||
MigrationBase:: |
constant | |||
MigrationBase:: |
constant | |||
MigrationBase:: |
public | function | Signal that any current import or rollback process should end itself at the earliest opportunity | |
MigrationBase:: |
protected | function | Test whether we're approaching the PHP time limit. | |
MigrationBase:: |
protected | function | Test whether we've exceeded the designated time limit. | |
MigrationBase:: |
public static | function | Convert an incoming string (which may be a UNIX timestamp, or an arbitrarily-formatted date/time string) to a UNIX timestamp. | |
WineWineMigration:: |
protected | function | ||
WineWineMigration:: |
public | function |
Default implementation of prepareRow(). This method is called from the source
plugin upon first pulling the raw data from the source. Overrides Migration:: |
|
WineWineMigration:: |
public | function |
General initialization of a Migration object. Overrides AdvancedExampleMigration:: |