Rank: Advanced Member
Groups: Developers
Joined: 11/7/2018(UTC) Posts: 303
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; }
|
|
|
|
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.
Important Information:
The AbleCommerce Forums uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close