예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function apply(base $appbox, Application $app)
 {
     $sql = 'DELETE FROM UserSettings';
     $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
     $stmt->execute();
     $stmt->closeCursor();
     $conn = $app['phraseanet.appbox']->get_connection();
     $sql = 'SELECT * FROM usr_settings';
     $stmt = $conn->prepare($sql);
     $stmt->execute();
     $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
     $stmt->closeCursor();
     $n = 0;
     $em = $app['EM'];
     foreach ($rs as $row) {
         if (substr($row['prop'], 0, 13) === "notification_") {
             continue;
         }
         if (null === ($user = $this->loadUser($app['EM'], $row['usr_id']))) {
             continue;
         }
         $userSetting = new UserSetting();
         $userSetting->setName($row['prop']);
         $userSetting->setValue($row['value']);
         $userSetting->setUser($user);
         $em->persist($userSetting);
         $n++;
         if ($n % 1000 === 0) {
             $em->flush();
             $em->clear();
         }
     }
     $em->flush();
     $em->clear();
     return true;
 }
예제 #2
0
 /**
  * Sets a preference setting for a user.
  *
  * @param User   $user
  * @param string $name
  * @param string $value
  */
 public function setUserSetting(User $user, $name, $value)
 {
     if ($user->getSettings()->containsKey($name)) {
         $user->getSettings()->get($name)->setValue($value);
     } else {
         $userSetting = new UserSetting();
         $userSetting->setUser($user);
         $userSetting->setName($name);
         $userSetting->setValue($value);
         $user->addSetting($userSetting);
     }
     $this->manager->update($user);
 }
 /**
  * {@inheritDoc}
  */
 public function setUpdated(\DateTime $updated)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setUpdated', array($updated));
     return parent::setUpdated($updated);
 }