mirror of
https://github.com/hauke68/Magallanes.git
synced 2025-10-14 17:20:18 +02:00
PSR-2 style.
This commit is contained in:
parent
5c4a2ad0be
commit
642773b5af
@ -5,21 +5,44 @@ use Mage\Task\AbstractTask;
|
|||||||
use Mage\Task\Releases\IsReleaseAware;
|
use Mage\Task\Releases\IsReleaseAware;
|
||||||
use Mage\Task\SkipException;
|
use Mage\Task\SkipException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class LinkSharedFilesTask
|
||||||
|
*
|
||||||
|
* @package Mage\Task\BuiltIn\Filesystem
|
||||||
|
* @author Andrey Kolchenko <a.j.kolchenko@baltsoftservice.ru>
|
||||||
|
*/
|
||||||
class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware
|
class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware
|
||||||
{
|
{
|
||||||
|
|
||||||
const LINKED_FOLDERS = 'linked_folders';
|
/**
|
||||||
const LINKED_STRATEGY = 'linking_strategy';
|
* Linked folders parameter name
|
||||||
|
*/
|
||||||
|
const LINKED_FOLDERS = 'linked_folders';
|
||||||
|
/**
|
||||||
|
* Linking strategy parameter name
|
||||||
|
*/
|
||||||
|
const LINKED_STRATEGY = 'linking_strategy';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Absolute linked strategy
|
||||||
|
*/
|
||||||
const ABSOLUTE_LINKING = 'absolute';
|
const ABSOLUTE_LINKING = 'absolute';
|
||||||
|
/**
|
||||||
|
* Relative linked strategy
|
||||||
|
*/
|
||||||
const RELATIVE_LINKING = 'relative';
|
const RELATIVE_LINKING = 'relative';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
public $linkingStrategies = array(
|
public $linkingStrategies = array(
|
||||||
self::ABSOLUTE_LINKING,
|
self::ABSOLUTE_LINKING,
|
||||||
self::RELATIVE_LINKING
|
self::RELATIVE_LINKING
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Title of the Task
|
* Returns the Title of the Task
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getName()
|
public function getName()
|
||||||
@ -35,11 +58,11 @@ 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(self::LINKED_FOLDERS, []);
|
$linkedFolders = $this->getParameter(self::LINKED_FOLDERS, []);
|
||||||
$linkingStrategy = $this->getParameter(self::LINKED_STRATEGY, self::ABSOLUTE_LINKING);
|
$linkingStrategy = $this->getParameter(self::LINKED_STRATEGY, self::ABSOLUTE_LINKING);
|
||||||
|
|
||||||
$linkedEntities = array_merge($linkedFiles,$linkedFolders);
|
$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.');
|
||||||
@ -51,20 +74,23 @@ class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware
|
|||||||
$releasesDirectoryPath = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory;
|
$releasesDirectoryPath = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory;
|
||||||
|
|
||||||
$currentCopy = $releasesDirectoryPath . '/' . $this->getConfig()->getReleaseId();
|
$currentCopy = $releasesDirectoryPath . '/' . $this->getConfig()->getReleaseId();
|
||||||
$relativeDiffPath = str_replace($this->getConfig()->deployment('to'),'',$currentCopy) . '/';
|
$relativeDiffPath = str_replace($this->getConfig()->deployment('to'), '', $currentCopy) . '/';
|
||||||
|
|
||||||
foreach ($linkedEntities as $ePath) {
|
foreach ($linkedEntities as $ePath) {
|
||||||
if(is_array($ePath) && in_array($strategy = reset($ePath), $this->linkingStrategies ) ) {
|
if (is_array($ePath) && in_array($strategy = reset($ePath), $this->linkingStrategies)) {
|
||||||
$entityPath = key($ePath);
|
$entityPath = key($ePath);
|
||||||
} else {
|
} else {
|
||||||
$strategy = $linkingStrategy;
|
$strategy = $linkingStrategy;
|
||||||
$entityPath = $ePath;
|
$entityPath = $ePath;
|
||||||
}
|
}
|
||||||
$sharedEntityLinkedPath = "$sharedFolderPath/$entityPath";
|
$sharedEntityLinkedPath = "$sharedFolderPath/$entityPath";
|
||||||
if($strategy==self::RELATIVE_LINKING) {
|
if ($strategy == self::RELATIVE_LINKING) {
|
||||||
$parentFolderPath = dirname($entityPath);
|
$parentFolderPath = dirname($entityPath);
|
||||||
$relativePath = $parentFolderPath=='.'?$relativeDiffPath:$relativeDiffPath.$parentFolderPath.'/';
|
$relativePath = $parentFolderPath == '.' ? $relativeDiffPath : $relativeDiffPath . $parentFolderPath . '/';
|
||||||
$sharedEntityLinkedPath = ltrim(preg_replace('/(\w+\/)/', '../', $relativePath),'/').$sharedFolderName .'/'. $entityPath;
|
$sharedEntityLinkedPath = ltrim(
|
||||||
|
preg_replace('/(\w+\/)/', '../', $relativePath),
|
||||||
|
'/'
|
||||||
|
) . $sharedFolderName . '/' . $entityPath;
|
||||||
}
|
}
|
||||||
$command = "ln -nfs $sharedEntityLinkedPath $currentCopy/$entityPath";
|
$command = "ln -nfs $sharedEntityLinkedPath $currentCopy/$entityPath";
|
||||||
$this->runCommandRemote($command);
|
$this->runCommandRemote($command);
|
||||||
|
Loading…
Reference in New Issue
Block a user