This patch provides support for exporting files for Drupal 7.

Since files are entities in Drupal 7, We need to take a bit of a different approach than in D6:

* This patch creates a new features category (Files), where you can export individual files. This was not the case in D6, where the files were only exported when they were they were part of an exported node. I think files deserve their own category since they can be fieldable when using file entity or media module.

* The patch provides support for file, image and media fields on nodes and automaticly adds the files to the feature when a node is selected.

Some other notes about the patch:

* Since it is hard to enforce a particular order in which items are imported, We might be in a situation where the node is created before the files has been created. To fix this, the patch contains code that checks if the file has been inserted, and if it hasn't, it invokes all default_files hooks and stores the file in the database if necessary.

Comments

fabsor’s picture

Title: Support File entities, file, image and media fields » Support File entities and file, image and media fields

Fixing title.

fabsor’s picture

StatusFileSize
new17.63 KB

Dreditor pointed out that I missed a newline, so here is an updated patch.

ao2’s picture

Hi, I have just started to play with uuid_features after trying Default Content and I find that uuid_features takes a more generic approach.

Exporting files is a very useful addition indeed, but even with this patch applied we still need to copy the files/ dir manually right? I can't see actual files in the feature archive when I export their drupal representation.

Thanks,
Antonio

fabsor’s picture

Hi!

This module provides a drush command to move the files to a feature, drush ufuf. It can be used after the feature has been created.

ao2’s picture

OK, so if I get it the workflow should be:

  1. Create a feature (e.g. default_content)
  2. Install that very feature, AFAICS when a new feature is created it is not installed automatically
  3. Run drush ufuf default_content to copy the actual files in the directory of the feature above
  4. Repack the feature archive for distribution
  5. Install the feature on another site (or on site reinstall for example: I am using drush make to rebuild the site after each feature is complete).

This seems to work well with some minor glitches:

  • drush ufuf wants to depend on filefield, I had to change that:
    diff --git a/includes/uuid_features.drush.inc b/includes/uuid_features.drush.inc
    index c5182e1..c82a5d4 100644
    --- a/includes/uuid_features.drush.inc
    +++ b/includes/uuid_features.drush.inc
    @@ -22,7 +22,7 @@ function uuid_features_drush_command() {
         'arguments' => array(
           'feature' => 'Feature name to export.',
         ),
    -    'drupal dependencies' => array('features', 'uuid', 'uuid_features', 'filefield'),
    +    'drupal dependencies' => array('features', 'uuid', 'uuid_features', 'file'),
         'aliases' => array('ufuf'),
       );
     
    
  • When installing the feature on a new site there are some warnings:
    $ drush en default_content
    The following extensions will be enabled: default_content
    Do you really want to continue? (y/n): y
    WD php: Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of       [warning]
    /home/ao2/public_html/mysite/includes/entity.inc).
    default_content was enabled successfully.                                                                                           [ok]
    array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of                     [warning]
    /home/ao2/public_html/mysite/includes/entity.inc).
    

But it is very promising, thanks @fabsor.

d.olaresko’s picture

there is a little mistake in this patch:
function uuid_file_features_export.

   foreach ($data as $uuid) {
    if (isset($map[$identifier]) && $map[$identifier] != $module_name) {
      if (isset($export['features']['uuid_file'][$uuid])) {
        unset($export['features']['uuid_file'][$uuid]);
      }
      $export['dependencies'][$module] = $map[$identifier];
    }
    else {
      $export['features']['uuid_file'][$uuid] = $uuid;
    }
   }

must be

   foreach ($data as $uuid) {
    if (isset($map[$uuid]) && $map[$uuid] != $module_name) {
      if (isset($export['features']['uuid_file'][$uuid])) {
        unset($export['features']['uuid_file'][$uuid]);
      }
      $export['dependencies'][$module] = $map[$uuid];
    }
    else {
      $export['features']['uuid_file'][$uuid] = $uuid;
    }
   }
fabsor’s picture

Status: Needs review » Needs work

Setting this issue to needs work as appropriate. I will work on this as soon as possible, if someone doesn't post a patch before me =)

natts’s picture

Hi there - are you still working on this?

lotyrin’s picture

Status: Needs work » Needs review

Attempt at a reroll without a deep understanding of the code, and accounting for #6

lotyrin’s picture

StatusFileSize
new0 bytes

Oops. And here's the file.

lotyrin’s picture

StatusFileSize
new0 bytes

Oops again, and this one also has the change from #5 to fix drush ufuf

lotyrin’s picture

StatusFileSize
new17.6 KB

:( And here is a file with actual stuff in it.

lotyrin’s picture

Status: Needs review » Needs work

Doesn't seem to actually work.

cinnamon’s picture

It seems this patch is using obsolete uuid_file_find(), instead one could use this for example:

$files = array_values(entity_uuid_load('file', array($uuid)));
$fid = $files[0]->fid;

I'm sure it can be done prettier, but this works(tm)! It's however not the whole story:
- one should use the dev version of uuid_featrues
- apply patch from #12
- edit like shown above (replace all occurences of uuid_file_find that is
- in your feature choose recreate, and uncheck and recheck an entry under node(uuid), file entities should now be picked up
- save and deploy your updated feature
- run "drush uuid-features-update-files %your feature%"

You should now have a feature with embedded files to deploy on another install.

Hope this helps!

jrao’s picture

Status: Needs work » Needs review
StatusFileSize
new13.31 KB

Rerolled patch from #12 with changes suggested in #14

RAD-lance’s picture

Should I use drush for working this module now?

I need to export my cck imagefield content with my feature.

hswong3i’s picture

Assigned: Unassigned » hswong3i
ergonlogic’s picture

Assigned: hswong3i » Unassigned
Status: Needs review » Needs work

Hi all,

Nice effort so far on this issue. Unfortunately, alone, the patch in #15 doesn't appear to work. While the file entity is recreated properly, the reference to it from within a node body is still pointing to the original Field ID:

[[{"fid":"8","view_mode":"default", ...

When reverting the feature, it tries to revert the node first and then the file. So I tried reverting the file field first, then the node, but still no luck.

There's also a minor E_STRICT warning, but that's really just a coding style thing, and using a temporary variable clears it up:

Strict warning: Only variables should be passed by reference in uuid_file_features_export_render() (line 70 of /var/aegir/platforms/oatest/sites/all/modules/uuid_features/includes/uuid_file.features.inc).
jrao’s picture

Status: Needs work » Needs review
StatusFileSize
new13.43 KB

Revised patch which added null checking to avoid errors when file doesn't exist.

@ergonlogic: The reason it doesn't work with reference in body is because of #2117453: uuid_node doesn't use entity_uuid_load/save to load/save node

discipolo’s picture

Issue summary: View changes
StatusFileSize
new12.73 KB

didnt apply anymore so i rerolled

discipolo’s picture

http://www.php.net/manual/en/language.references.pass.php

to avoid strict php notices we should pass this as a variable since
The following things can be passed by reference:

  • Variables, i.e. foo($a)
  • New statements, i.e. foo(new foobar())
  • References returned from functions
$fileextension = explode('.', $file->filename);
array_pop($fileextension);
chrisgross’s picture

The newest dev version of this module no longer seems to export media field data in features. This worked just fine in alpha4.

ergonlogic’s picture

StatusFileSize
new11.97 KB

Re-rolled the patch from #20 to apply against latest head.

chrisgross’s picture

#24 still results in the following warning when viewing the feature:
Strict warning: Only variables should be passed by reference in uuid_file_features_export_render() (line 74 of /sites/all/modules/contrib/uuid_features/includes/uuid_file.features.inc).

This also seems new:

WD node: EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7783 of /includes/common.inc).[error]
<h1>Uncaught exception thrown in shutdown function.</h1><p>EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7783 of /includes/common.inc).</p><hr />

Adding the files via "file" in features now works in bringing that actual files along, but images are still not being attached to nodes on feature revert. The feature is listed as overridden and wants to remove the image field value from itself because it is empty.

Update: This last part seems to be caused by the fid being inserted in my_feature.features.uuid_node.inc, which makes sense because the file in the feature does not have an fid associated with it. Removing this value and reverting the feature seems to work, so the patch should probably be altered to exclude this value, as the whole point of uuid is so that you don't need an fid. The errors are still present, though.

chrisgross’s picture

The problem seems to be in uuid_node.features.inc:

  // Don't cause conflicts with nid/vid/revision_timestamp/changed fields.
  uuid_features_file_field_export($export, 'node');

  $entity_type = 'node';
  drupal_alter('uuid_entity_features_export_render', $entity_type, $export, $node, $module);
  drupal_alter('uuid_node_features_export_render', $export, $node, $module);

uuid_features_file_field_export() is where the fid stripping occurs, but after this is done, uuid_entity_features_export_render puts them back in the $export variable. Is it safe to simply flip the order of these things? such as in:

  $entity_type = 'node';
  drupal_alter('uuid_entity_features_export_render', $entity_type, $export, $node, $module);
  drupal_alter('uuid_node_features_export_render', $export, $node, $module);

  // Don't cause conflicts with nid/vid/revision_timestamp/changed fields.
  uuid_features_file_field_export($export, 'node');

I don't really know the full implications of this, but it seems to fix the problem. If this is not okay, then the fid stripping functionality needs to reproduced in uuid_entity_features_export_render. There's a lot going on here, and it seems that there might be some redundancy in the code.

Either that, or if these are two different options, there needs to be some logic to determine which to execute.

chrisgross’s picture

So, I just discovered what seem to be hidden UUID Features settings which, combined with the file_entity module (which I was already using), seem to make all of these patches unnecessary, for the dev build of this module as of today. Simply making file entities exportable on admin/structure/features/uuid_features works just fine. no patches to uuid_features necessary. I may just be blind, but the only link I could find to that page is from admin/modules, which is why I didn't see it before and started trying all of these recent patches that seem to be doing nothing but breaking things and causing errors.

If anyone else is in the same boat, I recommend trying these settings and exporting them as well. Solved all my problems.

andypost’s picture

+1 to #26, specific entities should go second

PascalAnimateur’s picture

StatusFileSize
new12.82 KB

Re-rolled #24 against latest -dev to include suggestion from #26.

Seems to work in my case...

PascalAnimateur’s picture

Hrm.. doesn't seem to work against latest uuid / uuid_features with either the base64 / packaged files option.

PascalAnimateur’s picture

First part of the problem solved by fixing the check for exportable file types in includes/uuid_file_entity.features.inc

With this patch, I can see the files under "File Entity" section of the feature creation form, but the actual files are not included in the generated module when packaged in assets (it does get included as inline base64, but the module can get really big).

Getting closer...

Status: Needs review » Needs work

The last submitted patch, 31: uuid_features-check_enabled_file_types-1229670-31.patch, failed testing.

PascalAnimateur’s picture

This new patch works with packaged files in my case. More testing needed though...

socialnicheguru’s picture

conflicts with Usage filter for files

Which is a better approach?

socialnicheguru’s picture

PascalAnimateur’s picture

My previous patch had a problem with missing files in the assets folder, as only the last file would be included.

This is an updated version of this patch, which doesn't address the conflict mentioned by @SocialNicheGuru.

danielveza’s picture

Using the patch in #36 was fantastic! Solved my issue perfectly.

dimaro’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work
zipymonkey’s picture

Not sure if this is the right place for this but I've modified the patch in exclude the user_uuid from the file_entity export. This is causing my feature to always appear overridden when deployed to a different site or environment.

zipymonkey’s picture

#41. This does not fix the issue I'm having.

nelsongrin’s picture

Patch #36 works perfectly!

nelsongrin’s picture

Provided new patch to fix coding standard issues based on patch #36.

nelsongrin’s picture

nelsongrin’s picture

Status: Needs work » Needs review