Commit 9e799b1d authored by totten's avatar totten

CRM-20243 - CRM_Upgrade_Form - Delete orphaned files before upgrade

parent dbc6b62a
......@@ -567,6 +567,13 @@ SET version = '$version'
'reset' => TRUE,
));
$task = new CRM_Queue_Task(
array('CRM_Upgrade_Form', 'doFileCleanup'),
array($postUpgradeMessageFile),
"Cleanup old files"
);
$queue->createItem($task);
$revisions = $upgrade->getRevisionSequence();
foreach ($revisions as $rev) {
// proceed only if $currentVer < $rev
......@@ -603,6 +610,47 @@ SET version = '$version'
return $queue;
}
/**
* Find any old, orphaned files that should have been deleted.
*
* These files can get left behind, eg, if you use the Joomla
* upgrade procedure.
*
* The earlier we can do this, the better - don't want upgrade logic
* to inadvertently rely on old/relocated files.
*
* @param \CRM_Queue_TaskContext $ctx
* @param string $postUpgradeMessageFile
* @return bool
*/
public static function doFileCleanup(CRM_Queue_TaskContext $ctx, $postUpgradeMessageFile) {
$source = new CRM_Utils_Check_Component_Source();
$files = $source->findOrphanedFiles();
$errors = array();
foreach ($files as $file) {
if (is_dir($file['path'])) {
@rmdir($file['path']);
}
else {
@unlink($file['path']);
}
if (file_exists($file['path'])) {
$errors[] = sprintf("<li>%s</li>", htmlentities($file['path']));
}
}
if (!empty($errors)) {
file_put_contents($postUpgradeMessageFile,
'<br/><br/>' . ts('Some old files could not be removed. Please remove them.')
. '<ul>' . implode("\n", $errors) . '</ul>',
FILE_APPEND
);
}
return TRUE;
}
/**
* Perform an incremental version update.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment