Skip to content

Commit

Permalink
db messages
Browse files Browse the repository at this point in the history
  • Loading branch information
baukezwaan committed Sep 19, 2022
1 parent 9c2b296 commit 2f9bfdc
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions src/Tasks/UserFormsCleanupOldEntriesTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,33 @@

namespace Hamaka;

use SilverStripe\Control\Director;
use SilverStripe\Dev\BuildTask;
use SilverStripe\ORM\DB;
use SilverStripe\UserForms\Model\Submission\SubmittedForm;

class UserFormsCleanupOldEntriesTask extends BuildTask
{

protected $title = "UserForms Clean-up SubmittedForm task";

protected $description = "Removes old user data for privacy reasons";
protected $description = "Removes old userdata for privacy reasons";

private static $segment = 'userforms-cleanup';

private static $days_retention = 31;

public function run($request)
{

$aFeedback = [];
$iThresholdDate = strtotime('-' . $this->config()->get('days_retention') . ' days');
$sThresholdDate = date('Y-m-d 00:00:00', $iThresholdDate);
$aFeedback[] = 'Removing all entries before ' . $sThresholdDate;
DB::alteration_message('Removing all entries before ' . $sThresholdDate);

$aFeedback[] = 'Total entries in database (before cleanup): ' . SubmittedForm::get()->count();
DB::alteration_message('Total entries in database (before cleanup): ' . SubmittedForm::get()->count());

$iClearedEntries = $this->cleanUpUserForms($sThresholdDate);
$aFeedback[] = 'Total entries to be deleted: ' . $iClearedEntries;

$aFeedback[] = "Done, total entries after cleanup: " . SubmittedForm::get()->count();

if (Director::is_cli()) {
$sFeedback = implode(PHP_EOL, $aFeedback);
}
else {
$sSep = PHP_EOL . '<br>&bull; ';
$sFeedback = $sSep . implode($sSep, $aFeedback);
}
DB::alteration_message('Total entries to be deleted: ' . $iClearedEntries);

echo $sFeedback;
DB::alteration_message("Done, total entries after cleanup: " . SubmittedForm::get()->count());
}

/**
Expand Down

0 comments on commit 2f9bfdc

Please sign in to comment.