Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: More than 10.000 categories  (Read 17283 times)

0 Members and 3 Guests are viewing this topic.

kamad3

  • Coppermine newbie
  • Country: hu
  • Offline Offline
  • Gender: Male
  • Posts: 10
More than 10.000 categories
« on: September 02, 2016, 04:22:51 pm »

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!
Logged

gmc

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: us
  • Offline Offline
  • Gender: Male
  • Posts: 785
    • GMC Design Photo Gallery
Re: More than 10.000 categories
« Reply #1 on: September 02, 2016, 08:11:18 pm »

FIRST_USER_CAT is defined in yourcpgfolder/include/init.inc.php on line 106 of CPG1.5.40...
Code: [Select]
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:
Code: [Select]
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??
Logged
Thanks!
Greg
My Coppermine Gallery
Need a web hosting account? See my gallery for an offer for CPG Forum users.
Send me money

gmc

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: us
  • Offline Offline
  • Gender: Male
  • Posts: 785
    • GMC Design Photo Gallery
Re: More than 10.000 categories
« Reply #2 on: September 02, 2016, 09:35:48 pm »

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:
Code: [Select]
define('FIRST_USER_CAT', 10000);replace with:
Code: [Select]
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:
Code: [Select]
    cpg_db_query("INSERT INTO {$CONFIG['TABLE_CATEGORIES']} (pos, parent, name, description) VALUES (10000, $parent, '$name', '$description')");replace with:
Code: [Select]
    cpg_db_query("INSERT INTO {$CONFIG['TABLE_CATEGORIES']} (pos, parent, name, description) VALUES (".FIRST_USER_CAT.", $parent, '$name', '$description')");
index.php
find:
Code: [Select]
    $cat_owner_id = ($cat > 10000)?(10000 - $cat):(10001);replace with:
Code: [Select]
    $cat_owner_id = ($cat > FIRST_USER_CAT)?(FIRST_USER_CAT - $cat):(FIRST_USER_CAT + 1);
sidebar.php
find:
Code: [Select]
                $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:
Code: [Select]
                $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:
Code: [Select]
            $sql  = "SELECT category - 10000 AS user_id "replace with:
Code: [Select]
            $sql  = "SELECT category - ".FIRST_USER_CAT." AS user_id "(no semicolon as the SQL statement continues on next line...)

include/functions.inc.php
find:
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
            $sql  = "SELECT category - 10000 as user_id ";replace with:
Code: [Select]
            $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 *
Code: [Select]
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
« Last Edit: September 05, 2016, 02:41:11 pm by gmc »
Logged
Thanks!
Greg
My Coppermine Gallery
Need a web hosting account? See my gallery for an offer for CPG Forum users.
Send me money

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: Re: More than 10.000 categories
« Reply #3 on: September 05, 2016, 09:12:31 am »

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.
Logged

kamad3

  • Coppermine newbie
  • Country: hu
  • Offline Offline
  • Gender: Male
  • Posts: 10
Re: More than 10.000 categories
« Reply #4 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:
Code: [Select]
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
Logged

gmc

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: us
  • Offline Offline
  • Gender: Male
  • Posts: 785
    • GMC Design Photo Gallery
Re: More than 10.000 categories
« Reply #5 on: September 05, 2016, 02:26:34 pm »

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:
Code: [Select]
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:
Code: [Select]
function& cpg_get_system_thumb($filename, $user = 10001)replace with:
Code: [Select]
function& cpg_get_system_thumb($filename, $user = FIRST_USER_CAT + 1)
Editing post below with this info so it is complete...
Logged
Thanks!
Greg
My Coppermine Gallery
Need a web hosting account? See my gallery for an offer for CPG Forum users.
Send me money

kamad3

  • Coppermine newbie
  • Country: hu
  • Offline Offline
  • Gender: Male
  • Posts: 10
Re: Re: More than 10.000 categories
« Reply #6 on: September 05, 2016, 02:32:19 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:
Code: [Select]
function& cpg_get_system_thumb($filename, $user = 10001)replace with:
Code: [Select]
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

Code: [Select]
function& cpg_get_system_thumb($filename, $user = FIRST_USER_CAT + 1)
{
Logged

gmc

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: us
  • Offline Offline
  • Gender: Male
  • Posts: 785
    • GMC Design Photo Gallery
Re: Re: More than 10.000 categories
« Reply #7 on: September 05, 2016, 02:38:47 pm »


I get an error message:

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

Code: [Select]
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...
« Last Edit: September 05, 2016, 08:03:41 pm by gmc »
Logged
Thanks!
Greg
My Coppermine Gallery
Need a web hosting account? See my gallery for an offer for CPG Forum users.
Send me money

kamad3

  • Coppermine newbie
  • Country: hu
  • Offline Offline
  • Gender: Male
  • Posts: 10
Re: More than 10.000 categories
« Reply #8 on: September 05, 2016, 03:06:00 pm »

Thanks, it works  :)
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: More than 10.000 categories
« Reply #9 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?
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: More than 10.000 categories
« Reply #10 on: September 06, 2016, 11:03:58 am »

We also need to update this query in sql/update.sql:
Code: [Select]
UPDATE CPG_albums SET owner = category - 10000 WHERE category > 10000;

Open update.php, find
Code: [Select]
$sql_query = preg_replace('/CPG_/', $CONFIG['TABLE_PREFIX'], $sql_query);and below, add
Code: [Select]
$sql_query = str_replace('{FIRST_USER_CAT}', FIRST_USER_CAT, $sql_query);
Open sql/update.sql, find
Code: [Select]
UPDATE CPG_albums SET owner = category - 10000 WHERE category > 10000;and replace with
Code: [Select]
UPDATE CPG_albums SET owner = category - {FIRST_USER_CAT} WHERE category > {FIRST_USER_CAT};
« Last Edit: September 06, 2016, 11:12:06 am by Αndré »
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: More than 10.000 categories
« Reply #11 on: September 06, 2016, 12:07:09 pm »

Committed changes to SVN revision 8859.
Logged

gmc

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: us
  • Offline Offline
  • Gender: Male
  • Posts: 785
    • GMC Design Photo Gallery
Re: Re: More than 10.000 categories
« Reply #12 on: September 06, 2016, 08:43:38 pm »

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.
Logged
Thanks!
Greg
My Coppermine Gallery
Need a web hosting account? See my gallery for an offer for CPG Forum users.
Send me money

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: More than 10.000 categories
« Reply #13 on: September 07, 2016, 04:34:44 pm »

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

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.
Logged

gmc

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: us
  • Offline Offline
  • Gender: Male
  • Posts: 785
    • GMC Design Photo Gallery
Re: Re: More than 10.000 categories
« Reply #14 on: September 07, 2016, 05:04:23 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.)
Logged
Thanks!
Greg
My Coppermine Gallery
Need a web hosting account? See my gallery for an offer for CPG Forum users.
Send me money

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: More than 10.000 categories
« Reply #15 on: September 07, 2016, 08:21:14 pm »

Okay, now I got what you mean. Initially I thought you want to change that value to something different (e.g. 0 or whatever).
Logged
Pages: [1]   Go Up
 

Page created in 0.027 seconds with 20 queries.