Fork me on GitHub

pnsearchapi -- still not fixed ooof!  Bottom

  • So I am still working on this and I thought I solved the problem, but alas I did not. Increasing the memory on the prouduction server did not fix it. The problem is that trying to have Zikula search the content of a book in the Book module, causes a fatal error. Here is the search code for this module.....

    Code

    function book_searchapi_search($args)
    {
       
        pnModDBInfoLoad('Search');
        $pntable = pnDBGetTables();
        $booktable = $pntable['book'];
        $bookcolumn = $pntable['book_column'];
        $searchTable = $pntable['search_result'];
        $searchColumn = $pntable['search_result_column'];

        $where = search_construct_where($args,
                                        array($bookcolumn['title'],
                                              $bookcolumn['contents']),
                                                $bookcolumn['lang']);
       
        $sessionId = session_id();

        $insertSql =
    "INSERT INTO $searchTable
      ($searchColumn[title],
       $searchColumn[text],
       $searchColumn[extra],
       $searchColumn[module],
       $searchColumn[created],
       $searchColumn[session])
    VALUES "
    ;

        pnModAPILoad('Book', 'user');

        $permChecker = new book_result_checker();
        $stories = DBUtil::selectObjectArrayFilter('book', $where, null, null, null, '', $permChecker, null);

        foreach ($stories as $story)
        {
              $sql = $insertSql . '('
                     . '\'' . DataUtil::formatForStore($story['title']) . '\', '
                     . '\'' . DataUtil::formatForStore($story['contents']) . '\', '
                     . '\'' . DataUtil::formatForStore($story['art_id']) . '\', '
                     . '\'' . 'Book' . '\', '
                     . '\'' . '' . '\', '
                     . '\'' . DataUtil::formatForStore($sessionId) . '\')';
              $insertResult = DBUtil::executeSQL($sql);
              if (!$insertResult) {
                  return LogUtil::registerError (_GETFAILED);
              }
        }
        return true;
    }


    This code will work just fine on my local server, but fails on the production server. I was able to replicate the problem on my local machine by setting the memory limit to 8M, and increasing it back fixed it. However, when I tried setting the local memory limit to 32M on my production server, it still failed. If I turn debugging on, this is what I get as a readout.

    Code

    Exit-Handler: Invalid table-key [faqanswer] passed to _getAllColumns
    Stacktrace:

       1. (array) 0:
             1. (string) file = /home/virtual/site9/fst/var/www/html/includes/pnobjlib/DBUtil.class.php
             2. (integer) line = 379
             3. (string) function = pn_exit
             4. (array) args:
                   1. (string) 0 = Invalid table-key [faqanswer] passed to _getAllColumns
       2. (array) 1:
             1. (string) file = /home/virtual/site9/fst/var/www/html/includes/pnobjlib/DBUtil.class.php
             2. (integer) line = 350
             3. (string) function = _getallcolumns
             4. (string) class = dbutil
             5. (string) type = ::
             6. (array) args:
                   1. (string) 0 = faqanswer
                   2. (null) 1 = (none)
       3. (array) 2:
             1. (string) file = /home/virtual/site9/fst/var/www/html/includes/pnobjlib/DBUtil.class.php
             2. (integer) line = 1475
             3. (string) function = _getselectallcolumnsfrom
             4. (string) class = dbutil
             5. (string) type = ::
             6. (array) args:
                   1. (string) 0 = faqanswer
                   2. (string) 1 = WHERE ( ( LIKE '%atp%' OR LIKE '%atp%'))
                   3. (string) 2 = ORDER BY faqid
                   4. (null) 3 = (none)
       4. (array) 3:
             1. (string) file = /home/virtual/site9/fst/var/www/html/modules/FAQ/pnsearchapi.php
             2. (integer) line = 62
             3. (string) function = selectobjectarray
             4. (string) class = dbutil
             5. (string) type = ::
             6. (array) args:
                   1. (string) 0 = faqanswer
                   2. (string) 1 = ( ( LIKE '%atp%' OR LIKE '%atp%'))
                   3. (string) 2 = faqid
                   4. (integer) 3 = 1
                   5. (integer) 4 = -1
                   6. (string) 5 =
                   7. (array) 6:
                         1. (array) 0:
                               1. (integer) realm = 0
                               2. (string) component_left = FAQ
                               3. (string) instance_left = faqid
                               4. (string) instance_right =
                               5. (integer) level = 200
       5. (array) 4:
             1. (string) file = /home/virtual/site9/fst/var/www/html/includes/pnMod.php
             2. (integer) line = 670
             3. (string) function = faq_searchapi_search
             4. (array) args:
                   1. (array) 0:
                         1. (string) q = atp
                         2. (string) searchtype = AND
                         3. (string) searchorder = newest
                         4. (integer) numlimit = 20
                         5. (integer) page = 1
                         6. (integer) startnum = 1
       6. (array) 5:
             1. (string) file = /home/virtual/site9/fst/var/www/html/includes/pnMod.php
             2. (integer) line = 633
             3. (string) function = pnmodfuncexec
             4. (array) args:
                   1. (string) 0 = FAQ
                   2. (string) 1 = search
                   3. (string) 2 = search
                   4. (array) 3:
                         1. (string) q = atp
                         2. (string) searchtype = AND
                         3. (string) searchorder = newest
                         4. (integer) numlimit = 20
                         5. (integer) page = 1
                         6. (integer) startnum = 1
                   5. (boolean) 4 = 1
       7. (array) 6:
             1. (string) file = /home/virtual/site9/fst/var/www/html/system/Search/pnuser.php
             2. (integer) line = 356
             3. (string) function = pnmodapifunc
             4. (array) args:
                   1. (string) 0 = FAQ
                   2. (string) 1 = search
                   3. (string) 2 = search
                   4. (array) 3:
                         1. (string) q = atp
                         2. (string) searchtype = AND
                         3. (string) searchorder = newest
                         4. (integer) numlimit = 20
                         5. (integer) page = 1
                         6. (integer) startnum = 1
       8. (array) 7:
             1. (string) file = /home/virtual/site9/fst/var/www/html/includes/pnMod.php
             2. (integer) line = 670
             3. (string) function = search_user_search
             4. (array) args:
                   1. (array) 0: (empty)
       9. (array) 8:
             1. (string) file = /home/virtual/site9/fst/var/www/html/includes/pnMod.php
             2. (integer) line = 607
             3. (string) function = pnmodfuncexec
             4. (array) args:
                   1. (string) 0 = Search
                   2. (string) 1 = user
                   3. (string) 2 = search
                   4. (array) 3: (empty)
      10. (array) 9:
             1. (string) file = /home/virtual/site9/fst/var/www/html/index.php
             2. (integer) line = 99
             3. (string) function = pnmodfunc
             4. (array) args:
                   1. (string) 0 = Search
                   2. (string) 1 = user
                   3. (string) 2 = search
                   4. (array) 3: (empty)


    Doe this help anyone figure out what is going on? If I put in a print/debug statement I show that the search page executes completely through my searchapi and fills the table correctly. Any and all help appreciated.
  • I created a very simple test case. This afternoon I took a few minutes and created a completely fresh install of zikula. I then installed my book module and created a rudimentary book with one chapter and one article. The article has a number of "the" s in it. It now creates the problem. This is a test site, so I would be happy to turn on debugging or anything else that people want.

    To see the bug, go here

    http://www.microbiol…x.php?module=Search

    And do a search for "the". You will get a Blank Page. There must be something stupid I am doing in my pnsearchapi. Can someone explain to me what it might be. There is $50 in it for anyone who can figure out this bug.

    Thanks



    edited by: Paustian, Nov 18, 2008 - 06:22 PM
  • Blank pages can have a number of causes. To where things fail, please do the following:

    1) Turn on the display of errors in your php.ini (alternatively, look in your apache error log for any error messages)
    2) Set the parameter "development" in your config.php to 1

    Then re-test and tell us what the system is telling you.

    Greetings
    R
  • R,

    Thanks so much for your help. So I did what you asked and was able to track it down to the permission checker. I have something wrong in there. It must be failing silently. Here is the code for the permission checker.

    Code

    class book_result_checker
    {
        var $ok;
        function tostring()
        {
            if($ok===true){
                return "true";
            }
            return "false";
        }
        // This method is called by DBUtil::selectObjectArrayFilter() for each and every search result.
        // A return value of true means "keep result" - false means "discard".
        function checkResult(&$item)
        {
            $book = pnModAPIFunc('Book', 'user', 'get', array ('book_id' => $item[book_id]));
            $chapter = pnModAPIFunc('Book', 'user', 'getchapter', array ('chap_id' => $item[chap_id]));
            $ok = SecurityUtil::checkPermission( 'Book::Chapter', "$book[book_name]::$chapter[chap_name]", ACCESS_READ);
            return $ok;
        }
    }


    If I comment out the code in the middle and just return true, then the search works! This in itself is great, since it make the search work. However, the permission part is broken. Any ideas what I might be doing wrong here?

    Tim
  • So a bit more time to think about this, and I think I may have an idea. Maybe I cannot call the pnModAPIFunc from within this handler? In any case, if I comment out the two calls to pnModAPIFunc, it works. Although I will have to change my permission scheme to get this to function completely properly, but that is not a big deal.

    One other question, the search is displaying large amounts of text if I return $story['contents'], the contents of the article. From looking at the code, shouldn't this truncate to a smaller amount?
  • Well, it's definitely better to have an ID-based permission scheme, so you don't need to load the $book and $chapter. Also, if $item[book_id] exists, i guess that $item already have the Book info...

    You may perform a print_r($item); to see the data of the $item and confirm that it's already the book.

    --
    - Mateo T. -
    Mis principios... son mis fines
  • Mateo,

    Thanks for the reply and I agree. I thought it would be hard to work out the IDs for all the chapters, but then realized I could list that stuff for admins of the site only. They would be the ones setting permissions anyway. I am curious if pnModAPIFunc calls are not aloud in the context of the pnsearchapi, or if something else is going on.

    Some things I learned in this process,

    1. Memory matters. If you are getting weird bugs, check your memory allocation. This will often be a problem, especially on shared hosts.
    2. There can be more than one problem. That is what really stuck me is I had two issues going on at the same time and it did not occur to me to fix them both and test at the same time.
    3. Debug is your friend. To turn this on, set $PNConfig['System']['development'] = 1; and then set flags in the $PNConfig['Debug'] series as needed. You get all sorts of useful information from this and this pointed me in the right direction. The developers did a great job of putting in code for working out problems

    Thanks to all who helped with this. I do plan on submitting the new module once I get all the deprecated code out of it to the repository.

    Tim
  • Nice points Tim icon_smile
    thx for share the experience and the module (soon)
    Keep it up!

    --
    - Mateo T. -
    Mis principios... son mis fines

This list is based on users active over the last 60 minutes.