Those who don't know about Dolibarr, Dolibarr is a Open Source ERP and CRM system for businesses. It's codebase is written in PHP.
Here is the repository if you are interested. btw I don't think any developer will be comfortable working on this codebase first time 😅
It had a composer file to manage some dependency before but in the current stable version it is disabled. You can check the commit message here 😜
So anyway, to install any module we need to zip the module and upload via Dolibarr admin panel. Or we can copy the module to the htdocs/custom folder area. 😐
But it causes some issues when we are continuously updating modules and managing version control system for modules.
Also it causes some security risk when we open the upload functionality of the modules. 😱
And honestly why we shouldn't use composer to install modules? It felt like I am in the age of Dinosaurs. 🙄
So what we did was simple. Initialize the dolibarr project with composer. Created separate repositories for the modules.
And when we need to install any modules we just need to add that in the composer.json file.
{
"name": "dolibarr/dolibarr",
"description": "Dolibarr ERP & CRM is a modern and easy to use web software to manage your business",
"license": "GPL-3.0-or-later",
"require": {
"myproject/dashboard": "dev-master",
"myproject/report": "dev-master"
},
"repositories": [
{
"url": "git@github.com:myproject/dashboard.git",
"type": "git"
},
{
"url": "git@github.com:myproject/report.git",
"type": "git"
}
],
"config" : {
"vendor-dir" : "../vendor"
}
}
I did install the modules outside the project folder in the vendor
directory and created symlink to show this as the custom folder inside htdocs directory.
And in the modules I added composer.json to make the module repositories as packages. Here is the composer.json file of the module
{
"name": "myproject/dashboard",
"description": "This module shows custom dashboard",
"type": "dolibarr-module",
"license": "MIT",
"authors": [
{
"name": "Ahmad Jamaly Rabib",
"email": "rabib@japantravel.com"
}
],
"require": {}
}
I have kept the require as empty as it is not needed now but we can modify based on our needs.
So in this way whenever we add/update any module in our dolibarr main project we just need to run composer install
or composer update
. No need to copy the folders or making zip files to upload from dolibarr dashboard. 😎🥳
We can do the same approach for any PHP projects to reuse codes and reduce complexity. 😇 Thank you for reading!
Top comments (1)
Great. I will use this approach in my next projects with Dolibarr. I think the core team needs to adapt to composer and the features of the latest PHP versions.