Home » plugins » User management plugins » sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
| sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail [message #92774] |
Tue, 02 February 2010 20:41  |
stephenrs Messages: 22 Registered: January 2010 |
Junior Member |
|
|
I had some problems getting sfDoctrineApplyPlugin to work - mostly because of some gaps in the documentation and weirdness in the code - so I decided to document what I did to make it work, in case anyone else is having trouble. Also, this solution uses Symfony's bundled mailer (SwiftMailer), so you don't have to install anything from Zend...which seems to make a little more sense to me...
This solution has been tested with Symfony1.4.1 and sfDoctrineApplyPlugin1.1.0. I'm sure it can be improved further but this has worked for me:
1. Installation
Since the plugin's readme says much about how to install Zend_Mailer, and nothing about how to install the plugin itself (and I couldn't find any combination of ./symfony plugin:install... that would fetch the plugin and install it) - and if you're not used to installing plugins manually, try this:
- Download the plugin from the plugins page ( http://www.symfony-project.org/plugins/sfDoctrineApplyPlugin)
- Unpack the archive, and copy the plugin directory to your project's /plugins directory (I called mine sfDoctrineApplyPlugin, removing the version "-1.1.0" from the directory name)
- Important: add this line to the setup() method of your /config/ProjectConfiguration.class.php:
$this->enablePlugins('sfDoctrineApplyPlugin');
2. Configuration
The readme will tell you to put the following in your doctrine/schema.yml:
sfGuardUserProfile:
tableName: sf_guard_user_profile
columns:
id:
type: integer(4)
primary: true
autoincrement: true
user_id:
type: integer(4)
notnull: true
email:
type: string(80)
fullname:
type: string(80)
validate:
type: string(17)
...etc...
If you're using the latest version of sfDoctrineGuard, then the above entries in your schema.yml will produce SQL errors when you run your next symfony doctrine:build..., and your foreign key won't work. To fix this, replace the above with the following:
sfGuardUserProfile:
tableName: sf_guard_user_profile
columns:
id:
type: integer(20)
primary: true
autoincrement: true
user_id:
type: integer(20)
notnull: true
email:
type: string(80)
fullname:
type: string(80)
validate:
type: string(17)
Notice the type definitions for id and user_id in the lines above. The user_id type is the most important, because in a foreign key relationship, the columns involved in the relation must have types that match exactly. The user(id) column of sf_guard_user is a BIGINT (integer(20)), so the foreign key user_id must also be a BIGINT. I've also made sf_guard_user_profile(id) an integer(20) so that my system can have as many profiles as users.
3. Getting rid of Zend_Mailer
To do this, you need to override 2 of sfApply's methods. Create a module called sfApply in your application, and put this in the .../modules/sfApply/actions/actions.class.php:
require_once(sfConfig::get('sf_plugins_dir').'/sfDoctrineApplyPlugin/modules/sfApply/lib/BasesfApplyActions.class.php');
class sfApplyActions extends BasesfApplyActions
{
public function executeApply(sfRequest $request)
{
$this->form = $this->newForm('sfApplyApplyForm');
if ($request->isMethod('post'))
{
$this->form->bind($request->getParameter('sfApplyApply'));
if ($this->form->isValid())
{
$guid = "n" . self::createGuid();
$this->form->setValidate($guid);
$this->form->save();
try
{
$profile = $this->form->getObject();
$this->mail(array('subject' => sfConfig::get('app_sfApplyPlugin_apply_subject',
sfContext::getInstance()->getI18N()->__("Please verify your account on %1%", array('%1%' => $this->getRequest()->getHost()))),
'fullname' => $profile->getFullname(),
'email' => $profile->getEmail(),
'parameters' => array('fullname' => $profile->getFullname(), 'validate' => $profile->getValidate()),
'text' => 'sfApply/sendValidateNewText',
'html' => 'sfApply/sendValidateNew'));
return 'After';
}
catch (Exception $e)
{
//$mailer->disconnect();
$profile = $this->form->getObject();
$user = $profile->getUser();
$user->delete();
// You could re-throw $e here if you want to
// make it available for debugging purposes
return 'MailerError';
}
}
}
}
protected function mail($options) {
$required = array('subject', 'parameters', 'email', 'fullname', 'html', 'text');
foreach ($required as $option)
{
if (!isset($options[$option]))
{
throw new sfException("Required option $option not supplied to sfApply::mail");
}
}
$message = $this->getMailer()->compose();
$message->setSubject($options['subject']);
// Render message parts
$message->setBody($this->getPartial($options['html'], $options['parameters']), 'text/html');
$message->addPart($this->getPartial($options['text'], $options['parameters']), 'text/plain');
$address = $this->getFromAddress();
$message->setFrom(array($address['email'] => $address['fullname']));
$message->setTo(array($options['email'] => $options['fullname']));
$this->getMailer()->send($message);
}
}
This snippet overrides the mail() method to replace Zend_Mailer with the built-in SwifMailer.
It also overrides the executeApply method, simply commenting out the line that says:
...because this line will always generate a PHP fatal error...$mailer is never defined...
You may also need to configure SwiftMailer to handle outbound mail, depending on your server environment. The JoeBeet tutorial (http://www.symfony-project.org/jobeet/1_4/Doctrine/en/16) is an excellent source of info on how to do this. For reference, I'm using a gmail account for sending mail, and the relevant section of my factories.yml file looks like this:
all:
mailer:
class: sfMailer
param:
logging: %SF_LOGGING_ENABLED%
charset: %SF_CHARSET%
delivery_strategy: realtime
transport:
class: Swift_SmtpTransport
param:
host: smtp.gmail.com
port: 465
encryption: ssl
username: your.username@gmail.com
password: your.password
As I mentioned, this setup is working for me - so I hope this helps someone. Better yet, I hope the authors are inspired to update the docs, clean up the plugin, and remove the unnecessary dependency to Zend_Mailer.
Happy coding!
|
|
|
 |
sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
|
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
|
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
|
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
|
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
|
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
|
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
|
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
|
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Mon, 01 March 2010 14:43 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: nwahs81 on Wed, 24 February 2010 14:25 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: NeoX on Tue, 04 May 2010 19:15 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Tue, 04 May 2010 20:13 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: nwahs81 on Wed, 24 February 2010 14:57 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
|
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Thu, 25 February 2010 23:51 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
|
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Mon, 01 March 2010 16:52 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Mon, 01 March 2010 22:53 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
|
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
|
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Thu, 04 March 2010 21:43 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Wed, 10 March 2010 23:15 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Thu, 11 March 2010 22:26 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: lukyanov on Mon, 29 March 2010 20:58 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Mon, 29 March 2010 21:43 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: sela on Sat, 03 April 2010 21:57 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Sun, 04 April 2010 00:14 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: sela on Mon, 05 April 2010 10:41 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Mon, 05 April 2010 13:10 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
|
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Fri, 12 March 2010 19:54 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Mon, 15 March 2010 22:51 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
|
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
|
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
|
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
|
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Tue, 16 March 2010 08:18 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: tnaseem on Thu, 18 March 2010 10:07 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: tnaseem on Thu, 18 March 2010 10:13 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Thu, 18 March 2010 12:16 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: tnaseem on Thu, 18 March 2010 12:28 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Thu, 18 March 2010 22:33 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: tnaseem on Thu, 18 March 2010 23:39 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Fri, 19 March 2010 19:54 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: sela on Wed, 24 March 2010 13:44 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Wed, 24 March 2010 17:44 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: sela on Wed, 24 March 2010 17:50 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Wed, 24 March 2010 18:32 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: sela on Wed, 24 March 2010 18:43 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Wed, 24 March 2010 20:16 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: sela on Wed, 24 March 2010 22:19 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Wed, 24 March 2010 22:38 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: sela on Thu, 25 March 2010 10:59 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: sela on Mon, 05 April 2010 20:02 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Mon, 05 April 2010 20:57 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: sela on Mon, 05 April 2010 21:26 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Mon, 05 April 2010 22:40 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: sela on Wed, 07 April 2010 10:49 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Wed, 07 April 2010 21:27 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: sela on Wed, 07 April 2010 21:34 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Wed, 07 April 2010 22:09 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: sela on Wed, 07 April 2010 22:49 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
|
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Thu, 08 April 2010 18:06 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: ringhio on Thu, 08 April 2010 18:12 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: tnaseem on Thu, 08 April 2010 04:01 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: ringhio on Thu, 08 April 2010 16:39 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
|
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Mon, 03 May 2010 12:07 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: NeoX on Tue, 04 May 2010 20:24 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Tue, 04 May 2010 21:26 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: NeoX on Wed, 05 May 2010 13:46 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: NeoX on Wed, 05 May 2010 19:24 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Wed, 05 May 2010 19:52 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: NeoX on Wed, 05 May 2010 20:15 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Wed, 05 May 2010 20:55 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: zuby on Mon, 10 May 2010 11:52 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Mon, 10 May 2010 19:44 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: zuby on Mon, 10 May 2010 19:54 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Mon, 10 May 2010 20:20 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: zuby on Mon, 10 May 2010 20:32 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Mon, 10 May 2010 20:54 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: zuby on Mon, 10 May 2010 21:25 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Mon, 10 May 2010 23:58 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: zuby on Tue, 11 May 2010 10:58 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: zuby on Tue, 18 May 2010 13:27 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Tue, 18 May 2010 22:23 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: NeoX on Wed, 09 June 2010 23:54 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Thu, 10 June 2010 17:32 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: NeoX on Thu, 10 June 2010 19:46 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Thu, 10 June 2010 20:13 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: NeoX on Thu, 10 June 2010 21:40 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Thu, 10 June 2010 22:03 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: NeoX on Thu, 10 June 2010 22:10 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Thu, 10 June 2010 22:35 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: zuby on Mon, 21 June 2010 10:52 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: NeoX on Thu, 17 June 2010 19:15 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Thu, 17 June 2010 19:34 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: NeoX on Tue, 22 June 2010 11:28 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fortx on Wed, 28 July 2010 18:42 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
|
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fortx on Thu, 29 July 2010 04:47 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fizyk on Thu, 29 July 2010 18:06 |
 |
Re: sfDoctrineApplyPlugin - Undocumented steps to make it work, and without Zend_Mail
By: fortx on Fri, 30 July 2010 00:25 |
Goto Forum:
|