<?php
/********************************************************************************
 * (c)1337 aheadware.com - All rights reserved
 ********************************************************************************/

require_once __DIR__ . '/../../config/boot_global.php';
require_once __DIR__ . '/../../config/boot_local.php';


class TB_Server_Cron_SendPasswordReset extends TB_Server_Core_CronBase {
    /**
     * @throws Exception
     * @throws phpmailerException
     */
    protected function run() {
        $cnt = 0;
        $pwrs = TB_Shared_Ent_Core_PasswordReset::getForSending();
        /** @var TB_Shared_Ent_Core_PasswordReset $pwr */
        foreach( $pwrs as $pwr ) {
            $data = array(
                'email' => $pwr->email,
                'pwr_link' => TB_Server_Core_Request::createClientUrl( 'Auth', 'reset_password', array( 't' => $pwr->token ) )
            );
            TB_Server_Utils_Mail::sendPasswordReset( $data );
            $pwr->state = TB_Shared_Ent_Core_PasswordReset::STATE_DELIVERED;
            $pwr->save();
        }

    }
}

$cron = new TB_Server_Cron_SendPasswordReset();
$cron->execute();