diff --git a/fivestar.info b/fivestar.info index f4d802c..3e5bbb0 100644 --- a/fivestar.info +++ b/fivestar.info @@ -6,3 +6,4 @@ dependencies[] = votingapi configure = admin/config/content/fivestar files[] = test/fivestar.base.test files[] = test/fivestar.field.test +files[] = fivestar.migrate.inc \ No newline at end of file diff --git a/fivestar.migrate.inc b/fivestar.migrate.inc new file mode 100644 index 0000000..414e3fb --- /dev/null +++ b/fivestar.migrate.inc @@ -0,0 +1,46 @@ + array('source_field' => 'example_target'), + * ); + * // The rating should be passed in as the primary value. + * $this->addFieldMapping('field_rating', 'user_rate') + * ->arguments($arguments); + * // Since the excerpt is mapped via an argument, add a null mapping so it's + * // not flagged as unmapped. + * $this->addFieldMapping(NULL, 'example_target'); + * @endcode + */ +class MigrateFivestarHandler extends MigrateFieldHandler { + public function __construct() { + $this->registerTypes(array('fivestar')); + } + + public function prepare($entity, array $field_info, array $instance, array $values) { + $arguments = array(); + if (isset($values['arguments'])) { + $arguments = array_filter($values['arguments']); + unset($values['arguments']); + } + $language = $this->getFieldLanguage($entity, $field_info, $arguments); + + // Setup the standard Field API array for saving. + $delta = 0; + foreach ($values as $value) { + $return[$language][$delta] = array('rating' => $value) + array_intersect_key($arguments, $field_info['columns']); + $delta++; + } + + return isset($return) ? $return : NULL; + } +} diff --git a/fivestar.module b/fivestar.module index 1b9db2c..9f47c7f 100644 --- a/fivestar.module +++ b/fivestar.module @@ -178,7 +178,7 @@ function _fivestar_cast_vote($entity_type, $id, $value, $tag = NULL, $uid = NULL } // Moving the calculationg after saving/deleting the vote but before getting the votes. - votingapi_recalculate_results($entity_type, $id); + votingapi_recalculate_results($entity_type, $id); return fivestar_get_votes($entity_type, $id, $tag, $uid); } } @@ -804,3 +804,13 @@ function _fivestar_target_comment_parent_node($entity, $field, $instance, $langc 'entity_type' => 'node', ); } + +/** + * Implements hook_migrate_api(). + */ +function fivestar_migrate_api() { + $api = array( + 'api' => 2, + ); + return $api; +}