Hi,
I have been working on providing devel generate support for media.
To start with, i have added in support for image types and have been able to get it working to large extent.
Images get generated, they do get assigned to relevant nodes, however i also get the following warnings

Notice: Undefined property: stdClass::$status in media_save_attached_file() (line 959 of /Applications/XAMPP/xamppfiles/htdocs/di/sites/all/modules/contrib/media/media.module).
Notice: Undefined property: stdClass::$fid in file_usage_list() (line 616 of /Applications/XAMPP/xamppfiles/htdocs/di/includes/file.inc).
Notice: Undefined property: stdClass::$fid in media_file_delete() (line 392 of /Applications/XAMPP/xamppfiles/htdocs/di/sites/all/modules/contrib/media/media.module).
Notice: Undefined property: stdClass::$fid in user_file_delete() (line 877 of /Applications/XAMPP/xamppfiles/htdocs/di/modules/user/user.module).
Notice: Undefined property: stdClass::$fid in file_delete() (line 1236 of /Applications/XAMPP/xamppfiles/htdocs/di/includes/file.inc).
Notice: Undefined property: stdClass::$fid in file_delete() (line 1237 of /Applications/XAMPP/xamppfiles/htdocs/di/includes/file.inc).
Notice: Undefined property: stdClass::$fid in user_file_delete() (line 877 of /Applications/XAMPP/xamppfiles/htdocs/di/modules/user/user.module).
Notice: Undefined property: stdClass::$fid in file_delete() (line 1236 of /Applications/XAMPP/xamppfiles/htdocs/di/includes/file.inc).
Notice: Undefined property: stdClass::$fid in file_delete() (line 1237 of /Applications/XAMPP/xamppfiles/htdocs/di/includes/file.inc).

After reading through code and inline documentation within code, i understand the above warnings are something to do with how file_usage table is used by media. However with my limited knowledge of the full media framework structure, i am finding difficult to fix the errors.

Attached is the first cut of work i have done so far. Appreciate your help and feedback

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Ravi.J’s picture

FileSize
1.84 KB

previous attached file is not right, Here is updated accurate file. Thanks for the help

rickvug’s picture

Attached is Ravi's work in patch form (no modifications made).

rickvug’s picture

Status: Active » Needs review
FileSize
1.5 KB

Attached is a different version of the patch. It does not try to generate files for usage so it is assumed that files will already be available to be referenced. Admittedly EntityFieldQuery() is new to me so some of query code is borrowed from elsewhere in Media. This certainly needs a good review and testing in a variety of circumstances. Caching of the allowed values would be helpful for speed. It could also be worth while to look at optionally generating files for reference. Finally note that this patch is against the last beta. It should be simple to adapt to dev however.

Status: Needs review » Needs work

The last submitted patch, 1198820-media-devel-generate2.patch, failed testing.

rickvug’s picture

Status: Needs work » Needs review

#3: 1198820-media-devel-generate2.patch queued for re-testing.

Ravi.J’s picture

I have got the patch from 1-2 approach to work, turned out to be a very minor change. I was trying to do a _media_save_permanent before doing file_save.

Ravi.J’s picture

Just so that its clear
#5 works perfectly well, takes the approach of using existing images
#6 Generates images on the fly and them assigns them to media.

SebCorbin’s picture

Status: Needs review » Reviewed & tested by the community

#6 1198820-media-devel-generate3.patch worked fine for me

aaron’s picture

Status: Reviewed & tested by the community » Needs work

great work on this! the only problem i see is with the non-standard hook you're implementing. firstly, if someone decides to create a media_image module, this would conflict with that module, not only disallowing its own version of the hook, but actually unintentionally calling the function twice. additionally, at some point down the road, media will most likely allow for module or user-defined media types. which will cause similar problems, for instance, with youtube or flickr.

i would suggest we create a new hook in the standard drupal way, such as hook_media_devel_generate.

aaron’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev

changing version

slashrsm’s picture

Patch #6 works fine, but when I generate content during install process i get strange errors:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 'uri': INSERT INTO {file_managed} (filesize, status, timestamp, type) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array
(
    [:db_insert_placeholder_0] => 0
    [:db_insert_placeholder_1] => 1
    [:db_insert_placeholder_2] => 1311840567
    [:db_insert_placeholder_3] => default
)

I did a bit of debugging and it looks like $file gets a really strange value after file_move() at line 65:

stdClass Object
(
    [is_new] => 1
    [name] => 
    [status] => 1
)

Temporary object $source looks fine though:


stdClass Object
(
    [uri] => temporary://imagefield_afYOyq.png
    [uid] => 1
    [filemime] => image/png
)

Any idea?

rerooting’s picture

It's been a while on this, wondering if a fix has been committed or if this is still a hanging issue.

Tried this a patch to devel_generate here http://drupal.org/node/1589056#comment-6013772 and it didn't seem to take care of it, at least for media 2.x-dev.

Any news on this front? Should I try this patch as well? Does this technically fall within the perview of media folks or devel folks?

bobodrone’s picture

Status: Needs work » Needs review
FileSize
5.37 KB

I have rewritten the patch due to the fact that for this to work, it nowdays need to be put in the mediafield directory and be renamed. In devel_generate it tries to include this file under the module name "mediafield" and "media"... doesnt work then.

I have extended the module to work with any source of images, for example the Lorempixel service.

/ bobodrone

Status: Needs review » Needs work

The last submitted patch, 1198820-mediafield-devel-generate4.patch, failed testing.

bobodrone’s picture

Minor typo. New try.

bobodrone’s picture

Status: Needs work » Needs review

And redo for test.

rerooting’s picture

Doesn't work with default image provider nor does it work with devel_image_provider and lorempixum or flickrholdr submodules. I am testing it against the latest media 2.x-dev

rerooting’s picture

can't get it to work with lorempixel module either. no errors or debug output. i will try on a simpler sandbox here in a sec.

rerooting’s picture

meu error, it works on a clean install with your lorempixel module! awesome. i like your lorempoxel module better :)

rerooting’s picture

Funny, without the lorempixel module I keep getting this error:

Fatal error: Call to undefined function _lorempixel_devel_generate_image() in [...]/modules/media/modules/mediafield/mediafield.devel_generate.inc on line 33

This is after disabling, uninstalling and even removing the codebase. However, I cannot find this function or any reference to lorempixel in the file at all.

rerooting’s picture

Status: Needs review » Reviewed & tested by the community

Very strange! After I did a full reinstall on mediafield, I was able to swap out and use this with the default devel image provider, as well as both the devel_image_provider and lorempixel modules. I will see if I can reproduce the error above, but it seems like everything should be ok!

After subjecting it to a battery of tests, I would say that this patch works.

bobodrone’s picture

Hi, the trick behind this is to let devel generate to use a variable (Instead of hook function for now) to decide which of the callbacks are going to be used for image creation.

In mediafield.devel_generate there is a variable_get('devel_generate_media_file_function') in which my module Lorempixel MIGHT have stored its own callback function. If not it should use the default mediafield callback function for generating images.

It works for me but if you have this problem again, just report it and we will see what it can be. It has probably something to do with either that after you applied the patch you MUST clear the cache, or that the variable above is not set yet. To verify this, uncheck the chechbox in lorempixel and save and recheck it again and save.

b.r
/ bobodrone

rerooting’s picture

Indeed, clearing the cache was the issue. This is a really innovative approach to the problem. Really love the work, thanks! (apologies for the torrent of comments...)

aaron’s picture

ParisLiakos’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/modules/mediafield/mediafield.devel_generate.incundefined
@@ -0,0 +1,133 @@
+<?php
+define('MEDIA_DEVEL_GENERATE_IMAGE_MAX', 5);
+/**
+ * Implements hook_devel_generate

Please add some space between lines here.
Also a @file doc block

+++ b/modules/mediafield/mediafield.devel_generate.incundefined
@@ -0,0 +1,133 @@
+      $function = "mediafield_" .$type ."_devel_generate";

Use spaces next to dots.
eg . instead of ..
Also whats the point on using double quotes here if you just concatenate the variable. Use single ones instead

+++ b/modules/mediafield/mediafield.devel_generate.incundefined
@@ -0,0 +1,133 @@
+        return $function($object, $field, $instance, $bundle, $settings);

Why return here? This stops the foreach, which leads to only one function called. The first found.

+++ b/modules/mediafield/mediafield.devel_generate.incundefined
@@ -0,0 +1,133 @@
+ * Implements media_<type>_devel_generate

Implements media_TYPE_devel_generate().

+++ b/modules/mediafield/mediafield.devel_generate.incundefined
@@ -0,0 +1,133 @@
+  // To let other modules generate media/image files instead of the standard file function.

I guess "To" is not needed here. Just "Let"

+++ b/modules/mediafield/mediafield.devel_generate.incundefined
@@ -0,0 +1,133 @@
+ * @return <type>

Fix or remove. return is boolean

+++ b/modules/mediafield/mediafield.devel_generate.incundefined
@@ -0,0 +1,133 @@
+    else {
+      return FALSE;
+    }

This is not needed

anandkp’s picture

TLDR: Skip this comment... ;o)

Sorry but the coding in this is way beyond me, it's a nice to have thing and so I'm hoping to get the attention of those working on it...

So, Bump... Cheers!

queenvictoria’s picture

I'm chasing my tail on this one. I've chased devel_generate all the way to the end on the patch in this thread only to discover that because I'm using the File field (not mediafield) this method will never fire.

Surely as mediafield is deprecated this effort should be abandoned? Please let me know if I'm wrong. It seems to me that we should pursue this thread instead http://drupal.org/node/1589056 (that one references this one).

Mediafile deprecated here
http://drupal.org/node/1324316
and here
http://drupal.org/node/1349058

Effort to hook in to file.devel_generate here
http://drupal.org/node/1589056
and here
http://drupal.org/project/devel_image_provider

timbrandin’s picture

This could be of intrest to read, for us to get to the goal with this issue.
https://drupal.org/node/2011776

discipolo’s picture

Title: Support for Devel Generate » Support for Devel Generate in deprecated mediafield

changing title because this patch is only concerned with the deprecated mediafield and not file fields with media widget.

steinmb’s picture

Status: Needs work » Closed (won't fix)

As mention above. Mediafile is deprecated so I think it is OK to close this.