diff --git a/comments-bundle/CHANGELOG.md b/comments-bundle/CHANGELOG.md index 708fdade6c5..a310ce02a4e 100644 --- a/comments-bundle/CHANGELOG.md +++ b/comments-bundle/CHANGELOG.md @@ -2,5 +2,6 @@ ## DEV + * Remove subscriptions that are not activated within 24 hours (see contao/core-bundle#1512). * Append the parent ID to the form field IDs to prevent duplicate IDs (see contao/core-bundle#1493). * Replace `
` (see contao/core#2244). diff --git a/comments-bundle/src/Resources/contao/classes/Comments.php b/comments-bundle/src/Resources/contao/classes/Comments.php index e820b850cca..e0dd7650e42 100644 --- a/comments-bundle/src/Resources/contao/classes/Comments.php +++ b/comments-bundle/src/Resources/contao/classes/Comments.php @@ -506,6 +506,24 @@ public function convertLineFeeds($strComment) return preg_replace(array_keys($arrReplace), array_values($arrReplace), $strComment); } + /** + * Purge subscriptions that have not been activated within 24 hours + */ + public function purgeSubscriptions() + { + $objNotify = \CommentsNotifyModel::findExpiredSubscriptions(); + + if ($objNotify === null) + { + return; + } + + foreach ($objNotify as $objModel) + { + $objModel->delete(); + } + } + /** * Add the subscription and send the activation mail (double opt-in) * diff --git a/comments-bundle/src/Resources/contao/config/config.php b/comments-bundle/src/Resources/contao/config/config.php index df693ba3574..fba7f658fcf 100644 --- a/comments-bundle/src/Resources/contao/config/config.php +++ b/comments-bundle/src/Resources/contao/config/config.php @@ -23,3 +23,6 @@ 'stylesheet' => 'bundles/contaocomments/comments.min.css' ) )); + +// Cron jobs +$GLOBALS['TL_CRON']['daily']['purgeCommentSubscriptions'] = array('Comments', 'purgeSubscriptions'); diff --git a/comments-bundle/src/Resources/contao/models/CommentsNotifyModel.php b/comments-bundle/src/Resources/contao/models/CommentsNotifyModel.php index c168c07d90c..06c821086a5 100644 --- a/comments-bundle/src/Resources/contao/models/CommentsNotifyModel.php +++ b/comments-bundle/src/Resources/contao/models/CommentsNotifyModel.php @@ -124,6 +124,20 @@ public static function findActiveBySourceAndParent($strSource, $intParent, array return static::findBy(array("$t.source=? AND $t.parent=? AND tokenConfirm=''"), array($strSource, $intParent), $arrOptions); } + + /** + * Find subscriptions that have not been activated for more than 24 hours + * + * @param array $arrOptions An optional options array + * + * @return Model\Collection|CommentsNotifyModel[]|CommentsNotifyModel|null A collection of models or null if there are no active subscriptions + */ + public static function findExpiredSubscriptions(array $arrOptions=array()) + { + $t = static::$strTable; + + return static::findBy(array("$t.addedOn AND $t.tokenConfirm!=''"), array(strtotime('-1 day')), $arrOptions); + } } class_alias(CommentsNotifyModel::class, 'CommentsNotifyModel');