Skip to content

Commit

Permalink
Updated to match Zuora-DeveloperNetwork
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeSulivan committed Feb 27, 2012
1 parent 4e7f693 commit 3e4ce8a
Show file tree
Hide file tree
Showing 20 changed files with 20,109 additions and 58 deletions.
59 changes: 39 additions & 20 deletions call-lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,14 +426,17 @@ public static function login($client, $username, $password, $debug){
"password"=>$password
);

$client->myDebug = 0;
$result = $client->login($login);
if ($debug) var_dump($result);
$client->myDebug = $debug;
//if ($debug) var_dump($result);

$session = $result->result->Session;
$url = $result->result->ServerUrl;
if ($debug) {
print "\nSession: " . $session;
print "\nServerUrl: " . $url;
print "\n";
}

# set the authentication
Expand Down Expand Up @@ -579,8 +582,9 @@ public static function createRequestAndHeadersWithNS($sessionKey, $batchSize, $c
global $defaultApiNamespaceURL;
global $defaultObjectNamespaceURL;

$sessionHeader = "";
if (count(array_keys($callOptions)) > 0) {
$sessionHeader = "<" . $apiNamespace . ":CallOptions>";
$sessionHeader .= "<" . $apiNamespace . ":CallOptions>";
foreach ($callOptions as $paramKey => $paramValue) {
$sessionHeader .= "<" . $apiNamespace . ":" . $paramKey . ">" . $paramValue . "</" . $apiNamespace . ":" . $paramKey . ">";
}
Expand Down Expand Up @@ -650,7 +654,7 @@ public static function getFileContents($wsdl) {
}

################################################################################
public static function bulkOperation($client, $header, $method, $payload, $itemCount, $debug, $htmlOutput=FALSE) {
public static function bulkOperation($client, $header, $method, $payload, $itemCount, $debug, $htmlOutput=FALSE, $zObjectCap=-1) {

global $maxZObjectCount;
global $defaultApiNamespaceURL;
Expand All @@ -666,18 +670,23 @@ public static function bulkOperation($client, $header, $method, $payload, $itemC
$nodeName = "ids";
}

// Allow control over how many objects are submitted in one call.
if ($zObjectCap < 0) {
$zObjectCap = $maxZObjectCount;
}

$soapRequest = createRequest($header->data["session"], $payload);
$xml_obj = new SimpleXMLElement($soapRequest);
$xml_obj->registerXPathNamespace("SOAP-ENV","http://schemas.xmlsoap.org/soap/envelope/");
$xml_obj->registerXPathNamespace("ns1",$defaultApiNamespaceURL);
$type = $xml_obj->xpath("//SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:" . $method . "/ns1:type");

// Iterate through the list of items, $maxZObjectCount at a time
for ($counter = 0; $counter < $itemCount; $counter += $maxZObjectCount) {
// Iterate through the list of items, $zObjectCap at a time
for ($counter = 0; $counter < $itemCount; $counter += $zObjectCap) {

// Identify upper bound for this batch.
$lowerBound = $counter + 1;
$upperBound = $counter + $maxZObjectCount;
$upperBound = $counter + $zObjectCap;
if ($upperBound > $itemCount) {
$upperBound = $itemCount;
}
Expand All @@ -694,7 +703,7 @@ public static function bulkOperation($client, $header, $method, $payload, $itemC
}
$batchPayload = $batchPayload . "</ns1:" . $method . ">\n";

print "Batch " . ceil($upperBound / $maxZObjectCount) . ": submitting ZObjects " . $lowerBound . "-" . $upperBound . " (" . count($batchNodes) . ")...";
print "Batch " . ceil($upperBound / $zObjectCap) . ": submitting ZObjects " . $lowerBound . "-" . $upperBound . " (" . count($batchNodes) . ")...";
$soapRequest = createRequest($header->data["session"], $batchPayload);

// Execute the API call.
Expand All @@ -712,23 +721,33 @@ public static function bulkOperation($client, $header, $method, $payload, $itemC
$xml_obj2 = new SimpleXMLElement($batchResponse);
$xml_obj2->registerXPathNamespace("SOAP-ENV","http://schemas.xmlsoap.org/soap/envelope/");
$xml_obj2->registerXPathNamespace("ns1",$defaultApiNamespaceURL);
$resultNodes = $xml_obj2->xpath("//SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:" . $method . "Response/ns1:result/ns1:Success");
$soapFaultNode = $xml_obj2->xpath("//SOAP-ENV:Envelope/SOAP-ENV:Body/SOAP-ENV:Fault");
$resultNodes = $xml_obj2->xpath("//SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:" . $method . "Response/ns1:result/ns1:Success | //SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:" . $method . "Response/ns1:result/ns1:success");

$successCount = 0;
$errorCount = 0;
for ($i = 0; $i < count($resultNodes); $i++) {
$resultNode = $resultNodes[$i];
if ($resultNode[0] == "false") {
$errorCodeNodes = $xml_obj2->xpath("//SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:" . $method . "Response/ns1:result[position()=" . ($i+1) . "]/ns1:Errors/ns1:Code");
$errorMsgNodes = $xml_obj2->xpath("//SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:" . $method . "Response/ns1:result[position()=" . ($i+1) . "]/ns1:Errors/ns1:Message");
$errorCount++;
array_push($result["errorList"], array("index" => ($lowerBound + $i), "code" => (string)$errorCodeNodes[0], "message" => (string)$errorMsgNodes[0]));
} else {
$successCount++;
}
if (count($soapFaultNode) > 0) {
$errorCount = count($batchNodes);
for ($i = 0; $i < count($batchNodes); $i++) {
$faultCode = $xml_obj2->xpath("//SOAP-ENV:Envelope/SOAP-ENV:Body/SOAP-ENV:Fault/faultstring");
$faultMessage = $xml_obj2->xpath("//SOAP-ENV:Envelope/SOAP-ENV:Body/SOAP-ENV:Fault/detail/Exception");
array_push($result["errorList"], array("index" => ($lowerBound + $i), "code" => (string)$faultCode[0], "message" => (string)$faultMessage[0]));
}
array_push($result["batchList"], array("start" => $lowerBound, "end" => $upperBound, "size" => count($batchNodes), "successCount" => $successCount, "errorCount" => $errorCount));
} else {
for ($i = 0; $i < count($resultNodes); $i++) {
$resultNode = $resultNodes[$i];
if (strcasecmp($resultNode,"false") == 0) {
$errorCodeNodes = $xml_obj2->xpath("//SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:" . $method . "Response/ns1:result[position()=" . ($i+1) . "]/ns1:errors/ns1:Code | //SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:" . $method . "Response/ns1:result[position()=" . ($i+1) . "]/ns1:Errors/ns1:Code");
$errorMsgNodes = $xml_obj2->xpath("//SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:" . $method . "Response/ns1:result[position()=" . ($i+1) . "]/ns1:errors/ns1:Message | //SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:" . $method . "Response/ns1:result[position()=" . ($i+1) . "]/ns1:Errors/ns1:Message");
$errorCount++;
array_push($result["errorList"], array("index" => ($lowerBound + $i), "code" => (string)$errorCodeNodes[0], "message" => (string)$errorMsgNodes[0]));
} else {
$successCount++;
}
}
array_push($result["batchList"], array("start" => $lowerBound, "end" => $upperBound, "size" => count($resultNodes), "successCount" => $successCount, "errorCount" => $errorCount));
}
array_push($result["batchList"], array("start" => $lowerBound, "end" => $upperBound, "size" => count($resultNodes), "successCount" => $successCount, "errorCount" => $errorCount));

$result["successCount"] += $successCount;
$result["errorCount"] += $errorCount;
}
Expand Down
57 changes: 46 additions & 11 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

include("call-lib.php");

$DEFAULT_WSDL = 'zuora-29.0-sandbox-AllOptions.wsdl';
$DEFAULT_WSDL = 'zuora-38.0-sandbox-AllOptions.wsdl';
$SUBSCRIBE_TEMPLATE = array(1=>array(
"version"=>'1.0',
"subscribe"=>'subscribe.xml',
Expand All @@ -44,16 +44,34 @@
"subscribeWithExistingAccount"=>'',
"queryMore"=>'queryMore.xml',
"generate"=>'generate.xml'),
19=>array(
"version"=>'19.0',
"subscribe"=>'subscribeV11.xml',
"subscribeWithExistingAccount"=>'',
"queryMore"=>'queryMore.xml',
"generate"=>'generate.xml',
"getUserInfo"=>'getUserInfo.xml'),
25=>array(
"version"=>'25.0',
"subscribe"=>'subscribeV25.xml',
"subscribeWithExistingAccount"=>'',
"queryMore"=>'queryMore.xml',
"generate"=>'generate.xml')
"generate"=>'generate.xml',
"getUserInfo"=>'getUserInfo.xml'),
29=>array(
"version"=>'29.0',
"subscribe"=>'subscribeV25.xml',
"subscribeWithExistingAccount"=>'',
"queryMore"=>'queryMore.xml',
"generate"=>'generate.xml',
"getUserInfo"=>'getUserInfo.xml',
"amend"=>'amend.xml')
);

session_start();

## CMB update - undefined variable issue
$debug = false;
// Test whether the form has been submitted.
if (array_key_exists('_submit_check', $_POST)) {
$_SESSION['method'] = $_POST['method'];
Expand All @@ -68,7 +86,8 @@
if (strlen($_SESSION['service_url']) <= 0) {
unset($_SESSION['service_url']);
}
if ($_POST['sessionId-refresh']) {
# CMB update - undefined index issue fixed by adding isset() test
if (isset($_POST['sessionId-refresh'])) {
$_SESSION['sessionId-refresh'] = true;
} else {
$_SESSION['sessionId-refresh'] = false;
Expand Down Expand Up @@ -171,12 +190,14 @@ function dirList ($directory)
$timings = array();

$outputCSV = false;
if ($_POST['csv']) {
# CMB update - undefined index issue fixed by adding isset() test
if (isset($_POST['csv'])) {
$outputCSV = true;
}

$outputQM = false;
if ($_POST['queryMore']) {
# CMB update - undefined index issue fixed by adding isset() test
if (isset($_POST['queryMore'])) {
$outputQM = true;
}

Expand Down Expand Up @@ -220,7 +241,7 @@ function dirList ($directory)
}

$callOptions = array();
if ($_POST['api-singleTxn']) {
if (isset($_POST['api-singleTxn'])) {
$callOptions = array("useSingleTransaction"=>$_POST['api-singleTxn']);
}

Expand Down Expand Up @@ -327,7 +348,7 @@ function popup(url)
params += ', scrollbars=yes';
params += ', status=no';
params += ', toolbar=no';
newwin=window.open('http://apidocs.developer.zuora.com/index.php/'+url,'windowname5', params);
newwin=window.open('http://knowledgecenter.zuora.com/C_Zuora_API_Developer\'s_Guide/G_API_Objects/'+url,'windowname5', params);
if (window.focus) {newwin.focus()}
return false;
}
Expand Down Expand Up @@ -361,24 +382,38 @@ function popup(url)

try {
$templateException = false;
$pos = strpos(strtolower($call),'subscribe');
$callStr = strtolower($call);
$pos = strpos($callStr,'subscribe');
if ($pos === false && !$templateException) {
$templateException = false;
} else {
$templateException = true;
}
$pos = strpos(strtolower($call),'querymore');
$pos = strpos($callStr,'querymore');
if ($pos === false && !$templateException) {
$templateException = false;
} else {
$templateException = true;
}
$pos = strpos(strtolower($call),'generate');
$pos = strpos($callStr,'generate');
if ($pos === false && !$templateException) {
$templateException = false;
} else {
$templateException = true;
}
$pos = strpos($callStr,'getuserinfo');
if ($pos === false && !$templateException) {
$templateException = false;
} else {
$templateException = true;
}
$pos = strpos($callStr,'amend');
if ($pos === false && !$templateException) {
$templateException = false;
} else {
$templateException = true;
}

if (!$templateException) {
if (strlen($object) > 0) {
$_SESSION['body'] = printTemplateWithNS($_SESSION['wsdl'], $call, $object, $debug, 0, $_SESSION['api-ns'], $_SESSION['object-ns']);
Expand Down Expand Up @@ -641,4 +676,4 @@ function cmp($a, $b) {
</tr>
</table>
</body>
</html>
</html>
56 changes: 39 additions & 17 deletions loader/call.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@

// Parameters to be expected:
// 1) WSDL filename
// 2) Username
// 3) Password
// 4) Operation
// 5) Object
// 6) Show request flag
// 2) URL
// 3) Username
// 4) Password
// 5) Operation
// 6) Object
// 7) (Optional) Show request flag
// 8) (Optional) Object Count to be made per API call.

// Output Expected:
// 1) Timestamp
Expand All @@ -58,10 +60,10 @@

// check for all required arguments
// first argument is always name of script!
if ($argc != 7) {
fwrite($lf,"ERROR: Too few arguments.\n\n");
if ($argc < 7 || $argc > 9) {
fwrite($lf,"ERROR: Wrong number of arguments.\n\n");
fwrite($of, date($DATE_FORMAT, time()).$SEPARATOR.
"ERROR: Too few arguments.".$SEPARATOR.
"ERROR: Wrong number of arguments.".$SEPARATOR.
$argc.$SEPARATOR.
"".$SEPARATOR.
"".$SEPARATOR.
Expand All @@ -78,22 +80,33 @@
$wsdl = $argv[0];

// get and use remaining arguments
$username = $argv[1];
$password = $argv[2];
$operation = $argv[3];
$object = $argv[4];
if (strcasecmp($argv[5],"true") == 0) {
$service_url = $argv[1];
$username = $argv[2];
$password = $argv[3];
$operation = $argv[4];
$object = $argv[5];
if ($argc >= 8 && strcasecmp($argv[6],"true") == 0) {
$showRequest = true;
} else {
$showRequest = false;
}
$objectCount = -1;
if ($argc >= 9 && is_numeric($argv[7]) && $argv[7] > 0 && $argv[7] <= $maxZObjectCount) {
$objectCount = (int)$argv[7];
}
$fileName = $INPUT_FILE;

fwrite($lf, "WSDL: " . $wsdl . "\n");
fwrite($lf, "URL: " . $service_url . "\n");
fwrite($lf, "Username: " . $username . "\n");
fwrite($lf, "Operation: " . $operation . "\n");
fwrite($lf, "Object: " . $object . "\n");
fwrite($lf, "Show Request: " . $showRequest . "\n");
fwrite($lf, "Show Request: " . ($showRequest?"true":"false") . "\n");
if ($objectCount < 0) {
fwrite($lf, "Object Cap: DEFAUL\n");
} else {
fwrite($lf, "Object Cap: " . $objectCount . "\n");
}
fwrite($lf, "File Name: " . $fileName . "\n");

$error = false;
Expand Down Expand Up @@ -125,18 +138,26 @@
$header = $line;
# Validate the header.
$fields = ZuoraAPIHelper::getFieldList($wsdl,$object);
# Need to add the Id field, since it belongs on the ZObject.
# Need to add the fieldsToNull and Id field, since they're part of ZObject.
array_unshift($fields, $FIELDSTONULL_FIELD);
array_unshift($fields, $ID_FIELD);
$errorFields = array();
for ($i = 0; $i < count($header); $i++) {
$found = false;
for ($j = 0; $j < count($fields); $j++) {
if (strcasecmp(trim($header[$i]), $fields[$j]) == 0) {
$found = true;
break;
}
}
if (!$found) {
$errorFields[] = $header[$i];
// Exclude custom fields from validation.
if (strpos($header[$i], "__")) {
// Add the custom field to the list of valid headers.
$fields[] = $header[$i];
} else {
$errorFields[] = $header[$i];
}
}
}
if (count($errorFields) > 0) {
Expand Down Expand Up @@ -178,6 +199,7 @@
# Process the data.
# Make the API call.
$client = createClient($wsdl, $debug);
$client->setLocation($service_url);
$header = login($client, $username, $password, $debug);

// Iterate through the data.
Expand All @@ -200,7 +222,7 @@
fwrite($lf, xml_pretty_printer($soapRequest, true) . "\n");
continue;
}
$result = ZuoraAPIHelper::bulkOperation($client, $header, $operation, $xml, count($chunk), $debug, TRUE);
$result = ZuoraAPIHelper::bulkOperation($client, $header, $operation, $xml, count($chunk), $debug, TRUE, $objectCount);
$successCount += $result["successCount"];
$errorCount += $result["errorCount"];
$resultArray[] = $result;
Expand Down
Loading

0 comments on commit 3e4ce8a

Please sign in to comment.