diff --git a/statuses.info b/statuses.info index 25e6f9d..8a7b369 100644 --- a/statuses.info +++ b/statuses.info @@ -9,6 +9,7 @@ files[] = statuses.author-pane.inc files[] = statuses.install files[] = statuses.module files[] = statuses.tokens.inc +files[] = statuses.migrate.inc files[] = includes/statuses.preprocess.inc files[] = includes/utility/statuses.access.inc files[] = includes/utility/statuses.admin.inc diff --git a/statuses.migrate.inc b/statuses.migrate.inc new file mode 100644 index 0000000..67995d7 --- /dev/null +++ b/statuses.migrate.inc @@ -0,0 +1,150 @@ + array( + 'type' => 'int', + 'not null' => TRUE, + ), + ); + } + + /** + * Delete the provided statuses. + * + * @param $id + * IDs to be deleted. + */ + public function bulkRollback(array $ids) { + migrate_instrument_start(__METHOD__); + + db_delete('statuses') + ->condition('sid', $ids, 'IN') + ->execute(); + + if (module_exists('fbsmp')) { + db_delete('fbsmp') + ->condition('sid', $ids, 'IN') + ->execute(); + } + + migrate_instrument_stop(__METHOD__); + } + + /** + * Import a single status. + * + * @param $entity + * Object object to build. Prefilled with any fields mapped in the Migration. + * @param $row + * Raw source data object - passed through to prepare/complete handlers. + * @return array + * Array of key fields of the object that was saved if + * successful. FALSE on failure. + */ + public function import(stdClass $entity, stdClass $row) { + $this->prepare($entity, $row); + + if (isset($entity->created)) { + $entity->created = Migration::timestamp($entity->created); + } + + $update = empty($entity->sid) ? array() : array('sid'); + $result = drupal_write_record('statuses', $entity, $update); + + if (!empty($entity->mp_type) && module_exists('fbsmp')) { + $data = unserialize($entity->mp_data); + if (!empty($entity->mp_fid)) { + $data['fid'] = $entity->mp_fid; + } + + db_merge('fbsmp') + ->key(array('sid' => $entity->sid)) + ->fields(array( + 'type' => $entity->mp_type, + 'data' => serialize($data) + )) + ->execute(); + } + + return $result ? array($entity->sid) : FALSE; + } + + /** + * Returns a list of fields available to be mapped/ + * + * @return array + * Keys: machine names of the fields (to be passed to addFieldMapping) + * Values: Human-friendly descriptions of the fields. + */ + public function fields() { + $fields = array( + 'sid' => 'Status ID', + 'sender' => 'Status sender', + 'recipient' => 'Status recipient', + 'type' => 'Entity type', + 'created' => 'Created timestamp', + 'message' => 'Text message', + ); + + if (module_exists('fbsmp')) { + $fields['mp_type'] = 'Micropublisher type'; + $fields['mp_data'] = 'Micropublisher data'; + $fields['mp_fid'] = 'Micropublisher file ID'; + } + + return $fields; + } + + /** + * Give handlers a shot at modifying the object before saving it. + * + * @param $entity + * Entity object to build. Prefilled with any fields mapped in the Migration. + * @param $source_row + * Raw source data object - passed through to prepare handlers. + */ + public function prepare(stdClass $entity, stdClass $source_row) { + $migration = Migration::currentMigration(); + $entity->migrate = array( + 'machineName' => $migration->getMachineName(), + ); + + // Call any prepare handler for this specific Migration. + if (method_exists($migration, 'prepare')) { + $migration->prepare($entity, $source_row); + } + } + + /** + * Give handlers a shot at modifying the object (or taking additional action) + * after saving it. + * + * @param $object + * Entity object to build. This is the complete object after saving. + * @param $source_row + * Raw source data object - passed through to complete handlers. + */ + public function complete(stdClass $entity, stdClass $source_row) { + $migration = Migration::currentMigration(); + + // Call any complete handler for this specific Migration. + if (method_exists($migration, 'complete')) { + $migration->complete($entity, $source_row); + } + } +} \ No newline at end of file