SlideShare uma empresa Scribd logo
1 de 34
Baixar para ler offline
How and Why
to Patch a Module
1 August, 2014
Buenos tardes!
Introduction and overview.
What’s a Patch?
A Small Change File
Patches are small files that contain a list of all the differences
between the publicly-available code, and the code you want to
run.
You “apply” them to the existing code, and your changes are made
in the code.
They are a small file that contains a list of all the differences between the existing code, and the code you want to run.
This allows you to both use the code you want, and also keep up with changes in the contrib or core code you’re basing it. Every time they update, you
can re-run your patch on the new version, to modify the module and make it do what you want it to.
Why and When?
Hacking core/contrib... Nicely
In the Drupal community, we
DON’T HACK CORE!
Patches are a way to modify core or contrib
code in a way that’s maintainable, future-
friendly, and reproducible.
And it saves kittens.
There are two main reasons we don’t hack core or contrib.
1 - Forward compatibility: If new features or changes, or most importantly, security releases, are made to the module, you can’t take advantage of them
without losing your changes.
2 - Developer friendliness: If your changes introduce a bug down the road, other developers will not look in that module, because they will assume it
hasn’t been changed. This will cost them time and frustration.
DON’T DO IT!
When would I patch a module?
• You’ve found a module that does most of what you need...
but not quite everything.
• You’ve found a bug in the module.
• You need to integrate custom functionality into the
module, but it doesn’t have the right API functions.
• You need a change right now and the module maintainer
isn’t responding.
When would I not patch a module?
• The module provides hooks or alter functions that will
allow you to do what you need.
• The module only does a little of what you need, and you
probably can build a custom module for the same effort.
• The dev version of the module has what you need, or
there’s already a patch in the issue queue.
That last point leads us to the next section...
How?
Work Smarter
Check the Issue Queue and the
Dev Version of the module!
Step One: Work Smarter!
It’s quite possible that someone has already done what you need to do. Check first, save yourself some work!
These links lead to the issue queue, where you can find other people’s bug reports, feature requests, support requests, and - best of all - patches.
If you find a patch that looks promising, you can skip to the “Apply a Patch” section towards the end of this presentation.
Edit and patch
Check it out!
Step Two: Check out the module!
You need to be working from a git repo to make a patch. Just downloading the module from the links doesn’t work.
Find and click the link on the module’s page that says “Version Control”. Make sure that the “Version to work from” form item says “-x” at the end. This is
the dev version of the project.
Then copy and paste the git clone line into your terminal.
Hack Away!
Now’s your chance!
Make changes, experiment, do all the
crazy things you can think of.
Step Three: The Hack
The magic of source control means that you are not going to wind up with an unusable module - you can always rewind your work and start over if you
have to.
Then, enable the hacked module in a site, and test! Repeat this until it works just the way you want.
Two Things to Remember
• Make sure you’re working against the dev version of the
module. If you are submitting to the module’s issue queue
(and we will be) you’ll usually be asked by the maintainer
to roll your patch against the dev version.
• And please, please make sure you try to follow best Drupal
security practices!
Once you’re done, diff.
The Command line way:
git diff > patch_demo.patch
Step Four: make the patch. There’s two ways.
The command line way:
cd into your module directory
git diff > patch file
This will put all modified files into the patch. There are command line options to only include certain files, or to compare different directories, etc.
However, I personally favor a different way...
Once you’re done, diff.
Sourcetree.
This is a GUI interface for management of your repositories, and it is awesome. It’s also free.
It lists the files you’ve changed...
and shows you the changes to those files
And you can create a patch just like that. The best part of creating a patch in Sourcetree is that if you have changed more than one file, it will ask you
which files to include, in a nice checkbox menu. Much better than having to specify them on the command line.
Submit your work
Step Five: Submit your work.
This is the Issue Queue of a module. (You should already be familiar with this from searching it for solutions before.)
Create a new issue.
Fill out all the form elements - make the title descriptive, and the summary a good explanation of what the problem is.
Don’t attach your file yet!
Naming
[module name] - [short description] - [issue number] -
[comment number] . patch
example:
patch_demo-job_field-2056001-3.patch
Next, you’ll rename your patch file to match the Drupal community’s standards. Here’s how:
module name - short description of what your patch does - issue node number - comment number .patch
Let me show you where to find those numbers...
Issue Number
Issue number is the
nid of the issue queue
node.
You find it in the URL.
After you’ve created the issue node in the issue queue, the issue number is the nid of that node. It’s in the URL.
Comment Number
Comment number is
the number of the
comment on the
node, plus 1.
NOT the cid.
In order to add a patch to the issue node, you’ll need to attach it to a comment. Your comment number will be one more than the highest comment
number on the node already. If there are no comments, then it will be 1.
It is NOT the cid.
Naming
[module name] - [short description] - [issue number] -
[comment number] . patch
example:
patch_demo-job_field-2056001-3.patch
Now that you have the numbers, you can rename your patch. Do that, then upload and make a comment like “Patch attached”.
You’ve done it!
Use your work
in production
Step Six: Bring all the pieces together.
Drush Make
Drush make allows you to specify modules, libraries, themes... it makes site building work the way it’s supposed to. It’s great, and if you aren’t using it,
you should be.
It also allows you to specify patches to apply to your modules. The patches must be somewhere accessible via the web, which is why we put it into the
drupal issue queue.
Running drush make on this make file will download drupal, the features module, our patch_demo module. It will assemble the site, then apply the patch
to the patch_demo module, making the changes we specified much earlier in the process.
That’s all there is to it.
Community Response
Discussion of possible outcomes for your patch (Acceptance / Rejection / Discussion).
Why bother?
Since the patch only needs to be accessible to drush, it could be anywhere - like, on a file server or your company’s web site download directory. Why
contribute?
Because each of you, no matter how new, or inexperienced, or totally ninja, can help make Drupal better. Communities work best when everyone
contributes. Your patch may not be accepted, but it may, or it may spark a discussion that leads to a better way of doing what you need.
Also - even it it isn’t accepted, it’s in the issue queue file system, so it never goes away - meaning you can continue to use it. I’ve submitted many patches
I knew would never get accepted, because I needed something to work in a particular unique way. That’s OK.
Links
• Drupal Patch Contributor Guide: drupal.org/node/1054616
• joshuabrauer.com/2008/07/dont-hack-core-and-dont-
hack-contrib-unless-you-have
• Git Diff: git-scm.com/docs/git-diff
• SourceTree: sourcetreeapp.com
Senior Developer
Email: jturton@phase2technology.com
Joshua Turton
Twitter: @sjinteractive
PHASE2TECHNOLOGY.COM

Mais conteúdo relacionado

Destaque

Git workflow in agile development
Git workflow in agile developmentGit workflow in agile development
Git workflow in agile developmentZack Siri
 
Use git the proper way
Use git the proper wayUse git the proper way
Use git the proper wayJaime Buelta
 
Tools/Processes for serious android app development
Tools/Processes for serious android app developmentTools/Processes for serious android app development
Tools/Processes for serious android app developmentGaurav Lochan
 
The development workflow of git github for beginners
The development workflow of git github for beginnersThe development workflow of git github for beginners
The development workflow of git github for beginnersGunjan Patel
 
Git flow for daily use
Git flow for daily useGit flow for daily use
Git flow for daily useMediacurrent
 

Destaque (9)

Git workflow in agile development
Git workflow in agile developmentGit workflow in agile development
Git workflow in agile development
 
Use git the proper way
Use git the proper wayUse git the proper way
Use git the proper way
 
Tools/Processes for serious android app development
Tools/Processes for serious android app developmentTools/Processes for serious android app development
Tools/Processes for serious android app development
 
Git workflows
Git workflowsGit workflows
Git workflows
 
Mini git tutorial
Mini git tutorialMini git tutorial
Mini git tutorial
 
The development workflow of git github for beginners
The development workflow of git github for beginnersThe development workflow of git github for beginners
The development workflow of git github for beginners
 
git flow
git flowgit flow
git flow
 
Git flow for daily use
Git flow for daily useGit flow for daily use
Git flow for daily use
 
Git collaboration
Git collaborationGit collaboration
Git collaboration
 

Mais de Phase2

Phase2 Health and Wellness Brochure
Phase2 Health and Wellness BrochurePhase2 Health and Wellness Brochure
Phase2 Health and Wellness BrochurePhase2
 
A Modern Digital Experience Platform
A Modern Digital Experience PlatformA Modern Digital Experience Platform
A Modern Digital Experience PlatformPhase2
 
Beyond websites: A Modern Digital Experience Platform
Beyond websites: A Modern Digital Experience PlatformBeyond websites: A Modern Digital Experience Platform
Beyond websites: A Modern Digital Experience PlatformPhase2
 
Omnichannel For Government
Omnichannel For Government Omnichannel For Government
Omnichannel For Government Phase2
 
Bad camp2016 Release Management On Live Websites
Bad camp2016 Release Management On Live WebsitesBad camp2016 Release Management On Live Websites
Bad camp2016 Release Management On Live WebsitesPhase2
 
A FUTURE-FOCUSED DIGITAL PLATFORM WITH DRUPAL 8
A FUTURE-FOCUSED DIGITAL PLATFORM WITH DRUPAL 8A FUTURE-FOCUSED DIGITAL PLATFORM WITH DRUPAL 8
A FUTURE-FOCUSED DIGITAL PLATFORM WITH DRUPAL 8Phase2
 
The Future of Digital Storytelling - Phase2 Talk
The Future of Digital Storytelling - Phase2 TalkThe Future of Digital Storytelling - Phase2 Talk
The Future of Digital Storytelling - Phase2 TalkPhase2
 
Site building with end user in mind
Site building with end user in mindSite building with end user in mind
Site building with end user in mindPhase2
 
Fields, entities, lists, oh my!
Fields, entities, lists, oh my!Fields, entities, lists, oh my!
Fields, entities, lists, oh my!Phase2
 
Performance Profiling Tools and Tricks
Performance Profiling Tools and TricksPerformance Profiling Tools and Tricks
Performance Profiling Tools and TricksPhase2
 
NORTH CAROLINA Open Source, OpenPublic, OpenShift
NORTH CAROLINA Open Source, OpenPublic, OpenShiftNORTH CAROLINA Open Source, OpenPublic, OpenShift
NORTH CAROLINA Open Source, OpenPublic, OpenShiftPhase2
 
Drupal 8 for Enterprise: D8 in a Changing Digital Landscape
Drupal 8 for Enterprise: D8 in a Changing Digital LandscapeDrupal 8 for Enterprise: D8 in a Changing Digital Landscape
Drupal 8 for Enterprise: D8 in a Changing Digital LandscapePhase2
 
Riding the Drupal Wave: The Future for Drupal and Open Source Content Manage...
Riding the Drupal Wave:  The Future for Drupal and Open Source Content Manage...Riding the Drupal Wave:  The Future for Drupal and Open Source Content Manage...
Riding the Drupal Wave: The Future for Drupal and Open Source Content Manage...Phase2
 
Site Building with the End User in Mind
Site Building with the End User in MindSite Building with the End User in Mind
Site Building with the End User in MindPhase2
 
The Yes, No, and Maybe of "Can We Build That With Drupal?"
The Yes, No, and Maybe of "Can We Build That With Drupal?"The Yes, No, and Maybe of "Can We Build That With Drupal?"
The Yes, No, and Maybe of "Can We Build That With Drupal?"Phase2
 
User Testing For Humanitarian ID App
User Testing For Humanitarian ID AppUser Testing For Humanitarian ID App
User Testing For Humanitarian ID AppPhase2
 
Redhat.com: An Architectural Case Study
Redhat.com: An Architectural Case StudyRedhat.com: An Architectural Case Study
Redhat.com: An Architectural Case StudyPhase2
 
The New Design Workflow
The New Design WorkflowThe New Design Workflow
The New Design WorkflowPhase2
 
Drupal 8, Don’t Be Late (Enterprise Orgs, We’re Looking at You)
Drupal 8, Don’t Be Late (Enterprise Orgs, We’re Looking at You)Drupal 8, Don’t Be Late (Enterprise Orgs, We’re Looking at You)
Drupal 8, Don’t Be Late (Enterprise Orgs, We’re Looking at You)Phase2
 
Memorial Sloan Kettering: Adventures in Drupal 8
Memorial Sloan Kettering: Adventures in Drupal 8Memorial Sloan Kettering: Adventures in Drupal 8
Memorial Sloan Kettering: Adventures in Drupal 8Phase2
 

Mais de Phase2 (20)

Phase2 Health and Wellness Brochure
Phase2 Health and Wellness BrochurePhase2 Health and Wellness Brochure
Phase2 Health and Wellness Brochure
 
A Modern Digital Experience Platform
A Modern Digital Experience PlatformA Modern Digital Experience Platform
A Modern Digital Experience Platform
 
Beyond websites: A Modern Digital Experience Platform
Beyond websites: A Modern Digital Experience PlatformBeyond websites: A Modern Digital Experience Platform
Beyond websites: A Modern Digital Experience Platform
 
Omnichannel For Government
Omnichannel For Government Omnichannel For Government
Omnichannel For Government
 
Bad camp2016 Release Management On Live Websites
Bad camp2016 Release Management On Live WebsitesBad camp2016 Release Management On Live Websites
Bad camp2016 Release Management On Live Websites
 
A FUTURE-FOCUSED DIGITAL PLATFORM WITH DRUPAL 8
A FUTURE-FOCUSED DIGITAL PLATFORM WITH DRUPAL 8A FUTURE-FOCUSED DIGITAL PLATFORM WITH DRUPAL 8
A FUTURE-FOCUSED DIGITAL PLATFORM WITH DRUPAL 8
 
The Future of Digital Storytelling - Phase2 Talk
The Future of Digital Storytelling - Phase2 TalkThe Future of Digital Storytelling - Phase2 Talk
The Future of Digital Storytelling - Phase2 Talk
 
Site building with end user in mind
Site building with end user in mindSite building with end user in mind
Site building with end user in mind
 
Fields, entities, lists, oh my!
Fields, entities, lists, oh my!Fields, entities, lists, oh my!
Fields, entities, lists, oh my!
 
Performance Profiling Tools and Tricks
Performance Profiling Tools and TricksPerformance Profiling Tools and Tricks
Performance Profiling Tools and Tricks
 
NORTH CAROLINA Open Source, OpenPublic, OpenShift
NORTH CAROLINA Open Source, OpenPublic, OpenShiftNORTH CAROLINA Open Source, OpenPublic, OpenShift
NORTH CAROLINA Open Source, OpenPublic, OpenShift
 
Drupal 8 for Enterprise: D8 in a Changing Digital Landscape
Drupal 8 for Enterprise: D8 in a Changing Digital LandscapeDrupal 8 for Enterprise: D8 in a Changing Digital Landscape
Drupal 8 for Enterprise: D8 in a Changing Digital Landscape
 
Riding the Drupal Wave: The Future for Drupal and Open Source Content Manage...
Riding the Drupal Wave:  The Future for Drupal and Open Source Content Manage...Riding the Drupal Wave:  The Future for Drupal and Open Source Content Manage...
Riding the Drupal Wave: The Future for Drupal and Open Source Content Manage...
 
Site Building with the End User in Mind
Site Building with the End User in MindSite Building with the End User in Mind
Site Building with the End User in Mind
 
The Yes, No, and Maybe of "Can We Build That With Drupal?"
The Yes, No, and Maybe of "Can We Build That With Drupal?"The Yes, No, and Maybe of "Can We Build That With Drupal?"
The Yes, No, and Maybe of "Can We Build That With Drupal?"
 
User Testing For Humanitarian ID App
User Testing For Humanitarian ID AppUser Testing For Humanitarian ID App
User Testing For Humanitarian ID App
 
Redhat.com: An Architectural Case Study
Redhat.com: An Architectural Case StudyRedhat.com: An Architectural Case Study
Redhat.com: An Architectural Case Study
 
The New Design Workflow
The New Design WorkflowThe New Design Workflow
The New Design Workflow
 
Drupal 8, Don’t Be Late (Enterprise Orgs, We’re Looking at You)
Drupal 8, Don’t Be Late (Enterprise Orgs, We’re Looking at You)Drupal 8, Don’t Be Late (Enterprise Orgs, We’re Looking at You)
Drupal 8, Don’t Be Late (Enterprise Orgs, We’re Looking at You)
 
Memorial Sloan Kettering: Adventures in Drupal 8
Memorial Sloan Kettering: Adventures in Drupal 8Memorial Sloan Kettering: Adventures in Drupal 8
Memorial Sloan Kettering: Adventures in Drupal 8
 

Último

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 

Último (20)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

How and Why to Patch a Module: DrupalCamp Costa Rica

  • 1. How and Why to Patch a Module 1 August, 2014 Buenos tardes! Introduction and overview.
  • 3. A Small Change File Patches are small files that contain a list of all the differences between the publicly-available code, and the code you want to run. You “apply” them to the existing code, and your changes are made in the code. They are a small file that contains a list of all the differences between the existing code, and the code you want to run. This allows you to both use the code you want, and also keep up with changes in the contrib or core code you’re basing it. Every time they update, you can re-run your patch on the new version, to modify the module and make it do what you want it to.
  • 5. Hacking core/contrib... Nicely In the Drupal community, we DON’T HACK CORE! Patches are a way to modify core or contrib code in a way that’s maintainable, future- friendly, and reproducible. And it saves kittens. There are two main reasons we don’t hack core or contrib. 1 - Forward compatibility: If new features or changes, or most importantly, security releases, are made to the module, you can’t take advantage of them without losing your changes. 2 - Developer friendliness: If your changes introduce a bug down the road, other developers will not look in that module, because they will assume it hasn’t been changed. This will cost them time and frustration. DON’T DO IT!
  • 6. When would I patch a module? • You’ve found a module that does most of what you need... but not quite everything. • You’ve found a bug in the module. • You need to integrate custom functionality into the module, but it doesn’t have the right API functions. • You need a change right now and the module maintainer isn’t responding.
  • 7. When would I not patch a module? • The module provides hooks or alter functions that will allow you to do what you need. • The module only does a little of what you need, and you probably can build a custom module for the same effort. • The dev version of the module has what you need, or there’s already a patch in the issue queue. That last point leads us to the next section...
  • 9. Work Smarter Check the Issue Queue and the Dev Version of the module! Step One: Work Smarter! It’s quite possible that someone has already done what you need to do. Check first, save yourself some work! These links lead to the issue queue, where you can find other people’s bug reports, feature requests, support requests, and - best of all - patches. If you find a patch that looks promising, you can skip to the “Apply a Patch” section towards the end of this presentation.
  • 11. Check it out! Step Two: Check out the module! You need to be working from a git repo to make a patch. Just downloading the module from the links doesn’t work. Find and click the link on the module’s page that says “Version Control”. Make sure that the “Version to work from” form item says “-x” at the end. This is the dev version of the project. Then copy and paste the git clone line into your terminal.
  • 12. Hack Away! Now’s your chance! Make changes, experiment, do all the crazy things you can think of. Step Three: The Hack The magic of source control means that you are not going to wind up with an unusable module - you can always rewind your work and start over if you have to. Then, enable the hacked module in a site, and test! Repeat this until it works just the way you want.
  • 13. Two Things to Remember • Make sure you’re working against the dev version of the module. If you are submitting to the module’s issue queue (and we will be) you’ll usually be asked by the maintainer to roll your patch against the dev version. • And please, please make sure you try to follow best Drupal security practices!
  • 14. Once you’re done, diff. The Command line way: git diff > patch_demo.patch Step Four: make the patch. There’s two ways. The command line way: cd into your module directory git diff > patch file This will put all modified files into the patch. There are command line options to only include certain files, or to compare different directories, etc. However, I personally favor a different way...
  • 15. Once you’re done, diff. Sourcetree. This is a GUI interface for management of your repositories, and it is awesome. It’s also free.
  • 16. It lists the files you’ve changed...
  • 17. and shows you the changes to those files
  • 18. And you can create a patch just like that. The best part of creating a patch in Sourcetree is that if you have changed more than one file, it will ask you which files to include, in a nice checkbox menu. Much better than having to specify them on the command line.
  • 19. Submit your work Step Five: Submit your work.
  • 20. This is the Issue Queue of a module. (You should already be familiar with this from searching it for solutions before.)
  • 21. Create a new issue.
  • 22. Fill out all the form elements - make the title descriptive, and the summary a good explanation of what the problem is. Don’t attach your file yet!
  • 23. Naming [module name] - [short description] - [issue number] - [comment number] . patch example: patch_demo-job_field-2056001-3.patch Next, you’ll rename your patch file to match the Drupal community’s standards. Here’s how: module name - short description of what your patch does - issue node number - comment number .patch Let me show you where to find those numbers...
  • 24. Issue Number Issue number is the nid of the issue queue node. You find it in the URL. After you’ve created the issue node in the issue queue, the issue number is the nid of that node. It’s in the URL.
  • 25. Comment Number Comment number is the number of the comment on the node, plus 1. NOT the cid. In order to add a patch to the issue node, you’ll need to attach it to a comment. Your comment number will be one more than the highest comment number on the node already. If there are no comments, then it will be 1. It is NOT the cid.
  • 26. Naming [module name] - [short description] - [issue number] - [comment number] . patch example: patch_demo-job_field-2056001-3.patch Now that you have the numbers, you can rename your patch. Do that, then upload and make a comment like “Patch attached”. You’ve done it!
  • 27. Use your work in production Step Six: Bring all the pieces together.
  • 28. Drush Make Drush make allows you to specify modules, libraries, themes... it makes site building work the way it’s supposed to. It’s great, and if you aren’t using it, you should be.
  • 29. It also allows you to specify patches to apply to your modules. The patches must be somewhere accessible via the web, which is why we put it into the drupal issue queue. Running drush make on this make file will download drupal, the features module, our patch_demo module. It will assemble the site, then apply the patch to the patch_demo module, making the changes we specified much earlier in the process. That’s all there is to it.
  • 30. Community Response Discussion of possible outcomes for your patch (Acceptance / Rejection / Discussion).
  • 31. Why bother? Since the patch only needs to be accessible to drush, it could be anywhere - like, on a file server or your company’s web site download directory. Why contribute? Because each of you, no matter how new, or inexperienced, or totally ninja, can help make Drupal better. Communities work best when everyone contributes. Your patch may not be accepted, but it may, or it may spark a discussion that leads to a better way of doing what you need. Also - even it it isn’t accepted, it’s in the issue queue file system, so it never goes away - meaning you can continue to use it. I’ve submitted many patches I knew would never get accepted, because I needed something to work in a particular unique way. That’s OK.
  • 32. Links • Drupal Patch Contributor Guide: drupal.org/node/1054616 • joshuabrauer.com/2008/07/dont-hack-core-and-dont- hack-contrib-unless-you-have • Git Diff: git-scm.com/docs/git-diff • SourceTree: sourcetreeapp.com