Merge branch 'master' of bitbucket.org:colosa/processmaker

This commit is contained in:
Wendy Nestor
2014-04-02 11:27:45 -04:00
4 changed files with 162 additions and 34 deletions

View File

@@ -136,7 +136,14 @@
</exec>
</target>
<target name="behat" description="Behaviour tests with Behat">
<target name="prepare-behat" description="Prepare Behat Env.">
<exec executable="${basedir}/../prepare_behat_env">
<arg value="--source-dir" />
<arg value="${basedir}/../" />
</exec>
</target>
<target name="behat" description="Behaviour tests with Behat" depends="prepare-behat">
<exec executable="vendor/behat/behat/bin/behat">
<arg value="--format" />
<arg value="junit,progress" />

View File

@@ -2,7 +2,7 @@
namespace Maveriks\Extension;
use Luracast\Restler\Defaults;
use Luracast\Restler\Format\UrlEncodedFormat;
/**
* Class Restler
* Extension Restler class to implement in ProcessMaker
@@ -11,6 +11,35 @@ use Luracast\Restler\Defaults;
*/
class Restler extends \Luracast\Restler\Restler
{
public $flagMultipart = false;
public $responseMultipart = array();
public $inputExecute = '';
/**
* This method to set the value flag Multipart
*
* @param boolean $multipart. flag Multipart
*
* @access public
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @return void
*/
public function setFlagMultipart($multipart = false)
{
$this->flagMultipart = ($multipart === true) ? true : false;
}
/**
* This method to print or save the api response
*
* @access public
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @return void
*/
protected function respond()
{
$this->dispatch('respond');
@@ -21,7 +50,57 @@ class Restler extends \Luracast\Restler\Restler
usleep(1e6 * (Defaults::$throttle / 1e3 - $elapsed));
}
}
echo $this->responseData;
if ($this->flagMultipart === true) {
$responseTemp['status'] = $this->responseCode;
$responseTemp['response'] = \G::json_decode($this->responseData);
$this->responseMultipart = $responseTemp;
} else {
echo $this->responseData;
}
$this->dispatch('complete');
}
/**
* This method to set request data
*
* @param boolean $includeQueryParameters.
*
* @access public
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @return void
*/
public function getRequestData($includeQueryParameters = true)
{
$get = UrlEncodedFormat::decoderTypeFix($_GET);
if ($this->requestMethod == 'PUT'
|| $this->requestMethod == 'PATCH'
|| $this->requestMethod == 'POST'
) {
if (!empty($this->requestData)) {
return $includeQueryParameters
? $this->requestData + $get
: $this->requestData;
}
if ($this->flagMultipart === false) {
$r = file_get_contents('php://input');
if (is_null($r)) {
return array(); //no body
}
} else {
$r = $this->inputExecute;
}
$r = $this->requestFormat->decode($r);
$r = is_array($r)
? array_merge($r, array(Defaults::$fullRequestDataName => $r))
: array(Defaults::$fullRequestDataName => $r);
return $includeQueryParameters
? $r + $get
: $r;
}
return $includeQueryParameters ? $get : array(); //no body
}
}

View File

@@ -8,6 +8,7 @@ class WebApplication
protected $rootDir = "";
protected $workflowDir = "";
protected $requestUri = "";
protected $responseMultipart = array();
const RUNNING_DEFAULT = "default.running";
const RUNNING_INDEX = "index.running";
@@ -78,18 +79,51 @@ class WebApplication
$this->loadEnvironment($request["workspace"]);
Util\Logger::log("API::Dispatching ".$_SERVER["REQUEST_METHOD"]." ".$request["uri"]);
$this->dispatchApiRequest($request["uri"], $request["version"]);
if (isset($_SERVER["HTTP_X_REQUESTED_WITH"]) && \G::toUpper($_SERVER["HTTP_X_REQUESTED_WITH"]) == 'MULTYPART') {
$this->multipart($request["uri"], $request["version"]);
} else {
$this->dispatchApiRequest($request["uri"], $request["version"]);
}
Util\Logger::log("API::End Dispatching ".$_SERVER["REQUEST_METHOD"]." ".$request["uri"]);
break;
}
}
/**
* This method performs the functionality of multipart
*
* @param string $version. Version Api
*
* @access public
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @return void
*/
public function multipart($uri, $version = "1.0")
{
$stringInput = file_get_contents('php://input');
if (is_null($stringInput)) {
return array(); //no body
}
$input = json_decode($stringInput);
$baseUrl = (empty($input->base_url)) ? $uri : $input->base_url;
foreach($input->calls as $value) {
$_SERVER["REQUEST_METHOD"] = (empty($value->method)) ? 'GET' : $value->method;
$uriTemp = trim($baseUrl) . trim($value->url);
$inputExecute = (empty($value->data)) ? '' : \G::json_encode($value->data);
$this->responseMultipart[] = $this->dispatchApiRequest($uriTemp, $version, true, $inputExecute);
}
echo \G::json_encode($this->responseMultipart);
}
/**
* This method dispatch rest/api service
*
* @author Erik Amaru Ortiz <erik@colosa.com>
*/
public function dispatchApiRequest($uri, $version = "1.0")
public function dispatchApiRequest($uri, $version = "1.0", $multipart = false, $inputExecute = '')
{
// to handle a request with "OPTIONS" method
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
@@ -134,6 +168,9 @@ class WebApplication
// create a new Restler instance
//$rest = new \Luracast\Restler\Restler();
$rest = new \Maveriks\Extension\Restler();
// setting flag for multipart to Restler
$rest->setFlagMultipart($multipart);
$rest->inputExecute = $inputExecute;
// setting api version to Restler
$rest->setAPIVersion($version);
// adding $authenticationClass to Restler
@@ -211,6 +248,9 @@ class WebApplication
}
$rest->handle();
if ($rest->flagMultipart === true) {
return $rest->responseMultipart;
}
}
public function parseApiRequestUri()

View File

@@ -23,39 +23,41 @@
*/
ini_set( 'max_execution_time', '0' );
$ext = pathinfo($_FILES["PROCESS_FILENAME"]["name"], PATHINFO_EXTENSION);
if (isset($_FILES["PROCESS_FILENAME"])) {
$ext = pathinfo($_FILES["PROCESS_FILENAME"]["name"], PATHINFO_EXTENSION);
if ($ext == "pmx") {
$importer = new \ProcessMaker\Importer\XmlImporter();
$importer->setSourceFromGlobals("PROCESS_FILENAME");
$importer->setData("usr_uid", $_SESSION['USER_LOGGED']);
if ($ext == "pmx") {
$importer = new \ProcessMaker\Importer\XmlImporter();
$importer->setSourceFromGlobals("PROCESS_FILENAME");
$importer->setData("usr_uid", $_SESSION['USER_LOGGED']);
try {
$res = $importer->import();
try {
$res = $importer->import();
$result = array(
"success" => true,
"catchMessage" => "",
"ExistProcessInDatabase" => 0,
"ExistGroupsInDatabase" => 0,
"sNewProUid" => $res[0]["new_uid"],
"project_type" => "bpmn"
);
} catch (Exception $e) {
$result = array(
"success" => true,
"catchMessage" => "", //$e->getMessage(),
"ExistProcessInDatabase" => 1,
"ExistGroupsInDatabase" => 0,
"groupBeforeAccion" => "uploadFileNewProcess",
"sNewProUid" => "63626727053359dabb8fee8019503780",
"proFileName" => $_FILES['PROCESS_FILENAME']['name'],
"project_type" => "bpmn"
);
$result = array(
"success" => true,
"catchMessage" => "",
"ExistProcessInDatabase" => 0,
"ExistGroupsInDatabase" => 0,
"sNewProUid" => $res[0]["new_uid"],
"project_type" => "bpmn"
);
} catch (Exception $e) {
$result = array(
"success" => true,
"catchMessage" => "", //$e->getMessage(),
"ExistProcessInDatabase" => 1,
"ExistGroupsInDatabase" => 0,
"groupBeforeAccion" => "uploadFileNewProcess",
"sNewProUid" => "63626727053359dabb8fee8019503780",
"proFileName" => $_FILES['PROCESS_FILENAME']['name'],
"project_type" => "bpmn"
);
}
echo json_encode($result);
exit(0);
}
echo json_encode($result);
exit(0);
}
function reservedWordsSqlValidate ($data)