<?php

namespace App\Controllers\CLI\Cloudflare\API;

use App\Entities\Cloudflare\API\AuthEntity;

class Auth extends API
{
    final public function execute()
    {
        try {
            $entitys = $this->getAuthModel()->asObject(AuthEntity::class)->where(['status' => 'use'])->findAll();
            //transation처리
            // $this->getAuthModel()->db->transBegin();
            foreach ($entitys as $entity) {
                $api = new \App\Libraries\Cloudflare\API\Account($entity);
                $api->reload();
            }
            //transation 완료
            // $this->getAuthModel()->db->transCommit();
            echo __METHOD__ . "에서 Account Reload 완료";
        } catch (\Exception $e) {
            //transaction 오류복구
            // $this->getAuthModel()->db->transRollback();
            $message = __METHOD__ . "에서 Account Reload 오류\n" . $e->getMessage();
            log_message("error", $message);
            echo $message;
        }
    }
}
