How to work with SuiteCRM via GIT
Asked Answered
Y

6

6

My company took a terrible decision. They decided to use SuiteCRM, someone installed it for them, and now i should support and develop it. We should customize it a lot and of course it's needed to create many relationships, custom fields, e.t.c. But... how we can do it via git? After any changes in Admin/Studio system creates about 30-40 changes in files, and it's impossible to manage them. After every repair and rebuild there are hundreds changes. It's terrible.

Is there "the right way" to work with CRM and git? I tried to find documentation about changes in relationships and fields via code, not GUI, and found many different instructions and ways... It there a one right way?

Thanks.

Y answered 9/2, 2017 at 16:14 Comment(1)
Terrible as opposed to what? This is the most mature open source CRM out there, it's not perfect but there's def nothing better there. Here, have a downvote!Goerke
M
6
  • As others pointed out you want to use a .gitignore file to ignore certain files and folders, e.g. /*.log /custom/working, /cache and /upload. Also .ext.php-files in /custom/modules/ are generated and could probably remain untracked by git.
  • If you're using Studio to add or change fields you'll have to also write hooks that dump/load the contents of the database table fields_meta_data (hint: with mysqldump I recommend using --skip-extended-insert --skip-dump-date to avoid a git-unmaintainable dump format). As an alternative, you could convert them to vardefs
  • If you also want to ignore // created: <timestamp> lines, you'll have to have a look at git-attributes/filters and probably go through some headache. If you find a working solution for this - feel free to share :)
Monumental answered 16/2, 2017 at 13:36 Comment(0)
T
6

It's not all that bad. I've been using varying levels of Git and SVN management for Sugar for years.

Here's a template .gitignore I usually start with:

# Ignore Everything
/*

# Except .htaccess and Config files
!.htaccess
!config.php
!config_override.php
!.gitignore

# Except custom
!/custom/

# but do ignore some of custom and Extensions stuff
/custom/backup
/custom/blowfish
/custom/history
/custom/index.html
/custom/workflow
/custom/modulebuilder
custom/modules/Connectors
/custom/modules/*/Ext
/custom/application/Ext

# and do track custom modules
!/modules/
/modules/*
!/modules/org_MyModule/

Make sure you keep that last section tracked manually. When you create a module, add it to that list.

If you do end up modifying core files, either for bug fixing or enhancement (which you should try to avoid), you can explicitly add them to your .gitignore

The biggest issue I end up having are config.php and config_override.php. Depending on your environment set up, these aren't all that bad, but the site_url param needs to change based on the URL for the system, so kind of a PITA. Don't think that you can just track one or the other though, since Sugar's config updating processes can rewrite them on a regular and somewhat unpredictable basis.

As for the statement that every change causes dozens of file changes, yes and no. It depends a little bit, but I've certainly seen it. One thing that you can do to minimize this a bit is to make sure you've disabled languages you don't use. I've had projects that I joined that were tracking literally tens of thousands of language files that no one at the organization was speaking. It was English only. We configured Sugar to not generate these and the diff I created deleting those files was so large that our GUI diff tool wouldn't display it.

what about a database or studio changes in production?

Easily the biggest difficulty. As you likely know, Sugar stores field information both in the vardef file and the database table fields_meta_data.

Depending on your set up for development/deployment, you can work around this one of a few ways. I'll outline a few I've seen,

  1. nightly backups of the
    • database schema
    • fields_meta_data
    • Product Catalog, Product Category tables
    • users table (but scrubbed user_hash data)
    • email addresses table, but only for users

This method allows for pretty good development matching of production, but scrubbing some sensitive data and not including unnecessary data. The downside is that custom scripting needs to be employed to (1) handle the backup and (2) handle your dev. environment's download of the backup

  1. a frequent CRON driven script that uses mysqldump to back up key tables (e.g. config, fields_meta_data, users) to individual files, then detects "actual changes" (e.g. diff configured to ignore whitespace timestamps) and if they are found, will commit these files to master.

You can pair this with a similar script that watches the output of git status on production; I've also seen Inotify used for this. When those changes are found (again, on production), they're automatically committed to master.

Once perfected, this method is much more automatic and will even be informed if one of your business managers makes changes in Studio. As you move to commit your local development changes, you'll notice that your master is not the same as origin/master, and you can handle potential conflicts there.

Tunnage answered 16/2, 2017 at 16:16 Comment(4)
just to confirm, you init the git > create .gitignore file with your settings > then do "git add ." to add all the files?Goerke
sorry last question, why do you ignore stuff in the custom folder like /custom/application/Ext does sugar populate it with autogenerated files?Goerke
hey @RobertSinclair -- yes, drop that .gitignore file then git init && git add . && git commit -m 'project start' to get everything loaded up to start. And yes, the dirs custom/application/Ext/* and custom/modules/$ModuleName/Ext/ will contain entirely auto-generated data, created during the Quick Repair and Rebuild process.Tunnage
I've deviated from the above script a bit in my last few projects and am now in favor of tracking all of /modules so we can better track all of the app. through upgrades and even unsafe customizations: gist.github.com/matthewpoer/d2efc395b31728752deaa9922edcb085Tunnage
L
3

For git to do version control for suiteCRM, you can use different branches to manage installation files and codes. Such as master branch to manage the installation files and dev branch to manage your codes. For the files you don’t want version control, just add them in .gitignore.

There is the SuiteCRM on github for your reference.

Luellaluelle answered 10/2, 2017 at 2:11 Comment(0)
B
2

This: .gitignore is valid for SuiteCRM as well.

Bellda answered 9/2, 2017 at 19:2 Comment(1)
Because they use similar Sugar with some different UI :)Lepto
G
1

Official suiteCRM .gitignore file you can just copy/paste (source https://github.com/salesagility/SuiteCRM/blob/master/.gitignore)

So for brand new repos you would:

1) Go to folder and do 'git init'

2) Create .gitignore file with the content below

3) Add all the files using git add . (do this last otherwise gitignore will not work properly)

## First part from https://github.com/github/gitignore/blob/master/SugarCRM.gitignore
# Ignore custom .htaccess stuff.
/.htaccess
# Ignore large parts of the annoying cache directory without breaking things.
cache/*
upload/*
!upload/index.html
# Ignore some files and directories from the custom directory.
custom/
custom/history/*
custom/blowfish/*
custom/modulebuilder/*
custom/working/*
custom/modules/*/Ext/
custom/modules/unified_search_modules_display.php
# Ignore AOD indexes
modules/AOD_Index/Index/*
install/status.json
# Configuration files should be ignored.
/config.php
/config_override.php
/config_si.php
# Connector configuration should also be ignored.
custom/modules/Connectors/connectors/sources/ext/*/*/config.php
# Logs files can safely be ignored.
*.log
## IDE specific items
# Eclipse
*.pydevproject
.project
.metadata
bin/**
tmp/**
tmp/**/*
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath
# Emacs
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
.elc
auto-save-list
tramp
# IntelliJ Idea
*.iml
*.ipr
*.iws
.idea/
.phpstorm.meta.php
# NetBeans
nbproject/
# Vim
.*.sw[a-z]
*.un~
Session.vim
tags
# Windows
Thumbs.db
Desktop.ini
.DS_Store
.DS_Store?
# Microsoft Visual Studio
*.sln
*.suo
*.phpproj
# Disytel
lang_cmp.php
.kdev4/
SuiteCRM.kdev4

#Ignore composer vendor folder
vendor/
public/

#Ignore bower_components
bower_components/
node_modules/


#Ignore Sass Generated files in SuiteP
themes/SuiteP/css/*.map
themes/SuiteP/css/*/*.map
themes/SuiteP/css/*/color-palette.css
themes/SuiteP/css/*/variables.css
tests/_output/*


#Ignore browserstack
BrowserStackLocal
browserstack.err
cache/
custom/**/
.sass-cache/
.php_cs.cache

# Ignore testing environment
build/tmp/
Goerke answered 3/10, 2018 at 18:6 Comment(0)
U
0

We use PhpStorm internally for the product, which enables you to create change lists. I typically use a 3 change list "TODO", "Default", and "Ignore". This is the other way in which you can easily filter out the stuff you don't need. We also take full advantage of .gitignore.

If you are developing on a Linux/Mac. You will probably want to configure git to ignore file permissions as a change. You can do this in a command line:

git config core.fileMode false

There is documentation about SuiteCRM on the SuiteCRM Wiki.

SuiteCRM for Developers by Jim Mackin is a great reference book to get a hold off.

If you run into any trouble then please feel free to use our forum page.

We are more than happy to help. :)

Unwitnessed answered 20/2, 2017 at 9:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.