We are currently passing a TRUE/FALSE boolean to hook_field_storage_write(). I'd much rather see FIELD_STORAGE_INSERT and FIELD_STORAGE_UPDATE defined constants.

Comments

venkatd’s picture

StatusFileSize
new1.11 KB

I defined FIELD_STORAGE_UPDATE to be TRUE and FIELD_STORAGE_INSERT to be FALSE.

I wasn't sure whether the constants should be defined as integers or if it would be better to keep the constants the same.

jkitching’s picture

Status: Active » Needs review
StatusFileSize
new1.65 KB

Just wanted to fill a simple patch to figure out CVS commands and the process for posting one up here.

I wasn't entirely sure where the constant definitions were supposed to go, but all of the others were in field.module so I put them there.

venkatd’s picture

Status: Needs review » Active
StatusFileSize
new3.12 KB

I made a new version of the patch that makes use of the constants throughout the module.

bjaspan’s picture

Status: Active » Needs work

Thanks for the patch! Review:

* The INSERT and UPDATE constants are really just unique identifiers. In other languages they would be an "atom." They do not really correspond to TRUE and FALSE. So, I'd suggest just defining them as strings for themselves, e.g. define(INSERT, 'INSERT'). Then, code can check if ($op == INSERT).

* Add a PHPdoc block for each constant explaining what it is for. See field.module for an example. Make sure the PHPdoc is in the same @defgroup as the function(s) that use the constants so they show up on the same page at api.drupal.org.

* Since hook_field_storage_write() always needs to know whether it is an insert or an update, there is probably no benefit to having a default value for the argument. Just make it mandatory and always provide one value or the other.

* In field_sql_storage_field_storage_write(), you changed the $update argument to $op but then did not change the body of the function to use $op instead of $update. Running the unit tests would have revealed this mistake.

Keep it coming! :-)

venkatd’s picture

StatusFileSize
new4.3 KB

Made some changes. Now the defines have been moved to field.module. Now, FIELD_STORAGE_INSERT = 'insert' and FIELD_STORAGE_UPDATE = 'update'.

Fixed my mistake of not renaming $update.

Not sure if I did the @defgroup thing right. Also, my localhost Field SimpleTests are running out of memory so I haven't tested these changes either.

bjaspan’s picture

Hi. Here is my second-round review. Note that I am asking you to make these changes instead of making them myself in order to help you learn how to do core patches, not because I'm trying to be annoying. :-)

* @defgroup field_storage is at the top of field.attach.inc. But these defines there instead of a separate defgroup.

* You are passing FIELD_STORAGE_UPDATE from field_attach_insert(). This turns out to work because it just causes an extra db_delete() that has nothing to delete, but is still wrong.

* If you set a patch to status "Code Needs Review", the testbot will run all core tests with your patch applied for you.

venkatd’s picture

StatusFileSize
new3.92 KB

Thanks for the review!

Here's yet another attempt.

yched’s picture

- if ($op == 'update') { should be if ($op == FIELD_STORAGE_UPDATE) { now

- Minor :

+ * This is used in hook_field_storage_write when updating to an 
+ * existing object.

should probably be "when updating an existing object".

venkatd’s picture

StatusFileSize
new3.92 KB

Did the $op == 'update' to $op == FIELD_STORAGE_UPDATE change.

Reworded the $op comments as suggested.

Edit: Oops! I forgot to set the status to "code needs review."

bjaspan’s picture

Status: Needs work » Reviewed & tested by the community

RTBC.

Status: Reviewed & tested by the community » Needs work

The last submitted patch failed testing.

bjaspan’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new4.55 KB

Re-rolled from docroot.

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.