Apply patch file to Magento core files - php

I edit some core code of magento. After this I would like to patch all my edited files to the Magento directory.
My question is: How can I implement php patch with magento? Or how to create patch file with PHP.
Please help me.

Pathfiles are great way to record & distribute you local modifications. Creating a patch file is relatively easy, and applying a patch is even easier.
Before you begin, how did you retrieve Magento's source file?
If you've checkout the source code with SVN, generating a patch is pretty simple.
shell $> cd path/to/your/working/copy
shell $> svn diff > ~/Desktop/magento.path
However, if you downloaded Magento from an archive (tar,zip), you'll need to have the copy of the original files before comparing your revisions. I like to make a original file backup, cp source.php source.php.org, before I alter anything. Sometimes I forget, and I'll need extract the original source-code to a new directory for comparison. To generate a patch file by comparing two sources, use the diff command
shell $> diff -Naur path/to/original/copy path/to/your/working/copy > ~/Desktop/magento.patch
To apply your newly created patch, use the patch command.
shell $> cd path/to/new/magento
shell $> patch -p0 < ~/Desktop/magento.patch
Piece of cake.
Now your question implied that you may want PHP to apply patches. If you comfortable with compiling PHP extentions, take a look at xdiff's xdiff_file_patch function. Else, simply run the previous commands through PHP's system or shell_exec methods.

Related

PhpDocumentor for Laravel 5.7/6.x

This might be a very newbie question but, how exactly do you use phpDocumentor to generate your docs through Laravel? In my Laravel project there's no phpdoc in the vendor/bin directory, and trying to install phpDocumentor via composer fails (as suggested on the GitHub page).
I couldn't find any recent resources about it, the only thing I had luck with is running the phpDocumentor.phar file from the terminal, but the newest version fails immediately.
To get this working, downgrade to PHP 7.1. Then download the latest phpDocumentor.phar file from [http://www.phpdoc.org/phpDocumentor.phar]. Place the phpDocumentor.phar into your Laravel 6.x project's /vendor/bin/ directory.
Then use Homebrew to install other needed packages...
brew install intltool
brew install graphviz
Lastly, cd into /vendor/bin and run...
php phpDocumentor.phar -d ../../app/Http/Controllers
Your documentation output should be at /vendor/bin/output.
Adding a more complete solution that worked for me on creating documentation of my Laravel project with the system environment comprising of MacOS Catalina,Laravel 6 and PHP 7.2.
Visit https://docs.phpdoc.org/3.0/guide/getting-started/installing.html. To install the dependencies, recommended to update homebrew as brew update and brew upgrade. After updating the homebrew, execute the following:
brew install graphviz
brew install plantuml
Once the dependencies are installed, download the phpDocumentor.phar from the above link, and make the file executable as follows:
chmod +x phpDocumentor.phar
Then, copy and paste this file to your laravel app under /vendor/bin
I also placed this file under local bin mv phpDocumentor.phar /usr/local/bin/phpDocumentor for easier access (as shown in step 6 below).
For testing purpose, create a simple test.php file under /vendor/bin/docs/test.php directory with the following content as mentioned in https://docs.phpdoc.org/3.0/guide/getting-started/your-first-set-of-documentation.html
<?php
/**
* This is a DocBlock.
*/
function associatedFunction()
{
}
Then execute the phpdoc script from the same /vendor/bin location as:
phpDocumentor.phar -d docs/test.php -t docs/test
This will generate several files.
Open the index.html file generated in your web browser (eg. Chrome) to view the documentation:
open -a "Google Chrome" ./docs/test/index.html
Notably, because we placed the phpDocumentor.phar in /usr/local/bin/phpDocumentor/phpDocumentor.phar, we can easily access phpdoc and easily create the documentation of our whole App as follows ( the documentation will be stored inside the folder DOCS)
phpDocumentor.phar -d app/ -t DOCS/
I have found the problem with most PHP documentation solutions is they require large amounts of code just to get something you can actually use. And that takes a lot of time and trial and error to set up.
I also have issues with the generated documentation. Often it is not even sorted! Also it is hard to navigate and understand the whole class. As a consumer of a class, you are not interested in private or even protected things (unless you are trying to extend it). But often the docs only show you the methods and properties of the current class, and not what it inherits (which is the WHOLE point of OO!).
Anyway, I got sick of the current state of PHP documentation and decided to do it right. I wrote PHPFUI/InstaDoc to address all the issues I had with existing solutions. InstaDoc is the fastest document generator out there because it simply scans the class directory structure and saves it off. This generally only takes a few seconds (for large code bases) each time you generate (on release, or if you add a new class in your dev env). Then it renders the docs for a specific class at runtime, because, hey, who ever looks at the documentation anyway? Just us nerds, and there are not many of us, and we can wait a fraction of a second for the server to generate the docs on the fly. Also you don't need server disk space to store all your docs. They are generated on the fly. And of course if you have a high volume site, InstaDoc can generate static HTML files, but who has a high volume PHP doc site (like nobody).
Anyway, check out a live example at PHPFUI/InstaDoc and see if it fits your needs. It is not a Laravel module or plug in, but you should be able to run it under Laravel easily. Just return the output of the controller in your controller, and it should just work.

Do a "git diff" between two directories due to website owner making live changes

I have a project I'm working on which I've set up in a git repo.
Since I put my latest version live, the website owner has made some changes to the working/content by overwriting it directly.
Obviously these changes were made outside of version control. I suppose I could overwrite the entire contents of my repo, then commit. That should work... but I don't really like the idea of doing that, especially if there's been any replacement of correct code/html-structure with stuff that's incorrect or bad practice.
What I'd like to do is dump the website from live into another directory and do a recursive diff so I can only overwrite those files which have changed (any correct any issues if there are any)
As in if I just overwrite what's in my git repo, then run git status?
No, you don't have to overwrite anything.
You can do a diff between:
the index representing your site in its latest versioned state (in the git repo)
a dump of the current live site (a copy done in a different folder, not under version control)
You can then do (using git options) a:
git diff --git-dir=/path/to/repo/.git --work-tree=/path/to/dump .
You actually can execute that command from any folder: it will look for the git index and for the right working tree.
The OP Tom Busby adds in the comments:
In the end I solved it by simply overwriting the .git folder in my dump directory with the one from my git repo and running git diff.
VonC's answer is excellent, but I believe you could also just use the diff command (a built-in command on most operating systems). This would also ensure that "gitignored" files were diffed (though VonC's might already do that).
Assuming the website in /www/mysite and a fresh clone in /git/mysite you could just do:
diff /www/mysite /git/mysite
Yes We can compare two directories very easily
simply using this command on Shell/Terminal
git diffdir any-branch-name any-other-branch-name

Running a git post-commit hook

I'm running MAMP locally. I have a php script that I use to build a web site, to generate static HTML files, that I then push to a web server.
This process acts a lot like Jekyll on github pages.
For now, I simply make changes to Markdown files (my content) and then hit a local url, localhost/mysite/build, to which generates the html files. Simple.
I do have git installed locally to version the PHP script itself, along with the markdown files.
Ideally I would like to create a post-commit hook that will simply "ping" that build URL to allow it do run.
A couple things. I have been trying but the post-commit doesn't run the URL.
I would like to use PHP in the post-commit file, is that possible? I don't need any validation or anything yet, just simply want to call the URL to have the process run when I commit.
I have done the chmod to make sure the script is executable.
The post-commit file is named 'post-commit', no extension.
I would think I could just add one simple line, like a file_get_contents(myurl), or something close to that.
I have been googling for a few hours now and found things that are close but not exactly right. Its really very simple, just sort of a noob with git hooks.
Thanks.
Commit hooks are shell scripts, so it is definitely possible to either run a php script (just as you would do from cmd line) or issue a request to your URL using curl: curl --request GET --url http://stackoverflow.com -v in order to fire the build. Depending on the build time you might want to run curl in the background.
First of all, try to prepare a shell script, which runs the build. Then setup the hook itself. See Simple git post-commit hook to copy committed files to a certain folder as an example hook.

Generate a version number of my site with git?

I am building a PHP/Yii application. While developing and testing on different machines, I'd like to be able to quickly see in the footers if the version I am seeing is the latest. So basically I want to generate some kind of version number every time I modify something.
I was thinking since I use Git (and GitHub) I could use some of the meta data generated at every commit?
How could I achieve this?
Note: I'd like to avoid using command-line stuff as my current hosting won't allow me to do this.
Add a git hook to create a txt file in the root folder of your app to keep track of the version (or tag, or whatever) of the current deployed code.
Just a 30 sec. example (search google for more details and how to use hooks in git) put in the .git/hooks folder a file named pre-commit and add this shell code:
#!/bin/sh
rm version.txt -i
git describe --tags >> version.txt
git add version.txt
If you deploy with Capistrano, one very serious possibility is to read the 'REVISION' file from the base of the site. If you deploy from a git repo, it will be the commit SHA.

Remove files from Bazaar

I'm using Bazaar (bzr) to keep source code for a website updated, but we've ran into a problem when we remove files from version control. The files we are removing are ones we never intended to version to begin with.
When this happens we use bzr rm --keep to remove the file from version control, but keep the file in the file system. Doing a bzr push or bzr pull results in the removed file(s) being removed on the other branches (other sites that use our code)
We need a way to make sure that a bzr push or bzr pull doesn't actually remove those from the working copy. Anyone have any ideas?
You need to run bzr rm --keep in all locations manually before updating them with pull/push. There is no other way unfortunately.

Categories