Image sync method fixes
gitea/hedera-web/pipeline/head This commit looks good Details

This commit is contained in:
Juan Ferrer 2020-08-29 13:48:32 +02:00
parent 6c59b72023
commit 079e9266f1
4 changed files with 30 additions and 15 deletions

2
debian/changelog vendored
View File

@ -1,4 +1,4 @@
hedera-web (1.407.27) stable; urgency=low
hedera-web (1.407.28) stable; urgency=low
* Initial Release.

1
debian/cron.d vendored
View File

@ -5,4 +5,5 @@ MAILTO=webmaster
0 23 * * * root hedera-web.php -m edi/clean
0 5 * * * root hedera-web.php -m edi/update
0 5 * * * root hedera-web.php -m misc/exchange-rate
0 0 * * * root hedera-web.php -m image/sync
0 */1 * * * root /usr/share/hedera-web/utils/update-browscap.sh > /dev/null

View File

@ -1,6 +1,6 @@
{
"name": "hedera-web",
"version": "1.407.27",
"version": "1.407.28",
"description": "Verdnatura web page",
"license": "GPL-3.0",
"repository": {

View File

@ -49,22 +49,36 @@ class Sync extends Vn\Lib\Method {
// Deletes unreferenced images.
$res = $db->query(
'SELECT `name`, collectionFk
FROM `image`
WHERE nRefs = 0 AND collectionFk = #collection',
['collection' => $collection]
);
try {
$db->query('START TRANSACTION');
$res = $db->query(
'SELECT id, `name`, collectionFk
FROM `image`
WHERE nRefs = 0 AND collectionFk = #collection
FOR UPDATE',
['collection' => $collection]
);
while ($image = $res->fetch_object()) {
$deleteCount++;
$this->recycle("$collection/full/{$image->name}.png");
while ($image = $res->fetch_object())
if (!empty($image) && !in_array($image->name, ['.', '..'])) {
$deleteCount++;
$this->recycle("$collection/full/{$image->name}.png");
foreach ($info['sizes'] as $size => $i)
$this->recycle("$collection/$size/{$image->name}.png");
foreach ($info['sizes'] as $size => $i)
$this->recycle("$collection/$size/{$image->name}.png");
$db->query(
'DELETE FROM `image`
WHERE nRefs = 0 AND id = #id',
['id' => $image->id]
);
}
$res->free();
$db->query('COMMIT');
} catch(Exception $e) {
$db->query('ROLLBACK');
}
$res->free();
}
echo "Syncronization finished. $deleteCount images moved to trash.\n";