Exemplo n.º 1
0
	public function setUp()
	{
		parent::setUp();
		$this->_keystore = Interspire_KeyStore::instance();
		$this->_prefix = 'email:rule_export:' . $this->args['id'] . ':';
		$this->_db = $GLOBALS['ISC_CLASS_DB'];
	}
Exemplo n.º 2
0
	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);
	}
Exemplo n.º 4
0
	protected function _deleteUnusedProductImages ($letter)
	{
		// check to see if this upgrade step has already run once
		// storage of this may be volatile but it's a compromise between using upgrade session (very volatile) and some new specific mysql table (permanent)
		$key = 'upgrade:6100:deleteUnusedProductImages:' . $letter;
		$keys = new Interspire_KeyStore;
		if ($keys->exists($key)) {
			return true;
		}

		// scan our product_images directory to begin detecting orphaned images
		$base = ISC_BASE_PATH . '/' . GetConfig('ImageDirectory') . '/' . $letter;

		$imageDirectoryLength = strlen(ISC_BASE_PATH . '/' . GetConfig('ImageDirectory') . '/');

		$deleteCounter = 0;
		$directory = new RecursiveDirectoryIterator($base);
		foreach (new RecursiveIteratorIterator($directory) as $absoluteFilename => $current) {
			if ($current->isDir()) {
				// skip directories
				continue;
			}

			if (DIRECTORY_SEPARATOR == "\\") {
				// normalise the filename because DirectoryIterator will return \ on Windows but we store / in db
				$absoluteFilename = str_replace("\\", "/", $absoluteFilename);
			}

			$filename = substr($absoluteFilename, $imageDirectoryLength);

			// check that the filename matches our pattern of generated names such as __{random}_{size}.ext before
			// deleting it, if it doesn't match then it's a file that probably wasn't generated by the product.image
			// classes and we should leave it alone
			if (!preg_match('#__[0-9]{5}(_(std|thumb|tiny|zoom))?\.[^.]+$#', $filename)) {
				continue;
			}

			try {
				if ($this->_isImageInUse($filename)) {
					// filename exists in db somewhere; skip
					continue;
				}
			} catch (Exception $exception) {
				$this->SetError($exception->getMessage());
				return false;
			}

			// remove this file
			if (!unlink($absoluteFilename)) {
				$this->SetError('unlink() failed for file: ' . $absoluteFilename);
				return false;
			}

			$deleteCounter++;
		}

		// the key need only exist to flag the step as run, we can store whatever we want, so let's store when the step
		// ran and the number of files which were deleted
		$keys->set($key, time() . '.' . $deleteCounter);
		return true;
	}
Exemplo n.º 5
0
	/**
	* 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);
	}
Exemplo n.º 6
0
	/**
	* 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;
	}
Exemplo n.º 7
0
	/**
	* 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;
	}
Exemplo n.º 8
0
	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;
	}