map.inc 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. /**
  3. * @file
  4. * Defines the framework for map and message handling.
  5. */
  6. /**
  7. * We implement the Iterator interface to support iteration over the map table
  8. * for the purpose of rollback.
  9. */
  10. abstract class MigrateMap implements Iterator {
  11. /**
  12. * Codes reflecting the current status of a map row.
  13. */
  14. const STATUS_IMPORTED = 0;
  15. const STATUS_NEEDS_UPDATE = 1;
  16. const STATUS_IGNORED = 2;
  17. const STATUS_FAILED = 3;
  18. /**
  19. * Arrays of key fields for the source and destination. Array keys are the
  20. * field names - array values are specific to the concrete map class.
  21. *
  22. * @var array
  23. */
  24. protected $sourceKey, $destinationKey;
  25. abstract public function getSourceKey();
  26. abstract public function getDestinationKey();
  27. /**
  28. * Mapping from field names to the map/message table key names (e.g.,
  29. * from input_field to sourceid1, or from nid to destid1)
  30. *
  31. * @var array
  32. */
  33. protected $sourceKeyMap, $destinationKeyMap;
  34. /**
  35. * Boolean determining whether to track last_imported times in map tables
  36. *
  37. * @var boolean
  38. */
  39. protected $trackLastImported = FALSE;
  40. /**
  41. * Save a mapping from the key values in the source row to the destination
  42. * keys.
  43. *
  44. * @param $source_row
  45. * @param $dest_ids
  46. * @param $status
  47. */
  48. abstract public function saveIDMapping(stdClass $source_row, array $dest_ids,
  49. $status = MigrateMap::STATUS_IMPORTED);
  50. /**
  51. * Record a message related to a source record
  52. *
  53. * @param array $source_key
  54. * Source ID of the record in error
  55. * @param string $message
  56. * The message to record.
  57. * @param int $level
  58. * Optional message severity (defaults to MESSAGE_ERROR).
  59. */
  60. abstract public function saveMessage($source_key, $message, $level = MigrationBase::MESSAGE_ERROR);
  61. /**
  62. * Prepare to run a full update - mark all previously-imported content as
  63. * ready to be re-imported.
  64. */
  65. abstract public function prepareUpdate();
  66. /**
  67. * Report the number of processed items in the map
  68. */
  69. abstract public function processedCount();
  70. /**
  71. * Report the number of imported items in the map
  72. */
  73. abstract public function importedCount();
  74. /**
  75. * Report the number of items that failed to import
  76. */
  77. abstract public function errorCount();
  78. /**
  79. * Report the number of messages
  80. */
  81. abstract public function messageCount();
  82. /**
  83. * Delete the map and message entries for a given source record
  84. *
  85. * @param array $source_key
  86. */
  87. abstract public function delete(array $source_key, $messages_only = FALSE);
  88. /**
  89. * Delete the map and message entries for a given destination record
  90. *
  91. * @param array $destination_key
  92. */
  93. abstract public function deleteDestination(array $destination_key);
  94. /**
  95. * Delete the map and message entries for a set of given source records.
  96. *
  97. * @param array $source_keys
  98. */
  99. abstract public function deleteBulk(array $source_keys);
  100. /**
  101. * Clear all messages from the map.
  102. */
  103. abstract public function clearMessages();
  104. /**
  105. * Retrieve map data for a given source or destination item
  106. */
  107. abstract public function getRowBySource(array $source_id);
  108. abstract public function getRowByDestination(array $destination_id);
  109. /**
  110. * Retrieve an array of map rows marked as needing update.
  111. */
  112. abstract public function getRowsNeedingUpdate($count);
  113. /**
  114. * Given a (possibly multi-field) destination key, return the (possibly multi-field)
  115. * source key mapped to it.
  116. *
  117. * @param array $destination_id
  118. * Array of destination key values.
  119. * @return array
  120. * Array of source key values, or NULL on failure.
  121. */
  122. abstract public function lookupSourceID(array $destination_id);
  123. /**
  124. * Given a (possibly multi-field) source key, return the (possibly multi-field)
  125. * destination key it is mapped to.
  126. *
  127. * @param array $source_id
  128. * Array of source key values.
  129. * @return array
  130. * Array of destination key values, or NULL on failure.
  131. */
  132. abstract public function lookupDestinationID(array $source_id);
  133. /**
  134. * Remove any persistent storage used by this map (e.g., map and message tables)
  135. */
  136. abstract public function destroy();
  137. }