public function backupArchive(ContainerNodeInterface $containerNode, \SplFileInfo $archive)
{
// if we don't want to create backups, to nothing
if ($this->getExtractorNode()->isCreateBackups() === false) {
return;
}
// load the PHAR archive's pathname
$pharPathname = $archive->getPathname();
// create tmp & webapp folder name based on the archive's basename
$webappFolderName = $this->getWebappsDir($containerNode) . DIRECTORY_SEPARATOR . basename($archive->getFilename(), $this->getExtensionSuffix());
$tmpFolderName = $this->getTmpDir($containerNode) . DIRECTORY_SEPARATOR . md5(basename($archive->getFilename(), $this->getExtensionSuffix()));
// initialize PHAR archive
$p = new \Phar($archive);
// iterate over the PHAR content to backup files that are NOT part of the archive
foreach (new \RecursiveIteratorIterator($p) as $file) {
unlink(str_replace($this->createUrl($pharPathname), $webappFolderName, $file->getPathName()));
}
// delete empty directories but LEAVE files created by app
$this->removeDir($webappFolderName, false);
// copy backup to tmp directory
$this->copyDir($webappFolderName, $tmpFolderName);
// we have to set the user rights to the user:group configured within the system configuration
$this->setUserRights(new \SplFileInfo($tmpFolderName));
// log a message that the application has successfully been deployed
$this->getInitialContext()->getSystemLogger()->info(sprintf('Application archive %s has succussfully been backed up', $archive->getBasename($this->getExtensionSuffix())));
}