Skip to content

Commit 10c600e

Browse files
author
Yaroslav Onischenko
authored
Merge pull request #14 from magento-falcons/MAGETWO-59264
[Falcons] Bug fixes for Composer, Cache, Catalog
2 parents a12b957 + b903315 commit 10c600e

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

README.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ In the component's `composer.json`, specify:
88

99
* `type`, type of Magento 2 component.
1010
* `extra/map`, list of files to move and their paths relative to the Magento root directory.
11+
* `extra/chmod`, list of permissions that should be set for files.
12+
13+
**Note**:
14+
* `extra/map` is required only if your component needs to be moved to a location other than `<Magento root>/vendor`. Otherwise, omit this section.
15+
* `extra/chmod` is required only if you need to set specific permissions for files.
1116

12-
**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.
1317

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

166170
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.
167171

172+
## Usage `extra/chmod`
173+
174+
The following example shows how you can set specific permissions for files.
175+
176+
Example:
177+
178+
```json
179+
{
180+
"name": "magento/module-sample",
181+
"description": "N/A",
182+
"require": {
183+
...
184+
},
185+
"type": "magento2-module",
186+
"extra": {
187+
"chmod": [
188+
{
189+
"mask": "0755",
190+
"path": "bin/magento"
191+
},
192+
{
193+
"mask": "0644",
194+
"path": "some_dir/file.jpg"
195+
}
196+
]
197+
}
198+
}
199+
```
200+
201+
`mask` is a bit mask for chmod command
202+
203+
`path` is a path to file relative to the Magento root folder
204+
168205
# Notes
169206
- The extra->magento-root-dir option is no longer supported. It displays only to preseve backward compatibility.

src/MagentoHackathon/Composer/Magento/Plugin.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,51 @@ public function onNewCodeEvent(\Composer\Script\Event $event)
157157
$this->deployLibraries();
158158
$this->saveVendorDirPath($event->getComposer());
159159
$this->requestRegeneration();
160+
$this->setFilePermissions();
160161
}
161162

163+
/**
164+
* Set permissions for files using extra->chmod from composer.json
165+
*
166+
* @return void
167+
*/
168+
private function setFilePermissions()
169+
{
170+
$packages = $this->composer->getRepositoryManager()->getLocalRepository()->getPackages();
171+
$message = 'Check "chmod" section in composer.json of %s package.';
172+
173+
foreach ($packages as $package) {
174+
$extra = $package->getExtra();
175+
if (!isset($extra['chmod']) || !is_array($extra['chmod'])) {
176+
continue;
177+
}
178+
179+
$error = false;
180+
foreach ($extra['chmod'] as $chmod) {
181+
if (!isset($chmod['mask']) || !isset($chmod['path']) || strpos($chmod['path'], '..') !== false) {
182+
$error = true;
183+
continue;
184+
}
185+
186+
$file = $this->installer->getTargetDir() . '/' . $chmod['path'];
187+
if (file_exists($file)) {
188+
chmod($file, octdec($chmod['mask']));
189+
} else {
190+
$this->io->writeError([
191+
'File doesn\'t exist: ' . $chmod['path'],
192+
sprintf($message, $package->getName())
193+
]);
194+
}
195+
}
196+
197+
if ($error) {
198+
$this->io->writeError([
199+
'Incorrect mask or file path.',
200+
sprintf($message, $package->getName())
201+
]);
202+
}
203+
}
204+
}
162205

163206
protected function deployLibraries()
164207
{

0 commit comments

Comments
 (0)