Example #1
0
 /**
  * {@inheritdoc}
  */
 public function apply(base $appbox, Application $app)
 {
     try {
         $sql = 'SELECT usr_id, user_agent, ip, platform, browser, app,
                     browser_version, screen, token, nonce, lastaccess, created_on
                 FROM cache';
         $stmt = $appbox->get_connection()->prepare($sql);
         $stmt->execute();
         $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
         $stmt->closeCursor();
     } catch (DBALException $e) {
         // this may fail on oldest versions
         return false;
     }
     foreach ($rs as $row) {
         if (null === ($user = $this->loadUser($app['EM'], $row['usr_id']))) {
             continue;
         }
         $created = $updated = null;
         if ('0000-00-00 00:00:00' !== $row['created_on']) {
             $created = \DateTime::createFromFormat('Y-m-d H:i:s', $row['created_on']);
         }
         if ('0000-00-00 00:00:00' !== $row['lastaccess']) {
             $updated = \DateTime::createFromFormat('Y-m-d H:i:s', $row['lastaccess']);
         }
         $session = new Session();
         $session->setUser($user)->setUserAgent($row['user_agent'])->setUpdated($updated)->setToken($row['token'])->setPlatform($row['platform'])->setNonce($row['nonce'])->setIpAddress($row['ip'])->setCreated($created)->setBrowserVersion($row['browser_version'])->setBrowserName($row['browser']);
         $sizes = explode('x', $row['screen']);
         if (2 === count($sizes)) {
             $session->setScreenWidth($sizes[0])->setScreenHeight($sizes[1]);
         }
         if (false !== ($apps = @unserialize($row['app']))) {
             foreach ($apps as $appli) {
                 $module = new SessionModule();
                 $module->setModuleId($appli)->setCreated($created)->setSession($session)->setUpdated($updated);
                 $session->addModule($module);
                 $app['EM']->persist($module);
             }
         }
         $app['EM']->persist($session);
     }
     $app['EM']->flush();
     return true;
 }
 /**
  * {@inheritDoc}
  */
 public function setScreenWidth($screenWidth)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setScreenWidth', array($screenWidth));
     return parent::setScreenWidth($screenWidth);
 }