destination.inc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /**
  3. * @file
  4. * Defines base for migration destinations.
  5. */
  6. /**
  7. * Abstract base class for destination handling.
  8. *
  9. * Derived classes are expected to define __toString(), returning a string
  10. * describing the type of destination and significant options. See
  11. * MigrateDestinationEntity for an example.
  12. */
  13. abstract class MigrateDestination {
  14. /**
  15. * To support MigrateSQLMap maps, derived destination classes should return
  16. * schema field definition(s) corresponding to the primary key of the destination
  17. * being implemented. These are used to construct the destination key fields
  18. * of the map table for a migration using this destination.
  19. *
  20. * abstract static public function getKeySchema()
  21. */
  22. /**
  23. * Derived classes must implement __toString().
  24. *
  25. * @return string
  26. * Description of the destination being migrated into
  27. */
  28. abstract public function __toString();
  29. /**
  30. * Derived classes must implement fields(), returning a list of available
  31. * destination fields.
  32. *
  33. * @param Migration $migration
  34. * Optionally, the migration containing this destination.
  35. * @return array
  36. * Keys: machine names of the fields (to be passed to addFieldMapping)
  37. * Values: Human-friendly descriptions of the fields.
  38. */
  39. abstract public function fields();
  40. /**
  41. * Derived classes must implement either bulkRollback or rollback() according to
  42. * the signatures below, to rollback (usually by deletion) previously-migrated
  43. * items.
  44. *
  45. * $ids is an array of single-field keys to be deleted
  46. * abstract public function bulkRollback(array $ids);
  47. *
  48. * $key is an array of fields keying a single entry to delete
  49. * abstract public function rollback(array $key);
  50. */
  51. /**
  52. * Derived classes must implement import(), to construct one new object (pre-pppulated
  53. * using field mappings in the Migration). It is expected to call prepare and
  54. * complete handlers, passing them $row (the raw data from the source).
  55. */
  56. abstract public function import(stdClass $object, stdClass $row);
  57. /**
  58. * Derived classes may implement preImport() and/or postImport(), to do any
  59. * processing they need done before or after looping over all source rows.
  60. * Similarly, preRollback() or postRollback() may be implemented.
  61. *
  62. * abstract public function preImport();
  63. * abstract public function postImport();
  64. * abstract public function preRollback();
  65. * abstract public function postRollback();
  66. */
  67. /**
  68. * Maintain stats on the number of destination objects created or updated.
  69. *
  70. * @var int
  71. */
  72. protected $numCreated = 0;
  73. public function getCreated() {
  74. return $this->numCreated;
  75. }
  76. protected $numUpdated = 0;
  77. public function getUpdated() {
  78. return $this->numUpdated;
  79. }
  80. /**
  81. * Reset numCreated and numUpdated back to 0.
  82. */
  83. public function resetStats() {
  84. $this->numCreated = 0;
  85. $this->numUpdated = 0;
  86. }
  87. /**
  88. * Null constructor
  89. */
  90. public function __construct() {
  91. }
  92. }
  93. /**
  94. * All destination handlers should be derived from MigrateDestinationHandler
  95. */
  96. abstract class MigrateDestinationHandler extends MigrateHandler {
  97. // Any one or more of these methods may be implemented
  98. /**
  99. * Documentation of any fields added to the destination by this handler.
  100. *
  101. * @param $entity_type
  102. * The entity type (node, user, etc.) for which to list fields.
  103. * @param $bundle
  104. * The bundle (article, blog, etc.), if any, for which to list fields.
  105. * @param Migration $migration
  106. * Optionally, the migration providing the context.
  107. * @return array
  108. * An array keyed by field name, with field descriptions as values.
  109. */
  110. //abstract public function fields($entity_type, $bundle, $migration = NULL);
  111. //abstract public function prepare($entity, stdClass $row);
  112. //abstract public function complete($entity, stdClass $row);
  113. }