Browse Source

Initial commit by fgm.

Frederic G. MARAND 12 years ago
commit
9ed282a98d
3 changed files with 170 additions and 0 deletions
  1. 141 0
      UnfuddleMigration.inc
  2. 11 0
      migrateunfuddle.info
  3. 18 0
      migrateunfuddle.module

+ 141 - 0
UnfuddleMigration.inc

@@ -0,0 +1,141 @@
+<?php
+/**
+ * @file
+ * Migration class to import user accounts from an Unfuddle dump.
+ *
+ * @copyright Coyright (c) 2011 Ouest Systèmes Informatiques (OSI, OSInet)
+ *
+ * @license Licensed under the General Public License version 2 and later, and the CeCILL 2.0 license.
+ */
+
+class UnfuddlePeopleMigration extends XMLMigration {
+  protected function getFieldInfo() {
+    $fields = array(
+      'account-id'                    => t('Unfuddle account Id'),
+      'id'                            => t('User account ID'),
+      'created-at'                    => t('User account creation timestamp'),
+      'email'                         => t('Current email address for the account'),
+      'first-name'                    => t('User given name'),
+      'identity-url'                  => t('OpenID URL for the user account'),
+      'is-administrator'              => t('User is an Unfuddle project administrator'),
+      'is-removed'                    => t('User account has been removed'),
+      'last-name'                     => t('User last name'),
+      'last-signed-in'                => t('Latest login timestamp'),
+      'notification-frequency'        => t('Unfuddle notification frequency'),
+      'notification-ignore-self'      => t('Ignore self when sending notifications'),
+      'notification-last-sent'        => t('Timestamp of latest notification sent'),
+      'notification-scope-messages'   => t('Send message notifications'),
+      'notification-scope-milestones' => t('Send milestones notifications'),
+      'notification-scope-notebooks'  => t('Send notebooks notifications'),
+      'notification-scope-source'     => t('Send source notifications'),
+      'notification-scope-tickets'    => t('Send tickets notifications'),
+      'text-markup'                   => t('Preferred markup format for issues'),
+      'time-zone'                     => t('Timezone'),
+      'updated-at'                    => t('Timestamp of latest user account change'),
+      'username'                      => t('The user account login name'),
+    );
+
+    return $fields;
+  }
+
+  public function __construct() {
+    parent::__construct(MigrateGroup::getInstance('Unfuddle'));
+
+    $items_url = file_directory_path() . '/unfuddle/backup.xml';
+    $item_xpath = '/account/people/person';
+    $item_ID_xpath = 'id';
+    $items_class = new MigrateItemsXML($items_url, $item_xpath, $item_ID_xpath);
+
+    $this->source = new MigrateSourceMultiItems($items_class, $this->getFieldInfo());
+    $source_key = array(
+      'id' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+      )
+    );
+
+    $this->destination = new MigrateDestinationUser();
+    $this->map = new MigrateSQLMap('unfuddle_people',
+      $source_key,
+      MigrateDestinationUser::getKeySchema());
+
+    // Do not map uid: this prevents user_save from creating the accounts.
+
+    $this->addFieldMapping('created',  'created-at')
+      ->xpath('created-at');
+    $this->addFieldMapping('mail',     'email')
+      ->xpath('email');
+    $this->addFieldMapping('init',     'email')
+      ->defaultValue('support@osinet.fr')
+      ->description(t('Unfuddle does not keep the original email address'));
+    $this->addFieldMapping('status',   'is-removed')
+      ->xpath('is-removed')
+      ->description(t('Inverted when converting to user.status'));
+    $this->addFieldMapping('login',    'last-signed-in')
+      ->xpath('last-signed-in');
+    $this->addFieldMapping('access',   'last-signed-in')
+      ->xpath('last-signed-in')
+      ->description(t('Unfuddle does not log access time, only sign in.'));
+    $this->addFieldMapping('timezone', 'time-zone')
+      ->xpath('time-zone')
+      ->description(t('Only Paris and London currently supported, without DST'));
+    $this->addFieldMapping('name',     'username')
+      ->xpath('username');
+
+    $this->addUnmigratedDestinations(array(
+      'pass',
+      'roles',
+      'theme',
+      'signature',
+      'signature_format',
+      'language',
+      'picture',
+    ), t('White hole'));
+
+    $this->addUnmigratedSources(array(
+      'account-id',
+      'first-name',
+      'identity-url',
+      'is-administrator',
+      'last-name',
+      'notification-frequency',
+      'notification-ignore-self',
+      'notification-last-sent',
+      'notification-scope-messages',
+      'notification-scope-milestones',
+      'notification-scope-notebooks',
+      'notification-scope-source',
+      'notification-scope-tickets',
+      'text-markup',
+      'updated-at',
+      ), t('Black hole'));
+  }
+
+  /**
+   * - Timestamp format conversion not needed, as per MigrationBase::timestamp()
+   * - Invert is-removed to convert to status
+   * - Convert Unfuddle timezones to Drupal offset seconds
+   *
+   * Do not forget type casts when reading SimpleXML elements.
+   *
+   * @param object $row
+   */
+  public function prepareRow(stdClass $row) {
+    // Automatic via MigrationBase::timestamp()
+    // $row->xml->{'created-at'} = strtotime($row->xml->{'created-at'});
+    // $row->xml->{'last-signed-in'} = strtotime($row->xml->{'last-signed-in'});
+
+    $row->xml->{'is-removed'} = ((int) $row->xml->{'is-removed'}) ? 0 : 1;
+
+    // @todo TODO Primitive and does not account for DST
+    $timezones = array(
+      'London' => 0,
+      'Paris'  => 7200,
+    );
+    $timezone = (string) $row->xml->{'time-zone'};
+    $row->xml->{'time-zone'} = empty($timezones[$timezone])
+      ? 0
+      : $timezones[$timezone];
+  }
+}

+ 11 - 0
migrateunfuddle.info

@@ -0,0 +1,11 @@
+name = Migrate Unfuddle
+description = "Import issue data from an Unfuddle dump to Casetracker" 
+core = 6.x
+php = 5.3
+
+dependencies[] = casetracker
+dependencies[] = casetracker_basic
+dependencies[] = migrate
+dependencies[] = views
+
+files[] = UnfuddleMigration.inc

+ 18 - 0
migrateunfuddle.module

@@ -0,0 +1,18 @@
+<?php
+/**
+ * @file
+ * Import an Unfuddle dump into a Drupal Casetracker instance
+ *
+ * @copyright Coyright (c) 2011 Ouest Systèmes Informatiques (OSI, OSInet)
+ * @license Licensed under the General Public License version 2 and later, and
+ *   the CeCILL 2.0 license.
+ */
+
+function migrateunfuddle_migrate_api() {
+  $api = array(
+    'api' => 2,
+  );
+
+  // dsm(get_defined_vars(), __FUNCTION__);
+  return $api;
+}