Skip to content

Commit

Permalink
Merge pull request #177 from ProxiBlue/3.1.2-dev
Browse files Browse the repository at this point in the history
New Deploy Strategy - Move
  • Loading branch information
Flyingmana authored Dec 5, 2018
2 parents 5921fb1 + bf30d6d commit fad9b31
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 8 deletions.
4 changes: 2 additions & 2 deletions doc/ConfigurationParameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Here a overview of all available parameters.

## Deploy

- magento-deploystrategy : `"copy|symlink|absoluteSymlink|link|none"` [Deploy strategy](Deploy.md)
- magento-deploystrategy-overwrite : `{"vendor/package": "copy|symlink|absoluteSymlink|link|none", ...}` [Deploy overwrite](Deploy.md#overwrite-deploy-method-per-module)
- magento-deploystrategy : `"copy|symlink|absoluteSymlink|link|none|move"` [Deploy strategy](Deploy.md)
- magento-deploystrategy-overwrite : `{"vendor/package": "copy|symlink|absoluteSymlink|link|none|move", ...}` [Deploy overwrite](Deploy.md#overwrite-deploy-method-per-module)
- magento-deploy-sort-priority : `{"vendor/package": 200, ...}` (Deploy sort priority)[Deploy.md#define-order-in-which-you-want-your-magento-packages-deployed]
- magento-deploy-ignore : `{"vendor/package": ["file/to/exclude.php"], ...}` [Deploy ignore files](Deploy.md#prevent-single-files-from-deploy)
- magento-force : `true|false` [Deploy force overwrite](Deploy.md#define-order-in-which-you-want-your-magento-packages-deployed)
Expand Down
28 changes: 28 additions & 0 deletions doc/Deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,34 @@ Here is how to use it:
}
```


### Deploy per Move instead of Copy

There is a deploy per move strategy. This can only be configured in the root composer.json, it can't be configured on a per-package level.
Here is how to use it:

```json
{
"extra":{
"magento-root-dir": "htdocs/",
"magento-deploystrategy": "move"
}
}
```

Instead of copy, files are moved.
The source folder, located in vendor folder, will be removed.

The goal with this option is to limit unwanted file copy procedures during deployment to a server.
Since all the file exist inside Magento root, having to copy the same files in vendor to the server is pointless,
and doubles deployment time.

This only affects Magento module. Vendor specific code, which are not placed in Magento structure, is left in place.
Usually, this option is used in conjunction with DevMode, allowing developers to retain the copy of files in
vendor.

** this is a new feature, and still requires feedback **

### overwrite deploy method per module

Caution: this feature is new, so doku may be wrong, not uptodate or we have a bug somewhere.
Expand Down
3 changes: 2 additions & 1 deletion src/MagentoHackathon/Composer/Magento/DeployManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Composer\IO\IOInterface;
use MagentoHackathon\Composer\Magento\Deploy\Manager\Entry;
use MagentoHackathon\Composer\Magento\Deploystrategy\Copy;
use MagentoHackathon\Composer\Magento\Deploystrategy\Move;
use MagentoHackathon\Composer\Magento\Event\EventManager;
use MagentoHackathon\Composer\Magento\Event\PackageDeployEvent;

Expand Down Expand Up @@ -77,7 +78,7 @@ protected function sortPackages()
$result = 100;
if (isset($sortPriority[$object->getPackageName()])) {
$result = $sortPriority[$object->getPackageName()];
} elseif ($object->getDeployStrategy() instanceof Copy) {
} elseif ($object->getDeployStrategy() instanceof Copy || $object->getDeployStrategy() instanceof Move) {
$result = 101;
}
return $result;
Expand Down
19 changes: 16 additions & 3 deletions src/MagentoHackathon/Composer/Magento/Deploystrategy/Copy.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace MagentoHackathon\Composer\Magento\Deploystrategy;

/**
* Symlink deploy strategy
* Copy deploy strategy
*/
class Copy extends DeploystrategyAbstract
{
Expand Down Expand Up @@ -86,7 +86,7 @@ public function createDelegate($source, $dest)
}
$destPath = str_replace('\\', '/', $destPath);
$this->addDeployedFile($destPath);
return copy($sourcePath, $destPath);
return $this->transfer($sourcePath, $destPath);
}

// Copy dir to dir
Expand All @@ -109,7 +109,7 @@ public function createDelegate($source, $dest)
}
} else {
$subDestPath = str_replace('\\', '/', $subDestPath);
copy($item, $subDestPath);
$this->transfer($item, $subDestPath);
$this->addDeployedFile($subDestPath);
}
if (!is_readable($subDestPath)) {
Expand All @@ -119,4 +119,17 @@ public function createDelegate($source, $dest)

return true;
}

/**
* transfer by copy files
*
* @param string $item
* @param string $subDestPath
* @return bool
*/

protected function transfer($item, $subDestPath)
{
return copy($item, $subDestPath);
}
}
70 changes: 70 additions & 0 deletions src/MagentoHackathon/Composer/Magento/Deploystrategy/Move.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/**
* Composer Magento Installer
*/

namespace MagentoHackathon\Composer\Magento\Deploystrategy;

/**
* Move deploy strategy
* Ref: https://github.com/Cotya/magento-composer-installer/issues/176
*/
class Move extends Copy
{
/**
* transfer by moving files
*
* @param string $item
* @param string $subDestPath
* @return bool
*/
protected function transfer($item, $subDestPath)
{
return rename($item, $subDestPath);
}

/**
* afterDeploy
*
* @return void
*/
protected function afterDeploy()
{
if(is_dir($this->sourceDir)) {
$this->removeDir($this->sourceDir);
}
}

/**
* Recursively remove files and folders from given path
*
* @param $path
* @return void
* @throws \Exception
*/
private function removeDir($path)
{
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS),
\RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($iterator as $fileInfo) {
$filename = $fileInfo->getFilename();
if($filename != '..' || $filename != '.') {
$removeAction = ($fileInfo->isDir() ? 'rmdir' : 'unlink');
try {
$removeAction($fileInfo->getRealPath());
} catch (\Exception $e) {
if (strpos($e->getMessage(), 'Directory not empty')) {
$this->removeDir($fileInfo->getRealPath());
} else {
throw new Exception(sprintf('%s could not be removed.', $fileInfo->getRealPath()));
}

}
}
}
rmdir($path);
}

}
3 changes: 2 additions & 1 deletion src/MagentoHackathon/Composer/Magento/ProjectConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ public function getModuleSpecificSortValue($packagename)
$sortValue = $sortPriorityArray[$packagename];
} else {
$sortValue = 100;
if ($this->getModuleSpecificDeployStrategy($packagename) === 'copy') {
if ($this->getModuleSpecificDeployStrategy($packagename) === 'copy'
|| $this->getModuleSpecificDeployStrategy($packagename) === 'move') {
$sortValue++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ public function has($packageName, $version = null)

return $package->getVersion() === $version;
} catch (\Exception $e) {
// @todo add logging
return false;
}
}
Expand Down

0 comments on commit fad9b31

Please sign in to comment.