Commit bb7b1350423920aff9a52d68e60d213854beab7b

Authored by Neil Blakey-Milner
1 parent 0d3e200c

Add repository cleanup management for visualisation of what the cleanup

script will remove.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3830 c91229c3-7414-0410-bfa2-8a42b809f60b
config/siteMap.inc
@@ -143,6 +143,7 @@ $default->siteMap->addPage("manageHelp", "/presentation/lookAndFeel/knowledgeTre @@ -143,6 +143,7 @@ $default->siteMap->addPage("manageHelp", "/presentation/lookAndFeel/knowledgeTre
143 $default->siteMap->addPage("managePermissions", "/presentation/lookAndFeel/knowledgeTree/administration/permissions/managePermissions.php", "Administration", SysAdmin, _("Permissions Administration"), true, 18); 143 $default->siteMap->addPage("managePermissions", "/presentation/lookAndFeel/knowledgeTree/administration/permissions/managePermissions.php", "Administration", SysAdmin, _("Permissions Administration"), true, 18);
144 $default->siteMap->addPage("manageLookupTrees", "/presentation/lookAndFeel/knowledgeTree/administration/docfieldmanagement/manageLookupTrees.php", "Administration", SysAdmin, _("Lookup Tree Administration"), true, 19); 144 $default->siteMap->addPage("manageLookupTrees", "/presentation/lookAndFeel/knowledgeTree/administration/docfieldmanagement/manageLookupTrees.php", "Administration", SysAdmin, _("Lookup Tree Administration"), true, 19);
145 $default->siteMap->addPage("manageWorkflows", "/presentation/lookAndFeel/knowledgeTree/administration/workflow/workflows.php", "Administration", SysAdmin, _("Workflow Management"), true, 20); 145 $default->siteMap->addPage("manageWorkflows", "/presentation/lookAndFeel/knowledgeTree/administration/workflow/workflows.php", "Administration", SysAdmin, _("Workflow Management"), true, 20);
  146 +$default->siteMap->addPage("manageCleanup", "/presentation/lookAndFeel/knowledgeTree/administration/documentmanagement/manageCleanup.php", "Administration", SysAdmin, _("Repository Cleanup"), true, 21);
146 147
147 $default->siteMap->addSectionColour("Administration", "th", "056DCE"); 148 $default->siteMap->addSectionColour("Administration", "th", "056DCE");
148 $default->siteMap->addSectionColour("Administration", "td", "6699FF"); 149 $default->siteMap->addSectionColour("Administration", "td", "6699FF");
presentation/lookAndFeel/knowledgeTree/administration/documentmanagement/manageCleanup.php 0 → 100644
  1 +<?php
  2 +
  3 +require_once("../../../../../config/dmsDefaults.php");
  4 +
  5 +require_once(KT_DIR . "/presentation/Html.inc");
  6 +
  7 +require_once(KT_LIB_DIR . "/templating/templating.inc.php");
  8 +require_once(KT_LIB_DIR . "/help/helpreplacement.inc.php");
  9 +require_once(KT_LIB_DIR . "/help/helpentity.inc.php");
  10 +require_once(KT_LIB_DIR . "/help/help.inc.php");
  11 +
  12 +require_once(KT_LIB_DIR . "/dispatcher.inc.php");
  13 +$sectionName = "Administration";
  14 +require_once(KT_DIR . "/presentation/webpageTemplate.inc");
  15 +
  16 +require_once(KT_LIB_DIR . '/browse/browseutil.inc.php');
  17 +
  18 +$oConfig =& KTConfig::getSingleton();
  19 +$fsPath = $oConfig->get('urls/documentRoot');
  20 +
  21 +$aIgnore = array(
  22 + '.', '..',
  23 + 'CVS',
  24 + '.empty',
  25 + '.htaccess',
  26 + '.cvsignore',
  27 +);
  28 +
  29 +$aFoldersToRemove = array();
  30 +$aFilesToRemove = array();
  31 +$aRepoDocumentProblems = array();
  32 +$aRepoFolderProblems = array();
  33 +$aRepoVersionProblems = array();
  34 +
  35 +function checkFileVersion($path, $version) {
  36 + $fod = KTBrowseUtil::folderOrDocument($path);
  37 + if ($fod === false) {
  38 + // No document by that name, so no point checking version
  39 + // information.
  40 + return;
  41 + }
  42 + return true;
  43 +}
  44 +
  45 +function checkFile($path, $first = true) {
  46 + $pattern = "/^(.*)-((?:\d+)\.(?:\d+))$/";
  47 + if (preg_match($pattern, $path, $matches)) {
  48 + if (checkFileVersion($matches[1], $matches[2])) {
  49 + // If it's a version, then don't check for full path
  50 + // below...
  51 + return;
  52 + }
  53 + }
  54 + $fod = KTBrowseUtil::folderOrDocument($path);
  55 + if ($fod === false) {
  56 + $GLOBALS["aFilesToRemove"][] = $path;
  57 + return;
  58 + }
  59 +}
  60 +
  61 +function checkDirectory($path) {
  62 + global $fsPath, $aIgnore;
  63 + $fullpath = sprintf("%s/%s", $fsPath, $path);
  64 +
  65 + if (!is_dir($fullpath)) {
  66 + print "Not a directory: $fullpath\n";
  67 + }
  68 +
  69 + if ($path === '/Deleted') {
  70 + // Deleted files handled separately.
  71 + return;
  72 + }
  73 +
  74 + if (!empty($path)) {
  75 + $fod = KTBrowseUtil::folderOrDocument($path);
  76 + if ($fod === false) {
  77 + $GLOBALS["aFoldersToRemove"][] = $path;
  78 + return;
  79 + }
  80 + }
  81 +
  82 + $dh = @opendir($fullpath);
  83 + if ($dh === false) {
  84 + print "Could not open directory: $fullpath\n";
  85 + }
  86 + while (($filename = readdir($dh)) !== false) {
  87 + if (in_array($filename, $aIgnore)) { continue; }
  88 + $subrelpath = sprintf("%s/%s", $path, $filename);
  89 + $subfullpath = sprintf("%s/%s", $fsPath, $subrelpath);
  90 + if (is_dir($subfullpath)) {
  91 + checkDirectory($subrelpath);
  92 + }
  93 + if (is_file($subfullpath)) {
  94 + checkFile($subrelpath);
  95 + }
  96 + }
  97 +}
  98 +
  99 +function checkRepoFolder($oFolder) {
  100 + global $fsPath, $aRepoFolderProblems;
  101 + $sFolderPath = sprintf("%s/%s", $oFolder->getFullPath(), $oFolder->getName());
  102 + $sFullPath = sprintf("%s/%s", $fsPath, $sFolderPath);
  103 + if (!is_dir($sFullPath)) {
  104 + $aRepoFolderProblems[] = $sFolderPath;
  105 + }
  106 +}
  107 +
  108 +function checkRepoDocument($oDocument) {
  109 + global $fsPath, $aRepoDocumentProblems;
  110 + $sDocumentPath = $oDocument->getStoragePath();
  111 + $sFullPath = sprintf("%s/%s", $fsPath, $sDocumentPath);
  112 + if (!is_file($sFullPath)) {
  113 + $aRepoDocumentProblems[] = $sDocumentPath;
  114 + }
  115 + checkRepoVersions($oDocument);
  116 +}
  117 +
  118 +function checkRepoVersions($oDocument) {
  119 + global $fsPath, $aRepoVersionProblems;
  120 + $table = "document_transactions";
  121 + $aVersions = DBUtil::getResultArrayKey(array("SELECT DISTINCT version FROM $table WHERE document_id = ?", array($oDocument->getID())), "version"); foreach($aVersions as $sVersion) {
  122 + if ($sVersion == $oDocument->getVersion()) {
  123 + continue;
  124 + }
  125 + $sDocumentPath = $oDocument->getStoragePath();
  126 + $sFullPath = sprintf("%s/%s-%s", $fsPath, $sDocumentPath, $sVersion);
  127 + if (!is_file($sFullPath)) {
  128 + $aRepoVersionProblems[] = array($sDocumentPath, $sVersion);
  129 + continue;
  130 + }
  131 + }
  132 +}
  133 +
  134 +class ManageCleanupDispatcher extends KTAdminDispatcher {
  135 + function do_main() {
  136 + global $aFoldersToRemove;
  137 + global $aFilesToRemove;
  138 + global $aRepoDocumentProblems;
  139 + global $aRepoFolderProblems;
  140 + global $aRepoVersionProblems;
  141 +
  142 + checkDirectory("");
  143 + $aFolders =& Folder::getList();
  144 + foreach ($aFolders as $oFolder) {
  145 + checkRepoFolder($oFolder);
  146 + }
  147 + $aDocuments =& Document::getList(array("status_id = ?", array(LIVE)));
  148 + foreach ($aDocuments as $oDocument) {
  149 + checkRepoDocument($oDocument);
  150 + }
  151 + $oTemplate =& $this->oValidator->validateTemplate('ktcore/document/cleanup');
  152 + $oTemplate->setData(array(
  153 + 'aFoldersToRemove' => $aFoldersToRemove,
  154 + 'aFilesToRemove' => $aFilesToRemove,
  155 + 'aRepoDocumentProblems' => $aRepoDocumentProblems,
  156 + 'aRepoFolderProblems' => $aRepoFolderProblems,
  157 + 'aRepoVersionProblems' => $aRepoVersionProblems,
  158 + ));
  159 + return $oTemplate->render();
  160 + }
  161 +}
  162 +
  163 +$oDispatcher = new ManageCleanupDispatcher();
  164 +$oDispatcher->dispatch();
  165 +
  166 +?>
templates/ktcore/document/cleanup.smarty 0 → 100644
  1 +{if $aFoldersToRemove}
  2 +<p>Would remove these folders (and all their contents):</p>
  3 +<ul>
  4 +{foreach from=$aFoldersToRemove item=sFolder}
  5 +<li>{$sFolder|escape}</li>
  6 +{/foreach}
  7 +</ul>
  8 +{/if}
  9 +
  10 +{if $aFilesToRemove}
  11 +<p>Would remove these files:</p>
  12 +<ul>
  13 +{foreach from=$aFoldersToRemove item=sFile}
  14 +<li>{$sFile|escape}</li>
  15 +{/foreach}
  16 +</ul>
  17 +{/if}
  18 +
  19 +{if $aRepoFolderProblems}
  20 +<p>These folders are not on the filesystem</p>
  21 +<ul>
  22 +{foreach from=$aRepoFolderProblems item=sFolder}
  23 +<li>{$sFolder|escape}</li>
  24 +{/foreach}
  25 +</ul>
  26 +{/if}
  27 +
  28 +{if $aRepoDocumentProblems}
  29 +<p>These documents are not on the filesystem</p>
  30 +<ul>
  31 +{foreach from=$aRepoDocumentProblems item=sDocument}
  32 +<li>{$sDocument|escape}</li>
  33 +{/foreach}
  34 +</ul>
  35 +{/if}
  36 +
  37 +{if $aRepoVersionProblems}
  38 +<p>These documents have versions not on the filesystem</p>
  39 +<ul>
  40 +{foreach from=$aRepoVersionProblems item=aSomething}
  41 +<li>{$aSomething[0]|escape} - version {$aSomething[1]|escape}</li>
  42 +{/foreach}
  43 +</ul>
  44 +{/if}