From: Roland Häder Date: Sun, 26 Jul 2009 16:35:20 +0000 (+0000) Subject: Rewrite for fixing reported error message at ticket #56 X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4291e81f572c5628861eb77abcc6bbdbbed74c3e;p=mailer.git Rewrite for fixing reported error message at ticket #56 --- diff --git a/inc/libs/yoomedia_functions.php b/inc/libs/yoomedia_functions.php index 3650465a5e..70b510502f 100644 --- a/inc/libs/yoomedia_functions.php +++ b/inc/libs/yoomedia_functions.php @@ -54,7 +54,7 @@ function YOOMEDIA_TEST_CONFIG ($data) { mergeConfig($data); // Temporary allow maximum - setConfigEntry('yoomedia_tm_max_reload' , 1000); + setConfigEntry('yoomedia_tm_max_reload' , 100000); setConfigEntry('yoomedia_tm_min_wait' , 0); setConfigEntry('yoomedia_tm_clicks_remain', 10); setConfigEntry('yoomedia_tm_min_pay' , 0); @@ -62,19 +62,34 @@ function YOOMEDIA_TEST_CONFIG ($data) { // Query the API with a test request without couting it // If zero reply comes back the data is invalid! - $response = YOOMEDIA_QUERY_API("out_textmail.php", true); // @TODO Ask Yoo!Media for test script + $response = YOOMEDIA_QUERY_API('out_textmail.php', true); // @TODO Ask Yoo!Media for test script + + // Default error code is 0 = all fine! + $errorCode = YOOMEDIA_GET_ERRORCODE_FROM_RESULT($response); // Log the response if failed if (count($response) == 0) { // Queries depleted (as we count here!) - DEBUG_LOG(__FUNCTION__, __LINE__, " Requested depleted. Maxmimum was: ".getConfig('yoomedia_requests_total')); - } elseif (count($response) <= 10) { + DEBUG_LOG(__FUNCTION__, __LINE__, "Requested depleted. Maxmimum was: " . getConfig('yoomedia_requests_total')); + $errorCode = -1; + } elseif (!isset($response[8])) { + // Invalid response + DEBUG_LOG(__FUNCTION__, __LINE__, "Missing response line [8]. Raw response=" . base64_encode(serialize($response))); + $errorCode = -1; + } elseif ((($errorCode <= 4) && ($errorCode > 0)) || ($errorCode >= 8)) { + // An error has returned from the account + DEBUG_LOG(__FUNCTION__, __LINE__, "Unexpected error code " . $errorCode . " received."); + } elseif (count($response) < 9) { // Log serialized raw response - DEBUG_LOG(__FUNCTION__, __LINE__, " Raw response=".base64_encode(serialize($response))); - } // END - if + DEBUG_LOG(__FUNCTION__, __LINE__, "Raw response=" . base64_encode(serialize($response))); + $errorCode = -1; + } else { + // This is fine, because the result array is okay and the response code on element 8 is fine + $errorCode = 0; + } // Do we have some data there? - return (count($response) > 10); + return ($errorCode == 0); } // Queries the given Yoo!Media API 2.0 script @@ -101,7 +116,7 @@ function YOOMEDIA_QUERY_API ($script, $countQuery = true) { $response = sendGetRequest($requestString); // Shall we count the query as used? - if ($countQuery) { + if ($countQuery === true) { // Then update the config! updateConfiguration('yoomedia_requests_remain', 1, '-'); } // END - if @@ -340,7 +355,7 @@ function YOOMEDIA_RELOAD_LOCK ($data, $mode) { // Add the entry SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_yoomedia_reload` (`type`,`y_id`,`y_reload`) VALUES ('%s',%s,%s)", - array($mode, bigintval($data['id']), bigintval($data['reload'])), __FUNCTION__, __LINE__); + array($mode, bigintval($data['id']), bigintval($data['reload'])), __FUNCTION__, __LINE__); } // END - if } @@ -361,5 +376,41 @@ function YOOMEDIA_CONVERT_MODE ($mode) { return $mode; } -// +// Extract code from response +function YOOMEDIA_GET_ERRORCODE_FROM_RESULT (array $response) { + // Bad code as default + $code = -999; + + // Which response should we parse? + if (isset($response[8])) { + // Use error code from element 8 (mostly API errors) + $codeArray = explode("
", $response[8]); + + // Use only the first element + $code = bigintval($codeArray[0]); + } elseif (isset($response[0]['id'])) { + // Begin with extraction + $codeArray = explode(" ", $response[0]['id']); + $code = $codeArray[0]; + $codeArray = explode("
", $code); + $code = $codeArray[0]; + $codeArray = explode("
", $code); + $code = $codeArray[0]; + + // Remove all new-line characters + $codeArray = explode("\n", $code); + $code = $codeArray[0]; + + // Remove carrige-return + $code = str_replace("\n", '', $code); + } else { + // Should not happen! + DEBUG_LOG(__FUNCTION__, __LINE__, "Cannot parse response. Raw response=" . base64_encode(serialize($response))); + } + + // Return error code + return $code; +} + +// [EOF] ?> diff --git a/inc/modules/admin/what-list_yoomedia_tm.php b/inc/modules/admin/what-list_yoomedia_tm.php index dd4e2303af..26589b98ca 100644 --- a/inc/modules/admin/what-list_yoomedia_tm.php +++ b/inc/modules/admin/what-list_yoomedia_tm.php @@ -85,19 +85,7 @@ if ((!is_array($result)) || (count($result) == 0) || (!isset($result[0]['id']))) return false; } elseif (count($result[0]) < 7) { // Error received so prepare error code - $codeArray = explode(" ", $result[0]['id']); - $code = $codeArray[0]; - $codeArray = explode("
", $code); - $code = $codeArray[0]; - $codeArray = explode("
", $code); - $code = $codeArray[0]; - - // Remove all new-line characters - $codeArray = explode("\n", $code); - $code = $codeArray[0]; - - // Remove carrige-return - $code = str_replace("\n", '', $code); + $code = YOOMEDIA_GET_ERRORCODE_FROM_RESULT($result); // Output message LOAD_TEMPLATE('admin_yoomedia_error', false, sprintf("{--ADMIN_YOOMEDIA_ERROR_%s--}", strtoupper(yoomediaTranslateError($code))));