Introducing apostrophePollPlugin

31 views
Skip to first unread message

Raffaele Bolliger

unread,
May 13, 2012, 4:07:13 PM5/13/12
to apostr...@googlegroups.com
Hi all,

after a few weeks of work, I would like to introduce a new plugin called apostrophePollPlugin.

The goal of the plugin is to provide support for publishing forms in Apostrophe CMS websites.

The plugin provides a structured workflow, which includes:
- form publication via a slot
- form submission management and data storage
- an admin module to manage the form publication
- an admin module to manage user-submitted answers

The plugin is very flexible and accepts a high degree of customization, both in forms appearance and data management. A dedicated configuration syntax is provided.

If you are interested, you can find the code on gitHub (https://github.com/rbolliger/apostrophePollPlugin). A documentation is also available (https://github.com/rbolliger/apostrophePollPlugin/wiki).

The plugin is in alpha state since it requires a deeper testing phase. I would be glad to receive some feedback, both on code and on the documentation. I am sorry, english is not my mother tongue and the documentation certainly deserves some improvements.

Thank you,

Raffaele

Geoff DiMasi

unread,
May 13, 2012, 5:25:47 PM5/13/12
to apostr...@googlegroups.com
Very exciting. Can't wait to try it out.

-------------------------
Geoff DiMasi
ge...@punkave.com
215 755 1330

On May 13, 2012, at 4:07 PM, Raffaele Bolliger

colin

unread,
May 14, 2012, 6:28:56 AM5/14/12
to apostr...@googlegroups.com
Hi,

I tried to try it out, but can't get the plugin to work.
After trying to update the database I end up with this error.

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'a5.poll_id' in 'field list'

Raffaele Bolliger

unread,
May 14, 2012, 6:54:52 AM5/14/12
to apostr...@googlegroups.com
Hi Colin,

this looks quite strange. In my project I run "doctrine:build --all-classes --and-migrate" to build the DB. How did you built your DB? Which page are you loading when you get the error message?

The error message is probably due to the fact that my plugin creates a a_poll_slot table which inherits from the a_slot table. My table adds a a poll_id field. This shouldn't be a problem, but maybe the inheritance mechanism is creating the problem.

Let me know if you solve the problem and I will update the doc with your instructions.

Raffaele

colin

unread,
May 14, 2012, 7:07:10 AM5/14/12
to apostr...@googlegroups.com
Hi Raffaele,

I Just did the steps for doctrine seperatly, but I also tried it with doctrine:build --all-classes --and-migrate but ended up with the same error.
your plugin in my case added a_poll_answer, a_poll_answer_field, a_poll_poll, a_poll_poll_translation tables. Thats all...???

Colin

Raffaele Bolliger

unread,
May 14, 2012, 7:35:07 AM5/14/12
to apostr...@googlegroups.com
The plugin creates the following tables:

- a_poll_slot
- a_poll_poll
- a_poll_poll_translation
- a_poll_answer
- a_poll_answer_field

You did not cite a_poll_slot, probably because of the error. Is the error happening while building the model?

I tried to create a fresh install. I downloaded the apostrophe sandbox and my plugin. I followed the installation guides (apostrophe and my plugin), rebuilt the model and I did not get any error message.

I updated the installation guide with a few additional steps. Maybe they will help you.

Raffaele

colin

unread,
May 14, 2012, 8:00:11 AM5/14/12
to apostr...@googlegroups.com, Raffaele Bolliger
you did a lil typo here
standard_area_slots:
            ...
            -aPoll (schoud be "- aPoll")
            ...

Just for those who dont know...

Raffaele Bolliger

unread,
May 14, 2012, 8:27:00 AM5/14/12
to apostr...@googlegroups.com, Raffaele Bolliger
You are right. Fixed.

Thank you.

Does the plugin works now?

colin

unread,
May 14, 2012, 8:44:18 AM5/14/12
to apostr...@googlegroups.com
Hi Raffaele,

I did the same:
cloned the svn rep to a new testbase
followed your instruction
but doctrine:build --all-classes --and-migrate did not create any tables.

Raffaele Bolliger

unread,
May 14, 2012, 8:46:13 AM5/14/12
to apostr...@googlegroups.com
With the fresh install i ran:
./symfony doctrine:build --all
./symfony doctrine:data-load

colin

unread,
May 14, 2012, 8:50:39 AM5/14/12
to apostr...@googlegroups.com
Ok it is working!
But doesnt doctrine:build --all destroy all previously stored data, wich would be not so fine for a non fresh install?

colin

unread,
May 14, 2012, 8:55:29 AM5/14/12
to apostr...@googlegroups.com
Preview a Poll produces

Fatal error: Class 'sfWidgetFormReCaptcha' not found in /home/efelo/workspace/testbase/plugins/apostrophePollPlugin/lib/widget/aPollWidgetFormReCaptcha.class.php

So maybe sfFormExtraPlugin is not optional???


Am 14.05.2012 14:46, schrieb Raffaele Bolliger:

Raffaele Bolliger

unread,
May 14, 2012, 8:58:36 AM5/14/12
to apostr...@googlegroups.com
Exactly, this is why I use migrations. If all your data are stored in fixtures (which is normally not the case with CMSes), you could reload everything after a build:all.

The best would be to learn how to work with migrations. Have a look at the doctrine doc or at this article. Anyways, if you plan to deploy your website using apostrophe tools, they will call doctrine:migrate to sync the code.

Raffaele Bolliger

unread,
May 14, 2012, 9:00:56 AM5/14/12
to apostr...@googlegroups.com
sfFormExtraPlugin is optional IF you replace the aPollWidgetFormReCaptcha with another captcha or if you deactivate captcha display in the config. Maybe I should explain that in the doc.

Thank you for the remark.

Raffaele

colin

unread,
May 14, 2012, 9:03:46 AM5/14/12
to apostr...@googlegroups.com
Thanks for the link!

Or just provide the plugin with deactivated captcha as default so that the plugin work fine without errors. If you than want a captcha you can enhance by installing the sfFormExtraPlugin (wich I did, and it left the error away)

Colin

Raffaele Bolliger

unread,
May 14, 2012, 9:21:35 AM5/14/12
to apostr...@googlegroups.com
Thanks for the suggestion.

To ease the plugin installation it would probably be better to deactivate the captcha. But, from a security point of view (and to show the features of the plugin), it may be better to let it turned on.

Maybe it would be interesting to know the opinion of other people. Shall we publish a poll about the toipc? ;)

Raffaele
Raffaele Bolliger
Rue Guillaume-Triponez 19
CH - 2336 Les Bois
Tél. 032/961.15.25

colin

unread,
May 14, 2012, 12:09:48 PM5/14/12
to apostr...@googlegroups.com
But you should mention the error that will apear when you haven't installed sfFormExtra (wich your documentation said is optional) in your documentation.

Unless all that I need to say that you did a great Job with your Plugin and your documentation is much better than most of the other plugin documentations are.
Very Nice.

Colin

Tom Boutell

unread,
May 14, 2012, 12:21:03 PM5/14/12
to apostr...@googlegroups.com
Raffaele, thanks for creating the plugin, which I look forward to checking out!

There is a better way to handle migrations for Apostrophe plugins.
Doctrine migrations are not really set up for that, you have to do
things in a very picky order for Doctrine migrations to spot plugin
changes and even if you do it can easily go wrong.

Instead, you want to catch the a.migrateSchemaAdditions event and do
your migrations there via aMysql. This event comes from the
apostrophe:migrate task which is the officially encouraged way to do
migrations at the plugin level for Apostrophe. (You can use it at the
project level too although that works okay with Doctrine migrations.)

Take a look at this code:

class apostropheWorkflowPluginConfiguration extends sfPluginConfiguration
{
static $registered = false;
public function initialize()
{
// Yes, this can get called twice. This is Fabien's workaround:
// http://trac.symfony-project.org/ticket/8026
if (!self::$registered)
{
$this->dispatcher->connect('a.migrateSchemaAdditions',
array($this, 'migrate'));
self::$registered = true;
}
}

And here's the migrate method:

public function migrate($event)
{
$migrate = $event->getSubject();
if (!$migrate->columnExists('a_area', 'draft_version'))
{
$migrate->sql(array('ALTER TABLE a_area ADD COLUMN draft_version
BIGINT DEFAULT NULL'));
}
}

There is also a tableExists() method, etc. in the aMigrate class.

Be aware that your migrations MUST be safe to run more than once. They
must use tableExists and columnExists to determine what is already in
the schema rather than crashing with an error if the migration has
been carried out before. This simple solution avoids some serious
chicken and egg problems that come up when you try to track migrations
the Doctrine way.

You can use doctrine:build --sql to generate the SQL statements and
then go copy and paste them from data/sql/schema.db.sql or use them as
a guide for things like ALTER TABLE statements.

When you follow this approach other developers can painlessly add your
plugin to an existing project. Our recommended deployment process
(apostrophe:deploy) knows to run apostrophe:migrate on your staging
and production servers, for instance.
--
Tom Boutell
P'unk Avenue
215 755 1330
punkave.com
window.punkave.com

Raffaele Bolliger

unread,
May 14, 2012, 12:33:09 PM5/14/12
to apostr...@googlegroups.com
Thank you Tom for your answer.

So, if I understand well, I should create a migration function in my plugin.

Then, a developer willing to install the plugin will simply run apostrophe:migrate and the DB will be updated without problems. Right?

Raffaele

Tom Boutell

unread,
May 14, 2012, 1:35:10 PM5/14/12
to apostr...@googlegroups.com
That's correct. Your function must use the aMigrate API like my
example does. Make sure you test this, removing the relevant columns
and/or tables and trying it to ensure it corrects them, and also
trying it to ensure it does no harm when they are already there.

Raffaele Bolliger

unread,
May 14, 2012, 3:29:14 PM5/14/12
to apostr...@googlegroups.com
OK, done.  Tested on a fresh install and on my project. Does not harm and creates the right tables and columns.


On Monday, May 14, 2012 7:35:10 PM UTC+2, Tom Boutell wrote:
That's correct. Your function must use the aMigrate API like my
example does. Make sure you test this, removing the relevant columns
and/or tables and trying it to ensure it corrects them, and also
trying it to ensure it does no harm when they are already there.

On Mon, May 14, 2012 at 12:33 PM, Raffaele Bolliger

Tom Boutell

unread,
May 14, 2012, 4:47:16 PM5/14/12
to apostr...@googlegroups.com
Great! That should make it much easier for people to snap your plugin
into their projects.
Reply all
Reply to author
Forward
0 new messages