example.table_copy.inc 954 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. /**
  3. * @file
  4. * Make a copy of the role table. To use this you must create a table named
  5. * role_copy with the same structure as role.
  6. */
  7. class RoleTableMigration extends Migration {
  8. public function __construct() {
  9. parent::__construct();
  10. $this->dependencies = array();
  11. $this->description = 'Copy the role table as an example of table_copy plugin.';
  12. $destination_key = array(
  13. 'rid' => array(
  14. 'type' => 'int',
  15. 'unsigned' => TRUE,
  16. 'not null' => TRUE,
  17. ),
  18. );
  19. $query = db_select('role', 'r')->fields('r');
  20. $this->source = new MigrateSourceSQL($query);
  21. $this->destination = new MigrateDestinationTableCopy('role_copy', $destination_key);
  22. $this->map = new MigrateSQLMap($this->machineName,
  23. array('rid' => array(
  24. 'type' => 'int',
  25. 'unsigned' => TRUE,
  26. 'not null' => TRUE,
  27. 'alias' => 'r',
  28. )
  29. ),
  30. $destination_key
  31. );
  32. }
  33. }