diff --git a/CHANGELOG.md b/CHANGELOG.md index a9f88134..a51dbf33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Release Notes for Blitz +## 5.9.0 - Unreleased + +### Added + +- Added the ability to ignore hints in the Blitz Hints utility. + ## 5.8.1 - 2024-10-01 ### Fixed diff --git a/composer.json b/composer.json index 0a47cf91..c6a955bb 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "putyourlightson/craft-blitz", "description": "Intelligent static page caching for creating lightning-fast sites.", - "version": "5.8.1", + "version": "5.9.0", "type": "craft-plugin", "homepage": "https://putyourlightson.com/plugins/blitz", "license": "proprietary", diff --git a/src/Blitz.php b/src/Blitz.php index 96a86f83..949f3304 100644 --- a/src/Blitz.php +++ b/src/Blitz.php @@ -116,7 +116,7 @@ public static function config(): array /** * @inheritdoc */ - public string $schemaVersion = '5.8.0'; + public string $schemaVersion = '5.9.0'; /** * @inheritdoc diff --git a/src/controllers/HintsController.php b/src/controllers/HintsController.php index 1f1b0cc9..2b4c3eeb 100644 --- a/src/controllers/HintsController.php +++ b/src/controllers/HintsController.php @@ -43,4 +43,17 @@ public function actionClear(): Response return $this->redirectToPostedUrl(); } + + /** + * Ignores a specific hint. + */ + public function actionIgnore(): Response + { + $this->requirePostRequest(); + + $id = Craft::$app->getRequest()->getRequiredBodyParam('id'); + Blitz::$plugin->hints->ignore($id); + + return $this->redirectToPostedUrl(); + } } diff --git a/src/helpers/HintsHelper.php b/src/helpers/HintsHelper.php index 0de8d19b..f102a1d0 100644 --- a/src/helpers/HintsHelper.php +++ b/src/helpers/HintsHelper.php @@ -21,7 +21,9 @@ class HintsHelper extends Component */ public static function getCount(): int { - return HintRecord::find()->count(); + return HintRecord::find() + ->where(['ignored' => false]) + ->count(); } /** @@ -35,6 +37,7 @@ public static function getAll(): array /** @var HintRecord[] $hintRecords */ $hintRecords = HintRecord::find() + ->where(['ignored' => false]) ->orderBy(['dateUpdated' => SORT_DESC]) ->all(); diff --git a/src/migrations/Install.php b/src/migrations/Install.php index e7a1ef69..cc13abd5 100644 --- a/src/migrations/Install.php +++ b/src/migrations/Install.php @@ -192,6 +192,7 @@ protected function createTables(): bool 'template' => $this->string()->notNull(), 'line' => $this->integer(), 'stackTrace' => $this->text(), + 'ignored' => $this->boolean(), 'dateCreated' => $this->dateTime()->notNull(), 'dateUpdated' => $this->dateTime()->notNull(), 'uid' => $this->uid(), diff --git a/src/migrations/m241001_120000_add_ignored_column.php b/src/migrations/m241001_120000_add_ignored_column.php new file mode 100644 index 00000000..9d54f3f5 --- /dev/null +++ b/src/migrations/m241001_120000_add_ignored_column.php @@ -0,0 +1,31 @@ +db->columnExists(HintRecord::tableName(), 'ignored')) { + $this->addColumn(HintRecord::tableName(), 'ignored', $this->boolean()->defaultValue(false)->after('stackTrace')); + } + + return true; + } + + /** + * @inheritdoc + */ + public function safeDown(): bool + { + echo self::class . " cannot be reverted.\n"; + + return true; + } +} diff --git a/src/models/HintModel.php b/src/models/HintModel.php index 5148e4ef..90446659 100644 --- a/src/models/HintModel.php +++ b/src/models/HintModel.php @@ -41,6 +41,11 @@ class HintModel extends Model */ public array $stackTrace = []; + /** + * @var bool + */ + public bool $ignored = false; + /** * @var DateTime|null */ diff --git a/src/records/HintRecord.php b/src/records/HintRecord.php index 52c57685..ff66642e 100644 --- a/src/records/HintRecord.php +++ b/src/records/HintRecord.php @@ -14,6 +14,7 @@ * @property string $template * @property int $line * @property array $stackTrace + * @property bool $ignored * @property DateTime $lastUpdated */ class HintRecord extends ActiveRecord diff --git a/src/services/HintsService.php b/src/services/HintsService.php index b38e9b30..16c92acd 100644 --- a/src/services/HintsService.php +++ b/src/services/HintsService.php @@ -52,6 +52,19 @@ public function clear(int $id): void ]); } + /** + * Ignores a hint. + * + * @since 5.9.0 + */ + public function ignore(int $id): void + { + HintRecord::updateAll( + ['ignored' => true], + ['id' => $id], + ); + } + /** * Checks for opportunities to eager-load elements. */ diff --git a/src/templates/_utilities/hints/components/hints.twig b/src/templates/_utilities/hints/components/hints.twig index 0c8bf186..d9c3d23c 100644 --- a/src/templates/_utilities/hints/components/hints.twig +++ b/src/templates/_utilities/hints/components/hints.twig @@ -22,7 +22,7 @@