Skip to content
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

fix: do not forcefully set area in template if it is already set, fixes #14968, fixes #13530 #15137

Merged
merged 4 commits into from May 16, 2018

Conversation

DanielRuf
Copy link
Contributor

@DanielRuf DanielRuf commented May 10, 2018

Description

This reverts the addition of the enforced area in d3aef7c which caused #14968 and introduced this regression

Fixed Issues (if relevant)

  1. Can't change the applied theme in 2.2.4 #14968: Can't change the applied theme in 2.2.4
  2. "Template file 'header.html' is not found" error while trying to save Design Configuration. #13530: "Template file 'header.html' is not found" error while trying to save Design Configuration.

Manual testing scenarios

  1. comment / disable line 117 in app/code/Magento/Theme/Model/Design/Config/Validator.php
  2. change theme in store view

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@DanielRuf DanielRuf changed the title fix: do not set forced area in template, fixes #14968 fix: do not forcefully set area in template if it is already set, fixes #14968 May 10, 2018
@hostep
Copy link
Contributor

hostep commented May 10, 2018

For completeness sake, this PR also fixes #13530 (which was already fixed by d3aef7c, but that was an incomplete fix)

@DanielRuf
Copy link
Contributor Author

For completeness sake, this PR also fixes #13530 (which was already fixed by d3aef7c, but that was an incomplete fix)

Thanks for the reference, updated the list in the PR comment to link to it.

@DanielRuf DanielRuf changed the title fix: do not forcefully set area in template if it is already set, fixes #14968 fix: do not forcefully set area in template if it is already set, fixes #14968, fixes #13530 May 11, 2018
@@ -534,10 +534,9 @@ protected function cancelDesignConfig()
*/
public function setForcedArea($templateId)
{
if ($this->area) {
throw new \LogicException(__('Area is already set'));
if (!isset($this->area)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can $this->area be empty and not null? Looks like simple if (!$this->area) is sufficient here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that I knew, it is either set or null according to the class where it is set in the constructor.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, then simplify condition please. Commit amend is preferable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty and isset check are different, what should I change here? It can just be null or set and isset checks for it already.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DanielRuf I meant that there is no reason to change if ($this->area) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isset is more strict and still correct so I think we can keep it like this.

@@ -534,10 +534,9 @@ protected function cancelDesignConfig()
*/
public function setForcedArea($templateId)
{
if ($this->area) {
throw new \LogicException(__('Area is already set'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there any logic in this exception before? Any idea why it was introduced?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was still the original code from 3 years ago which was untouched. The annotations and exception class are not correct imo but should be solved in another PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the blame view of the file in the original repo and you see that the code was never really touched ;-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DanielRuf Is there any patch available for temporary. I need to fix this in my Magento v.2.2.4.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@magento-engcom-team
Copy link
Contributor

magento-engcom-team commented May 16, 2018

Hi @DanielRuf. Thank you for your contribution.
Changes from your Pull Request will be available with the upcoming 2.2.6 release.

@pfortin-expertime
Copy link

pfortin-expertime commented Jun 7, 2018

Hi guys,

a small module to fix it without touching the core:

https://github.com/pfortin-expertime/MageFix-Misc

Enjoy ;)

@DanielRuf
Copy link
Contributor Author

Hi guys,

a small module to fix it without touching the core:

pfortin-expertime/MageFix-Misc

Enjoy ;)

A composer patch would be better ;-)

@0xpwn
Copy link

0xpwn commented Jun 22, 2018

@DanielRuf Can you please explain in short how to apply this patch using composer-patches?

I have the following in my composer.json:

{
  "config": {
    "preferred-install": "source"
  },
  "extra": {
    "patches": {
      "magento/product-community-edition": {
        "Fix force switch theme": "https://patch-diff.githubusercontent.com/raw/magento/magento2/pull/15137.patch"
      }
    }
  }
}

But I get the following errors:

composer update magento/product-community-edition -vvv

  - Applying patches for magento/product-community-edition
    https://patch-diff.githubusercontent.com/raw/magento/magento2/pull/15137.patch (Fix force switch theme)
Downloading https://patch-diff.githubusercontent.com/raw/magento/magento2/pull/15137.patch
patch '-p1' --no-backup-if-mismatch -d '' < '/var/folders/n1/0cl9jxm90lg1r5qkrqnwf3580000gn/T/5b2ce62c2819b.patch'
Executing command (CWD): patch '-p1' --no-backup-if-mismatch -d '' < '/var/folders/n1/0cl9jxm90lg1r5qkrqnwf3580000gn/T/5b2ce62c2819b.patch'
patch: **** Can't change to directory  : No such file or directory

patch '-p0' --no-backup-if-mismatch -d '' < '/var/folders/n1/0cl9jxm90lg1r5qkrqnwf3580000gn/T/5b2ce62c2819b.patch'
Executing command (CWD): patch '-p0' --no-backup-if-mismatch -d '' < '/var/folders/n1/0cl9jxm90lg1r5qkrqnwf3580000gn/T/5b2ce62c2819b.patch'
patch: **** Can't change to directory  : No such file or directory

patch '-p2' --no-backup-if-mismatch -d '' < '/var/folders/n1/0cl9jxm90lg1r5qkrqnwf3580000gn/T/5b2ce62c2819b.patch'
Executing command (CWD): patch '-p2' --no-backup-if-mismatch -d '' < '/var/folders/n1/0cl9jxm90lg1r5qkrqnwf3580000gn/T/5b2ce62c2819b.patch'
patch: **** Can't change to directory  : No such file or directory

patch '-p4' --no-backup-if-mismatch -d '' < '/var/folders/n1/0cl9jxm90lg1r5qkrqnwf3580000gn/T/5b2ce62c2819b.patch'
Executing command (CWD): patch '-p4' --no-backup-if-mismatch -d '' < '/var/folders/n1/0cl9jxm90lg1r5qkrqnwf3580000gn/T/5b2ce62c2819b.patch'
patch: **** Can't change to directory  : No such file or directory

   Could not apply patch! Skipping. The error was: Cannot apply patch https://patch-diff.githubusercontent.com/raw/magento/magento2/pull/15137.patch



  [ErrorException]
  file_put_contents(/PATCHES.txt): failed to open stream: Permission denied

@DanielRuf
Copy link
Contributor Author

file_put_contents(/PATCHES.txt): failed to open stream: Permission denied

Looks like some chown / rights issues.

@hostep
Copy link
Contributor

hostep commented Jun 23, 2018

@1x0: a patch won't just work from Github, since the file paths in the patch won't match the composer installation (app/code/Magento/Theme/ vs vendor/magento/module-theme/).

You can find information about how to create, edit and apply patches using this recently introduced Knowledge Base article from Magento: https://support.magento.com/hc/en-us/articles/360005484154
Hope this helps :)

@DanielRuf
Copy link
Contributor Author

(app/code/Magento/Theme/ vs vendor/magento/module-theme/).

Ah right forgot that the Git repo and composer based installs are different but we can still use app/code to overwrite the original files.

Changing the file paths in the patch file should be sufficient.

@DanielRuf
Copy link
Contributor Author

Edit the file and remove vendor// from all paths so that they are relative to the vendor// directory.

Simply forgot this one =)

ihor-sviziev pushed a commit to ihor-sviziev/magento2 that referenced this pull request Jul 10, 2018
Squashed commit of the following:

commit db9fa53cce1c8042caf24c855cfc18d1d948a6b8
Author: Daniel Ruf <[email protected]>
Date:   Thu May 10 19:18:37 2018 +0200

    fix: change unit test back to test for the setForcedArea method

commit af6d5c137ff57b13fbd8d6c9e097f7455f67cf7e
Author: Daniel Ruf <[email protected]>
Date:   Thu May 10 19:10:11 2018 +0200

    fix: just set the area if it is not set

commit 2fd7e5d84abcdea5306f2bd81dd44b86aaa970d7
Author: Daniel Ruf <[email protected]>
Date:   Thu May 10 16:55:35 2018 +0200

    fix: do not expect setForcedArea in unit tests for Magento\Theme\Test\Unit\Model\Design\Config\Validator

commit a1bf00c10d5fc01e5e592f38472b820141a47133
Author: Daniel Ruf <[email protected]>
Date:   Thu May 10 16:46:04 2018 +0200

    fix: do not set forced area in template, fixes magento#14968
@ihor-sviziev
Copy link
Contributor

FYI I created squashed commit that can used for composer patches:
https://github.com/ihor-sviziev/magento2/commit/e4ec8adef586c615cda168175ad8950c701b0874.patch

@hostep
Copy link
Contributor

hostep commented Jul 10, 2018

@ihor-sviziev : @sidolov also already did that on 16 May, you can view his commit if you scroll up a bit, see: 7019a0a

And it's available on here as well: https://magento.com/tech-resources/download (MAGETWO-93036), don't know if this got communicated or something, because I only found out about that by accident.

But thanks anyways! :)

@ihor-sviziev
Copy link
Contributor

Hi @hostep,
We tried to apply this patch from commit 7019a0a with composer patches and got an error. Reason is simple commit that you showed - when you trying to use it as a patch - it contains changes both form magneto email and magneto theme modules + reverting changes in magento theme also. While mine contains only changes in magento theme because it contains squashed chanages into 1 commit

@DanielRuf
Copy link
Contributor Author

There should be just one file changed. Do you use Magento 2.2.5?

@DanielRuf
Copy link
Contributor Author

DanielRuf commented Jul 11, 2018

Only app/code/Magento/Email/Model/AbstractTemplate.php should be affected.

@ihor-sviziev
Copy link
Contributor

ihor-sviziev commented Jul 11, 2018

@DanielRuf sure, just take a look at https://github.com/magento/magento2/commit/7019a0a1392095185505ff3ca7b97dd3e9cb4ef2.patch - it contains all changes form all commits - adds changes to magneto theme, removes changed files in magento theme and adds changes to magneto email.
That's why it's better to squash commits into single one when you have final result

@DanielRuf
Copy link
Contributor Author

Try https://github.com/magento/magento2/pull/15137.diff if the other one is problematic.

@DanielRuf
Copy link
Contributor Author

Also the other should be problematic, the result should be the same (in general).

MarsArt pushed a commit to ConvertGroupsAS/magento2-patches that referenced this pull request Aug 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants