/** * @param CM_Action_Abstract $action */ public function trackAction(CM_Action_Abstract $action) { if (0 === count($this->_getIdentityList()) && ($actor = $action->getActor())) { $this->setUserId($actor->getId()); } $trackEventJob = new CMService_KissMetrics_TrackEventJob(); $trackEventJob->queue(array('code' => $this->_getCode(), 'identityList' => $this->_getIdentityList(), 'eventName' => $action->getLabel(), 'propertyList' => $action->getTrackingPropertyList())); }
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; } })); }
public function testProcess() { $user = $this->getMockUser(); $mail = new CM_Mail_ExampleMailable($user); $site = CM_Site_Abstract::factory(); $render = new CM_Frontend_Render(new CM_Frontend_Environment($site)); $request = new CM_Http_Request_Get($render->getUrlEmailTracking($mail), ['host' => $site->getHost()]); $response = CM_Http_Response_EmailTracking::createFromRequest($request, $site, $this->getServiceManager()); $response->process(); $actionList = new CM_Paging_Action_User($user, CM_Action_Email::getTypeStatic(), CM_Action_Abstract::getVerbByVerbName(CM_Action_Abstract::VIEW)); $this->assertSame(1, $actionList->getCount()); }
/** * @param array $params * @param Smarty_Internal_Template $template * @return bool */ function smarty_function_actionAllowed(array $params, Smarty_Internal_Template $template) { if (!isset($params['type'])) { trigger_error('Param `type` missing.'); } if (!isset($params['verb'])) { trigger_error('Param `verb` missing.'); } $arguments = isset($params['arguments']) ? (array) $params['arguments'] : array(); /** @var CM_Model_User $viewer */ $viewer = $template->smarty->getTemplateVars('viewer'); if (!isset($viewer)) { return false; } $action = CM_Action_Abstract::factory($viewer, $params['verb'], (int) $params['type']); return call_user_func_array(array($action, 'isAllowed'), $arguments); }
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())); }
public function add(CM_Action_Abstract $action, $limitType) { $limitType = (int) $limitType; CM_Db_Db::insertDelayed('cm_action', array('ip' => $this->_ip, 'verb' => $action->getVerb(), 'type' => $action->getType(), 'actionLimitType' => $limitType, 'createStamp' => time())); }
public function getLabel() { return parent::getLabel() . ' ' . $this->_nameEmail; }
/** * @param CM_Action_Abstract $action */ public function __construct(CM_Action_Abstract $action) { $source = new CM_PagingSource_Sql('DISTINCT `actionType`, `actionVerb`, `type`', 'cm_actionLimit', '`actionType` = ' . $action->getType() . ' AND `actionVerb` = ' . $action->getVerb(), '`type`'); $source->enableCacheLocal(); parent::__construct($source); }
/** * @param string $streamChannel * @param CM_Action_Abstract $action * @param CM_Model_Abstract $model * @param mixed|null $data */ public static function publishAction($streamChannel, CM_Action_Abstract $action, CM_Model_Abstract $model, $data = null) { $namespace = 'CM_Action_Abstract' . ':' . $action->getVerbName() . ':' . $action->getType(); self::publish($streamChannel, $namespace, array('action' => $action, 'model' => $model, 'data' => $data)); }
/** * * @throws CM_Exception_Invalid * @return array */ public function getActionVerbs() { $actionVerbs = array(); $actionVerbsValues = array(); $classNames = CM_Action_Abstract::getClassChildren(true); array_unshift($classNames, 'CM_Action_Abstract'); foreach ($classNames as $className) { $class = new ReflectionClass($className); $constants = $class->getConstants(); unset($constants['TYPE']); foreach ($constants as $constant => $value) { if (array_key_exists($constant, $actionVerbsValues) && $actionVerbsValues[$constant] !== $value) { throw new CM_Exception_Invalid('Constant `' . $className . '::' . $constant . '` already set. Tried to set value to `' . $value . '` - previously set to `' . $actionVerbsValues[$constant] . '`.'); } if (!array_key_exists($constant, $actionVerbsValues) && in_array($value, $actionVerbsValues)) { throw new CM_Exception_Invalid('Cannot set `' . $className . '::' . $constant . '` to `' . $value . '`. This value is already used for `' . $className . '::' . array_search($value, $actionVerbsValues) . '`.'); } if (!array_key_exists($constant, $actionVerbsValues)) { $actionVerbsValues[$constant] = $value; $actionVerbs[] = array('name' => $constant, 'value' => $value, 'className' => $className); } } } return $actionVerbs; }
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; } })); } }
public static function fromArray(array $data) { $verb = CM_Action_Abstract::getVerbNameByVerb($data['verb']); return self::factory($data['actor'], $verb, $data['type']); }
public function testDeleteTransgressionsOlder() { $user = CMTest_TH::createUser(); $action = $this->mockClass('CM_Action_Abstract')->newInstanceWithoutConstructor(); $action->mockMethod('getType')->set(function () { return 1; }); $action->mockMethod('getVerb')->set(function () { return 2; }); /** @var CM_Action_Abstract $action */ $transgressions = $user->getTransgressions(); $actions = $user->getActions(); $transgressions->add($action, 1); $transgressions->add($action, 2); $actions->add($action, 1); CMTest_TH::timeForward(61); CM_Action_Abstract::deleteTransgressionsOlder(60); $transgressions->add($action, 3); $this->assertCount(1, $actions); $this->assertCount(1, $transgressions); CMTest_TH::timeForward(61); CM_Action_Abstract::deleteTransgressionsOlder(60); $transgressions->_change(); $this->assertCount(0, $transgressions); }