diff --git a/module/bi/control.php b/module/bi/control.php index 7c639c5e21..65eefdd94f 100644 --- a/module/bi/control.php +++ b/module/bi/control.php @@ -22,35 +22,17 @@ class bi extends control public function syncParquetFile() { $startTime = microtime(true); - $duckdb = $this->bi->getDuckDBPath(); - if(!$duckdb) - { - echo("DuckDB bin path not exists."); - return; - } - - $duckdbTmpPath = $this->bi->getDuckDBTmpDir(); - if(!$duckdbTmpPath) - { - echo("Create DuckDB tmp dir permission denied."); - return; - } - - $copySQL = $this->bi->prepareCopySQL($duckdbTmpPath); - $command = $this->bi->prepareSyncCommand($duckdb->bin, $duckdb->extension, $copySQL); - - $output = shell_exec($command); - $endTime = microtime(true); - $runTime = $endTime - $startTime; + $result = $this->bi->generateParquetFile(); + $endTime = microtime(true); + $runTime = $endTime - $startTime; echo "$runTime \n"; - if(empty($output)) + if($result !== true) { - echo('success'); + echo $result; return; } - - echo($output); + echo 'success'; } /** diff --git a/module/bi/model.php b/module/bi/model.php index 8b9ad626b8..fe6ff96799 100644 --- a/module/bi/model.php +++ b/module/bi/model.php @@ -829,9 +829,10 @@ class biModel extends model * @access public * @return string|false */ - public function getDuckDBTmpDir() + public function getDuckDBTmpDir($static = false) { $duckdbTmpPath = $this->app->getTmpRoot() . 'duckdb' . DS . 'bi' . DS; + if($static) return $duckdbTmpPath; if(!is_dir($duckdbTmpPath) && !mkdir($duckdbTmpPath, 0755, true)) return false; return $duckdbTmpPath; @@ -910,6 +911,22 @@ class biModel extends model return "$sqlContent 2>&1"; } + public function generateParquetFile() + { + $duckdb = $this->getDuckDBPath(); + if(!$duckdb) return $this->lang->bi->binNotExists; + + $duckdbTmpPath = $this->getDuckDBTmpDir(); + if(!$duckdbTmpPath) return sprintf($this->lang->bi->tmpPermissionDenied, $this->getDuckDBTmpDir(true), $this->getDuckDBTmpDir(true)); + + $copySQL = $this->prepareCopySQL($duckdbTmpPath); + $command = $this->prepareSyncCommand($duckdb->bin, $duckdb->extension, $copySQL); + $output = shell_exec($command); + if(!empty($output)) return $output; + + return true; + } + /** * Process filter variables in sql. *