コード例 #1
0
ファイル: script.php プロジェクト: ls-wang/data-import-script
        }
    }
    public function commitData($sheet = null)
    {
        if (is_null($sheet)) {
            foreach (array_keys($this->_pending_data) as $sheet) {
                $this->commitData($sheet);
            }
            return;
        }
        error_log("commiting {$sheet} {$this->_pending_data[$sheet][0][0]}");
        $curl = curl_init("https://sheethub.com{$sheet}/insert?access_token=" . getenv('access_token'));
        $params = array();
        $params[] = 'data=' . urlencode(json_encode($this->_pending_data[$sheet], JSON_UNESCAPED_UNICODE));
        $params[] = 'unique_columns[]=' . $this->_unique_column_id[$sheet];
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, implode('&', $params));
        $content = curl_exec($curl);
        $obj = json_decode($content);
        error_log($content);
        if (is_null($obj->data->count)) {
            error_log('count null, retry');
            $this->commitData($sheet);
            return;
        }
        $this->_pending_data[$sheet] = array();
    }
}
$i = new Importer();
$i->main();