Esempio n. 1
0
 public function testStart()
 {
     /** @var CM_Model_User $user */
     $user = CM_Model_User::createStatic();
     $activityStamp1 = time();
     $session = new CM_Session();
     $session->setUser($user);
     $sessionId = $session->getId();
     unset($session);
     $session = new CM_Session($sessionId);
     $this->assertEquals($activityStamp1, $session->getUser(true)->getLatestActivity(), null, 1);
     CMTest_TH::timeForward(CM_Model_User::ACTIVITY_EXPIRATION / 2);
     $session = new CM_Session($sessionId);
     $session->start();
     $this->assertEquals($activityStamp1, $session->getUser(true)->getLatestActivity(), null, 1);
     CM_Db_Db::update('cm_session', array('data' => serialize(array('userId' => $user->getId(), 'foo' => 'bar'))));
     unset($session);
     CMTest_TH::clearCache();
     CMTest_TH::timeForward(CM_Model_User::ACTIVITY_EXPIRATION / 2 + 1);
     $activityStamp2 = time();
     $session = new CM_Session($sessionId);
     $session->start();
     $this->assertEquals($activityStamp2, $session->getUser(true)->getLatestActivity(), null, 1);
     CMTest_TH::timeForward($session->getLifetime() / 2);
     $session->start();
     $this->assertEquals('bar', $session->get('foo'));
     CM_Db_Db::update('cm_session', array('data' => serialize(array('userId' => $user->getId(), 'foo' => 'foo'))));
     unset($session);
     CMTest_TH::clearCache();
     $session = new CM_Session($sessionId);
     $this->assertEquals('bar', $session->get('foo'));
 }
Esempio n. 2
0
 /**
  * @param string $streamName
  * @param string $clientKey
  * @param int    $start
  * @param int    $width
  * @param int    $height
  * @param int    $serverId
  * @param string $data
  * @throws CM_Exception
  * @throws CM_Exception_NotAllowed
  * @return int
  */
 public function publish($streamName, $clientKey, $start, $width, $height, $serverId, $data)
 {
     $streamName = (string) $streamName;
     $clientKey = (string) $clientKey;
     $start = (int) $start;
     $width = (int) $width;
     $height = (int) $height;
     $serverId = (int) $serverId;
     $data = (string) $data;
     $params = CM_Params::factory(CM_Params::jsonDecode($data), true);
     $streamChannelType = $params->getInt('streamChannelType');
     $session = new CM_Session($params->getString('sessionId'));
     $user = $session->getUser(true);
     /** @var CM_Model_StreamChannel_Abstract $streamChannel */
     $streamChannel = CM_Model_StreamChannel_Abstract::createType($streamChannelType, array('key' => $streamName, 'adapterType' => $this->getType(), 'params' => $params, 'width' => $width, 'height' => $height, 'serverId' => $serverId, 'thumbnailCount' => 0));
     try {
         CM_Model_Stream_Publish::createStatic(array('streamChannel' => $streamChannel, 'user' => $user, 'start' => $start, 'key' => $clientKey));
     } catch (CM_Exception $ex) {
         $streamChannel->delete();
         throw new CM_Exception_NotAllowed('Cannot publish: ' . $ex->getMessage());
     }
     return $streamChannel->getId();
 }