Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
C
Core
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 920
    • Issues 920
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Operations
    • Operations
    • Incidents
  • Analytics
    • Analytics
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
  • Development
  • Core
  • Issues
  • #335

Closed
Open
Opened Aug 16, 2018 by gharris@gharrisReporter

Warning that $greetingToken is not always an array

When adding Activities to Scheduled Reminders, I came across a couple of warnings coming from core/CRM/Utils/Token.php. (https://lab.civicrm.org/dev/core/blob/master/CRM/Utils/Token.php)

Notice: Undefined index: contact in plugins/civicrm/civicrm/CRM/Utils/Token.php on line 1457

Warning: array_diff(): Argument #1 is not an array in plugins/civicrm/civicrm/CRM/Utils/Token.php on line 1457

According to line 1376, $greetingTokens is not necessarily expected to be an array, but lines 1454 and 1457 do expect it to be an array. Line 1407 looks like it might create an array for $greetingTokens, if you get there. Wrapping if statements around 1454 and 1457 so they look like below does remove the warnings:

    // Remove null contact fields from $greetingTokens
if (!empty($greetingTokens) && array_key_exists('contact', $greetingTokens)) {
    $greetingTokens['contact'] = array_diff($greetingTokens['contact'], $nullFields);
}

    // Also remove them from $tokenString
if (!empty($greetingTokens) && array_key_exists('contact', $greetingTokensOriginal)) {
    $removedTokens = array_diff($greetingTokensOriginal['contact'], $greetingTokens['contact']);
}

However, I expect that's not the correct answer. It seems like $greetingTokens should be treated as an array throughout the file, and an "if" test should be done at the top, converting it to an array if the test is false. However, I'm afraid that's deeper than I can wade.

Originally found while also attempting to diagnose #58

Edited Aug 16, 2018 by gharris
To upload designs, you'll need to enable LFS and have admin enable hashed storage. More information
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: dev/core#335