Clear out version history
Permalink
Hello,
When I move a site from staging to production, I want to wipe out all old versions so we start with a clean slate.
I understand there's little overhead in keeping the old versions around, but once we turn the site over, I'd rather have a baseline so that if something breaks, I'm only looking at changes someone else has made rather than digging through the (sometimes hundreds) of changes that were made during testing and QA.
How can I do this on a site-wide basis?
Thanks!
When I move a site from staging to production, I want to wipe out all old versions so we start with a clean slate.
I understand there's little overhead in keeping the old versions around, but once we turn the site over, I'd rather have a baseline so that if something breaks, I'm only looking at changes someone else has made rather than digging through the (sometimes hundreds) of changes that were made during testing and QA.
How can I do this on a site-wide basis?
Thanks!
so, it's not only me after all, he hee..
the problem is, we dont want to mess up with db and relation beetwen tabel.
the problem is, we dont want to mess up with db and relation beetwen tabel.
Easiest way I know how is to go via the Sitemap within the Dashboard for each page. :(
I notice the latest C5 has a automated job to clear out versions leaving just the last 10 versions of each page.
Does someone have a way to clear out all versions?
Does someone have a way to clear out all versions?
Bump
Not tested, but something like this maybe?
Probably needs some exception handling...
Probably needs some exception handling...
Loader::model('page_list'); $pl = new PageList(); $pages = $pl->getPages(); foreach($pages as $page) { if($page instanceof Page) { $pvl = new VersionList($page); $versions = $pvl->getVersionListArray(); $versions = array_reverse($versions); foreach($versions as $v) { if($v instanceof CollectionVersion) { if($v->isApproved() || $v->isMostRecent()) { // may want to add a date check here too continue; } else { @$v->delete(); }
Viewing 15 lines of 19 lines. View entire code block.
Looks good ... where should it go pray tell?
This code is not ready for a production site. It was just meant as a starting point.
However, if you wanted to try it out, I would just create a single page and past it in, then go to the page and see what errors you get. Then you can make adjustments until you get the desired result.
One thing I would do is add a filter to the page list (for instance, filter by parent or page type) to limit the number of pages until you get the code to work properly. You will likely not be able to process a large number of pages at once. I know there is a way to split a page list up so that you only process a specific number of pages at a time.
Again, this is not ready for use. Just off the top of my head.
However, if you wanted to try it out, I would just create a single page and past it in, then go to the page and see what errors you get. Then you can make adjustments until you get the desired result.
One thing I would do is add a filter to the page list (for instance, filter by parent or page type) to limit the number of pages until you get the code to work properly. You will likely not be able to process a large number of pages at once. I know there is a way to split a page list up so that you only process a specific number of pages at a time.
$pl->setItemsPerPage(10); $pg = ($lastPg ? 0 : $lastPg); $pg++; $pages = $pl->getPage($pg);
Again, this is not ready for use. Just off the top of my head.
I am wondering whether one can tweak the existing automated job (or create a new one based on it) to delete all but the most recent version...?
I believe all you would need to do is remove this line (line 67).
from [root]/concrete/core/jobs/remove_old_page_version.php
if($i >= $stopAt) { break; }
from [root]/concrete/core/jobs/remove_old_page_version.php
Thanks for the tip.
I actually did it slightly differently by changing lines 53-55 from this:
to this:
Wasn't sure if removing line 67 would not result in all the pages from being removed without having to first think too hard about it!
I actually did it slightly differently by changing lines 53-55 from this:
if($vCount <= 10) { continue; } $pageCount++; $stopAt = $vCount - 10;
to this:
if($vCount <= 1) { continue; } $pageCount++; $stopAt = $vCount - 1;
Wasn't sure if removing line 67 would not result in all the pages from being removed without having to first think too hard about it!
http://www.concrete5.org/community/forums/usage/delete-previous-ver...
Maybe one day someone writes an add-on that could to this...?
Michael