CleanUp

Summary: Purge deleted pages and attachments from the server directories
Version: 20220507
Prerequisites:
Status: Beta
Maintainer: Petko
Users: +6 (view / edit)
Discussion: CleanUp-Talk
License: GPL3+

Purge deleted pages and attachments from the server directories.

Description

  • When a wiki page is deleted, the disk file which contained it is archived and hidden. To actually remove the file, the administrator needs to log into the server via FTP or SSH and manually delete it.
  • When a new version of an attachment is uploaded (see $EnableUploadVersions), its previous versions are similarly archived.

With this recipe, wiki administrators can remove all "deleted" archived files (wiki pages or uploads) via a pmwiki action, without logging into the server.

Installation

  • Copy cleanup.phpΔ to your pmwiki/cookbook directory (alt. download: cleanup.php).
  • Add to config.php such a line:
    if($action=='cleanup' || $action=='cleanup2') include_once("$FarmD/cookbook/cleanup.php");

You also need to set the directories to be cleaned up. Typically, one or more of the following lines should be added to config.php:

  $CleanUpDirs[$WorkDir]  = 1;  # cleanup deleted wiki pages
  $CleanUpDirs["uploads"] = 1;  # cleanup deleted uploads

If you have enabled $PageCacheDir or $PageListCacheDir, you can also add them:

  $CleanUpDirs[$PageListCacheDir] = 1; # cleanup old cache from pagelists

The script will scan these directories recursively and will remove all "deleted" files from them and from their subdirectories.

Configuration

The script will remove files which were deleted more than 30 days ago and will keep the more recently deleted ones. To change the number of days, set in config.php:

  $CleanUpKeepDays =  0; # remove all deleted files/pages  -OR-
  $CleanUpKeepDays = 10; # remove files/pages deleted 10+ days ago

Note, the cleanup of the "cache" directories deletes the cached files as soon as they are obsolete.

The recipe should work with different $UploadPrefixFmt settings and with PerGroupSubDirectories. To scan only certain subdirectories of pmwiki/wiki.d or of pmwiki/uploads, set them instead of the ones in the Install section above:

  $CleanUpDirs["uploads/Main"]  = 1;    # cleanup deleted uploads in Main group

  # cleanup deleted pages in Main group (if PerGroupSubDirectories installed)
  $CleanUpDirs["$WorkDir/Main"] = 1;   # note the quotes

Usage

To purge all deleted files, there are two steps:

  1. Go to http://yourwiki/pmwiki.php?action=cleanup (you may need to enter your Administrator password). You will see a list of all scanned directories and subdirectories, and all files to be purged.
  2. If you are happy with the listed files, click on the link at the bottom of the page to actually delete them.

Notes

  • It is highly recommended to have backups when you perform mass deletions.
  • If you have a huge number of files to be deleted, combined with a slow server/filesystem, the script might hit the system limits before finishing the cleanup and display a warning about max_execution_time or set_time_limit. In that case, just reload the page until it finishes cleanly.

Change log / Release notes

  • 20220507 : Update for PHP 7.4-8.1.
  • 20140808 : Add preview mode. Only list directories containing files [to be] deleted, not all scanned directories. Note that the installation line has changed.
  • 20111102 : The recipe can now clean up cache directories.
  • 20111026 : First public release, ready to be tested.

See also

PmWiki /
BackupAndRestore  background information and some basic backup and restore procedures
DeletingPages  Removing wiki pages
Uploads  Allow authors to upload files, also known as page attachments
UploadsAdmin  Administration of PmWiki uploads
Cookbook /
Attachtable  Actions to rename, delete & restore deleted attachments, as well as an attachlist replacement to use those actions, show file types and list attachment references. (beta)
PageAttic  How to store backup files of deleted pages in a separate directory

Contributors

  • Recipe written and maintained by Petko (5ko [snail] 5ko [period] fr).
  • If this recipe helps you or saves you time, you can help support its continued development by .

Comments

See discussion at CleanUp-Talk

User notes +6: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.