/** * {@inheritdoc} */ public function prepareRow(Row $row) { $row->setSourceProperty('options', unserialize($row->getSourceProperty('options'))); $row->setSourceProperty('enabled', !$row->getSourceProperty('hidden')); $row->setSourceProperty('description', Unicode::truncate($row->getSourceProperty('options/attributes/title'), 255)); return parent::prepareRow($row); }
/** * {@inheritdoc} */ public function prepareRow(Row $row) { $roles = $this->select('users_roles', 'ur')->fields('ur', ['rid'])->condition('ur.uid', $row->getSourceProperty('uid'))->execute()->fetchCol(); $row->setSourceProperty('roles', $roles); $row->setSourceProperty('data', unserialize($row->getSourceProperty('data'))); // Get Field API field values. foreach (array_keys($this->getFields('user')) as $field) { $row->setSourceProperty($field, $this->getFieldValues('user', $field, $row->getSourceProperty('uid'))); } // Get profile field values. This code is lifted directly from the D6 // ProfileFieldValues plugin. if ($this->getDatabase()->schema()->tableExists('profile_value')) { $query = $this->select('profile_value', 'pv')->fields('pv', array('fid', 'value')); $query->leftJoin('profile_field', 'pf', 'pf.fid=pv.fid'); $query->fields('pf', array('name', 'type')); $query->condition('uid', $row->getSourceProperty('uid')); $results = $query->execute(); foreach ($results as $profile_value) { if ($profile_value['type'] == 'date') { $date = unserialize($profile_value['value']); $date = date('Y-m-d', mktime(0, 0, 0, $date['month'], $date['day'], $date['year'])); $row->setSourceProperty($profile_value['name'], array('value' => $date)); } elseif ($profile_value['type'] == 'list') { // Explode by newline and comma. $row->setSourceProperty($profile_value['name'], preg_split("/[\r\n,]+/", $profile_value['value'])); } else { $row->setSourceProperty($profile_value['name'], array($profile_value['value'])); } } } return parent::prepareRow($row); }
/** * {@inheritdoc} */ public function prepareRow(Row $row) { $row->setSourceProperty('teaser_length', $this->teaserLength); $row->setSourceProperty('node_preview', $this->nodePreview); $type = $row->getSourceProperty('type'); $source_options = $this->variableGet('node_options_' . $type, array('promote', 'sticky')); $options = array(); foreach (array('promote', 'sticky', 'status', 'revision') as $item) { $options[$item] = in_array($item, $source_options); } $row->setSourceProperty('options', $options); // Don't create a body field until we prove that this node type has one. $row->setSourceProperty('create_body', FALSE); if ($this->moduleExists('field')) { // Find body field for this node type. $body = $this->select('field_config_instance', 'fci')->fields('fci', array('data'))->condition('entity_type', 'node')->condition('bundle', $row->getSourceProperty('type'))->condition('field_name', 'body')->execute()->fetchAssoc(); if ($body) { $row->setSourceProperty('create_body', TRUE); $body['data'] = unserialize($body['data']); $row->setSourceProperty('body_label', $body['data']['label']); } } $row->setSourceProperty('display_submitted', $this->variableGet('node_submitted_' . $type, TRUE)); return parent::prepareRow($row); }
/** * {@inheritdoc} */ public function prepareRow(Row $row) { $filters = array(); $roles = $row->getSourceProperty('roles'); $row->setSourceProperty('roles', array_values(array_filter(explode(',', $roles)))); $format = $row->getSourceProperty('format'); // Find filters for this row. $results = $this->select('filters', 'f')->fields('f', array('module', 'delta', 'weight'))->condition('format', $format)->execute(); foreach ($results as $raw_filter) { $module = $raw_filter['module']; $delta = $raw_filter['delta']; $filter = array('module' => $module, 'delta' => $delta, 'weight' => $raw_filter['weight'], 'settings' => array()); // Load the filter settings for the filter module, modules can use // hook_migration_d6_filter_formats_prepare_row() to add theirs. if ($raw_filter['module'] == 'filter') { if (!$delta) { if ($setting = $this->variableGet("allowed_html_{$format}", NULL)) { $filter['settings']['allowed_html'] = $setting; } if ($setting = $this->variableGet("filter_html_help_{$format}", NULL)) { $filter['settings']['filter_html_help'] = $setting; } if ($setting = $this->variableGet("filter_html_nofollow_{$format}", NULL)) { $filter['settings']['filter_html_nofollow'] = $setting; } } elseif ($delta == 2 && ($setting = $this->variableGet("filter_url_length_{$format}", NULL))) { $filter['settings']['filter_url_length'] = $setting; } } $filters[] = $filter; } $row->setSourceProperty('filters', $filters); return parent::prepareRow($row); }
/** * {@inheritdoc} */ public function getFieldType(Row $row) { $widget_type = $row->getSourceProperty('widget_type'); if ($widget_type == 'text_textfield') { $settings = $row->getSourceProperty('global_settings'); $field_type = $settings['text_processing'] ? 'text' : 'string'; if (empty($settings['max_length']) || $settings['max_length'] > 255) { $field_type .= '_long'; } return $field_type; } else { switch ($widget_type) { case 'optionwidgets_buttons': case 'optionwidgets_select': return 'list_string'; case 'optionwidgets_onoff': return 'boolean'; case 'text_textarea': return 'text_long'; default: return parent::getFieldType($row); break; } } }
/** * {@inheritdoc} */ public function prepareRow(Row $row) { // User roles. $roles = $this->select('users_roles', 'ur') ->fields('ur', array('rid')) ->condition('ur.uid', $row->getSourceProperty('uid')) ->execute() ->fetchCol(); $row->setSourceProperty('roles', $roles); // We are adding here the Event contributed module column. // @see https://api.drupal.org/api/drupal/modules%21user%21user.install/function/user_update_7002/7 if ($row->hasSourceProperty('timezone_id') && $row->getSourceProperty('timezone_id')) { if ($this->getDatabase()->schema()->tableExists('event_timezones')) { $event_timezone = $this->select('event_timezones', 'e') ->fields('e', array('name')) ->condition('e.timezone', $row->getSourceProperty('timezone_id')) ->execute() ->fetchField(); if ($event_timezone) { $row->setSourceProperty('event_timezone', $event_timezone); } } } // Unserialize Data. $row->setSourceProperty('data', unserialize($row->getSourceProperty('data'))); return parent::prepareRow($row); }
/** * {@inheritdoc} */ public function prepareRow(Row $row) { // Find node types for this row. $node_types = $this->select('vocabulary_node_types', 'nt')->fields('nt', array('type', 'vid'))->condition('vid', $row->getSourceProperty('vid'))->execute()->fetchCol(); $row->setSourceProperty('node_types', $node_types); $row->setSourceProperty('cardinality', $row->getSourceProperty('tags') == 1 || $row->getSourceProperty('multiple') == 1 ? FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED : 1); return parent::prepareRow($row); }
/** * {@inheritdoc} */ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { $value = $row->getSourceProperty('settings'); if ($row->getSourceProperty('type') == 'image' && !is_array($value['default_image'])) { $value['default_image'] = array('uuid' => ''); } return $value; }
/** * {@inheritdoc} */ public function prepareRow(Row $row) { // Get Field API field values. foreach (array_keys($this->getFields('node', $row->getSourceProperty('type'))) as $field) { $nid = $row->getSourceProperty('nid'); $vid = $row->getSourceProperty('vid'); $row->setSourceProperty($field, $this->getFieldValues('node', $field, $nid, $vid)); } return parent::prepareRow($row); }
/** * {@inheritdoc} */ public function prepareRow(Row $row, $keep = TRUE) { // Unserialize data. $global_settings = unserialize($row->getSourceProperty('global_settings')); $widget_settings = unserialize($row->getSourceProperty('widget_settings')); $db_columns = unserialize($row->getSourceProperty('db_columns')); $row->setSourceProperty('global_settings', $global_settings); $row->setSourceProperty('widget_settings', $widget_settings); $row->setSourceProperty('db_columns', $db_columns); return parent::prepareRow($row); }
/** * {@inheritdoc} */ public function prepareRow(Row $row) { $cid = $row->getSourceProperty('cid'); $node_type = $row->getSourceProperty('node_type'); $comment_type = 'comment_node_' . $node_type; $row->setSourceProperty('comment_type', 'comment_node_' . $node_type); foreach (array_keys($this->getFields('comment', $comment_type)) as $field) { $row->setSourceProperty($field, $this->getFieldValues('comment', $field, $cid)); } return parent::prepareRow($row); }
/** * {@inheritdoc} */ public function prepareRow(Row $row) { // Unserialize data. $widget_settings = unserialize($row->getSourceProperty('widget_settings')); $display_settings = unserialize($row->getSourceProperty('display_settings')); $global_settings = unserialize($row->getSourceProperty('global_settings')); $row->setSourceProperty('widget_settings', $widget_settings); $row->setSourceProperty('display_settings', $display_settings); $row->setSourceProperty('global_settings', $global_settings); return parent::prepareRow($row); }
/** * {@inheritdoc} */ public function prepareRow(Row $row) { $aid = $row->getSourceProperty('aid'); if (is_numeric($aid)) { if ($this->getModuleSchemaVersion('system') >= 7000) { $label = $row->getSourceProperty('label'); } else { $label = $row->getSourceProperty('description'); } $row->setSourceProperty('aid', $label); } }
/** * {@inheritdoc} * * Migrate filter format serial to string id in permission name. */ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { $rid = $row->getSourceProperty('rid'); if ($formats = $row->getSourceProperty("filter_permissions:{$rid}")) { foreach ($formats as $format) { $new_id = $this->migrationPlugin->transform($format, $migrate_executable, $row, $destination_property); if ($new_id) { $value[] = 'use text format ' . $new_id; } } } return $value; }
/** * {@inheritdoc} */ public function prepareRow(Row $row) { /** * Let's go get the subTeam taxonomy tid for each product */ $start = $row->getSourceProperty('salestart'); if (!is_null($start)) { // drupal_set_message('start:' . $start) ; $timestamp = strtotime($start); $start = date("Y-m-d\\TH:i:s", $timestamp); // drupal_set_message('reformatted start: ' . $start); $row->setSourceProperty('salestart', $start); } $end = $row->getSourceProperty('saleend'); if (!is_null($end)) { // drupal_set_message('end:' . $end); $timestamp = strtotime($start); $end = date("Y-m-d\\TH:i:s", $timestamp); // drupal_set_message('reformatted end: ' . $end); $row->setSourceProperty('saleend', $end); } // Fill in the field_product_ref entity ref to the product node. $id = $row->getSourceProperty('identifier'); $product_ref_id = $this->lookupProductNid($id); $row->setSourceProperty('product_ref_id', $product_ref_id); $tlc = $row->getSourceProperty('tlc'); $store_ref_id = $this->lookupStoreNid($tlc); $row->setSourceProperty('store_ref_id', $store_ref_id); $ssid = $row->getSourceProperty('ssid'); drupal_set_message('Processing: ' . $ssid); /** * As explained above, we need to pull the style relationships into our * source row here, as an array of 'style' values (the unique ID for * the beer_term migration). */ // $terms = $this->select('migrate_example_beer_topic_node', 'bt') // ->fields('bt', ['style']) // ->condition('bid', $row->getSourceProperty('bid')) // ->execute() // ->fetchCol(); // $row->setSourceProperty('terms', $terms); // As we did for favorite beers in the user migration, we need to explode // the multi-value country names. // if ($value = $row->getSourceProperty('countries')) { // $row->setSourceProperty('countries', explode('|', $value)); // } return parent::prepareRow($row); // } }
/** * {@inheritdoc} */ public function transform($value, MigrateExecutable $migrate_executable, Row $row, $destination_property) { // If it's an array then the map missed. if (is_array($value)) { // Filefields in D6 have no way to tell if it's an image or file so we // have to look at the widget type as well. if ($row->getSourceProperty('module') == 'filefield') { $widget_type = $row->getSourceProperty('widget_type'); $value = $widget_type == "imagefield_widget" ? "image" : "file"; } else { throw new MigrateSkipRowException(); } } return $value; }
/** * {@inheritdoc} */ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { $timezone = NULL; if ($row->hasSourceProperty('timezone_name')) { if (isset(static::$timezones[$row->getSourceProperty('timezone_name')])) { $timezone = $row->getSourceProperty('timezone_name'); } } if (!$timezone && $row->hasSourceProperty('event_timezone')) { if (isset(static::$timezones[$row->getSourceProperty('event_timezone')])) { $timezone = $row->getSourceProperty('event_timezone'); } } return $timezone; }
/** * {@inheritdoc} */ public function prepareRow(Row $row) { if ($this->variableGet('comment_subject_field_' . $row->getSourceProperty('type'), 1)) { // Comment subject visible. $row->setSourceProperty('field_name', 'comment'); $row->setSourceProperty('comment_type', 'comment'); } else { $row->setSourceProperty('field_name', 'comment_no_subject'); $row->setSourceProperty('comment_type', 'comment_no_subject'); } // In D6, status=0 means published, while in D8 means the opposite. // See https://www.drupal.org/node/237636. $row->setSourceProperty('status', !$row->getSourceProperty('status')); return parent::prepareRow($row); }
protected function transformEntityViewDisplaySettings(Row $row) { $row->setSourceProperty('extracted_settings', $row->getSourceProperty('settings/display')); $view_modes = array_diff(array_keys($row->getSourceProperty('extracted_settings')), ['label', 'description', 'weight']); $view_modes = array_filter($view_modes, function ($value) { return !is_numeric($value); }); $row->setSourceProperty('view_mode_keys', $view_modes); $view_modes = []; foreach ($row->getSourceProperty('view_mode_keys') as $view_mode) { $source_settings = $row->getSourceProperty('extracted_settings/' . $view_mode); $row->setSourceProperty('view_modes', []); $settings = ['format_type' => 'details', 'format_settings' => []]; switch ($source_settings['format']) { case 'no_style': $settings['format_type'] = 'no_style'; break; case 'simple': $settings['format_type'] = 'html_element'; $settings['format_settings']['element'] = 'div'; $settings['format_settings']['label_element'] = 'h2'; break; case 'fieldset': $settings['format_type'] = 'fieldset'; break; case 'fieldset_collapsible': $settings['format_type'] = 'details'; $settings['format_settings']['open'] = TRUE; break; case 'fieldset_collapsed': $settings['format_type'] = 'details'; $settings['format_settings']['open'] = FALSE; break; case 'hidden': $settings['format_type'] = 'hidden'; break; } /** * @todo: ? */ if ($view_mode == 'full') { $view_mode = 'default'; } // $row->setSourceProperty('view_modes/' . $view_mode, $settings); $view_modes[$view_mode] = $settings; } $row->setSourceProperty('view_modes', $view_modes); }
/** * {@inheritdoc} */ public function prepareRow(Row $row) { /** * prepareRow() is the most common place to perform custom run-time * processing that isn't handled by an existing process plugin. It is called * when the raw data has been pulled from the source, and provides the * opportunity to modify or add to that data, creating the canonical set of * source data that will be fed into the processing pipeline. * * In our particular case, the list of a user's favorite ssds is a pipe- * separated list of ssd IDs. The processing pipeline deals with arrays * representing multi-value fields naturally, so we want to explode that * string to an array of individual ssd IDs. */ if ($value = $row->getSourceProperty('ssds')) { $row->setSourceProperty('ssds', explode('|', $value)); } /** * Always call your parent! Essential processing is performed in the base * class. Be mindful that prepareRow() returns a boolean status - if FALSE * that indicates that the item being processed should be skipped. Unless * we're deciding to skip an item ourselves, let the parent class decide. */ return parent::prepareRow($row); }
/** * {@inheritdoc} */ public function prepareRow(Row $row) { $row->setSourceProperty('filename', basename($row->getSourceProperty('picture'))); $row->setSourceProperty('file_directory_path', $this->filePath); $row->setSourceProperty('temp_directory_path', $this->tempFilePath); return parent::prepareRow($row); }
/** * {@inheritdoc} */ public function prepareRow(Row $row) { if ($value = $row->getSourceProperty('value')) { $row->setSourceProperty('value', unserialize($value)); } return parent::prepareRow($row); }
/** * {@inheritdoc} */ public function prepareRow(Row $row) { // Find node types for this row. $node_types = $this->select('vocabulary_node_types', 'nt')->fields('nt', array('type', 'vid'))->condition('vid', $row->getSourceProperty('vid'))->execute()->fetchCol(); $row->setSourceProperty('node_types', $node_types); return parent::prepareRow($row); }
/** * {@inheritdoc} */ public function prepareRow(Row $row, $keep = TRUE) { foreach (unserialize($row->getSourceProperty('data')) as $key => $value) { $row->setSourceProperty($key, $value); } return parent::prepareRow($row); }
/** * {@inheritdoc} */ protected function getEntity(Row $row, array $old_destination_id_values) { if ($row->isStub()) { $row->setDestinationProperty('name', $this->t('Stub name for source tid:') . $row->getSourceProperty('tid')); } return parent::getEntity($row, $old_destination_id_values); }
/** * {@inheritdoc} */ public function prepareRow(Row $row) { $vocab = $row->getSourceProperty('taxonomy'); $label = $vocab == 'category' ? 'Category' : 'Post Tags'; $row->setSourceProperty('label', $label); return parent::prepareRow($row); }
/** * {@inheritdoc} */ public function import(Row $row, array $old_destination_id_values = array()) { $file = $row->getSourceProperty($this->configuration['source_path_property']); $destination = $row->getDestinationProperty($this->configuration['destination_path_property']); $source = $this->configuration['source_base_path'] . $file; // Ensure the source file exists, if it's a local URI or path. if ($this->isLocalUri($source) && !file_exists($source)) { throw new MigrateException(SafeMarkup::format('File @source does not exist.', ['@source' => $source])); } // If the start and end file is exactly the same, there is nothing to do. if ($this->isLocationUnchanged($source, $destination)) { return parent::import($row, $old_destination_id_values); } $replace = $this->getOverwriteMode($row); $success = $this->writeFile($source, $destination, $replace); if (!$success) { $dir = $this->getDirectory($destination); if (file_prepare_directory($dir, FILE_CREATE_DIRECTORY)) { $success = $this->writeFile($source, $destination, $replace); } else { throw new MigrateException(SafeMarkup::format('Could not create directory @dir', ['@dir' => $dir])); } } if ($success) { return parent::import($row, $old_destination_id_values); } else { throw new MigrateException(SafeMarkup::format('File %source could not be copied to %destination.', ['%source' => $source, '%destination' => $destination])); } }
/** * {@inheritdoc} */ public function prepareRow(Row $row) { $nid = $row->getSourceProperty('nid'); // taxonomy term IDs // (here we use MySQL's GROUP_CONCAT() function to merge all values into one row.) $result = $this->getDatabase()->query(' SELECT GROUP_CONCAT(fld.field_links_tags_tid) as tids FROM {dcf_field_data_field_links_tags} fld WHERE fld.entity_id = :nid ', array(':nid' => $nid)); foreach ($result as $record) { if (!is_null($record->tids)) { $row->setSourceProperty('tags', explode(',', $record->tids)); } } // field_url $result = $this->getDatabase()->query(' SELECT fld.field_url_url as url, fld.field_url_title as title FROM {dcf_field_data_field_url} fld WHERE fld.entity_id = :nid ', array(':nid' => $nid)); foreach ($result as $record) { $row->setSourceProperty('field_url_url', $record->url); $row->setSourceProperty('field_url_title', $record->title); } return parent::prepareRow($row); }
/** * {@inheritdoc} */ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { $source = $this->configuration['source']; $properties = is_string($source) ? array($source) : $source; $return = array(); foreach ($properties as $property) { if ($property || (string) $property === '0') { $is_source = TRUE; if ($property[0] == '@') { $property = preg_replace_callback('/^(@?)((?:@@)*)([^@]|$)/', function ($matches) use(&$is_source) { // If there are an odd number of @ in the beginning, it's a // destination. $is_source = empty($matches[1]); // Remove the possible escaping and do not lose the terminating // non-@ either. return str_replace('@@', '@', $matches[2]) . $matches[3]; }, $property); } if ($is_source) { $return[] = $row->getSourceProperty($property); } else { $return[] = $row->getDestinationProperty($property); } } else { $return[] = $value; } } if (is_string($source)) { $this->multiple = is_array($return[0]); return $return[0]; } return $return; }
/** * {@inheritdoc} */ public function prepareRow(Row $row) { // Find parents for this row. $parents = $this->select('term_hierarchy', 'th')->fields('th', array('parent', 'tid'))->condition('tid', $row->getSourceProperty('tid'))->execute()->fetchCol(); $row->setSourceProperty('parent', $parents); return parent::prepareRow($row); }