<?php

namespace web\admin\datasse;

class imgs {
    static function sse_upimg($senddata, $sendevent) {
        global $db;
        $rsuser = verifyfast();
        if (nopower($db, $rsuser['id'], 'p610r'))
            return errjson('您未被授权操作');
        //多参数建议用strparam
        //SSE支持data、type、id。其中type为空或fix。id可选，可作为另一种数据。
        $param = get('param');
        $bdel = $param == 'del';
        $senddata($bdel?'del: True':'需填写参数:del');
        $csql = new \ciy\sql('INFORMATION_SCHEMA.SCHEMATA');
        $csql->where('SCHEMA_NAME = DATABASE()');
        $sehrow = $db->getone($csql);
        $csql = new \ciy\sql('INFORMATION_SCHEMA.TABLES');
        $csql->where('TABLE_SCHEMA', $sehrow['SCHEMA_NAME']);
        $tablerows = $db->get($csql);
        //$senddata('log: ' . json_encode($row));
        foreach($tablerows as $tablerow){
            $csql = new \ciy\sql();
            $colrows = $db->getraw('show full fields from '.$tablerow['TABLE_NAME']);
            //分析col是否有saasxid
            foreach($colrows as $colrow){
                if(strpos($colrow['Comment'],',IMG') === false)
                    continue;
                //读取一条，分析库类型，是saas还是非saas的path
                //如果是saas，则分析saasid/orgid/还是saasxid
                $senddata('log: ' . $colrow['Field'].','. $colrow['Comment']);
            }
            //Comment
        }

        // for ($i = 0; $i < 100; $i++) {
        //     if ($i % 10 == 1)
        //         $senddata('ssr: ' . $i . "\n\n" . 'ddd', $i);
        //     $sendevent($i);
        //     usleep(50000);
        // }
        $sendevent('ok');
    }
}
