Skip to content

Commit

Permalink
Magento: Added static-content-deploy relative symlink patch.
Browse files Browse the repository at this point in the history
  • Loading branch information
paales committed Mar 4, 2020
1 parent 2462764 commit f9c757b
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to

- Varnish bypass for blackfire.io
- Install: Added zsh support
- Magento: Added static-content-deploy relative symlink patch.

### Changed

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ You are now done with the global installation 🎉
- Install this in the project
`composer require --dev reach-digital/docker-devbox`
- Install `static-content-deploy`
[patches](https://github.com/ho-nl/magento2-ReachDigital_Patches) and remove
[patch](patch/static-content-deploy.md) and remove
`pub/static/frontend/*`.
- Disable services you don't need in `docker-compose.yml` (required: `hitch`,
`varnish`, `nginx` and `db`).
Expand Down
51 changes: 51 additions & 0 deletions patch/static-content-deploy.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
diff --git a/magento/framework/Filesystem/Driver/File.php b/magento/framework/Filesystem/Driver/File.php
index 59c9775d73a..76609e6023f 100644
--- a/magento/framework/Filesystem/Driver/File.php
+++ b/magento/framework/Filesystem/Driver/File.php
@@ -353,7 +353,7 @@ class File implements DriverInterface
{
$result = false;
if ($targetDriver === null || get_class($targetDriver) == get_class($this)) {
- $result = @symlink($this->getScheme() . $source, $destination);
+ $result = symlink($this->relativePath($destination, $this->getScheme() . $source), $destination);
}
if (!$result) {
throw new FileSystemException(
@@ -370,6 +370,37 @@ class File implements DriverInterface
return $result;
}

+
+ private function relativePath($basePath, $targetPath)
+ {
+ if ($basePath === $targetPath) {
+ return '';
+ }
+
+ $sourceDirs = explode('/', isset($basePath[0]) && '/' === $basePath[0] ? substr($basePath, 1) : $basePath);
+ $targetDirs = explode('/', isset($targetPath[0]) && '/' === $targetPath[0] ? substr($targetPath, 1) : $targetPath);
+ array_pop($sourceDirs);
+ $targetFile = array_pop($targetDirs);
+
+ foreach ($sourceDirs as $i => $dir) {
+ if (isset($targetDirs[$i]) && $dir === $targetDirs[$i]) {
+ unset($sourceDirs[$i], $targetDirs[$i]);
+ } else {
+ break;
+ }
+ }
+
+ $targetDirs[] = $targetFile;
+ $path = str_repeat('../', count($sourceDirs)).implode('/', $targetDirs);
+
+ // A reference to the same base directory or an empty subdirectory must be prefixed with "./".
+ // This also applies to a segment with a colon character (e.g., "file:colon") that cannot be used
+ // as the first segment of a relative-path reference, as it would be mistaken for a scheme name
+ // (see http://tools.ietf.org/html/rfc3986#section-4.2).
+ return '' === $path || '/' === $path[0]
+ || false !== ($colonPos = strpos($path, ':')) && ($colonPos < ($slashPos = strpos($path, '/')) || false === $slashPos)
+ ? "./$path" : $path;
+ }
/**
* Delete file
*
23 changes: 23 additions & 0 deletions patch/static-content-deploy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patch static-content-deploy relative symlinks

Makes the static content deploy use relative symlinks in developer mode. Does not affect production mode.

# Installation

1. Install https://github.com/vaimo/composer-patches

2. Add the following to the patches area of your `composer.json`

```
{
"extra": {
"patches": {
"*": {
"Patch static-content-deploy relative symlinks": {
"source": "./vendor/reach-digital/docker-devbox/patch/static-content-deploy.diff"
}
}
}
}
}
```

0 comments on commit f9c757b

Please sign in to comment.