Closed (fixed)
Project:
Party
Version:
7.x-1.x-dev
Component:
Code
Priority:
Critical
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
31 Oct 2011 at 07:40 UTC
Updated:
4 Jan 2014 at 01:11 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
joachim commentedUpping this. Would be good to have for OOTB hats and party demo site.
Comment #2
joachim commentedTagging.
This is a fairly easy one:
- add a field to hook_schema()
- update function
- add form element for it to the hat form
Comment #3
rerooting commentedWorking on this. This is a really amateur question - what does the update function need to accomplish? I have the other things taken care of. I am assuming it's a function that would add the field column to the table when you run update.php, but I'm too green to know where to look to accomplish this embarassingly simple task.
Comment #4
joachim commentedYou can look at the patch for adding a parent field to hats. Or most core and contrib modules will have at least one update function that adds a field to a table.
Comment #5
rerooting commentedOk here it is so far. I'm still looking around for a simple 'added a new field to this entity so I need this simple update hook example'.
Comment #6
rerooting commentedMaybe this is it? Borrowed from party label update function in party.install .
Comment #7
rerooting commentedOn a secondary note, I should be describing these as party-hat-description-field or something of the like.
Comment #8
rerooting commentedoops! naming it 7005 would conflict with the hat parent field, it should be changed to 7006 or something thereafter. my bad.
Comment #9
joachim commentedNot change field, as we want to add one.
Be sure to check the API docs for functions you're not familiar with: http://api.drupal.org/api/drupal/includes!database!database.inc/function...
You want: http://api.drupal.org/api/drupal/includes!database!database.inc/function...
> oops! naming it 7005 would conflict with the hat parent field, it should be changed to 7006 or something thereafter. my bad.
Yup. But it doesn't matter for testing. I'll make sure the names are all ok when I commit.
But let's say this gets 7006 because it's simpler than #1613440: Give hats a parent hat which is optionally empty and therefore will probably land first.
A few other things in your patch:
- you don't need #required = FALSE
- a textfield should be given a max length (which is possible IIRC) so users don't enter more characters that can be saved
- check your indentation :)
Comment #10
rerooting commentedOk, fixed, alongside the issue of using the new 'lenth' property in the schema ;)
Thanks for the friendly feedback
Comment #11
rlmumfordDo people think this should be a text-area rather than a text field? Or do we want to force these descriptions to be really short?
Comment #12
joachim commented> Do people think this should be a text-area rather than a text field
Could be, I suppose. Taxonomy descriptions are text areas IIRC. But those are meant for public consumption.
But then again, you might want to give a complex description to a hat? If so, we could have a textarea but then it can't be a varchar 255.
But then if they're really long, they'll break the admin UI. What I had in mind here is a brief description. If you want longer, maybe add a textarea field in the Field admin?
Comment #13
rlmumfordSweet that makes sense. Maybe there's a better name for this then? Like 'tagline' or something?
Comment #14
rerooting commentedI think 'description' works fine as a field name for a short description (see: Views UI). For more detail, you might want to use 'help' or 'summary'. This should be fine for now.
Also, with this length, we could potentially fit it into the 'Manage Hats' UI as an additional column? What about that? Might get a little scrunched on smaller displays. We could hide the machine name displays if we wanted to do that.
Comment #15
rlmumfordIn the Content Types system it's a text area, and they fit it in in small grey writing under the Content Type name. Wouldn't it be better to follow this convention?
BTW, thanks for all the work you're putting in rerooting! It's good to have you on board!
Comment #16
joachim commented> we could potentially fit it into the 'Manage Hats' UI as an additional column?
That's the plan :)
Rob's suggestion makes sense too.
Comment #17
rerooting commentedHow about 'brief description'. If folks want a more detailed description they can add a field via the UI (which we are keeping, correct?)
Comment #18
joachim commentedLet's just call it 'description' in the schema and the UI too for now -- we can bikeshed over the UI string some more later....
Comment #19
rlmumfordHere's a patch with the description as a text area. I don't know which one we want to use.
Either way, I'd like this committed quick so we can get #1613440: Give hats a parent hat which is optionally empty in.
Comment #20
rerooting commentedI think we should keep it as a normal text field, since the plan is to put it into admin UI for hats. If we make it that long, it won't fit.
Comment #21
rlmumford255 chars seems really short though, I was just basing it off of the Content types system that has a text area and can cope with longer descriptions. I'm happy to go with a text field for now - especially as for longer descriptions we can add a field. Once it's in we can always change it later.
I'll commit this now.
Comment #22
joachim commentedNow we're aiming towards stable releases, could we be a bit less hasty in committing when we're not yet reached what feels like a decision? :)
I'd be happy to follow the example of node types.
Comment #23
rlmumfordCool! We're in! I made a couple of final tweaks, so the final patch is here. But we're all committed now!
Thanks rerooting! that's gone in under your name.
Comment #24
rlmumfordOh man, I was committing this as you posted. We can roll back? Or make another issue?
I've got two big hunks of work waiting on hat parents though.
Comment #25
rlmumfordMajorly fast decision made on IRC to change this to following the node-types convention.
@rerooting sorry to mess this about a bit. We want to do it quick so we don't have to faff with more update functions. I tried to find you on IRC but couldn't - me and joachim normally hang out on #drupal-crm
Comment #26
rlmumfordHere's the final patch
Comment #27
rerooting commentedoh hey! we should hang out on #drupal-crm, im ususally available as rerooting on #drupal-contrib when I am on IRC.
I was away from the drupal world working on a node.js/titanium project for the past few hours. I'd be glad to get myself and scresante on #drupal-crm regularly since we are becoming more involved with party.
Looks good though, want me to re-roll OOTB hats patch for this new field?
Comment #28
joachim commentedYes please!
Comment #29
joachim commentedThe update totally killed my site:
Error message
PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'base.description' in 'field list': SELECT base.hid AS hid, base.name AS name, base.label AS label, base.description AS description, base.data AS data, base.required AS required, base.status AS status, base.module AS module FROM {party_hat} base WHERE (base.status IN (:db_condition_placeholder_0, :db_condition_placeholder_1, :db_condition_placeholder_2)) ; Array ( [:db_condition_placeholder_0] => 3 [:db_condition_placeholder_1] => 2 [:db_condition_placeholder_2] => 6 ) in EntityAPIController->query() (line 152 of /Users/joachim/Sites/7-drupal/sites/all/modules/contrib/entity/includes/entity.controller.inc).
Admittedly I've had to roll a few updates back and stuff, so I'll try it again on a clean install
Comment #30
rlmumfordHmmm, I had that issue with the patch in number 10 - i assumed it was down to me having rolled back updates and stuff and the hook schema caching being really aggressive.
Comment #31
joachim commentedSlightly different error on a clean install:
Failed: PDOException: SQLSTATE[42000]: Syntax error or access violation: 1101 BLOB/TEXT column 'description' can't have a default value: ALTER TABLE {party_hat} ADD `description` MEDIUMTEXT NOT NULL DEFAULT '' COMMENT 'Some text describing the purpose of the hat'; Array ( ) in db_add_field() (line 2812 of /Users/joachim/Sites/7-drupal/includes/database/database.inc).
Comment #32
rlmumfordIs that a SQL thing? Can TEXT columns not have defaults? If not, how can they be 'not null'?
Comment #33
rerooting commentedI think that the issue has to do with defaults.
http://drupalcode.org/project/drupal.git/blob/refs/heads/7.x:/modules/no... for example
Comment #34
joachim commented> Note that type 'text' and 'blob' fields cannot have default values.
http://drupal.org/node/146939.
Comment #35
joachim commentedShould be fixed.
Can someone test it?
Comment #36
rlmumfordI just got this error again when running the update.
PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'base.description' in 'field list': SELECT base.hid AS hid, base.name AS name, base.label AS label, base.description AS description, base.data AS data, base.required AS required, base.status AS status, base.module AS module FROM {party_hat} base WHERE (base.status IN (:db_condition_placeholder_0, :db_condition_placeholder_1, :db_condition_placeholder_2)) ; Array ( [:db_condition_placeholder_0] => 3 [:db_condition_placeholder_1] => 2 [:db_condition_placeholder_2] => 6 ) in EntityAPIController->query() (line 152 of /home/deva/public_html/sites/all/modules/entity/includes/entity.controller.inc
Comment #37
rlmumfordOk, so you only that error if you try and upgrade 7005 and 7006 at the same time. Because hook_schema has already been updated, the entity_load and party_hat_save methods both look for a description column when loading and saving the Party Hats.
However, only running 7006 gives a different error.
I guess this is because we have a NOT NULL text field, but then don't put a value in it (for all the hats that already exist in the database) I guess the simple solution is to make description not NOT NULL.
Comment #38
joachim commentedUrgh.
> the simple solution is to make description not NOT NULL.
Yup.
> Ok, so you only that error if you try and upgrade 7005 and 7006 at the same time
Let's file a different issue for that.
ARGH party is broken :(
Comment #39
joachim commentedHuh?
node_schema:
So how does that manage to be NOT NULL and not have a default???
Comment #40
joachim commentedHang on...
> CHANGE `description` `description` MEDIUMTEXT NOT NULL
You sure you weren't re-running the update? Why would it do a CHANGE?
Normally that would be 'ALTER TABLE tablename ADD newfieldname ...'
Comment #41
rlmumfordhttp://api.drupal.org/api/drupal/includes%21database%21mysql%21schema.in...
When something is 'NOT NULL' drupal seems to always run that as a changeField later. I don't know why. This also explains why the field gets created when the update runs.
I guess cos It's a core module they haven't had to worry about update hooks adding this field to a table that doesn't already exist.
Comment #42
rlmumfordAlso, we just hit something similar when saving a Party Hat. We'll need to add something to the save() method to atleast set description as an empty string, otherwise you'll get errors on save. Alternatively, we can make description not NOT NULL
Comment #43
rerooting commentedYeah, maybe not null => true is what we want.
See what our friends at profile2 did with a text field:
http://drupalcode.org/project/profile2.git/blob/refs/heads/7.x-1.x:/prof...
I don't think we can set a default value such as '' like we can with a varchar.
Comment #44
rlmumfordFollowing profile2's pattern seems like a good idea to me.
Comment #45
joachim commentedWhich profile2 db field do you mean? The only one I see is 'data' and that's serialized.
Comment #46
rlmumfordOh yeah, I didn't read that properly
Comment #47
rlmumfordHere's a patch that should mean every PartyHat object has a description. this should allow us to keep the NOT NULL on description.
We may also want to check whether the description field is null inside PartyHat->save()
Comment #48
rlmumfordOk, I just pushed this (I fixed the white-space error first). Tested it out and it seemed to fix saving a party.
Comment #49
joachim commented> Here's a patch that should mean every PartyHat object has a description. this should allow us to keep the NOT NULL on description.
You've lost me now.
I thought the problem was with updates.
What does patch 47 do?
Comment #50
rlmumfordIf you programmatically create a Party Hat and saved it without explicitly giving a discription, the save would fail.
Comment #51
rerooting commentedThis should work as of a while ago, or so it seems:
#392696: Save default values on insert
Looking into this further...
Comment #52
joachim commentedFollow-ups:
- UI: #1437272: Provide a description entity key especially for use with exportable entites (e.g. as seen in node types)
- WTF?? #1692446: hat description not loaded into hat