/**
* Compares two "files" entries to find deleted files/folders
*
* @param array $oldFiles An array of \SimpleXMLElement objects that are the old files
* @param array $newFiles An array of \SimpleXMLElement objects that are the new files
*
* @return array An array with the delete files and folders in findDeletedFiles[files] and findDeletedFiles[folders] respectively
*
* @since 3.1
*/
public function findDeletedFiles($oldFiles, $newFiles)
{
// The magic find deleted files function!
// The files that are new
$files = array();
// The folders that are new
$folders = array();
// The folders of the files that are new
$containers = array();
// A list of files to delete
$files_deleted = array();
// A list of folders to delete
$folders_deleted = array();
foreach ($newFiles as $file) {
switch ($file->getName()) {
case 'folder':
// Add any folders to the list
$folders[] = (string) $file;
break;
case 'file':
default:
// Add any files to the list
$files[] = (string) $file;
// Now handle the folder part of the file to ensure we get any containers
// Break up the parts of the directory
$container_parts = explode('/', \dirname((string) $file));
// Make sure this is clean and empty
$container = '';
foreach ($container_parts as $part) {
// Iterate through each part
// Add a slash if its not empty
if (!empty($container)) {
$container .= '/';
}
// Append the folder part
$container .= $part;
if (!\in_array($container, $containers)) {
// Add the container if it doesn't already exist
$containers[] = $container;
}
}
break;
}
}
foreach ($oldFiles as $file) {
switch ($file->getName()) {
case 'folder':
if (!\in_array((string) $file, $folders)) {
// See whether the folder exists in the new list
if (!\in_array((string) $file, $containers)) {
// Check if the folder exists as a container in the new list
// If it's not in the new list or a container then delete it
$folders_deleted[] = (string) $file;
}
}
break;
case 'file':
default:
if (!\in_array((string) $file, $files)) {
// Look if the file exists in the new list
if (!\in_array(\dirname((string) $file), $folders)) {
// Look if the file is now potentially in a folder
$files_deleted[] = (string) $file;
}
}
break;
}
}
return array('files' => $files_deleted, 'folders' => $folders_deleted);
}