Esempio n. 1
1
 /**
  * {@inheritdoc}
  */
 public function apply(base $appbox, Application $app)
 {
     $conn = $app['phraseanet.appbox']->get_connection();
     $sql = 'SELECT date, login, ip, locked
             FROM badlog
             ORDER BY id ASC';
     $stmt = $conn->prepare($sql);
     $stmt->execute();
     $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
     $stmt->closeCursor();
     $n = 1;
     foreach ($rs as $row) {
         $date = Datetime::createFromFormat('Y-m-d h:i:s', $row['date']);
         $failure = new AuthFailure();
         if ($date) {
             $failure->setCreated($date);
         }
         $failure->setIp($row['ip']);
         $failure->setLocked(!!$row['locked']);
         $failure->setUsername($row['login']);
         $app['EM']->persist($failure);
         if (0 === $n++ % 1000) {
             $app['EM']->flush();
             $app['EM']->clear();
         }
     }
     $app['EM']->flush();
     $app['EM']->clear();
     return true;
 }
 private function insertAuthFailures(EntityManager $em, \Pimple $DI)
 {
     $ip = '192.168.16.178';
     $username = '******';
     for ($i = 0; $i < 10; $i++) {
         $failure = new AuthFailure();
         $failure->setIp($ip);
         $failure->setUsername($username);
         $failure->setLocked(false);
         $failure->setCreated(new \DateTime('-3 months'));
         $em->persist($failure);
     }
     for ($i = 0; $i < 2; $i++) {
         $failure = new AuthFailure();
         $failure->setIp($ip);
         $failure->setUsername($username);
         $failure->setLocked(false);
         $failure->setCreated(new \DateTime('-1 months'));
         $em->persist($failure);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function setCreated(\DateTime $created)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setCreated', array($created));
     return parent::setCreated($created);
 }