Skip to content

Instantly share code, notes, and snippets.

@joomdonation
Created June 18, 2014 09:11
Show Gist options
  • Select an option

  • Save joomdonation/184e7808d3a4435678a5 to your computer and use it in GitHub Desktop.

Select an option

Save joomdonation/184e7808d3a4435678a5 to your computer and use it in GitHub Desktop.
Clean up un-used files in EDocman
<?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