diff --git a/CHANGELOG.md b/CHANGELOG.md index f10eabc..56a6f40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes for carbon-tracker +## 4.1.2 - 2024-09-02 +### Backport v5 bugfix +- Website carbon sidebar always showed the OLDEST carbon result instead of the NEWEST + ## 4.1.1 - 2024-09-02 ### Added - Fixed ttr on queue job @@ -21,4 +25,4 @@ - Fixed issue with failing jobs on multi-site installs ## 4.0.0 - 2024-01-02 -- Initial release 🚀 \ No newline at end of file +- Initial release 🚀 diff --git a/composer.json b/composer.json index 3eeaff4..6a158bf 100644 --- a/composer.json +++ b/composer.json @@ -1,58 +1,57 @@ { - "name": "statikbe/craft-carbon-tracker", - "description": "Carbon tracker aims to raise awareness of the carbon emissions created by webpages, by displaying these insights along side the content in Craft's control panel.", - "type": "craft-plugin", - "version": "4.1.1", - "license": "mit", - "support": { - "email": "support@statik.be", - "issues": "https://github.com/statikbe/craft-carbon-tracker/issues?state=open", - "source": "https://github.com/statikbe/craft-carbon-tracker", - "docs": "https://github.com/statikbe/craft-carbon-tracker", - "rss": "https://github.com/statikbe/craft-carbon-tracker/releases.atom" - }, - "require": { - "php": ">=8.0.2", - "craftcms/cms": "^4.5.0" - }, - "require-dev": { - "craftcms/ecs": "dev-main", - "craftcms/phpstan": "dev-main" - }, - "authors": [ - { - "name": "Jan Henckens", - "email": "jan@statik.be", - "homepage": "https://www.statik.de" - } - ], - "autoload": { - "psr-4": { - "statikbe\\carbontracker\\": "src/" - } - }, - "extra": { - "handle": "carbon-tracker", - "name": "Carbon Emissions Tracker", - "developer": "Statik.be", - "documentationUrl": "https://github.com/statikbe/craft-carbon-tracker", - "class": "statikbe\\carbontracker\\CarbonTracker" - }, - "scripts": { - "check-cs": "ecs check --ansi", - "fix-cs": "ecs check --ansi --fix", - "phpstan": "phpstan --memory-limit=1G", - "ci": "ecs check --ansi --fix && phpstan --memory-limit=1G" + "name": "statikbe/craft-carbon-tracker", + "description": "Carbon tracker aims to raise awareness of the carbon emissions created by webpages, by displaying these insights along side the content in Craft's control panel.", + "type": "craft-plugin", + "version": "4.1.2", + "license": "mit", + "support": { + "email": "support@statik.be", + "issues": "https://github.com/statikbe/craft-carbon-tracker/issues?state=open", + "source": "https://github.com/statikbe/craft-carbon-tracker", + "docs": "https://github.com/statikbe/craft-carbon-tracker", + "rss": "https://github.com/statikbe/craft-carbon-tracker/releases.atom" + }, + "require": { + "php": ">=8.0.2", + "craftcms/cms": "^4.5.0" + }, + "require-dev": { + "craftcms/ecs": "dev-main", + "craftcms/phpstan": "dev-main" + }, + "authors": [ + { + "name": "Jan Henckens", + "email": "jan@statik.be", + "homepage": "https://www.statik.de" + } + ], + "autoload": { + "psr-4": { + "statikbe\\carbontracker\\": "src/" + } + }, + "extra": { + "handle": "carbon-tracker", + "name": "Carbon Emissions Tracker", + "developer": "Statik.be", + "documentationUrl": "https://github.com/statikbe/craft-carbon-tracker", + "class": "statikbe\\carbontracker\\CarbonTracker" + }, + "scripts": { + "check-cs": "ecs check --ansi", + "fix-cs": "ecs check --ansi --fix", + "phpstan": "phpstan --memory-limit=1G", + "ci": "ecs check --ansi --fix && phpstan --memory-limit=1G" + }, + "config": { + "sort-packages": true, + "platform": { + "php": "8.0.2" }, - "config": { - "sort-packages": true, - "platform": { - "php": "8.0.2" - }, - "allow-plugins": { - "yiisoft/yii2-composer": true, - "craftcms/plugin-installer": true - } + "allow-plugins": { + "yiisoft/yii2-composer": true, + "craftcms/plugin-installer": true } + } } - diff --git a/src/services/StatsService.php b/src/services/StatsService.php index 88add60..b85527c 100644 --- a/src/services/StatsService.php +++ b/src/services/StatsService.php @@ -13,12 +13,14 @@ class StatsService extends Component { public function getDataForEntry(Entry $entry): SiteStatisticsModel|bool { - $record = SiteStatisticsRecord::findOne(['entryId' => $entry->id, 'siteId' => $entry->siteId]); - - if (!$record) { - // Search again without the siteId - $record = SiteStatisticsRecord::findOne(['entryId' => $entry->id]); - if (!$record) { + /** @var SiteStatisticsRecord|null $record */ + $record = SiteStatisticsRecord::find()->where(['entryId' => $entry->id])->andWhere(['siteId' => $entry->siteId])->orderBy('id DESC')->one(); + + // INFO: if we don't find a record, we'll try to find one without the siteId + if ($record === null) { + /** @var SiteStatisticsRecord|null $record */ + $record = SiteStatisticsRecord::find()->where(['entryId' => $entry->id])->orderBy('id DESC')->one(); + if ($record === null) { return false; } }