Archive for the ‘Technical Jargon’ Category

Ants in my Zend Framework (with doctrine for good measure)

Wednesday, July 15th, 2009

I’m starting to use Zend Framework 1.8.4 with Doctrine Object Relational Mapper (because after working on a java/hibernate project, I can’t go back to writing SQL and building databases)  With Doctrine ORM, you can define a data model in YAML or XML and it will build the database with foreign keys, etc, etc ,etc… learn more on that here.

On starting my project, I looked around to see what everyone else was doing.  Since 1.8.4 is relatively new, and there were some pretty neat changes, there aren’t many good tutorials out there.

That being said, and because of said java/hibernate project I’ve been working on, I’ve become quite familiar with Apache Ant.  It’s basically an easy way to do some of the mundane work and sometimes heavy lifting in day to day programming.  That, and I use Eclipse IDE, so wasn’t too fond of always running to the command prompt to rebuild my models, create a zend module, etc.

So here’s what I’ve come up with.

I started with this tutorial: Doctrine ORM and Zend Framework It shows you how to create a Zend 1.8.4 project with doctrine.  The key aspect is the doctrine-cli.php script.

I should let you know, while I do use Eclipse for most of my projects, a while back I bought Zend Studio for Eclipse. I think it’s much better for writing PHP than any plugin for eclipse (PDT, PHPEclipse).  If you write a lot of PHP, ZS4E is very very worth the money.  While it does say it is “zend studio for eclipse”, it installs its own installation of eclipse.  If you find yourself in this boat, and want to use Ant in Zend Studio for Eclipse, check out this tutorial.  It’s rather screwy that you can’t install ant tools easily, but this definitely does the trick.

But I digress… let’s get started.

Here is the directory structure of my project, basically defined by the above tutorial:

- root
-  htdocs [zend framework project root]
    - application
        - [all application folders]
        - doctrine
    - library
    - public
    - scripts
    - test
-  .project
-  build.xml
-  env.properties

The body of env.properties looks like this:

zf.project.basedir=htdocs
doctrine.scripts.path=${zf.project.basedir}/scripts

And the body of the build.xml looks like this:

<project name="zf-doctrine-project">
     <property file="env.properties" />
     <target name="doctrine.cli" description="Run a doctrine task on doctrine-cli.php - default reload">
          <input message="Enter a task:"
               addproperty="doctrine.task"
               defaultvalue="build-all-reload" />
          <fail unless="doctrine.task" message="No task selected" />
          <exec dir="${doctrine.scripts.path}"
               command="php doctrine-cli.php ${doctrine.task} y"/>
     </target>
</project>

Although it’s painfully self-explanatory, for the sake of completeness, here’s what it does, line by line:

2.  Loads in the env.properties file
3.  Defines the target, which is like a job/task in ant
4. – 6.  Prompts the user to enter a task to pass to the cli script (just like you would pass in the command line)
7.  Makes sure the user enters a value
8. – 9. Executes the php script, passing in the entered task as a command line option, and forces yes to “are you sure?”

Now, the fun part.

In your project in Eclipse, open the ant window by going to Window > Show View > Other and select Ant under the Ant folder.  When you see the Ant View, either open your ant file in that window using it’s open dialog, or just drag your build.xml to that panel.  You’ll see the little white file with the ant on it and whatever you have as the name attribute of the <project> tag in your build xml.  Expand that so you can see the targets, and you should see this:

Showing the doctrine task in the eclipse ant view

Showing the doctrine task in the eclipse ant view

Now if you double click that target, you should see a prompt for the task you want to run.  The default value there will run your schema.yml and rebuild your db and models.

Crafty kids may notice that i have the “Hide internal targets button” turned on in that image… well, those targets are for another show…  (damn you crafty kids…)

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Granite SecureAMFChannel – AMF over HTTPS

Sunday, March 15th, 2009

At work we’ve started to use JBoss, writing an application in Java and AS 3.0.  We’re using Seam and Tide to sandwich it all together, and we came upon a slight problem.  Everything worked out great in the test environment, but when we went live, on an HTTPS connection, firebug was reporting that the AMF request out of flex was failing.  That’s due to the services-config.xml in the application pointing to a non-secure connection.  After much digging, we found this to be the solution.

WEB-INF/flex/services-config.xml
in the channels definition at the top:

<channels>
    <!--USED IN THE LIVE ENVIRONMENT-->
          <!--channel ref="my-graniteamf-secure"/-->
    <!--USED IN THE LOCAL/DEV ENVIRONMENT-->
          <channel ref="my-graniteamf"/>
</channels>

Then in the channel definition below we have both definitions:

<channel-definition id="my-graniteamf"
	class="mx.messaging.channels.AMFChannel">
	<endpoint
		uri="http://{server.name}:{server.port}/{context.root}/graniteamf/amf"
		class="flex.messaging.endpoints.AMFEndpoint" />
</channel-definition>
<channel-definition id="my-graniteamf-secure"
	class="mx.messaging.channels.SecureAMFChannel">
	<endpoint
		uri="https://{server.name}:443/{context.root}/graniteamf/amf"
		class="flex.messaging.endpoints.SecureAMFEndpoint" />
</channel-definition>

Click Here to Download: services-config.xml

We couldn’t get {server.port} to work correctly, so we’re forcing the port in the address for now.

The only problem with this is you have to remember to switch the AMF channel before deploying.  It’s on our checklist before doing the full deploy, but we’re most likely going to add it to the ant task list to deploy dev, deploy live.  Something like that.

The KEY THING TO REMEMBER is this: although this file is deployed with the war/ear, it is ALSO COMPILED INTO THE APPLICATION SWF when it is built.  Make sure to change it locally and rebuild your swf before posting, or you will see no change in your app. (found this out after a significant amount of time changing the file on the server to no avail…)

(Ref: http://www.mail-archive.com/discussion@affug.com/msg00605.html)
[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Subversion Update Builder – Learning Python

Saturday, September 6th, 2008

Ok, so I’m back.  It’s been a while.

I’ve decided I would like to jump on the Python bandwagon.  I’ve been living the Ubuntu life for a while now, so I figured I should make myself at home…

Whenever I learn a new language, I need a pet project.  I’m not one that can learn just by doing a Hello World, so I came up with this idea.

At work, I deal mainly with kiosks in the field.  They leave the factory and exist in a Toys R’ Us, Walmart, even BMW showrooms (check my company:  http://www.realityi.com).  When they go out, they have a certain version of content on them.  By content, I mean usually .swf, .xml, etc.  These are files that can easily be updated and are in a predictable file structure (seeming as I made it).  We’ve begun to finally use version control, using subversion as our drug of choice.  After much googling, I wasn’t able to find a viable way to create an update package.  It seems that most applications of subversion are connected and can use rsync/svn checkout to get the most update to date content, but machines in my situation are either completely disconnected and updated via USB, or connected to a network but behind a hefty firewall (eg: bmw).

What I needed was a way to find what files have been added or modified between a certain revision and the current content to build an update package (no removals, tell you why in a second).

Enter: SVNUpdateBuilder

SVNUpdateBuilderI’ve taken on a small, linux-based (for now) project that does just what I need.  It uses the pysvn library, and creates a .tgz file with a directory tree of files that have been added or modified.  I’m learning how to use Python, but also Glade User Interface Builder to create a GTK application.  Check out the website for more information.

You may be asking: “Why is it a compiled python file?”  Well, I’ll tell you.  This is still my learning tool.  I have a few more items on my wishlist that I want to complete before I release it to the masses.  Like I said on the website, this isn’t a difficult project for someone more skilled than I to build, but I would like to be selfish with it until I figure I’ve learned all I care to.  Then I definitely plan to release it on Sourceforge.

You may also be asking “What about files that have been removed?”  In my line of work, with how fickle clients are, it’s better, for now, for us to leave content on the machines and just remove the link to the file in the xml (read: send a modified file).  That way, if a client wants a video relinked on a kiosk, we just have to relink it, not send it out again.  Disk space, for this current project, isn’t a concern as much as bandwidth, so we chose to leave the files out there.  Plans for this project include having output methods for bash scripts or batch files to clean up the target machine, but they haven’t been implemented yet.

So, I will continue to code…  I’ll keep you posted.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

sproif.com is Digg proof thanks to caching by WP Super Cache!