/** * @AfterScenario @datastore * * @param AfterScenarioScope $scope */ public function dropDatastores($scope) { $result = db_query("SELECT n.nid FROM {node} n WHERE n.type = :type", array(":type" => "resource")); foreach ($result as $n) { if (!empty($n->nid)) { $node = node_load($n->nid); $importer_ids = feeds_get_importer_ids($node->type); foreach ($importer_ids as $importer_id) { $source = feeds_source($importer_id, $node->nid); $table_name = feeds_flatstore_processor_table_name($source->id, $source->feed_nid); $has_file = dkan_datastore_file_field($node); $wrapper = entity_metadata_wrapper('node', $node); $status = $has_file ? DKAN_DATASTORE_FILE_EXISTS : DKAN_DATASTORE_EMPTY; $wrapper->field_datastore_status->set($status); $wrapper->save(); $this->dropTable($table_name); } } } }
*/ foreach ($pdf_file_array as $key => $row) { $csv_array_key = smv_sitecron_recursive_array_search($row[0], $csv_file_array); $pdf_file = $row[1]; //check sync_status $sync_status = $csv_file_array[$csv_array_key][10]; if ($sync_status == 1) { $pdf = smv_sitecron_move_to_active_folder($importer_id, $pdf_file, $vendor_no); $csv_file_array[$csv_array_key][9] = $pdf; } else { $exception_file = smv_sitecron_move_to_exception_folder($importer_id, $pdf_file); $csv_file_array[$csv_array_key][9] = $exception_file; } } //output to csv only if file details and file header is not empty if ($csv_file_array && $file_header) { $output_csv = smv_sitecron_output_csv($csv_file_array, $file_header, $destination, '/smprime_nonpo.csv'); } } /** * Feed import process * Non PO feeds */ $nonpo_feeds_file = smv_sitecron_folder_files_count($destination); if ($nonpo_feeds_file > 2) { if (file_exists($destination . '/smprime_nonpo.csv')) { smv_sitecron_source_config_path($importer_id); $source = feeds_source($importer_id); $source->startImport(); } }
<?php // Run buildings feed importer. while (FEEDS_BATCH_COMPLETE != feeds_source('feedname', 0)->import()) { }
/** * @Given /^I re import feed item "([^"]*)"$/ */ public function iReImportFeedItem($node) { $nid = FeatureHelp::GetNodeId($node); $source = feeds_source('os_reader', $nid); try { $source->import(); } catch (\Exception $e) { } }
<?php // Set feed importer URL. $source = feeds_source('feedname'); $source->addConfig(array('FeedsHTTPFetcher' => array('source' => 'http://example.com/feedurl'))); $source->save();
/** * Migrates the given type to a Feeds importer * * @param $type * Content-type machine name */ public function migrateType($type) { // First attempt to retrieve an existing importer for this content type. // If it can be retrieved, assume that it is configured correctly. $importers = feeds_importer_load_all(); foreach ($importers as $potential_importer) { if (!empty($potential_importer->config['content_type']) && $potential_importer->config['content_type'] === $type) { $importer = $potential_importer; if ($class = get_class($importer->processor)) { $processor = array_search($class, $this->dictionary); } break; } } // Otherwise, create a new importer from the legacy FeedAPI configuration. if (!isset($importer)) { if (!function_exists('feedapi_get_settings')) { module_load_include('inc', 'feedapi2feeds', 'feedapi2feeds.legacy'); } $settings = feedapi_get_settings($type); // 1) Create new importer and configure it // Generate a name for importer $importer_name = $type; $collision = TRUE; $i = 0; do { $importer = feeds_importer($importer_name); if (!ctools_export_load_object('feeds_importer', 'conditions', array('id' => $importer_name))) { $collision = FALSE; } else { $importer_name = $type . '_' . $i++; } } while ($collision); // Enable given parsers, processors w/ configuration, Feeds do not support multi parser, processor if (!empty($settings)) { $parser = $this->getActive($settings, 'parsers'); $processor = $this->getActive($settings, 'processors'); } if (empty($parser) || empty($processor)) { throw new Exception($type . ' content-type cannot migrated because there is no enabled parser or processor for it.'); break; } if (!isset($this->dictionary[$parser])) { throw new Exception($parser . ' parser is not supported by this migration script, skipping ' . $type); break; } if (!isset($this->dictionary[$processor])) { throw new Exception($parser . ' processor is not supported by this migration script, skipping ' . $type); break; } // Create the new importer $this->createImporter($importer_name, $type); $importer = feeds_importer_load($importer_name); $importer->setPlugin($this->dictionary[$parser]); $importer->setPlugin($this->dictionary[$processor]); if ($settings['upload_method'] == 'upload') { $importer->setPlugin('FeedsFileFetcher'); } // Apply per-submodule settings foreach (array($parser, $processor) as $module) { $config_func = 'feedapi2feeds_configure_' . $module; if (method_exists($this, $config_func)) { $ret = $this->{$config_func}($settings, $importer); if (is_array($ret) && !empty($ret)) { $this->default_mapping = $ret; } } else { $this->messages[] = t('The settings at @type for @submodule were not migrated.', array('@type' => $type, '@submodule' => $module)); } } // Supporting FeedAPI Mapper 1.x style mappings, only per-content-type $custom_mapping = variable_get('feedapi_mapper_mapping_' . $type, array()); if (!empty($custom_mapping) && is_array($custom_mapping)) { $sources = $importer->parser->getMappingSources(); $targets = $importer->processor->getMappingTargets(); foreach ($custom_mapping as $source => $target) { $matched_source = $this->match($source, $sources); $matched_target = $this->match($target, $targets); if (!empty($matched_source) && !empty($matched_target)) { $importer->processor->addMapping($matched_source, $matched_target, FALSE); } else { $this->messages[] = t('Failed to migrate this mapping (@type): @source - @target', array('@type' => $type, '@source' => $source, '@target' => $target)); } } } // See what's abandoned $count = db_result(db_query("SELECT COUNT(*) FROM {feedapi_mapper} m LEFT JOIN {node} n on m.nid = n.nid WHERE n.type = '%s'", $type)); if ($count > 0) { $this->messages[] = t('@num feed nodes were detected with custom mapping (@type), these mappings were skipped, you need to manually migrate them!', array('@type' => $type, '@num' => $count)); } // We have default mapping for these processors if ($processor == 'feedapi_node' || $processor == 'feedapi_fast') { foreach ($this->default_mapping as $mapping) { $importer->processor->addMapping($mapping['source'], $mapping['target'], $mapping['unique']); } } // Attach importer to content-type, disable FeedAPI for that content-type $importer->addConfig(array('content_type' => $type)); $importer->save(); // Detach FeedAPI from that content-type variable_del('feedapi_settings_' . $type); variable_set('_backup_feedapi_settings_' . $type, $settings); } // 2) Migrate feeds // Join on vid because of the revision support if (db_table_exists('feedapi')) { $result = db_query("SELECT f.url, f.nid FROM {feedapi} f LEFT JOIN {node} n on f.vid = n.vid WHERE n.type='%s'", $type); while ($feed = db_fetch_array($result)) { if (empty($feed['url'])) { break; } $source = feeds_source($importer->id, $feed['nid']); $config = $source->getConfig(); $config['source'] = $config[get_class($importer->fetcher)]['source'] = $feed['url']; $source->setConfig($config); $source->save(); } } // 3) Migrate items $item_func = 'feedapi2feeds_item_' . $processor; if (method_exists($this, $item_func)) { $this->{$item_func}($type, $importer); } }
/** * Importing nodes from a demo CSV. * * @pram $import * The file name(without .csv) */ public static function ImportCsv($type) { global $base_url; $importers = array('blog' => 'os_blog_csv', 'news' => 'os_news', 'event' => 'os_ical', 'page' => 'os_pages', 'class' => 'os_classes', 'faq' => 'os_faq', 'presentation' => 'os_presentation', 'software_project' => 'os_software', 'person' => 'os_people', 'link' => 'os_links', 'media_gallery' => 'os_gallery'); // Specify a specific encoding of importers files. This meant for testing the // import of files in various encodings. $encodes = array('blog' => 'WINDOWS-1255', 'news' => 'WINDOWS-1254'); $ending = $type == 'event' ? 'ics' : 'csv'; $url = $base_url . '/' . drupal_get_path('module', 'os_migrate_demo') . '/includes/import_csv/' . $type . '.' . $ending; // todo: Use system_retrieve_file(). $file = system_retrieve_file($url, 'public://', TRUE); $source = feeds_source($importers[$type]); $fetcher_config = $source->getConfigFor($source->importer->fetcher); $fetcher_config['source'] = $file->uri; $fetcher_config['file'] = $file; // Add encoding for specific files. if (isset($encodes[$type])) { $fetcher_config['encode'] = $encodes[$type]; } $source->setConfigFor($source->importer->fetcher, $fetcher_config); $source->save(); feeds_source($importers[$type], 0)->import(); }