Log in

View Full Version : recalculation picture counts


sailnet
11-30-2009, 10:57 PM
I have an external program which runs outside of vb adding records to the pictures tables and it also updates the album, albumpicture and albumupdate tables.

it's working great except that vb is not recalculating the number of of pictures in the album (well - vb is not displaying the correct number of pictures in the album on it's screens). I've looked through the code and found the function which does this in class_dm_album.php but there does not appear to an update statement at the end of the function. so where is this information stored?

* Rebuilds counts for an album
*
*/
function rebuild_counts()
{
if (!$this->fetch_field('albumid'))
{
return;
}

$counts = $this->registry->db->query_first("
SELECT
SUM(IF(picture.state = 'visible', 1, 0)) AS visible,
SUM(IF(picture.state = 'moderation', 1, 0)) AS moderation,
MAX(IF(picture.state = 'visible', albumpicture.dateline, 0)) AS lastpicturedate
FROM " . TABLE_PREFIX . "albumpicture AS albumpicture
INNER JOIN " . TABLE_PREFIX . "picture AS picture ON (albumpicture.pictureid = picture.pictureid)
WHERE albumpicture.albumid = " . $this->fetch_field('albumid') . "

");

$this->set('visible', $counts['visible']);
$this->set('moderation', $counts['moderation']);
$this->set('lastpicturedate', $counts['lastpicturedate']);
}

so - how do I get the count of pictures in an album to get updated properly outside of vb?

thanks in advance.

I suppose I could take all of my code and move it inside of a vbulletin module (or at least create a new module and just run that module and attempt to figure out how this function is called, but that's clearly not my prerference.

thanks in advance for any help you can give or direction.

kh99
11-30-2009, 11:21 PM
That class extends vB_DataManager, which means some of the functions are in class_dm.php.

I think you could probably do the query like it's done in the code above, then use the results to update the album table 'visible', 'moderation', and 'lastpicturedate' fields for that albumid using an UPDATE query.

sailnet
12-01-2009, 02:46 AM
That class extends vB_DataManager, which means some of the functions are in class_dm.php.

I think you could probably do the query like it's done in the code above, then use the results to update the album table 'visible', 'moderation', and 'lastpicturedate' fields for that albumid using an UPDATE query.

yes, but I already do that in my code. all tables are updated properly.

--------------- Added 1259672493 at 1259672493 ---------------

found it - fixed it.

cool