How do you debug SugarCRM problems/learn how SugarCRM works? - php

I'm in the process of trying to move our company from SalesForce to SugarCRM, but I've run in to a nasty bug (the moment I add a custom field to Accounts, all accounts stop showing up). We've paid for support from the SugarCRM people, but they only have take-forever-then-get-a-worthless-response-level tech support for the open-source version (and we avoid proprietary software like the plague). Oh, and did I mention our Salesforce contract expires at the end of the week?
So, long story short, I'm stuck debugging the SugarCRM app myself. I'm an decently experienced programmer, and I have baseline PHP competency, but I don't even know where to being trying to solve this issue. Can any Sugar developers out there recommend any kind of process for debugging Sugar? Are there any resources out there that would help me to understand what the different PHP files do, or how the Sugar system works overall?
Just as an example of the sort of thing I'm talking about: I figured out how to get sugar to print stack traces, and by following several I noticed a pattern with all the problem lines involving $this->_tpl_vars
I'd love to try and figure out why that method call isn't working, but I don't know:
A) what _tpl_vars is supposed to do
B) where _tpl_vars is defined
C) what $this is supposed to be
D) where in the framework $this gets set
etc.
So if anyone can help explain how/where I would start finding answers to these questions, I'd be incredibly grateful.

I worked with SugarCRM a couple years ago, and although I loved what I saw on the surface, I ended up rejecting it for our project because of what you are experiencing now. The internals of the product are woefully underdocumented. I had envisioned writing a bunch of slick modules for the product, but the resources just don't exist. You'll spend all your time digging through code, pouring over forum posts, and trying to find examples of what you're trying to accomplish. Doesn't sound like things have gotten much better.
Given that your PHP experience is less-than-guru level, and you're undoubtedly busy with a lot of other tasks and deadlines, I think you should maybe reconsider this transition if it's not too late, at least until you get a better comfort level with Sugar. If you're forced to move to Sugar because of an expiring contract with Salesforce, I think you might be in for some serious heartburn!

Use the Krumo library to help. It's super easy and way better than var_dump or print_r.
Simply download the source code and add it somewhere in your custom folder. I use the custom/include folder.
Then override a View or whatever you need to look at. Include the path to file class.krumo.php file, and krumo whatever object you want to take a look at:
Quick example -
<?php
require_once('include/MVC/View/views/view.detail.php');
require_once('custom/include/krumo/class.krumo.php');
class AccountsViewDetail extends ViewDetail {
function AccountsViewDetail() {
parent::ViewDetail();
}
// Override the parent function "preDisplay" to add our own template
function preDisplay(){
krumo($this->bean);
$metadataFile = $this->getMetaDataFile();
$this->dv = new DetailView2();
$this->dv->ss =& $this->ss;
$this->dv->setup($this->module, $this->bean, $metadataFile, 'custom/modules/Accounts/tpls/AccountsDetailView.tpl');
}
}
?>
You'll get a nice object on the page that you can drill into.

Although it's not a perfect answer to my question, this article:
http://developers.sugarcrm.com/wordpress/2008/09/26/where-is-the-code-for-x/
did help a bit. Also when I looked further through the official Sugar docs I found that the Developer Guide does contain some explanation of how Sugar works (although obviously it's not as focused on how Sugar works so much as it's focused on how to make Sugar do new things).
Hope that helps any other burgeoning Sugar devs out there.

These code are coming from Smarty lib, not coming from SugarCRM directly.
Maybe this chm doc will be a little helpful, http://code.google.com/p/sugardoc/downloads/list.

You can also try installing xdebug (PHP extension) and stepping through the code with a compatible IDE such as eclipse or Komodo.
The URL tells you which module directory is being accessed and which action/view. There's a "views" folder under most modules. If it's not there, it's either using the default MVC view in the include folder in conjunction with the metadata layout, or it's using the classic view architecture: index.php (listview), DetailView.php, and EditView.php and templates.
A lot has changed for the better in the last couple years, so I'm not sure the first answer (Nack) is still relevant. It's still pretty rough around the edges, but the new Sugar framework is a PHP hacker's best friend (really easy to override stuff in an upgrade-friendly manner). It's great for companies who happen to already have PHP hackers and only need a few enhancements. And finding affordable PHP contractors to help out isn't that hard (disclaimer: I am one). I think it's a great tool if you're into open source, just need basic CRM and have fewer than 100 users.

tpl is smarty template files. They are used when displaying data on screen. How i do my debuging proces is create a lot of var dumps to error lof or just print them on screen.
Also get xdebug on the server, this will help you a lot. Sugar is mvc platform so get knowing how that works, and will be much easier then.
take a look at some snippets i post at www.eontek.rs

If I encountered the same problem, when the detail page of the account wasn't displayed and gave 500 internal error. I checked that it was not generated by the TPL. At first I checked the permissions on that folder, in my case they were all set. So I took the backup of cache\modules\accounts\DetailView.tpl and manually added the field, after that everything worked. Every time in the developer mode there's a need to manually copy this file. It's a pain, but there's still no answer. I have asked this in forums, Bug, Twitter, no help. By the way, we are using Sugar Professional.

I'd suggest making sure that it really is a code bug and not just a miss config. Are you adding the field through Admin > Studio > Contacts > Fields or through the SOAP API ?
Are you using the latest version of Sugar?
I really agree that the project it horribly under-documented and lacking in tutorials and examples.
I myself am experiencing the pains of outdated / missing documentation.
Good luck!

$this is a reference to the current object.
class Test {
var $tmp;
function __construct() {
$this->tmp = 42;
}
}

Related

Code Hinting custom functions/objects/constants, and on chaining, commentary in Adobe Dreamweaver CS5

In Dreamweaver CS5 there's something called Code Hinting (let's call it CH for short).
CH has a bunch of information about functions, constants and objects built in the core library.
When you press CTRL+SPACEBAR or begin structuring a statement starting with $,
a window with lots of information pops up, giving me the information about it without having to look it up myself. If I press ENTER while the CH is up and something is selected, it will automatically fill in the rest for me.
I love this feature, I really do. Reminds me a little of Intellisense.
It saves me lots of time.
The issues I face, and haven't found any solutions to, are straightforward.
Issue #1 Chained methods do not display a code hint
Since PHP implemented the Classes and Objects, I've been able to chain my methods within classes/objects. Chaining is actually easy, by returning $this (the instance of that class), you can have a continuous chain of calls
class Object_Factory{
public function foo(){
echo "foo";
return $this;
}
public function bar(){
echo "bar";
return $this;
}
}
$objf = new Object_Factory;
//chaining
$objf->foo()
->bar();
Calling them separately shows the CH.
$objf->foo();
$objf->bar();
The problem is that after the first method has been called and I try to chain another method, there's no CH to display the next calls information.
So, here's my first question:
Is there a way, in Dreamweaver CS5, to make the code hints appear on chaining?
Plugins, some settings I haven't found, anything?
if("no") "Could you explain why?";
Issue #2 Code hinting for custom functions, objects and constants
As shown in the first picture, there's a lot of information popping up. In fact, there's a document just like it on the online library. Constants usually have a very small piece of information, such as a number.
In this image, MYSQL_BOTH represents 3.
Here's my second question:
Is it possible to get some information to the CH window for custom functions, objects and constants?
For example, with Intellisense you can use a setup with HTML tags and three slashes ///
///<summary>
///This is test function
///</summary>
public void TestFunction(){
//Do something...
}
Can something similar be done here?
Changing some settings, a plugin, anything?
Update
I thought I'd found something that might be the answer to at least issue #1, but it costs money, and I'm not going to pay for anything until I know it actually does what I want.
Has anyone tried it, or know it won't solve any of the issues?
The search continues...
In case none of these are possible to fix, here's hoping one of the developers notices this question and implements it in an update/new release.
I just switched to NetBeans after 10 years of using Dreamweaver. My impressions may help you. (I'll call them NB and DW respectively from now on)
Code Hints / Documentation
PHP built-in functions
Both DW and NB show all of the built-in PHP functions and constants. A nice feature is that they also provide with a link that opens the related PHP documentation page.
DW is much slower to update the definitions (through sporadic Adobe updates or on the next release) and updating them doesn't look easy (on the other hand, I quickly found the .zip files that NB uses for the PHP/HTML/CSS reference, in case I wanted to manually edit/update them).
However, since documentation can be opened so easily, I do not consider this to be a problem.
Custom functions/classes
This is where NB is clearly better; it instantly learns from your project's code. Hints for function parameters are smart in many cases, suggesting the most likely variable first.
Method chaining works wonderfully, as seen here:
(This would address question #1)
PHPDoc Support
I was greatly impressed with this feature. Take for example the above screenshot. I just typed /** followed by Enter and NB automatically completed the comment with the return type hint (also function parameters if present).
<?php
/**
*
* #return \Object_Factory
*/
public function foo(){
echo "foo";
return $this;
}
?>
Another example:
(This would address question #2)
You can include HTML code as well as some special # tags to your PHPDoc comments to include external links, references, examples, etc.
Debugging tools
Also noteworthy IMHO are the debugging tools included with NB. You can trace all variables (also superglobals!) while you advance step-by-step.
Configuring xDebug is very easy, just uncomment some lines in your php.ini and that's it!
Other stuff
The refactoring (i.e. renaming or safely deleting functions/variables) in NB is really nice. It gives you a very graphically detailed preview of the changes before committing them.
However, the search/replace functions of DW are vastly better. I miss a lot the "search for specific tag with attribute..." function. NB only provides a RegEx search/replace.
NB has a nice color chooser but it almost never suggests it; I thought for a while there wasn't one until I accidentally discovered it. Now I know how to invoke it (CTRL+SPACE, start typing Color chooser and Enter). Very cumbersome, indeed.
I haven't used FTP a lot since I moved to NB, but I have the feeling that DW was also much better, specially for syncing local/remote folders.
NB has really good native support for SVN, Mercurial and Git. When you activate versioning support, you can see every change next to the line number (the green part on my screenshots means those lines are new). I can click on a block and compare/revert those changes, see who originally committed every line (and when), etc.
Even when [team] versioning is deactivated, NB has a built-in local history that helps you recover previous versions as well as deleted files.
Conclusion
Starting with Macromedia Dreamweaver and seeing how it slowly stayed behind the Internet as Adobe struggled to integrate and adapt their products is a painful process. (To this day DW still doesn't render correctly, even with LiveView. To be fair, NB doesn't have a built-in renderer)
Certainly, the Adobe-ization of DW has had its advantages, but this humble programmer was having a hard time justifying a $399 USD ~400MB IDE vs a very comparable free 49MB multi-platform IDE.
After the initial learning curve, I'm very comfortable with NetBeans and I don't think I'll be returning to Dreamweaver any time soon.
I know this doesn't directly answer your questions regarding DW, but I hope it helps anyway.
Use the Site-Specfic Code Hinting feature
Make your own structure, just add the files where your functions, classes, etc. are stored. Save the structure and your done, just worked for me!
I know it is an older question and this is not the complete answer. But it will help someone for sure.
http://tv.adobe.com/watch/learn-dreamweaver-cs5/sitespecific-code-hinting-in-dreamweaver-cs5/
"Use Dreamweaver CS5 to view code hints related to content management
system frameworks such as WordPress, Drupal, and Joomla. Learn how to
set up site-specific code hinting for a CMS so you can easily work
with your PHP website in Dreamweaver. "
for #1, The complication with a scripting language is its not strict typing. The function/method could return null, false, true, int, array, string...
So the 'intellisense' has no type to base a hint off from unless it recompiles it and checks every possible return type.
for #2, the hinting is based off a clip definition file that exists for each version of PHP. With Microsoft products the currents projects (compiled) definitions are added. With PHP there is no compiling, checking or addition to the clip database (automatically). Some like PSPad will give you CodeExplorer that list each function and class in that file, but the only means I know of to get them to show up in hinting is to add it to the cips definition. I don't know where or if its possible in dreamweaver. Zend Studio and others do custom compiling and inclusion.

Is PHP-GTK being used at all today? if yes what is it being used for or can be used for?

I dont seem to see any popular php based tutorial sites ever talking about GDK. Is it even being used? If yes what is it that can be made? the way i see it is I have the ability to build a Linux application with php which is amazing but I honestly don't see what good it can do. Maybe if someone can shine some light on it for its great use?
thanks
I dont seem to see any popular php based tutorial sites
I am afraid it has some truth in it, some very helpful link are these:
Php Gtk Comunity page
http://php-gtk.eu/
Small tutorial
http://zetcode.com/gui/phpgtktutorial/
Sample scripts by widgets (this contains the most!)
http://www.kksou.com/php-gtk2/list-sample-codes-by-widgets/
A few other more specific link I distinguished are:
Php+Gtk+Cairo in Particular
http://zetcode.com/gui/phpgtktutorial/cairo/
I've done a class project on random walk (balls moving around on the screen) in cairo and it is a great library!
Few sample scripts
http://php-gtk.eu/en/gtk/gtkwindow
CairoForPHP Samples
http://fffree.phpws.org/?p=6
PHP-GTK installer for windows (this must be very helpful!)
http://php-gtk.eu/en/apps/php-gtk-installer-for-windows
Is it even being used?
There are a few projects displayed on the community page. I am working my self on a class project on descision support models.
Also I have made a comment here: https://stackoverflow.com/a/4522521/642173 that is somehow relative to your question.
I wish the future will be better for php-gtk, I think it is worth.

Advice on using Wordpress or a PHP Framework?

I am currently building a blog type website for myself. I have used wordpress in the past and really enjoy it, but when it comes to building more than just a blog I usually get bogged down in writing hacks for it.
The site I'm building is going to pretty much be a blog, but with a 'question and answer' side to it (NOT A FORUM - purely Q&A). Therefore, bbPress and buddyPress doesn't quite hit the mark. I have used CI for awhile now, but when it comes to security I fall short. CI does not have an auth library, however, Kohana does.
My question is: I would like to have full control over my site, but I'm worried about my lack of knowledge in the security department. Would I be better off using Wordpress as a base, or would it be beneficial for me in the long run to use something like Kohana?
Your advice is greatly appreciated.
First of all, I would like to say that you can't compare Wordpress and Kohana. One is a content management system and the other is a programming framework.
As for your question: Since you've stated you're not that experienced with security I suggest you stick with Wordpress; It's maintained by developers who know what they're doing.
If you want to go ahead and create something yourself then make sure you keep up-to date with all the current security issues and how to resolve them. Here are a few resources you might be interested in: PHPSEC, OWASP and PHP Security. You should probably read those anyway (as you're writing Wordpress plugins).
Good luck with your choice either way.
Hmm, if you can write the "hacks" for wordpress, than modify it to your needs.
If you think you can write the security better, than use Zend Framework since it has a Auth lib.
http://framework.zend.com/
I dont realy know about kohana
Hmmm... for the Questions and Answers, have a look at Qhub. I'm aboutto implement it for a client of mine who's an adoption counselor. She gets tons of questions via emails and it's always the same ones over and over. I saw it on Design Reviver a while back and I thought it was a great idea. Plus I got in contact with one of the co-founders of Qhub and they told me that they are implementing some more privacy and privileges controls which is really good news since I only want my client to be able to answer the questions.
I would use WP with Qhub to be honest. If it's a blog-type site and you're already comfortable with WP, why not stick with it?
Hope this helps!
Check out the TDO Mini Forms plugin. I think it may serve your needs perfectly!

Best place to get PHP generic code examples

Aside from the PEAR repository, which I find often has quite messy code with a lot of it using old or deprecated methods and techniques, I was wondering if there was a great place to find simple (and not so simple) PHP examples of some generic functions and good pieces that people have written.
A good example would be the PEAR spreadsheet module I used a while back. The thing worked but it was written quite messily and if I remember correctly, in PHP 4.
I'd like to find something with well written and well documented code that I can refer to and see exactly how people are doing things and why they are doing things that way.
The PHP manual's as good a place to start as any, I've particularly found some of the comments on there helpful.
There's also The PHP Resource Index, which is mostly a jumping off point to other projects' websites.
Don't forget to look at questions tagged PHP on stackoverflow.
Have a look at PHP Classes. They have a large selection of classes, all with user ratings.
There's also Zend Framework spesific ZF Snippets site
Github is another good resource, more often than not it is polished code that is updated frequently.
Getting classes from other people is all well and good but keep upgrade-ability in mind, if i'm using someone else's class and need to tweek it i always extend from it.

How do we get coders to look up existing functions before writing their own?

Why are so many people still writing crappy versions of things in standard libraries? Not to go after PHP developers, but guys go read the PHP SPL
Peer review can help catch that kind of thing. If you have another developer looking at the code, and they continually find implementations of standard library methods, it should fail the review unless there's a good reason for reinventing the wheel.
Young, ambitious programmers like to solve every problem on their own. They don't need no stinkin' libraries. Older, lazy programmers would rather search for existing solutions to the problem at hand.
So my advice: the next time you hire a programmer, choose the old guy who falls asleep in the reception area.
Just kidding, mostly. Peer review and education is the answer.
Better search techniques. and Domain Specific Familiarity
How does a developer check for a function they dont know the name of? Or perhaps there isnt an EXACT built in function to do what they want, but something they can use to save a lot of code. You need to be able to find the right terminology for the problem at hand, and from there you know what to search for. This is best achived by reading topics specific to your problem domain. Get away from coding specific resources and spend sometime in the field which you are coding for... wether it be retail, medical, insurance, etc.
Summary: Assumption is the mother of all FUBARs
I see this a lot from colleagues who are unfamiliar with the concept of frameworks (god how they complain about "two languages in one"), to wit: old C++ guys suddenly confronted with C# diving in head first to recreate hashtables from scratch...
Clearly a big part of this phenomenon from that angle is not stepping out of old mindsets and habits. If you're in a new environment you need to learn the new rules. The only way to deal with that from the outside looking in is to provide training, whether that's pair-programming for a while or something more formal.
Lack of familiarity with your tools breeds the contempt of others.
A simple coding style document might help by reminding the devs that there are libraries available (maybe list some preferred) and that they should be familiar with them.
Sometimes, you just have to remind people.
A peer review would help.
PHP is well documented if and only if, you know exactly what you're looking for. For example, you'd open Arrays and Array functions sections to see what you can do with arrays. And guess what, there is not even mention of SPL.
You should also encourage research before actually setting out on writing code. I usually approach problems by thinking about a way to do it, then I try to find anything in the standard library or any other libraries that will help me out. I'd say that an hour of research in some cases can be worth days of coding.
If people aren't doing this, it may be a good idea to have someone ask them questions about their general approach to the problem and what library functions/classes they are thinking about using. If they're missing something obvious, suggest it to them.
Two reasons pop to mind quickly. First, the Standard PHP Library isn't WELL known, and suffers from poor documentation. The php.net website is widely considered the language's best asset, but a lot of the newer built in classes (such as the SPL, reflection API, DomDocument, etc.) are little more than a list of methods without a lot of context.
More importantly though, it looks like the full SPL never shipped by default with any version of PHP prior to the (unreleased) 5.3. This is a killer as far as adoption goes. Usually people writing PHP code don't have control over what gets complied into their PHP binary. That's handled by their web-host and/or operations team, and web hosts and/or operations teams have different goals than a developer and aren't going to install every optional extension that comes along. This also means projects like Drupal, Joomla, Wordpress, etc. can't rely on the SPL being installed everywhere, so they don't use it.
Part of the reason PHP "won out" over perl was a single install had everything you ever needed. Optional extensions have never become widely adopted until they became part of the base install.
Very hard question to answer. Obviously peer review helps, but also proper documentation. Do your projects have technical specs, where you map out the classes and intefaces to be created?
If so, someone else on the team should review the specs and point out where existing code could be used...
Agree with training and peer review, but also enforcing unit testing and code documentation should help with the NIH syndrome :)

Categories