Skip to content

Commit

Permalink
Merge pull request #14 from magento-falcons/MAGETWO-59264
Browse files Browse the repository at this point in the history
[Falcons] Bug fixes for Composer, Cache, Catalog
  • Loading branch information
Yaroslav Onischenko authored Oct 6, 2016
2 parents a12b957 + b903315 commit 10c600e
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 1 deletion.
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ In the component's `composer.json`, specify:

* `type`, type of Magento 2 component.
* `extra/map`, list of files to move and their paths relative to the Magento root directory.
* `extra/chmod`, list of permissions that should be set for files.

**Note**:
* `extra/map` is required only if your component needs to be moved to a location other than `<Magento root>/vendor`. Otherwise, omit this section.
* `extra/chmod` is required only if you need to set specific permissions for files.

**Note**: `extra/map` is required only if your component needs to be moved to a location other than `<Magento root>/vendor`. Otherwise, omit this section.

## Supported Components
The following list explains the use of `type` in `composer.json`.
Expand Down Expand Up @@ -165,5 +169,38 @@ The Magneto Composer Installer uses the `copy` deployment strategy. It copies ea

There are [other deployment strategies](https://github.com/magento/magento-composer-installer/blob/master/doc/Deploy.md) that could be used; however, we don't guarantee that any of them will work.

## Usage `extra/chmod`

The following example shows how you can set specific permissions for files.

Example:

```json
{
"name": "magento/module-sample",
"description": "N/A",
"require": {
...
},
"type": "magento2-module",
"extra": {
"chmod": [
{
"mask": "0755",
"path": "bin/magento"
},
{
"mask": "0644",
"path": "some_dir/file.jpg"
}
]
}
}
```

`mask` is a bit mask for chmod command

`path` is a path to file relative to the Magento root folder

# Notes
- The extra->magento-root-dir option is no longer supported. It displays only to preseve backward compatibility.
43 changes: 43 additions & 0 deletions src/MagentoHackathon/Composer/Magento/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,51 @@ public function onNewCodeEvent(\Composer\Script\Event $event)
$this->deployLibraries();
$this->saveVendorDirPath($event->getComposer());
$this->requestRegeneration();
$this->setFilePermissions();
}

/**
* Set permissions for files using extra->chmod from composer.json
*
* @return void
*/
private function setFilePermissions()
{
$packages = $this->composer->getRepositoryManager()->getLocalRepository()->getPackages();
$message = 'Check "chmod" section in composer.json of %s package.';

foreach ($packages as $package) {
$extra = $package->getExtra();
if (!isset($extra['chmod']) || !is_array($extra['chmod'])) {
continue;
}

$error = false;
foreach ($extra['chmod'] as $chmod) {
if (!isset($chmod['mask']) || !isset($chmod['path']) || strpos($chmod['path'], '..') !== false) {
$error = true;
continue;
}

$file = $this->installer->getTargetDir() . '/' . $chmod['path'];
if (file_exists($file)) {
chmod($file, octdec($chmod['mask']));
} else {
$this->io->writeError([
'File doesn\'t exist: ' . $chmod['path'],
sprintf($message, $package->getName())
]);
}
}

if ($error) {
$this->io->writeError([
'Incorrect mask or file path.',
sprintf($message, $package->getName())
]);
}
}
}

protected function deployLibraries()
{
Expand Down

0 comments on commit 10c600e

Please sign in to comment.