Commit 198fd7e0060905e5ab1b2c964477b8aff4e21764
1 parent
ea521904
Cronjob-friendly storage verification.
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5550 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
2 changed files
with
146 additions
and
0 deletions
bin/storageverification.php
0 → 100755
| 1 | +<?php | |
| 2 | + | |
| 3 | +require_once('../config/dmsDefaults.php'); | |
| 4 | +require_once(KT_LIB_DIR . "/dispatcher.inc.php"); | |
| 5 | +$sectionName = "Administration"; | |
| 6 | +require_once(KT_LIB_DIR . "/templating/kt3template.inc.php"); | |
| 7 | + | |
| 8 | +require_once(KT_LIB_DIR . '/browse/browseutil.inc.php'); | |
| 9 | + | |
| 10 | +class VerifyDispatcher extends KTDispatcher { | |
| 11 | + function VerifyDispatcher() { | |
| 12 | + $this->aIgnore = array( | |
| 13 | + '.', '..', | |
| 14 | + 'CVS', | |
| 15 | + '.empty', | |
| 16 | + '.htaccess', | |
| 17 | + '.cvsignore', | |
| 18 | + '.svn', | |
| 19 | + ); | |
| 20 | + | |
| 21 | + $oConfig =& KTConfig::getSingleton(); | |
| 22 | + $this->fsPath = $oConfig->get('urls/documentRoot'); | |
| 23 | + | |
| 24 | + return parent::KTDispatcher(); | |
| 25 | + } | |
| 26 | + | |
| 27 | + function do_main() { | |
| 28 | + global $aFoldersToRemove; | |
| 29 | + global $aFilesToRemove; | |
| 30 | + global $aRepoDocumentProblems; | |
| 31 | + global $aRepoFolderProblems; | |
| 32 | + global $aRepoVersionProblems; | |
| 33 | + | |
| 34 | + | |
| 35 | + $this->checkDirectory(""); | |
| 36 | + | |
| 37 | + $aDocuments =& Document::getList(); | |
| 38 | + foreach ($aDocuments as $oDocument) { | |
| 39 | + $this->checkRepoDocument($oDocument); | |
| 40 | + } | |
| 41 | + | |
| 42 | + if (!($this->aFilesToRemove or $this->aRepoDocumentProblems)) { | |
| 43 | + return; | |
| 44 | + } | |
| 45 | + | |
| 46 | + $oTemplate =& | |
| 47 | + $this->oValidator->validateTemplate('ktcore/document/cleanup_script'); | |
| 48 | + $oTemplate->setData(array( | |
| 49 | + 'aFilesToRemove' => $this->aFilesToRemove, | |
| 50 | + 'aRepoDocumentProblems' => $this->aRepoDocumentProblems, | |
| 51 | + )); | |
| 52 | + print $oTemplate->render(); | |
| 53 | + exit(0); | |
| 54 | + } | |
| 55 | + | |
| 56 | + function checkDirectory($path) { | |
| 57 | + $fullpath = sprintf("%s/%s", $this->fsPath, $path); | |
| 58 | + | |
| 59 | + if (!is_dir($fullpath)) { | |
| 60 | + print "Not a directory: $fullpath\n"; | |
| 61 | + } | |
| 62 | + | |
| 63 | + $dh = @opendir($fullpath); | |
| 64 | + if ($dh === false) { | |
| 65 | + print "Could not open directory: $fullpath\n"; | |
| 66 | + } | |
| 67 | + while (($filename = readdir($dh)) !== false) { | |
| 68 | + if (in_array($filename, $this->aIgnore)) { continue; } | |
| 69 | + $subrelpath = sprintf("%s/%s", $path, $filename); | |
| 70 | + if (substr($subrelpath, 0, 1) == "/") { | |
| 71 | + $subrelpath = substr($subrelpath, 1); | |
| 72 | + } | |
| 73 | + $subfullpath = sprintf("%s/%s", $this->fsPath, $subrelpath); | |
| 74 | + if (is_dir($subfullpath)) { | |
| 75 | + $this->checkDirectory($subrelpath); | |
| 76 | + } | |
| 77 | + if (is_file($subfullpath)) { | |
| 78 | + $this->checkFile($subrelpath); | |
| 79 | + } | |
| 80 | + } | |
| 81 | + } | |
| 82 | + | |
| 83 | + function checkFile($path, $first = true) { | |
| 84 | + $oDocument = KTEntityUtil::getByDict('KTDocumentContentVersion', array( | |
| 85 | + 'storage_path' => $path, | |
| 86 | + )); | |
| 87 | + if (is_a($oDocument, 'ktentitynoobjects')) { | |
| 88 | + $this->aFilesToRemove[] = $path; | |
| 89 | + return; | |
| 90 | + } | |
| 91 | + } | |
| 92 | + | |
| 93 | + function checkRepoDocument($oDocument) { | |
| 94 | + global $aRepoDocumentProblems; | |
| 95 | + $aDCVs = KTDocumentContentVersion::getByDocument($oDocument); | |
| 96 | + foreach ($aDCVs as $oDCV) { | |
| 97 | + $sDocumentPath = $oDCV->getStoragePath(); | |
| 98 | + $sFullPath = sprintf("%s/%s", $this->fsPath, $sDocumentPath); | |
| 99 | + if (!is_file($sFullPath)) { | |
| 100 | + $this->aRepoDocumentProblems[] = array( | |
| 101 | + 'document' => $oDocument, | |
| 102 | + 'content' => $oDCV, | |
| 103 | + 'path' => $sDocumentPath, | |
| 104 | + 'doclink' => KTBrowseUtil::getUrlForDocument($oDocument), | |
| 105 | + ); | |
| 106 | + } | |
| 107 | + } | |
| 108 | + } | |
| 109 | +} | |
| 110 | +$oDispatcher = new VerifyDispatcher; | |
| 111 | +$oDispatcher->do_main(); | |
| 112 | + | |
| 113 | +?> | ... | ... |
templates/ktcore/document/cleanup_script.smarty
0 → 100644
| 1 | +{i18n}Warning: Database is inconsistent with the contents of the repository.{/i18n} | |
| 2 | + | |
| 3 | + | |
| 4 | +{i18n}All paths are relative to your Documents directory.{/i18n} | |
| 5 | + | |
| 6 | + | |
| 7 | +{if $aRepoDocumentProblems} | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | +{i18n}These documents have versions that are not present on the filesystem. Consider restoring them from backups.{/i18n} | |
| 12 | + | |
| 13 | + | |
| 14 | +{foreach from=$aRepoDocumentProblems item=aInfo} | |
| 15 | +{assign var=oDocument value=$aInfo.document} | |
| 16 | +{assign var=oContent value=$aInfo.content} | |
| 17 | +{assign var=docname value=$oDocument->getName()} | |
| 18 | + {i18n arg_filepath="`$aInfo.path`" arg_docname="$docname" arg_doclink="`$aInfo.doclink`"}#docname# (#doclink# version {$oContent->getMajorVersionNumber()}.{$oContent->getMinorVersionNumber()}) — Cannot find file: #filepath#{/i18n} | |
| 19 | +{/foreach} | |
| 20 | + | |
| 21 | +{/if} | |
| 22 | + | |
| 23 | +{if $aFilesToRemove} | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | +{i18n}The following files are present in the repository, but do not exist in the database.{/i18n}: | |
| 28 | + | |
| 29 | +{foreach from=$aFilesToRemove item=sFile} | |
| 30 | + {$sFile|escape} | |
| 31 | +{/foreach} | |
| 32 | + | |
| 33 | +{/if} | ... | ... |