Tip: Click lines to highlight, hold ctrl/cmd to multi-select

http://codedumper.com/olame (24-Feb @ 19:22)

Syntax Highlighted Code

  1. <?
  2.   include_once '../config/config.php';
  3.   include_once $setts['themDir'] . "/_classes/membersarea/migration/accountMigrationMain.class.php";
  4.  
  5.   $bbParserObj = new BBparser();
  6.  
  7.   function parceDetailFinal($text) {
  8.       global $bbParserObj;
  9.       $text = str_replace("\n", "<br>", $text);
  10.       return $bbParserObj->BB_Parse(addSpecialChars($text),false);
  11.   }
  12.  
  13.   function getUahAmountConverted($amount, $currency) {
  14.       if ($currency == 'UAH') {
  15.           return (float)$amount;
  16.       }
  17.  
  18.       $currency = empty($currency) ? 'USD' : $currency;
  19.       $getCurrentCurrency = getSqlRow("SELECT * FROM probid_currencies WHERE symbol = '" . $currency . "'");
  20.  
  21.       $getAllCurrencies = mysql_query("SELECT * FROM probid_currencies WHERE symbol != '" . $currency . "'");
  22.       while($convert = mysql_fetch_array($getAllCurrencies)) {
  23.           $converted = $amount * ($getCurrentCurrency['converter'] / $convert['converter']);
  24.           if ($convert['symbol'] == 'UAH') {
  25.               return (float)$converted;
  26.           }
  27.       }
  28.   }
  29.  
  30.   function convertFuncCallback(&$e) {
  31.       $e = iconv('windows-1251', 'utf-8//IGNORE', $e);
  32.   }
  33.  
  34.   function migrationCronCriticalError($migrationID, $soapFault) {
  35.       $faultTrace = $soapFault->getTrace();
  36.       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())");
  37.       mysql_query("UPDATE probid_migration_item SET state = 'error' WHERE id = ".(int)$migrationID);
  38.   }
  39.  
  40.  
  41.   // Some auction options
  42.   $arrayDurationAuction = array( 3 => 0, 5 => 1, 7 => 2, 10 => 3, 14 => 4, 21 => 5);
  43.   $arrayQueryMethods = array(
  44.       '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'
  45.       '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()'
  46.       'limit' => 100
  47.   );
  48.  
  49.  
  50.   $query = mysql_query("SELECT * FROM probid_migration_item WHERE state = 'work' ORDER BY id LIMIT 1");
  51.  
  52.   while ($dataApp = mysql_fetch_assoc($query)) {
  53.       // Connect to SOAP server
  54.       try {
  55.           $soapClient = new SoapClient(accountMigrationMain::$soapConfig['soapURL']);
  56.       } catch (Exception $soapFault) {
  57.           migrationCronCriticalError($dataApp['id'], $soapFault);
  58.           break;
  59.       }
  60.       // Get local version ID
  61.       try {
  62.           $soapSysVersion = $soapClient->doQuerySysStatus(1, accountMigrationMain::$soapConfig['countryID'], accountMigrationMain::$soapConfig['apiKey']);
  63.       } catch (Exception $soapFault) {
  64.           migrationCronCriticalError($dataApp['id'], $soapFault);
  65.           break;
  66.       }
  67.  
  68.       array_walk($dataApp, 'convertFuncCallback');
  69.       // Try to login
  70.       try {
  71.           $soapUserSession = $soapClient->doLogin($dataApp['aukro_login'], $dataApp['aukro_pass'], accountMigrationMain::$soapConfig['countryID'], accountMigrationMain::$soapConfig['apiKey'], $soapSysVersion['ver-key']);
  72.       } catch (Exception $soapFault) {
  73.           migrationCronCriticalError($dataApp['id'], $soapFault);
  74.           break;
  75.       }
  76.       // Get user personal data
  77.       try {
  78.           $soapUserInfo = $soapClient->doGetMyData($soapUserSession['session-handle-part']);
  79.       } catch (Exception $soapFault) {
  80.           migrationCronCriticalError($dataApp['id'], $soapFault);
  81.           break;
  82.       }
  83.       // Prepare query
  84.       if ($dataApp['move_current'] == 'Y' && $dataApp['move_closed'] == 'N') { // only current item's
  85.           $queryItems = mysql_query(sprintf($arrayQueryMethods['current'], (int)$dataApp['auc_id']) . " LIMIT " . $arrayQueryMethods['limit']);
  86.       } else if ($dataApp['move_current'] == 'N' && $dataApp['move_closed'] == 'Y') { // only closed item's
  87.           $queryItems = mysql_query(sprintf($arrayQueryMethods['closed'], (int)$dataApp['auc_id']) . " LIMIT " . $arrayQueryMethods['limit']);
  88.       } else if ($dataApp['move_current'] == 'Y' && $dataApp['move_closed'] == 'Y') { // all item's
  89.           $queryItems = mysql_query("(" . sprintf($arrayQueryMethods['current'], (int)$dataApp['auc_id']) . ") UNION (" . sprintf($arrayQueryMethods['closed'], (int)$dataApp['auc_id']) . ") LIMIT " . $arrayQueryMethods['limit']);
  90.       }
  91.       if (mysql_num_rows($queryItems) == 0) {
  92.           mysql_query("UPDATE probid_migration_item SET state = 'complete' WHERE id = ".(int)$dataApp['id']);
  93.       }
  94.       while ($dataItem = mysql_fetch_assoc($queryItems)) {
  95.          $dataItem['description'] = parceDetailFinal($dataItem['description']);
  96.          $dataItem['itemname'] = addSpecialChars($dataItem['itemname']);
  97.          array_walk($dataItem, 'convertFuncCallback');
  98.          $affectedArray = array(
  99.              array('fid' => 1, 'fvalue-string' => mb_strcut($dataItem['itemname'], 0, 49)), // itemname
  100.              array('fid' => 2, 'fvalue-int' => 28721), // category
  101.              array('fid' => 4, 'fvalue-int' => array_key_exists($dataItem['duration'], $arrayDurationAuction) ? $arrayDurationAuction[$dataItem['duration']] : 1), // duration
  102.              array('fid' => 5, 'fvalue-int' => 1), // quantity
  103.              array('fid' => 6, 'fvalue-float' => getUahAmountConverted($dataItem['bidstart'], $dataItem['currency'])), // start bid
  104.              array('fid' => 9, 'fvalue-int' => (int)$soapUserInfo['user-data']->{'user-country-id'}), // country
  105.              array('fid' => 10, 'fvalue-int' => (int)$soapUserInfo['user-data']->{'user-state-id'}), // state
  106.              array('fid' => 11, 'fvalue-string' => $soapUserInfo['user-data']->{'user-city'}), // city
  107.              array('fid' => 12, 'fvalue-int' => $dataItem['sc'] == 'SP' ? 0 : 1), // delivery
  108.              array('fid' => 13, 'fvalue-int' => empty($dataItem['shipping_details']) ? 1 : 16), // delivery additional
  109.              array('fid' => 24, 'fvalue-string' => $dataItem['description']), // description
  110.              array('fid' => 27, 'fvalue-string' => mb_strcut($dataItem['shipping_details'], 0, 450)), // shipping_details
  111.              array('fid' => 40, 'fvalue-int' => 1) // pay method
  112.          );
  113.  
  114.          if ($dataItem['rp'] == 'Y' && $soapUserInfo['user-data']->{'user-rating'} >=3) { // reserv price
  115.             $affectedArray[] = array('fid' => 7, 'fvalue-float' => getUahAmountConverted($dataItem['rpvalue'], $dataItem['currency']));
  116.          }
  117.  
  118.          if ($dataItem['bn'] == 'Y') { // buy now
  119.             $affectedArray[] = array('fid' => 8, 'fvalue-float' => getUahAmountConverted($dataItem['bnvalue'], $dataItem['currency']));
  120.          }
  121.  
  122.          if ($dataItem['sc'] == 'SD') { //self delivery
  123.             $affectedArray[] = array('fid' => 35, 'fvalue-int' => 1);
  124.          }
  125.  
  126.          // Parce image's
  127.          $userImageArray = array_merge((array)$dataItem['picpath'], getUserImages($dataItem['ownerid'], '1 day'));
  128.  
  129.          $imageInterator = 16;
  130.          foreach ($userImageArray as $singleImage) {
  131.              $fileImageName = strpos($singleImage, "http://") === false ? $site_root . $singleImage : $singleImage;
  132.              if (!empty($singleImage) && file_exists($fileImageName)) {
  133.                  $imageCode = @file_get_contents($fileImageName);
  134.                  if(!empty($imageCode) && $imageInterator < 22) {
  135.                      $affectedArray[] = array('fid' => $imageInterator++, 'fvalue-image' => $imageCode);
  136.                  }
  137.              }
  138.          }
  139.  
  140.  
  141.          // Add obligatory field
  142.          $obligatoryField = array('fvalue-string', 'fvalue-int', 'fvalue-float', 'fvalue-image', 'fvalue-text', 'fvalue-datetime', 'fvalue-boolean');
  143.  
  144.          foreach ($affectedArray as &$propertyArray) {
  145.             foreach ($obligatoryField as $oblField) {
  146.               if (array_key_exists($oblField, $propertyArray)) continue;
  147.               $propertyArray[$oblField] = '';
  148.             }
  149.          }
  150.  
  151.          // Post new auction to aukro
  152.          try {
  153.              $postResult = $soapClient->doNewAuctionExt($soapUserSession['session-handle-part'], $affectedArray, 0, 565551486);
  154.              mysql_query("INSERT INTO probid_migration_item_state VALUES(NULL, ".(int)$dataItem['ownerid'].", ".(int)$dataItem['id'].", ".(int)$postResult['item-id'].", 'done', NOW())");
  155.          } catch(Exception $soapFault) {
  156.              mysql_query("INSERT INTO probid_migration_item_state VALUES(NULL, ".(int)$dataItem['ownerid'].", ".(int)$dataItem['id'].", 0, 'error', NOW())");
  157.              $lastStateID = mysql_insert_id();
  158.              if ($lastStateID > 0) {
  159.                  mysql_query("INSERT INTO probid_migration_item_state_error VALUES(NULL, ".$lastStateID.", '".mysql_real_escape_string(soapExceptionFaultEncoded($soapFault->getMessage()))."'))");
  160.              }
  161.          }
  162.  
  163.  
  164.       }
  165.       mysql_free_result($queryItems);
  166.   }
  167. ?>

Plain Code

<?
  include_once '../config/config.php';
  include_once $setts['themDir'] . "/_classes/membersarea/migration/accountMigrationMain.class.php";

  $bbParserObj = new BBparser();

  function parceDetailFinal($text) {
      global $bbParserObj;
      $text = str_replace("\n", "<br>", $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);
  }
?>

Permalink: http://codedumper.com/olame