/**
 * Creates a new block.
 */
function install_add_block($module, $delta, $theme, $status, $weight, $region, $visibility, $pages, $custom, $throttle, $title) {
  db_query("INSERT INTO {blocks} (module, delta, theme, status, weight, region, visibility, pages, custom, throttle, title) VALUES ('%s', '%s', '%s', %d, %d, '%s', %d, '%s', %d, %d, '%s')", $module, $delta, $theme, $status, $weight, $region, $visibility, $pages, $custom, $throttle, $title);
  if ($module == 'block') {
    $box = db_fetch_object(db_query('SELECT * FROM {boxes} WHERE bid=%d', $delta));
    db_query("INSERT INTO {boxes} (bid, body, info, format) VALUES (%d, '%s', '%s', '%s')", $box->bid, $box->body, $box->info, $box->format);
  }
}

note:

    $box = db_fetch_object(db_query('SELECT * FROM {boxes} WHERE bid=%d', $delta));
    db_query("INSERT INTO {boxes} (bid, body, info, format) VALUES (%d, '%s', '%s', '%s')", $box->bid, $box->body, $box->info, $box->format);

Won't $box always contain null values? How can we do a select from boxes before we actually insert into it? :-)

AFAICT, the Wizard only exports the blocks data, and not the actual box content.

Comments

rwohleb’s picture

Version: 5.x-1.x-dev » 5.x-1.1
Component: crud.inc » Profile Wizard
Status: Active » Needs review
StatusFileSize
new2.88 KB

Here is a patch that fixes this functionality. It also fixes an argument order issue between crud.inc and the export code for install_add_block().

dww’s picture

Version: 5.x-1.1 » 6.x-1.x-dev
Component: Profile Wizard » CRUD functions and includes

Marked #312913: Custom block creation duplicate of this, though I think the patch there (http://drupal.org/files/issues/install_profile_api-block.patch) is a cleaner, better approach to this. That patch also needs backporting to D5, which should be pretty easy.

dww’s picture

Assigned: Unassigned » dww
StatusFileSize
new1.91 KB
new2.96 KB

Updated the previously linked patch. I didn't like how it was automatically trying to call install_add_block() since then the caller has no control over the new custom block. I think it's better how Roger López described it in the original issue, instead of how it is in his patch. So, I re-wrote the patch, added better PHPDoc comments, renamed the "$title" argument to "$description" since that's what it really is, and gave $format a default of FILTER_FORMAT_DEFAULT. With this patch, to install a custom block, it's like so:

  $delta = install_create_custom_block($body, $description, $format);
  install_add_block('block', $delta, ...);

Shockingly, for the D5 backport, I had to backport db_last_insert_id(), too. :( {boxes}.bid is auto_increment in D5, too, and there doesn't seem to be any reasonable way to get the bid natively. Using the D5 admin UI, you create the box as 1 form and submit that on its own. Then you can configure it (to give it a title), and finally enable it. So, the D5 API doesn't provide any way to get the bid directly when you add a box. *sigh*

Patches for both D5 and D6. Both tested. Any objections to any of this before I commit?

dww’s picture

Status: Needs review » Fixed

dmitrig01 said this was RTBC, so I committed to DRUPAL-6--1 and DRUPAL-5--2.

Status: Fixed » Closed (fixed)

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