protected function execute($arguments = array(), $options = array())
 {
     $databaseManager = new sfDatabaseManager($this->configuration);
     $con = $databaseManager->getDatabase($options['connection'])->getConnection();
     if (isset($options['email'])) {
         $validatorEmail = new sfValidatorEmail();
         try {
             $options['email'] = $validatorEmail->clean($options['email']);
         } catch (Exception $e) {
             throw new sfCommandException('The email is invalid.');
         }
         $emails = array('sf_plop_messaging_from_email', 'sf_plop_messaging_to_email');
         foreach ($emails as $email) {
             sfPlopConfigPeer::addOrUpdate($email, $options['email'], $con);
         }
     }
     if (isset($options['email'])) {
         $validatorName = new sfValidatorString();
         try {
             $options['name'] = $validatorName->clean($options['name']);
         } catch (Exception $e) {
             throw new sfCommandException('The name is invalid.');
         }
         $names = array('sf_plop_messaging_from_name', 'sf_plop_messaging_to_name');
         foreach ($names as $name) {
             sfPlopConfigPeer::addOrUpdate($name, $options['name'], $con);
         }
     }
     if (isset($options['username'])) {
         $user = sfGuardUserQuery::create()->findOneByUsername($options['username']);
         if ($user) {
             if (isset($options['email'])) {
                 $user->getProfile()->setEmail($options['email']);
             }
             $names = explode(' ', $options['name']);
             $firstName = $names[0];
             unset($names[0]);
             $lastName = implode(' ', $names);
             $user->getProfile()->setFirstName($firstName);
             $user->getProfile()->setLastName($lastName);
             $user->getProfile()->save();
         } else {
             throw new sfCommandException('There is no user whith username "' . $options['username'] . '".');
         }
     }
 }
Пример #2
0
 /**
  * Returns a new sfGuardUserQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return    sfGuardUserQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof sfGuardUserQuery) {
         return $criteria;
     }
     $query = new sfGuardUserQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
Пример #3
0
 /**
  * Get the associated sfGuardUser object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     sfGuardUser The associated sfGuardUser object.
  * @throws     PropelException
  */
 public function getsfGuardUser(PropelPDO $con = null)
 {
     if ($this->asfGuardUser === null && $this->user_id !== null) {
         $this->asfGuardUser = sfGuardUserQuery::create()->findPk($this->user_id, $con);
         /* The following can be used additionally to
         			guarantee the related object contains a reference
         			to this object.  This level of coupling may, however, be
         			undesirable since it could result in an only partially populated collection
         			in the referenced object.
         			$this->asfGuardUser->addsfGuardRememberKeys($this);
         		 */
     }
     return $this->asfGuardUser;
 }
Пример #4
0
 /**
  * Check if a user is the last super admin
  * @return Boolean
  */
 public static function isLastSuperAdminUser()
 {
     return sfGuardUserQuery::create()->filterByIsSuperAdmin(true)->count() > 1 ? false : true;
 }
Пример #5
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      PropelPDO $con
  * @return     void
  * @throws     PropelException
  * @see        BaseObject::setDeleted()
  * @see        BaseObject::isDeleted()
  */
 public function delete(PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(sfGuardUserPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = sfGuardUserQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         // symfony_behaviors behavior
         foreach (sfMixer::getCallables('BasesfGuardUser:delete:pre') as $callable) {
             if (call_user_func($callable, $this, $con)) {
                 $con->commit();
                 return;
             }
         }
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             // symfony_behaviors behavior
             foreach (sfMixer::getCallables('BasesfGuardUser:delete:post') as $callable) {
                 call_user_func($callable, $this, $con);
             }
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }