Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/release-7.002.4.1-RC1'
Browse files Browse the repository at this point in the history
  • Loading branch information
datazen committed Jun 27, 2014
2 parents 91e18f1 + 8d86f1c commit 45072e3
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 42 deletions.
95 changes: 82 additions & 13 deletions catalog/admin/includes/applications/login/classes/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,27 @@ public static function validateSerial($serial) {

$resultArr = utility::xml2arr($resultXML);

if (isset($resultArr['data']['valid']) && $resultArr['data']['valid'] == '1') {
$result['rpcStatus'] = '1';
// make sure the products for this serial have been downloaded from the cloud
$products = (is_array($resultArr['data']['products'])) ? $resultArr['data']['products']['line_0'] : $resultArr['data']['products'];
if (isset($products) && empty($products) === false) self::verifyProductsAreDownloaded($products);
if (count($resultArr) == 0) { // there was an error with the api
$error = true;
$errorMsg = preg_match("'<title[^>]*?>.*?</title>'si", $resultXML, $regs);
$errorMsg = (is_array($regs)) ? strip_tags(end($regs)) : NULL;
if ($errorMsg == '') $errorMsg = 'Resource Unavailable at https://api.loadedcommerce.com/' . $api_version . '/check/serial/';
// log the error
self::log('Error: ' . $errorMsg);
// update last checked so we don't check until tomorrow
self::updateLastCheckedDate();
// send ok to enter admin
$resultArr['data']['valid'] = true;
$result['rpcStatus'] = true;
} else {
$result['rpcStatus'] = $resultArr['data']['rpcStatus'];
if (isset($resultArr['data']['valid']) && $resultArr['data']['valid'] == '1') {
$result['rpcStatus'] = '1';
// make sure the products for this serial have been downloaded from the cloud
$products = (is_array($resultArr['data']['products'])) ? $resultArr['data']['products']['line_0'] : $resultArr['data']['products'];
if (isset($products) && empty($products) === false) self::verifyProductsAreDownloaded($products);
} else {
$result['rpcStatus'] = $resultArr['data']['rpcStatus'];
}
}

return $result;
Expand All @@ -244,9 +258,21 @@ public static function apiCheck() {
$apiCheck = transport::getResponse(array('url' => 'https://api.loadedcommerce.com/' . $api_version . '/updates/available/?ver=' . utility::getVersion() . '&ref=' . $_SERVER['SCRIPT_FILENAME'], 'method' => 'get'));
$versions = utility::xml2arr($apiCheck);

if ($versions == null) {
$file = @fopen(DIR_FS_WORK . 'apinocom.tmp', "w");
@fclose($file);
$error = false;
if (count($versions) == 0) { // there was an error with the api
$error = true;
$errorMsg = preg_match("'<title[^>]*?>.*?</title>'si", $versions, $regs);
$errorMsg = (is_array($regs)) ? strip_tags(end($regs)) : NULL;
if ($errorMsg == '') $errorMsg = 'Resource Unavailable at https://api.loadedcommerce.com/' . $api_version . '/updates/available/?ver=' . utility::getVersion() . '&ref=' . $_SERVER['SCRIPT_FILENAME'];
$error = true;
// log the error
self::log('Error: ' . $errorMsg);
}

if ($versions == null || $error) { // set the error flag
if ( is_writable(DIR_FS_WORK) ) {
file_put_contents(DIR_FS_WORK . 'apinocom.tmp', '[' . lC_DateTime::getNow('d-M-Y H:i:s') . '] ' . $errorMsg . "\n", FILE_APPEND);
}
}
}
/*
Expand Down Expand Up @@ -308,11 +334,11 @@ public static function getProVersionTag() {
private static function _timeToCheck() {
global $lC_Database;

$check = (defined('INSTALLATION_ID') && INSTALLATION_ID != '') ? INSTALLATION_ID : NULL;
if ($check == NULL) return TRUE;
$serial = (defined('INSTALLATION_ID') && INSTALLATION_ID != '') ? INSTALLATION_ID : NULL;
if ($serial == NULL) return TRUE;

if (defined('ADDONS_SYSTEM_LOADED_7_PRO_STATUS') && !file_exists(DIR_FS_CATALOG . 'addons/Loaded_7_Pro/controller.php')) return TRUE;
if (defined('ADDONS_SYSTEM_LOADED_7_B2B_STATUS') && !file_exists(DIR_FS_CATALOG . 'addons/Loaded_7_B2B/controller.php')) return TRUE;
// if (defined('ADDONS_SYSTEM_LOADED_7_PRO_STATUS') && !file_exists(DIR_FS_CATALOG . 'addons/Loaded_7_Pro/controller.php')) return TRUE;
// if (defined('ADDONS_SYSTEM_LOADED_7_B2B_STATUS') && !file_exists(DIR_FS_CATALOG . 'addons/Loaded_7_B2B/controller.php')) return TRUE;

$Qcheck = $lC_Database->query('select * from :table_configuration where configuration_key = :configuration_key limit 1');
$Qcheck->bindTable(':table_configuration', TABLE_CONFIGURATION);
Expand All @@ -325,8 +351,51 @@ private static function _timeToCheck() {
$check = substr(lC_DateTime::getShort($Qcheck->value('last_modified')), 3, 2);

$Qcheck->freeResult();

// update last checked
if ($serial != NULL) self::updateLastCheckedDate($serial);

return (((int)$today != (int)$check) ? TRUE : FALSE);
}
/**
* Update the last checked date
*
* @access private
* @return boolean
*/
public static function updateLastCheckedDate() {
global $lC_Database;

$error = false;

$lC_Database->startTransaction();

$Qupdate = $lC_Database->query('update :table_configuration set last_modified = :last_modified where configuration_key = :configuration_key');
$Qupdate->bindTable(':table_configuration', TABLE_CONFIGURATION);
$Qupdate->bindValue(':configuration_key', 'INSTALLATION_ID');
$Qupdate->bindValue(':last_modified', @date("Y-m-d H:m:s"));
$Qupdate->execute();

if ( !$lC_Database->isError() ) {
$lC_Database->commitTransaction();
return true;
}

$lC_Database->rollbackTransaction();

return false;
}
/**
* Make a log entry
*
* @param string $message The message to log
* @access protected
* @return void
*/
protected static function log($message) {
if ( is_writable(DIR_FS_WORK . 'logs') ) {
file_put_contents(DIR_FS_WORK . 'logs/api_errors.txt', '[' . lC_DateTime::getNow('d-M-Y H:i:s') . '] ' . $message . "\n", FILE_APPEND);
}
}
}
?>
25 changes: 1 addition & 24 deletions catalog/admin/includes/classes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ private function _doRegister($data) {
$registerArr['ver'] = utility::getVersion();

$resultXML = transport::getResponse(array('url' => 'https://api.loadedcommerce.com/' . $api_version . '/register/install/', 'method' => 'post', 'parameters' => $registerArr));

$newInstallationID = (preg_match("'<installationID[^>]*?>(.*?)</installationID>'i", $resultXML, $regs) == 1) ? $regs[1] : NULL;
$products = (preg_match("'<products[^>]*?>(.*?)</products>'i", $resultXML, $regs) == 1) ? $regs[1] : NULL;

Expand All @@ -75,30 +76,6 @@ private function _doRegister($data) {
} else {
return utility::arr2xml(array('error' => TRUE, 'message' => 'error processing the request'));
}
}
/**
* Check to see if it's time to re-check installation validity
*
* @access private
* @return boolean
*/
private function _timeToCheck() {
global $lC_Database;

$check = (defined('INSTALLATION_ID') && INSTALLATION_ID != '') ? INSTALLATION_ID : NULL;
if ($check == NULL) return TRUE;

$Qcheck = $lC_Database->query('select last_modified from :table_configuration where configuration_key = :configuration_key');
$Qcheck->bindTable(':table_configuration', TABLE_CONFIGURATION);
$Qcheck->bindValue(':configuration_key', 'INSTALLATION_ID');
$Qcheck->execute();

$today = substr(lC_DateTime::getShort(date("Y-m-d H:m:s")), 3, 2);
$check = substr(lC_DateTime::getShort($Qcheck->value('last_modified')), 3, 2);

$Qcheck->freeResult();

return (((int)$today != (int)$check) ? TRUE : FALSE);
}
}
?>
2 changes: 1 addition & 1 deletion catalog/admin/includes/languages/en_US/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@

button_understood = I Understand
text_api_com_issue = API Communication
text_api_com_issue_warnings = There were issues communicating with the API.
text_api_com_issue_warnings = There was an issue communicating with the API and<br />because of this some functionality such as Core<br />Updates and Addon delivery will not function properly.<br /><br />Please refer to the error log located at<br />catalog/includes/works/logs/api_errors.txt for more<br />detailed information.
6 changes: 3 additions & 3 deletions catalog/includes/classes/transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public static function getResponse($parameters, $driver = 'curl', $rawResponse =

$result = trim(call_user_func(array($driver, 'execute'), $parameters));

if (strlen($result) == 0) {
$result = self::getResponse($parameters, 'stream');
}
// if (strlen($result) == 0) {
// $result = self::getResponse($parameters, 'stream');
// }

return $result;
}
Expand Down
2 changes: 1 addition & 1 deletion catalog/includes/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.002.4.0|05/21/2014
7.002.4.1|06/27/2014

0 comments on commit 45072e3

Please sign in to comment.