-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #177 from ProxiBlue/3.1.2-dev
New Deploy Strategy - Move
- Loading branch information
Showing
7 changed files
with
120 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/MagentoHackathon/Composer/Magento/Deploystrategy/Move.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters