Delete old page versions

Vote:
 

I am abouot to do a test-migration of a CMS4 site to CMS5, and one recommended action is to delete old versjons of pages before starting the migration tool. Since the migration tool parses each en every version of a page, having a large number of versioned pages will naturally slow down the migration process.

I have set the "max number of old versions" under System settings to a low number, but obviously that does not have any effect on versions already created.

My question is therefore: How to get rid of old versions for the entire site (or leave say, max 2 versions)?

I have posted this as a feature request, but if anyone have a good solution already, please respond to this post.

#21324
Jun 26, 2008 11:25
Vote:
 

Hi,

 There is a code sample for this, a scheduled job that you can run:

http://world.episerver.com/Download/Code-Samples/Productivity/Remove-old-versions-job/

Do a backup of the database before you start if anything goes wrong...

 -- Per

#21327
Jun 26, 2008 11:59
Vote:
 

Hi guys,

Per, I have tryed your code on a web site im perfecting and it doesn't work so good. The problem is that there are a LOT of page versions that I need to delete (around 25/page and over 5000 pages) I am working straight toward the database procedures now to try to make it more efficiently.

Do you have any suggestions or a script that could help me out?

cheers

Diego

#24064
Sep 23, 2008 10:04
Vote:
 

I got the same trouble Diego, I´m having a lot of pages with a lot of versions and this job doesn't work. 

In the recycle bin I have around 1000 pages and some of the pages in the recycle bin has more then 4000 page versions. All these pages makes the empty recycle bin job to fail every night.

All SQL query's from episerver support seems to stop to work when the site has to many pages with to many page versions. Even the store procedure editDeleteObsoletePageVersions fails when i use it directly in the sql server.

Right now I have built a rely slooooow job that deletes all old page versions in the recycle bin.

Its an recusive function that uses this method to delete the old versions.

PageVersionCollection versions = PageVersion.List(p.PageLink);
if (versions.Count > 1)
{
    foreach (PageVersion version in versions)
    {
        if (version.ID != versions[versions.Count - 1].ID)
        {
            EPiServer.Global.EPDataFactory.DeleteVersion(version.ID);
            totalremovedversions++;
        }
    }
}

This function deletes on page version every sec. I'm not looking forward to doing this on all pages on the website.

#45356
Nov 04, 2010 15:26
Vote:
 

i created the following script to minimize all page version too 5. Please note this was the first version of the script and alot of optomisation was done afterwards to it although cant seem to find the final version.

 

SET

SET

declare

NOCOUNT ON XACT_ABORT ON @pkID int;

declare

SELECT

 

page_cursor CURSOR FOR [pkID]FROM EPiSe[dbo].[tblPage]

open

page_cursor

fetch

next from page_cursor into @pkID

while

@@FETCH_STATUS = 0

BEGIN

 

DECLARE @ObsoleteVersions INT

 

DECLARE @DeleteWorkPageID INT

 

DECLARE @retval INT

 

DECLARE @CurrentLanguage INT

 

DECLARE @FirstLanguage BIT

 

 

 

SET @FirstLanguage = 1BEGIN TRAN

 

CREATE TABLE #languages (fkLanguageBranchID INT)

 

 

INSERT INTO #languages SELECT fkLanguageBranchID FROM tblWorkPage WHERE fkPageID = @pkID GROUP BY fkLanguageBranchIDSET @CurrentLanguage = (SELECT MIN(fkLanguageBranchID) FROM #languages)

 

 

WHILE (NOT @CurrentLanguage = 0)

 

BEGIN

 

 

SELECT @ObsoleteVersions=COUNT(pkID)-1 FROM tblWorkPage WHERE fkPageID= @pkID AND HasBeenPublished=1 AND fkLanguageBranchID = @CurrentLanguageWHILE (@ObsoleteVersions > 5)

 

BEGIN

 

SELECT TOP 1 @DeleteWorkPageID=pkID FROM tblWorkPage WHERE fkPageID= @pkID AND HasBeenPublished=1 AND fkLanguageBranchID = @CurrentLanguage ORDER BY pkID ASC

 

 

EXEC @retval=editDeletePageVersion @WorkPageID=@DeleteWorkPageIDIF (@retval <> 0)

 

BREAK

 

 

SET @ObsoleteVersions=@ObsoleteVersions - 1END

 

IF EXISTS(SELECT fkLanguageBranchID FROM #languages WHERE fkLanguageBranchID > @CurrentLanguage)

 

SET @CurrentLanguage = (SELECT MIN(fkLanguageBranchID) FROM #languages WHERE fkLanguageBranchID > @CurrentLanguage)

 

ELSE

 

 

SET @CurrentLanguage = 0END

 

 

 

 

DROP TABLE #languagesCOMMIT TRAN

 

fetch next from page_cursor into @pkID

END

close

page_cursor

deallocate

page_cursor

#47718
Feb 10, 2011 13:43
* 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.