We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14567
    • 1 Posts
    Been trying to get a call to runSnippet() working through the MODxAPI library, and I think I’ve found a bug but don’t understand why it hasn’t been noticed before. There is a test in the runSnippet() code, just after running the db query, that was:

    if(!$this->recordCount($result)==1) {
            $row = $this->fetchRow($result);
            $snippet = $this->snippetCache[$row['name']] = $row['snippet'];
            $properties = $this->snippetCache[$row['name']."Props"] = $row['properties'];
    } else {
            $snippet = $this->snippetCache[$snippetName] = "return false;";
            $properties = '';
    }
    


    Seems to me that the conditional is the inverse of what it should be. If the record count is 1, then you want to get the snippet from the database, otherwise you use the ’return false;’ default. Changing the test in this way makes it work for my code too, but I was still a little concerned that I was missing something here. I’m using 0.9.2.1, but I did also check the latest code in svn, and it is still the same.
      • 10487 MODX Staff
      • 1,535 Posts
      Hi john_94501,

      Looks to be a good catch! Could you record it into the bugtracker, I should be able to look at this in a bit more detail tonight.

      I think it’s probably not been an issue for a lot of people as runSnippet() is not a widely-used function in the API, most snippets are cached via the evalSnippets() function which is used during the document parsing process. So, in a lot of runSnippet() cases it would be able to retrieve the snippet from the cache rather than querying the database.

      Thanks,
      Garry

        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com