/**
  * Save recursively the values.
  * @param Array $values
  */
 public function doSave($values)
 {
     foreach ($values as $field => $value) {
         if (isset($this->embeddedForms[$field])) {
             $this->doSave($value);
         } else {
             sfPlopConfigPeer::addOrUpdate($field, $value);
         }
     }
 }
 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'] . '".');
         }
     }
 }
 /**
  * Check if the config needs to be updated given to his value.
  * @param String $name
  * @param String $value
  * @param PropelPDO $con
  */
 public static function addOrUpdate($name, $value, $con = null)
 {
     $config = sfPlopConfigPeer::retrieveByName($name, $con);
     $config_static = self::dump(sfPlop::get($name, true));
     $value_dump = self::dump($value);
     if ($config && !self::isIdentical($config->getValue(), $value_dump)) {
         if (is_string($value_dump) && trim($value_dump) == '' || self::isIdentical($value_dump, $config_static)) {
             $config->delete();
         } elseif (!self::isIdentical($value_dump, $config_static)) {
             $config->setValue($value_dump);
             $config->save();
         }
     } elseif (!$config && trim($value_dump) != '' && !self::isIdentical($value_dump, $config_static)) {
         $config = new sfPlopConfig();
         $config->setName($name);
         $config->setValue($value_dump);
         $config->save();
     }
     sfPlop::set($name, $value);
 }
Example #4
0
 /**
  * Load a Plop plugin which can contain modules and slots
  * @param Array $options
  */
 public static function loadPlugin($options)
 {
     if (self::is_set() && self::is_ready()) {
         $plugin_options = array('modules' => 'sf_plop_loaded_modules', 'slots' => 'sf_plop_loaded_slots', 'themes' => 'sf_plop_loaded_themes', 'links' => 'sf_plop_loaded_links');
         foreach ($plugin_options as $plugin_option => $plugin_config) {
             if (isset($options[$plugin_option])) {
                 $loaded_options = sfPlop::get($plugin_config);
                 foreach ($options[$plugin_option] as $name => $desc) {
                     $loaded_options[$name] = $desc;
                 }
                 sfPlopConfigPeer::addOrUpdate($plugin_config, $loaded_options);
             }
         }
     }
 }
Example #5
0
 /**
  * Return a PHP value of the config value which is formatted to Yaml
  * @return Mixed
  */
 public function getPhpValue()
 {
     return sfPlopConfigPeer::load($this->getValue());
 }
 /**
  * Get or set a value thanks to the given key.
  * @param sfWebRequest $request
  * @return String
  */
 public function executeWsConfig(sfWebRequest $request)
 {
     $key = $request->getParameter('key');
     $value = $request->getParameter('value');
     $return = false;
     $this->forward404Unless($request->isXmlHttpRequest() && $key && $this->isUserAdmin);
     if ($request->isMethod($request::POST)) {
         $this->forward404Unless($value);
         sfPlopConfigPeer::addOrUpdate($key, $value);
         $return = true;
     } elseif ($request->isMethod($request::GET)) {
         $return = sfPlop::get($key);
     }
     $this->setLayout(false);
     $this->key = $key;
     if (!is_bool($return)) {
         return $this->renderText($return);
     } elseif ($return === false) {
         return sfView::ERROR;
     }
 }