From c17412e2ff1cde9c66f0bc719623cbd01ca64411 Mon Sep 17 00:00:00 2001
From: megachriz <megachriz@654114.no-reply.drupal.org>
Date: Sat, 30 May 2015 00:38:00 -0700
Subject: [PATCH] Issue #2469219 by MegaChriz, twistor: Remove the Generic
 Entity Processor

---
 feeds.info                        |   2 -
 feeds.module                      |  82 ---------
 feeds.plugins.inc                 |  23 ---
 plugins/FeedsEntityProcessor.inc  | 270 ------------------------------
 tests/feeds_processor_entity.test |  93 ----------
 tests/feeds_tests.info            |   1 -
 6 files changed, 471 deletions(-)
 delete mode 100644 plugins/FeedsEntityProcessor.inc
 delete mode 100644 tests/feeds_processor_entity.test

diff --git a/feeds.info b/feeds.info
index d95f6aa3..be3f52a5 100644
--- a/feeds.info
+++ b/feeds.info
@@ -14,7 +14,6 @@ files[] = libraries/PuSHSubscriber.inc
 
 ; Plugins
 files[] = plugins/FeedsCSVParser.inc
-files[] = plugins/FeedsEntityProcessor.inc
 files[] = plugins/FeedsFetcher.inc
 files[] = plugins/FeedsFileFetcher.inc
 files[] = plugins/FeedsHTTPFetcher.inc
@@ -48,7 +47,6 @@ files[] = tests/feeds_mapper_format_config.test
 files[] = tests/feeds_fetcher_http.test
 files[] = tests/feeds_parser_sitemap.test
 files[] = tests/feeds_parser_syndication.test
-files[] = tests/feeds_processor_entity.test
 files[] = tests/feeds_processor_node.test
 files[] = tests/feeds_processor_term.test
 files[] = tests/feeds_processor_user.test
diff --git a/feeds.module b/feeds.module
index e74582e1..f5369265 100644
--- a/feeds.module
+++ b/feeds.module
@@ -1333,85 +1333,3 @@ function feeds_api_version() {
   $version = feeds_ctools_plugin_api('feeds', 'plugins');
   return $version['version'];
 }
-
-/**
- * Implements hook_form_FORM_ID_alter().
- */
-function node_form_feedsentityprocessor_feeds_form_alter(&$form, &$form_state) {
-  if ($form['#configurable']->entityType() == 'node') {
-    unset($form['values']['title']);
-    $form['values']['author']['#required'] = FALSE;
-    $form['values']['author']['#autocomplete_path'] = 'user/autocomplete';
-    array_unshift($form['#validate'], 'node_form_feedsentityprocessor_feeds_form_validate');
-    if (is_numeric($form['values']['author']['#default_value']) &&
-      $account = user_load($form['values']['author']['#default_value'])) {
-      $form['values']['author']['#default_value'] = $account->name;
-    }
-  }
-}
-
-/**
- * Validation callback for node_form_feedsentityprocessor_feeds_form_alter().
- */
-function node_form_feedsentityprocessor_feeds_form_validate(&$form, &$form_state) {
-  if (empty($form_state['values']['values']['author'])) {
-    form_set_value($form['values']['author'], 0, $form_state);
-  }
-  else {
-    $account = user_load_by_name($form_state['values']['values']['author']);
-    if ($account) {
-      form_set_value($form['values']['author'], $account->uid, $form_state);
-    }
-  }
-}
-
-/**
- * Implements hook_feeds_processor_targets_alter().
- */
-function node_feeds_processor_targets_alter(&$targets, $entity_type, $bundle) {
-  if ($entity_type == 'node') {
-    $targets['nid']['name'] = t('Node id');
-    $targets['nid']['description'] = t('The nid of the node. NOTE: use this feature with care, node ids are usually assigned by Drupal.');
-  }
-}
-
-/**
- * Implements hook_form_FORM_ID_alter().
- */
-function user_form_feedsentityprocessor_feeds_form_alter(&$form, &$form_state) {
-  if ($form['#configurable']->entityType() == 'user') {
-    unset($form['values']['name']);
-    $form['values']['mail']['#required'] = FALSE;
-  }
-}
-
-/**
- * Implements hook_form_FORM_ID_alter().
- */
-function taxonomy_form_feedsentityprocessor_feeds_form_alter(&$form, &$form_state) {
-  if ($form['#configurable']->entityType() == 'taxonomy_term') {
-    unset($form['values']['name']);
-    if (empty($form['values']['weight']['#default_value'])) {
-      $form['values']['weight']['#default_value']= '';
-    }
-    array_unshift($form['#validate'], 'taxonomy_form_feedsentityprocessor_feeds_form_validate');
-    unset($form['values']['parent']);
-    $form['values']['machine_name'] = $form['values']['vocabulary'];
-    $form['values']['vocabulary']['#access'] = FALSE;
-  }
-  elseif ($form['#configurable']->entityType() == 'taxonomy_vocabulary') {
-    unset($form['values']['name']);
-    unset($form['values']['machine_name']);
-    unset($form['values']['vid']);
-  }
-}
-
-/**
- * Validation callback for taxonomy_form_feedsentityprocessor_feeds_form_alter().
- */
-function taxonomy_form_feedsentityprocessor_feeds_form_validate(&$form, &$form_state) {
-  if (empty($form_state['values']['values']['weight'])) {
-    form_set_value($form['values']['weight'], 0, $form_state);
-  }
-  form_set_value($form['values']['vocabulary'], $form_state['values']['values']['machine_name'], $form_state);
-}
diff --git a/feeds.plugins.inc b/feeds.plugins.inc
index fa451373..cbba3f5c 100644
--- a/feeds.plugins.inc
+++ b/feeds.plugins.inc
@@ -166,29 +166,6 @@ function _feeds_feeds_plugins() {
       ),
     );
   }
-  if (module_exists('entity')) {
-    foreach (entity_get_info() as $type => $entity_info) {
-      // @todo: Test for saving and whatever else necessary?
-      if (entity_type_supports($type, 'create')) {
-        $info['FeedsEntityProcessor' . drupal_ucfirst($type)] = array(
-          'name' => $entity_info['label'] . ' entity processor - EXPERIMENTAL',
-          // @todo: Use plural label if there.
-          'description' => 'Create and update ' . drupal_strtolower($entity_info['label']) . 's.',
-          'help' => 'Create and update ' . drupal_strtolower($entity_info['label']) . 's from parsed content.',
-          'plugin_key' => 'FeedsEntityProcessor',
-          'handler' => array(
-            'parent' => 'FeedsProcessor',
-            'class' => 'FeedsEntityProcessor',
-            'file' => 'FeedsEntityProcessor.inc',
-            'path' => $path,
-          ),
-          // Add in the entity type used.
-          // @see FeedsEntityProcessor::entityType()
-         'type' => $type,
-        );
-      }
-    }
-  }
 
   return $info;
 }
diff --git a/plugins/FeedsEntityProcessor.inc b/plugins/FeedsEntityProcessor.inc
deleted file mode 100644
index 5125c94b..00000000
--- a/plugins/FeedsEntityProcessor.inc
+++ /dev/null
@@ -1,270 +0,0 @@
-<?php
-/**
- * @file
- * Class definition of FeedsEntityProcessor.
- */
-
-/**
- * Creates entities from feed items.
- */
-class FeedsEntityProcessor extends FeedsProcessor {
-
-  /**
-   * Returns the entity type.
-   *
-   * @return string
-   *   The type of entity this processor will create.
-   */
-  public function entityType() {
-    $plugin_info = $this->pluginDefinition();
-    return $plugin_info['type'];
-  }
-
-  /**
-   * Returns the bundle.
-   *
-   * @return string
-   *   The bundle of the entities this processor will create.
-   */
-  public function bundle() {
-    $bundle = $this->entityType();
-
-    $entity_info = $this->entityInfo();
-    if(!empty($this->config['bundle']) && isset($entity_info['bundles'][$this->config['bundle']])) {
-      $bundle = $this->config['bundle'];
-    }
-
-    return $bundle;
-  }
-
-  /**
-   * Overrides parent::entityInfo().
-   */
-  protected function entityInfo() {
-    $info = parent::entityInfo();
-    if (isset($info['label plural'])) {
-      $plural = $info['label plural'];
-    }
-    else {
-      $plural = $info['label'];
-    }
-
-    $info += array('label plural' => $plural);
-    return $info;
-  }
-
-  /**
-   * Creates a new entity in memory and returns it.
-   */
-  protected function newEntity(FeedsSource $source) {
-    $info = $this->entityInfo();
-    $values = $this->config['values'];
-
-    if (isset($info['entity keys']['bundle']) && isset($this->config['bundle'])) {
-      $values[$info['entity keys']['bundle']] = $this->config['bundle'];
-    }
-
-    return entity_create($this->entityType(), $values);
-  }
-
-  /**
-   * Check that the user has permission to save an entity.
-   *
-   * @todo Is checking the uid safe? A quick glance through core and some
-   *   contrib seems to say yes.
-   */
-  protected function entitySaveAccess($entity) {
-
-    // The check will be skipped for anonymous users.
-    if (!empty($this->config['authorize']) && !empty($entity->uid)) {
-
-      $author = user_load($entity->uid);
-
-      // If the uid was mapped directly, rather than by email or username, it
-      // could be invalid.
-      if (!$author) {
-        $message = 'User %uid is not a valid user.';
-        throw new FeedsAccessException(t($message, array('%uid' => $entity->uid)));
-      }
-
-      if (!empty($entity->is_new)) {
-        $op = 'create';
-        $access = entity_access($op, $this->entityType(), $author);
-      }
-      else {
-        $op = 'update';
-        $access = entity_access($op, $this->entityType(), $author);
-      }
-
-      if (!$access) {
-        $message = t('The user %name is not authorized to %op entity %entity_type. To import this item, the user "@name" (owner of the item) must be given the permission to @op entity @entity_type.', array(
-          '%name' => $author->name,
-          '%op' => $op,
-          '%entity_type' => $this->entityType(),
-          '@name' => $author->name,
-          '@op' => $op,
-          '@entity_type' => $this->entityType(),
-        ));
-        throw new FeedsAccessException($message);
-      }
-    }
-  }
-
-  /**
-   * Save a entity.
-   */
-  public function entitysave($entity) {
-    entity_save($this->entityType(), $entity);
-  }
-
-  /**
-   * Delete a series of entities.
-   */
-  protected function entityDeleteMultiple($ids) {
-    entity_delete_multiple($this->entityType(), $ids);
-  }
-
-  /**
-   * Override parent::configDefaults().
-   */
-  public function configDefaults() {
-    return array(
-      'mappings' => array(),
-      'update_existing' => FEEDS_SKIP_EXISTING,
-      'update_non_existent' => FEEDS_SKIP_NON_EXISTENT,
-      'input_format' => NULL,
-      'skip_hash_check' => FALSE,
-      'bundle' => NULL,
-      'values' => array(),
-    );
-  }
-
-  /**
-   * Override parent::configForm().
-   */
-  public function configForm(&$form_state) {
-    $form = parent::configForm($form_state);
-
-    $form['values'] = array(
-      '#type' => 'fieldset',
-      '#title' => t('Default values'),
-      '#tree' => TRUE,
-      '#description' => t('Most of the values below can be overriden by mapping a value.'),
-    );
-
-    $entity_info = $this->entityInfo();
-    $label_plural = $entity_info['label plural'];
-
-    $form['input_format']['#description'] = t('Select the default input format for the %entity to be created.', array('%entity' => $label_plural));
-
-    $wrapper = entity_metadata_wrapper($this->entityType());
-
-    $bundle_key = !empty($entity_info['entity keys']['bundle']) ? $entity_info['entity keys']['bundle']: NULL;
-
-    foreach ($wrapper->getPropertyInfo() as $name => $property) {
-      if ($name == $bundle_key) {
-        continue;
-      }
-
-      if (!empty($property['setter callback']) && empty($property['field'])) {
-        $form['values'][$name] = array(
-          '#type' => 'textfield',
-          '#title' => $property['label'],
-          '#description' => isset($property['description']) ? $property['description'] : '',
-          '#default_value' => isset($this->config['values'][$name]) ? $this->config['values'][$name] : NULL,
-          '#required' => !empty($property['required']),
-        );
-
-        if (!empty($property['options list'])) {
-          $form['values'][$name]['#type'] = 'select';
-          if (isset($property['type']) && entity_property_list_extract_type($property['type'])) {
-            $form['values'][$name]['#type'] = 'checkboxes';
-            if (!is_array($form['values'][$name]['#default_value'])) {
-              $form['values'][$name]['#default_value'] = array($form['values'][$name]['#default_value']);
-            }
-          }
-          $form['values'][$name]['#options'] = $wrapper->$name->optionsList();
-        }
-
-        elseif (!empty($property['type']) && $property['type'] == 'boolean') {
-          $form['values'][$name]['#type'] = 'checkbox';
-        }
-        // elseif (!empty($property['type']) && $property['type'] == 'date') {
-        //   $form['values'][$name]['#type'] = 'date';
-        // }
-      }
-    }
-    return $form;
-  }
-
-  /**
-   * Override parent::configFormValidate().
-   */
-  public function configFormValidate(&$values) {
-    $form = parent::configFormValidate($values);
-
-    $wrapper = entity_metadata_wrapper($this->entityType());
-
-    foreach ($wrapper->getPropertyInfo() as $name => $property) {
-      if (!empty($property['setter callback']) && empty($property['field'])) {
-
-        // Entity api won't accept empty date values.
-        if (!empty($property['type']) && $property['type'] == 'date') {
-          if (empty($values['values'][$name])) {
-            unset($values['values'][$name]);
-            continue;
-          }
-        }
-
-        if (isset($property['type']) && array_key_exists($name, $values['values'])) {
-          if (entity_property_list_extract_type($property['type']) && !is_array($values['values'][$name])) {
-            $values['values'][$name] = array($values['values'][$name]);
-          }
-          // check if values empty first as all default values are optional
-          if (!empty($values['values'][$name])) {
-            $valid = entity_property_verify_data_type($values['values'][$name], $property['type']);
-            if (!$valid) {
-              form_set_error("values][$name", t('Invalid data value given. Be sure it matches the required data type and format.'));
-            }
-          }
-        }
-      }
-    }
-  }
-
-  /**
-   * Returns available mapping targets.
-   */
-  public function getMappingTargets() {
-    // Get a wrapper with the right bundle info.
-
-    $targets = parent::getMappingTargets();
-    $info = array('bundle' => $this->bundle());
-
-    $wrapper = entity_metadata_wrapper($this->entityType(), NULL, $info);
-    // @todo: maybe restrict to data types feeds can deal with.
-    foreach ($wrapper->getPropertyInfo() as $name => $property) {
-      if (empty($property['field'])) {
-        $targets[$name] = array(
-          'name' => $property['label'],
-          'description' => isset($property['description']) ? $property['description'] : NULL,
-        );
-      }
-    }
-
-    $entity_info = $this->entityInfo();
-    $targets[$entity_info['entity keys']['id']]['optional_unique'] = TRUE;
-
-    // Remove the bundle target.
-    if (isset($entity_info['bundle keys']['bundle'])) {
-      unset($targets[$entity_info['bundle keys']['bundle']]);
-    }
-
-    // Let other modules expose mapping targets.
-    self::loadMappers();
-    $type = $this->entityType();
-    drupal_alter('feeds_processor_targets', $targets, $type, $info['bundle']);
-
-    return $targets;
-  }
-}
diff --git a/tests/feeds_processor_entity.test b/tests/feeds_processor_entity.test
deleted file mode 100644
index 87738c80..00000000
--- a/tests/feeds_processor_entity.test
+++ /dev/null
@@ -1,93 +0,0 @@
-<?php
-
-/**
- * @file
- * Tests for plugins/FeedsEntityProcessor.inc.
- */
-
-/**
- * Test aggregating a feed as node items.
- */
-class FeedsEntityProcessorTest extends FeedsWebTestCase {
-
-  public static function getInfo() {
-    return array(
-      'name' => 'Processor: Entity',
-      'description' => 'Tests importing entities using the generic processor.',
-      'group' => 'Feeds',
-      'dependencies' => array('entity_test'),
-    );
-  }
-
-  /**
-   * Set up test.
-   */
-  public function setUp() {
-    parent::setUp(array('entity_test'));
-    // Create an importer configuration.
-    $this->createImporterConfiguration('Syndication', 'syndication');
-    $this->setPlugin('syndication', 'FeedsEntityProcessorEntity_test');
-    $this->addMappings('syndication',
-      array(
-        0 => array(
-          'source' => 'guid',
-          'target' => 'guid',
-          'unique' => TRUE,
-        ),
-      )
-    );
-  }
-
-  /**
-   * Test basic entity creation.
-   */
-  public function test() {
-    $bundle = drupal_strtolower($this->randomName());
-
-    // Create bundle entity.
-    entity_create('entity_test_type', array(
-      'id' => drupal_strtolower($this->randomName()),
-      'name' => $bundle,
-    ))->save();
-
-    $this->setSettings('syndication', 'FeedsEntityProcessorEntity_test', array(
-      'bundle' => $bundle,
-    ));
-
-    // Run import.
-    $this->importURL('syndication', $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed.rss2');
-
-    // Assert 10 items created.
-    $this->assertText('Created 10 test entity');
-    $this->assertEqual(10, db_query("SELECT COUNT(*) FROM {entity_test}")->fetchField());
-
-    // Enable skip missing test entities and import updated feed file.
-    $this->setSettings('syndication', 'FeedsEntityProcessorEntity_test', array('update_non_existent' => 'skip'));
-    $missing_url = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed_missing.rss2';
-    $this->importURL('syndication', $missing_url);
-    $this->assertText('There are no new test entity');
-    $this->assertEqual(10, db_query("SELECT COUNT(*) FROM {entity_test}")->fetchField());
-
-    // Now delete all items.
-    $this->drupalPost('import/syndication/delete-items', array(), 'Delete');
-    $this->assertText('Deleted 10 test entity');
-    $this->assertEqual(0, db_query("SELECT COUNT(*) FROM {entity_test}")->fetchField());
-
-    // Import again, to reset entity counts.
-    $this->importURL('syndication', $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed.rss2');
-    $this->assertText('Created 10 test entity');
-    $this->assertEqual(10, db_query("SELECT COUNT(*) FROM {entity_test}")->fetchField());
-
-    // Change settings to delete non-existent entities from feed.
-    $this->setSettings('syndication', 'FeedsEntityProcessorEntity_test', array('update_non_existent' => 'delete'));
-    $this->importURL('syndication', $missing_url);
-    $this->assertText('Removed 1 test entity');
-    $this->assertEqual(9, db_query("SELECT COUNT(*) FROM {entity_test}")->fetchField());
-
-    // Now delete all items.
-    $this->drupalPost('import/syndication/delete-items', array(), 'Delete');
-    $this->assertText('Deleted 9 test entity');
-    $this->assertEqual(0, db_query("SELECT COUNT(*) FROM {entity_test}")->fetchField());
-  }
-
-}
diff --git a/tests/feeds_tests.info b/tests/feeds_tests.info
index 0ac42095..df368ca2 100644
--- a/tests/feeds_tests.info
+++ b/tests/feeds_tests.info
@@ -4,7 +4,6 @@ package = Testing
 version = VERSION
 core = 7.x
 test_dependencies[] = date
-test_dependencies[] = entity
 test_dependencies[] = feeds_xpathparser
 test_dependencies[] = link
 hidden = TRUE
-- 
GitLab