Drupal: Using Of Patch
You can find this article helpful if you need to use a patch with various modifications. Here, I will tell you about two ways of using a patch.
Solutions:
Manual using of patch
Important: do not forget to create a backup copy of a file you want to modify!
Open patch file and find lines in the following format at the beginning of the file:
— Sites/drupal/sites/all/modules/filter_default/filter_default.module 2007-09-12 15:58:16.000000000 -0500
+++ sites/drupal6/sites/all/modules/filter_default/filter_default.module 2008-04-25 17:18:29.000000000 -0500
“—” means this is original file, and “+++” means this is resulting file. Thus if you use a patch to the original file (“—“), you should get the resulting file (“+++”).
Every piece with changes has the following format:
@@ -59,8 +66,8 @@ function theme_filter_default_admin_defa
for ($i = 1; $i < count($roles)+1; $i++) {
$row = array();
$row[] = $i;
– $row[] = drupal_render($form[‘role_’.$i]);
– $row[] = drupal_render($form[‘format_’.$i]);
+ $row[] = drupal_render($form[‘role_’. $i]);
+ $row[] = drupal_render($form[‘format_’. $i]);
$rows[] = $row;
}
How to read this code:
- @@ -59,8 +66,8 @@ function theme_filter_default_admin_defa – means that lines 59-66 are changed
- “-“ at the beginning of a line means that tha line have to be deleted
- “+” at the beginning of a line – need to add this code
- The rest of lines are context of changes
You should just make changes in the required file…
- Using a patch
Unix and Linux
info about patch (Unix): man patch:
- Copy patch files to a place where the file was created (the path is the first two lines of a patch ).
- Apply patch command
- from a folder with a file that is to be changed:
patch -p0 < path/file.patch
- from the site root:
patch < file.patch
- from a folder with a file that is to be changed:
Cancel patch
If you have some problems with engine working after using a patch, you can use the following command to roll the changes back:
patch -p0 -R < path/file.patch
or
patch -R < file.patch
depending on a command you used for the patch originally. But it’s always better to restore file from the backup copy.
Windows
- Download PATCH program: http://gnuwin32.sourceforge.net/packages/patch.htm
- Install it (run Setup).
- Open installation folder and find patch.exe in bin folder.
- Copy patch.exe to a folder with patch and source files.
- Run patch.exe – terminal window will open.
- Click CTRL+C – you’ll see the console: C:\patch>
- Run a command:
patch.exe –binary -p0 < SA-CORE-2009-009-6.14.patch
Enter name of a patch file instead of SA-CORE-2009-009-6.14.patch.
Summary: Manual using of a patch is the most complicated way but you can always use it. Using a patch is a quick method but it requires installing of additional programs in Windows.