diff --git a/debian/changelog b/debian/changelog index 070363ea..393fe564 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -hedera-web (1.407.27) stable; urgency=low +hedera-web (1.407.28) stable; urgency=low * Initial Release. diff --git a/debian/cron.d b/debian/cron.d index ee465ec7..73230e70 100755 --- a/debian/cron.d +++ b/debian/cron.d @@ -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 diff --git a/package.json b/package.json index 51e33b1a..ae178e33 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hedera-web", - "version": "1.407.27", + "version": "1.407.28", "description": "Verdnatura web page", "license": "GPL-3.0", "repository": { diff --git a/rest/image/sync.php b/rest/image/sync.php index 7882ebaf..eeee48ee 100644 --- a/rest/image/sync.php +++ b/rest/image/sync.php @@ -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";