Rework block.module for the new data api

zoo33 - August 31, 2008 - 13:34
Project:Drupal
Version:7.x-dev
Component:block.module
Category:task
Priority:normal
Assigned:Unassigned
Status:duplicate
Issue tags:DBTNG Conversion
Description

Here is an uncomplete patch from the code sprint! Uncomplete as I have to get som air and then go to the airport, and I need some help on a few parts. I did test everything that I changed though, and I think everything is running as it should.

All parts that are either not ported yet or have other problems are marked with TODO:.

– In block_user() and _block_load_blocks() there are two dynamic queries with joins that I can't convert without either some more documentation or some more help.

– block_admin_display_form_submit() isn't working.

I'll try to finish the rest of the trivial stuff on the train. So long!

AttachmentSizeStatusTest resultOperations
block-module-db-rewrite.patch9.46 KBIdleFailed: Failed to apply patch.View details | Re-test

#1

zoo33 - November 12, 2008 - 21:34

OK, block_admin_display_form_submit() wasn't working simply because I had left out execute().

More thougths:

Crell says we should the default object fetch mode as much as possible. There are at least two places in this patch where I override that and use arrays, since it seemed like a pretty big job to change every occurrence of the retrieved variable from arrays to objects ($box and $old_block). So I wanted to check first to see if people think we should actually do that.

Also:

Since there are still few examples to look at I'm not sure how to format this code: chained method calls, wrapping long statements etc. I seem to remember Crell showing something similar to this:

<?php
db_update
('blocks')->fields(array(
 
'status' => $block['status'],
 
'weight' => $block['weight'],
 
'region' => $block['region'],
))->
condition('module', $block['module'])->condition('delta', $block['delta'])->condition('theme', $block['theme'])->execute();
?>

...or even:

<?php
db_update
('blocks')->fields(array(
 
'status' => $block['status'],
 
'weight' => $block['weight'],
 
'region' => $block['region'],
))->
condition(
 
'module',
 
$block['module']
)->
condition(
 
'delta',
 
$block['delta']
)->
condition(
 
'theme',
 
$block['theme']
)->
execute();
?>

The fields array works good this way I think, but I don't particularly like the condition() clutter in any of these two examples. Thoughts?

I'll be back later with an updated patch.

#2

zoo33 - September 3, 2008 - 20:48

Ah, so this it probably what we should do:

<?php
db_update
('blocks')->fields(array(
 
'status' => $block['status'],
 
'weight' => $block['weight'],
 
'region' => $block['region'],
))->
condition('module', $block['module'])
  ->
condition('delta', $block['delta'])
  ->
condition('theme', $block['theme'])
  ->
execute();
?>

Wasn't aware of that possibility. Looks a lot better.

#3

zoo33 - September 3, 2008 - 23:36
Status:needs work» needs review

Here comes a new patch. All tests pass!

It's been pretty easy to port this moule once I got the hang of it.

Just a couple of questions (as above):
– is db_last_insert_id() used in the new API?
– are there any query results that should be converted to objects (instead of using PDO::FETCH_ASSOC)?
– coding style OK?

AttachmentSizeStatusTest resultOperations
block-module-db-rewrite.patch12.11 KBIdleFailed: Failed to apply patch.View details | Re-test

#4

zoo33 - September 3, 2008 - 23:46

Oh, and of course, there are still two complicated dynamic queries marked TODO.

#5

Anonymous (not verified) - November 11, 2008 - 20:55
Status:needs review» needs work

The last submitted patch failed testing.

#6

zoo33 - November 15, 2008 - 13:21
Status:needs work» needs review

Greetings from Drupalcamp Copenhagen!

Here is a new patch which is updated to reflect recent changes in HEAD, such as changed table names.
I also had to add a couple of (int) casts as PDO was complaining about wrong data types.

The TODO items are still there.

AttachmentSizeStatusTest resultOperations
block-302263-db_tng.patch12.15 KBIdleFailed: Failed to install HEAD.View details | Re-test

#7

Anonymous (not verified) - November 15, 2008 - 13:35
Status:needs review» needs work

The last submitted patch failed testing.

#8

zoo33 - March 8, 2009 - 02:26

#9

moshe weitzman - May 27, 2009 - 23:32

Add tag. I would like to see a tag on the key queries for loading blocks so that modules can alter the query. That means using db_select() instead of db_query().

#10

Berdir - May 28, 2009 - 10:32
Status:needs work» duplicate

Closing as duplicate of #337212-10: DBTNG: Block module. That one also contains a block_load tag for loading query...

 
 

Drupal is a registered trademark of Dries Buytaert.