logo
Welcome to our new AbleCommerce forums. As a guest, you may view the information here. To post to this forum, you must have a registered account with us, either as a new user evaluating AbleCommerce or an existing user of the application. For all questions related to the older version of Gold and earlier, please go to AbleCommerce Gold forum. Please use your AbleCommerce username and password to Login. New Registrations are disabled.

Notification

Icon
Error

Options
Go to last post Go to first unread
judy at Web2Market  
#1 Posted : Saturday, February 24, 2024 9:11:53 AM(UTC)
judy at Web2Market

Rank: Advanced Member

Groups: Developers
Joined: 11/7/2018(UTC)
Posts: 289

Thanks: 21 times
Was thanked: 5 time(s) in 5 post(s)
I believe this has been discussed before because I remember changing the source code on an older site after someone reported it. Rebuilding the product urls will sometimes make the website unusable to where the app pool has to be restarted. The issue is in the following code- there should be a transaction around each product instead of all the products.
private static List<string> GenerateProductUrls(bool overrideUrls, int maximumLength, bool createRedirect, bool useLowercaseOnly)
{
List<string> errors = new List<string>();
ICatalogUrlRepository repo = AbleContext.Resolve<ICatalogUrlRepository>();
IUrlGenerator generator = AbleContext.Resolve<IUrlGenerator>();
var products = NHibernateHelper.CreateCriteria<Product>()
.List<Product>();

Dictionary<string, int> urlMap = new Dictionary<string, int>(StringComparer.InvariantCultureIgnoreCase);
////jme
//AbleContext.Current.Database.BeginTransaction();
foreach (var product in products)
{
AbleContext.Current.Database.BeginTransaction();
try
{
string url = product.CatalogUrl;
bool generateUrl = string.IsNullOrEmpty(url) ? true : (!product.CatalogUrlObject.IsCustomized || overrideUrls);
if (generateUrl)
{
var newUrl = GenerateUrl(product.Id, CatalogNodeType.Product, product.Name, generator, repo, urlMap);
if (!string.IsNullOrEmpty(newUrl))
{
if (maximumLength > 0 && newUrl.Length > maximumLength)
throw new Exception(string.Format("The generated URL for product '{0}' is {1} characters which is too long.", product.Name, newUrl.Length));

if (useLowercaseOnly)
newUrl = newUrl.ToLowerInvariant();

product.CatalogUrl = newUrl;
product.CatalogUrlObject.IsCustomized = false;
product.Save();
urlMap.Add(newUrl, product.Id);

// CREATE A FIXED REDIRECT
if (createRedirect)
AbleContext.Container.Resolve<IRedirectRepository>().CreateRedirect(url, newUrl, product.CatalogUrlObject.Id);
}
}
}
catch (Exception e)
{
errors.Add(e.Message);
}
AbleContext.Current.Database.CommitTransaction();
}
//AbleContext.Current.Database.CommitTransaction();
return errors;
}

Wanna join the discussion?! Login to your AbleCommerce Forums forum account. New Registrations are disabled.

Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.