mirror of
				https://github.com/hauke68/Magallanes.git
				synced 2025-10-30 23:10:16 +01:00 
			
		
		
		
	Merge pull request #149 from gudron/relative_linking
Relative linking @ shared file task.
This commit is contained in:
		
						commit
						27a4da4115
					
				| @ -8,6 +8,16 @@ use Mage\Task\SkipException; | |||||||
| class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware | class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware | ||||||
| { | { | ||||||
| 
 | 
 | ||||||
|  |     const LINKED_FOLDERS   = 'linked_folders'; | ||||||
|  |     const LINKED_STRATEGY  = 'linking_strategy'; | ||||||
|  | 
 | ||||||
|  |     const ABSOLUTE_LINKING = 'absolute'; | ||||||
|  |     const RELATIVE_LINKING = 'relative'; | ||||||
|  | 
 | ||||||
|  |     public $linkingStrategies = array( | ||||||
|  |         self::ABSOLUTE_LINKING, | ||||||
|  |         self::RELATIVE_LINKING | ||||||
|  |     ); | ||||||
|     /** |     /** | ||||||
|      * Returns the Title of the Task |      * Returns the Title of the Task | ||||||
|      * @return string |      * @return string | ||||||
| @ -26,24 +36,37 @@ class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware | |||||||
|     public function run() |     public function run() | ||||||
|     { |     { | ||||||
|         $linkedFiles    = $this->getParameter('linked_files', []); |         $linkedFiles    = $this->getParameter('linked_files', []); | ||||||
|         $linkedFolders = $this->getParameter('linked_folders', []); |         $linkedFolders  = $this->getParameter(self::LINKED_FOLDERS, []); | ||||||
|  |         $linkingStrategy = $this->getParameter(self::LINKED_STRATEGY, self::ABSOLUTE_LINKING); | ||||||
|  | 
 | ||||||
|  |         $linkedEntities = array_merge($linkedFiles,$linkedFolders); | ||||||
|  | 
 | ||||||
|         if (sizeof($linkedFiles) == 0 && sizeof($linkedFolders) == 0) { |         if (sizeof($linkedFiles) == 0 && sizeof($linkedFolders) == 0) { | ||||||
|             throw new SkipException('No files and folders configured for sym-linking.'); |             throw new SkipException('No files and folders configured for sym-linking.'); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         $sharedFolderName = $this->getParameter('shared', 'shared'); |         $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 = $this->getConfig()->release('directory', 'releases'); | ||||||
|         $releasesDirectory = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory; |         $releasesDirectoryPath = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory; | ||||||
| 
 | 
 | ||||||
|         $currentCopy = $releasesDirectory . '/' . $this->getConfig()->getReleaseId(); |         $currentCopy = $releasesDirectoryPath . '/' . $this->getConfig()->getReleaseId(); | ||||||
|         foreach ($linkedFolders as $folder) { |         $relativeDiffPath = str_replace($this->getConfig()->deployment('to'),'',$currentCopy) . '/'; | ||||||
|             $command = "ln -nfs $sharedFolderName/$folder $currentCopy/$folder"; | 
 | ||||||
|             $this->runCommandRemote($command); |         foreach ($linkedEntities as $ePath) { | ||||||
|  |             if(is_array($ePath) && in_array($strategy = reset($ePath), $this->linkingStrategies ) ) { | ||||||
|  |                 $entityPath = key($ePath); | ||||||
|  |             } else { | ||||||
|  |                 $strategy = $linkingStrategy; | ||||||
|  |                 $entityPath = $ePath; | ||||||
|             } |             } | ||||||
| 
 |             $sharedEntityLinkedPath = "$sharedFolderPath/$entityPath"; | ||||||
|         foreach ($linkedFiles as $folder) { |             if($strategy==self::RELATIVE_LINKING) { | ||||||
|             $command = "ln -nfs $sharedFolderName/$folder $currentCopy/$folder"; |                 $parentFolderPath = dirname($entityPath); | ||||||
|  |                 $relativePath = $parentFolderPath=='.'?$relativeDiffPath:$relativeDiffPath.$parentFolderPath.'/'; | ||||||
|  |                 $sharedEntityLinkedPath = ltrim(preg_replace('/(\w+\/)/', '../', $relativePath),'/').$sharedFolderName .'/'. $entityPath; | ||||||
|  |             } | ||||||
|  |             $command = "ln -nfs $sharedEntityLinkedPath $currentCopy/$entityPath"; | ||||||
|             $this->runCommandRemote($command); |             $this->runCommandRemote($command); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user