public function setUp() { parent::setUp(); $this->_keystore = Interspire_KeyStore::instance(); $this->_prefix = 'email:rule_export:' . $this->args['id'] . ':'; $this->_db = $GLOBALS['ISC_CLASS_DB']; }
public function setUp() { parent::setUp(); GetLib('class.json'); $this->_keystore = Interspire_KeyStore::instance(); $this->_prefix = 'ebay:list_products:' . $this->args['id'] . ':'; $this->_db = $GLOBALS['ISC_CLASS_DB']; $this->_engine = getClass('ISC_ADMIN_ENGINE'); $this->_engine->LoadLangFile('ebay'); $this->_log = $GLOBALS['ISC_CLASS_LOG']; }
/** * Begins an actual export job sequence based on requested data -- the job class itself will validate most of this info before attempting an export * * @param array $data */ protected function _moduleExportCommenceCommon($data) { $keystore = Interspire_KeyStore::instance(); // find a unique export id to use do { $id = md5(uniqid('',true)); } while ($keystore->exists('email:module_export:id:' . $id)); $keystore->set('email:module_export:id:' . $id, $id); $prefix = 'email:module_export:' . $id; if (!isset($data['exportSearch'])) { $data['exportSearch'] = array(); } if (!isset($data['exportMap'])) { $data['exportMap'] = array(); } $keystore->set($prefix . ':started', time()); $keystore->set($prefix . ':abort', 0); $keystore->set($prefix . ':skip', 0); $keystore->set($prefix . ':type', $data['exportType']); $keystore->set($prefix . ':module', $data['exportModule']); $keystore->set($prefix . ':list', $data['exportList']); $keystore->set($prefix . ':search', ISC_JSON::encode($data['exportSearch'])); $keystore->set($prefix . ':map', ISC_JSON::encode($data['exportMap'])); $keystore->set($prefix . ':success_count', 0); $keystore->set($prefix . ':error_count', 0); $keystore->set($prefix . ':doubleoptin', $data['exportDoubleOptin']); $keystore->set($prefix . ':updateexisting', $data['exportUpdateExisting']); // so we can send an email later, or diagnose troublesome users $user = $GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetUser(); $keystore->set($prefix . ':owner:id', $user['pk_userid']); $keystore->set($prefix . ':owner:username', $user['username']); $keystore->set($prefix . ':owner:email', $user['useremail']); $jobData = array( 'id' => $id, ); $json = array( 'success' => (bool)Interspire_TaskManager::createTask('emailintegration', 'Job_EmailIntegration_ModuleExport', $jobData), 'id' => $id, ); if (isset($data['return']) && $data['return']) { return $json; } ISC_JSON::output($json); }
/** * Processes the next site that needs its cache updated * */ private function continueEbayCacheUpdateAction() { $ebayClass = GetClass('ISC_ADMIN_EBAY'); $expiredSites = $ebayClass->getExpiredCacheSites(); // no more to update if (empty($expiredSites)) { ISC_JSON::output('', true, array('done' => true)); } // the next site to update $nextSiteId = current($expiredSites); $keystore = Interspire_KeyStore::instance(); $prefix = 'ebay:details:last_update:site:'; try { $xml = $ebayClass->GeteBayDetailsAction($nextSiteId); } catch (ISC_EBAY_API_EXCEPTION $ex) { FlashMessage($ex->getMessage(), MSG_ERROR, '', 'EbayConfig'); ISC_JSON::output('', false); } // Write the content to local file system if(!$ebayClass->WriteCache($nextSiteId, $xml->asXML())) { FlashMessage(GetLang('EbayRequestProblem'), MSG_ERROR, '', 'EbayConfig'); ISC_JSON::output('', false); } // set the last update time for the site if (!$keystore->set($prefix . $nextSiteId, time())) { FlashMessage(GetLang('EbayRequestProblem'), MSG_ERROR, '', 'EbayConfig'); ISC_JSON::output('', false); } ISC_JSON::output('', true); }
/** * Gets the site Id's whose cache has expired * * @return array Array of site Id's */ public function getExpiredCacheSites() { $keystore = Interspire_KeyStore::instance(); $prefix = 'ebay:details:last_update:site:'; $expiredSites = array(); foreach ($this->getSupportedSites() as $siteId => $siteName) { // the time the cache for the site was last updated $lastUpdate = $keystore->get($prefix . $siteId); $cacheFile = $this->cacheBaseDir . '/ebaydetails_' . $siteId . '.xml'; // if the cache has never been updated, has expired or the cache file doesn't exist then add it to our list of expired sites if (!$lastUpdate || (($lastUpdate + self::CACHE_VALID_FOR) < time()) || !is_file($cacheFile) ) { $expiredSites[] = $siteId; } } return $expiredSites; }
/** * Retrieves an array of category data for the specified category * * Elements use the category ID as their key. Each category has the following fields: * name => The category name (string) * category_id => The ID of the category (int) * parent_id => The ID of the parent category (int) * is_leaf => Is this a leaf category? (bool) * lot_size_enabled => Are lot sizes allowed on listings in this category? (bool) * best_offer_enabled => Are best offers allowed on listings? (bool) * reserve_price_allowed => Are reserve prices allowed on listings? (bool) * minimum_reserve_price => The minimum reserve price for listings. (double) * * @param int $parentCategoryId The parent category to retrieve child categories from. * @param int $levelLimit The maximum depth of the heirarchy to retrieve. * @param int $siteId The eBay site to get categories for * @return array An array of category data in the format described. */ public static function getCategories($parentCategoryId, $levelLimit, $siteId) { ISC_ADMIN_EBAY_OPERATIONS::setSiteId($siteId); $currentCategoryVersion = 0; $cacheCategoryVersion = 0; $categories = array(); $keystore = Interspire_KeyStore::instance(); $versionKey = 'ebay:categories:version:site:' . $siteId; $updateKey = 'ebay:categories:last_update:site:' . $siteId; // get the cached version and last update time $cacheVersion = $keystore->get($versionKey); $cacheLastUpdate = $keystore->get($updateKey); if ($cacheVersion !== false && $cacheLastUpdate !== false) { $cacheCategoryVersion = $cacheVersion; // use the cached version as the current version if it was retrieved from ebay less than 10 minutes ago if ($cacheLastUpdate > (time() - 600)) { $currentCategoryVersion = $cacheCategoryVersion; } } if (empty($currentCategoryVersion)) { // retrieve the latest category version from ebay $currentCategoryVersion = ISC_ADMIN_EBAY_OPERATIONS::getCategoryVersion(); // update our cached version $keystore->set($versionKey, $currentCategoryVersion); $keystore->set($updateKey, time()); } // is our category heirarchy out of date? if ($currentCategoryVersion != $cacheCategoryVersion) { // lets nuke off our locally stored categories $GLOBALS['ISC_CLASS_DB']->DeleteQuery('ebay_categories', 'WHERE ebay_site_id = ' . $siteId); } // fetch categories from the database if they exist $query = ' SELECT * FROM [|PREFIX|]ebay_categories WHERE parent_id = ' . $parentCategoryId . ' AND ebay_site_id = ' . $siteId . ' ORDER BY name '; $res = $GLOBALS['ISC_CLASS_DB']->Query($query); if ($GLOBALS['ISC_CLASS_DB']->CountResult($res)) { while ($categoryRow = $GLOBALS['ISC_CLASS_DB']->Fetch($res)) { $categories[$categoryRow['category_id']] = $categoryRow; } return $categories; } // retrieve categories from the API $categoriesXML = ISC_ADMIN_EBAY_OPERATIONS::getCategories($levelLimit, $parentCategoryId); if ((int)$categoriesXML->CategoryCount == 0) { return false; } // are reserved prices allowed (site-wide level) $reservePriceAllowed = (bool)$categoriesXML->ReservePriceAllowed; $categories = array(); foreach($categoriesXML->CategoryArray->Category as $categoryInfo) { // skip categories not on the level we've requested (ie. the parent category) and virtual categories as they don't allow listing if ((int)$categoryInfo->CategoryLevel != $levelLimit || (bool)$categoryInfo->Virtual) { continue; } $categoryReservedPriceAllowed = $reservePriceAllowed; // is this category overriding the reserve price allowed? toggle the site-side setting. if (isset($categoryInfo->ORPA)) { $categoryReservedPriceAllowed = !$categoryReservedPriceAllowed; } $newCategory = array( 'name' => (string)$categoryInfo->CategoryName, 'category_id' => (int)$categoryInfo->CategoryID, 'parent_id' => $parentCategoryId, 'ebay_site_id' => $siteId, 'is_leaf' => isset($categoryInfo->LeafCategory), 'lot_size_enabled' => !isset($categoryInfo->LSD), 'best_offer_enabled' => isset($categoryInfo->BestOfferEnabled), 'reserve_price_allowed' => $categoryReservedPriceAllowed, 'minimum_reserve_price' => (double)$categoryInfo->MinimumReservePrice ); $categories[(int)$categoryInfo->CategoryID] = $newCategory; // add the category to the database $GLOBALS['ISC_CLASS_DB']->InsertQuery('ebay_categories', $newCategory); } return $categories; }
protected function getEbayListingNotifications() { $notifications = array(); // Show information about email integration tasks in progress $keystore = Interspire_KeyStore::instance(); $exports = $keystore->multiGet('ebay:list_products:id:*'); foreach ($exports as $exportId) { $prefix = 'ebay:list_products:' . $exportId . ':'; $offset = (int)$keystore->get($prefix . 'true_offset'); $abort = (bool)$keystore->get($prefix . 'abort'); $error = (int)$keystore->get($prefix . 'error_count'); $total = (int)$keystore->get($prefix . 'estimated_total'); $eta = ''; if ($total) { if ($offset) { $per = (time() - (int)$keystore->get($prefix . 'started')) / $offset; $remaining = Store_DateTime::duration(($total - $offset) * $per, Store_DateTime::DURATION_MINUTES); if ($remaining) { $eta = '<br />' . GetLang('Ebay_Notifications_InProgress_ETA', array( 'remaining' => $remaining, )); } } $total = GetLang('of') . ' ' . number_format($total, 0, GetConfig('DecimalToken'), GetConfig('ThousandsToken')); } else { $total = ''; } $offset = number_format($offset, 0, GetConfig('DecimalToken'), GetConfig('ThousandsToken')); $error = number_format($error, 0, GetConfig('DecimalToken'), GetConfig('ThousandsToken')); $template = $keystore->get($prefix . 'template_name'); $notice = ''; if ($abort) { $notice = GetLang('Ebay_Notifications_Abort', array( 'template' => $template, )); } else { $notice = GetLang('Ebay_Notifications_InProgress', array( 'offset' => $offset, 'total' => $total, 'error' => $error, 'eta' => $eta, 'template' => $template, )) . '<br /><a href="#" class="Ebay_Export_Abort" id="Ebay_Export_Abort_' . isc_html_escape($exportId) . '" title="' . isc_html_escape(GetLang('Ebay_Notifications_InProgress_Abort_Title')) . '">' . GetLang('Ebay_Notifications_InProgress_Abort_Label') . '</a>'; } if ($notice) { $notifications[] = $notice; } } return $notifications; }