AppserverIo\Appserver\Core\Extractors\PharExtractor::backupArchive PHP Method

backupArchive() public method

Creates a backup of files that are NOT part of the passed archive.
public backupArchive ( AppserverIo\Appserver\Core\Api\Node\ContainerNodeInterface $containerNode, SplFileInfo $archive ) : void
$containerNode AppserverIo\Appserver\Core\Api\Node\ContainerNodeInterface The container the archive belongs to
$archive SplFileInfo Backup files that are NOT part of this archive
return void
    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())));
    }