mirror of
				https://github.com/hauke68/Magallanes.git
				synced 2025-11-04 09:00:18 +01:00 
			
		
		
		
	added relative linking @ Link shared files task
This commit is contained in:
		
							parent
							
								
									861a823f7e
								
							
						
					
					
						commit
						6f551cabf0
					
				@ -8,6 +8,8 @@ use Mage\Task\SkipException;
 | 
			
		||||
class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    const ABSOLUTE_LINKING = 'absolute';
 | 
			
		||||
    const RELATIVE_LINKING = 'relative';
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns the Title of the Task
 | 
			
		||||
     * @return string
 | 
			
		||||
@ -27,23 +29,31 @@ class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware
 | 
			
		||||
    {
 | 
			
		||||
        $linkedFiles    = $this->getParameter('linked_files', []);
 | 
			
		||||
        $linkedFolders  = $this->getParameter('linked_folders', []);
 | 
			
		||||
        $linkingStrategy = $this->getParameter('linking_stategy', self::ABSOLUTE_LINKING);
 | 
			
		||||
 | 
			
		||||
        $linkedEntities = array_merge($linkedFiles,$linkedFolders);
 | 
			
		||||
 | 
			
		||||
        if (sizeof($linkedFiles) == 0 && sizeof($linkedFolders) == 0) {
 | 
			
		||||
            throw new SkipException('No files and folders configured for sym-linking.');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $sharedFolderName = $this->getParameter('shared', 'shared');
 | 
			
		||||
        $sharedFolderName = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $sharedFolderName;
 | 
			
		||||
        $sharedFolderPath = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $sharedFolderName;
 | 
			
		||||
        $releasesDirectory = $this->getConfig()->release('directory', 'releases');
 | 
			
		||||
        $releasesDirectory = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory;
 | 
			
		||||
        $releasesDirectoryPath = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory;
 | 
			
		||||
 | 
			
		||||
        $currentCopy = $releasesDirectory . '/' . $this->getConfig()->getReleaseId();
 | 
			
		||||
        foreach ($linkedFolders as $folder) {
 | 
			
		||||
            $command = "ln -nfs $sharedFolderName/$folder $currentCopy/$folder";
 | 
			
		||||
            $this->runCommandRemote($command);
 | 
			
		||||
        $currentCopy = $releasesDirectoryPath . '/' . $this->getConfig()->getReleaseId();
 | 
			
		||||
        if($linkingStrategy==self::RELATIVE_LINKING)
 | 
			
		||||
            $relativeDiffPath = str_replace($this->getConfig()->deployment('to'),'',$currentCopy) . '/';
 | 
			
		||||
 | 
			
		||||
        foreach ($linkedEntities as $entityPath) {
 | 
			
		||||
            $sharedEntityLinkedPath = "$sharedFolderPath/$entityPath";
 | 
			
		||||
            if($linkingStrategy==self::RELATIVE_LINKING) {
 | 
			
		||||
                $parentFolderPath = dirname($entityPath);
 | 
			
		||||
                $relativePath = empty($parentFolderPath)?$relativeDiffPath:$relativeDiffPath.$parentFolderPath.'/';
 | 
			
		||||
                $sharedEntityLinkedPath = ltrim(preg_replace('/(\w+\/)/', '../', $relativePath),'/').$sharedFolderName .'/'. $entityPath;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        foreach ($linkedFiles as $folder) {
 | 
			
		||||
            $command = "ln -nfs $sharedFolderName/$folder $currentCopy/$folder";
 | 
			
		||||
            $command = "ln -nfs $sharedEntityLinkedPath $currentCopy/$entityPath";
 | 
			
		||||
            $this->runCommandRemote($command);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user