More than 10.000 categories More than 10.000 categories
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

More than 10.000 categories

Started by kamad3, September 02, 2016, 04:22:51 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

kamad3

I have a big gallery which exceeded its limit. I didn't read the whole documentation so I didn't realize, that the gallery can support up to 10.000 categories.

On this page (http://documentation.coppermine-gallery.net/en/dev_database.htm) I found the following information under cpg15x_albums description:

"The parent category of this album. A category of 0 indicates the album is in 'no category' and is displayed on the main page directly. If the value is more than 10000 then it means the album is a user album belonging to the user with id of category - 10000."

Is there any chance for me to increase these limit to 100.000? My users can't make more categories because the gallery started to add them to user galleries.

Thank you very much in advance!

gmc

FIRST_USER_CAT is defined in yourcpgfolder/include/init.inc.php on line 106 of CPG1.5.40...
define('FIRST_USER_CAT', 10000);

This can be changed... but may be some 'downstream effects'...
If you don't have any user galleries - I suspect you may be ok.

If you do - at least the albums table may reference categories over 10,000... They would need to be adjusted based on the new value you set.  (ie - if changing from 10000 to 50000, the category reference in cpg_albums would need to be changed from 10xxx to 50xxx.
Something like this issued thru a tool like phpMyAdmin:

UPDATE `cpg_albums` SET `category` = `category` + '40000' WHERE `category` > '10000';


It may be that simple...  but would need some testing...

After further review, I am seeing some hardcoded values of 10000 in the code - those (if referring to the user category) would need changes to reference the FIRST_USER_CAT constant...

Looks like an update needed to:

  • catmgr.php
  • index.php
  • sidebar.php
  • bridge/udbbase.inc.php
  • include/functions.inc.php
  • plugins/usergal_alphatabs/codebase.php (a distributed plugin in core package)
and a change to one of my plugins...
All appear to be one line updates (not counting comments...)  Find 10000 in each - and change references to FIRST_USER_CAT

(FIRST_USER_CAT is defined as a constant in init.inc.php - called by every CPG invocation which makes it globally available to all code and functions... )

Feel like giving it a try??
Thanks!
Greg
My Coppermine Gallery
Need a web hosting account? See my gallery for an offer for CPG Forum users.
Send me money

gmc

#2
Detailed changes that I would suggest - prefix each filepath with your cpg folder name.
All but one file are only one line changes.

include/init.inc.php
find:
define('FIRST_USER_CAT', 10000);
replace with:
define('FIRST_USER_CAT', 50000);

catmgr.php
(Other Dev's - not sure this needs to or should change... sets default pos in cpg_categories to 10000 - but tree rebuild is based on lft=0... Don't see what it would hurt changing... Please comment...)
find:
    cpg_db_query("INSERT INTO {$CONFIG['TABLE_CATEGORIES']} (pos, parent, name, description) VALUES (10000, $parent, '$name', '$description')");
replace with:
    cpg_db_query("INSERT INTO {$CONFIG['TABLE_CATEGORIES']} (pos, parent, name, description) VALUES (".FIRST_USER_CAT.", $parent, '$name', '$description')");

index.php
find:
    $cat_owner_id = ($cat > 10000)?(10000 - $cat):(10001);
replace with:
    $cat_owner_id = ($cat > FIRST_USER_CAT)?(FIRST_USER_CAT - $cat):(FIRST_USER_CAT + 1);

sidebar.php
find:
                $sql = "SELECT DISTINCT user_id, user_name FROM {$CONFIG['TABLE_USERS']}, {$CONFIG['TABLE_ALBUMS']} WHERE  10000 + {$CONFIG['TABLE_USERS']}.user_id = {$CONFIG['TABLE_ALBUMS']}.category ORDER BY user_name ASC";
replace with:
                $sql = "SELECT DISTINCT user_id, user_name FROM {$CONFIG['TABLE_USERS']}, {$CONFIG['TABLE_ALBUMS']} WHERE  ".FIRST_USER_CAT." + {$CONFIG['TABLE_USERS']}.user_id = {$CONFIG['TABLE_ALBUMS']}.category ORDER BY user_name ASC";

bridge/udb_base.inc.php
find:
            $sql  = "SELECT category - 10000 AS user_id "
replace with:
            $sql  = "SELECT category - ".FIRST_USER_CAT." AS user_id "
(no semicolon as the SQL statement continues on next line...)

include/functions.inc.php
find:
function& cpg_get_system_thumb($filename, $user = 10001)
{
    global $CONFIG;

    // Correct user_id
    if ($user < 10000) {
        $user += 10000;
    }

    if ($user == 10000) {
        $user = 10001;
    }

replace with:
function& cpg_get_system_thumb($filename, $user = FIRST_USER_CAT)
{
    global $CONFIG;

    // Correct user_id
    if ($user < FIRST_USER_CAT) {
        $user += FIRST_USER_CAT;
    }

    if ($user == FIRST_USER_CAT) {
        $user = FIRST_USER_CAT + 1;
    }

('+ 1' not needed in function statement - second IF will add the one for us...)

plugins/usergal_alphatabs/codebase.php
find:
            $sql  = "SELECT category - 10000 as user_id ";
replace with:
            $sql  = "SELECT category - ".FIRST_USER_CAT." as user_id ";
(This one may look strange in your PHP editor as this is part of a parm to a PHP eval function...)

Run SQL (via phpMyAdmin or other tool):
* Change cpg_ to your defined cpg table prefix *
UPDATE `cpg_albums` SET `category` = `category` + '40000' WHERE `category` > '10000';

Disclaimer - I did not test this code... It may contain errors including typos - though I tried to catch them...

If this works - I would suggest inclusion in a future release... We should be using the defined constant and not hardcoding the 10000 value.

Edited to include change to function statement as found by kamad3 in reply 5... and reply 7
Thanks!
Greg
My Coppermine Gallery
Need a web hosting account? See my gallery for an offer for CPG Forum users.
Send me money

Αndré

Quote from: gmc on September 02, 2016, 08:11:18 PM
After further review, I am seeing some hardcoded values of 10000 in the code - those (if referring to the user category) would need changes to reference the FIRST_USER_CAT constant...

I'll fix this, so it's included in the next release.

kamad3

Thank you for your help, I made the changes you recommended. I found one more row, should I change this one too?

include/functions.inc.php:

function& cpg_get_system_thumb($filename, $user = 10001)
{


I don't have any user galleries, so I didn't change anything in SQL. I tried to create new categories after the modifications, and I can say that your solution works!!! Thank you very much!

Adam

gmc

Quote from: kamad3 on September 05, 2016, 10:17:57 AM
Thank you for your help, I made the changes you recommended. I found one more row, should I change this one too?

include/functions.inc.php:

function& cpg_get_system_thumb($filename, $user = 10001)
{


Yes... I was searching for 10000 - not 10001, but this was just above other changes... should have seen that.

include/functions.inc.php
find:
function& cpg_get_system_thumb($filename, $user = 10001)
replace with:
function& cpg_get_system_thumb($filename, $user = FIRST_USER_CAT + 1)

Editing post below with this info so it is complete...
Thanks!
Greg
My Coppermine Gallery
Need a web hosting account? See my gallery for an offer for CPG Forum users.
Send me money

kamad3

Quote from: gmc on September 05, 2016, 02:26:34 PM
Yes... I was searching for 10000 - not 10001, but this was just above other changes... should have seen that.

include/functions.inc.php
find:
function& cpg_get_system_thumb($filename, $user = 10001)
replace with:
function& cpg_get_system_thumb($filename, $user = FIRST_USER_CAT + 1)

Editing post below with this info so it is complete...


I get an error message:

Parse error: syntax error, unexpected '+', expecting ')' in /var/www/html/gallery/include/functions.inc.php on line 3225

function& cpg_get_system_thumb($filename, $user = FIRST_USER_CAT + 1)
{

gmc

#7
Quote from: kamad3 on September 05, 2016, 02:32:19 PM

I get an error message:

Parse error: syntax error, unexpected '+', expecting ')' in /var/www/html/gallery/include/functions.inc.php on line 3225

function& cpg_get_system_thumb($filename, $user = FIRST_USER_CAT + 1)
{


Something told me i should have tested that one... An expression setting a default value... thought that might be an issue. ok...
Just drop the '+ 1' - there is already code to change a value of FIRST_USER_CAT to FIRST_USER_CAT + 1...

Correcting original post again...
Thanks!
Greg
My Coppermine Gallery
Need a web hosting account? See my gallery for an offer for CPG Forum users.
Send me money

kamad3


Αndré

Greg, do you want to push your changes to cpg1.6.x yourself, or should I do this?

Αndré

#10
We also need to update this query in sql/update.sql:
UPDATE CPG_albums SET owner = category - 10000 WHERE category > 10000;


Open update.php, find
$sql_query = preg_replace('/CPG_/', $CONFIG['TABLE_PREFIX'], $sql_query);
and below, add
$sql_query = str_replace('{FIRST_USER_CAT}', FIRST_USER_CAT, $sql_query);

Open sql/update.sql, find
UPDATE CPG_albums SET owner = category - 10000 WHERE category > 10000;
and replace with
UPDATE CPG_albums SET owner = category - {FIRST_USER_CAT} WHERE category > {FIRST_USER_CAT};

Αndré


gmc

Quote from: Αndré on September 06, 2016, 09:53:01 AM
Greg, do you want to push your changes to cpg1.6.x yourself, or should I do this?

Go ahead... I'm in middle of moving - have to see if I have everything setup for GIT and play with it a little more first.
Thanks!
Greg
My Coppermine Gallery
Need a web hosting account? See my gallery for an offer for CPG Forum users.
Send me money

Αndré

Pushed to Github: https://github.com/coppermine-gallery/cpg1.6.x/commit/afbe8439608d15cdeae4e9ba4141d7932e0e864e

Quote from: gmc on September 02, 2016, 09:35:48 PM
sets default pos in cpg_categories to 10000 - but tree rebuild is based on lft=0...

Can you please explain this more detailed or tell me where I find the corresponding code? Thanks.

gmc

Quote from: Αndré on September 07, 2016, 04:34:44 PM
Pushed to Github: https://github.com/coppermine-gallery/cpg1.6.x/commit/afbe8439608d15cdeae4e9ba4141d7932e0e864e

Can you please explain this more detailed or tell me where I find the corresponding code? Thanks.

In catmgr - the 'default' pos on insert seems to be getting set to 10000... I assume that is just to get it out of the way - and should be able to change to 'FIRST_USER_CAT'...

Following the insert (catmgr.php) - check_rebuild_tree (functions.inc.php) is called - and it looks for any categories with lft=0 (lft is not included in the INSERT command and database default value is 0) and determines/sets the correct lft, rgt, depth, pos for the new categories - resetting the 10000 used at INSERT time a few milliseconds ago.

I think changing to FIRST_USER_CAT is appropriate for the INSERT - as it should keep from having a conflicting 'pos' in the small window between INSERT and tree rebuild.  Certainly doesn't hurt anything I can see.

(This was an interesting area to explore when I wrote the gallery_merge plugin... as I was adding the 'merged' categories and still maintaining the tree structure.  Turned out to be simple - set lft=0 and let check_rebuild_tree do the heavy lifting.)
Thanks!
Greg
My Coppermine Gallery
Need a web hosting account? See my gallery for an offer for CPG Forum users.
Send me money

Αndré

Okay, now I got what you mean. Initially I thought you want to change that value to something different (e.g. 0 or whatever).