11 use Composer\Autoload\AutoloadGenerator;
12 use Composer\Autoload\ClassMapGenerator;
13 use Composer\EventDispatcher\EventDispatcher;
14 use RecursiveDirectoryIterator;
15 use RecursiveIteratorIterator;
16 use Composer\Composer;
17 use Composer\IO\IOInterface;
18 use Composer\Package\PackageInterface;
19 use Composer\Plugin\PluginInterface;
20 use Composer\Plugin\PluginEvents;
21 use Composer\EventDispatcher\EventSubscriberInterface;
22 use Composer\Script\ScriptEvents;
23 use Composer\Installer\PackageEvents;
24 use Composer\Util\Filesystem;
25 use Symfony\Component\Process\Process;
27 class Plugin implements PluginInterface, EventSubscriberInterface
66 private $regenerate =
'/.regenerate';
71 private $varFolder =
'/var';
78 $sortPriority = isset(
$extra[
'magento-deploy-sort-priority']) ?
$extra[
'magento-deploy-sort-priority'] : array();
79 $this->deployManager->setSortPriority($sortPriority);
88 $this->filesystem =
new Filesystem();
92 $this->installer->setDeployManager($this->deployManager);
93 $this->installer->setConfig($this->config);
94 if ($this->io->isDebug()) {
95 $this->io->write(
'activate magento plugin');
97 $composer->getInstallationManager()->addInstaller($this->installer);
103 PluginEvents::COMMAND => array(
104 array(
'onCommandEvent', 0),
106 ScriptEvents::POST_INSTALL_CMD => array(
107 array(
'onNewCodeEvent', 0),
109 ScriptEvents::POST_UPDATE_CMD => array(
110 array(
'onNewCodeEvent', 0),
112 PackageEvents::POST_PACKAGE_UNINSTALL => array(
113 array(
'onPackageUnistall', 0),
120 $ds = DIRECTORY_SEPARATOR;
121 $package = $event->getOperation()->getPackage();
122 list($vendor, $packageName) = explode(
'/', $package->getPrettyName());
123 $packageName = trim(str_replace(
'module-',
'', $packageName));
124 $packageInstallationPath = $packageInstallationPath = $this->installer->getTargetDir();
125 $packagePath = ucfirst($vendor) . $ds . str_replace(
' ',
'', ucwords(str_replace(
'-',
' ', $packageName)));
126 $this->io->write(
"Removing $packagePath");
127 $libPath =
'lib' . $ds .
'internal' . $ds . $packagePath;
128 $magentoPackagePath =
'app' . $ds .
'code' . $ds . $packagePath;
129 $deployStrategy = $this->installer->getDeployStrategy($package);
130 $deployStrategy->rmdirRecursive($packageInstallationPath . $ds .
$libPath);
131 $deployStrategy->rmdirRecursive($packageInstallationPath . $ds . $magentoPackagePath);
132 $this->requestRegeneration();
142 $command = $event->getCommandName();
152 if ($this->io->isDebug()) {
153 $this->io->write(
'start magento deploy via deployManager');
156 $this->deployManager->doDeploy();
157 $this->deployLibraries();
158 $this->saveVendorDirPath($event->getComposer());
159 $this->requestRegeneration();
160 $this->setFilePermissions();
168 private function setFilePermissions()
170 $packages = $this->composer->getRepositoryManager()->getLocalRepository()->getPackages();
171 $message =
'Check "chmod" section in composer.json of %s package.';
173 foreach ($packages as $package) {
174 $extra = $package->getExtra();
175 if (!isset(
$extra[
'chmod']) || !is_array(
$extra[
'chmod'])) {
180 foreach (
$extra[
'chmod'] as $chmod) {
181 if (!isset($chmod[
'mask']) || !isset($chmod[
'path']) || strpos($chmod[
'path'],
'..') !==
false) {
186 $file = $this->installer->getTargetDir() .
'/' . $chmod[
'path'];
187 if (file_exists($file)) {
188 chmod($file, octdec($chmod[
'mask']));
190 $this->io->writeError([
191 'File doesn\'t exist: ' . $chmod[
'path'],
192 sprintf(
$message, $package->getName())
198 $this->io->writeError([
199 'Incorrect mask or file path.',
200 sprintf(
$message, $package->getName())
206 protected function deployLibraries()
208 $packages = $this->composer->getRepositoryManager()->getLocalRepository()->getPackages();
209 $autoloadDirectories = array();
213 if ($this->io->isDebug()) {
214 $this->io->write(
'jump over deployLibraries as no Magento libraryPath is set');
220 $vendorDir = rtrim($this->composer->getConfig()->get(
'vendor-dir'),
'/');
226 foreach ($packages as $package) {
228 $packageConfig = $this->config->getLibraryConfigByPackagename($package->getName());
229 if ($packageConfig ===
null) {
232 if (!isset($packageConfig[
'autoload'])) {
233 $packageConfig[
'autoload'] = array(
'/');
235 foreach ($packageConfig[
'autoload'] as
$path) {
238 if ($this->io->isDebug()) {
239 $this->io->write(
'Magento deployLibraries executed for ' . $package->getName());
241 $libraryTargetPath =
$libraryPath .
'/' . $package->getName();
243 $filesystem->ensureDirectoryExists($libraryTargetPath);
248 $autoloadGenerator =
new AutoloadGenerator(
new EventDispatcher($this->composer, $this->io));
250 $executable = $this->composer->getConfig()->get(
'bin-dir') .
'/phpab';
251 if (!file_exists($executable)) {
252 $executable = $this->composer->getConfig()->get(
'vendor-dir') .
'/theseer/autoload/composer/bin/phpab';
254 if (file_exists($executable)) {
255 if ($this->io->isDebug()) {
256 $this->io->write(
'Magento deployLibraries executes autoload generator');
258 $process =
new Process($executable .
" -o {$libraryPath}/autoload.php " . implode(
' ', $autoloadDirectories));
261 if ($this->io->isDebug()) {
262 $this->io->write(
'Magento deployLibraries autoload generator not availabel, you should require "theseer/autoload"');
263 var_dump($executable, getcwd());
285 $it =
new RecursiveDirectoryIterator(
$source, RecursiveDirectoryIterator::SKIP_DOTS);
286 $ri =
new RecursiveIteratorIterator($it, RecursiveIteratorIterator::SELF_FIRST);
287 $this->filesystem->ensureDirectoryExists(
$target);
289 foreach ($ri as $file) {
290 $targetPath =
$target . DIRECTORY_SEPARATOR . $ri->getSubPathName();
291 if ($file->isDir()) {
292 $this->filesystem->ensureDirectoryExists($targetPath);
294 copy($file->getPathname(), $targetPath);
306 private function saveVendorDirPath(Composer
$composer)
308 $magentoDir = $this->installer->getTargetDir();
309 $vendorDirPath = $this->filesystem->findShortestPath(
311 realpath(
$composer->getConfig()->get(
'vendor-dir')),
314 $vendorPathFile = $magentoDir .
'/app/etc/vendor_path.php';
320 return '$vendorDirPath';
331 private function requestRegeneration()
333 if (
is_writable($this->installer->getTargetDir() . $this->varFolder)) {
334 $filename = $this->installer->getTargetDir() . $this->varFolder . $this->regenerate;
copyRecursive($source, $target)
if(!file_exists(VENDOR_PATH)) $vendorDir
static getSubscribedEvents()
activate(Composer $composer, IOInterface $io)
onCommandEvent(\Composer\Plugin\CommandEvent $event)
onNewCodeEvent(\Composer\Script\Event $event)
onPackageUnistall(\Composer\Installer\PackageEvent $event)
if(isset($opts->l)) $libraryPath
initDeployManager(Composer $composer, IOInterface $io)
if( $_orders &&count( $_orders))( 'Orders') ?></caption >< thead >< tr >< th scopeforeach( $_orders as $_order)(__( 'Order #')) ?>" class $extra