Skip to content

Commit

Permalink
fixes #9 only resets album thumbnail if the image was in the album be…
Browse files Browse the repository at this point in the history
…fore rebuilt
  • Loading branch information
plegall committed Nov 1, 2021
1 parent fde7ec7 commit 5913d8c
Showing 1 changed file with 41 additions and 11 deletions.
52 changes: 41 additions & 11 deletions include/functions.inc.php
Expand Up @@ -8,6 +8,38 @@
*/
function smart_make_associations($cat_id)
{
global $logger;

$logger->debug(__FUNCTION__);
// is the current album thumbnail associated to the album? If not, then we won't
// refresh it after associations reset. It would mean the album thumbnail is
// already in another album.
$album_thumbnail_was_in_album = false;

$query = '
SELECT representative_picture_id
FROM '.CATEGORIES_TABLE.'
WHERE id = '.$cat_id.'
;';
list($rep_id) = pwg_db_fetch_row(pwg_query($query));

if (!empty($rep_id))
{
$query = '
SELECT
COUNT(*)
FROM '.IMAGE_CATEGORY_TABLE.'
WHERE category_id = '.$cat_id.'
AND image_id = '.$rep_id.'
;';
list($count) = pwg_db_fetch_row(pwg_query($query));

if ($count > 0)
{
$album_thumbnail_was_in_album = true;
}
}

$query = '
DELETE FROM '.IMAGE_CATEGORY_TABLE.'
WHERE
Expand Down Expand Up @@ -36,18 +68,16 @@ function smart_make_associations($cat_id)
);
}

// representant, try to not overwrite if still in images list
$query = '
SELECT representative_picture_id
FROM '.CATEGORIES_TABLE.'
WHERE id = '.$cat_id.'
;';
list($rep_id) = pwg_db_fetch_row(pwg_query($query));

if (!in_array($rep_id, $images))
if ($album_thumbnail_was_in_album)
{
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
set_random_representant(array($cat_id));
$logger->debug(__FUNCTION__.' album thumbnail was in album');
// if the album thumbnail was already in the album and is still in the album, then do nothing here
if (!in_array($rep_id, $images))
{
$logger->debug(__FUNCTION__.' and is no longer in album, so we reset the album thumbnail');
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
set_random_representant(array($cat_id));
}
}

$query = '
Expand Down

0 comments on commit 5913d8c

Please sign in to comment.