/** * @param CM_Model_Location $location * @throws CM_Exception_Invalid */ public function setCountryMapping(CM_Model_Location $location) { $country = $location->get(CM_Model_Location::LEVEL_COUNTRY); if (null === $country) { throw new CM_Exception_Invalid('Location has no country', null, ['location' => $location->getName()]); } CM_Db_Db::replace('cm_model_currency_country', ['currencyId' => $this->getId(), 'countryId' => $country->getId()]); }
/** * @param string[] $stringList */ public function addMultiple(array $stringList) { $data = \Functional\map($stringList, function ($string) { return ['type' => $this->_type, 'string' => (string) $string]; }); CM_Db_Db::replace('cm_string', ['type', 'string'], $data); $this->_change(); }
/** * @param string $section * @param string $key * @param boolean $value * @throws CM_Exception */ public function set($section, $key, $value) { $value = (bool) $value; $defaults = self::getDefaults(); if (!isset($defaults[$section][$key])) { throw new CM_Exception("Invalid preference ({$section}.{$key})"); } if ($value == $defaults[$section][$key]['value']) { CM_Db_Db::delete('cm_user_preference', array('userId' => $this->_model->getId(), 'preferenceId' => $defaults[$section][$key]['id'])); } else { CM_Db_Db::replace('cm_user_preference', array('userId' => $this->_model->getId(), 'preferenceId' => $defaults[$section][$key]['id'], 'value' => $value)); } $this->_change(); }
/** * @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()]); }
public function write() { if (!$this->isEmpty()) { CM_Db_Db::replace('cm_session', array('sessionId' => $this->getId(), 'data' => serialize($this->_data), 'expires' => time() + $this->getLifetime())); $this->_change(); } elseif ($this->_isPersistent) { CM_Db_Db::delete('cm_session', array('sessionId' => $this->getId())); $this->_change(); } }
public function setUp() { CMTest_TH::clearEnv(); CM_Db_Db::replace('cm_actionLimit', array('actionType', 'actionVerb', 'type', 'role', 'limit', 'period'), array(array($this->_actionType, $this->_actionVerb, $this->_type, $this->_role, 2, 3), array($this->_actionType, $this->_actionVerb, $this->_type, null, 10, 11))); }
/** * @param int $ip */ public function add($ip) { $ip = (int) $ip; CM_Db_Db::replace('cm_ipBlocked', ['ip' => $ip, 'createStamp' => time(), 'expirationStamp' => time() + $this->_getMaxAge()]); }
/** * @param int $trainingsMax */ public static function deleteOldTrainings($trainingsMax) { $trainingsMax = (int) $trainingsMax; $ids = CM_Db_Db::select('cm_svm', 'id')->fetchAllColumn(); foreach ($ids as $id) { $trainingsCount = CM_Db_Db::count('cm_svmtraining', array('svmId' => $id)); if ($trainingsCount > $trainingsMax) { $limit = (int) ($trainingsCount - $trainingsMax); $deletedCount = CM_Db_Db::exec('DELETE FROM `cm_svmtraining` WHERE `svmId` = ? ORDER BY `createStamp` LIMIT ' . $limit, array($id))->getAffectedRows(); if ($deletedCount > 0) { CM_Db_Db::replace('cm_svm', array('id' => $id, 'updateStamp' => time())); } } } }
/** * @param boolean $state * @throws CM_Exception_Invalid * @return CM_Model_User */ public function setVisible($state = true) { $state = (int) $state; if (!$this->getOnline()) { throw new CM_Exception_Invalid('Must not modify visibility of a user that is offline'); } CM_Db_Db::replace('cm_user_online', array('userId' => $this->getId(), 'visible' => $state)); $this->_set(array('online' => $this->getId(), 'visible' => $state)); return $this; }