コード例 #1
0
ファイル: User.php プロジェクト: cargomedia/cm
 /**
  * @param CM_Model_User $user
  * @param int           $actionType OPTIONAL
  * @param int           $actionVerb OPTIONAL
  * @param int           $limitType  OPTIONAL
  * @param int           $period     OPTIONAL
  */
 public function __construct(CM_Model_User $user, $actionType = null, $actionVerb = null, $limitType = null, $period = null)
 {
     $this->_user = $user;
     $where = '`actorId` = ' . $user->getId();
     if ($actionType) {
         $actionType = (int) $actionType;
         $where .= ' AND `type` = ' . $actionType;
     }
     if ($actionVerb) {
         $actionVerb = (int) $actionVerb;
         $where .= ' AND `verb` = ' . $actionVerb;
     }
     if ($limitType) {
         $limitType = (int) $limitType;
         $where .= ' AND `actionLimitType` = ' . $limitType;
     } else {
         $where .= ' AND `actionLimitType` IS NOT NULL';
     }
     if ($period) {
         $period = (int) $period;
         $time = time() - $period;
         $where .= ' AND `createStamp` > ' . $time;
     }
     $source = new CM_PagingSource_Sql_Deferred('type, verb, createStamp', 'cm_action', $where, '`createStamp` DESC');
     parent::__construct($source);
 }
コード例 #2
0
ファイル: User.php プロジェクト: NicolasSchmutz/cm
 /**
  * @param CM_Model_User      $user
  * @param CM_Action_Abstract $action
  * @param CM_Model_Abstract  $model
  * @param mixed|null         $data
  */
 public static function publishAction($user, CM_Action_Abstract $action, CM_Model_Abstract $model, $data = null)
 {
     if (!$user->getOnline()) {
         return;
     }
     $streamChannel = self::getKeyByUser($user);
     parent::publishAction($streamChannel, $action, $model, $data);
 }
コード例 #3
0
ファイル: Online.php プロジェクト: cargomedia/cm
 /**
  * @param int|CM_Model_User $user
  * @return bool
  */
 public function contains($user)
 {
     if ($user instanceof CM_Model_User) {
         $userId = $user->getId();
     } else {
         $userId = (int) $user;
     }
     return in_array($userId, $this->getItemsRaw());
 }
コード例 #4
0
ファイル: EnvironmentTest.php プロジェクト: cargomedia/cm
 public function testHasViewer()
 {
     $environment = new CM_Frontend_Environment();
     $this->assertFalse($environment->hasViewer());
     $environment = new CM_Frontend_Environment(null, CM_Model_User::createStatic());
     $this->assertTrue($environment->hasViewer());
 }
コード例 #5
0
ファイル: Abstract.php プロジェクト: NicolasSchmutz/cm
 /**
  * @return CM_Model_User|null
  */
 public function getUser()
 {
     if (is_null($this->getUserId())) {
         return null;
     }
     return CM_Model_User::factory($this->getUserId());
 }
コード例 #6
0
ファイル: UserTest.php プロジェクト: cargomedia/cm
 public function testCreateWithLanguage()
 {
     $language = CMTest_TH::createLanguage();
     /** @var CM_Model_User $user */
     $user = CM_Model_User::createStatic(array('language' => $language));
     $this->assertEquals($language, $user->getLanguage());
 }
コード例 #7
0
ファイル: Splitfeature.php プロジェクト: cargomedia/cm
 /**
  * @param CM_Model_User $user
  * @throws CM_Exception_Invalid
  * @return boolean
  */
 public function getEnabled(CM_Model_User $user)
 {
     $cacheKey = CM_CacheConst::SplitFeature_Fixtures . '_userId:' . $user->getId();
     $cacheWrite = false;
     $cache = CM_Cache_Local::getInstance();
     if (($fixtures = $cache->get($cacheKey)) === false) {
         $fixtures = CM_Db_Db::select('cm_splitfeature_fixture', array('splitfeatureId', 'fixtureId'), array('userId' => $user->getId()))->fetchAllTree();
         $cacheWrite = true;
     }
     if (!array_key_exists($this->getId(), $fixtures)) {
         $fixtureId = CM_Db_Db::replace('cm_splitfeature_fixture', array('splitfeatureId' => $this->getId(), 'userId' => $user->getId()));
         $fixtures[$this->getId()] = $fixtureId;
         $cacheWrite = true;
     }
     if ($cacheWrite) {
         $cache->set($cacheKey, $fixtures);
     }
     return $this->_calculateEnabled($fixtures[$this->getId()]);
 }
コード例 #8
0
ファイル: Cli.php プロジェクト: aladin1394/CM
 protected function _registerCallbacks()
 {
     $this->_registerClockworkCallbacks('10 seconds', array('CM_Model_User::offlineDelayed' => function () {
         CM_Model_User::offlineDelayed();
     }));
     $this->_registerClockworkCallbacks('1 minute', array('CM_Model_User::offlineOld' => function () {
         CM_Model_User::offlineOld();
     }, 'CM_ModelAsset_User_Roles::deleteOld' => function () {
         CM_ModelAsset_User_Roles::deleteOld();
     }, 'CM_Paging_Useragent_Abstract::deleteOlder' => function () {
         CM_Paging_Useragent_Abstract::deleteOlder(100 * 86400);
     }, 'CM_File_UserContent_Temp::deleteOlder' => function () {
         CM_File_UserContent_Temp::deleteOlder(86400);
     }, 'CM_SVM_Model::deleteOldTrainings' => function () {
         CM_SVM_Model::deleteOldTrainings(3000);
     }, 'CM_Paging_Ip_Blocked::deleteOlder' => function () {
         CM_Paging_Ip_Blocked::deleteOld();
     }, 'CM_Captcha::deleteOlder' => function () {
         CM_Captcha::deleteOlder(3600);
     }, 'CM_Session::deleteExpired' => function () {
         CM_Session::deleteExpired();
     }, 'CM_Stream_Video::synchronize' => function () {
         CM_Stream_Video::getInstance()->synchronize();
     }, 'CM_Stream_Video::checkStreams' => function () {
         CM_Stream_Video::getInstance()->checkStreams();
     }, 'CM_MessageStream_Service::synchronize' => function () {
         CM_Service_Manager::getInstance()->getStreamMessage()->synchronize();
     }));
     $this->_registerClockworkCallbacks('15 minutes', array('CM_Mail::processQueue' => function () {
         CM_Mail::processQueue(500);
     }, 'CM_Action_Abstract::aggregate' => function () {
         CM_Action_Abstract::aggregate();
     }, 'CM_Action_Abstract::deleteTransgressionsOlder' => function () {
         CM_Action_Abstract::deleteTransgressionsOlder(3 * 31 * 86400);
     }, 'CM_Paging_Log_Abstract::cleanup' => function () {
         foreach (CM_Paging_Log_Abstract::getClassChildren() as $logClass) {
             /** @var CM_Paging_Log_Abstract $log */
             $log = new $logClass();
             $log->cleanUp();
         }
     }));
     $this->_registerClockworkCallbacks('8 days', array('CMService_MaxMind::upgrade' => function () {
         try {
             $maxMind = new CMService_MaxMind();
             $maxMind->upgrade();
         } catch (Exception $exception) {
             if (!is_a($exception, 'CM_Exception')) {
                 $exception = new CM_Exception($exception->getMessage(), ['file' => $exception->getFile(), 'line' => $exception->getLine(), 'trace' => $exception->getTraceAsString()]);
             }
             $exception->setSeverity(CM_Exception::FATAL);
             throw $exception;
         }
     }));
 }
コード例 #9
0
ファイル: Video.php プロジェクト: NicolasSchmutz/cm
 /**
  * @return CM_Model_User|null
  */
 public function getUser()
 {
     $userId = $this->getUserId();
     if (null === $userId) {
         return null;
     }
     try {
         return CM_Model_User::factory($userId);
     } catch (CM_Exception_Nonexistent $ex) {
         return null;
     }
 }
コード例 #10
0
ファイル: Mail.php プロジェクト: NicolasSchmutz/cm
 /**
  * @param boolean|null $delayed
  * @throws CM_Exception_Invalid
  */
 public function send($delayed = null)
 {
     $delayed = (bool) $delayed;
     if (empty($this->_to)) {
         throw new CM_Exception_Invalid('No recipient specified.');
     }
     $verificationMissing = $this->_verificationRequired && $this->_recipient && !$this->_recipient->getEmailVerified();
     if ($verificationMissing) {
         return;
     }
     list($subject, $html, $text) = $this->render();
     if ($delayed) {
         $this->_queue($subject, $text, $html);
     } else {
         $this->_send($subject, $text, $html);
     }
 }
コード例 #11
0
ファイル: AbstractTest.php プロジェクト: cargomedia/cm
 public function testGetUser()
 {
     $user = CM_Model_User::createStatic();
     $user2 = CM_Model_User::createStatic();
     CM_Model_Entity_Mock::createStatic(array('userId' => $user->getId(), 'foo' => 'bar1'));
     $entityMock = new CM_Model_Entity_Mock(1);
     $this->assertEquals($user->getId(), $entityMock->getUser()->getId());
     $this->assertInstanceOf('CM_Model_User', $user);
     $this->assertNotEquals($user2, $entityMock->getUser());
     CM_Db_Db::delete('cm_user', array('userId' => $user->getId()));
     CMTest_TH::clearCache();
     try {
         $entityMock->getUser();
         $this->fail('User not deleted');
     } catch (CM_Exception_Nonexistent $ex) {
         $this->assertTrue(true);
     }
     $this->assertNull($entityMock->getUserIfExists());
 }
コード例 #12
0
ファイル: Params.php プロジェクト: cargomedia/cm
 /**
  * @param string             $key
  * @param CM_Model_User|null $default
  * @throws CM_Exception_InvalidParam
  * @return CM_Model_User
  */
 public function getUser($key, CM_Model_User $default = null)
 {
     $param = $this->_get($key, $default);
     if (ctype_digit($param) || is_int($param)) {
         return CM_Model_User::factory($param);
     }
     if (!$param instanceof CM_Model_User) {
         throw new CM_Exception_InvalidParam('Not a CM_Model_User');
     }
     return $param;
 }
コード例 #13
0
ファイル: Client.php プロジェクト: NicolasSchmutz/cm
 /**
  * @param CM_Model_User $user
  */
 protected function _setUser(CM_Model_User $user)
 {
     $this->_setIdentity($user->getDisplayName());
 }
コード例 #14
0
ファイル: Cli.php プロジェクト: cargomedia/cm
 protected function _registerCallbacks()
 {
     $this->_registerClockworkCallbacks('1 second', ['CM_Jobdistribution_DelayedQueue::queueOutstanding' => function () {
         $delayedQueue = $this->getServiceManager()->getDelayedJobQueue();
         $delayedQueue->queueOutstanding();
     }]);
     $this->_registerClockworkCallbacks('1 minute', array('CM_Model_User::offlineOld' => function () {
         CM_Model_User::offlineOld();
     }, 'CM_ModelAsset_User_Roles::deleteOld' => function () {
         CM_ModelAsset_User_Roles::deleteOld();
     }, 'CM_Paging_Useragent_Abstract::deleteOlder' => function () {
         CM_Paging_Useragent_Abstract::deleteOlder(100 * 86400);
     }, 'CM_File_UserContent_Temp::deleteOlder' => function () {
         CM_File_UserContent_Temp::deleteOlder(86400);
     }, 'CM_SVM_Model::deleteOldTrainings' => function () {
         CM_SVM_Model::deleteOldTrainings(3000);
     }, 'CM_Paging_Ip_Blocked::deleteOlder' => function () {
         CM_Paging_Ip_Blocked::deleteOld();
     }, 'CM_Captcha::deleteOlder' => function () {
         CM_Captcha::deleteOlder(3600);
     }, 'CM_Session::deleteExpired' => function () {
         CM_Session::deleteExpired();
     }, 'CM_MessageStream_Service::synchronize' => function () {
         CM_Service_Manager::getInstance()->getStreamMessage()->synchronize();
     }));
     if ($this->getServiceManager()->has('janus')) {
         $this->_registerClockworkCallbacks('1 minute', array('CM_Janus_Service::synchronize' => function () {
             $this->getServiceManager()->getJanus('janus')->synchronize();
         }, 'CM_Janus_Service::checkStreams' => function () {
             $this->getServiceManager()->getJanus('janus')->checkStreams();
         }));
     }
     $this->_registerClockworkCallbacks('15 minutes', array('CM_Action_Abstract::aggregate' => function () {
         CM_Action_Abstract::aggregate();
     }, 'CM_Action_Abstract::deleteTransgressionsOlder' => function () {
         CM_Action_Abstract::deleteTransgressionsOlder(3 * 31 * 86400);
     }, 'CM_Paging_Log::cleanup' => function () {
         $allLevelsList = array_values(CM_Log_Logger::getLevels());
         foreach (CM_Paging_Log::getClassChildren() as $pagingLogClass) {
             /** @type CM_Paging_Log $log */
             $log = new $pagingLogClass($allLevelsList);
             $log->cleanUp();
         }
         (new CM_Paging_Log($allLevelsList, false))->cleanUp();
         //deletes all untyped records
     }));
     if ($this->getServiceManager()->has('maxmind')) {
         $this->_registerClockworkCallbacks('8 days', array('CMService_MaxMind::upgrade' => function () {
             try {
                 /** @var CMService_MaxMind $maxMind */
                 $maxMind = $this->getServiceManager()->get('maxmind', 'CMService_MaxMind');
                 $maxMind->upgrade();
             } catch (Exception $exception) {
                 if (!is_a($exception, 'CM_Exception')) {
                     $exception = new CM_Exception($exception->getMessage(), null, ['file' => $exception->getFile(), 'line' => $exception->getLine(), 'trace' => $exception->getTraceAsString()]);
                 }
                 $exception->setSeverity(CM_Exception::FATAL);
                 throw $exception;
             }
         }));
     }
 }
コード例 #15
0
ファイル: User.php プロジェクト: cargomedia/cm
 public function add(CM_Action_Abstract $action)
 {
     CM_Db_Db::insertDelayed('cm_action', array('actorId' => $this->_user->getId(), 'verb' => $action->getVerb(), 'type' => $action->getType(), 'createStamp' => time()));
 }
コード例 #16
0
ファイル: Mailable.php プロジェクト: cargomedia/cm
 /**
  * @return CM_Frontend_Render
  */
 public function getRender()
 {
     $environment = $this->_recipient ? $this->_recipient->getEnvironment() : new CM_Frontend_Environment();
     $environment->setSite($this->_site);
     return new CM_Frontend_Render($environment);
 }
コード例 #17
0
ファイル: Session.php プロジェクト: cargomedia/cm
 /**
  * @param CM_Model_User $user
  */
 public function setUser(CM_Model_User $user)
 {
     $user->setOnline(true);
     $this->set('userId', $user->getId());
     $this->regenerateId();
     if ($request = $this->getRequest()) {
         CM_Splittest_Fixture::setUserForRequestClient($request, $user);
         $user->getUseragents()->addFromRequest($request);
     }
 }
コード例 #18
0
ファイル: SessionTest.php プロジェクト: NicolasSchmutz/cm
 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'));
 }
コード例 #19
0
ファイル: Blocked.php プロジェクト: aladin1394/CM
 /**
  * @param CM_Model_User $user
  */
 public function __construct(CM_Model_User $user)
 {
     parent::__construct('Blocked', null, array('messagePublic' => '{$username} has blocked you.', 'messagePublicVariables' => array('username' => $user->getDisplayName())));
 }
コード例 #20
0
ファイル: AbstractTest.php プロジェクト: NicolasSchmutz/cm
 public function canSubscribe(CM_Model_User $user, $allowedUntil)
 {
     return $user->getId() != 1 ? $allowedUntil + 100 : $allowedUntil;
 }
コード例 #21
0
ファイル: RenderTest.php プロジェクト: cargomedia/cm
 public function testParseTemplateContent()
 {
     $viewer = CM_Model_User::createStatic();
     $render = new CM_Frontend_Render();
     $render->getEnvironment()->setViewer($viewer);
     $content = '{$viewer->getId()} {$foo} normal-text';
     $expected = $viewer->getId() . ' bar normal-text';
     $this->assertSame($expected, $render->parseTemplateContent($content, ['foo' => 'bar']));
 }
コード例 #22
0
ファイル: AbstractTest.php プロジェクト: aladin1394/CM
 public function testCreateType()
 {
     $user = CM_Model_Abstract::createType(CM_Model_User::getTypeStatic());
     $this->assertInstanceOf('CM_Model_User', $user);
 }
コード例 #23
0
ファイル: Fixture.php プロジェクト: cargomedia/cm
 /**
  * @param CM_Http_Request_Abstract $request
  * @param CM_Model_User       $user
  */
 public static function setUserForRequestClient(CM_Http_Request_Abstract $request, CM_Model_User $user)
 {
     $requestClientId = $request->getClientId();
     $userId = $user->getId();
     CM_Db_Db::updateIgnore('cm_splittestVariation_fixture', array('userId' => $userId), array('requestClientId' => $requestClientId));
 }
コード例 #24
0
ファイル: QueueTrait.php プロジェクト: cargomedia/cm
 /**
  * @param CM_Model_User $user
  * @return CM_Queue
  */
 protected function _getTrackingQueue(CM_Model_User $user)
 {
     return new CM_Queue(get_called_class() . '::_getTrackingQueue:' . $user->getId());
 }
コード例 #25
0
ファイル: Client.php プロジェクト: NicolasSchmutz/cm
 /**
  * @param CM_Model_User $user
  * @return CM_Queue
  */
 protected function _getTrackingQueue(CM_Model_User $user)
 {
     return new CM_Queue(__METHOD__ . ':' . $user->getId());
 }
コード例 #26
0
ファイル: UserTest.php プロジェクト: NicolasSchmutz/cm
 public function testOfflineDelayed()
 {
     $user1 = CMTest_TH::createUser();
     $user2 = CMTest_TH::createUser();
     $user3 = CMTest_TH::createUser();
     $user1->setOnline();
     $user2->setOnline();
     $user3->setOnline();
     $user1->setOfflineStamp();
     $user2->setOfflineStamp();
     CMTest_TH::timeForward(CM_Model_User::OFFLINE_DELAY);
     $user3->setOfflineStamp();
     $user2->setOnline();
     $userOnlinePaging = new CM_Paging_User_Online();
     $this->assertEquals([$user1, $user2, $user3], $userOnlinePaging);
     CM_Model_User::offlineDelayed();
     $userOnlinePaging = new CM_Paging_User_Online();
     $this->assertEquals([$user1, $user2, $user3], $userOnlinePaging);
     CMTest_TH::timeForward(1);
     CM_Model_User::offlineDelayed();
     $userOnlinePaging = new CM_Paging_User_Online();
     $this->assertEquals([$user2, $user3], $userOnlinePaging);
 }
コード例 #27
0
ファイル: TH.php プロジェクト: aladin1394/CM
 /**
  * @return CM_Model_User
  */
 public static function createUser()
 {
     return CM_Model_User::createStatic();
 }
コード例 #28
0
ファイル: Abstract.php プロジェクト: cargomedia/cm
 /**
  * @param CM_Model_User                 $user
  * @param CM_Model_Stream_Abstract|null $excludedStream
  * @return bool
  */
 public function isPublisher(CM_Model_User $user, CM_Model_Stream_Abstract $excludedStream = null)
 {
     /** @var $stream CM_Model_Stream_Publish */
     foreach ($this->getStreamPublishs() as $stream) {
         if (!$stream->equals($excludedStream) && $stream->getUserId() == $user->getId()) {
             return true;
         }
     }
     return false;
 }
コード例 #29
0
ファイル: User.php プロジェクト: cargomedia/cm
 /**
  * @param string $useragent
  */
 public function add($useragent)
 {
     $useragent = (string) $useragent;
     CM_Db_Db::replaceDelayed('cm_useragent', array('userId' => $this->_user->getId(), 'useragent' => $useragent, 'createStamp' => time()));
 }
コード例 #30
0
ファイル: User.php プロジェクト: aladin1394/CM
    public static function offlineOld()
    {
        $res = CM_Db_Db::exec('
			SELECT `o`.`userId`
			FROM `cm_user_online` `o`
			LEFT JOIN `cm_user` `u` USING(`userId`)
			WHERE `u`.`activityStamp` < ? OR `u`.`userId` IS NULL', array(time() - self::ONLINE_EXPIRATION));
        while ($userId = $res->fetchColumn()) {
            try {
                $user = CM_Model_User::factory($userId);
                $user->setOnline(false);
            } catch (CM_Exception_Nonexistent $e) {
                CM_Db_Db::delete('cm_user_online', array('userId' => $userId));
            }
        }
    }