<commit_before><?php

namespace Seat\EveApi\Character;

use Seat\EveApi\BaseApi;
use Pheal\Pheal;

class AssetList extends BaseApi {

	public static function Update($keyID, $vCode)
	{

		// Start and validate they key pair
		BaseApi::bootstrap();
		BaseApi::validateKeyPair($keyID, $vCode);

		// Set key scopes and check if the call is banned
		$scope = 'Char';
		$api = 'AssetList';

		if (BaseApi::isBannedCall($api, $scope, $keyID))
			return;

		// Get the characters for this key
		$characters = BaseApi::findKeyCharacters($keyID);

		// Check if this key has any characters associated with it
		if (!$characters)
			return;

		// Lock the call so that we are the only instance of this running now()
		// If it is already locked, just return without doing anything
		if (!BaseApi::isLockedCall($api, $scope, $keyID))
			$lockhash = BaseApi::lockCall($api, $scope, $keyID);
		else
			return;

		// Next, start our loop over the characters and upate the database
		foreach ($characters as $characterID) {

			// Prepare the Pheal instance
			$pheal = new Pheal($keyID, $vCode);

			// Do the actual API call. pheal-ng actually handles some internal
			// caching too.
			try {
				
				$asset_list = $pheal
					->charScope
					->AssetList(array('characterID' => $characterID));

			} catch (\Pheal\Exceptions\APIException $e) {

				// If we cant get account status information, prevent us from calling
				// this API again
				BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage());
			    return;

			} catch (\Pheal\Exceptions\PhealException $e) {

				throw $e;
			}

			// Check if the data in the database is still considered up to date.
			// checkDbCache will return true if this is the case
			if (!BaseApi::checkDbCache($scope, $api, $asset_list->cached_until, $characterID)) {

				// TODO: Look as how we update this. As per https://neweden-dev.com/Character/Asset_List, the itemID
				// may change. So, we cant really just update existing ids. For now, we just trash all and recreate the
				// assets :<
				// Maybe do this in one big transaction? lel

				\EveCharacterAssetList::where('characterID', '=', $characterID)->delete();
				\EveCharacterAssetListContents::where('characterID', '=', $characterID)->delete();

				// Populate the assets for this character as well as the contents.
				foreach ($asset_list->assets as $asset) {

					$asset_data = new \EveCharacterAssetList;

					$asset_data->characterID = $characterID;
					$asset_data->itemID = $asset->itemID;
					$asset_data->locationID = $asset->locationID;
					$asset_data->typeID = $asset->typeID;
					$asset_data->quantity = $asset->quantity;
					$asset_data->flag = $asset->flag;
					$asset_data->singleton = $asset->singleton;
					$asset_data->save();

					// Process the contents if there are any
					if (isset($asset->contents)) {

						foreach ($asset->contents as $content) {

							$content_data = new \EveCharacterAssetListContents;

							$content_data->characterID = $characterID;
							$content_data->itemID = $asset_data->itemID;
							$content_data->typeID = $content->itemID;
							$content_data->quantity = $content->quantity;
							$content_data->flag = $content->flag;
							$content_data->singleton = $content->singleton;
							$content_data->rawQuantity = (isset($content->rawQuantity) ? $content->rawQuantity : 0);

							$asset_data->contents()->save($content_data);
						}
					}
				}

				// Update the cached_until time in the database for this api call
				BaseApi::setDbCache($scope, $api, $asset_list->cached_until, $characterID);
			}
		}

		// Unlock the call
		BaseApi::unlockCall($lockhash);

		return $asset_list;
	}
}
<commit_msg>Fix character assets content typeID reference<commit_after><?php

namespace Seat\EveApi\Character;

use Seat\EveApi\BaseApi;
use Pheal\Pheal;

class AssetList extends BaseApi {

	public static function Update($keyID, $vCode)
	{

		// Start and validate they key pair
		BaseApi::bootstrap();
		BaseApi::validateKeyPair($keyID, $vCode);

		// Set key scopes and check if the call is banned
		$scope = 'Char';
		$api = 'AssetList';

		if (BaseApi::isBannedCall($api, $scope, $keyID))
			return;

		// Get the characters for this key
		$characters = BaseApi::findKeyCharacters($keyID);

		// Check if this key has any characters associated with it
		if (!$characters)
			return;

		// Lock the call so that we are the only instance of this running now()
		// If it is already locked, just return without doing anything
		if (!BaseApi::isLockedCall($api, $scope, $keyID))
			$lockhash = BaseApi::lockCall($api, $scope, $keyID);
		else
			return;

		// Next, start our loop over the characters and upate the database
		foreach ($characters as $characterID) {

			// Prepare the Pheal instance
			$pheal = new Pheal($keyID, $vCode);

			// Do the actual API call. pheal-ng actually handles some internal
			// caching too.
			try {
				
				$asset_list = $pheal
					->charScope
					->AssetList(array('characterID' => $characterID));

			} catch (\Pheal\Exceptions\APIException $e) {

				// If we cant get account status information, prevent us from calling
				// this API again
				BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage());
			    return;

			} catch (\Pheal\Exceptions\PhealException $e) {

				throw $e;
			}

			// Check if the data in the database is still considered up to date.
			// checkDbCache will return true if this is the case
			if (!BaseApi::checkDbCache($scope, $api, $asset_list->cached_until, $characterID)) {

				// TODO: Look as how we update this. As per https://neweden-dev.com/Character/Asset_List, the itemID
				// may change. So, we cant really just update existing ids. For now, we just trash all and recreate the
				// assets :<
				// Maybe do this in one big transaction? lel

				\EveCharacterAssetList::where('characterID', '=', $characterID)->delete();
				\EveCharacterAssetListContents::where('characterID', '=', $characterID)->delete();

				// Populate the assets for this character as well as the contents.
				foreach ($asset_list->assets as $asset) {

					$asset_data = new \EveCharacterAssetList;

					$asset_data->characterID = $characterID;
					$asset_data->itemID = $asset->itemID;
					$asset_data->locationID = $asset->locationID;
					$asset_data->typeID = $asset->typeID;
					$asset_data->quantity = $asset->quantity;
					$asset_data->flag = $asset->flag;
					$asset_data->singleton = $asset->singleton;
					$asset_data->save();

					// Process the contents if there are any
					if (isset($asset->contents)) {

						foreach ($asset->contents as $content) {

							$content_data = new \EveCharacterAssetListContents;

							$content_data->characterID = $characterID;
							$content_data->itemID = $asset_data->itemID;
							$content_data->typeID = $content->typeID;
							$content_data->quantity = $content->quantity;
							$content_data->flag = $content->flag;
							$content_data->singleton = $content->singleton;
							$content_data->rawQuantity = (isset($content->rawQuantity) ? $content->rawQuantity : 0);

							$asset_data->contents()->save($content_data);
						}
					}
				}

				// Update the cached_until time in the database for this api call
				BaseApi::setDbCache($scope, $api, $asset_list->cached_until, $characterID);
			}
		}

		// Unlock the call
		BaseApi::unlockCall($lockhash);

		return $asset_list;
	}
}

{'fraction_non_alphanumeric': 0.13118279569892474, 'fraction_numerical': 0.0005376344086021505, 'mean_word_length': 3.3011560693641617, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 87, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4544058', 'n_tokens_mistral': 2805, 'n_tokens_neox': 2278, 'n_words': 659}