forum.coppermine-gallery.net

Support => cpg1.5.x Support => cpg1.5 miscellaneous => Topic started by: klewless on June 19, 2016, 09:22:23 pm

Title: Unknown Coward
Post by: klewless on June 19, 2016, 09:22:23 pm
I have just done an upgrade  to the latest CPG version, bridged it to my forum (SMF 2.011 with TP installed).

I had a certain number of albums left behind by former users of the gallery and forum (which is bridged to it). Their images are still there but they bear the label "unknown coward" as album owner. Their albums do not appear on the albums list. What shall I do to remove the "coward" label. The folks in question are actually nice people who have moved onto other things, but were kind enough not to delete their pictures, which we have enjoyed for a long time.

Also the images are "turning up" at random in some other members' galleries.

Thanks in advance!

Title: Re: Unknown Coward
Post by: Αndré on June 20, 2016, 09:58:21 am
To change the "coward", have a look at the language file(s) in the "lang" directory and search for:
Code: [Select]
$lang_common['username_if_blank']
To fix the reason why this happens, we need more information. I assume the users who uploaded those pictures in the past have deleted their account in your board? From which Coppermine version did you upgraded from? A link to your gallery may also help.
Title: Re: Unknown Coward
Post by: klewless on June 20, 2016, 01:54:27 pm
Andre,

Good morning!

My gallery is in maintenance mode right now, sorry. Thanks for the help though; I will at least remove the insulting title.

 I honestly do not think this is a version specific problem, because it was the same on 1410, our old version. On that version, the missing member would be called Mr. X, not "unknown coward"

 You are correct about what is happening: the gallery member list was fine before I bridged it, but once bridged, if the member no longer has an account on the forum, the pictures seem to have nowhere to go.

I looked in the database..... it goes by member number (10106, 10109, etc) there and the user info is still all there. But because the member names and accounts are coming from SMF, if it does not find a match, it calls the person Unknown Coward. I can fix that now but what to do with the albums.... hmmm.....

I wonder if I should create new accounts on SMF for those people, create new albums in the gallery,  and move the pictures to the new albums? Would I lose all the peripheral info (stats, hits,comments etc.)? Should I transfer the info in the database to the new row for the new album? Who would own the new account?
Title: Re: Unknown Coward
Post by: Αndré on June 20, 2016, 02:18:55 pm
I think I'd adjust the user ID in the pictures table to the user ID which corresponds to "guest" (i.e. "0") and then either move all affected files to one album or, if you want/need to keep the files in their albums, adjust the album permissions (or whatever is currently wrong).

I assume the affected albums/pictures were created in the "user galleries" category (ID "1)? If so, I need to have a look at the code what exactly Coppermine does if the user doesn't exist anymore.
Title: Re: Unknown Coward
Post by: klewless on June 20, 2016, 05:46:27 pm
Hi Andre,

Good.

I like the idea of doing this with php better than renaming etc. There has to be something. Some sort of "if userID exists / else"? After all it does something with the pictures i.e. doies not ignore them altogether.  Unf ortunately I am at  but I will have a look during lunch break or when I am home.

Thanks again

Title: Re: Unknown Coward
Post by: Αndré on June 20, 2016, 05:53:19 pm
If you need more detailed help, I need to have a look at your gallery and your MySQL database. Let me know.
Title: Re: Unknown Coward
Post by: klewless on June 23, 2016, 03:13:14 am
Sorry, how can I PM or contact you please?


Title: Re: Unknown Coward
Post by: Αndré on June 23, 2016, 09:04:24 am
I just sent you a PM.
Title: Re: Unknown Coward
Post by: klewless on June 26, 2016, 11:59:28 pm
People who are reading this out of curiosity might be reminded here that you can delete an account (user) on the SMF board but it does not delete their gallery. I think part of the reason I have this problem is my own fault. I have not kept on top of the users in Coppermine like I do on SMF, somehow, I thought that both accounts would be deleted. Not so.

Over the weekend I decided to clean up the albums/userpics file and data base. I found there were dozens of empty albums in userpics, which I  deleted, along with the matching albums in the albums database, if they were still there. In most cases, the empty albums were no longer in the database, but there were a few empties belonging to people who were members (I think in those cases they were people who decided to open an album for themselves but had some trouble with it). I also looked over albums/userpics and made a list of the userpics folders that did not correspond to an album in the database. There were around a dozen that still have pictures in them, that we want to keep.

Doing this pruning seems to have eliminated one of the empty pages at the end of the ember albums search. That means my theory that the "empty" pages were for member pics that did not match up with current users, is correct.

Thanks in advance.
Title: Re: Unknown Coward
Post by: Αndré on July 12, 2016, 04:00:18 pm
I just created 2 test users and created an album for each of them in their personal gallery. Then, I deleted 1 user directly in the MySQL database to simulate a deleted user in your board. When I now open the orphaned picture, Coppermine displays this category/album path:
Quote
Home > User galleries > Unknown coward > album of test2

You said the picture is moved to the album of another user when you update something. And here's the reason: on the "Edit file" page there's a dropdown menu where you can select the album which the pictures is assigned to. If the current album doesn't exist, your browser automatically selects the first available item. So when you now submit the form, Coppermine moves the picture to another album.

Actually, the album of the former user still exists, but Coppermine doesn't add it to the album dropdown, if the user doesn't exist. I'll have a closer look at the code how to fix this.
Title: Re: Unknown Coward
Post by: klewless on July 12, 2016, 04:18:48 pm
Awesome. About the picture showing up in another album... suspected as much.

I am at work now with limited access.

thanks soooo much.
Title: Re: Unknown Coward
Post by: Αndré on July 12, 2016, 04:38:16 pm
To include the albums of former users in the album dropdown, please try the following. Open include/functions.inc.php, find
Code: [Select]
            foreach ($users as $user) {
                if (!empty($albums[$user['user_id'] + FIRST_USER_CAT])) {
                    $options .= '<optgroup label="&nbsp;&nbsp;&nbsp;&nbsp;' . $user['user_name'] . '">' . $LINEBREAK;
                    foreach ($albums[$user['user_id'] + FIRST_USER_CAT] as $aid => $title) {
                        $options .= sprintf('<option value="%d"%s>%s</option>' . $LINEBREAK, $aid, $aid == $selected ? ' selected="selected"' : '', '&nbsp;&nbsp;&nbsp;&nbsp;'.$title);
                    }
                    $options .= '</optgroup>';
                }
            }
and replace with
Code: [Select]
            $user_categories = array();
            foreach ($users as $user) {
                $user_categories[] = $user['user_id'] + FIRST_USER_CAT;
                if (!empty($albums[$user['user_id'] + FIRST_USER_CAT])) {
                    $options .= '<optgroup label="&nbsp;&nbsp;&nbsp;&nbsp;' . $user['user_name'] . '">' . $LINEBREAK;
                    foreach ($albums[$user['user_id'] + FIRST_USER_CAT] as $aid => $title) {
                        $options .= sprintf('<option value="%d"%s>%s</option>' . $LINEBREAK, $aid, $aid == $selected ? ' selected="selected"' : '', '&nbsp;&nbsp;&nbsp;&nbsp;'.$title);
                    }
                    $options .= '</optgroup>';
                }
            }

            // search for albums of non-existing members
            foreach ($albums as $key => $value) {
                if ($key > FIRST_USER_CAT) {
                    if (!in_array($key, $user_categories)) {
                        $options .= '<optgroup label="&nbsp;&nbsp;&nbsp;&nbsp;' . $lang_common['username_if_blank'] . ' ' . ($key - FIRST_USER_CAT) . '">' . $LINEBREAK;
                        foreach ($albums[$key] as $aid => $title) {
                            $options .= sprintf('<option value="%d"%s>%s</option>' . $LINEBREAK, $aid, $aid == $selected ? ' selected="selected"' : '', '&nbsp;&nbsp;&nbsp;&nbsp;'.$title);
                        }
                        $options .= '</optgroup>';
                    }
                }
            }

I initially thought to add all orphaned albums in one group, but then used the "unknown coward" string and added their user ID to it. However, there are 3 possibilities to add the albums to the album dropdown:
1. Put all orphaned albums in one group, after the existing users
2. Put all orphaned albums of each former user after the existing users (that's how it currently works)
3. Put all orphaned albums of each former user along with the existing users and sort them by user ID

I need to think some time about this, but I currently (again) tend to option 1 :D
Title: Re: Unknown Coward
Post by: klewless on July 12, 2016, 06:10:05 pm
How will the orphaned albums appear when someone waants to view the albums list?

L.
Title: Re: Unknown Coward
Post by: klewless on July 13, 2016, 01:18:21 am
Hi Andre,

I added the code as suggested and it seems to work. (and thank you for telling me what file this is located in, I would never have found it).

At the end of the drop-down menu, there is now a very long list, not in numerical order, of Former Members, with their albums listed below.

On the gallery the pictures are visible, but not the albums' cover thumbnails, if you are looking at the Member Albums list. There are now four or five blank pages at the end of Member Galleries..

The funny thing is I went through and deleted the empty albums, and checked the data base for the user account if I deleted the user's empty folder from albums/userpix. Perhaps there is more member info in one of the other tables in the database, that I have to delete as well as what I did so far.

 :) :)



I would like to see the album
Title: Re: Unknown Coward
Post by: klewless on July 13, 2016, 02:28:31 pm
Just as an aside, we had lots of misplaced pictures, about 40 of them, which happened while I was adding key words to them, and they were reassigned to the wrong album, as described in the above posts. Andre's code, above, will fix future problems but the misplaced pictures will remain where they are, unless you intervene . I didn't want to unbridgle my gallery cos we have a custom menu installation being worked on right now, so I had to do the following:

So when a picture is accidentally assigned to the wrong album you must go to the CPG database and look at the Users table, locate its owner, (the userID is shown) Locate the column called "aid" for the user's album ID number) . You will also need the album number of the place where the pictures wound up (the user is visible on the breadcrumbs above a open album too).

Open up the Pictures database next, and search for the album number where the misplaced pictures are currently located. You now need only to change the number in the AID column to the number of the correct album.

If you open up your backup copy of the albumx/userpics folder, you can confirm that user X owns the picture, in cases where, like me, I had to guess a lot because people love to give their albums imaginative names like "MY Pictures" and "New" and so on.  There is also a picture number displayed in the URL bar on your browser when you open an image, but the picture list is kind of long so better to search by user/album.

It's a little tedious to do this when you have a lot of orphans, but better than using the scroll bar to move them if it's a long one, like I have.

Hope this helps :)
Title: Re: Unknown Coward
Post by: Αndré on July 14, 2016, 11:47:37 am
How will the orphaned albums appear when someone waants to view the albums list?

We need to add a similar approach to the function list_users() in index.php as we just did in include/functions.inc.php. Will have a closer look now.
Title: Re: Unknown Coward
Post by: klewless on July 14, 2016, 02:02:48 pm
Still here, Andre. Thanks.

; - )
Title: Re: Unknown Coward
Post by: Αndré on July 14, 2016, 02:04:22 pm
The following change needs some improvement, e.g. there currently no data about album and file number for each former user. But it's a start and should work.

Open index.php, find
Code: [Select]
    if (!$rowset) {
        msg_box($lang_list_users['user_list'], $lang_list_users['no_user_gal'], '', '', 'info');
        return;
    }
and below, add
Code: [Select]
    if ($user_count > count($rowset)) {
        $sql  = "SELECT category "
                . "FROM {$CONFIG['TABLE_ALBUMS']} AS p "
                . " INNER JOIN {$CONFIG['TABLE_PICTURES']} AS pics ON pics.aid = p.aid "
                . "WHERE ( category > " . FIRST_USER_CAT . " $FORBIDDEN_SET) ";
        $result = cpg_db_query($sql);
        while ($row = cpg_db_fetch_assoc($result)) {
            $user_categories[$row['category'] - FIRST_USER_CAT] = 1;
        }
        cpg_db_free_result($result);

        foreach ($rowset as $user) {
            unset($user_categories[$user['user_id']]);
        }
        foreach ($user_categories as $user_id => $tmp) {
            $rowset[] = array(
                'user_id' => $user_id,
                'user_name' => 'Former user '.$user_id,
            );
        }
    }
Title: Re: Unknown Coward
Post by: klewless on July 14, 2016, 02:19:27 pm
Great, will get to work on it tonight.

I have found the picture owners'  IDs are in the path for the picture but I still have to go to the DB to find the AID number.

L.
Title: Re: Unknown Coward
Post by: Αndré on July 14, 2016, 07:30:28 pm
Updated code with album and picture counters (just tested on a very small test data, so I need your feedback if everything works as expected).

Open index.php, find
Code: [Select]
    if (!$rowset) {
        msg_box($lang_list_users['user_list'], $lang_list_users['no_user_gal'], '', '', 'info');
        return;
    }
and below, add
Code: [Select]
    if ($user_count > count($rowset)) {
        $sql  = "SELECT category "
                . "FROM {$CONFIG['TABLE_ALBUMS']} AS p "
                . " INNER JOIN {$CONFIG['TABLE_PICTURES']} AS pics ON pics.aid = p.aid "
                . "WHERE ( category > " . FIRST_USER_CAT . " $FORBIDDEN_SET) ";
        $result = cpg_db_query($sql);
        while ($row = cpg_db_fetch_assoc($result)) {
            $user_ids[$row['category'] - FIRST_USER_CAT] = 1;
        }
        cpg_db_free_result($result);

        foreach ($rowset as $user) {
            unset($user_ids[$user['user_id']]);
        }
        foreach ($user_ids as $user_id => $tmp) {
            $user_categories[] = $user_id + FIRST_USER_CAT;
        }
        $result = cpg_db_query("
            SELECT p.owner_id, p.aid, COUNT(*) AS pic_count FROM {$CONFIG['TABLE_PICTURES']} AS p
            INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a
            ON a.aid = p.aid
            WHERE a.category IN (".implode(',', $user_categories).")
            GROUP BY p.aid
        ");
        while ($row = cpg_db_fetch_assoc($result)) {
            $user_category_data[$row['owner_id']]['alb_count']++;
            $user_category_data[$row['owner_id']]['pic_count'] += $row['pic_count'];
        }
        foreach ($user_ids as $user_id => $tmp) {
            $rowset[] = array(
                'user_id' => $user_id,
                'user_name' => 'Former user '.$user_id,
                'alb_count' => $user_category_data[$user_id]['alb_count'],
                'pic_count' => $user_category_data[$user_id]['pic_count'],
            );
        }
    }
Title: Re: Unknown Coward
Post by: klewless on July 15, 2016, 02:53:04 am
Working, sort-of, thank you.

All 9 pages of Home/Member Galleries are now full, rather than there being some blank pages at the end. Unfortunately, the active members and former members are mixed upL some of the active users' album cover thumbs are replaced by those empty film cans. The pictures are still inside fortunately, and so are the comments and other file information associated with the images, for everyone -- former members or members.

I will try to see if I missed a bracket or something in the copy-pasting.

 :-\ :-\ :-\
Title: Re: Unknown Coward
Post by: klewless on July 15, 2016, 03:49:45 am
Another odd thing is that "all" the results are showing up on each page of Home>Member Galleries: the same "film cans" , in the same order.
 :-\
Title: Re: Unknown Coward
Post by: Αndré on July 15, 2016, 06:50:42 am
I'll perform some tests on your gallery as soon as possible.
Title: Re: Unknown Coward
Post by: klewless on July 17, 2016, 04:04:58 pm
Still here  :)

I have left the new code in place for now so you can see   ???  :



Thanks again,
L.
Title: Re: Unknown Coward
Post by: Αndré on July 18, 2016, 02:08:00 pm
My last code change was created with totally wrong assumptions. I just updated the code on your website and it seems to work as expected as far as I can tell. I've reverted the first modification and instead I applied this mod.

Open index.php, find
Code: [Select]
    if (!$rowset) {
        msg_box($lang_list_users['user_list'], $lang_list_users['no_user_gal'], '', '', 'info');
        return;
    }

    $user_per_page = $CONFIG['thumbcols'] * $CONFIG['thumbrows'];
    $totalPages    = ceil($user_count / $user_per_page);
and replace with
Code: [Select]
    if (!$user_count) {
        msg_box($lang_list_users['user_list'], $lang_list_users['no_user_gal'], '', '', 'info');
        return;
    }

    $user_per_page = $CONFIG['thumbcols'] * $CONFIG['thumbrows'];
    $totalPages    = ceil($user_count / $user_per_page);

    $users_this_page = count($rowset);
    if ($user_count > $users_this_page && $users_this_page < $user_per_page) {
        $sql  = "SELECT {$cpg_udb->field['user_id']} AS user_id FROM {$cpg_udb->usertable}";
        $result = cpg_db_query($sql);
        while ($row = cpg_db_fetch_assoc($result)) {
            $user_ids_existing[] = $row['user_id'];
        }
        cpg_db_free_result($result);

        $sql  = "SELECT category "
                . "FROM {$CONFIG['TABLE_ALBUMS']} AS p "
                . "INNER JOIN {$CONFIG['TABLE_PICTURES']} AS pics ON pics.aid = p.aid "
                . "WHERE ( category > " . FIRST_USER_CAT . " $FORBIDDEN_SET) "
                . "GROUP BY category";
        $result = cpg_db_query($sql);
        while ($row = cpg_db_fetch_assoc($result)) {
            $user_ids_all[] = $row['category'] - FIRST_USER_CAT;
        }
        cpg_db_free_result($result);

        $users_missing = array_diff($user_ids_all, $user_ids_existing);

        $users_w_albums = count(array_intersect($user_ids_all, $user_ids_existing));

        $offset = max(0, ($PAGE - 1) * $user_per_page - $users_w_albums);

        $user_ids = array_slice($users_missing, $offset, $user_per_page - $users_this_page);

        foreach ($user_ids as $user_id) {
            $user_categories[] = $user_id + FIRST_USER_CAT;
        }
        $result = cpg_db_query("
            SELECT p.owner_id, p.aid, COUNT(*) AS pic_count FROM {$CONFIG['TABLE_PICTURES']} AS p
            INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a
            ON a.aid = p.aid
            WHERE a.category IN (".implode(',', $user_categories).")
            GROUP BY p.aid
        ");
        while ($row = cpg_db_fetch_assoc($result)) {
            $user_category_data[$row['owner_id']]['alb_count']++;
            $user_category_data[$row['owner_id']]['pic_count'] += $row['pic_count'];
        }
        foreach ($user_ids as $user_id) {
            $rowset[] = array(
                'user_id' => $user_id,
                'user_name' => 'Former user '.$user_id,
                'alb_count' => $user_category_data[$user_id]['alb_count'],
                'pic_count' => $user_category_data[$user_id]['pic_count'],
            );
        }
    }
Title: Re: Unknown Coward
Post by: klewless on July 19, 2016, 06:11:25 am
I am happy to confirm it works well. Just one problem, the Former Members galleries are showing up as film cans (when you are looking at an album list page), however all the pictures and their comments are intact.

Perhaps I can go in there and assign a picture to each of these albums.

Thanks VERY much!
 :) :) :) :) :) :) :) :)
Title: Re: Unknown Coward
Post by: Αndré on July 19, 2016, 10:48:50 am
Perhaps I can go in there and assign a picture to each of these albums.

Please don't! They're still set in the database, but I haven't added that part to the code, as it had no priority since now. I'll work further on the code and let you know when it's ready.
Title: Re: Unknown Coward
Post by: Αndré on July 19, 2016, 11:03:40 am
Updated code:
Code: [Select]
    if (!$user_count) {
        msg_box($lang_list_users['user_list'], $lang_list_users['no_user_gal'], '', '', 'info');
        return;
    }

    $user_per_page = $CONFIG['thumbcols'] * $CONFIG['thumbrows'];
    $totalPages    = ceil($user_count / $user_per_page);

    $users_this_page = count($rowset);
    if ($user_count > $users_this_page && $users_this_page < $user_per_page) {
        $sql  = "SELECT {$cpg_udb->field['user_id']} AS user_id FROM {$cpg_udb->usertable}";
        $result = cpg_db_query($sql);
        while ($row = cpg_db_fetch_assoc($result)) {
            $user_ids_existing[] = $row['user_id'];
        }
        cpg_db_free_result($result);

        $sql  = "SELECT category "
                . "FROM {$CONFIG['TABLE_ALBUMS']} AS p "
                . "INNER JOIN {$CONFIG['TABLE_PICTURES']} AS pics ON pics.aid = p.aid "
                . "WHERE ( category > " . FIRST_USER_CAT . " $FORBIDDEN_SET) "
                . "GROUP BY category";
        $result = cpg_db_query($sql);
        while ($row = cpg_db_fetch_assoc($result)) {
            $user_ids_all[] = $row['category'] - FIRST_USER_CAT;
        }
        cpg_db_free_result($result);

        $users_missing = array_diff($user_ids_all, $user_ids_existing);

        $users_w_albums = count(array_intersect($user_ids_all, $user_ids_existing));

        $offset = max(0, ($PAGE - 1) * $user_per_page - $users_w_albums);

        $user_ids = array_slice($users_missing, $offset, $user_per_page - $users_this_page);

        foreach ($user_ids as $user_id) {
            $user_categories[] = $user_id + FIRST_USER_CAT;
        }
        $result = cpg_db_query("
            SELECT p.owner_id, p.aid, COUNT(*) AS pic_count, MAX(pid) AS thumb_pid, MAX(galleryicon) AS gallery_pid
            FROM {$CONFIG['TABLE_PICTURES']} AS p
            INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a
            ON a.aid = p.aid
            WHERE a.category IN (".implode(',', $user_categories).")
            GROUP BY p.aid
        ");
        while ($row = cpg_db_fetch_assoc($result)) {
            $user_category_data[$row['owner_id']]['alb_count']++;
            $user_category_data[$row['owner_id']]['pic_count'] += $row['pic_count'];
            $user_category_data[$row['owner_id']]['thumb_pid'] = $row['thumb_pid'];
            $user_category_data[$row['owner_id']]['gallery_pid'] = $row['gallery_pid'];
        }
        foreach ($user_ids as $user_id) {
            $rowset[] = array(
                'user_id' => $user_id,
                'user_name' => 'Former user '.$user_id,
                'alb_count' => $user_category_data[$user_id]['alb_count'],
                'pic_count' => $user_category_data[$user_id]['pic_count'],
                'thumb_pid' => $user_category_data[$user_id]['thumb_pid'],
                'gallery_pid' => $user_category_data[$user_id]['gallery_pid'],
            );
        }
    }

I've already applied it to your gallery, and it seems to work for most user categories. Some have still the trash can icon, but I haven't checked in detail yet why this happens. Maybe you find something obvious.
Title: Re: Unknown Coward
Post by: klewless on July 19, 2016, 01:26:57 pm
I checked those folders with the cans, they have't got any pictures. I guess I just missed a few, some cans also among the sub-albums.


THANK YOU!!!!
Perfect now. Awesome! 
 :) :) :)