Added export button to Pipework
This commit is contained in:
@@ -4,8 +4,12 @@ class PipeworkController extends mfBaseController {
|
||||
|
||||
protected function init() {
|
||||
$this->needlogin=true;
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
$me = mfValuecache::singleton()->get("me");
|
||||
if(!$me) {
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
mfValuecache::singleton()->set("me", $this->me);
|
||||
}
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me",$me);
|
||||
|
||||
@@ -33,6 +37,19 @@ class PipeworkController extends mfBaseController {
|
||||
$pagination['start'] = intval($this->request->s);
|
||||
}
|
||||
|
||||
if($this->request->export) {
|
||||
$this->layout()->setTemplate("Pipework/export.xls");
|
||||
$pagination = [];
|
||||
}
|
||||
if($this->request->export_progress) {
|
||||
$this->layout()->setTemplate("Pipework/export_progress.xls");
|
||||
if($this->request->uid) {
|
||||
$this->layout()->set("export_uid", $this->request->uid);
|
||||
$this->layout()->set("path", BASEDIR."/var/temp/export");
|
||||
}
|
||||
$pagination = [];
|
||||
}
|
||||
|
||||
$my_networks = [];
|
||||
|
||||
// get allowed networks
|
||||
@@ -149,6 +166,119 @@ class PipeworkController extends mfBaseController {
|
||||
return $new_filter;
|
||||
}
|
||||
|
||||
public function startExport($request) {
|
||||
$this->request = new mfRequest($request);
|
||||
//var_dump($request);exit;
|
||||
return $this->indexAction();
|
||||
}
|
||||
|
||||
protected function exportAction() {
|
||||
$uid = "wfExport_".uniqid()."-".mt_rand(10000,99999);
|
||||
|
||||
$method = "http";
|
||||
if($_SERVER['HTTPS'] == "on") {
|
||||
$method = "https";
|
||||
}
|
||||
|
||||
$get = $this->request->get();
|
||||
unset($get['mod']);
|
||||
unset($get['action']);
|
||||
$get['export_progress'] = 1;
|
||||
$get['uid'] = $uid;
|
||||
$url = $method."://".$_SERVER['HTTP_HOST'].$this->getUrl("Pipework", "Index", $get);
|
||||
$url = escapeshellarg($url);
|
||||
//var_dump($url);exit;
|
||||
|
||||
$progress = new WorkflowExport();
|
||||
$progress->uid = $uid;
|
||||
$progress->create_by = $this->me->id;
|
||||
$progress->edit_by = $this->me->id;
|
||||
$progress->save();
|
||||
/*
|
||||
$cmd = "nohup curl ".$url." >/dev/null 2>&1 &";
|
||||
var_dump($cmd);exit;
|
||||
// start excel generation in background and dont wait
|
||||
exec($cmd);
|
||||
*/
|
||||
|
||||
$cmd = BASEDIR."/scripts/start_workflow_export.php";
|
||||
$args = "";
|
||||
|
||||
$get['filter']['type'] = "Pipework";
|
||||
$get['filter']['user_id'] = $this->me->id;
|
||||
|
||||
foreach($get['filter'] as $key => $value) {
|
||||
$args .= " ".escapeshellarg("--$key")." ". escapeshellarg($value);
|
||||
}
|
||||
|
||||
|
||||
$cmd = "$cmd --uid ". escapeshellarg($uid)." $args >/dev/null 2>&1 &";
|
||||
$this->log->debug($cmd);
|
||||
exec($cmd);
|
||||
|
||||
// return progress
|
||||
$this->returnJson(['status' => "OK", 'uid' => $uid, "progress" => 0]);
|
||||
}
|
||||
|
||||
protected function exportProgressAction() {
|
||||
$uid = $this->request->uid;
|
||||
if(!$uid) {
|
||||
$this->returnJson(['status' => "error", "msg" => "no uid"]);
|
||||
}
|
||||
|
||||
$progress = new WorkflowExport();
|
||||
$progress->loadByUid($this->request->uid);
|
||||
if(!$progress->id) {
|
||||
$this->returnJson(['status' => "error", "msg" => "export not found"]);
|
||||
}
|
||||
|
||||
$this->returnJson(['status' => "OK", 'export_uid ' => $uid, 'progress' => $progress->progress]);
|
||||
}
|
||||
|
||||
protected function downloadExportAction() {
|
||||
$uid = $this->request->uid;
|
||||
if(!$uid) {
|
||||
$this->returnJson(['status' => "error", "msg" => "no uid"]);
|
||||
}
|
||||
|
||||
$progress = new WorkflowExport();
|
||||
$progress->loadByUid($this->request->uid);
|
||||
if(!$progress->id) {
|
||||
$this->returnJson(['status' => "error", "msg" => "export not found"]);
|
||||
}
|
||||
|
||||
$file = BASEDIR."/var/temp/export/".$progress->filename;
|
||||
|
||||
if (!$fh = fopen($file, 'r')) {
|
||||
$this->layout()->setFlash("Fehler beim Export.", "error");
|
||||
$this->redirect("Linework");
|
||||
return false;
|
||||
}
|
||||
|
||||
set_time_limit(36000);
|
||||
header("Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
header('Content-disposition: attachment; filename="' . $progress->filename . '"');
|
||||
|
||||
$size = exec('stat -c %s '.escapeshellarg($file));
|
||||
|
||||
$this->log->debug("filename: ".$file);
|
||||
$this->log->debug("filesize: ".$size);
|
||||
|
||||
if(strlen($size)) {
|
||||
if($size < (pow(2,31))-1) {
|
||||
header('Content-Length: ' . $size);
|
||||
}
|
||||
}
|
||||
|
||||
while (!feof($fh)) {
|
||||
$data = fread($fh, 8192);
|
||||
echo $data;
|
||||
}
|
||||
exit;
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
//var_dump($r->get());exit;
|
||||
|
||||
Reference in New Issue
Block a user