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!

spork
View Replies:
okapi replied on at Permalink Reply
okapi
Me too, i would be happy to find a solution for clearing out all old versions of all pages of a site. But obviously there is no easy way to achieve that:

http://www.concrete5.org/community/forums/usage/delete-previous-ver...

Maybe one day someone writes an add-on that could to this...?

Michael
fastcrash replied on at Permalink Reply
fastcrash
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.
Kurieuo replied on at Permalink Reply
Easiest way I know how is to go via the Sitemap within the Dashboard for each page. :(
cytringan replied on at Permalink Reply
cytringan
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?
keeasti replied on at Permalink Reply
keeasti
Bump
ScottSandbakken replied on at Permalink Reply
ScottSandbakken
Not tested, but something like this maybe?

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();
                  }
keeasti replied on at Permalink Reply
keeasti
Looks good ... where should it go pray tell?
ScottSandbakken replied on at Permalink Reply
ScottSandbakken
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.

$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.
keeasti replied on at Permalink Reply
keeasti
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...?
ScottSandbakken replied on at Permalink Reply
ScottSandbakken
I believe all you would need to do is remove this line (line 67).

if($i >= $stopAt) { break; }


from [root]/concrete/core/jobs/remove_old_page_version.php
keeasti replied on at Permalink Reply
keeasti
Thanks for the tip.

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!