forked from coldsource/evqueue-frontend-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport.php
More file actions
44 lines (33 loc) · 1.34 KB
/
export.php
File metadata and controls
44 lines (33 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
require_once __DIR__ . '/includes/inc/auth_check.php';
require_once __DIR__ . '/includes/inc/logger.php';
$filename = tempnam('/tmp','evqueue-frontend-');
$zip = new ZipArchive();
$zip->open($filename,ZipArchive::CREATE|ZipArchive::OVERWRITE);
// Fetch workflow XML
$workflow_xml = $evqueue->Api('workflow','get',[ 'id' => $_GET['workflow_id'] ]);
$workflow_dom = new DOMDocument();
$workflow_dom->loadXML($workflow_xml);
$workflow_xml = $workflow_dom->saveXML($workflow_dom->documentElement->firstChild);
$zip->addFromString('workflow.xml',$workflow_xml);
// Fetch dependencies (ie tasks that are used by this workflow)
$workflow_xpath = new DOMXPath($workflow_dom);
$workflow_name = $workflow_xpath->evaluate('string(/response/workflow/@name)');
$tasks = $workflow_xpath->query('//task');
foreach($tasks as $task)
{
// Fetch task description and add to Zip
$task_name = $task->getAttribute('name');
$task_xml = $evqueue->Api('task','search',[ 'name' => $task_name]);
$task_dom = new DOMDocument();
$task_dom->loadXML($task_xml);
$task_xml = $task_dom->saveXML($task_dom->documentElement->firstChild);
$zip->addFromString("tasks/$task_name.xml",$task_xml);
}
$zip->close();
// Stream zip file
header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=$workflow_name.zip");
readfile($filename);
unlink($filename);
?>