Book Image

Magento 1.8 Development Cookbook

By : Bart Delvaux, Nurul Ferdous
Book Image

Magento 1.8 Development Cookbook

By: Bart Delvaux, Nurul Ferdous

Overview of this book

<p>Magento is an open source e-commerce platform which has all the functionality to function from small to large online stores. Its architecture makes it possible to extend the functionalities with plugins where a lot of them are shared by the community. This is the reason why the platform is liked by developers and retailers.</p> <p>A practical developer guide packed with recipes that cover all the parts of Magento development. The recipes will start with the simple development exercises and get the more advanced as the book progresses. A good reference for every Magento developer!</p> <p>This book starts with the basics. The first thing is to create a test environment. Next, the architecture, tools, files and other basics are described to make you ready for the real work.</p> <p>The real work starts with the simple things like theming and catalog configuration. When you are familiar with this, we will move on to more complex features such as module and database development. When you have survived this, we will move on to the last part of making a shop ready for launch: performance optimization and testing. This book will guide you through all the development phases of Magento, covering the most common pitfalls through its recipes.</p>
Table of Contents (19 chapters)
Magento 1.8 Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Adding version control to the source code


With version control, you can manage the changes that are made in the computer files. When you add this to a programming code, you can track all the changes you have made to the code from the time you initialized it. There are some very popular version control systems on the market, such as Subversion (SVN), Mercurial SCM, CVS, and Git SCM.

In this recipe, we will use Git SCM to add version control to our previously created Magento code. We will initialize an empty repository. After that, we will do several commits to add all the Magento code to the repository.

Getting ready

Go to your command line, and install Git on your local server by running the following command in the terminal:

sudo apt-get install git

How to do it...

The following steps show you how you can add the Magento code to the version control system Git:

  1. We have to initialize the Git repository. To do this, navigate to the source folder and enter the following command:

    git init
    
  2. Run the following command and you will see that all the files are marked as untracked:

    git status
    

    In the next steps, we will add the other folders to the repository.

  3. Add the app/ folder to the repository by running the following command:

    git add app/ 
    

    This will add all the files in the app/ directory. When you run the git status command, you will see a list of all the files.

  4. Run the following command to remove the local.xml file from the repository but not from the drive:

    git rm --cached app/etc/local.xml
    
  5. Run the following command to create the first commit:

    git commit –m "add app folder"
    
  6. Run the following command to track the file's status:

    git status
    
  7. Create a .gitignore file in the root, and add the following content in it:

    app/etc/local.xml
    
  8. Run the git status command again, and you will see that local.xml is ignored.

  9. Commit the .gitignore file by running the following command:

    git commit .gitignore –m "add gitignore file"
    
  10. Add the other application files and folders to the repository by running the command git add <folder or filename>. Run this command for the following folders:

    • downloader (for installing plugins)

    • errors (configuration about error handling)

    • js (the JS library folder)

    • lib (contains PHP libraries)

    • pkginfo (information about upgrades)

    • shell/ (contains PHP CLI scripts)

    • skin/ (the CSS and images folder)

    • api.php

    • cron.php

    • cron.sh

    • favicon.ico

    • get.php

    • index.php

    • index.php.sample

    • install.php

    • LICENCE_AFL.txt

    • LICENCE.html

    • LICENCE.txt

    • mage

    • php.ini.sample

    • RELEASE_NOTES.txt

  11. Run a new git commit command:

    git commit –m "add additional files"
    
  12. Ignore the other nonstatic Magento files and folders. Add the following content in the .gitignore file:

    /app/etc/local.xml
    
    /errors/local.xml
    
    /media/css/
    /media/dhl
    /media/downloadable
    /media/import/
    /media/js/
    /media/catalog/
    /media/customer
    /media/upload/
    /media/wysiwyg/
    /media/captcha/
    /media/tmp/
    /media/xmlconnect
    
    /var/import/
    /var/export/
    /var/cache/
    /var/log/
    /var/session/
    /var/locks/
    /var/package
    /var/report/
    /var/resource_config.json
    
    sitemap.xml
  13. Add the media/ and var/ folders to the repository with the following command:

    git add media/.htaccess
    git add var/.htaccess
    

    We only need the .htaccess files, the other files are ignored because they are dynamic.

How it works...

When working with a version control system, you have to keep in mind that another person who clones the project can set up the environment with a database and the code in the Git. That environment has to be the same as the one you have committed.

It is very important that every Magento core file and your customized files are in the Git repository. You don't have to add configuration files, such as app/etc/local.xml and errors/local.xml, in version control. When running your code on another server, the settings in the configuration files are mostly different from the settings on the server.

Dynamically generated files such as cache files and user images are stored in the media and var folder, so we don't need the content of these folders.

The only important file in these folders is the .htaccess file, which has the configuration to restrict the var folder and the media folder.