Category: GLPI Network

Subject

How-to : applying patches

Content

How-to : applying patches

The support team has just given you a patch to fix your ticket.

This documentation is here to explain how-to deal with it !

What is a patch

A file patch is a set of changes (+/-) designed to update, fix, improve or remove lines in GLPI source code.

Here is an example of myPatch.patch

ddc460c4-71844724-604b43a6122753.76837838

The + informs that we add some code
The - informs that we remove some code

You have patch file

Service support give you a file, the extension can be ‘patch’ or ‘diff’

Example : myPatch.patch

Go to Apply patch section

 

You have a commit number

Service support give you this commit number ex: adc9876

First, you need to retrieve changes from commit

Go to https://github.com/glpi-project/glpi/commit/ + COMMIT_NUMBER

Like this https://github.com/glpi-project/glpi/commit/adc9876

 

ddc460c4-71844724-604b43b9d8ea15.62167173

Then, transform the commit into a patch by adding .patch at the end of url.

Like this https://github.com/glpi-project/glpi/commit/adc9876.patch

 

ddc460c4-71844724-604b43caa5ddb9.92806363

Copy / paste all text into new file, and name it myPatch.patch (for example)

Finally, go to Apply patch section

 

You have PR number (Pull Request)

Service support give you a PR number 4770

First, you need to retrieve the PR

go to https://github.com/glpi-project/glpi/pull/ + PR_NUMBER

Like this https://github.com/glpi-project/glpi/pull/4770

 

 

ddc460c4-71844724-604b43d855bd86.09099892

First , transform the PR into a patch by adding .patch at the end of url.

Like this https://github.com/glpi-project/glpi/pull/4770.patch

 

ddc460c4-71844724-604b43f2a086d3.66853947

Copy / paste all text into new file, and name it myPatch.patch (for example)

Finally, go to Apply patch section

Apply patch

Patching GLPI

Move the previously created file to the root folder of GLPI.

ddc460c4-71844724-604b44071b3631.88199175

Go to the GLPI root folder

cd /var/www/html/glpi/ #Adapt the path if necessary

Patching a plugin

Move the previously created file to the root folder of the plugin.

ddc460c4-71844724-604b44113ba493.66506469

Go to the root folder of the plugin

cd /var/www/html/glpi/plugins/XXXX/ #Adapt the path if necessary

Check that the patch binary is installed

To known if it installed, just find the version of the binary patch installed

patch -v

If it installed you should have this

GNU patch 2.7.5
Copyright (C) 2003, 2009-2012 Free Software Foundation, Inc.
Copyright (C) 1988 Larry Wall

License GPLv3+: GNU GPL version 3 or later .
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Larry Wall and Paul Eggert

If not you should have this

command not found: patch

Install it with this command

apt-get install patch #Ubuntu / Debian
yum install patch #Cent OS / RHEL

Test patch before apply it

Before appling patch, you have to test it with this command and parameter --dry-run

patch -p1 --dry-run < myPatch.patch

Test is successfull ✅

In case of a success you should have this

patching file inc/config.class.php

or this

patching file inc/config.class.php
Hunk #1 succeeded at 891 with fuzz 1 (offset 23 lines).
Hunk #2 succeeded at 1301 with fuzz 2 (offset 41 lines).

You can now apply the patch for real with this command

patch -p1 < myPatch.patch

Congratulation the patch is applied ???? ????

Now you have to test this patch, feel free to give us a feedback

Test is failed ❌

In case of an error you should have this

patching file inc/config.class.php
Hunk #1 FAILED at 400.
1 out of 1 hunk FAILED -- saving rejects to file inc/config.class.php.rej

Many things can lead to failure :

Your version of GLPI is different from the version used to make the patch
The file that must be modified by the patch has already been previously

Contact support and explain your problem (do not hesitate to add screenshot, GLPI version, command used etc

Writer: TECLIB
Created on 2021-03-12 11:36
Last update on 2021-03-12 11:38
68 views
This item is part of the FAQ