Comments

MisterTeks created an issue. See original summary.

julien tekrane’s picture

StatusFileSize
new9.6 KB
julien tekrane’s picture

StatusFileSize
new10.42 KB
julien tekrane’s picture

StatusFileSize
new10.08 KB
julien tekrane’s picture

julien tekrane’s picture

StatusFileSize
new10.21 KB
megachriz’s picture

Status: Patch (to be ported) » Postponed (maintainer needs more info)

Can you explain why the hook hook_file_presave() is not sufficient for your use case?

Can you also explain what your patches are doing? Your latest patch seems to change a lot of code and I'm curious why so many changes are needed for just invoking a new hook.

julien tekrane’s picture

Issue summary: View changes
StatusFileSize
new13.64 KB
julien tekrane’s picture

Issue summary: View changes

Hello and thank you for your interest.

This patch do 3 things :

  1. hook_feeds_file_alter: It allows you to set properties to files only imported by feeds while the hook_file_presave() deals with every files saved. I needed to contextualize the feeds import so I added this hook.
  2. setFileProperties() : It allow you to set properties of a file just by adding the target via hook_feeds_processor_targets_alter. There is no need of additional callback that will be a copy&past of file_feeds_set_target() but with your custom property
  3. Adding the :filename target for "file" entities. The file will be created as previously but will be saved a second time to rename it.

Thanks for your attention

julien tekrane’s picture

StatusFileSize
new13.16 KB

Fix troubles with same field part of name (exemple "field_document" and "field_documents" was merged together). It is because my test was done with strpos ... now I explode the $mapping['target] and test if my current field is in_array of my exploded array.

megachriz’s picture

  1. +++ b/mappers/file.inc
    @@ -184,7 +191,11 @@ function file_feeds_set_target(FeedsSource $source, $entity, $target, array $val
    +            // Flag the current result path, set the value and unflag the path.
    +            _feeds_insert_unique_array_last($result_item_path, $k);
    ...
    +            _feeds_delete_unique_array_last($result_item_path, $k);
    

    It sounds like some nested value in an array is parsed here. Can you give some example data that clarifies why something in a multidimensional array needs to be searched?

  2. +++ b/plugins/FeedsParser.inc
    @@ -458,11 +458,34 @@ class FeedsEnclosure extends FeedsElement {
    +  public function getFile($destination, $replace = FILE_EXISTS_RENAME, $source = null, $mapping = null, array $result_item_path = array(), FeedsParserResult $result = null) {
    

    What is $result_item_path and why is the FeedsParserResult needed here?

  3. +++ b/plugins/FeedsParser.inc
    @@ -458,11 +458,34 @@ class FeedsEnclosure extends FeedsElement {
    +      //Extract subfields into an array.
    +      $subfields = array();
    +      if(isset($result)){
    +        $result_current_item = $result->currentItem();
    +        if(!empty($result_current_item)){
    +          $field_name = array_shift(explode(':', $mapping['target']));
    +          foreach($source->importer->processor->config['mappings'] as $_mapping){
    +            $targets = explode(':', $_mapping['target']);
    +            if(in_array($field_name, $targets)){
    +              $subfield_name = $targets[1];
    +              $value = $result_current_item[$_mapping['source']];
    +              if(!empty($value)){
    +                $subfields[$subfield_name] = _feeds_get_array_child_by_keys($value, $result_item_path);
    +              }
    +            }
    +          }
    +          // Unset because we are in this case (getFile() called only in 'uri').
    +          unset($subfields['uri']);
    +        }
    +      }
    

    What happens here and why is access to the parser result important here?

  4. +++ b/plugins/FeedsProcessor.inc
    @@ -814,14 +814,8 @@ abstract class FeedsProcessor extends FeedsPlugin {
    -    // This is where the actual mapping happens: For every mapping we invoke
    -    // the parser's getSourceElement() method to retrieve the value of the
    -    // source element and pass it to the processor's setTargetElement() to stick
    -    // it on the right place of the target item.
    ...
    -      $value = $this->getSourceValue($source, $result, $mapping['source']);
    
    @@ -855,31 +849,38 @@ abstract class FeedsProcessor extends FeedsPlugin {
    +    // This is where the actual mapping happens: For every mapping we invoke
    +    // the parser's getSourceElement() method to retrieve the value of the
    +    // source element and pass it to the processor's setTargetElement() to stick
    +    // it on the right place of the target item.
    +    $value = $this->getSourceValue($source, $result, $mapping['source']);
    

    Why is it that this code needed to be moved?

  5. +++ b/plugins/FeedsProcessor.inc
    @@ -855,31 +849,38 @@ abstract class FeedsProcessor extends FeedsPlugin {
    +   * @param mixed $field_name
    +   *   The field_name.
    

    $target !== $field_name. A feeds target is in most cases a field, but not always. It can also be a property on an entity.

  6. +++ b/plugins/FeedsProcessor.inc
    @@ -855,31 +849,38 @@ abstract class FeedsProcessor extends FeedsPlugin {
    +  protected function mapToTarget(FeedsSource $source, $field_name, &$target_item, array $mapping, FeedsParserResult $result) {
    

    Changing the method signature here possibly breaks modules that are overriding this method.

julien tekrane’s picture

Issue tags: -
StatusFileSize
new13.09 KB
bluegeek9’s picture

Assigned: julien tekrane » Unassigned
Status: Postponed (maintainer needs more info) » Closed (outdated)
//www.flaticon.com/free-icons/thank-you Thank you for your contribution!

Unfortunately, Drupal 7 is End of Life and no longer supported. We strongly encourage you to upgrade to a supported version of Drupal.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.