JInstaller/findDeletedFiles
From Joomla! Documentation
< API16:JInstaller
The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.
Description[edit]
Compares two "files" entries to find deleted files/folders
<! removed transcluded page call, red link never existed >
Syntax[edit]
findDeletedFiles($old_files, $new_files)
Parameter Name | Default Value | Description |
---|---|---|
$old_files | An array of objects that are the old files | |
$new_files | An array of objects that are the new files |
Returns[edit]
array An array with the delete files and folders in findDeletedFiles[files] and findDeletedFiles[folders] resepctively
Defined in[edit]
libraries/joomla/installer/installer.php
Importing[edit]
jimport( 'joomla.installer.installer' );
Source Body[edit]
public function findDeletedFiles($old_files, $new_files)
{
// The magic find deleted files function!
$files = Array(); // the files that are new
$folders = Array(); // the folders that are new
$containers = Array(); // the folders of the files that are new
$files_deleted = Array(); // a list of files to delete
$folders_deleted = Array(); // a list of folders to delete
foreach ($new_files as $file)
{
switch($file->getName())
{
case 'folder':
$folders[] = (string)$file; // add any folders to the list
break;
case 'file':
default:
$files[] = (string)$file; // add any files to the list
// now handle the folder part of the file to ensure we get any containers
$container_parts = explode('/',dirname((string)$file)); // break up the parts of the directory
$container = ''; // make sure this is clean and empty
foreach ($container_parts as $part)
{
// iterate through each part
if (!empty($container)) $container .= '/'; // add a slash if its not empty
$container .= $part; // append the folder part
if (!in_array($container, $containers)) $containers[] = $container; // add the container if it doesn't already exist
}
break;
}
}
foreach ($old_files as $file)
{
switch($file->getName())
{
case 'folder':
if (!in_array((string)$file, $folders))
{
// look if 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
$folders_deleted[] = (string)$file; // if its not in the new list or a container then delete it
}
}
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; // not in a folder, doesn't exist, wipe it out!
}
}
break;
}
}
return Array('files'=>$files_deleted, 'folders'=>$folders_deleted);
}
<! removed transcluded page call, red link never existed >
Examples[edit]
Code Examples[edit]