", $text); return $bbParserObj->BB_Parse(addSpecialChars($text),false); } function getUahAmountConverted($amount, $currency) { if ($currency == 'UAH') { return (float)$amount; } $currency = empty($currency) ? 'USD' : $currency; $getCurrentCurrency = getSqlRow("SELECT * FROM probid_currencies WHERE symbol = '" . $currency . "'"); $getAllCurrencies = mysql_query("SELECT * FROM probid_currencies WHERE symbol != '" . $currency . "'"); while($convert = mysql_fetch_array($getAllCurrencies)) { $converted = $amount * ($getCurrentCurrency['converter'] / $convert['converter']); if ($convert['symbol'] == 'UAH') { return (float)$converted; } } } function convertFuncCallback(&$e) { $e = iconv('windows-1251', 'utf-8//IGNORE', $e); } function migrationCronCriticalError($migrationID, $soapFault) { $faultTrace = $soapFault->getTrace(); mysql_query("INSERT INTO probid_migration_item_error VALUES (NULL, ".(int)$migrationID.", '".mysql_real_escape_string($faultTrace[1]['function'])."', '".mysql_real_escape_string(soapExceptionFaultEncoded($soapFault->getMessage()))."', NOW())"); mysql_query("UPDATE probid_migration_item SET state = 'error' WHERE id = ".(int)$migrationID); } // Some auction options $arrayDurationAuction = array( 3 => 0, 5 => 1, 7 => 2, 10 => 3, 14 => 4, 21 => 5); $arrayQueryMethods = array( 'current' => 'SELECT * FROM probid_auctions AS a LEFT JOIN probid_migration_item_state AS s ON (a.id = s.auc_item_id AND a.ownerid = s.auc_user_id) WHERE s.id IS NULL AND a.ownerid = %s AND a.closed = 0 AND a.deleted != 1 AND a.active = 1' 'closed' => 'SELECT * FROM probid_auctions_closed AS c LEFT JOIN probid_migration_item_state AS s ON (c.id = s.auc_item_id AND c.ownerid = s.auc_user_id) WHERE s.id IS NULL AND c.ownerid = %s AND c.closed = 1 AND c.deleted != 1 AND c.active = 1 AND DATE_ADD(c.enddate, INTERVAL 2 MONTH) > NOW()' 'limit' => 100 ); mb_internal_encoding("UTF-8"); $query = mysql_query("SELECT * FROM probid_migration_item WHERE state = 'work' ORDER BY id LIMIT 1"); while ($dataApp = mysql_fetch_assoc($query)) { // Connect to SOAP server try { $soapClient = new SoapClient(accountMigrationMain::$soapConfig['soapURL']); } catch (Exception $soapFault) { migrationCronCriticalError($dataApp['id'], $soapFault); break; } // Get local version ID try { $soapSysVersion = $soapClient->doQuerySysStatus(1, accountMigrationMain::$soapConfig['countryID'], accountMigrationMain::$soapConfig['apiKey']); } catch (Exception $soapFault) { migrationCronCriticalError($dataApp['id'], $soapFault); break; } array_walk($dataApp, 'convertFuncCallback'); // Try to login try { $soapUserSession = $soapClient->doLogin($dataApp['aukro_login'], $dataApp['aukro_pass'], accountMigrationMain::$soapConfig['countryID'], accountMigrationMain::$soapConfig['apiKey'], $soapSysVersion['ver-key']); } catch (Exception $soapFault) { migrationCronCriticalError($dataApp['id'], $soapFault); break; } // Get user personal data try { $soapUserInfo = $soapClient->doGetMyData($soapUserSession['session-handle-part']); } catch (Exception $soapFault) { migrationCronCriticalError($dataApp['id'], $soapFault); break; } // Prepare query if ($dataApp['move_current'] == 'Y' && $dataApp['move_closed'] == 'N') { // only current item's $queryItems = mysql_query(sprintf($arrayQueryMethods['current'], (int)$dataApp['auc_id']) . " LIMIT " . $arrayQueryMethods['limit']); } else if ($dataApp['move_current'] == 'N' && $dataApp['move_closed'] == 'Y') { // only closed item's $queryItems = mysql_query(sprintf($arrayQueryMethods['closed'], (int)$dataApp['auc_id']) . " LIMIT " . $arrayQueryMethods['limit']); } else if ($dataApp['move_current'] == 'Y' && $dataApp['move_closed'] == 'Y') { // all item's $queryItems = mysql_query("(" . sprintf($arrayQueryMethods['current'], (int)$dataApp['auc_id']) . ") UNION (" . sprintf($arrayQueryMethods['closed'], (int)$dataApp['auc_id']) . ") LIMIT " . $arrayQueryMethods['limit']); } if (mysql_num_rows($queryItems) == 0) { mysql_query("UPDATE probid_migration_item SET state = 'complete' WHERE id = ".(int)$dataApp['id']); } while ($dataItem = mysql_fetch_assoc($queryItems)) { $dataItem['description'] = parceDetailFinal($dataItem['description']); $dataItem['itemname'] = addSpecialChars($dataItem['itemname']); array_walk($dataItem, 'convertFuncCallback'); $affectedArray = array( array('fid' => 1, 'fvalue-string' => mb_strcut($dataItem['itemname'], 0, 49)), // itemname array('fid' => 2, 'fvalue-int' => 28721), // category array('fid' => 4, 'fvalue-int' => array_key_exists($dataItem['duration'], $arrayDurationAuction) ? $arrayDurationAuction[$dataItem['duration']] : 1), // duration array('fid' => 5, 'fvalue-int' => 1), // quantity array('fid' => 6, 'fvalue-float' => getUahAmountConverted($dataItem['bidstart'], $dataItem['currency'])), // start bid array('fid' => 9, 'fvalue-int' => (int)$soapUserInfo['user-data']->{'user-country-id'}), // country array('fid' => 10, 'fvalue-int' => (int)$soapUserInfo['user-data']->{'user-state-id'}), // state array('fid' => 11, 'fvalue-string' => $soapUserInfo['user-data']->{'user-city'}), // city array('fid' => 12, 'fvalue-int' => $dataItem['sc'] == 'SP' ? 0 : 1), // delivery array('fid' => 13, 'fvalue-int' => empty($dataItem['shipping_details']) ? 1 : 16), // delivery additional array('fid' => 24, 'fvalue-string' => $dataItem['description']), // description array('fid' => 27, 'fvalue-string' => mb_strcut($dataItem['shipping_details'], 0, 450)), // shipping_details array('fid' => 40, 'fvalue-int' => 1) // pay method ); if ($dataItem['rp'] == 'Y' && $soapUserInfo['user-data']->{'user-rating'} >=3) { // reserv price $affectedArray[] = array('fid' => 7, 'fvalue-float' => getUahAmountConverted($dataItem['rpvalue'], $dataItem['currency'])); } if ($dataItem['bn'] == 'Y') { // buy now $affectedArray[] = array('fid' => 8, 'fvalue-float' => getUahAmountConverted($dataItem['bnvalue'], $dataItem['currency'])); } if ($dataItem['sc'] == 'SD') { //self delivery $affectedArray[] = array('fid' => 35, 'fvalue-int' => 1); } // Parce image's $userImageArray = array_merge((array)$dataItem['picpath'], getUserImages($dataItem['ownerid'], '1 day')); $imageInterator = 16; foreach ($userImageArray as $singleImage) { $fileImageName = strpos($singleImage, "http://") === false ? $site_root . $singleImage : $singleImage; if (!empty($singleImage) && file_exists($fileImageName)) { $imageCode = @file_get_contents($fileImageName); if(!empty($imageCode) && $imageInterator < 22) { $affectedArray[] = array('fid' => $imageInterator++, 'fvalue-image' => $imageCode); } } } // Add obligatory field $obligatoryField = array('fvalue-string', 'fvalue-int', 'fvalue-float', 'fvalue-image', 'fvalue-text', 'fvalue-datetime', 'fvalue-boolean'); foreach ($affectedArray as &$propertyArray) { foreach ($obligatoryField as $oblField) { if (array_key_exists($oblField, $propertyArray)) continue; $propertyArray[$oblField] = ''; } } // Post new auction to aukro try { $postResult = $soapClient->doNewAuctionExt($soapUserSession['session-handle-part'], $affectedArray, 0, 565551486); mysql_query("INSERT INTO probid_migration_item_state VALUES(NULL, ".(int)$dataItem['ownerid'].", ".(int)$dataItem['id'].", ".(int)$postResult['item-id'].", 'done', NOW())"); } catch(Exception $soapFault) { mysql_query("INSERT INTO probid_migration_item_state VALUES(NULL, ".(int)$dataItem['ownerid'].", ".(int)$dataItem['id'].", 0, 'error', NOW())"); $lastStateID = mysql_insert_id(); if ($lastStateID > 0) { mysql_query("INSERT INTO probid_migration_item_state_error VALUES(NULL, ".$lastStateID.", '".mysql_real_escape_string(soapExceptionFaultEncoded($soapFault->getMessage()))."'))"); } } } mysql_free_result($queryItems); } ?>