Try our conversational search powered by Generative AI!

uiMaxVersions

Vote:
 

Hi Guys

CMS 7.9/CM Version: 7.9 (build: 0)

The BigTable within CMS is starting to get really big.  Within episerver.config I have uiMaxVersions="20".  I believe the main reason this table is getting really big is because I have some RESTful web services that perform create and update operations on product/variation data.

Can the max versions be set differently for CMS and CM?  i.e. 20 version for CMS pages and 5 versions for product catalog data - Just noticed this thread - http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=88142 - I would vote for this feature request.

I was reading that if I change this property it is difficult to change later - You would have to republish EVERY page on the site.  Well in my case every product/variation, so is there a simple way to do this? script? scheduled job?

http://world.episerver.com/blogs/Alexander-Haneng/Dates/2011/9/EPiServer-CMS-Checklist-Starting-Development-Checklist/

http://www.karolikl.com/2011/02/remove-old-versions-job-in-episerver.html

Thanks in advance
Mark

#123108
Jun 25, 2015 7:16
Vote:
 

Hi,

At the moment, no. Commerce uses the same value in UIMaxVersions as CMS does - the request in the link you provided was fixed and released in Commerce 7.10.3. For the simplicity we use the same UIMaxVersions  - as it should apply for all "versionable" content.

Regards.

/Q

#123113
Jun 25, 2015 9:30
Vote:
 

ok thanks, so would you happen to have a scheduled job or something similar that trims the version history for product content? Unfortunately upgrading at this point in time isn't an option for our client.

#123115
Jun 25, 2015 10:12
Vote:
 

We don't have that by default, but I think you can easily write one to iterate over catalog contents and make the trim.

Regards.

/Q

#123116
Jun 25, 2015 10:30
Vote:
 

Hi Quan,

I've hit an issue with my scheduled job.  I keep getting the following error when calling "_contentVersionRepository.Delete(versionContent.ContentLink)" - Access was denied to content 4442_3_CatalogContent. The required access level was "Delete".

If I run this same code by hitting an action on a controller, it works fine (as long as I'm logged in as admin), but running manually (logged in as admin) from the scheduled job keeps failing.

As you can see I've added a few checks to ensure I'm logged in as admin and within the "Administrators" role.

var accessLevel = content.QueryAccess(); // returns read

var contentACL = new ContentAccessControlList(content.ContentLink); // return 0 results

bool userHasDeleteAccess = content.QueryDistinctAccess(AccessLevel.Delete); // returns false

if I try to add the "Delete" access level to the admin user, the save method fails

Is there something I'm missing? anything obvious you can see?

Thanks, Mark

public override string Execute()
{
    if (PrincipalInfo.CurrentPrincipal.Identity.Name == string.Empty)
    {
        PrincipalInfo.CurrentPrincipal = PrincipalInfo.CreatePrincipal("admin");
    }

    var isInAdmin = PrincipalInfo.CurrentPrincipal.IsInRole("Administrators");

    ...
}


private void CheckProductVersions(IContent content, FashionProductContent fashionProduct)
{
    var productContentVersions = _contentVersionRepository.List(content.ContentLink);
    var versionCount = productContentVersions.Count(v => v.LanguageBranch.ToLowerInvariant().Equals(GlobalConstants.DEFAULT_LOCALE));

    // Get the access level for the current user
    var accessLevel = content.QueryAccess();

    // Get the content ACL
    var contentACL = new ContentAccessControlList(content.ContentLink);

    bool userHasDeleteAccess = content.QueryDistinctAccess(AccessLevel.Delete);

    //if (!userHasDeleteAccess)
    //{
    //    contentACL.Add(new AccessControlEntry("admin", AccessLevel.Delete));
    //    contentACL.Save();
    //}

    if (versionCount > _versionLimit)
    {
        _productCount++;

        var count = 0;
        var deleteCount = 0;
        foreach (var versionContent in productContentVersions.OrderByDescending(v => v.Status.Equals(VersionStatus.Published)).ThenByDescending(v => v.Saved))
        {
            if (versionContent.Status.Equals(VersionStatus.Published))
            {
                count++;
            }
            else
            {
                if (count >= _versionLimit)
                {
                    _contentVersionRepository.Delete(versionContent.ContentLink);
                }
                else
                {
                    count++;
                }
            }
        }
    }
}
#123219
Jun 29, 2015 9:46
Vote:
 

Hi,

Can you check (by logging/debugging) to see the current user running scheduled job. By default it'll be anonymous. 

You can follw this blog spot to run with a specific account:

http://tedgustaf.com/blog/2008/8/run-a-scheduled-job-as-a-specific-episerver-user/

Regards

/Q

#123220
Jun 29, 2015 9:55
Vote:
 

Yeah, already tried that, see first few lines in my code snippet.  I've logged in as admin and when executing the job manually I can see the PrincipalInfo.CurrentPrincipal is the admin user.

#123221
Jun 29, 2015 9:58
Vote:
 

Sorry - missed that.

Tried this code on our Sample site, it runs perfectly with admin account:

var contentVersionRepository = ServiceLocator.Current.GetInstance<IContentVersionRepository>();
var referenceConverter = ServiceLocator.Current.GetInstance<ReferenceConverter>();
var contentLink = referenceConverter.GetContentLink(10, CatalogContentType.CatalogEntry, 0);
var productContentVersions = contentVersionRepository.List(contentLink);
foreach(var version in productContentVersions)
{
contentVersionRepository.Delete(version.ContentLink);
}

Note that CatalogContent does not truly implement the ACL, so you might not need those code at all.

Regards.

/Q

#123224
Jun 29, 2015 10:40
Vote:
 

And that works for you in a 7.9 install using a scheduled job?

#123225
Jun 29, 2015 11:13
Vote:
 

I tested on latest version - 8.13, but I think there would be no difference in this matter between two versions

#123226
Jun 29, 2015 11:45
Vote:
 

ok that doesn't really help my situation, can you try against a 7.9 install?  I've tested the following code on the sample mvc site (7.9) and it doesn't work.

I'm guessing there is some context that is used to get the user from and this isn't set, but seems like in the latest version 8.13 this is, so maybe there is a work around I can implement..?

    [ScheduledPlugIn(
        DisplayName = "Remove Old Product Content Versions", 
        Description = "A scheduled job will try to remove old product content versions.", 
        SortIndex = 1)]
    public class RemoveOldProductContentVersionsJob : JobBase
    {
        private const int VERSION_LIMIT = 3;

        public override string Execute()
        {
            var productCode = "TTCN-01";

            var referenceConverter = ServiceLocator.Current.GetInstance<ReferenceConverter>();
            var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
            var versionRepository = ServiceLocator.Current.GetInstance<IContentVersionRepository>();

            var catalogEntryResponse = new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo);
            var entry = CatalogContext.Current.GetCatalogEntry(productCode, catalogEntryResponse);

            if (entry != null)
            {
                var entryIdFromCommerce = Convert.ToInt32(entry.CatalogEntryId);
                var entryLink = referenceConverter.GetContentLink(entryIdFromCommerce, CatalogContentType.CatalogEntry, 0);
                var productContent = contentLoader.Get<FashionProductContent>(entryLink);
                var productContentVersions = versionRepository.List(entryLink);

                int count = 0;
                int deleteCount = 0;
                foreach (var content in productContentVersions.OrderByDescending(v => v.Status.Equals(VersionStatus.Published)).ThenByDescending(v => v.Saved))
                {
                    if (content.Status.Equals(VersionStatus.Published))
                    {
                        count++;
                    }
                    else
                    {
                        if (count > VERSION_LIMIT)
                        {
                            // delete
                            versionRepository.Delete(content.ContentLink);
                            deleteCount++;
                        }
                        else
                        {
                            count++;
                        }
                    }
                }

                return string.Format("ProductCode: [{0}], Name: [{1}], Versions: [{2}], Delete Versions: [{3}]", productCode, productContent.Name, productContentVersions.Count(), deleteCount);
            }

            return string.Format("Can't find ProductCode: [{0}]", productCode);
        }
    }
#123246
Jun 30, 2015 5:13
Vote:
 

Hi m.hitchcock

I'm having the exact same issue (EPi > V10 ).

Did you manage to solve this? I suspect the problem might be with IContentVersionRepository... do you know if there's any other way to delete a page version, in code?

Raf

#187387
Jan 22, 2018 12:27
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.