CXDev Toolbox - PHP Stub Generator

The PHP Stub Generator is a developer centric tool that enables IDE code completion for the RightNow ConnectPHP API. The tool uses information from your site to create a PHP stub file with PHPDoc comments for every Standard Object, Custom Business Object and Custom Field on your CX site. When the PHP stub file is added to an IDE that supports PHPDoc's (Netbeans, Eclipse, etc), ConnectPHP classes and methods are included in the IDE's code completion functionality.

This tool is part of the CXDev Toolbox, an extensible platform for tools and utilities that support the management, maintenance and development of an Oracle RightNow CX site. Toolbox utilities and tools provide features to System Administrators and Developers that are either missing from the core Oracle RightNow CX platform or only possible through a lengthy custom development effort.

Generate the PHP Stub File

Access Tool and Authenticate

Open the CXDev Toolbox and select the "PHP Stub Generator" component from the component bar. Inside of the Toolbox, authenticate to your site using a Staff Account that has WebDAV upload permissions. Once authenticated, select the "Generate Stubs" button.

Generate Stub File

When you click "Generate Stubs", the tool will upload a PHP file to you Customer Portal site, execute the file, capture the output, and finally remove the file from Customer Portal. This file uses PHP reflection to build a PHP stub that contains information about all of your Custom Business Objects and Custom Fields.

Save Stub File

Once the PHP Stub is generated, it is displayed in the right-hand panel of the Toolbox. In order to use this PHP Stub with your IDE, you will need to save it to disk. Click the "Save" button and save the PHP Stub somewhere accessible to your IDE.

Use the PHP Stub with an IDE

We use Netbeans for most of our Customer Portal development; the following steps will focus using the PHP Stub file in this IDE. The steps should be fairly similar for Eclipse and other compatible IDEs.

Open a project with Customer Portal files

In Netbeans, create or open a project that contains your RightNow Customer Portal files.

Access Project Properties

In the "Projects" explorer, find the "Includes" folder, right-click, then select "Properties".

Add Folder w/ PHP Stub file

In the properties dialog, click "Add Folder" and select the folder where you saved the PHP Stub file.

Select the folder and click "Open".

Select "OK" to close the properties dialog.

If done properly, when you expand the Include's folder you should see the PHP Stub file

Open any PHP file and test Code Completion for ConnectPHP

Open any PHP file in the project; I've chosen to use the ajaxCustom.php controller file, but any .php file will work.

Begin typing any ConnectPHP variable name (with or without namespace) and observe that your IDE lists potential matches.

Create a new Incident and then try accessing the Incident object properties. See how your IDE now knows all of the available props and their types?

Next, try accessing your Custom Fields or Custom Attributes. Notice how they are all there! Note: If you add new Custom Fields, Custom Attributes, or CBO's you will need to regenerate the PHP Stub file.

Finally, try accessing a property that is a NamedID type. Notice how the PHP Stub includes a listing of valid ID's and their Lookup Names.

Conclusion

We've been using this tool internally for a while and have found that it speeds up our development times significantly. It works really well in Netbeans 7 and 8, but theoretically works in any IDE that supports code completion and PHPDocs. There are some known limitations due to the way that RightNow built the ConnectPHP API, but these are minor things. For example, we are unable to provide a listing of method parameters for RNObject methods such as "first()", "save()", or "find()". For these you will just have to rely upon the published documentation.

We'd love to hear how well this works in other IDE's; add your experience to the comments section of this posting.

To download the CXDev Toolbox visit http://toolbox.cxdeveloper.com

Categories : 

Comments

Superb tool, helps a ton!. Thanks.

First, thank you for sharing this guide. It's really great tools!!!

I used it before but now I'm having problems: failed to query webdav root folder.

We had the DB overwrite from other env, should I change something to get this working again?

Thanks and best regards.

Brunno

Hey guys, I was able to solve the issue. It's was related to CP permissions on the profile settings.

Regards,

Great, thanks for posting the resolution!

The Stub is a great thing for developers. Thanks a lot. I havea query, how can I upload a custom script directly from NetBeans? or from any other IDE?

For Customer Portal files, they are only accessible over WebDAV. As far as I know, Netbeans does not have a WebDAV plugin. Personally, I manually upload my files through a stand alone WebDAV program; I use Transmit, which is a Mac-only app.

The other quasi automatic solutions I've found for Netbeans is the use of the "Copy files from Source Folder to another location" project configuration feature. With this method, you have to have a program that can mount a WebDAV share as a local disk. I know that WebDrive for windows can do this. I've found it a little unreliable, so I don't use this method anymore and instead just do manual pushes.

There may be other options in other IDE's

Thanks alot andy for your time.

I'm having problems: failed to query webdav root folder

What CX site version are you using? Is it CP2 or CP3?

I am using rightnow agend desktop

Hi

I've used this tool before to great success, but I'm trying it today and it's only returning the HTML for the login page. Is there a way to ensure that it doesn't require login?

David Lumm - https://www.linkedin.com/in/davidlumm
Contract Developer

Hi David,
What OSvC site version and toolbox version are you using? I can't think of anything that would cause this except maybe if you didn't have the CP Edit permission enabled on your profile. My best guess is that there is something specific on your site's configuration that is causing this. I was unable to reproduce using a 18B site with the latest version of the toolbox (v18.11.13.7).

Do you have any pre-controller hooks enabled on your site (config/hooks.php)?

AR

We have a pretty weird setup, we're on 18A but still using CP2. Part of my job is to try and get switched over to CP3, it's taking a while to migrate some of our customisations, but that's by-the-by.

Toolbox is 2.5.1.2, by what I can see on the about box.

We do have a pre page render hook, but I don't think that looks like it should be interfering.

Is there any log I can send you to show what's happening?

David Lumm - https://www.linkedin.com/in/davidlumm
Contract Developer

Hi David,
Start by updating to the new version of the toolbox. It is installed now via the Windows Store. https://www.microsoft.com/en-us/p/cxdev-toolbox/9nwx4g2h5znc?activetab=pivot:overviewtab

The pre-page render hook should not interfere. Is there any other code in the hooks.php file outside of a hook registrations? Perhaps something that is doing a security check and a redirect?

I don't think we log anything that would be helpful with the stub generator. Can you email me a screenshot of the login page to andy@45n.co

Ah, I'm still on Windows 7 (corporate machine). I'll just soldier on without the stubs at the moment. I'll still send you a screenshot of the login page, for reference.

David Lumm - https://www.linkedin.com/in/davidlumm
Contract Developer

Zircon - This is a contributing Drupal Theme
Design by WeebPal.