There are lots of places in the code (variables, function names, database columns) that refer to 'content type' or 'content' when in the D7 world this means entity[*]. Furthermore, the {flag_content} table is now the base table of an entity called 'flagging'. Now is the best time to
The following tables are to be renamed:
* {flags} -> {flag} -- this is to follow the D7 pattern of table names in the singular rather than plural.
* {flag_content} -> {flagging} -- to match the entity that represents this table's data.
Table fields to change:
* content_type -> object_type
* content_id -> object_id
These are also to be changed where they occur in flag object properties, variables, and function names.
[*] Technically, a flag can be applied to any object that is identified with a string for its 'type' and a number for its id. However, the vast majority of cases will involve flagging entities. So while 'object' is technically correct, 'entity' is going to be a better fit and better DX in 90% of cases.
Original post
There are lots of places in the code (variables, function names, database columns) that refer to 'content type' or 'content' when in the D7 world this means entity.
Eg:
- flag_get_content_flags($content_type, $content_id ...
This is going to be hellish, and I'm torn as to whether to do it in 2.x or postpone till 3.x.
Reasons to do in 2.x:
- it's going to be a DX WTF to have to keep saying content types when we mean entity types, and types when we mean bundles.
Reasons to leave till 3.x:
- we would lose parity with the 6.x-2.x branch completely
I guess this might be an argument for doing #1035410: Flag any entity till 3.x, but branching for 3.x sooner rather than later. But that doesn't fix the problem of maintainability: we get two different APIs to maintain, on three branches rather than 2.
Comment | File | Size | Author |
---|---|---|---|
#27 | 1681540.27.flag_.rename-cataclysm.patch | 260.19 KB | joachim |
#22 | 1681540.22.flag_.rename-cataclysm.patch | 254.73 KB | joachim |
#17 | 1681540.17.flag_.rename-cataclysm.patch | 238.5 KB | joachim |
#11 | 1681540.11.flag_.rename-cataclysm.patch | 236.88 KB | joachim |
#8 | 1681540.7.flag_.rename-cataclysm-no-update.single.patch | 136.69 KB | joachim |
Comments
Comment #1
joachim CreditAttribution: joachim commentedSeems it's actually a bit more complicated than this, as flag types can defined on any kind of object -- in fact anything that has an ID that can fit into the table columns in {flags} and {flag_content}.
Comment #2
joachim CreditAttribution: joachim commentedSo probably:
content_type -> object_type
content_id -> object_id
type/ subtype -> ??? keep as subtype but use bundle within the flag_entity class?
content -> object
and also:
{flag_content} -> {flagging}
{flags} -> {flag}
Comment #3
joachim CreditAttribution: joachim commentedComment #4
joachim CreditAttribution: joachim commentedSo before we do this we should try to round up and commit all the issues that make changes to the database schema, because otherwise backporting them will be much more work.
So far I only know of #1650512: Index to improve view performance.
Comment #5
joachim CreditAttribution: joachim commented*sigh*
I'm still debating whether to replace 'content_type' with 'entity_type' or 'object_type':
- 'object_type': Technically, flags can go on anything that cares to declare itself to flags. You could define a flag type on poodles, and provided you output the flag link with the right parameters, the flagging table will just say 'ok you've flagged poodle id 1'. So this is the more correct term to use.
- 'entity_type': *However*, the vast majority of flags are going to be on entities: nodes, terms, users, commerce products and orders, and so on. It would be bumpy DX for all these cases to see 'object_type' here where in the rest of Drupal it's 'entity_type'.
So it boils down to either:
- the correct term which in 90% of cases is going to require a bit of brain-adjustment because they're also going to be entities, or
- the term that's going to look right 90% of the time and require a bit of 'oh I'm flagging poodles and so my entity type is poodle even though they're not really an entity' DX bump for the 10% exceptions.
Put like that, it seems like a no-brainer to go for 'entity_type': the 80-20 rule.
Comment #6
socketwench CreditAttribution: socketwench commentedAgreed.
Comment #7
joachim CreditAttribution: joachim commentedHere's a monster patch. It doesn't yet tackle all of the database updates, so it should only be tried with fresh installs to make sure everything works.
The patch file itself is in git format-patch format, thus a list of all the commits on my local branch. The advantage is that it's easier to follow the changes step by step. Also, we can use the log to write a change record later.
Apply it with 'git am' rather than 'patch', and do so on a local branch rather than 7.x-3.x (or be prepared to reset afterwards, as this will create commits!). (More details on this trick here: http://www.drupaler.co.uk/blog/moving-git-local-branch-one-local-another.)
I'm halfway through writing the column updates, which is fairly hairy and tedious due to all the indexes that have to be dropped and re-created.
Also I'm stumped as to whether/what to rename the 'fcid' column to.
Comment #8
joachim CreditAttribution: joachim commented... I guess the testbot won't like that file. So here's a single patch too.
Comment #9
socketwench CreditAttribution: socketwench commentedWow. That is a monster patch.
The only quibble I can come up with is that "fcid" seem a little obscure given the renaming of the table to "flaggings". The problem is, I can't think of anything better.
Beyond that, it looks good.
Comment #10
joachim CreditAttribution: joachim commentedHold your horses, it still needs the update functions! Thanks for the vote of confidence though! :)
> that "fcid" seem a little obscure given the renaming of the table to "flaggings". The problem is, I can't think of anything better.
Indeed.
I was thinking we take Commerce's pattern and do 'flagging_id'. But I really can't be bothered to change flag.fid to flag.flag_id to match!!!
The other thing is there are a lot of $flagged_content (or is it $flag_content) variables internal to functions. I am wary of changing those to $flagging when they are NOT the loaded entity, but just table row data (or partial rows), as that's a DX WTF. I should check none of these are in hooks or API-ish function definitions, and then leave the rest for follow-up :)
Comment #11
joachim CreditAttribution: joachim commentedOK here's the patch with the update functions.
To apply this you need a git checkout on branch 7.x-3.x and:
$ git co -b 1681540-local-branch
$ git am 1681540.11.flag.rename-cataclysm.patch
I've only tested this on a localhost with a handful of flaggings, so I would *really* appreciate it if someone could test it with some real site data (on a development copy of course!).
Comment #12
joachim CreditAttribution: joachim commented*sigh* I should really do the fcid column too, makes sense to do it now.
Comment #13
joachim CreditAttribution: joachim commented*double sigh* This is going to have to come first so the update function is the same: #1709498: lengths of db columns for entity and bundle names are too short.
Comment #14
socketwench CreditAttribution: socketwench commentedWhich this? #1681540: replace 'content' with 'entity', eg $content_type with $entity_type or #1709498: lengths of db columns for entity and bundle names are too short?
Comment #15
socketwench CreditAttribution: socketwench commentedSomething in one of the recent commits broke the patch. I had to rollback to 142e7589274a6a19bd216ddeb6fb0c23a5d731cf to get it to apply.
After that, I threw it against my local D7 test site, and it seemed to work well.
Comment #16
joachim CreditAttribution: joachim commented> Something in one of the recent commits broke the patch. I had to rollback to 142e7589274a6a19bd216ddeb6fb0c23a5d731cf to get it to apply.
Ah, that was me. I made two commits last night.
I rebased my local branch for this issue and fixed the conflicts but didn't get round to posting a patch.
Thanks for trying it out!
I'll do the fcid -> flagging_id soon.
Comment #17
joachim CreditAttribution: joachim commentedHere's a patch rebased to the current 7.x-3.x, just to keep everyone in the loop :)
Comment #18
socketwench CreditAttribution: socketwench commentedThere we go. That patch applied to the current commit, tests clean.
There was a hiccup with update.php. It tried to rename the flag and flagging tables, but they were already renamed. Might have been my fault.
Comment #19
joachim CreditAttribution: joachim commented> but they were already renamed. Might have been my fault.
Yeah, you need to not just restore the last DB from backup_migrate module, but then ALSO delete manually the renamed tables: B&M does not delete tables it doesn't have in the backup tarball.
Comment #20
socketwench CreditAttribution: socketwench commentedI suppose I should use the backup_migrate module. So far I've just been using a Drupal instance until it breaks, then wiping the DB and starting over. I suppose I could just keep a fresh-install SQL dump.
Comment #21
joachim CreditAttribution: joachim commentedThat approach is fine too -- it's what I tend to do for ongoing development. For this issue though I knew I was going to have to rollback quite a few times.
I was under the impression you're using flag for a live site? Once I've done the fcid rename, could you test the patch with a copy of that?
Comment #22
joachim CreditAttribution: joachim commentedLast patch, I hope.
(This is a patch against ed26176bb6f8a4aea6cc31d54a167a1e97e9b766, one back from the current 7.x.3.x. Testbot will fail.)
Note: I'm not changing the names of views handlers because AFAIK there's no easy way to change a user's existing views to account for this.
Comment #24
joachim CreditAttribution: joachim commented#22: 1681540.22.flag_.rename-cataclysm.patch queued for re-testing.
That was because of the commit from #1689400: make use of machine name field in admin UI. I've just reverted that, so let's test again.
Comment #25
joachim CreditAttribution: joachim commentedIf the testbot agrees, I think we're finally about able to commit this.
What would be great though would be a review from someone with real-world flag data to upgrade (on a test copy of course!).
Comment #26
joachim CreditAttribution: joachim commented> Note: I'm not changing the names of views handlers because AFAIK there's no easy way to change a user's existing views to account for this.
Turns out I'm wrong :)
#1714082: code and docs disagree on renaming of fields.
Comment #27
joachim CreditAttribution: joachim commentedHere's the patch once again with the Views changes too. Should be all done. For real this time! Honest!
Comment #28
socketwench CreditAttribution: socketwench commentedLooks good. I threw it against some deve_generate content and it seemed to work.
Comment #29
joachim CreditAttribution: joachim commentedHooray. Thanks for all your help on this. I'll commit this in the next day or so and we can get moving on other things.
Comment #30
joachim CreditAttribution: joachim commentedIssue #1681540 by joachim: Renamed database tables and columns, properties, functions, and variables to match Drupal 7 entity terminology.
Woohoo!
I merged this in with --no-fast-forward, so we keep the individual commits, should we ever need to go debugging what was changed here.
Comment #31
socketwench CreditAttribution: socketwench commentedAwesome!
Do you think we should use --no-fast-forward more often? It certainly looks useful...
Comment #32
joachim CreditAttribution: joachim commentedFor big, complex issues where we have a local branch that's got clean commits, sure.
For a local branch that's a total mess of changes and clean-ups (as my local branches usually are ;) -- best not ;)
Comment #33
socketwench CreditAttribution: socketwench commentedHeh. I guess I keep my branches quite a bit more tidy than is necessary, or sane. ^_^;
Comment #34
joachim CreditAttribution: joachim commentedOh. Yes. Nearly forgot. This needs a change notification. I'll try and get round to that in the next couple of days.
Comment #35
Orange Studio CreditAttribution: Orange Studio commentedUsing the 7.x-3.x-dev is causing problems with rules
Flag and Un flag works ok except when having a Rule with the event:
A node has been unflagged, under "flag name"
When I try to un flag the node I get the following error message:
RulesEvaluationException: Argument flagging is missing. in RulesPlugin->setUpState() (line 648 of /Applications/MAMP/htdocs/mysite/sites/all/modules/rules/includes/rules.core.inc).
When I disable the rule involved, unflagging works fine
This happens with 7.x-3.x-dev or 7.x-2.x-dev with any of the flag fields patches
Note: Rules with: A node has been flagged, under "flag name" events work ok
Comment #36
joachim CreditAttribution: joachim commentedArgh, rules. Could you file this as a new bug please, and attach the exported rule please?
Comment #37
joachim CreditAttribution: joachim commentedOK, I think this covers it: http://drupal.org/list-changes/flag
Comment #38
Orange Studio CreditAttribution: Orange Studio commented@joachim
Ok, posted in a new issue
http://drupal.org/node/1719942
Thanks
Comment #39.0
(not verified) CreditAttribution: commentedUpdated issue summary.