From 6f551cabf00e73bd1b6efc91e2ff1357a807715c Mon Sep 17 00:00:00 2001 From: Alex V Kotelnikov Date: Sun, 28 Sep 2014 00:42:15 +0400 Subject: [PATCH 1/3] added relative linking @ Link shared files task --- .../Filesystem/LinkSharedFilesTask.php | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php index 86dc645..105513c 100644 --- a/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php +++ b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php @@ -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 @@ -25,28 +27,36 @@ class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware */ public function run() { - $linkedFiles = $this->getParameter('linked_files', []); - $linkedFolders = $this->getParameter('linked_folders', []); + $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; - - $currentCopy = $releasesDirectory . '/' . $this->getConfig()->getReleaseId(); - foreach ($linkedFolders as $folder) { - $command = "ln -nfs $sharedFolderName/$folder $currentCopy/$folder"; - $this->runCommandRemote($command); - } - - foreach ($linkedFiles as $folder) { - $command = "ln -nfs $sharedFolderName/$folder $currentCopy/$folder"; + $releasesDirectoryPath = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory; + + $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; + } + $command = "ln -nfs $sharedEntityLinkedPath $currentCopy/$entityPath"; $this->runCommandRemote($command); } return true; } -} +} \ No newline at end of file From 0a1457312660bb590bce8b2b874ee44190e223fd Mon Sep 17 00:00:00 2001 From: Alex V Kotelnikov Date: Sun, 28 Sep 2014 16:59:09 +0400 Subject: [PATCH 2/3] relative linking @ Link shared files task. Added exclusion rules to symlinks creation. --- .../Filesystem/LinkSharedFilesTask.php | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php index 105513c..6ceaa16 100644 --- a/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php +++ b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php @@ -8,8 +8,16 @@ use Mage\Task\SkipException; class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware { + const LINKED_FOLDERS = 'linked_folders'; + const LINKED_STRATEGY = 'linking_stategy'; + const ABSOLUTE_LINKING = 'absolute'; const RELATIVE_LINKING = 'relative'; + + public $linkingStrategies = array( + self::ABSOLUTE_LINKING, + self::RELATIVE_LINKING + ); /** * Returns the Title of the Task * @return string @@ -28,8 +36,8 @@ class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware public function run() { $linkedFiles = $this->getParameter('linked_files', []); - $linkedFolders = $this->getParameter('linked_folders', []); - $linkingStrategy = $this->getParameter('linking_stategy', self::ABSOLUTE_LINKING); + $linkedFolders = $this->getParameter(self::LINKED_FOLDERS, []); + $linkingStrategy = $this->getParameter(self::LINKED_STRATEGY, self::ABSOLUTE_LINKING); $linkedEntities = array_merge($linkedFiles,$linkedFolders); @@ -43,14 +51,19 @@ class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware $releasesDirectoryPath = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory; $currentCopy = $releasesDirectoryPath . '/' . $this->getConfig()->getReleaseId(); - if($linkingStrategy==self::RELATIVE_LINKING) - $relativeDiffPath = str_replace($this->getConfig()->deployment('to'),'',$currentCopy) . '/'; + $relativeDiffPath = str_replace($this->getConfig()->deployment('to'),'',$currentCopy) . '/'; - foreach ($linkedEntities as $entityPath) { + 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"; - if($linkingStrategy==self::RELATIVE_LINKING) { + if($strategy==self::RELATIVE_LINKING) { $parentFolderPath = dirname($entityPath); - $relativePath = empty($parentFolderPath)?$relativeDiffPath:$relativeDiffPath.$parentFolderPath.'/'; + $relativePath = $parentFolderPath=='.'?$relativeDiffPath:$relativeDiffPath.$parentFolderPath.'/'; $sharedEntityLinkedPath = ltrim(preg_replace('/(\w+\/)/', '../', $relativePath),'/').$sharedFolderName .'/'. $entityPath; } $command = "ln -nfs $sharedEntityLinkedPath $currentCopy/$entityPath"; From 50e2d6eeb582ff4f6c8fdf863652cfc7cc0c40fc Mon Sep 17 00:00:00 2001 From: Alex V Kotelnikov Date: Mon, 29 Sep 2014 13:02:20 +0400 Subject: [PATCH 3/3] small fixes @ link shared files task. wrong constant value --- Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php index 6ceaa16..4ed89a1 100644 --- a/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php +++ b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php @@ -9,7 +9,7 @@ class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware { const LINKED_FOLDERS = 'linked_folders'; - const LINKED_STRATEGY = 'linking_stategy'; + const LINKED_STRATEGY = 'linking_strategy'; const ABSOLUTE_LINKING = 'absolute'; const RELATIVE_LINKING = 'relative';