mikespub-org / seblucas-cops

Calibre OPDS (and HTML) PHP Server : web-based light alternative to Calibre content server / Calibre2OPDS to serve ebooks (epub, mobi, pdf, ...)
http://blog.slucas.fr/en/oss/calibre-opds-php-server
GNU General Public License v2.0
65 stars 7 forks source link

Regression in PageIndex.php handling of custom columns in multi db COPS instances #89

Closed Chirishman closed 1 month ago

Chirishman commented 3 months ago

Since these changes I am seeing this error in the logs

  thrown in /app/www/public/lib/Pages/PageIndex.php on line 199" while reading response header from upstream, client: 10.1.2.42, server: _, request: "GET /feed.php?db=0 HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "library.chiriserv.com"
2024/06/08 15:21:14 [error] 257#257: *245 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught Error: Call to a member function setHandler() on null in /app/www/public/lib/Pages/PageIndex.php:199
Stack trace:
#0 /app/www/public/lib/Pages/PageIndex.php(52): SebLucas\Cops\Pages\PageIndex->getTopCountEntries()
#1 /app/www/public/lib/Pages/PageIndex.php(35): SebLucas\Cops\Pages\PageIndex->getEntries()
#2 /app/www/public/lib/Handlers/FeedHandler.php(61): SebLucas\Cops\Pages\PageIndex->InitializeContent()
#3 /app/www/public/lib/Framework.php(56): SebLucas\Cops\Handlers\FeedHandler->handle()
#4 /app/www/public/feed.php(15): SebLucas\Cops\Framework::run()
#5 {main}
  thrown in /app/www/public/lib/Pages/PageIndex.php on line 199" while reading response header from upstream, client: 10.1.2.42, server: _, request: "GET /feed.php?db=0 HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "library.chiriserv.com"

Which is a call to this:

$customColumn->setHandler($this->handler);

Based on the variable on that line I would guess this has to do with the fact that I have different custom columns in some of my libraries than others. Previously this was being handled without any terminating errors.

this is my config_local.php

<?php
    if (!isset($config))
        $config = array();

    /*
     * The directory containing calibre's metadata.db file, with sub-directories
     * containing all the formats.
     * BEWARE : it has to end with a /
     * $config['calibre_directory'] = '/books/ebooks/';
     */
    $config['calibre_directory'] = array ("eBooks" => "/books/ebooks/", "Comics" => "/books/comics/", "Manga" => "/books/manga/", "Fanfiction" => "/books/fanfiction/", "Webfiction" => "/books/webfiction/", "Light Novels" => "/books/lightnovels/");

    if (!empty ($_GET) && isset($_GET['db']) && $_GET['db'] != '') {
        if ( $_GET['db'] == 0 )
            $config['calibre_internal_directory'] = "/books/ebooks/";
        elseif ( $_GET['db'] == 1 )
               $config['calibre_internal_directory'] = "/books/comics/";
        elseif ( $_GET['db'] == 2 )
               $config['calibre_internal_directory'] = "/books/manga/";
        elseif ( $_GET['db'] == 3 )
               $config['calibre_internal_directory'] = "/books/fanfiction/";
        elseif ( $_GET['db'] == 4 )
               $config['calibre_internal_directory'] = "/books/webfiction/";
        elseif ( $_GET['db'] == 5 )
               $config['calibre_internal_directory'] = "/books/lightnovels/";
    }

    /*
     * Catalog's title
     */
    $config['cops_title_default'] = "COPS";

    /*
     * use URL rewriting for downloading of ebook in HTML catalog
     * See README for more information
     *  1 : enable
     *  0 : disable
     */
    $config['cops_use_url_rewriting'] = "0";
    $config['cops_ignored_categories'] = array("language");
    $config['cops_ignored_formats'] = ['ORIGINAL_EPUB', 'ORIGINAL_AZW3'];
    $config['cops_opds_filter_links'] = [];
    $config['cops_opds_sort_links'] = [];
    $config['cops_prefered_format'] = ['EPUB', 'M4B', 'AZW3', 'AZW', 'MOBI', 'CBR', 'CBZ', 'PDF'];
    $config['cops_calibre_custom_column'] = array("new","characters","fictype","pairings","pairingtypes","parody","relationships","status");
    $config['cops_calibre_custom_column_list'] = array ("new","characters","fictype","updated","lastchecked","chapters","wordcount","pairings","pairingtypes","parody","relationships","status","warnings","contentrated");
    $config['cops_calibre_custom_column_preview'] = array ("new","characters","fictype","updated","lastchecked","chapters","wordcount","pairings","pairingtypes","parody","relationships","status","warnings","contentrated");

     $config['cops_x_accel_redirect'] = "";
    /* Enable cache folder
     * especially useful for lower power hosts
     */
    $config['cops_thumbnail_handling'] = "";
    $config['cops_thumbnail_cache_directory'] = "/config/cache/";

Certain columns like "wordcount" don't exist in the comic and manga libraries, and "parody" exists only in the fanfiction one. As I said, this hasn't caused any terminating errors until now.

mikespub commented 2 months ago

Thanks @Chirishman for tracking this down and explaining the context. And this is a good use case for any other "invalid" custom column issues

mikespub commented 1 month ago

Included in release 2.7.3

Chirishman commented 1 month ago

Thanks! This column handling fix is working great, I unpinned my container version. Unfortunately the 2.8.0 release introduced a new bug that's completely broken downloads for me so I'm rolling back again (#102). Hopefully that's a quick fix.