Delete versions of files

Permalink 1 user found helpful
On version 5.3.1, I have deleted an older version of a PDF via the appropriate dashboard interface. The version is correctly deleted from the database but the file is still found on the filesystem.

1. Is this meant or is this a bug I should report? Is there some sort of maintenance script that purge such orphan files?

2. Is there an existing way to 'maintain' the system by deleting old versions (by date, or by number - i.e. keep only 5 versions of page/files)?

Cheers.

 
wombat replied on at Permalink Reply
Looking at concrete/models/file_version.php , it seems the intention was there (see the first comment inside the function):

/**
 * Removes a version of a file
 */
 public function delete() {
   // first, we remove all files from the drive
   if ($this->fvIsApproved == 1) {
     return false; // can only delete non-live files
   }
   $db = Loader::db();
   // now from the DB
   [..]
 }


but there is nothing actually deleting the file from the filesystem.

So -> for Question 1. I'll submit a bug.
Question 2. though is still very much something I'd like to hear about.
synlag replied on at Permalink Reply
synlag
the files aren't moved like themes into the trash folder and remain in the original folders
glockops replied on at Permalink Reply
glockops
I would also be interested in setting a cap to the number of version any particular file could have.

Like retain the last 5 or 10 versions of the file - when a new edit is made, the oldest version is automatically removed.

I've notice that there is a way to remove the versions by individually removing older versions on each file, but on a large site with lots of edits this will become burdensome.

I'm dealing with around 1,000 pages on an existing site and once I get it transferred into C5 I'm looking at somewhere between 6-10k versions of files (lots of edits / updates) - seems like a waste to keep everything when only the last 1-2 versions will ever be used.

So any ideas for automatically limit the number C5 saves? Does it do this now?

Thanks!
ScottC replied on at Permalink Reply
ScottC
those things are wide open :) It is a bit late here but i am sure file versions are stored in the db and you can certainly just get a chronological sort and run a delete method on anything older than your arbitrary #. Run it daily and keep the last 5 or whatever you are comfortable with.
NUL76 replied on at Permalink Reply
NUL76
Hé wombat,

I ran into the samen issue. Over 8000 large images on the disk with our real estate connector (NVM Realworks), while we only had 3000 different files in the library. It's build to update any changed image, but would like to remove the older versions immediately.

Here is a small function i made, which loops all versions of a file (fID) and unlinks + deletes the not active versions. For stats in a long batch, it returns the number of fileversions deleted.

private function del_old_versions($fID)
   {
      $f = File::getByID($fID);
      $i=0;
      foreach($f->getVersionList() as $key => $fv)
      {
         if(!$fv->isApproved())
         {
            $path = $fv->getPath();
            if (unlink($path)) 
            {
               $i++;
               $fv->delete();
            }
         }


Anyone running into this problem try this function. If you're having trouble, let me know.
abberdab replied on at Permalink Reply
abberdab
NUL76, I'm intrigued by this solution, having struggled with this old version problem, too. Excuse my ignorance, but how do you implement this script, where does it go? Are you just appending it to the standard Concrete file block? Or...?
NUL76 replied on at Permalink Reply
NUL76
Hi Abberdab,

It depends where or when you need it.

We implemented this in a job which imports files. If you don't do this, you could make a job like the one that deletes older page versions. And set a cronjob to automatically run it.

Hope this helps!