X-Cart Gold / X-Cart Pro Software: How to install patches
Diff file (or a patch) is a file ‘describing’ changes which needs to be applied to the file. In UNIX world diff files are a standard way to apply changes/fixes to a program source code. There is a special program called ‘patch’ which reads diff files and applies the changes to the source code.
In everyday use diff files are frequently called ‘patches’ which may sometimes cause confusion.
An example of a diff file:
Code:
Index: admin/category_modify.php
@@ -160,7 +160,7 @@
db_query(“update $sql_tbl[categories] set category=’$category_name’, description=’$description’,
meta_tags=’$meta_tags’, avail=’$avail’, order_by=’$order_by’, membership=’$cat_membership’ where
categoryid=’$cat’”);
db_query(“UPDATE $sql_tbl[categories] SET membership=’$cat_membership’ WHERE category LIKE
‘$category_name/%’”);
- db_query(“UPDATE $sql_tbl[categories] SET
category=CONCAT_WS(”,’$category_name’,SUBSTRING(category,”.strlen($old_category_name).”)) WHERE category LIKE
‘Books/%’”);
+ db_query(“UPDATE $sql_tbl[categories] SET
category=CONCAT_WS(”,’$category_name’,SUBSTRING(category,”.(strlen($old_category_name)+1).”)) WHERE category
LIKE ‘$old_category_name/%’”);
}
#
We suggest three methods for patch installation.
- - Save the text of the patch as a file.
- - Log in to the admin area and go to the ‘Patch/Upgrade’ section.
- - in section ‘Apply patch’, select your file by clicking on ‘Browse’ button. Click ‘Apply’.
2. Runing ‘patch’ command.
- - Save the text of the patch as a file (e.g. patch.diff).
- - Copy this file (patch.diff) to the directory where your X-Cart is installed.
- - check the patch adaptability: if you are on Linux OS, run command ‘patch –dry-run < patch.diff'; if you are on FreeBSD, run command 'patch -C < patch.diff'.
- If there are no errors, apply the patch by issuing command ‘patch < patch.diff'.
Learn more about ‘patch’ command in the manual (man patch, info patch).
If the patch fails in the first two cases, it might be caused by redundant spaces or conversion problems.
3. Incorporate the changes right in the source code.
Open the diff file in a text editor. Diff files are divided into parts (“hunks”). Each “hunk” starts with a line like this:
@@ -160,7 +160,7 @@
where:
160 – indicates the first line of the code that needs to be changed
7 – indicates the number of the lines in the hunk before patch applying
7 – indicates the number of the lines in the hunk that will be after the patch is applied
Under ‘Index:’ you will find the name of the file that you should patch. In our example, it is “admin/category_modify.php”
Then follows the file code marked with “+” and “-” signs:
Lines marked with “+” are the lines that you need to add in the file
Lines marked with “-” are the lines that you need to remove from the file
If you still fail to apply the patch, it might mean that the files to patch are modified or from another X-Cart version thus cannot be patched by this patch. Feel free to contact our support team for help.