UnfuddleMigration.inc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /**
  3. * @file
  4. * Migration class to import user accounts from an Unfuddle dump.
  5. *
  6. * @copyright Coyright (c) 2011 Ouest Systèmes Informatiques (OSI, OSInet)
  7. *
  8. * @license Licensed under the General Public License version 2 and later, and the CeCILL 2.0 license.
  9. */
  10. class UnfuddlePeopleMigration extends XMLMigration {
  11. protected function getFieldInfo() {
  12. $fields = array(
  13. 'account-id' => t('Unfuddle account Id'),
  14. 'id' => t('User account ID'),
  15. 'created-at' => t('User account creation timestamp'),
  16. 'email' => t('Current email address for the account'),
  17. 'first-name' => t('User given name'),
  18. 'identity-url' => t('OpenID URL for the user account'),
  19. 'is-administrator' => t('User is an Unfuddle project administrator'),
  20. 'is-removed' => t('User account has been removed'),
  21. 'last-name' => t('User last name'),
  22. 'last-signed-in' => t('Latest login timestamp'),
  23. 'notification-frequency' => t('Unfuddle notification frequency'),
  24. 'notification-ignore-self' => t('Ignore self when sending notifications'),
  25. 'notification-last-sent' => t('Timestamp of latest notification sent'),
  26. 'notification-scope-messages' => t('Send message notifications'),
  27. 'notification-scope-milestones' => t('Send milestones notifications'),
  28. 'notification-scope-notebooks' => t('Send notebooks notifications'),
  29. 'notification-scope-source' => t('Send source notifications'),
  30. 'notification-scope-tickets' => t('Send tickets notifications'),
  31. 'text-markup' => t('Preferred markup format for issues'),
  32. 'time-zone' => t('Timezone'),
  33. 'updated-at' => t('Timestamp of latest user account change'),
  34. 'username' => t('The user account login name'),
  35. );
  36. return $fields;
  37. }
  38. public function __construct() {
  39. parent::__construct(MigrateGroup::getInstance('Unfuddle'));
  40. $items_url = file_directory_path() . '/unfuddle/backup.xml';
  41. $item_xpath = '/account/people/person';
  42. $item_ID_xpath = 'id';
  43. $items_class = new MigrateItemsXML($items_url, $item_xpath, $item_ID_xpath);
  44. $this->source = new MigrateSourceMultiItems($items_class, $this->getFieldInfo());
  45. $source_key = array(
  46. 'id' => array(
  47. 'type' => 'int',
  48. 'unsigned' => TRUE,
  49. 'not null' => TRUE,
  50. )
  51. );
  52. $this->destination = new MigrateDestinationUser();
  53. $this->map = new MigrateSQLMap('unfuddle_people',
  54. $source_key,
  55. MigrateDestinationUser::getKeySchema());
  56. // Do not map uid: this prevents user_save from creating the accounts.
  57. $this->addFieldMapping('created', 'created-at')
  58. ->xpath('created-at');
  59. $this->addFieldMapping('mail', 'email')
  60. ->xpath('email');
  61. $this->addFieldMapping('init', 'email')
  62. ->defaultValue('support@osinet.fr')
  63. ->description(t('Unfuddle does not keep the original email address'));
  64. $this->addFieldMapping('status', 'is-removed')
  65. ->xpath('is-removed')
  66. ->description(t('Inverted when converting to user.status'));
  67. $this->addFieldMapping('login', 'last-signed-in')
  68. ->xpath('last-signed-in');
  69. $this->addFieldMapping('access', 'last-signed-in')
  70. ->xpath('last-signed-in')
  71. ->description(t('Unfuddle does not log access time, only sign in.'));
  72. $this->addFieldMapping('timezone', 'time-zone')
  73. ->xpath('time-zone')
  74. ->description(t('Only Paris and London currently supported, without DST'));
  75. $this->addFieldMapping('name', 'username')
  76. ->xpath('username');
  77. $this->addUnmigratedDestinations(array(
  78. 'pass',
  79. 'roles',
  80. 'theme',
  81. 'signature',
  82. 'signature_format',
  83. 'language',
  84. 'picture',
  85. ), t('White hole'));
  86. $this->addUnmigratedSources(array(
  87. 'account-id',
  88. 'first-name',
  89. 'identity-url',
  90. 'is-administrator',
  91. 'last-name',
  92. 'notification-frequency',
  93. 'notification-ignore-self',
  94. 'notification-last-sent',
  95. 'notification-scope-messages',
  96. 'notification-scope-milestones',
  97. 'notification-scope-notebooks',
  98. 'notification-scope-source',
  99. 'notification-scope-tickets',
  100. 'text-markup',
  101. 'updated-at',
  102. ), t('Black hole'));
  103. }
  104. /**
  105. * - Timestamp format conversion not needed, as per MigrationBase::timestamp()
  106. * - Invert is-removed to convert to status
  107. * - Convert Unfuddle timezones to Drupal offset seconds
  108. *
  109. * Do not forget type casts when reading SimpleXML elements.
  110. *
  111. * @param object $row
  112. */
  113. public function prepareRow(stdClass $row) {
  114. // Automatic via MigrationBase::timestamp()
  115. // $row->xml->{'created-at'} = strtotime($row->xml->{'created-at'});
  116. // $row->xml->{'last-signed-in'} = strtotime($row->xml->{'last-signed-in'});
  117. $row->xml->{'is-removed'} = ((int) $row->xml->{'is-removed'}) ? 0 : 1;
  118. // @todo TODO Primitive and does not account for DST
  119. $timezones = array(
  120. 'London' => 0,
  121. 'Paris' => 7200,
  122. );
  123. $timezone = (string) $row->xml->{'time-zone'};
  124. $row->xml->{'time-zone'} = empty($timezones[$timezone])
  125. ? 0
  126. : $timezones[$timezone];
  127. }
  128. }