No photo chosen. Tried deleting block-random.dat...

AlpineZone
AlpineZone's picture

Joined: 2004-01-21
Posts: 69
Posted: Thu, 2004-09-02 13:43

I keep receiving a "No photo chosen" message on my random block. I've tried deleting the block-random.dat and it hasn't helped. Nothing has changed and the random block has worked fine for a number of weeks, aside from a few other "No photo chosen" instances which were fixed by deleting the block-random.dat file. Thoughts?

 
signe
signe's picture

Joined: 2003-07-27
Posts: 2322
Posted: Thu, 2004-09-02 18:59

Here's something you could try:

Locate

if ($rebuild) {
        scanAlbums();
        saveCache();
} else {
        readCache();
}

$album = chooseAlbum();

if (!empty($album)) {
        $index = choosePhoto($album);
}

And immediately after it, add

if (empty($index)) {
        $album = chooseAlbum();
        if (!empty($album)) {
                $index = choosePhoto($album);
        }
}

right before the section that prints the output.

This could have a slight performance impact, since you're effectively running the block twice.

 
bbackland

Joined: 2004-12-08
Posts: 4
Posted: Sat, 2005-01-01 07:08

On occasion I have had ablums selected that could not return a photo, with the code provided above. So I followed a slightly different approach to solve the problem.

Remove the previous change before applying this patch.

Find the code:

$album = chooseAlbum();
	
if (!empty($album)) {
	$index = choosePhoto($album);
}

and change it to:

$max_iterations = 5;
while ( empty($index) and $max_iterations ) {
	$album = chooseAlbum();
	
	if (!empty($album)) {
		$index = choosePhoto($album);
	}
	$max_iterations--;
}

The $max_iterations counter ensures we never end up in an endless loop. We shoudn't see the 'No photo chosen' message unless 5 albums were chosen that could not display a photo. In testing I have found that the $max_iterations is normally 4, and sometimes hits 3. This means that on occasion one hidden album is selected and even less frequently two hidden albums are selected in a row. My testing has never hit 3 in a row...