protected function execute($arguments = array(), $options = array())
 {
     $context = sfContext::createInstance($this->configuration);
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'])->getConnection();
     $table = PetitionSigningTable::getInstance();
     $con = $table->getConnection();
     $silent = $options['silent'];
     $duration = (int) $options['duration'];
     $once = (bool) $options['once'];
     $limit = (int) $options['limit'];
     $petition_id = (int) $options['action_id'];
     $time = gmdate('Y-m-d H:i:s');
     $signings = $table->queryPendingSignings($duration, $once, $petition_id)->limit($limit)->execute();
     foreach ($signings as $signing) {
         /* @var $signing PetitionSigning */
         if (!$silent) {
             echo $signing->getId() . "\t" . $signing->getEmail() . "\n";
         }
         UtilEmailValidation::send($signing, 'Reminder:');
         $signing->setMailedAt($time);
         //      $signing->save();
     }
     $signings->save();
     if (!$silent) {
         echo "done.\n";
     }
 }
 protected function doSave($con = null)
 {
     if (null === $con) {
         $con = $this->getConnection();
     }
     $signing = $this->getObject();
     $petition = $signing->getPetition();
     $geo_existing = false;
     if ($petition->isGeoKind()) {
         // EMAIL-TO-LIST ACTION (AND PLEDGE)
         $existing_signing = PetitionSigningTable::getInstance()->findByPetitionIdAndEmail($petition->getId(), $this->getValue('email'));
         if ($existing_signing) {
             $geo_existing = true;
             $existing_signing->setPetition($petition);
             $this->object = $existing_signing;
             $signing = $existing_signing;
             $this->isNew = false;
             $signing->setWavePending($signing->getWavePending() + 1);
         } else {
             $signing->setWavePending(1);
         }
         $this->contact_num = 0;
         if ($petition->getKind() == Petition::KIND_PLEDGE) {
             $targets = ContactTable::getInstance()->fetchIdsByContactIds($petition, $this->getValue('pledges'), $existing_signing);
         } else {
             $targets = ContactTable::getInstance()->fetchIdsByTargetSelector($petition, $this->getValue('ts_1'), $this->getValue('ts_2'), $existing_signing);
         }
         if ($targets) {
             foreach ((array) $targets as $target) {
                 $signing_contact = new PetitionSigningContact();
                 $signing['PetitionSigningContact'][] = $signing_contact;
                 $signing_contact->setContactId($target['id']);
                 $signing_contact->setWave($signing->getWavePending());
                 $this->contact_num++;
             }
             parent::doSave($con);
         } else {
             $this->no_mails = true;
         }
     } else {
         parent::doSave($con);
     }
     $existing_signing = PetitionSigningTable::getInstance()->findByPetitionIdAndEmail($petition->getId(), $signing->getEmail(), $signing->getId());
     if ($existing_signing) {
         if ($existing_signing->getStatus() == PetitionSigning::STATUS_PENDING && !$geo_existing) {
             $existing_signing->delete();
         } else {
             $signing->delete();
             $this->object = $existing_signing;
             $signing = $existing_signing;
             return;
         }
     }
     $validation_kind = $this->getOption('validation_kind', PetitionSigning::VALIDATION_KIND_NONE);
     switch ($validation_kind) {
         case PetitionSigning::VALIDATION_KIND_EMAIL:
             UtilEmailValidation::send($signing);
             break;
         case PetitionSigning::VALIDATION_KIND_NONE:
         default:
             break;
     }
 }