diff --git a/README.txt b/README.txt index 5327f5a..30e966a 100644 --- a/README.txt +++ b/README.txt @@ -4,7 +4,7 @@ * README for Migrate Webform */ -This module is intended to bring the contents of a Drupal 6 Webform +This module is intended to bring the contents of a Drupal 6 or 7 Webform implementation into a new Drupal 7 site, done though the UI using migrate. It relies on the migrate_d2d package so that it is possible to bring over nodes created in the webform type without doing any other configration. It could in diff --git a/components.inc b/components.inc deleted file mode 100644 index 8655d8c..0000000 --- a/components.inc +++ /dev/null @@ -1,94 +0,0 @@ -query($fields); - $table_name = 'webform_component'; - - $this->source = new MigrateSourceSQL($query, $fields, NULL, array('map_joinable' => FALSE, 'skip_count' => FALSE)); - - $this->destination = new MigrateDestinationTable($table_name); - - $this->map = new MigrateSQLMap($this->machineName, - array( - 'nid' => array('type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'description' => 'Source node ID', - 'alias' => 'n', - ), - 'cid' => array('type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'description' => 'Source component ID', - 'alias' => 'c', - ), - ), - MigrateDestinationTable::getKeySchema($table_name) - ); - - $this->addSimpleMappings($simple_fields); - - $this->addFieldMapping('required', 'mandatory'); - - $this->addFieldMapping('nid', 'nid') - ->sourceMigration($arguments['node_migrations']); - - // is private_file enabled on the d6 site? - $connection = Database::getConnection('default', $arguments['source_connection']); - $query = $connection->select('system', 's')->fields('s', array('status')); - $query->condition('s.name', 'private_files', '='); - $this->private_file = $query->execute()->fetchField(); - - } - - protected function query($fields) { - $connection = migrate_webform_get_source_connection(); - $query = $connection - ->select('webform_component', 'wc') - ->fields('wc', $fields) - ->orderBy('cid', 'ASC'); - return $query; - } - - public function prepareRow($row) { - // skip? - if (parent::prepareRow($row) === FALSE) { - return FALSE; - } - - // Users may have put tokens in the default values. - // Prompt user if mapping uknown. - // May be possible to use _token_upgrade_token_list() - // from token.install, returns array('old' => 'new') without % prefix. - if (strpos($row->value, '%') === 0) { - switch($row->value) { - case '%useremail': - $row->value = '[current-user:mail]'; - break; - default: - drupal_set_message(t('The default value of :value in node :nid has not been remapped yet. Please submit a patch or !edit on that node!', array(':value' => $row->value, ':nid' => $row->nid, '!edit' => l('edit component', 'node/' . $row->nid . '/webform/components/' . $row->cid))), 'warning'); - } - } - - if ($this->private_file == TRUE) { - if ($row->type == 'private_file') { - $row->type = 'file'; - $extra = unserialize($row->extra); - $extra['scheme'] = 'private'; - $row->extra = serialize($extra); - } - } - } - - public function prepare($entity, $row) { - } - -} diff --git a/d6/components.inc b/d6/components.inc new file mode 100644 index 0000000..2b3d2fe --- /dev/null +++ b/d6/components.inc @@ -0,0 +1,94 @@ +query($fields); + $table_name = 'webform_component'; + + $this->source = new MigrateSourceSQL($query, $fields, NULL, array('map_joinable' => FALSE, 'skip_count' => FALSE)); + + $this->destination = new MigrateDestinationTable($table_name); + + $this->map = new MigrateSQLMap($this->machineName, + array( + 'nid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source node ID', + 'alias' => 'n', + ), + 'cid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source component ID', + 'alias' => 'c', + ), + ), + MigrateDestinationTable::getKeySchema($table_name) + ); + + $this->addSimpleMappings($simple_fields); + + $this->addFieldMapping('required', 'mandatory'); + + $this->addFieldMapping('nid', 'nid') + ->sourceMigration($arguments['node_migrations']); + + // is private_file enabled on the d6 site? + $connection = Database::getConnection('default', $arguments['source_connection']); + $query = $connection->select('system', 's')->fields('s', array('status')); + $query->condition('s.name', 'private_files', '='); + $this->private_file = $query->execute()->fetchField(); + + } + + protected function query($fields) { + $connection = migrate_webform_get_source_connection(); + $query = $connection + ->select('webform_component', 'wc') + ->fields('wc', $fields) + ->orderBy('cid', 'ASC'); + return $query; + } + + public function prepareRow($row) { + // skip? + if (parent::prepareRow($row) === FALSE) { + return FALSE; + } + + // Users may have put tokens in the default values. + // Prompt user if mapping uknown. + // May be possible to use _token_upgrade_token_list() + // from token.install, returns array('old' => 'new') without % prefix. + if (strpos($row->value, '%') === 0) { + switch($row->value) { + case '%useremail': + $row->value = '[current-user:mail]'; + break; + default: + drupal_set_message(t('The default value of :value in node :nid has not been remapped yet. Please submit a patch or !edit on that node!', array(':value' => $row->value, ':nid' => $row->nid, '!edit' => l('edit component', 'node/' . $row->nid . '/webform/components/' . $row->cid))), 'warning'); + } + } + + if ($this->private_file == TRUE) { + if ($row->type == 'private_file') { + $row->type = 'file'; + $extra = unserialize($row->extra); + $extra['scheme'] = 'private'; + $row->extra = serialize($extra); + } + } + } + + public function prepare($entity, $row) { + } + +} diff --git a/d6/emails.inc b/d6/emails.inc new file mode 100644 index 0000000..fc986fd --- /dev/null +++ b/d6/emails.inc @@ -0,0 +1,66 @@ +query($fields); + $table_name = 'webform_emails'; + + $this->source = new MigrateSourceSQL($query, $fields, NULL, array('map_joinable' => FALSE, 'skip_count' => FALSE)); + + $this->destination = new MigrateDestinationTable($table_name); + + $this->map = new MigrateSQLMap($this->machineName, + array( + 'nid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source node ID', + 'alias' => 'n', + ), + 'eid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source component ID', + 'alias' => 'e', + ), + ), + MigrateDestinationTable::getKeySchema($table_name) + ); + + $this->addSimpleMappings($simple_fields); + + $this->addFieldMapping('nid', 'nid') + ->sourceMigration($arguments['node_migrations']); + $this->addFieldMapping('extra', NULL) + ->defaultValue(serialize(array())); // is this ok empty? + } + + protected function query($fields) { + $connection = migrate_webform_get_source_connection(); + $query = $connection + ->select('webform_emails', 'we') + ->fields('we', $fields) + ->orderBy('eid', 'ASC'); + return $query; + } + + public function prepareRow($row) { + + // skip? + if (parent::prepareRow($row) === FALSE) { + return FALSE; + } + } + + public function prepare($entity, $row) { + } + +} + diff --git a/d6/lastdownload.inc b/d6/lastdownload.inc new file mode 100644 index 0000000..244623a --- /dev/null +++ b/d6/lastdownload.inc @@ -0,0 +1,78 @@ +query($fields); + $table_name = 'webform_last_download'; + + $this->source = new MigrateSourceSQL($query, $fields, NULL, array('map_joinable' => FALSE, 'skip_count' => FALSE)); + + $this->destination = new MigrateDestinationTable($table_name); + + $this->map = new MigrateSQLMap($this->machineName, + array( + 'nid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source node ID', + 'alias' => 'n', + ), + 'uid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source component ID', + 'alias' => 'u', + ), + ), + MigrateDestinationTable::getKeySchema($table_name) + ); + + $this->addSimpleMappings($simple_fields); + + $this->addFieldMapping('nid', 'nid') + ->sourceMigration($arguments['node_migrations']); + + // Get users if configured + // Default uid to 1 if we're not mapping it. + if (variable_get('migrate_webform_user_map_ok', FALSE)) { + $this->removeFieldMapping('uid'); + $this->addFieldMapping('uid', 'uid')->sourceMigration(variable_get('migrate_webform_user_migration_class', ""))->defaultValue(1); + } + else { + $this->removeFieldMapping('uid'); + $this->addFieldMapping('uid', 'uid')->defaultValue(1); + } + + $this->addFieldMapping('sid', 'sid') + ->sourceMigration('WebformSubmissions'); + } + + protected function query($fields) { + $connection = migrate_webform_get_source_connection(); + $query = $connection + ->select('webform_last_download', 'wld') + ->fields('wld', $fields) + ->orderBy('nid', 'ASC'); + return $query; + } + + public function prepareRow($row) { + + // skip? + if (parent::prepareRow($row) === FALSE) { + return FALSE; + } + } + + public function prepare($entity, $row) { + } + +} + diff --git a/d6/node.inc b/d6/node.inc new file mode 100644 index 0000000..6ba7e04 --- /dev/null +++ b/d6/node.inc @@ -0,0 +1,60 @@ +destination_type = $arguments['destination_type']; + if (isset($arguments['roles'])) { + $this->roles = $arguments['roles']; + } + $this->source_db = variable_get('migrate_webform_source_database', 'default'); + + // Keep old NIDs. + $this->addFieldMapping('nid', 'nid') + ->description('Let\'s reuse the old NIDs'); + $this->removeFieldMapping('is_new'); + $this->addFieldMapping('is_new')->defaultvalue(TRUE); + + // Get users if configured + // Default uid to 1 if we're not mapping it. + if (variable_get('migrate_webform_user_map_ok', FALSE)) { + $this->removeFieldMapping('uid'); + $this->addFieldMapping('uid', 'uid')->sourceMigration(variable_get('migrate_webform_user_migration_class', ""))->defaultValue(1); + } + else { + $this->removeFieldMapping('uid'); + $this->addFieldMapping('uid', 'uid')->defaultValue(1); + } + + } + + public function prepareRow($row) { + // skip? + if (parent::prepareRow($row) === FALSE) { + return FALSE; + } + + $result = db_query('select * from webform_roles where nid=:nid', array(':nid' => $row->nid), array('target' => $this->source_db)); + + // deal with role mappings + foreach ($result as $item) { + if (isset($this->roles[$item->rid]['new'])) { + $row->roles[] = $this->roles[$item->rid]['new']; + } + else { + $row->roles = array( 1 , 2 ); + } + } + if (sizeof($row->roles == 0)) { + $row->roles = array( 1 , 2 ); + } + } + + public function prepare($entity, $row) { + $entity->webform['roles'] = $row->roles; + } +} diff --git a/d6/settings.inc b/d6/settings.inc new file mode 100644 index 0000000..f971efd --- /dev/null +++ b/d6/settings.inc @@ -0,0 +1,99 @@ +query($fields); + $table_name = 'webform'; + + $this->source = new MigrateSourceSQL($query, $fields, NULL, array('map_joinable' => FALSE, 'skip_count' => FALSE)); + + $this->destination = new MigrateDestinationTable($table_name); + + $this->map = new MigrateSQLMap($this->machineName, + array( + 'nid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source node ID', + 'alias' => 'n', + ), + ), + MigrateDestinationTable::getKeySchema($table_name) + ); + + $this->addSimpleMappings($simple_fields); + + $this->addFieldMapping('nid', 'nid'); + + $this->addFieldMapping('confirmation_format', 'confirmation_format') + ->callbacks(array($this, 'mapFormat')); + + if (db_field_exists($table_name, 'preview_message')) { + $this->addFieldMapping('preview_message')->defaultValue(''); + } + if (db_field_exists($table_name, 'preview_message_format')) { + $this->addFieldMapping('preview_message_format')->defaultValue($arguments['default_format']); + } + if (db_field_exists($table_name, 'preview_excluded_components')) { + $this->addFieldMapping('preview_excluded_components')->defaultValue(''); + } + } + + protected function query($fields) { + $connection = migrate_webform_get_source_connection(); + $query = $connection + ->select('webform', 'w') + ->fields('w', $fields) + ->orderBy('nid', 'ASC'); + return $query; + } + + // Copied from migrate_d2d. Extending DrupalMigrate wasn't so hot... + protected function mapFormat($format) { + if (!is_array($format)) { + $format = array($format); + } + $result = array(); + foreach ($format as $format_value) { + if (isset($format_value) && isset($this->formatMappings[$format_value])) { + $result[] = $this->formatMappings[$format_value]; + } + else { + $result[] = NULL; + } + } + // Only return an array if we have to + if (count($result) > 1) { + return $result; + } + else { + return reset($result); + } + } + + public function prepareRow($row) { + // skip? + if (parent::prepareRow($row) === FALSE) { + return FALSE; + } + + $row->nid = $this->handleSourceMigration($this->arguments['node_migrations'], $row->nid); + + // Node creation filled the table with a bunch of junk defaults. + db_delete('webform') + ->condition('nid', $row->nid) + ->execute(); + + } + + public function prepare($entity, $row) { + } + +} diff --git a/d6/submissions.inc b/d6/submissions.inc new file mode 100644 index 0000000..32e7b02 --- /dev/null +++ b/d6/submissions.inc @@ -0,0 +1,69 @@ +query($fields); + $table_name = 'webform_submissions'; + + $this->source = new MigrateSourceSQL($query, $fields, NULL, array('map_joinable' => FALSE, 'skip_count' => FALSE)); + + $this->destination = new MigrateDestinationTable($table_name); + + $this->map = new MigrateSQLMap($this->machineName, + array( + 'sid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source component ID', + 'alias' => 's', + ), + ), + MigrateDestinationTable::getKeySchema($table_name) + ); + + $this->addSimpleMappings($simple_fields); + + $this->addFieldMapping('nid', 'nid'); + + $this->addFieldMapping('serial', 'sid'); + + // Get users if configured + // Default uid to 1 if we're not mapping it. + if (variable_get('migrate_webform_user_map_ok', FALSE)) { + $this->removeFieldMapping('uid'); + $this->addFieldMapping('uid', 'uid')->sourceMigration(variable_get('migrate_webform_user_migration_class', ""))->defaultValue(0); + } + else { + $this->removeFieldMapping('uid'); + $this->addFieldMapping('uid', 'uid')->defaultValue(0); + } + } + + protected function query($fields) { + $connection = migrate_webform_get_source_connection(); + $query = $connection + ->select('webform_submissions', 'wss') + ->fields('wss', $fields) + ->orderBy('sid', 'ASC'); + return $query; + } + + public function prepareRow($row) { + // skip? + if (parent::prepareRow($row) === FALSE) { + return FALSE; + } + + $row->nid = $this->handleSourceMigration($this->arguments['node_migrations'], $row->nid); + } + + public function prepare($entity, $row) { + } +} + diff --git a/d6/submitteddata.inc b/d6/submitteddata.inc new file mode 100644 index 0000000..23b5e90 --- /dev/null +++ b/d6/submitteddata.inc @@ -0,0 +1,105 @@ +query($fields); + $table_name = 'webform_submitted_data'; + + $this->source = new MigrateSourceSQL($query, $fields, NULL, array('map_joinable' => FALSE, 'skip_count' => FALSE)); + + $this->destination = new MigrateDestinationTable($table_name); + + $this->map = new MigrateSQLMap($this->machineName, + array( + 'nid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source node ID', + 'alias' => 'n', + ), + 'sid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source submission ID', + 'alias' => 's', + ), + 'cid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source component ID', + 'alias' => 'c', + ), + 'no' => array('type' => 'varchar', + 'length' => 128, + 'not null' => TRUE, + 'description' => 'Source component instance ID?', + 'alias' => 'o', + ), + ), + MigrateDestinationTable::getKeySchema($table_name) + ); + + $this->addSimpleMappings($simple_fields); + + $this->addFieldMapping('nid', 'nid'); + + $this->addFieldMapping('sid', 'sid') + ->sourceMigration('WebformSubmissions'); + $this->addFieldMapping('cid', 'cid'); // @todo consult WebformComponents + // ... but first see https://drupal.org/node/2093073 + } + + protected function query($fields) { + $connection = migrate_webform_get_source_connection(); + $query = $connection + ->select('webform_submitted_data', 'wsd') + ->fields('wsd', $fields) + ->orderBy('sid', 'ASC'); + return $query; + } + + public function prepareRow($row) { + + // skip? + if (parent::prepareRow($row) === FALSE) { + return FALSE; + } + + $row->nid = $this->handleSourceMigration($this->arguments['node_migrations'], $row->nid); + + // find the type of the component we are transferring + // cannot expand the base query because cid is part of the uniqueness + $type = db_select('webform_component', 'wc') + ->fields('wc', array('type', 'name')) + ->condition('cid', $row->cid) + ->condition('nid', $row->nid) + ->execute() + ->fetchField(); + + // mangle the file ID to be the new version + if ($type == 'file' || $type == 'private_file') { + $filemigrations = explode(' ', variable_get('migrate_webform_file_migration_class', "")); + foreach ($filemigrations as $key => $filemigration) { + $destfile = db_select('migrate_map_' . strtolower($filemigration), 'map') + ->fields('map', array('destid1')) + ->condition('map.sourceid1', $row->data) + ->execute() + ->fetchField(); + if ($destfile != NULL) { + $row->data = $destfile; + file_usage_add(file_load($destfile), 'webform', 'submission', $row->sid); + } + } + } + } + + public function prepare($entity, $row) { + } +} + diff --git a/d6/validationrule.inc b/d6/validationrule.inc new file mode 100644 index 0000000..e21c066 --- /dev/null +++ b/d6/validationrule.inc @@ -0,0 +1,60 @@ +query($fields); + $table_name = 'webform_validation_rule'; + + $this->source = new MigrateSourceSQL($query, $fields, NULL, array('map_joinable' => FALSE, 'skip_count' => FALSE)); + + $this->destination = new MigrateDestinationTable($table_name); + + $this->map = new MigrateSQLMap($this->machineName, + array( + 'ruleid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source node ID', + 'alias' => 'r', + ), + ), + MigrateDestinationTable::getKeySchema($table_name) + ); + + $this->addSimpleMappings($simple_fields); + + $this->addFieldMapping('nid', 'nid') + ->sourceMigration($arguments['node_migrations']); + } + + protected function query($fields) { + $connection = migrate_webform_get_source_connection(); + $query = $connection + ->select('webform_validation_rule', 'wvr') + ->fields('wvr', $fields) + ->orderBy('ruleid', 'ASC'); + return $query; + } + + public function prepareRow($row) { + + // skip? + if (parent::prepareRow($row) === FALSE) { + return FALSE; + } + + $row->nid = $this->handleSourceMigration($this->arguments['node_migrations'], $row->nid); + } + + public function prepare($entity, $row) { + } + +} + diff --git a/d6/validationrulecomponents.inc b/d6/validationrulecomponents.inc new file mode 100644 index 0000000..899ea98 --- /dev/null +++ b/d6/validationrulecomponents.inc @@ -0,0 +1,71 @@ +query($fields); + $table_name = 'webform_validation_rule_components'; + + $this->source = new MigrateSourceSQL($query, $fields, NULL, array('map_joinable' => FALSE, 'skip_count' => FALSE)); + + $this->destination = new MigrateDestinationTable($table_name); + + $this->map = new MigrateSQLMap($this->machineName, + array( + 'ruleid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source rule ID', + 'alias' => 'r', + ), + 'cid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source component ID', + 'alias' => 'c', + ), + ), + MigrateDestinationTable::getKeySchema($table_name) + ); + + + $this->addSimpleMappings($simple_fields); + + // @todo WebformComponents sourceMigration doesn't work (keys hard to line up) + $this->addFieldMapping('cid', 'cid'); + } + + protected function query($fields) { + $connection = migrate_webform_get_source_connection(); + $query = $connection + ->select('webform_validation_rule_components', 'wvrc') + ->fields('wvrc', $fields) + ->orderBy('ruleid', 'ASC'); + return $query; + } + + public function prepareRow($row) { + + // skip? + if (parent::prepareRow($row) === FALSE) { + return FALSE; + } + + $row->nid = $this->handleSourceMigration($this->arguments['node_migrations'], $row->nid); + } + + public function prepare($entity, $row) { + } + +} + + + + + diff --git a/d7/components.inc b/d7/components.inc new file mode 100644 index 0000000..f0a2452 --- /dev/null +++ b/d7/components.inc @@ -0,0 +1,93 @@ +query($fields); + $table_name = 'webform_component'; + + $this->source = new MigrateSourceSQL($query, $fields, NULL, array('map_joinable' => FALSE, 'skip_count' => FALSE)); + + $this->destination = new MigrateDestinationTable($table_name); + + $this->map = new MigrateSQLMap($this->machineName, + array( + 'nid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source node ID', + 'alias' => 'n', + ), + 'cid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source component ID', + 'alias' => 'c', + ), + ), + MigrateDestinationTable::getKeySchema($table_name) + ); + + $this->addSimpleMappings($simple_fields); + + $this->addFieldMapping('nid', 'nid') + ->sourceMigration($arguments['node_migrations']); + + // is private_file enabled on the d6 site? + $connection = Database::getConnection('default', $arguments['source_connection']); + $query = $connection->select('system', 's')->fields('s', array('status')); + $query->condition('s.name', 'private_files', '='); + $this->private_file = $query->execute()->fetchField(); + + } + + protected function query($fields) { + $connection = migrate_webform_get_source_connection(); + $query = $connection + ->select('webform_component', 'wc') + ->fields('wc', $fields) + ->orderBy('cid', 'ASC'); + return $query; + } + + public function prepareRow($row) { + // skip? + if (parent::prepareRow($row) === FALSE) { + return FALSE; + } + + // Users may have put tokens in the default values. + // Prompt user if mapping uknown. + // May be possible to use _token_upgrade_token_list() + // from token.install, returns array('old' => 'new') without % prefix. + if (strpos($row->value, '%') === 0) { + switch($row->value) { + case '%useremail': + $row->value = '[current-user:mail]'; + break; + default: + drupal_set_message(t('The default value of :value in node :nid has not been remapped yet. Please submit a patch or !edit on that node!', array(':value' => $row->value, ':nid' => $row->nid, '!edit' => l('edit component', 'node/' . $row->nid . '/webform/components/' . $row->cid))), 'warning'); + } + } + + if ($this->private_file == TRUE) { + if ($row->type == 'private_file') { + $row->type = 'file'; + $extra = unserialize($row->extra); + $extra['scheme'] = 'private'; + $row->extra = serialize($extra); + } + } + } + + public function prepare($entity, $row) { + } + +} diff --git a/d7/conditional.inc b/d7/conditional.inc new file mode 100644 index 0000000..bff061e --- /dev/null +++ b/d7/conditional.inc @@ -0,0 +1,66 @@ +query($fields); + $table_name = 'webform_conditional'; + + $this->source = new MigrateSourceSQL($query, $fields, NULL, array('map_joinable' => FALSE, 'skip_count' => FALSE)); + + $this->destination = new MigrateDestinationTable($table_name); + + $this->map = new MigrateSQLMap($this->machineName, + array( + 'nid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source node ID', + 'alias' => 'n', + ), + 'rgid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source rule group ID', + 'alias' => 'r', + ), + ), + MigrateDestinationTable::getKeySchema($table_name) + ); + + $this->addSimpleMappings($simple_fields); + + $this->addFieldMapping('nid', 'nid') + ->sourceMigration($arguments['node_migrations']); + } + + protected function query($fields) { + $connection = migrate_webform_get_source_connection(); + $query = $connection + ->select('webform_conditional', 'wc') + ->fields('wc', $fields) + ->orderBy('rgid', 'ASC'); + return $query; + } + + public function prepareRow($row) { + + // skip? + if (parent::prepareRow($row) === FALSE) { + return FALSE; + } + + $row->nid = $this->handleSourceMigration($this->arguments['node_migrations'], $row->nid); + } + + public function prepare($entity, $row) { + } + +} + diff --git a/d7/conditionalactions.inc b/d7/conditionalactions.inc new file mode 100644 index 0000000..acefda6 --- /dev/null +++ b/d7/conditionalactions.inc @@ -0,0 +1,72 @@ +query($fields); + $table_name = 'webform_conditional_actions'; + + $this->source = new MigrateSourceSQL($query, $fields, NULL, array('map_joinable' => FALSE, 'skip_count' => FALSE)); + + $this->destination = new MigrateDestinationTable($table_name); + + $this->map = new MigrateSQLMap($this->machineName, + array( + 'nid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source node ID', + 'alias' => 'n', + ), + 'rgid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source rule group ID', + 'alias' => 'r', + ), + 'aid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source rule action ID', + 'alias' => 'a', + ), + ), + MigrateDestinationTable::getKeySchema($table_name) + ); + + $this->addSimpleMappings($simple_fields); + + $this->addFieldMapping('nid', 'nid') + ->sourceMigration($arguments['node_migrations']); + } + + protected function query($fields) { + $connection = migrate_webform_get_source_connection(); + $query = $connection + ->select('webform_conditional_actions', 'wca') + ->fields('wca', $fields) + ->orderBy('rgid', 'ASC'); + return $query; + } + + public function prepareRow($row) { + + // skip? + if (parent::prepareRow($row) === FALSE) { + return FALSE; + } + + $row->nid = $this->handleSourceMigration($this->arguments['node_migrations'], $row->nid); + } + + public function prepare($entity, $row) { + } + +} + diff --git a/d7/conditionalrules.inc b/d7/conditionalrules.inc new file mode 100644 index 0000000..f8d8f96 --- /dev/null +++ b/d7/conditionalrules.inc @@ -0,0 +1,72 @@ +query($fields); + $table_name = 'webform_conditional_rules'; + + $this->source = new MigrateSourceSQL($query, $fields, NULL, array('map_joinable' => FALSE, 'skip_count' => FALSE)); + + $this->destination = new MigrateDestinationTable($table_name); + + $this->map = new MigrateSQLMap($this->machineName, + array( + 'nid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source node ID', + 'alias' => 'n', + ), + 'rgid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source rule group ID', + 'alias' => 'r', + ), + 'rid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source rule ID', + 'alias' => 'r', + ), + ), + MigrateDestinationTable::getKeySchema($table_name) + ); + + $this->addSimpleMappings($simple_fields); + + $this->addFieldMapping('nid', 'nid') + ->sourceMigration($arguments['node_migrations']); + } + + protected function query($fields) { + $connection = migrate_webform_get_source_connection(); + $query = $connection + ->select('webform_conditional_rules', 'wcr') + ->fields('wcr', $fields) + ->orderBy('rgid', 'ASC'); + return $query; + } + + public function prepareRow($row) { + + // skip? + if (parent::prepareRow($row) === FALSE) { + return FALSE; + } + + $row->nid = $this->handleSourceMigration($this->arguments['node_migrations'], $row->nid); + } + + public function prepare($entity, $row) { + } + +} + diff --git a/d7/emails.inc b/d7/emails.inc new file mode 100644 index 0000000..a624a7d --- /dev/null +++ b/d7/emails.inc @@ -0,0 +1,66 @@ +query($fields); + $table_name = 'webform_emails'; + + $this->source = new MigrateSourceSQL($query, $fields, NULL, array('map_joinable' => FALSE, 'skip_count' => FALSE)); + + $this->destination = new MigrateDestinationTable($table_name); + + $this->map = new MigrateSQLMap($this->machineName, + array( + 'nid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source node ID', + 'alias' => 'n', + ), + 'eid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source component ID', + 'alias' => 'e', + ), + ), + MigrateDestinationTable::getKeySchema($table_name) + ); + + $this->addSimpleMappings($simple_fields); + + $this->addFieldMapping('nid', 'nid') + ->sourceMigration($arguments['node_migrations']); + $this->addFieldMapping('extra', NULL) + ->defaultValue(serialize(array())); // is this ok empty? + } + + protected function query($fields) { + $connection = migrate_webform_get_source_connection(); + $query = $connection + ->select('webform_emails', 'we') + ->fields('we', $fields) + ->orderBy('eid', 'ASC'); + return $query; + } + + public function prepareRow($row) { + + // skip? + if (parent::prepareRow($row) === FALSE) { + return FALSE; + } + } + + public function prepare($entity, $row) { + } + +} + diff --git a/d7/lastdownload.inc b/d7/lastdownload.inc new file mode 100644 index 0000000..1dc3ad4 --- /dev/null +++ b/d7/lastdownload.inc @@ -0,0 +1,78 @@ +query($fields); + $table_name = 'webform_last_download'; + + $this->source = new MigrateSourceSQL($query, $fields, NULL, array('map_joinable' => FALSE, 'skip_count' => FALSE)); + + $this->destination = new MigrateDestinationTable($table_name); + + $this->map = new MigrateSQLMap($this->machineName, + array( + 'nid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source node ID', + 'alias' => 'n', + ), + 'uid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source component ID', + 'alias' => 'u', + ), + ), + MigrateDestinationTable::getKeySchema($table_name) + ); + + $this->addSimpleMappings($simple_fields); + + $this->addFieldMapping('nid', 'nid') + ->sourceMigration($arguments['node_migrations']); + + // Get users if configured + // Default uid to 1 if we're not mapping it. + if (variable_get('migrate_webform_user_map_ok', FALSE)) { + $this->removeFieldMapping('uid'); + $this->addFieldMapping('uid', 'uid')->sourceMigration(variable_get('migrate_webform_user_migration_class', ""))->defaultValue(1); + } + else { + $this->removeFieldMapping('uid'); + $this->addFieldMapping('uid', 'uid')->defaultValue(1); + } + + $this->addFieldMapping('sid', 'sid') + ->sourceMigration('WebformSubmissions'); + } + + protected function query($fields) { + $connection = migrate_webform_get_source_connection(); + $query = $connection + ->select('webform_last_download', 'wld') + ->fields('wld', $fields) + ->orderBy('nid', 'ASC'); + return $query; + } + + public function prepareRow($row) { + + // skip? + if (parent::prepareRow($row) === FALSE) { + return FALSE; + } + } + + public function prepare($entity, $row) { + } + +} + diff --git a/d7/node.inc b/d7/node.inc new file mode 100644 index 0000000..b4560bc --- /dev/null +++ b/d7/node.inc @@ -0,0 +1,60 @@ +destination_type = $arguments['destination_type']; + if (isset($arguments['roles'])) { + $this->roles = $arguments['roles']; + } + $this->source_db = variable_get('migrate_webform_source_database', 'default'); + + // Keep old NIDs. + // $this->addFieldMapping('nid', 'nid') + // ->description('Let\'s reuse the old NIDs'); + // $this->removeFieldMapping('is_new'); + // $this->addFieldMapping('is_new')->defaultvalue(TRUE); + + // Get users if configured + // Default uid to 1 if we're not mapping it. + if (variable_get('migrate_webform_user_map_ok', FALSE)) { + $this->removeFieldMapping('uid'); + $this->addFieldMapping('uid', 'uid')->sourceMigration(variable_get('migrate_webform_user_migration_class', ""))->defaultValue(1); + } + else { + $this->removeFieldMapping('uid'); + $this->addFieldMapping('uid', 'uid')->defaultValue(1); + } + + } + + public function prepareRow($row) { + // skip? + if (parent::prepareRow($row) === FALSE) { + return FALSE; + } + + $result = db_query('select * from webform_roles where nid=:nid', array(':nid' => $row->nid), array('target' => $this->source_db)); + + // deal with role mappings + foreach ($result as $item) { + if (isset($this->roles[$item->rid]['new'])) { + $row->roles[] = $this->roles[$item->rid]['new']; + } + else { + $row->roles = array( 1 , 2 ); + } + } + if (sizeof($row->roles == 0)) { + $row->roles = array( 1 , 2 ); + } + } + + public function prepare($entity, $row) { + $entity->webform['roles'] = $row->roles; + } +} diff --git a/d7/settings.inc b/d7/settings.inc new file mode 100644 index 0000000..efc999f --- /dev/null +++ b/d7/settings.inc @@ -0,0 +1,102 @@ +query($fields); + $table_name = 'webform'; + + $this->source = new MigrateSourceSQL($query, $fields, NULL, array('map_joinable' => FALSE, 'skip_count' => FALSE)); + + $this->destination = new MigrateDestinationTable($table_name); + + $this->map = new MigrateSQLMap($this->machineName, + array( + 'nid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source node ID', + 'alias' => 'n', + ), + ), + MigrateDestinationTable::getKeySchema($table_name) + ); + + $this->addSimpleMappings($simple_fields); + + $this->addFieldMapping('nid', 'nid'); + + $this->addFieldMapping('confirmation_format', 'confirmation_format') + ->callbacks(array($this, 'mapFormat')); + + if (db_field_exists($table_name, 'preview_message')) { + $this->addFieldMapping('preview_message')->defaultValue(''); + } + if (db_field_exists($table_name, 'preview_message_format')) { + $this->addFieldMapping('preview_message_format')->defaultValue($arguments['default_format']); + } + if (db_field_exists($table_name, 'preview_excluded_components')) { + $this->addFieldMapping('preview_excluded_components')->defaultValue(''); + } + } + + protected function query($fields) { + $connection = migrate_webform_get_source_connection(); + $query = $connection + ->select('webform', 'w') + ->fields('w', $fields) + ->orderBy('nid', 'ASC'); + return $query; + } + + // Copied from migrate_d2d. Extending DrupalMigrate wasn't so hot... + protected function mapFormat($format) { + if (!is_array($format)) { + $format = array($format); + } + $result = array(); + foreach ($format as $format_value) { + if (isset($format_value) && isset($this->formatMappings[$format_value])) { + $result[] = $this->formatMappings[$format_value]; + } + else { + $result[] = NULL; + } + } + // Only return an array if we have to + if (count($result) > 1) { + return $result; + } + else { + return reset($result); + } + } + + public function prepareRow($row) { + // skip? + if (parent::prepareRow($row) === FALSE) { + return FALSE; + } + + $row->nid = $this->handleSourceMigration($this->arguments['node_migrations'], $row->nid); + + // Node creation filled the table with a bunch of junk defaults. + db_delete('webform') + ->condition('nid', $row->nid) + ->execute(); + + } + + public function prepare($entity, $row) { + } + +} diff --git a/d7/submissions.inc b/d7/submissions.inc new file mode 100644 index 0000000..106d3f5 --- /dev/null +++ b/d7/submissions.inc @@ -0,0 +1,70 @@ +query($fields); + $table_name = 'webform_submissions'; + + $this->source = new MigrateSourceSQL($query, $fields, NULL, array('map_joinable' => FALSE, 'skip_count' => FALSE)); + + $this->destination = new MigrateDestinationTable($table_name); + + $this->map = new MigrateSQLMap($this->machineName, + array( + 'sid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source component ID', + 'alias' => 's', + ), + ), + MigrateDestinationTable::getKeySchema($table_name) + ); + + $this->addSimpleMappings($simple_fields); + + $this->addFieldMapping('nid', 'nid'); + + $this->addFieldMapping('serial', 'sid'); + + // Get users if configured + // Default uid to 1 if we're not mapping it. + if (variable_get('migrate_webform_user_map_ok', FALSE)) { + $this->removeFieldMapping('uid'); + $this->addFieldMapping('uid', 'uid')->sourceMigration(variable_get('migrate_webform_user_migration_class', ""))->defaultValue(0); + } + else { + $this->removeFieldMapping('uid'); + $this->addFieldMapping('uid', 'uid')->defaultValue(0); + } + } + + protected function query($fields) { + $connection = migrate_webform_get_source_connection(); + $query = $connection + ->select('webform_submissions', 'wss') + ->fields('wss', $fields) + ->orderBy('sid', 'ASC'); + return $query; + } + + public function prepareRow($row) { + // skip? + if (parent::prepareRow($row) === FALSE) { + return FALSE; + } + + $row->nid = $this->handleSourceMigration($this->arguments['node_migrations'], $row->nid); + } + + public function prepare($entity, $row) { + } +} + diff --git a/d7/submitteddata.inc b/d7/submitteddata.inc new file mode 100644 index 0000000..2365484 --- /dev/null +++ b/d7/submitteddata.inc @@ -0,0 +1,105 @@ +query($fields); + $table_name = 'webform_submitted_data'; + + $this->source = new MigrateSourceSQL($query, $fields, NULL, array('map_joinable' => FALSE, 'skip_count' => FALSE)); + + $this->destination = new MigrateDestinationTable($table_name); + + $this->map = new MigrateSQLMap($this->machineName, + array( + 'nid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source node ID', + 'alias' => 'n', + ), + 'sid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source submission ID', + 'alias' => 's', + ), + 'cid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source component ID', + 'alias' => 'c', + ), + 'no' => array('type' => 'varchar', + 'length' => 128, + 'not null' => TRUE, + 'description' => 'Source component instance ID?', + 'alias' => 'o', + ), + ), + MigrateDestinationTable::getKeySchema($table_name) + ); + + $this->addSimpleMappings($simple_fields); + + $this->addFieldMapping('nid', 'nid'); + + $this->addFieldMapping('sid', 'sid') + ->sourceMigration('WebformSubmissions'); + $this->addFieldMapping('cid', 'cid'); // @todo consult WebformComponents + // ... but first see https://drupal.org/node/2093073 + } + + protected function query($fields) { + $connection = migrate_webform_get_source_connection(); + $query = $connection + ->select('webform_submitted_data', 'wsd') + ->fields('wsd', $fields) + ->orderBy('sid', 'ASC'); + return $query; + } + + public function prepareRow($row) { + + // skip? + if (parent::prepareRow($row) === FALSE) { + return FALSE; + } + + $row->nid = $this->handleSourceMigration($this->arguments['node_migrations'], $row->nid); + + // find the type of the component we are transferring + // cannot expand the base query because cid is part of the uniqueness + $type = db_select('webform_component', 'wc') + ->fields('wc', array('type', 'name')) + ->condition('cid', $row->cid) + ->condition('nid', $row->nid) + ->execute() + ->fetchField(); + + // mangle the file ID to be the new version + if ($type == 'file' || $type == 'private_file') { + $filemigrations = explode(' ', variable_get('migrate_webform_file_migration_class', "")); + foreach ($filemigrations as $key => $filemigration) { + $destfile = db_select('migrate_map_' . strtolower($filemigration), 'map') + ->fields('map', array('destid1')) + ->condition('map.sourceid1', $row->data) + ->execute() + ->fetchField(); + if ($destfile != NULL) { + $row->data = $destfile; + file_usage_add(file_load($destfile), 'webform', 'submission', $row->sid); + } + } + } + } + + public function prepare($entity, $row) { + } +} + diff --git a/d7/validationrule.inc b/d7/validationrule.inc new file mode 100644 index 0000000..113028f --- /dev/null +++ b/d7/validationrule.inc @@ -0,0 +1,60 @@ +query($fields); + $table_name = 'webform_validation_rule'; + + $this->source = new MigrateSourceSQL($query, $fields, NULL, array('map_joinable' => FALSE, 'skip_count' => FALSE)); + + $this->destination = new MigrateDestinationTable($table_name); + + $this->map = new MigrateSQLMap($this->machineName, + array( + 'ruleid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source node ID', + 'alias' => 'r', + ), + ), + MigrateDestinationTable::getKeySchema($table_name) + ); + + $this->addSimpleMappings($simple_fields); + + $this->addFieldMapping('nid', 'nid') + ->sourceMigration($arguments['node_migrations']); + } + + protected function query($fields) { + $connection = migrate_webform_get_source_connection(); + $query = $connection + ->select('webform_validation_rule', 'wvr') + ->fields('wvr', $fields) + ->orderBy('ruleid', 'ASC'); + return $query; + } + + public function prepareRow($row) { + + // skip? + if (parent::prepareRow($row) === FALSE) { + return FALSE; + } + + $row->nid = $this->handleSourceMigration($this->arguments['node_migrations'], $row->nid); + } + + public function prepare($entity, $row) { + } + +} + diff --git a/d7/validationrulecomponents.inc b/d7/validationrulecomponents.inc new file mode 100644 index 0000000..856f3d9 --- /dev/null +++ b/d7/validationrulecomponents.inc @@ -0,0 +1,52 @@ +query($fields); + $table_name = 'webform_validation_rule_components'; + + $this->source = new MigrateSourceSQL($query, $fields, NULL, array('map_joinable' => FALSE, 'skip_count' => FALSE)); + + $this->destination = new MigrateDestinationTable($table_name); + + $this->map = new MigrateSQLMap($this->machineName, + array( + 'ruleid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source rule ID', + 'alias' => 'r', + ), + 'cid' => array('type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Source component ID', + 'alias' => 'c', + ), + ), + MigrateDestinationTable::getKeySchema($table_name) + ); + + + $this->addSimpleMappings($simple_fields); + + // @todo WebformComponents sourceMigration doesn't work (keys hard to line up) + $this->addFieldMapping('cid', 'cid'); + } + + protected function query($fields) { + $connection = migrate_webform_get_source_connection(); + $query = $connection + ->select('webform_validation_rule_components', 'wvrc') + ->fields('wvrc', $fields) + ->orderBy('ruleid', 'ASC'); + return $query; + } +} diff --git a/emails.inc b/emails.inc deleted file mode 100644 index d83681c..0000000 --- a/emails.inc +++ /dev/null @@ -1,66 +0,0 @@ -query($fields); - $table_name = 'webform_emails'; - - $this->source = new MigrateSourceSQL($query, $fields, NULL, array('map_joinable' => FALSE, 'skip_count' => FALSE)); - - $this->destination = new MigrateDestinationTable($table_name); - - $this->map = new MigrateSQLMap($this->machineName, - array( - 'nid' => array('type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'description' => 'Source node ID', - 'alias' => 'n', - ), - 'eid' => array('type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'description' => 'Source component ID', - 'alias' => 'e', - ), - ), - MigrateDestinationTable::getKeySchema($table_name) - ); - - $this->addSimpleMappings($simple_fields); - - $this->addFieldMapping('nid', 'nid') - ->sourceMigration($arguments['node_migrations']); - $this->addFieldMapping('extra', NULL) - ->defaultValue(serialize(array())); // is this ok empty? - } - - protected function query($fields) { - $connection = migrate_webform_get_source_connection(); - $query = $connection - ->select('webform_emails', 'we') - ->fields('we', $fields) - ->orderBy('eid', 'ASC'); - return $query; - } - - public function prepareRow($row) { - - // skip? - if (parent::prepareRow($row) === FALSE) { - return FALSE; - } - } - - public function prepare($entity, $row) { - } - -} - diff --git a/lastdownload.inc b/lastdownload.inc deleted file mode 100644 index b720ad4..0000000 --- a/lastdownload.inc +++ /dev/null @@ -1,78 +0,0 @@ -query($fields); - $table_name = 'webform_last_download'; - - $this->source = new MigrateSourceSQL($query, $fields, NULL, array('map_joinable' => FALSE, 'skip_count' => FALSE)); - - $this->destination = new MigrateDestinationTable($table_name); - - $this->map = new MigrateSQLMap($this->machineName, - array( - 'nid' => array('type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'description' => 'Source node ID', - 'alias' => 'n', - ), - 'uid' => array('type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'description' => 'Source component ID', - 'alias' => 'u', - ), - ), - MigrateDestinationTable::getKeySchema($table_name) - ); - - $this->addSimpleMappings($simple_fields); - - $this->addFieldMapping('nid', 'nid') - ->sourceMigration($arguments['node_migrations']); - - // Get users if configured - // Default uid to 1 if we're not mapping it. - if (variable_get('migrate_webform_user_map_ok', FALSE)) { - $this->removeFieldMapping('uid'); - $this->addFieldMapping('uid', 'uid')->sourceMigration(variable_get('migrate_webform_user_migration_class', ""))->defaultValue(1); - } - else { - $this->removeFieldMapping('uid'); - $this->addFieldMapping('uid', 'uid')->defaultValue(1); - } - - $this->addFieldMapping('sid', 'sid') - ->sourceMigration('WebformSubmissions'); - } - - protected function query($fields) { - $connection = migrate_webform_get_source_connection(); - $query = $connection - ->select('webform_last_download', 'wld') - ->fields('wld', $fields) - ->orderBy('nid', 'ASC'); - return $query; - } - - public function prepareRow($row) { - - // skip? - if (parent::prepareRow($row) === FALSE) { - return FALSE; - } - } - - public function prepare($entity, $row) { - } - -} - diff --git a/migrate_webform.info b/migrate_webform.info index 5779a2b..556378a 100644 --- a/migrate_webform.info +++ b/migrate_webform.info @@ -1,5 +1,5 @@ name = Migrate Webform -description = "Migration from Drupal 6 Webforms" +description = "Migration from Drupal 6/7 Webforms" package = "Migration" core = 7.x @@ -10,13 +10,28 @@ files[] = migrate_webform.install files[] = migrate_webform.module files[] = migrate_webform.migrate.inc -files[] = node.inc -files[] = settings.inc -files[] = components.inc -files[] = emails.inc -files[] = lastdownload.inc -files[] = submissions.inc -files[] = submitteddata.inc +files[] = d6/node.inc +files[] = d6/settings.inc +files[] = d6/components.inc +files[] = d6/emails.inc +files[] = d6/lastdownload.inc +files[] = d6/submissions.inc +files[] = d6/submitteddata.inc + +files[] = d6/validationrulecomponents.inc +files[] = d6/validationrule.inc + +files[] = d7/node.inc +files[] = d7/settings.inc +files[] = d7/components.inc +files[] = d7/emails.inc +files[] = d7/lastdownload.inc +files[] = d7/submissions.inc +files[] = d7/submitteddata.inc +files[] = d7/conditional.inc +files[] = d7/conditionalactions.inc +files[] = d7/conditionalrules.inc + +files[] = d7/validationrulecomponents.inc +files[] = d7/validationrule.inc -files[] = validationrulecomponents.inc -files[] = validationrule.inc diff --git a/migrate_webform.migrate.inc b/migrate_webform.migrate.inc index 17bde73..b56e6a1 100644 --- a/migrate_webform.migrate.inc +++ b/migrate_webform.migrate.inc @@ -11,29 +11,32 @@ */ function migrate_webform_migrate_api() { $configured = variable_get('migrate_webform_source_database', FALSE); + $source_version = substr(variable_get('migrate_webform_source_database_api_version', 'd6'), 1, 1); /** * Pre-set common arguments for creating classes. */ $common_arguments = array( 'source_connection' => variable_get('migrate_webform_source_database', 'default'), - 'source_version'=> substr(variable_get('migrate_webform_source_database_api_version', 'd6'), 1, 1), + 'source_version'=> $source_version, 'group_name' => 'webform', 'format_mappings' => array( '1' => 'filtered_html', ), - 'node_migrations' => explode(' ', variable_get('migrate_webform_node_migration_class', "WebformNode")), + 'default_format' => variable_get('migrate_webform_default_filter_format', 'plain_text'), + 'node_migrations' => explode(' ', variable_get('migrate_webform_node_migration_class', 'WebformNode' . $source_version)), ); /** * Node migration */ if (variable_get('migrate_webform_node_map_ok', TRUE)) { + $common_arguments['node_migrations'] = array('WebformNode'); $roles = migrate_webform_get_roles(); $node_arguments = array( array( - 'class_name' => 'WebformNode', - 'description' => t('Migration of webform nodes from Drupal 6'), + 'class_name' => 'WebformNode' . $source_version, + 'description' => t('Migration of webform nodes from Drupal ' . $source_version), 'machine_name' => 'WebformNode', 'source_type' => 'webform', 'destination_type' => 'webform', @@ -52,56 +55,74 @@ function migrate_webform_migrate_api() { * Webforms */ $settings_arguments = $common_arguments + array( - 'class_name' => 'WebformSettings', + 'class_name' => 'WebformSettings' . $source_version, 'machine_name' => 'WebformSettings', - 'description' => t('Migration of settings for webforms from Drupal 6'), + 'description' => t('Migration of settings for webforms from Drupal ' . $source_version), 'dependencies' => $common_arguments['node_migrations'], ); $components_arguments = $common_arguments + array( - 'class_name' => 'WebformComponents', + 'class_name' => 'WebformComponents' . $source_version, 'machine_name' => 'WebformComponents', - 'description' => t('Migration of components for webforms from Drupal 6'), + 'description' => t('Migration of components for webforms from Drupal ' . $source_version), 'dependencies' => array('WebformSettings'), ); $emails_arguments = $common_arguments + array( - 'class_name' => 'WebformEmails', + 'class_name' => 'WebformEmails' . $source_version, 'machine_name' => 'WebformEmails', - 'description' => t('Migration of settings for webforms from Drupal 6'), + 'description' => t('Migration of settings for webforms from Drupal ' . $source_version), 'dependencies' => array('WebformComponents'), ); $submissions_arguments = $common_arguments + array( - 'class_name' => 'WebformSubmissions', + 'class_name' => 'WebformSubmissions' . $source_version, 'machine_name' => 'WebformSubmissions', - 'description' => t('Migration of submissions for webforms from Drupal 6'), + 'description' => t('Migration of submissions for webforms from Drupal ' . $source_version), 'dependencies' => array('WebformEmails'), ); $submitted_data_arguments = $common_arguments + array( - 'class_name' => 'WebformSubmittedData', + 'class_name' => 'WebformSubmittedData' . $source_version, 'machine_name' => 'WebformSubmittedData', - 'description' => t('Migration of submitted data for webforms from Drupal 6'), + 'description' => t('Migration of submitted data for webforms from Drupal ' . $source_version), 'dependencies' => array('WebformSubmissions'), ); $last_download_arguments = $common_arguments + array( - 'class_name' => 'WebformLastDownload', + 'class_name' => 'WebformLastDownload' . $source_version, 'machine_name' => 'WebformLastDownload', - 'description' => t('Migration of last download of submission logs by webform administrators from Drupal 6'), + 'description' => t('Migration of last download of submission logs by webform administrators from Drupal ' . $source_version), 'dependencies' => array('WebformSubmittedData'), ); + $conditional_arguments = $common_arguments + array( + 'class_name' => 'WebformConditional' . $source_version, + 'machine_name' => 'WebformConditional', + 'description' => t('Migration of conditional from Drupal ' . $source_version), + 'dependencies' => array('WebformLastDownload'), + ); + $conditional_actions_arguments = $common_arguments + array( + 'class_name' => 'WebformConditionalActions' . $source_version, + 'machine_name' => 'WebformConditionalActions', + 'description' => t('Migration of conditional actions from Drupal ' . $source_version), + 'dependencies' => array('WebformConditional'), + ); + $conditional_rules_arguments = $common_arguments + array( + 'class_name' => 'WebformConditionalRules' . $source_version, + 'machine_name' => 'WebformConditionalRules', + 'description' => t('Migration of conditional from Drupal ' . $source_version), + 'dependencies' => array('WebformConditional'), + ); /** * Support for webform_validate module */ if (module_exists('webform_validation')) { $validation_rule_arguments = $common_arguments + array( - 'class_name' => 'WebformValidationRule', + 'class_name' => 'WebformValidationRule' . $source_version, 'machine_name' => 'WebformValidationRule', - 'description' => t('Migration of validation rules from Drupal 6'), - 'dependencies' => array('WebformLastDownload'), + 'description' => t('Migration of validation rules from Drupal ' . $source_version), + 'dependencies' => array('WebformConditionalRules'), ); $validation_rule_components_arguments = $common_arguments + array( - 'class_name' => 'WebformValidationRuleComponents', + 'class_name' => 'WebformValidationRuleComponents' . $source_version, 'machine_name' => 'WebformValidationRuleComponents', - 'description' => t('Migration of validation rules components from Drupal 6'), + 'description' => t('Migration of validation rules components from Drupal ' . $source_version), 'dependencies' => array('WebformValidationRule'), ); } @@ -131,7 +152,10 @@ function migrate_webform_migrate_api() { $api['migrations']['WebformSubmissions'] = $submissions_arguments; $api['migrations']['WebformSubmittedData'] = $submitted_data_arguments; $api['migrations']['WebformLastDownload'] = $last_download_arguments; - + $api['migrations']['WebformConditional'] = $conditional_arguments; + $api['migrations']['WebformConditionalActions'] = $conditional_actions_arguments; + $api['migrations']['WebformConditionalRules'] = $conditional_rules_arguments; + if (module_exists('webform_validation')) { $api['migrations']['WebformValidationRule'] = $validation_rule_arguments; $api['migrations']['WebformValidationRuleComponents'] = $validation_rule_components_arguments; diff --git a/migrate_webform.module b/migrate_webform.module index cb1d418..58fb2dd 100644 --- a/migrate_webform.module +++ b/migrate_webform.module @@ -34,6 +34,7 @@ function migrate_webform_admin_form($form, &$form_state) { '#title' => t('Source Database Drupal major version'), '#options' => array( 'd6' => t('Drupal 6'), + 'd7' => t('Drupal 7'), ), '#default_value' => variable_get('migrate_webform_source_database_api_version', 'd6'), ); diff --git a/node.inc b/node.inc deleted file mode 100644 index 5d4049d..0000000 --- a/node.inc +++ /dev/null @@ -1,60 +0,0 @@ -destination_type = $arguments['destination_type']; - if (isset($arguments['roles'])) { - $this->roles = $arguments['roles']; - } - $this->source_db = variable_get('migrate_webform_source_database', 'default'); - - // Keep old NIDs. - $this->addFieldMapping('nid', 'nid') - ->description('Let\'s reuse the old NIDs'); - $this->removeFieldMapping('is_new'); - $this->addFieldMapping('is_new')->defaultvalue(TRUE); - - // Get users if configured - // Default uid to 1 if we're not mapping it. - if (variable_get('migrate_webform_user_map_ok', FALSE)) { - $this->removeFieldMapping('uid'); - $this->addFieldMapping('uid', 'uid')->sourceMigration(variable_get('migrate_webform_user_migration_class', ""))->defaultValue(1); - } - else { - $this->removeFieldMapping('uid'); - $this->addFieldMapping('uid', 'uid')->defaultValue(1); - } - - } - - public function prepareRow($row) { - // skip? - if (parent::prepareRow($row) === FALSE) { - return FALSE; - } - - $result = db_query('select * from webform_roles where nid=:nid', array(':nid' => $row->nid), array('target' => $this->source_db)); - - // deal with role mappings - foreach ($result as $item) { - if (isset($this->roles[$item->rid]['new'])) { - $row->roles[] = $this->roles[$item->rid]['new']; - } - else { - $row->roles = array( 1 , 2 ); - } - } - if (sizeof($row->roles == 0)) { - $row->roles = array( 1 , 2 ); - } - } - - public function prepare($entity, $row) { - $entity->webform['roles'] = $row->roles; - } -} diff --git a/settings.inc b/settings.inc deleted file mode 100644 index 422c577..0000000 --- a/settings.inc +++ /dev/null @@ -1,99 +0,0 @@ -query($fields); - $table_name = 'webform'; - - $this->source = new MigrateSourceSQL($query, $fields, NULL, array('map_joinable' => FALSE, 'skip_count' => FALSE)); - - $this->destination = new MigrateDestinationTable($table_name); - - $this->map = new MigrateSQLMap($this->machineName, - array( - 'nid' => array('type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'description' => 'Source node ID', - 'alias' => 'n', - ), - ), - MigrateDestinationTable::getKeySchema($table_name) - ); - - $this->addSimpleMappings($simple_fields); - - $this->addFieldMapping('nid', 'nid'); - - $this->addFieldMapping('confirmation_format', 'confirmation_format') - ->callbacks(array($this, 'mapFormat')); - - if (db_field_exists($table_name, 'preview_message')) { - $this->addFieldMapping('preview_message')->defaultValue(''); - } - if (db_field_exists($table_name, 'preview_message_format')) { - $this->addFieldMapping('preview_message_format')->defaultValue($arguments['default_format']); - } - if (db_field_exists($table_name, 'preview_excluded_components')) { - $this->addFieldMapping('preview_excluded_components')->defaultValue(''); - } - } - - protected function query($fields) { - $connection = migrate_webform_get_source_connection(); - $query = $connection - ->select('webform', 'w') - ->fields('w', $fields) - ->orderBy('nid', 'ASC'); - return $query; - } - - // Copied from migrate_d2d. Extending DrupalMigrate wasn't so hot... - protected function mapFormat($format) { - if (!is_array($format)) { - $format = array($format); - } - $result = array(); - foreach ($format as $format_value) { - if (isset($format_value) && isset($this->formatMappings[$format_value])) { - $result[] = $this->formatMappings[$format_value]; - } - else { - $result[] = NULL; - } - } - // Only return an array if we have to - if (count($result) > 1) { - return $result; - } - else { - return reset($result); - } - } - - public function prepareRow($row) { - // skip? - if (parent::prepareRow($row) === FALSE) { - return FALSE; - } - - $row->nid = $this->handleSourceMigration($this->arguments['node_migrations'], $row->nid); - - // Node creation filled the table with a bunch of junk defaults. - db_delete('webform') - ->condition('nid', $row->nid) - ->execute(); - - } - - public function prepare($entity, $row) { - } - -} diff --git a/submissions.inc b/submissions.inc deleted file mode 100644 index ea556e8..0000000 --- a/submissions.inc +++ /dev/null @@ -1,69 +0,0 @@ -query($fields); - $table_name = 'webform_submissions'; - - $this->source = new MigrateSourceSQL($query, $fields, NULL, array('map_joinable' => FALSE, 'skip_count' => FALSE)); - - $this->destination = new MigrateDestinationTable($table_name); - - $this->map = new MigrateSQLMap($this->machineName, - array( - 'sid' => array('type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'description' => 'Source component ID', - 'alias' => 's', - ), - ), - MigrateDestinationTable::getKeySchema($table_name) - ); - - $this->addSimpleMappings($simple_fields); - - $this->addFieldMapping('nid', 'nid'); - - $this->addFieldMapping('serial', 'sid'); - - // Get users if configured - // Default uid to 1 if we're not mapping it. - if (variable_get('migrate_webform_user_map_ok', FALSE)) { - $this->removeFieldMapping('uid'); - $this->addFieldMapping('uid', 'uid')->sourceMigration(variable_get('migrate_webform_user_migration_class', ""))->defaultValue(0); - } - else { - $this->removeFieldMapping('uid'); - $this->addFieldMapping('uid', 'uid')->defaultValue(0); - } - } - - protected function query($fields) { - $connection = migrate_webform_get_source_connection(); - $query = $connection - ->select('webform_submissions', 'wss') - ->fields('wss', $fields) - ->orderBy('sid', 'ASC'); - return $query; - } - - public function prepareRow($row) { - // skip? - if (parent::prepareRow($row) === FALSE) { - return FALSE; - } - - $row->nid = $this->handleSourceMigration($this->arguments['node_migrations'], $row->nid); - } - - public function prepare($entity, $row) { - } -} - diff --git a/submitteddata.inc b/submitteddata.inc deleted file mode 100644 index 7e1c56d..0000000 --- a/submitteddata.inc +++ /dev/null @@ -1,105 +0,0 @@ -query($fields); - $table_name = 'webform_submitted_data'; - - $this->source = new MigrateSourceSQL($query, $fields, NULL, array('map_joinable' => FALSE, 'skip_count' => FALSE)); - - $this->destination = new MigrateDestinationTable($table_name); - - $this->map = new MigrateSQLMap($this->machineName, - array( - 'nid' => array('type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'description' => 'Source node ID', - 'alias' => 'n', - ), - 'sid' => array('type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'description' => 'Source submission ID', - 'alias' => 's', - ), - 'cid' => array('type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'description' => 'Source component ID', - 'alias' => 'c', - ), - 'no' => array('type' => 'varchar', - 'length' => 128, - 'not null' => TRUE, - 'description' => 'Source component instance ID?', - 'alias' => 'o', - ), - ), - MigrateDestinationTable::getKeySchema($table_name) - ); - - $this->addSimpleMappings($simple_fields); - - $this->addFieldMapping('nid', 'nid'); - - $this->addFieldMapping('sid', 'sid') - ->sourceMigration('WebformSubmissions'); - $this->addFieldMapping('cid', 'cid'); // @todo consult WebformComponents - // ... but first see https://drupal.org/node/2093073 - } - - protected function query($fields) { - $connection = migrate_webform_get_source_connection(); - $query = $connection - ->select('webform_submitted_data', 'wsd') - ->fields('wsd', $fields) - ->orderBy('sid', 'ASC'); - return $query; - } - - public function prepareRow($row) { - - // skip? - if (parent::prepareRow($row) === FALSE) { - return FALSE; - } - - $row->nid = $this->handleSourceMigration($this->arguments['node_migrations'], $row->nid); - - // find the type of the component we are transferring - // cannot expand the base query because cid is part of the uniqueness - $type = db_select('webform_component', 'wc') - ->fields('wc', array('type', 'name')) - ->condition('cid', $row->cid) - ->condition('nid', $row->nid) - ->execute() - ->fetchField(); - - // mangle the file ID to be the new version - if ($type == 'file' || $type == 'private_file') { - $filemigrations = explode(' ', variable_get('migrate_webform_file_migration_class', "")); - foreach ($filemigrations as $key => $filemigration) { - $destfile = db_select('migrate_map_' . strtolower($filemigration), 'map') - ->fields('map', array('destid1')) - ->condition('map.sourceid1', $row->data) - ->execute() - ->fetchField(); - if ($destfile != NULL) { - $row->data = $destfile; - file_usage_add(file_load($destfile), 'webform', 'submission', $row->sid); - } - } - } - } - - public function prepare($entity, $row) { - } -} - diff --git a/validationrule.inc b/validationrule.inc deleted file mode 100644 index 6b16f1b..0000000 --- a/validationrule.inc +++ /dev/null @@ -1,60 +0,0 @@ -query($fields); - $table_name = 'webform_validation_rule'; - - $this->source = new MigrateSourceSQL($query, $fields, NULL, array('map_joinable' => FALSE, 'skip_count' => FALSE)); - - $this->destination = new MigrateDestinationTable($table_name); - - $this->map = new MigrateSQLMap($this->machineName, - array( - 'ruleid' => array('type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'description' => 'Source node ID', - 'alias' => 'r', - ), - ), - MigrateDestinationTable::getKeySchema($table_name) - ); - - $this->addSimpleMappings($simple_fields); - - $this->addFieldMapping('nid', 'nid') - ->sourceMigration($arguments['node_migrations']); - } - - protected function query($fields) { - $connection = migrate_webform_get_source_connection(); - $query = $connection - ->select('webform_validation_rule', 'wvr') - ->fields('wvr', $fields) - ->orderBy('ruleid', 'ASC'); - return $query; - } - - public function prepareRow($row) { - - // skip? - if (parent::prepareRow($row) === FALSE) { - return FALSE; - } - - $row->nid = $this->handleSourceMigration($this->arguments['node_migrations'], $row->nid); - } - - public function prepare($entity, $row) { - } - -} - diff --git a/validationrulecomponents.inc b/validationrulecomponents.inc deleted file mode 100644 index 18bc3ed..0000000 --- a/validationrulecomponents.inc +++ /dev/null @@ -1,71 +0,0 @@ -query($fields); - $table_name = 'webform_validation_rule_components'; - - $this->source = new MigrateSourceSQL($query, $fields, NULL, array('map_joinable' => FALSE, 'skip_count' => FALSE)); - - $this->destination = new MigrateDestinationTable($table_name); - - $this->map = new MigrateSQLMap($this->machineName, - array( - 'ruleid' => array('type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'description' => 'Source rule ID', - 'alias' => 'r', - ), - 'cid' => array('type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'description' => 'Source component ID', - 'alias' => 'c', - ), - ), - MigrateDestinationTable::getKeySchema($table_name) - ); - - - $this->addSimpleMappings($simple_fields); - - // @todo WebformComponents sourceMigration doesn't work (keys hard to line up) - $this->addFieldMapping('cid', 'cid'); - } - - protected function query($fields) { - $connection = migrate_webform_get_source_connection(); - $query = $connection - ->select('webform_validation_rule_components', 'wvrc') - ->fields('wvrc', $fields) - ->orderBy('ruleid', 'ASC'); - return $query; - } - - public function prepareRow($row) { - - // skip? - if (parent::prepareRow($row) === FALSE) { - return FALSE; - } - - $row->nid = $this->handleSourceMigration($this->arguments['node_migrations'], $row->nid); - } - - public function prepare($entity, $row) { - } - -} - - - - -