Blame view

src/Request/TTRequestImpl/TTRequestClass.php 2.48 KB
0b6b2080   Elena.Budnik   TT download
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php 
/**
 * @class TTRequestClass
 * @brief Implementation of a  
 
 */
class TTRequestClass extends RequestAbstractClass
{
	 /*
	 * @brief Init a process request of type "run"
	*/
	public function init()
	{	
		if (!isset($this->requestData))
			return false;
			
		if ($this->requestData->getCmd() == '')
		{
			$this->requestData->setLastErrorMessage('No process command defined');
			return false;
		}

		if ($this->requestData->getOutputDir() == '')
		{
			$this->requestData->setLastErrorMessage('No output dir defined');
			return false;
		}

		if (!is_dir($this->requestData->getOutputDir()))
		{
			if (!mkdir($this->requestData->getOutputDir(),0777) || !is_dir($this->requestData->getOutputDir()))
			{
				$this->requestData->setLastErrorMessage('Cannot create output dir');
				return false;
			}			
		}
		
		if (!file_exists($this->requestData->getOutputDir()."app.properties"))
			KernelConfigClass::write($this->requestData->getOutputDir(), "", "");
			
		$this->requestData->setEnvVars(KernelConfigClass::getExecEnvVarArray());
		
		return true;
	}
	
	/*
	 * @brief Run a process request
	*/
	
	public function run()
	{
		if (!isset($this->requestData))
			return false;

		$this->requestData->setSuccess(false);
		$this->requestData->setLastErrorMessage('Cannot run process request');
					
		switch ($this->requestData->getType())
		{
			case FunctionTypeEnumClass::TTCONVERT :
				//run process 
				 
				$args = $this->requestData->getInputFileName()." ".$this->requestData->getInputFileFormat() 
				        ." ".$this->requestData->getOutputDir()." ".$this->requestData->getOutputFileName()
				        ." ".$this->requestData->getOutputFileFormat();
			              
				$cmd = $this->requestData->getCmd()." ".$args;
				 
			 	$process = new ProcessClass($cmd); //, $postProcessCmd);
			 	
			 	if (!$process->run($this->requestData->getOutputDir(), $this->requestData->getEnvVars()))
					return array("success" => false, "message" => "Cannot run the TT process");
					
			 	//TBD   
ddb6bf06   Elena.Budnik   wait for process ...
75
76
			 	while ($process->isRunning() && ( time() - $process->getRunningStart() ) < KernelConfigClass::getTimeToBatchMode()) {
						sleep(1);	 
0b6b2080   Elena.Budnik   TT download
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
				}				
				
			 	 $result = array('success' => true);
			 	 
				break;			
			default :
				$this->requestData->setLastErrorMessage("TT process method not implemented");
				return false;
		}

		$this->requestData->setSuccess($result['success']);

		if (!$result['success'])
			$this->requestData->setLastErrorMessage($result['message']);

		return ($result['success']);
	}
	  
}
?>