-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Derrick Heesbeen
authored and
Derrick Heesbeen
committed
Nov 6, 2017
1 parent
2c06889
commit e021309
Showing
4 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/** | ||
* A Magento 2 module named Experius/EmailCatcher | ||
* Copyright (C) 2016 Derrick Heesbeen | ||
* | ||
* This file included in Experius/EmailCatcher is licensed under OSL 3.0 | ||
* | ||
* http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) | ||
* Please see LICENSE.txt for the full text of the OSL 3.0 license | ||
*/ | ||
|
||
namespace Experius\EmailCatcher\Controller\Adminhtml\Emailcatcher; | ||
|
||
|
||
class Cleanup extends \Magento\Backend\App\Action { | ||
|
||
protected $clean; | ||
|
||
public function __construct( | ||
\Magento\Backend\App\Action\Context $context, | ||
\Magento\Framework\View\Result\PageFactory $resultPageFactory, | ||
\Experius\EmailCatcher\Cron\Clean $clean | ||
){ | ||
$this->clean = $clean; | ||
|
||
parent::__construct($context); | ||
} | ||
|
||
|
||
public function execute(){ | ||
|
||
$resultRedirect = $this->resultRedirectFactory->create(); | ||
|
||
try { | ||
$deleteCount = $this->clean->execute(); | ||
} catch (\Exception $e){ | ||
$this->messageManager->addError($e->getMessage()); | ||
return $resultRedirect->setPath('*/*/'); | ||
} | ||
|
||
$this->messageManager->addSuccessMessage(__('Removed %1 records from %2 days ago or older',$deleteCount,'30')); | ||
|
||
return $resultRedirect->setPath('*/*/'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
|
||
namespace Experius\EmailCatcher\Cron; | ||
|
||
class Clean | ||
{ | ||
|
||
protected $logger; | ||
|
||
protected $resourceConnection; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param \Psr\Log\LoggerInterface $logger | ||
*/ | ||
public function __construct( | ||
\Psr\Log\LoggerInterface $logger, | ||
\Magento\Framework\App\ResourceConnection $resourceConnection | ||
){ | ||
$this->logger = $logger; | ||
$this->resourceConnection = $resourceConnection; | ||
$this->connection = $this->resourceConnection->getConnection(); | ||
} | ||
|
||
/** | ||
* Execute the cron | ||
* | ||
* @return void | ||
*/ | ||
public function execute() | ||
{ | ||
|
||
$numberOfDays = 30; | ||
|
||
$where = "created_at < '" . date('c', time()-($numberOfDays*(3600*24))) ."'"; | ||
|
||
$deleteCount = $this->connection->delete( | ||
$this->resourceConnection->getTableName('experius_emailcatcher'), | ||
$where | ||
); | ||
|
||
$this->logger->addInfo(__('Experius EmailCatcher Cleanup: Removed %1 records',$deleteCount)); | ||
|
||
return $deleteCount; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" ?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd"> | ||
<group id="default"> | ||
<job instance="Experius\EmailCatcher\Cron\Clean" method="execute" name="experius_emailcatcher_clean"> | ||
<schedule>0 3 * * *</schedule> | ||
</job> | ||
</group> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters