Feeds drupal cafe

3,651 views

Published on

Feeds Drupal developer keynote

Published in: Technology
2 Comments
1 Like
Statistics
Notes
No Downloads
Views
Total views
3,651
On SlideShare
0
From Embeds
0
Number of Embeds
1,298
Actions
Shares
0
Downloads
12
Comments
2
Likes
1
Embeds 0
No embeds

No notes for slide

Feeds drupal cafe

  1. 1. Drupal Feeds Andriy Podanenko aka @podarok http://drupal.org/user/116002 Kyiv Drupal Cafe` feeds developer keynotes 08.09.2011 Kyiv Drupal Cafe`
  2. 2. POI FeedsSource extends FeedsConfigurable FeedsSource::import Plugins (FeedsFetcher, FeedsParser, FeedsProcessor) Hooks Mappings hook_feeds_processor_targets_alter() hook_feeds_parser_sources_alter() 08.09.2011 Kyiv Drupal Cafe`
  3. 3. Manual processstartImport() $config = $this->importer->getConfig(); if ($config[process_in_background]) { $this->startBackgroundJob(import); } else { $this->startBatchAPIJob(t(Importing), import); //method }} function startBatchAPIJob(){ $batch = array( title => $title, operations => array( array(feeds_batch, array($method, $this->id, $this->feed_nid)), ), ); batch_set($batch); } 08.09.2011 Kyiv Drupal Cafe`
  4. 4. Manual process feeds_batch() function feeds_batch($method, $importer_id, $feed_nid = 0, &$context) { $context[finished] = FEEDS_BATCH_COMPLETE; try { // main work doing here $context[finished] = feeds_source($importer_id, $feed_nid)->$method(); } catch (Exception $e) { drupal_set_message($e->getMessage(), error); }} 08.09.2011 Kyiv Drupal Cafe`
  5. 5. FeedsSource::import$this->acquireLock(); try { // Fetch. if (empty($this->fetcher_result) || FEEDS_BATCH_COMPLETE == $this->progressParsing()) { $this->fetcher_result = $this->importer->fetcher->fetch($this);//…. } // Parse. $parser_result = $this->importer->parser->parse($this, $this->fetcher_result); module_invoke_all(feeds_after_parse, $this, $parser_result); // Process. $this->importer->processor->process($this, $parser_result); } catch (Exception $e) {// …. } $this->releaseLock(); 08.09.2011 Kyiv Drupal Cafe`
  6. 6. Feeds hooksfunction feeds_hook_info() { $hooks = array( feeds_after_parse, feeds_after_import, feeds_after_clear, feeds_processor_targets_alter, feeds_parser_sources_alter, ); 08.09.2011 Kyiv Drupal Cafe`
  7. 7. Feeds plugins hook_feeds_plugins() function ofeeds_feeds_plugins() { $info = array(); $info[OpenERP_Fetcher] = array( name => OpenERP Fetcher, description => Fetches OpenERP objects from Models., help => Fetches OpenERP objects from Models. Additional help will bein a feature, handler => array( parent => FeedsFetcher, class => OpenERP_Fetcher, file => OpenERP_Fetcher.inc, path => drupal_get_path(module, ofeeds) . /fetchers,// Feeds will look for OpenERP_Fetcher.inc in the ofeeds/fetchers directory. ), ); return $info;} 08.09.2011 Kyiv Drupal Cafe`
  8. 8. Feeds plugins●class FeedsPlugin extends FeedsConfigurable implementsFeedsSourceInterface methods: save, sourceForm, configForm, loadMappers...FeedsFetcher extends FeedsPlugin●methods: clear, fetch...FeedsParser extends FeedsPlugin●methods: parse, clear...●FeedsProcessor extends FeedsPlugin methods: process, entityType, newEntity, entityLoad,entitySave, entityDeleteMultiple 08.09.2011 Kyiv Drupal Cafe`
  9. 9. Feeds plugins forms● configForm // forms displayed at feeds instance settings tab (admin level) FE: OpenERP_Fetcher::configForm($fs) – select model,setting for limiting count of fetched data etc. Exportable as config array !!! (via import export clone)// configFormSubmit,configFormValidate● sourceForm // forms displayed at /import/$feeds_instance page and atcontent type creation forms (user level) FE: FeedsFileFetcher::sourceForm($sc) – upload file form,form for listing already uploaded files etc.// sourceFormValidate, sourceFormSubmit 08.09.2011 Kyiv Drupal Cafe`
  10. 10. Feeds tricks function ofeeds_ctools_plugin_api($owner, $api) { if ($owner == feeds && $api == plugins) { return array(version => 1); } } function ofeeds_enable() { //clear the cache to display in Feeds as available plugin. cache_clear_all(plugins:feeds:plugins, cache); } // Do not use variable_set as instances config !!!   
  11. 11. Thanks Andriy Podanenko @podarok podarokua@gmail.com http://twitter.com/podarok http://facebook.com/podarok http://drupal.org/user/116002   

×