/** * Performs the full import of all regular (non-Matrix) Playa channel fields * into native Relationships fields * * @return array Array of new Playa field IDs */ public function do_import() { ee()->load->library('pm_import_common'); $playas = $this->get_playa_fields(); $playa_relationships = ee()->pm_import_common->get_playa_relationships(); ee()->load->library('api'); ee()->api->instantiate('channel_fields'); ee()->load->model('addons_model'); $new_field_ids = array(); $original_site_id = ee()->config->item('site_id'); foreach ($playas as $playa) { // Let's be explicit about what's making up this new field $new_relationship_field = array('site_id' => $playa['site_id'], 'group_id' => $playa['group_id'], 'field_label' => $playa['field_label'], 'field_name' => ee()->pm_import_common->get_unique_field_name($playa['field_name'], '_relate', $playa['site_id']), 'field_type' => 'relationship', 'field_instructions' => $playa['field_instructions'], 'field_required' => $playa['field_required'], 'field_search' => $playa['field_search'], 'field_order' => 0); // Hack to prevent site ID mismatch error in API channel fields ee()->config->config['site_id'] = $new_relationship_field['site_id']; $field_id = ee()->api_channel_fields->update_field($new_relationship_field); ee()->config->config['site_id'] = $original_site_id; $new_field_settings = PlayaConverter::convertSettings(unserialize(base64_decode($playa['field_settings']))); $new_relationships = array(); if (isset($playa_relationships[$playa['field_id']])) { $new_relationships = PlayaConverter::convertPlayaRelationships($playa_relationships[$playa['field_id']], $field_id); } // Set new field settings from translated Playa settings ee()->db->set('field_settings', base64_encode(serialize($new_field_settings)))->where('field_id', $field_id)->update('channel_fields'); if (!empty($new_relationships)) { if (ee()->addons_model->module_installed('publisher') && ee()->db->table_exists('publisher_relationships')) { ee()->db->insert_batch('publisher_relationships', $new_relationships); $new_relationships = PlayaConverter::filterPublisherRelationships($new_relationships, ee()->config->item('publisher_default_language_id') ?: 1); } // Finally, import Playa relationships ee()->db->insert_batch('relationships', $new_relationships); } $new_field_ids[] = $field_id; } return $new_field_ids; }
/** * Given decoded Matrix column settings, converts those settings to be * compatible to the specified native EE fieldtype * * @param string Target fieldtype's name, e.g. 'text', 'relationship' * @param settings Decoded settings for the Matrix column * @return string EE-equivalent fieldtype settings for specified fieldtype */ public static function mapColumnSettings($to_cell_type, $settings) { switch ($to_cell_type) { case 'date': // Matrix has no date field settings, we only have one return array('localize' => TRUE); break; case 'checkboxes': case 'radio': case 'select': case 'multi_select': return OptionsCellConverter::convertSettings($settings); break; case 'relationship': return PlayaConverter::convertSettings($settings); break; case 'file': return FileCellConverter::convertSettings($settings); break; case 'textarea': return TextareaCellConverter::convertSettings($settings); break; case 'rte': // Existing settings should be good except we have one thing to add return array_merge(array('field_text_direction' => 'ltr'), $settings); break; case 'text': return TextCellConverter::convertSettings($settings); default: return $settings; break; } return array(); }
/** * Test PlayaConverter::convertSettings() method * * @dataProvider settingsDataProvider */ public function testSettingsConversion($expected, $settings, $description) { $new_settings = PlayaConverter::convertSettings($settings); $this->assertEquals($expected, $new_settings, $description); }