Skip to content

Commit fad9b31

Browse files
authored
Merge pull request #177 from ProxiBlue/3.1.2-dev
New Deploy Strategy - Move
2 parents 5921fb1 + bf30d6d commit fad9b31

File tree

7 files changed

+120
-8
lines changed

7 files changed

+120
-8
lines changed

doc/ConfigurationParameters.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Here a overview of all available parameters.
1313

1414
## Deploy
1515

16-
- magento-deploystrategy : `"copy|symlink|absoluteSymlink|link|none"` [Deploy strategy](Deploy.md)
17-
- magento-deploystrategy-overwrite : `{"vendor/package": "copy|symlink|absoluteSymlink|link|none", ...}` [Deploy overwrite](Deploy.md#overwrite-deploy-method-per-module)
16+
- magento-deploystrategy : `"copy|symlink|absoluteSymlink|link|none|move"` [Deploy strategy](Deploy.md)
17+
- magento-deploystrategy-overwrite : `{"vendor/package": "copy|symlink|absoluteSymlink|link|none|move", ...}` [Deploy overwrite](Deploy.md#overwrite-deploy-method-per-module)
1818
- magento-deploy-sort-priority : `{"vendor/package": 200, ...}` (Deploy sort priority)[Deploy.md#define-order-in-which-you-want-your-magento-packages-deployed]
1919
- magento-deploy-ignore : `{"vendor/package": ["file/to/exclude.php"], ...}` [Deploy ignore files](Deploy.md#prevent-single-files-from-deploy)
2020
- magento-force : `true|false` [Deploy force overwrite](Deploy.md#define-order-in-which-you-want-your-magento-packages-deployed)

doc/Deploy.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,34 @@ Here is how to use it:
1313
}
1414
```
1515

16+
17+
### Deploy per Move instead of Copy
18+
19+
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.
20+
Here is how to use it:
21+
22+
```json
23+
{
24+
"extra":{
25+
"magento-root-dir": "htdocs/",
26+
"magento-deploystrategy": "move"
27+
}
28+
}
29+
```
30+
31+
Instead of copy, files are moved.
32+
The source folder, located in vendor folder, will be removed.
33+
34+
The goal with this option is to limit unwanted file copy procedures during deployment to a server.
35+
Since all the file exist inside Magento root, having to copy the same files in vendor to the server is pointless,
36+
and doubles deployment time.
37+
38+
This only affects Magento module. Vendor specific code, which are not placed in Magento structure, is left in place.
39+
Usually, this option is used in conjunction with DevMode, allowing developers to retain the copy of files in
40+
vendor.
41+
42+
** this is a new feature, and still requires feedback **
43+
1644
### overwrite deploy method per module
1745

1846
Caution: this feature is new, so doku may be wrong, not uptodate or we have a bug somewhere.

src/MagentoHackathon/Composer/Magento/DeployManager.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Composer\IO\IOInterface;
1212
use MagentoHackathon\Composer\Magento\Deploy\Manager\Entry;
1313
use MagentoHackathon\Composer\Magento\Deploystrategy\Copy;
14+
use MagentoHackathon\Composer\Magento\Deploystrategy\Move;
1415
use MagentoHackathon\Composer\Magento\Event\EventManager;
1516
use MagentoHackathon\Composer\Magento\Event\PackageDeployEvent;
1617

@@ -77,7 +78,7 @@ protected function sortPackages()
7778
$result = 100;
7879
if (isset($sortPriority[$object->getPackageName()])) {
7980
$result = $sortPriority[$object->getPackageName()];
80-
} elseif ($object->getDeployStrategy() instanceof Copy) {
81+
} elseif ($object->getDeployStrategy() instanceof Copy || $object->getDeployStrategy() instanceof Move) {
8182
$result = 101;
8283
}
8384
return $result;

src/MagentoHackathon/Composer/Magento/Deploystrategy/Copy.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace MagentoHackathon\Composer\Magento\Deploystrategy;
77

88
/**
9-
* Symlink deploy strategy
9+
* Copy deploy strategy
1010
*/
1111
class Copy extends DeploystrategyAbstract
1212
{
@@ -86,7 +86,7 @@ public function createDelegate($source, $dest)
8686
}
8787
$destPath = str_replace('\\', '/', $destPath);
8888
$this->addDeployedFile($destPath);
89-
return copy($sourcePath, $destPath);
89+
return $this->transfer($sourcePath, $destPath);
9090
}
9191

9292
// Copy dir to dir
@@ -109,7 +109,7 @@ public function createDelegate($source, $dest)
109109
}
110110
} else {
111111
$subDestPath = str_replace('\\', '/', $subDestPath);
112-
copy($item, $subDestPath);
112+
$this->transfer($item, $subDestPath);
113113
$this->addDeployedFile($subDestPath);
114114
}
115115
if (!is_readable($subDestPath)) {
@@ -119,4 +119,17 @@ public function createDelegate($source, $dest)
119119

120120
return true;
121121
}
122+
123+
/**
124+
* transfer by copy files
125+
*
126+
* @param string $item
127+
* @param string $subDestPath
128+
* @return bool
129+
*/
130+
131+
protected function transfer($item, $subDestPath)
132+
{
133+
return copy($item, $subDestPath);
134+
}
122135
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
/**
3+
* Composer Magento Installer
4+
*/
5+
6+
namespace MagentoHackathon\Composer\Magento\Deploystrategy;
7+
8+
/**
9+
* Move deploy strategy
10+
* Ref: https://github.com/Cotya/magento-composer-installer/issues/176
11+
*/
12+
class Move extends Copy
13+
{
14+
/**
15+
* transfer by moving files
16+
*
17+
* @param string $item
18+
* @param string $subDestPath
19+
* @return bool
20+
*/
21+
protected function transfer($item, $subDestPath)
22+
{
23+
return rename($item, $subDestPath);
24+
}
25+
26+
/**
27+
* afterDeploy
28+
*
29+
* @return void
30+
*/
31+
protected function afterDeploy()
32+
{
33+
if(is_dir($this->sourceDir)) {
34+
$this->removeDir($this->sourceDir);
35+
}
36+
}
37+
38+
/**
39+
* Recursively remove files and folders from given path
40+
*
41+
* @param $path
42+
* @return void
43+
* @throws \Exception
44+
*/
45+
private function removeDir($path)
46+
{
47+
$iterator = new \RecursiveIteratorIterator(
48+
new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS),
49+
\RecursiveIteratorIterator::CHILD_FIRST
50+
);
51+
foreach ($iterator as $fileInfo) {
52+
$filename = $fileInfo->getFilename();
53+
if($filename != '..' || $filename != '.') {
54+
$removeAction = ($fileInfo->isDir() ? 'rmdir' : 'unlink');
55+
try {
56+
$removeAction($fileInfo->getRealPath());
57+
} catch (\Exception $e) {
58+
if (strpos($e->getMessage(), 'Directory not empty')) {
59+
$this->removeDir($fileInfo->getRealPath());
60+
} else {
61+
throw new Exception(sprintf('%s could not be removed.', $fileInfo->getRealPath()));
62+
}
63+
64+
}
65+
}
66+
}
67+
rmdir($path);
68+
}
69+
70+
}

src/MagentoHackathon/Composer/Magento/ProjectConfig.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ public function getModuleSpecificSortValue($packagename)
238238
$sortValue = $sortPriorityArray[$packagename];
239239
} else {
240240
$sortValue = 100;
241-
if ($this->getModuleSpecificDeployStrategy($packagename) === 'copy') {
241+
if ($this->getModuleSpecificDeployStrategy($packagename) === 'copy'
242+
|| $this->getModuleSpecificDeployStrategy($packagename) === 'move') {
242243
$sortValue++;
243244
}
244245
}

src/MagentoHackathon/Composer/Magento/Repository/InstalledPackageFileSystemRepository.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ public function has($packageName, $version = null)
109109

110110
return $package->getVersion() === $version;
111111
} catch (\Exception $e) {
112-
// @todo add logging
113112
return false;
114113
}
115114
}

0 commit comments

Comments
 (0)