📜 ⬆️ ⬇️

Development of Magento modules with application deployment through Magento Composer

Introduction


The article describes the experience of deploying a developer version of a Magento application using Magento Composer. The structure of a typical Magento application in our company:


The developer version of the Magento application should allow you to develop the code of our modules and upload changes to the corresponding repositories, allowing the code of common modules to migrate between projects.

In connection with the launch of a new project to deploy Magento applications, we decided to try Magento Composer . At the moment, we have the code for each project stored in its SVN repository, plus in a separate - all modules developed by us (both general and specialized):

')
To use Magento Composer, the project was divided into the following parts (each in its git repository):





Environment preparation


During the experiments, it turned out that Windows is not well suited for deploying the developer version of the application. Magento Composer offers two deployment strategies: copy (copying module files to the structure of a Magento application) and symlink (creating symbolic links to module files in the structure of a Magento application). The developer version can only use symbolic links, since you need to keep the sources of the modules compactly in their folders in the vendor directory (the place where Composer places the files of the used modules). Symbolic links in Windows do not work out well enough - changes made to the original file are reflected by reference with a long delay (both in IDE PhpStorm and on the web server itself). Plus (or rather, minus) - the approach used in Magento to find templates and description of layouts ( app / design / frontend / [default] / [default] directory) does not work in Windows (Mage_Core_Model_Design_Package :: validateFile and Mage_Core_Block_Template :: fetchView), but this is more a problem at the PHP level than at the Magento level. In general, after long attempts to deploy a developer version of Windows, it was considered not the most convenient option for development (although possible), so Linux remained to be continued (Ubuntu 14.04).

There were no problems with the installation of Composer itself:
curl -sS https://getcomposer.org/installer | php mv composer.phar /usr/local/bin/composer 


Everything else (including the installation of Magento Composer) is done by setting up the project in composer.json.

composer.json


I give only the settings that are relevant in this context (full version of composer.json ):
 { ... "type": "magento-module", ... "require": { "magento-hackathon/magento-composer-installer": "*", "magento-hackathon/composer-command-integrator": "*@dev", "composer/composer": "*@alpha", "magento/core": "1.9.1.0", "magento-hackathon/hackathon_magemonitoring": "*", "connect20/nmmlm_log": "*", "praxigento/z_mage_composer_mod_01": "*@dev", "praxigento/z_mage_composer_mod_02": "*@dev" }, "repositories": [ { "type": "composer", "url": "http://packages.firegento.com" }, { "type": "vcs", "url": "https://github.com/praxigento/z_mage_composer_mod_01" }, { "type": "vcs", "url": "https://github.com/praxigento/z_mage_composer_mod_02" } ], "extra": { "magento-root-dir": "mage", "magento-deploystrategy": "symlink", "auto-append-gitignore": true } } 


Require section



Repositories section

Close the composer to the repository of Magento modules:
  { "type": "composer", "url": "http://packages.firegento.com" } 

... and indicate the addresses of the repositories, where our own modules used in the project are located:
  { "type": "vcs", "url": "https://github.com/praxigento/z_mage_composer_mod_01" }, { "type": "vcs", "url": "https://github.com/praxigento/z_mage_composer_mod_02" } 


Extra section



Deploying the project


 $ git clone git@github.com:praxigento/z_mage_composer_prj_01_full.git full $ cd full $ composer install 

console messages
 Loading composer repositories with package information Installing dependencies (including require-dev) - Installing justinrainbow/json-schema (dev-master 87b54b4) Cloning 87b54b460febed69726c781ab67462084e97a105 - Installing icecave/isolator (2.3.0) Loading from cache - Installing eloquent/pops (3.1.1) Loading from cache - Installing eloquent/liberator (1.1.1) Loading from cache - Installing eloquent/enumeration (5.1.0) Loading from cache - Installing eloquent/composer-config-reader (2.0.0) Loading from cache - Installing magento-hackathon/magento-composer-installer (dev-master 38e6c01) Cloning 38e6c01e6252fa408fbe63ef0b5b632b154f421b - Installing symfony/console (2.7.x-dev b2d63b9) Cloning b2d63b962688615d9b895a3d0be8bca7c3acf2fd - Installing praxigento/z_mage_composer_mod_01 (dev-master 73ac1b0) Cloning 73ac1b00c04eeb7037a5fb4bcea2502d06c588a0 - Installing praxigento/z_mage_composer_mod_02 (dev-master ae7f96c) Cloning ae7f96cb757a971e95d23f4ce6141bb441315075 - Installing seld/jsonlint (1.3.0) Downloading: 100% - Installing symfony/process (2.7.x-dev 3131373) Cloning 3131373c59f463709b04e39ae0818a2b84d01d38 - Installing symfony/finder (2.7.x-dev 3163e33) Cloning 3163e335375f3433569996fd68c89887e4a82d29 - Installing composer/composer (dev-master 095dc61) Cloning 095dc6129550de93cd98170c8e6c6ccd4558e983 - Installing magento-hackathon/composer-command-integrator (dev-master 826aa5a) Cloning 826aa5a2a68d10d991b457c397b98773793f0f4c - Installing magento/core (1.9.1.0) Loading from cache - Installing magento-hackathon/hackathon_magemonitoring (dev-master 393fd28) Cloning 393fd2851597ed7e1a9ab87dae7f05feab455e3b - Installing connect20/nmmlm_log (0.3.0) Downloading: 100% icecave/isolator suggests installing eloquent/asplode (Drop-in exception-based error handling.) magento-hackathon/magento-composer-installer suggests installing colinmollenhour/modman (*) magento-hackathon/magento-composer-installer suggests installing theseer/autoload (~1.14) magento-hackathon/magento-composer-installer suggests installing zetacomponents/console-tools (dev-master) symfony/console suggests installing symfony/event-dispatcher () symfony/console suggests installing psr/log (For using the console logger) Writing lock file Generating autoload files 



As a result of the project deployment, the source codes of our modules fall into the vendor directory (screenshots are taken from the local station on Windows)

... linked to the mage Magento-catalog:

... the theme and modules that are not installed via Magento Composer are uploaded directly to the mage directory:

Mount points for various repositories with source codes:


There are two .gitignore files in the project :


Features of the development of modules


All module files must be registered in the modman's mapping registry :
 path/to/file/in/module path/to/file/in/magento 

You can create a modman file with the following command :
 for i in `find . -type f | grep -v \.git | grep -v "^.$" | grep -v "modman" | sed 's/\.\///'`; do echo ${i} ${i}; done > modman 


After adding a new file to the module, you need to start the command integrator so that the new files link to the root directory of Magento:
 $ ./vendor/bin/composerCommandIntegrator.php magento-module-deploy 

In order for the module to unfold in a form suitable for working with a version control system, in the composer.json file of the module you need to specify:
 { "name": "praxigento/z_mage_composer_mod_01", ... "config": { "preferred-install": "source" } } 


When editing a file by reference in IDE (PhpStorm), there is a discrepancy between the “apparent” ( mage / app / code / community / Vendor / Ext / Model / Observer.php ) and the “existing” (vendor / company / module / app / code / community / Vendor / Ext / Model / Observer.php) - editing the “existing” version with a delay is reflected in the “apparent” (and the Refresh function in PhpStorm is not provided for this case - you have to add a symbol to the “apparent” version, press Ctrl + S and update via “Load File System Changes”). Breakpoints for debugging can be set in both versions of the file, but step-by-step tracing goes only on the “existing” (sometimes the stop appears as if from scratch - in the “seeming” version there is a breakpoint on the corresponding line).

Additionally


" Using different VCS repositories in PhpStorm "

Source: https://habr.com/ru/post/246703/


All Articles