I'm using Casetracker with Open Atrium.

Problem

Steps:

1. Create group
2. Create case
3. Add a comment to case
3. Create project
4. Resave case*

* Resaving will assign it to the project just created.

In PHP 5.2.1:
warning: preg_match() expects parameter 2 to be string, array given in /var/www/.../includes/bootstrap.inc on line 858.

In PHP 5.3.1:
warning: htmlspecialchars() expects parameter 1 to be string, array given in /var/www/.../includes/bootstrap.inc on line 856.

This error has been reported in several places and it seems at least a few instances are related (or very likely related) to the scenario where you have cases that are created before a project exists.

Other reports:
http://drupal.org/node/1141584
http://drupal.org/node/909334
https://community.openatrium.com/issues/node/2560#comment-7012

Getting rid of the error

I think I may have this figured out. Commenting on a case that has no project will write a record to the {casetracker_comment_status} table with pid = 0. Later on, theme_casetracker_comment_changes() will send $csid with its value set to "0" as an argument to casetracker_case_state_load(), which will then incorrectly return an array. Here's why:

function casetracker_case_state_load($csid = NULL, $realm = NULL, $reset = FALSE) {
  ... // some code
  }
  elseif (!$csid && $realm) {
    $options = array(); // suitable for form api.
    if (!empty($states_lookup[$realm])) {
      foreach ($states_lookup[$realm] as $state) {
        $options[$state->csid] = $state->display;
      }
    }
    return $options;
  }
}

Obviously "0" will pass a check for !$csid. I'll be posting a patch (below) that uses isset() instead. This resolves the error in my case.

Correcting pid in {casetracker_comment_status}

As a closer-to-fail-safe, ideally it would be great if the module could update this table when the case is updated with a project id. In hook_nodeapi() ($op == 'update') I believe we could reference the {comments} table to get our cid (based on case nid) and then update the pid field accordingly. I could submit a separate patch if others agree.

Prevention

It's interesting that users are permitted to create cases when there is no project, even though the module generates the message "You must create a project before adding cases." Unfortunately not everyone pays attention to this message, so I'm often going back and fixing things after the fact.

That said, I've added a couple of lines to the patch which returns drupal_access_denied() (along with the existing message) when users attempt to create a case when there are no projects:

function casetracker_form_alter(&$form, &$form_state, $form_id) {
  if (!empty($form['#node'])) {
    $node = $form['#node'];

    // Add case options to our basic case type.
    if (casetracker_is_case($node->type)) {
      $count = count(casetracker_project_options());
      if ($count == 0) {
        drupal_set_message(t('You must create a project before adding cases.'), 'error');
        // Unset form and return access denied.
        $form = array();
        drupal_access_denied();
      }
      ... // some more code
    }
  }
}

I hope that helps us at least partly resolve this issue!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

othermachines’s picture