Home » Blogs » Magento Cron: Captcha Delete Old Attemps

Magento Cron: Captcha Delete Old Attemps

Detailed Explanation:

When an administrator enters correct credentials but enters the wrong captcha, it counts against you as a Login Attempt. This count is get stored in the table named ‘captcha_log’ with value and time. The role of captcha_delete_old_attemps cron job is to remove all entries of login attempt from ‘captcha_log’ table.
Now, we will see how this cron remove all entries.
Mage::getResourceModel(‘captcha/log’)
This line fetching collection of ‘captcha_log’ table.


public function deleteOldAttempts()
{
      $this->_getWriteAdapter()->delete($this->getMainTable(),array('updated_at 
}
time():1402407940 (In this case, this is time when cron is executed in timestamp)
time() – 60*30:1402406403 (In timestamp)
gmtDate(null):Convert timestamp to date/time format
DELETE FROM `captcha_log` WHERE (updated_at < '2014-06-10 20:01:15')
This function removes the record from table ‘captcha_log’ which was updated before the current time.

XML of cron job as in config.xml is:-
From this, we can make out that this job will be executed every in every 30 minutes.
Function Code:-

public function deleteOldAttempts()
{
       Mage::getResourceModel('captcha/log')->deleteOldAttempts();
       return $this;
}
Database related comments:-
‘captcha_log’: This table counts the attempt the captcha.
Sql query to delete:-
DELETE FROM `captcha_log` WHERE (updated_at < ‘2014-06-10 20:01:15’)
Schema of Table:

Field Type Null Key Default
type Varchar(32) No None
value Varchar(32) No None
count int(10) No 0
updated_id timestamp yes Null
Example:
type value count Updated_at
2 fdfdfd 1 2014-06-10 13:04:27

Leave A Comment