Skip to content

[Falcons] Bug fixes for Composer, Cache, Catalog #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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