Created
June 18, 2014 09:11
-
-
Save joomdonation/184e7808d3a4435678a5 to your computer and use it in GitHub Desktop.
Clean up un-used files in EDocman
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function files_clean_up() | |
| { | |
| jimport('joomla.filesystem.folder'); | |
| jimport('joomla.filesystem.file'); | |
| $db = JFactory::getDbo(); | |
| $config = EdocmanHelper::getConfig(); | |
| $path = $config->documents_path; | |
| $pathLength = strlen($path) ; | |
| $files = JFolder::files($config->documents_path, '.', true, true); | |
| $removeFiles = array(); | |
| for ($i = 0 , $n = count($files); $i < $n; $i++) | |
| { | |
| $file = $files[$i] ; | |
| $file = substr($file, $pathLength + 1) ; | |
| $file = str_replace("\\", '/', $file) ; | |
| $sql = 'SELECT COUNT(*) FROM #__edocman_documents WHERE filename='.$db->quote($file); | |
| $db->setQuery($sql); | |
| $total = $db->loadResult(); | |
| if (!$total) | |
| { | |
| $removeFiles[] = $files[$i]; | |
| } | |
| } | |
| print_r($removeFiles); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment