Magento Cron Job Name: captcha_delete_old_attemps

  • Detailed Explanation:
  • When an administrator enters correct credentials but enter the wrong captcha, it counts against you as a Login Attempt. This count is get stored in 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 <?'
             =>Mage::getSingleton('core/date')->gmtDate(null, time() - 60*30)));
          }

    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 current time.

  • XML of cron job as in config.xml is:-captcha_delete_old_attemps_config
  • From this we can make out that this job will be executed every in every 30 minuets.

  • Function Code:-
  •  public function deleteOldAttempts()
                {
                    Mage::getResourceModel('captcha/log')->deleteOldAttempts();
                    return $this;
                }
  • Database related comments :-

    ‘captcha_log’: This table is count the attempt the captcha.

    Sql query to delete:-

    DELETE FROM `captcha_log` WHERE (updated_at < '2014-06-10 20:01:15')

    Schema of Table:

    FieldTypeNullKeyDefault
    typeVarchar(32)NoNone
    valueVarchar(32)NoNone
    countint(10)No0
    updated_idtimestampyesNull

    Example:

    typevaluecountUpdated_at
    2fdfdfd12014-06-10 13:04:27