It would be nice to add relations to content with devel
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | relation-devel-drush-1167024-16.patch | 1.37 KB | clemens.tolboom |
| #10 | relation_generate-1167024-10.patch | 4.38 KB | clemens.tolboom |
| #8 | relation_generate-1167024-8.patch | 4.8 KB | clemens.tolboom |
| #7 | relation_generate_2.patch | 2.57 KB | naught101 |
| #5 | RDF_relation_as_array_2.patch | 2.45 KB | naught101 |
Comments
Comment #1
clemens.tolboomComment #2
naught101 commentedAbsolutely, this would be great. Potentially we'd need to patch devel_generate (See #616160: Extending devel generate), but even then, relations are more complex than the average entity, as they rely on other entities.
That said, what we'd basically need to do, assuming we don't rely on devel_generate:
1. loop over each relation type (assume relation types are already created by the user).
2. For each relation type, get the available endpoint types (checking if the relation type is directional)
3. randomly choose an endpoint type from those available, then do an EFQ with entityOrderBy('RAND()') (if that works)
4. Repeat an n-1 times, where min_arity<=n<=max_arity
5. create the relations.
I'll have a go.
Comment #3
clemens.tolboomFrom the relation.test
and testDropzonePickCreate we can can boil some code to generate this I guess.
Comment #4
naught101 commentedThis basically works for me (without drush integration), although it creates (broken) relations to entity_id 0 sometimes, for some unknown reason.
run
drush ev "relation_generate_relations();"and it'll generate 10 valid relations of what ever relation types you have created.Comment #5
naught101 commentedThis works better. I don't really get why array_rand() returns a key... oh well.
This is still highly inefficient, but it works well enough for development work.
Comment #6
clemens.tolboomPlease merge patch #4 and #5 :-)
Comment #7
naught101 commentedSorry, completely wrong patch.
Comment #8
clemens.tolboomI added a form to /admin/config/development/generate/relation
Works nice but when selecting kill we should add 'x relations deleted' I guess.
Furthermore it's hard to find new relations ... or do I miss a path?
Comment #9
naught101 commentedThanks Clemens! Modified slightly and committed (d99982b). Let's call this fixed, we can revisit if EFQ introduces random ordering.
Comment #10
clemens.tolboomOn an empty database generating relations gives errors.
I added required to relation types fields and checked for generated rids count
I'm not sure whether this test is enough
Comment #11
clemens.tolboomThe patch in #10 is ok when there are no 'Source and Target bundles' defined on ie admin/structure/relation/manage/relation-name
But not when there is no content.
Comment #12
naught101 commentedhrm... maybe just something warning that you need content before making relations? There's always going to be problems if people look for content that does exist though, including taxonomy terms and files, and what ever other entities they've defined as endpoints in their relations..
What can we really do about that? We'd have to do blank EFQ calls to all entity types at the beginning, and blacklist those with no results. Seems a bit expensive.
Comment #13
clemens.tolboom@naught101 : we discussed the creation of relationships through code and ended up with
Why can't we get these relation types into the relation_generate code? We do have entity_get_info() to pop-out a list of entity:bundle combinations right?
Comment #14
chx commentedWhy is this still open? My nice little relation-generate drush command does not work?
Comment #15
clemens.tolboom@chx I didn't knew we had a drush command now for generating relations.
Nice solution moving the code out of relation.admin.inc to relation.drush.inc :)
But we still fail to have a command to generate relation types.
Comment #16
clemens.tolboomAttached patch fixes some args.
Comment #17
clemens.tolboomThe patch still needs review but the test for how many relations created is puzzling me.
Currently doing a
generates 20 relations instead of the default setting of 10. So testing
count($new_rids) == $number_relationsis incorrect. $number_relations is half of count($new_rids).This is due to arity as for each arity a relation is created ... see
Note that min_arity is used twice! So this part I don't get :(
Replacing the error flow by
feels awkward but it is still better when used by
Comment #18
chx commentedSure. That'd be a bug report. As for generating types, I dunno, drush can't generate node types why would it generate relation types?
Comment #19
naught101 commentedNot a bug.
drush genrel 10generates 10 relations for each relation type. You have 2 types defined, so it generates 20 relations.Comment #20
clemens.tolboomPlease apply patch #16 then as that fixed arg defaults. With last remark from #17
Comment #21
naught101 commentedAh, sorry.
This doesn't make much sense as an error message. Shouldn't it be something like "Generated count($new_rids) relations. Should have generated $num_rel"?
Also, status should be "status", not "ok"
Comment #22
clemens.tolboomEhrm ... the status value should be (and was) ok. I added the 'error' and (needed to) fixed the arg for
Fixed argument
I got a message "Generated 10 ..." when these was no generation at all. Because I had no entities and/or relation_types.
Operator == should be changed into >=
This still gives an error if for some reasons no relation is created.
Comment #23
naught101 commentedAh, confusion. drush_log() accepts 'ok', but drupal_set_message() only accepts 'status'
Message should probably just say "generated @numrel relations for each defined relation type." or something then, no?
Is there any reason why it would generate some relations, but not all of them? If not, we probably don't need a numerical comparison, just a "Whoops, relation creation failed"...
Comment #24
clemens.tolboomAh ... now I get it :p
dsm knows 'status', 'warning', 'error' so indeed we need to transform between 'ok' and 'status' depending on the context.
Comment #25
naught101 commentedClosing this as fixed, since the feature has been in for ages. If there are still problems, let's open new issues, this one is confusing.