Skip to content

Commit

Permalink
[Comments] Remove subscriptions that are not activated within 24 hour…
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Jun 28, 2018
1 parent fe25a17 commit 0c9ea83
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions comments-bundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<div class="quote">` with `<blockquote>` (see contao/core#2244).
18 changes: 18 additions & 0 deletions comments-bundle/src/Resources/contao/classes/Comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*
Expand Down
3 changes: 3 additions & 0 deletions comments-bundle/src/Resources/contao/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@
'stylesheet' => 'bundles/contaocomments/comments.min.css'
)
));

// Cron jobs
$GLOBALS['TL_CRON']['daily']['purgeCommentSubscriptions'] = array('Comments', 'purgeSubscriptions');
Original file line number Diff line number Diff line change
Expand Up @@ -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');

0 comments on commit 0c9ea83

Please sign in to comment.