I got
Notice: Undefined index: version in legal_version_check() (line 769 of /home/***/public_html/sites/all/modules/legal/legal.module).

when login using administrator.

on authenticate user login, this not happened

CommentFileSizeAuthor
#3 version-key-notice-1541638-2.patch771 bytesAnonymous (not verified)

Comments

itz_andr3’s picture

I try to debug, this is my first time debuging drupal

function legal_version_check($uid, $version, $revision, $legal_account = array()) {
  if (empty($legal_account)) $legal_account = legal_get_accept($uid);

  if ($legal_account['version'] == $version && $legal_account['revision'] == $revision) {
    $accepted = TRUE;
  }
  else {
    $accepted = FALSE;
  }

  return $accepted;
}

$legal_account is empty when user not accepted any T&C yet,
so $legal_account['version'] and $legal_account['revision'] daon't have any value
this causing error.

Question:
- why error message only showed in admin? is the warning message hidden on original user?
- can isset($legal_account['version']) check used for skipping this error? i try this can worked out

so the code would become:

function legal_version_check($uid, $version, $revision, $legal_account = array()) {
  if (empty($legal_account)) $legal_account = legal_get_accept($uid);

  if (isset($legal_account['version']) && isset($legal_account['revision'])) { 
      if ($legal_account['version'] == $version && $legal_account['revision'] == $revision) {
        $accepted = TRUE;
      }
      else {
        $accepted = FALSE;
      }
	} 
	else {
	  $accepted = FALSE;
	}

  return $accepted;
}

need review

seworthi’s picture

The above solution worked great. I did remove a few if/else with this:

$accepted = FALSE;
if (isset($legal_account['version']) && isset($legal_account['revision'])) {
  if ($legal_account['version'] == $version && $legal_account['revision'] == $revision) {
    $accepted = TRUE;
  }
}
Anonymous’s picture

Title: Notice: Undefined index: version dalam legal_version_check() (line 769 of /home/***/public_html/sites/all/modules/legal/legal.mo » Notice: Undefined index: version in legal_version_check() (line 769)
Version: 7.x-1.2 » 7.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new771 bytes

Seworthi's solution works. I've created the same compact code independently 15 minutes ago. The only difference of my code was to use array_key_exists(), because this is all needed to avoid the PHP notice. It's just a bit more accurate.

Please find the patch against latest dev version attached.

robert castelo’s picture

Status: Needs review » Fixed

Patch #3 committed to dev.

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

translate to english