destination.inc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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
  17. * destination being implemented. These are used to construct the destination
  18. * key fields 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. *
  36. * @return array
  37. * Keys: machine names of the fields (to be passed to addFieldMapping)
  38. * Values: Human-friendly descriptions of the fields.
  39. */
  40. abstract public function fields();
  41. /**
  42. * Derived classes must implement either bulkRollback or rollback() according
  43. * to the signatures below, to rollback (usually by deletion)
  44. * previously-migrated items.
  45. *
  46. * $ids is an array of single-field keys to be deleted
  47. * abstract public function bulkRollback(array $ids);
  48. *
  49. * $key is an array of fields keying a single entry to delete
  50. * abstract public function rollback(array $key);
  51. */
  52. /**
  53. * Derived classes must implement import(), to construct one new object
  54. * (pre-pppulated using field mappings in the Migration). It is expected to
  55. * call prepare and complete handlers, passing them $row (the raw data from
  56. * the source).
  57. */
  58. abstract public function import(stdClass $object, stdClass $row);
  59. /**
  60. * Derived classes may implement preImport() and/or postImport(), to do any
  61. * processing they need done before or after looping over all source rows.
  62. * Similarly, preRollback() or postRollback() may be implemented.
  63. *
  64. * abstract public function preImport();
  65. * abstract public function postImport();
  66. * abstract public function preRollback();
  67. * abstract public function postRollback();
  68. */
  69. /**
  70. * Maintain stats on the number of destination objects created or updated.
  71. *
  72. * @var int
  73. */
  74. protected $numCreated = 0;
  75. public function getCreated() {
  76. return $this->numCreated;
  77. }
  78. protected $numUpdated = 0;
  79. public function getUpdated() {
  80. return $this->numUpdated;
  81. }
  82. /**
  83. * Reset numCreated and numUpdated back to 0.
  84. */
  85. public function resetStats() {
  86. $this->numCreated = 0;
  87. $this->numUpdated = 0;
  88. }
  89. /**
  90. * Null constructor
  91. */
  92. public function __construct() {
  93. }
  94. }
  95. /**
  96. * All destination handlers should be derived from MigrateDestinationHandler
  97. */
  98. abstract class MigrateDestinationHandler extends MigrateHandler {
  99. // Any one or more of these methods may be implemented
  100. /**
  101. * Documentation of any fields added to the destination by this handler.
  102. *
  103. * @param $entity_type
  104. * The entity type (node, user, etc.) for which to list fields.
  105. * @param $bundle
  106. * The bundle (article, blog, etc.), if any, for which to list fields.
  107. * @param Migration $migration
  108. * Optionally, the migration providing the context.
  109. *
  110. * @return array
  111. * An array keyed by field name, with field descriptions as values.
  112. */
  113. //abstract public function fields($entity_type, $bundle, $migration = NULL);
  114. //abstract public function prepare($entity, stdClass $row);
  115. //abstract public function complete($entity, stdClass $row);
  116. }