# HG changeset patch # User Dirk Wintergruen # Date 1434560114 -7200 # Node ID 1c73c660c2f29f3a0c4f1bd8cac1414a0cc564c0 # Parent 124ef8f3b22dafb92255985e694af41bcdd5afd1 new relation_processor diff -r 124ef8f3b22d -r 1c73c660c2f2 relation_processor/FeedsProcessor.inc --- a/relation_processor/FeedsProcessor.inc Fri Mar 27 19:21:42 2015 +0100 +++ b/relation_processor/FeedsProcessor.inc Wed Jun 17 18:55:14 2015 +0200 @@ -554,8 +554,9 @@ '#type' => 'select', '#options' => $this->bundleOptions(), '#title' => !empty($info['bundle name']) ? $info['bundle name'] : t('Bundle'), - '#required' => TRUE, - '#default_value' => $this->bundle(), + '#required' => false, + '#description' => t('if not set, relation_name has to be one of the mappings'), + '#default_value' => "generic", ); } else { diff -r 124ef8f3b22d -r 1c73c660c2f2 relation_processor/FeedsRelationProcessor.inc --- a/relation_processor/FeedsRelationProcessor.inc Fri Mar 27 19:21:42 2015 +0100 +++ b/relation_processor/FeedsRelationProcessor.inc Wed Jun 17 18:55:14 2015 +0200 @@ -137,6 +137,7 @@ * Save a node. */ public function entitySave($entity) { + relation_save($entity); } @@ -197,6 +198,22 @@ $form = parent::configForm($form_state); $author = user_load($this->config['author']); + + + $options =$this->bundleOptions(); + $form['bundle'] = array( + '#type' => 'select', + '#options' => $options, + '#title' => !empty($info['bundle name']) ? $info['bundle name'] : t('Bundle'), + '#required' => false, + '#description' => t('if set to generic, relation_name has to be one of the mappings'), + '#default_value' => "generic", + ); + + + + + $form['author'] = array( '#type' => 'textfield', '#title' => t('Author'), @@ -359,8 +376,9 @@ //$entity_type = $this->entityType(); $entity_type = "relation"; $bundle = $this->bundle(); - drupal_alter('feeds_processor_targets', $targets, $entity_type, $bundle); + #drupal_alter('feeds_processor_targets', $targets, $entity_type, $bundle); + relation_feeds_processor_targets_alter($targets, $entity_type, $bundle); return $targets; } diff -r 124ef8f3b22d -r 1c73c660c2f2 relation_processor/FeedsRelationProcessor.inc~ --- a/relation_processor/FeedsRelationProcessor.inc~ Fri Mar 27 19:21:42 2015 +0100 +++ b/relation_processor/FeedsRelationProcessor.inc~ Wed Jun 17 18:55:14 2015 +0200 @@ -45,7 +45,7 @@ $relation = new stdClass(); $relation->is_new = TRUE; - dpm($this->bundle()); + $relation->relation_type = $this->bundle(); $relation->uid = $this->config['author']; $relation->endpoints[LANGUAGE_NONE] = Null; @@ -137,6 +137,7 @@ * Save a node. */ public function entitySave($entity) { + dpm($entity); relation_save($entity); } @@ -197,6 +198,22 @@ $form = parent::configForm($form_state); $author = user_load($this->config['author']); + + + $options =$this->bundleOptions(); + $form['bundle'] = array( + '#type' => 'select', + '#options' => $options, + '#title' => !empty($info['bundle name']) ? $info['bundle name'] : t('Bundle'), + '#required' => false, + '#description' => t('if set to generic, relation_name has to be one of the mappings'), + '#default_value' => "generic", + ); + + + + + $form['author'] = array( '#type' => 'textfield', '#title' => t('Author'), @@ -283,7 +300,8 @@ */ public function getMappingTargets() { $type = relation_type_load($this->bundle()); - + dpm("MAPT"); + dpm($type); $targets = parent::getMappingTargets(); $targets['source_id'] = array( @@ -359,8 +377,9 @@ //$entity_type = $this->entityType(); $entity_type = "relation"; $bundle = $this->bundle(); - drupal_alter('feeds_processor_targets', $targets, $entity_type, $bundle); - + dpm("ALTER"); + #drupal_alter('feeds_processor_targets', $targets, $entity_type, $bundle); + relation_feeds_processor_targets_alter($targets, $entity_type, $bundle); return $targets; } diff -r 124ef8f3b22d -r 1c73c660c2f2 relation_processor/nodes.inc --- a/relation_processor/nodes.inc Fri Mar 27 19:21:42 2015 +0100 +++ b/relation_processor/nodes.inc Wed Jun 17 18:55:14 2015 +0200 @@ -25,11 +25,11 @@ * Search by CITEKEY. */ define('FEEDS_ENTITY_SEARCH_TERM_CITEKEY', 3); - +dpm("RELATION_include"); /** * Implements hook_feeds_parser_sources_alter(). */ -function entity_feeds_parser_sources_alter(&$sources, $content_type) { +function relation_feeds_parser_sources_alter(&$sources, $content_type) { if (!empty($content_type)) { $sources['sources'] = array( @@ -44,7 +44,7 @@ /** * Callback, returns taxonomy from feed node. */ -function entity_feeds_get_source(FeedsSource $source, FeedsParserResult $result, $key) { +function relation_feeds_get_source(FeedsSource $source, FeedsParserResult $result, $key) { /*if ($node = node_load($source->feed_nid)) { $terms = taxonomy_feeds_node_get_terms($node); $vocabularies = taxonomy_vocabulary_load_multiple(array(), array('machine_name' => str_replace('parent:taxonomy:', '', $key))); @@ -63,7 +63,7 @@ /** * Implements hook_feeds_processor_targets_alter(). */ -function entity_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) { +function relation_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) { /*foreach (field_info_instances($entity_type, $bundle_name) as $name => $instance) { $info = field_info_field($name); if ($info['type'] == 'taxonomy_term_reference') { @@ -82,23 +82,23 @@ $targets["source_id"]= array( 'name' => 'Source Field', - 'callback' => 'entity_feeds_set_target', + 'callback' => 'relation_feeds_set_target', 'description' => t('The guid of the entity.'), - 'summary_callback' => 'entity_feeds_summary_callback', - 'form_callback' => 'entity_feeds_form_callback', + 'summary_callback' => 'relation_feeds_summary_callback', + 'form_callback' => 'relation_feeds_form_callback', ); $targets["target_id"]= array( 'name' => 'Target Field', - 'callback' => 'entity_feeds_set_target', + 'callback' => 'relation_feeds_set_target', 'description' => t('The guid of the entity.'), - 'summary_callback' => 'entity_feeds_summary_callback', - 'form_callback' => 'entity_feeds_form_callback', + 'summary_callback' => 'relation_feeds_summary_callback', + 'form_callback' => 'relation_feeds_form_callback', ); $targets["relation_name"]= array( 'name' => 'Relation Type', - 'callback' => 'entity_feeds_set_relation_type', + 'callback' => 'relation_feeds_set_relation_type', ); @@ -112,8 +112,7 @@ * * */ -function entity_feeds_set_relation_type($source, $entity, $target, $terms, $mapping = array()) { - +function relation_feeds_set_relation_type($source, $entity, $target, $terms, $mapping = array()) { if (empty($terms)) { return; } @@ -124,10 +123,14 @@ } + dpm("CHECK: TYPE"); + dpm($terms); + $types=relation_get_types(array($terms)); + if(sizeof($types)==0){ //typ gibt es nicht dann erzeuge mit defualt werten #TODO konfigurierbar? - dpm("CREATE RELATION TYPE:" . $terms); + $info = array(); $info['relation_type']=$terms; $info['directional']=TRUE; @@ -138,8 +141,47 @@ relation_type_save($rel_type); } + $entity->relation_type=$terms; + + if ( _relation_feeds_checkRelationComplete($entity)){ + + $entity->is_new=FALSE; + } relation_update($entity); + +} + + +function _relation_feeds_checkRelationComplete($relation){ + //einer der Endpunkte existiert nicht + + if (count($relation->endpoints['und'][0]) == 0) + return false; + if (!isset($relation->endpoints['und'][1])) + return false; + if (count($relation->endpoints['und'][1]) == 0) + return false; + + if ($relation->relation_type == "generic") + return false; + return true; + +} + +function _relation_feeds_checkEndpointsComplete($relation){ + //einer der Endpunkte existiert nicht + + + if (count($relation->endpoints['und'][0]) == 0) + return false; + if (!isset($relation->endpoints['und'][1])) + return false; + if (count($relation->endpoints['und'][1]) == 0) + return false; + + return true; + } /** @@ -147,7 +189,7 @@ * * @todo Do not create new terms for non-autotag fields. */ -function entity_feeds_set_target($source, $entity, $target, $terms, $mapping = array()) { +function relation_feeds_set_target($source, $entity, $target, $terms, $mapping = array()) { // Allow mapping the string '0' to a term name. if (empty($terms) && $terms != 0) { @@ -206,8 +248,9 @@ // Lookup by GUID. case FEEDS_ENTITY_SEARCH_TERM_GUID: - $tid = entity_feeds_entity_lookup_entity_by_guid($term); - + + $tid = relation_feeds_entity_lookup_entity_by_guid($term); + break; case FEEDS_ENTITY_SEARCH_TERM_CITEKEY: @@ -216,6 +259,7 @@ } + $eps = $entity->endpoints[LANGUAGE_NONE]; if (!isset($entity->endpoints[LANGUAGE_NONE])){ // noch nicht existent $entity->endpoints[LANGUAGE_NONE][]=array(); @@ -225,6 +269,7 @@ switch ($target){ case "source_id": + // source is immer der erste eintrag $entity->endpoints[LANGUAGE_NONE][0]=array('entity_type' => 'node', 'entity_id' => $tid); break; @@ -234,17 +279,29 @@ $entity->endpoints[LANGUAGE_NONE][]=array('entity_type' => 'node', 'entity_id' => $tid); } - //dpm($entity); + + + if ( _relation_feeds_checkRelationComplete($entity)){ + + $entity->is_new=FALSE; + relation_update($entity); + } - //if ($target=="target_id"){ - relation_update($entity); + if ( _relation_feeds_checkEndpointsComplete($entity)){ + relation_update($entity); + } - if (sizeof($entity->endpoints[LANGUAGE_NONE])>1){ // WENN ZWEI ENDPUNKTE VORHANDEN DANN abspeichern - $entity->is_new=FALSE; + # if ($target=="source_id"){ + # relation_update($entity); + # } - } + #if (sizeof($entity->endpoints[LANGUAGE_NONE])>1){ // WENN ZWEI ENDPUNKTE VORHANDEN DANN abspeichern + + //$entity->is_new=FALSE; + + #} // } } @@ -293,7 +350,7 @@ * @see taxonomy_feeds_node_get_terms() * @see field_get_items() */ -function _entity_feeds_extract_tid($item) { +function _relation_feeds_extract_tid($item) { return $item['tid']; } @@ -306,7 +363,7 @@ * @return int|FALSE * The term id, or FALSE if one was not found. */ -function entity_feeds_entity_lookup_entity_by_guid($guid) { +function relation_feeds_entity_lookup_entity_by_guid($guid) { $res = db_select('feeds_item') @@ -347,8 +404,8 @@ * If the return value is empty, no summary and no option to view the form * will be displayed. */ -function entity_feeds_summary_callback($mapping, $target, $form, $form_state) { - $options = _entity_feeds_form_callback_options(); +function relation_feeds_summary_callback($mapping, $target, $form, $form_state) { + $options = _relation_feeds_form_callback_options(); if (empty($mapping['term_search'])) { return t('Search Entity terms by: @search', array('@search' => $options[FEEDS_ENTITY_SEARCH_TERM_NAME])); } @@ -362,12 +419,12 @@ * The per mapping configuration form. Once the form is saved, $mapping will * be populated with the form values. */ -function entity_feeds_form_callback($mapping, $target, $form, $form_state) { +function relation_feeds_form_callback($mapping, $target, $form, $form_state) { return array( 'term_search' => array( '#type' => 'select', '#title' => t('Search Entity by'), - '#options' => _entity_feeds_form_callback_options(), + '#options' => _relation_feeds_form_callback_options(), '#default_value' => !empty($mapping['term_search']) ? $mapping['term_search'] : FEEDS_ENTITY_SEARCH_TERM_NAME, ), ); @@ -379,7 +436,7 @@ * @return array * An array of taxonomy search option titles. */ -function _entity_feeds_form_callback_options() { +function _relation_feeds_form_callback_options() { return array( FEEDS_ENTITY_SEARCH_TERM_NAME => 'Entity name', FEEDS_ENTITY_SEARCH_TERM_ID => 'Entity ID', diff -r 124ef8f3b22d -r 1c73c660c2f2 relation_processor/relation_processor.module --- a/relation_processor/relation_processor.module Fri Mar 27 19:21:42 2015 +0100 +++ b/relation_processor/relation_processor.module Wed Jun 17 18:55:14 2015 +0200 @@ -10,7 +10,7 @@ $info['FeedsRelationProcessor'] = array( 'name' => 'Relation processor', 'description' => 'Create and update relations.', - 'help' => 'Create and update relations from parsed content.', + 'help' => 'Create and update relations from parsed content. (II)', 'handler' => array( 'parent' => 'FeedsProcessor', 'class' => 'FeedsRelationProcessor',