feeds drupal cafe
DESCRIPTION
Feeds Drupal developer keynoteTRANSCRIPT
08.09.2011 Kyiv Drupal Cafe`
Drupal Feeds
Andriy Podanenko aka @podarok
http://drupal.org/user/116002
Kyiv Drupal Cafe`
feeds developer keynotes
08.09.2011 Kyiv Drupal Cafe`
POI
FeedsSource extends FeedsConfigurableFeedsSource::import
Plugins (FeedsFetcher, FeedsParser, FeedsProcessor)
Hooks Mappings
hook_feeds_processor_targets_alter()
hook_feeds_parser_sources_alter()
08.09.2011 Kyiv Drupal Cafe`
Manual process startImport()
$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`
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`
$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();
FeedsSource::import
08.09.2011 Kyiv Drupal Cafe`
Feeds hooks
function 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`
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 be
in 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`
Feeds plugins● class FeedsPlugin extends FeedsConfigurable implements FeedsSourceInterfacemethods: save, sourceForm, configForm, loadMappers...
● FeedsFetcher extends FeedsPluginmethods: clear, fetch...
● FeedsParser extends FeedsPluginmethods: parse, clear...
● FeedsProcessor extends FeedsPluginmethods: process, entityType, newEntity, entityLoad,
entitySave, entityDeleteMultiple
08.09.2011 Kyiv Drupal Cafe`
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 at
content type creation forms (user level)FE: FeedsFileFetcher::sourceForm($sc) – upload file form,
form for listing already uploaded files etc.
// sourceFormValidate, sourceFormSubmit
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 !!!
Thanks
Andriy Podanenko @podarok
[email protected]://twitter.com/podarokhttp://facebook.com/podarokhttp://drupal.org/user/116002