We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Error in mod.channel.php search

Developer Preview

Brian Litzinger's avatar
Brian Litzinger
693 posts
7 years ago
Brian Litzinger's avatar Brian Litzinger

It looks like if a query id is found it is passing the full query string to the generateSQLForEntries() method instead of an array. Basically $query_parts[‘entries’] is a full sql string. Looks like it should be an array of entry ids based on what generateSQLForEntries is attempting to do.

https://www.dropbox.com/s/xfccb79b16igbxz/Screenshot 2017-11-21 09.06.03.png?dl=0

Warning
Illegal string offset 'entries'

ee/EllisLab/Addons/search/mod.search.php, line 1228

    Severity: E_WARNING

Warning
Illegal string offset 'channel_ids'

ee/EllisLab/Addons/search/mod.search.php, line 1228

    Severity: E_WARNING


( ! ) TypeError: Argument 1 passed to Channel::generateSQLForEntries() must be of the type array, string given, called in /var/www/html/system/ee/EllisLab/Addons/search/mod.search.php on line 1228 in /var/www/html/system/ee/EllisLab/Addons/channel/mod.channel.php on line 2333
Call Stack
# Time Memory Function Location
1 0.0049 367608 {main}( ) .../index.php:0
2 0.1344 369800 require_once( '/var/www/html/system/ee/EllisLab/ExpressionEngine/Boot/boot.php' ) .../index.php:172
3 0.1549 482512 EllisLab\ExpressionEngine\Core\Core->run( ??? ) .../boot.php:146
4 0.1609 572696 EllisLab\ExpressionEngine\Core\Core->runController( ??? ) .../Core.php:109
5 0.6023 2136112 call_user_func_array:{/var/www/html/system/ee/EllisLab/ExpressionEngine/Core/Core.php:229} ( ???, ??? ) .../Core.php:229
6 0.6023 2136504 EE->index( ??? ) .../Core.php:229
7 0.6023 2136504 EE_Core->generate_page( ) .../ee.php:62
8 0.6155 2232152 EE_Template->run_template_engine( ???, ??? ) .../Core.php:657
9 0.6155 2232152 EE_Template->fetch_and_parse( ???, ???, ???, ???, ??? ) .../Template.php:162
10 0.6182 2248848 EE_Template->parse( ???, ???, ???, ??? ) .../Template.php:229
11 0.6402 2359008 EE_Template->tags( ) .../Template.php:545
12 0.6617 2376696 EE_Template->process_tags( ) .../Template.php:1449
13 0.6637 2383176 Search->search_results( ) .../Template.php:1810
14 279.0143 2672824 Channel->generateSQLForEntries( ???, ??? )
       
Brian Litzinger's avatar
Brian Litzinger
693 posts
7 years ago
Brian Litzinger's avatar Brian Litzinger

It looks like the signature of the channel_search_modify_search_query hook has changed. Instead of returning an sql string it should return an array. If that is the case then this bit of code may need to be updated:

if (ee()->extensions->active_hook('channel_search_modify_search_query') === TRUE)
   {
    $modified_sql = ee()->extensions->call('channel_search_modify_search_query', $sql, $this->hash);

    // Make sure its valid
    if (is_string($modified_sql) && $modified_sql != '')
    {
     $sql = $modified_sql;
    }

    // This will save the custom query and the total results to exp_search
    if (ee()->extensions->end_script === TRUE)
    {
     $query = ee()->db->query($sql);

     if ($query->num_rows() == 0)
     {
      return FALSE;
     }

     $this->num_rows = $query->num_rows();

     return $sql;
    }
   }
       
Seth Barber's avatar
Seth Barber
172 posts
7 years ago
Seth Barber's avatar Seth Barber

I’ve got a potential fix for you. Try replacing that hook call in mod.search.php with:

if (ee()->extensions->active_hook('channel_search_modify_search_query') === TRUE)
{
 $modified_sql = ee()->extensions->call('channel_search_modify_search_query', $sql, $this->hash);

 // Make sure its valid
 if (is_string($modified_sql) && $modified_sql != '')
 {
  $sql = $modified_sql;
 }

 // This will save the custom query and the total results to exp_search
 if (ee()->extensions->end_script === TRUE)
 {
  $query = ee()->db->query($sql);

  if ($query->num_rows() == 0)
  {
   return FALSE;
  }

  $this->num_rows = $query->num_rows();

  $return = array(
   'entries' => array(),
   'channel_ids' => array(),
   'end' => ''
  );

  foreach ($query->result_array() as $row)
  {
   $return['entries'][] = $row['entry_id'];
   $return['channel_ids'][] = $row['channel_id'];
  }

  $return['channel_ids'] = array_unique($return['channel_ids']);

  if (stripos($sql, ' ORDER BY ') !== FALSE)
  {
   list($before, $end) = explode(' ORDER BY ', $sql);
   $return['end'] = ' ORDER BY ' . $end;
  }

  return $return;
 }
}

Let me know if that resolves the issue.

       
Brian Litzinger's avatar
Brian Litzinger
693 posts
7 years ago
Brian Litzinger's avatar Brian Litzinger

I think that does it, thanks for the quick fix!

Its also EE3 and EE4 compatible from the add-on dev’s side of things. ?

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.