Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error patching Magento 1.7.1 Hunk #1 Failed at

I see the last Critical Reminder notification in my Magento Dashboard v.1.7.0.2 (2 important security patches (SUPEE-5344 and SUPEE-1533)...)

So, I download and istalled them correctly in other Magento's (e.g. 1.6.0, 1.6.1), but I'm getting these errors in this version 1.7.0.2

[root@oc1 httpdocs]# sh PATCH_SUPEE-1533_EE_1.12.x_v1-2015-02-10-08-19-16.sh
Checking if patch can be applied/reverted successfully...
ERROR: Patch can't be applied/reverted successfully.

patching file app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php
Hunk #1 FAILED at 444.
1 out of 1 hunk FAILED -- saving rejects to file app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php.rej
patching file app/code/core/Mage/Adminhtml/controllers/DashboardController.php
Hunk #1 FAILED at 92.
1 out of 1 hunk FAILED -- saving rejects to file app/code/core/Mage/Adminhtml/controllers/DashboardController.php.rej

I was searching and I found this Magento patch failing to install post, but it didn't work for me

I download on windows, Mac and Linux the .sh file, and the resault is the same... Some ideas?

like image 905
Di36o Avatar asked Apr 17 '15 15:04

Di36o


3 Answers

I am using Windows on my local machine. The server is Linux of course. And I use Git for version control.

Long story short: Try using dos2unix utility to try to get the line endings of your .php files to match the .sh patch file. (I think you can also run dos2unix on the .sh file or unix2dos on the .sh file - some combination to make them both the same).

Although I think your error messages look a little different to mine. Actually, have you looked in the 'reject file'? If this isn't a line-endings glitch, can you think of anything different between your 1.6 and 1.7 installs? (I have patched 1.7.0.2 and 1.9.0.1 using the method I describe here). If you inspect the Graph.php file, are there any edits in it?

Here is more about what worked for me:

I used Cygwin (Gitbash seemed to struggle with Linux vs Windows file paths and gave the error /app/etc must exist). Also I had to run Cygwin as administrator to get around a file permission error (which is strange and probably unique to my set up).

But the main thing I needed to do was run dos2unix on the files that the patch is trying to diff. I did this by editing the .sh patch files which you can see towards the end of the file has the paths to the files that will be changed.

So I edited the .sh file adding these two lines at line 66 before the comment # 5. File pathes :-

# extra steps for windows CRLF:
dos2unix app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php
dos2unix app/code/core/Mage/Adminhtml/controllers/DashboardController.php

You may want to consider a plan B and edit the files manually; there aren't that many changes.

Patch 5344 does have a few more changes though. For that one I added these lines before the comment # 5. File pathes in file PATCH_SUPEE-5345_CE_1.7.0.2_v1-2015-02-10-08-11-22.sh :-

#  extra steps for windows CRLF:
dos2unix lib/Varien/Db/Adapter/Pdo/Mysql.php
dos2unix app/code/core/Mage/XmlConnect/Model/Observer.php
dos2unix app/code/core/Mage/Oauth/controllers/Adminhtml/Oauth/AuthorizeController.php
dos2unix app/code/core/Mage/Core/Controller/Request/Http.php
dos2unix app/code/core/Mage/Admin/Model/Observer.php

And that worked for me. I read a few Stack Overflow answers to come up with this solution. It seems the 'patch' command is very sensitive to line endings. One other thing you might try is adding the -w flag into the diff command (again by editing the .sh file) which supposedly makes diff ignore white space at the beginning and end of lines but it didn't work for me. http://unixhelp.ed.ac.uk/CGI/man-cgi?diff

As a final gotcha I would note that I needed to add the patch command to Cygwin by re-running the Cygwin setup-x86.exe 'install or update' programme to add in the dev packages that contain patch.

like image 152
Malachy Avatar answered Nov 18 '22 08:11

Malachy


If the file being patched in Magento has different line endings than the patch file itself, you'll see the above HUNK error.

For example:

  • File being patched: Windows Line endings
  • Patch file: Unix line endings

If this is the case you need to change the line endings of whichever file DOES NOT match the system on which it's being run.

ie:

  • If running on Linux, make sure both have Unix line endings.
  • If running on Windows, make sure both have Windows line endings.

You can easily do this in Sublime editor: View > Line Endings > (choose the right one)

If you're running on Linux and your file being patched has Windows line endings (which mine did for some reason and apparently PHP doesn't mind), changing the patch file to also have Windows line endings results in this cryptic error:

$ sh PATCH_SUPEE-2629_EE_1.12.0.0_v1.sh
: command not found_1.12.0.0_v1.sh: line 7:
'ATCH_SUPEE-2629_EE_1.12.0.0_v1.sh: line 9: syntax error near unexpected token `{
'ATCH_SUPEE-2629_EE_1.12.0.0_v1.sh: line 9: `_check_installed_tools() {

See Magento patch failing to install for more details

like image 26
Daniel Flippance Avatar answered Nov 18 '22 06:11

Daniel Flippance


My solution also uses dos2unix, but this is what worked for me:

step 1

in the linux terminal I've run cat PATCH------something---.sh | grep "diff ", which results in all files involved in the patch.

tip: If there is a lot of files, add > diff_files.txt and download/access it using your browser.

step 2

copy the diff with file paths instructions to notepad++ (I assume you're using Windows, that's why the line endings happens).

You will have something like this:

diff --git app/code/core/Mage/Adminhtml/Helper/Sales.php app/code/core/Mage/Adminhtml/Helper/Sales.php diff --git app/code/core/Mage/Core/Model/Config.php app/code/core/Mage/Core/Model/Config.php diff --git lib/Varien/File/Uploader.php lib/Varien/File/Uploader.php

As you can see, the file path is duplicated; nevermind.

step 3

Now simply replace diff --git with dos2unix, copy the result and past in the ssh terminal, keep in mind you need to be in the Magento root folder. The dos2unix will call the same file twice, but there is no problem.

dos2unix app/code/core/Mage/Adminhtml/Helper/Sales.php app/code/core/Mage/Adminhtml/Helper/Sales.php dos2unix app/code/core/Mage/Core/Model/Config.php app/code/core/Mage/Core/Model/Config.php dos2unix lib/Varien/File/Uploader.php lib/Varien/File/Uploader.php

tip: maybe the last line needs an extra return in the terminal.

Conclusion

this way you avoid running dos2unix in the all files, which for me seems more secure. Next, call sh PATCH----something--.sh like Magento instructions.

like image 1
WilliamK Avatar answered Nov 18 '22 08:11

WilliamK