Skip to content

Commit e3453d2

Browse files
committed
Merge pull request #1 from bibumathew/master
Added Listener logic to package unintsall
2 parents 8460b5b + 26e419d commit e3453d2

File tree

2 files changed

+20
-27
lines changed

2 files changed

+20
-27
lines changed

src/MagentoHackathon/Composer/Magento/Installer.php

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Installer extends LibraryInstaller implements InstallerInterface
3333
*
3434
* @var \SplFileInfo
3535
*/
36-
protected $defaultMagentoRootDir = 'root';
36+
protected $defaultMagentoRootDir = './';
3737

3838
/**
3939
* The base directory of the modman packages
@@ -124,19 +124,14 @@ public function __construct(IOInterface $io, Composer $composer, $type = 'magent
124124

125125
$extra = $composer->getPackage()->getExtra();
126126

127-
if (isset($extra['magento-root-dir']) || (($rootDirInput = $io->ask('please define your magento root dir [' . $this->defaultMagentoRootDir . '] ', $this->defaultMagentoRootDir)) || $rootDirInput = $this->defaultMagentoRootDir)) {
127+
if (isset($extra['magento-root-dir']) || $rootDirInput = $this->defaultMagentoRootDir) {
128128

129129
if (isset($rootDirInput)) {
130130
$extra['magento-root-dir'] = $rootDirInput;
131-
$this->updateJsonExtra($extra, $io);
132131
}
133132

134133
$dir = rtrim(trim($extra['magento-root-dir']), '/\\');
135134
$this->magentoRootDir = new \SplFileInfo($dir);
136-
if (!is_dir($dir) && $io->askConfirmation('magento root dir "' . $dir . '" missing! create now? [Y,n] ')) {
137-
$this->initializeMagentoRootDir($dir);
138-
$io->write('magento root dir "' . $dir . '" created');
139-
}
140135

141136
if (!is_dir($dir)) {
142137
$dir = $this->vendorDir . "/$dir";
@@ -213,26 +208,6 @@ public function getDeployManager()
213208
{
214209
return $this->deployManager;
215210
}
216-
217-
/**
218-
* Create base requrements for project installation
219-
*/
220-
protected function initializeMagentoRootDir() {
221-
if (!$this->magentoRootDir->isDir()) {
222-
$magentoRootPath = $this->magentoRootDir->getPathname();
223-
$pathParts = explode(DIRECTORY_SEPARATOR, $magentoRootPath);
224-
$baseDir = explode(DIRECTORY_SEPARATOR, $this->vendorDir);
225-
array_pop($baseDir);
226-
$pathParts = array_merge($baseDir, $pathParts);
227-
$directoryPath = '';
228-
foreach ($pathParts as $pathPart) {
229-
$directoryPath .= $pathPart . DIRECTORY_SEPARATOR;
230-
$this->filesystem->ensureDirectoryExists($directoryPath);
231-
}
232-
}
233-
234-
// $this->getSourceDir($package);
235-
}
236211

237212

238213
/**

src/MagentoHackathon/Composer/Magento/Plugin.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,27 @@ public static function getSubscribedEvents()
9898
ScriptEvents::POST_UPDATE_CMD => array(
9999
array('onNewCodeEvent', 0),
100100
),
101+
ScriptEvents::POST_PACKAGE_UNINSTALL => array(
102+
array('onPackageUnistall', 0),
103+
)
101104
);
102105
}
103106

107+
public function onPackageUnistall( \Composer\Script\PackageEvent $event )
108+
{
109+
$ds = DIRECTORY_SEPARATOR;
110+
$package = $event->getOperation()->getPackage();
111+
list($vendor, $packageName) = explode('/', $package->getPrettyName());
112+
$packageName = trim(str_replace('module-','',$packageName));
113+
$packageInstallationPath = $packageInstallationPath = $this->installer->getTargetDir();
114+
$packagePath = ucfirst($vendor).$ds.str_replace(' ', '', ucwords(str_replace('-', ' ', $packageName)));
115+
$this->io->write("Removing $packagePath");
116+
$libPath = 'lib'.$ds.'internal'.$ds.$packagePath;
117+
$magentoPackagePath = 'app'.$ds.'code'.$ds.$packagePath;
118+
$deployStrategy = $this->installer->getDeployStrategy($package);
119+
$deployStrategy->rmdirRecursive($packageInstallationPath.$ds.$libPath);
120+
$deployStrategy->rmdirRecursive($packageInstallationPath.$ds.$magentoPackagePath);
121+
}
104122

105123
/**
106124
* actually is triggered before anything got executed

0 commit comments

Comments
 (0)