/** * @param bool $state * @throws CM_Exception */ public function setEnabled($state) { $state = (bool) $state; $variationsEnabled = $this->getSplittest()->getVariationsEnabled(); if (!$state && $state != $this->getEnabled() && $variationsEnabled->getCount() <= 1) { throw new CM_Exception('No variations for Splittest', null, array('messagePublic' => 'At least one variation needs to be enabled')); } CM_Db_Db::update('cm_splittestVariation', array('enabled' => $state), array('id' => $this->getId())); $this->_change(); $variationsEnabled->_change(); }
public function testUpdateItemWithJob() { $query = new CM_Elasticsearch_Query(); $query->queryMatchMulti(array('name'), 'foo'); $source = new CM_PagingSource_Elasticsearch($this->_type, $query); $this->assertSame(0, $source->getCount()); $id1 = $this->_type->createEntry('foo'); $id2 = $this->_type->createEntry('foo bar'); $this->assertSame(2, $source->getCount()); $this->assertEquals(array($id1, $id2), $source->getItems()); CM_Db_Db::update('index_mock', array('name' => 'bar'), array('id' => $id2)); $this->_type->updateItemWithJob(array('id' => $id2)); $this->assertSame(1, $source->getCount()); $this->assertEquals(array($id1), $source->getItems()); }
public function testPaging() { $language = CM_Model_Language::create('Foo', 'foo', true); $languagePagingAll = $language->getTranslations(); $languagePagingJavascriptOnly = $language->getTranslations(true); $this->assertEquals([], $languagePagingAll); $this->assertEquals([], $languagePagingJavascriptOnly); $languagePagingAll->set('foo', 'foo'); // js CM_Db_Db::update('cm_model_languagekey', ['javascript' => 1], ['name' => 'foo']); $languagePagingJavascriptOnly->set('bar', 'bar'); // js CM_Db_Db::update('cm_model_languagekey', ['javascript' => 1], ['name' => 'bar']); $languagePagingAll->set('baz', 'baz'); // no js $this->assertSame('foo', $language->getTranslations()->get('foo')); $this->assertSame('foo', $language->getTranslations(true)->get('foo')); $this->assertSame('bar', $language->getTranslations()->get('bar')); $this->assertSame('bar', $language->getTranslations(true)->get('bar')); $this->assertSame('baz', $language->getTranslations()->get('baz')); $exception = $this->catchException(function () use($language) { $language->getTranslations(true)->get('baz'); }); $this->assertInstanceOf('CM_Exception_Invalid', $exception); $languagePagingJavascriptOnly->set('foo', 'bar'); $this->assertSame('bar', $language->getTranslations(true)->get('foo')); $this->assertSame('bar', $language->getTranslations()->get('foo')); $languagePagingAll->set('bar', 'foo'); $this->assertSame('foo', $language->getTranslations()->get('bar')); $this->assertSame('foo', $language->getTranslations(true)->get('bar')); $languagePagingAll->remove('foo'); $this->assertSame(null, $language->getTranslations()->get('foo')); $this->assertSame(null, $language->getTranslations(true)->get('foo')); $languagePagingJavascriptOnly->remove('bar'); $this->assertSame(null, $language->getTranslations()->get('bar')); $this->assertSame(null, $language->getTranslations(true)->get('bar')); }
protected function _upgradeCityList() { $this->_streamOutput->writeln('Updating cities database…'); $count = $this->_count(array($this->_cityListByRegionRenamed, $this->_cityListByRegionUpdatedCode, $this->_cityListByRegionAdded), 4) + $this->_count($this->_cityListUpdatedRegion, 2); $item = 0; foreach ($this->_cityListByRegionRenamed as $cityListByRegionRenamed) { foreach ($cityListByRegionRenamed as $cityListRenamed) { foreach ($cityListRenamed as $cityCode => $cityNames) { $cityName = $cityNames['name']; CM_Db_Db::update('cm_model_location_city', array('name' => $cityName), array('_maxmind' => $cityCode)); $this->_printProgressCounter(++$item, $count); } } } unset($this->_cityListByRegionRenamed); foreach ($this->_cityListByRegionUpdatedCode as $cityListByRegionUpdatedCode) { foreach ($cityListByRegionUpdatedCode as $cityListUpdatedCode) { foreach ($cityListUpdatedCode as $cityCode) { $cityId = $this->_cityIdList[$cityCode]; CM_Db_Db::update('cm_model_location_city', array('_maxmind' => $cityCode), array('id' => $cityId)); $this->_printProgressCounter(++$item, $count); } } } unset($this->_cityListByRegionUpdatedCode); foreach ($this->_cityListUpdatedRegion as $countryCode => $cityListUpdatedRegion) { foreach ($cityListUpdatedRegion as $cityCode => $regionCodes) { $cityId = $this->_cityIdList[$cityCode]; $regionCode = $regionCodes['regionCode']; $regionName = $this->_getRegionName($countryCode, $regionCode); $cityName = $this->_cityListByRegion[$countryCode][$regionCode][$cityCode]; if ($regionName === 'Unknown region') { CM_Db_Db::update('cm_model_location_city', array('stateId' => null, 'name' => $cityName), array('id' => $cityId)); } else { $regionId = $this->_regionIdListByCountry[$countryCode][$regionCode]; CM_Db_Db::update('cm_model_location_city', array('stateId' => $regionId, 'name' => $cityName), array('id' => $cityId)); } $this->_printProgressCounter(++$item, $count); } } unset($this->_regionListByCountry); unset($this->_cityListByRegion); unset($this->_cityListUpdatedRegion); foreach ($this->_cityListByRegionAdded as $countryCode => $cityListByRegionAdded) { foreach ($cityListByRegionAdded as $regionCode => $cityListAdded) { if (isset($this->_regionIdListByCountry[$countryCode][$regionCode])) { $regionId = $this->_regionIdListByCountry[$countryCode][$regionCode]; $parentLocation = new CM_Model_Location(CM_Model_Location::LEVEL_STATE, $regionId); } else { $countryId = $this->_countryIdList[$countryCode]; $parentLocation = new CM_Model_Location(CM_Model_Location::LEVEL_COUNTRY, $countryId); } foreach ($cityListAdded as $cityCode => $cityName) { $cityData = $this->_locationTree[$countryCode]['regions'][$regionCode]['cities'][$cityName]['location']; $city = CM_Model_Location::createCity($parentLocation, $cityName, $cityData['latitude'], $cityData['longitude'], $cityData['maxMind']); $cityId = $city->getId(); $this->_cityIdList[$cityCode] = $cityId; $this->_printProgressCounter(++$item, $count); } } } unset($this->_regionIdListByCountry); unset($this->_cityListByRegionAdded); unset($this->_locationTree); }
public function monitorSynchronizedCommands() { $time = time(); $timeoutStamp = $time + self::TIMEOUT; $process = $this->_getProcess(); $machineId = $this->_getMachineId(); $result = CM_Db_Db::select('cm_cli_command_manager_process', ['commandName', 'processId'], ['machineId' => $machineId]); foreach ($result->fetchAll() as $row) { $commandName = $row['commandName']; $processId = (int) $row['processId']; $where = ['machineId' => $machineId, 'commandName' => $commandName]; if ($process->isRunning($processId)) { CM_Db_Db::update('cm_cli_command_manager_process', ['timeoutStamp' => $timeoutStamp], $where); } else { CM_Db_Db::delete('cm_cli_command_manager_process', $where); } } CM_Db_Db::delete('cm_cli_command_manager_process', '`timeoutStamp` < ' . $time); }
protected function _updateLatestActivity() { $currentTime = time(); CM_Db_Db::update('cm_user', array('activityStamp' => $currentTime), array('userId' => $this->getId())); $this->_set('activityStamp', $currentTime); }
/** * @param CM_File_UserContent|null $file */ public function setFile(CM_File_UserContent $file = null) { $filename = null !== $file ? $file->getFileName() : null; CM_Db_Db::update('cm_streamChannelArchive_media', ['file' => $filename], ['id' => $this->getId()]); $this->_change(); }
/** * @param int $percentage */ public function setPercentage($percentage) { $percentage = $this->_checkPercentage($percentage); CM_Db_Db::update('cm_splitfeature', array('percentage' => $percentage), array('id' => $this->getId())); $this->_change(); }
<?php $rowList = CM_Db_Db::select('cm_log', '*')->fetchAll(); foreach ($rowList as $row) { $metaInfo = @unserialize($row['metaInfo']); if (is_array($metaInfo)) { $variableInspector = new CM_Debug_VariableInspector(); $metaInfo = Functional\map($metaInfo, function ($value) use($variableInspector) { return $variableInspector->getDebugInfo($value, ['recursive' => true]); }); } else { $metaInfo = null; } CM_Db_Db::update('cm_log', ['metaInfo' => serialize($metaInfo)], ['id' => $row['id']]); }
public function unsetUser() { CM_Db_Db::update('cm_stream_publish', array('userId' => null), array('id' => $this->getId())); $this->_change(); }
<?php if (!CM_Db_Db::existsTable('cm_requestClientCounter')) { CM_Db_Db::exec(' CREATE TABLE `cm_requestClientCounter` ( `counter` int(10) unsigned NOT NULL, PRIMARY KEY (`counter`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; '); CM_Db_Db::insert('cm_requestClientCounter', array('counter' => 0)); } if (CM_Db_Db::existsTable('cm_requestClient')) { $highestEntry = (int) CM_Db_Db::select('cm_requestClient', 'id', null, array('id' => 'DESC'))->fetchColumn(); CM_Db_Db::update('cm_requestClientCounter', array('counter' => $highestEntry)); CM_Db_Db::exec('DROP TABLE IF EXISTS `cm_requestClient`;'); }
/** * @param bool $optimized * @return CM_Model_Splittest */ public function setOptimized($optimized) { $optimized = (bool) $optimized; CM_Db_Db::update('cm_splittest', ['optimized' => $optimized], ['id' => $this->getId()]); return $this->_change(); }
<?php if (!CM_Db_Db::existsColumn('cm_languageKey', 'variables')) { CM_Db_Db::exec("ALTER TABLE `cm_languageKey` ADD `variables` text CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL AFTER name"); } if (CM_Db_Db::existsTable('cm_languageKey_variable')) { $results = CM_Db_Db::select('cm_languageKey_variable', '*')->fetchAll(); $variableList = array(); foreach ($results as $result) { $variableList[$result['languageKeyId']][] = $result['name']; } foreach ($variableList as $languageKeyId => $variables) { CM_Db_Db::update('cm_languageKey', array('variables' => json_encode($variables)), array('id' => $languageKeyId)); } CM_Db_Db::exec('DROP TABLE `cm_languageKey_variable`'); }
/** * @param int|null $role * @param int $period */ public function setPeriod($role, $period) { $role = $role ? (int) $role : null; $period = (int) $period; if (CM_Db_Db::count('cm_actionLimit', array('actionType' => $this->getActionType(), 'actionVerb' => $this->getActionVerb(), 'type' => $this->getType(), 'role' => $role))) { CM_Db_Db::update('cm_actionLimit', array('period' => $period), array('actionType' => $this->getActionType(), 'actionVerb' => $this->getActionVerb(), 'type' => $this->getType(), 'role' => $role)); } else { CM_Db_Db::insert('cm_actionLimit', array('period' => $period, 'actionType' => $this->getActionType(), 'actionVerb' => $this->getActionVerb(), 'type' => $this->getType(), 'role' => $role)); } $this->_change(); }
protected function _onDeleteBefore() { CM_Db_Db::delete('cm_languageValue', array('languageId' => $this->getId())); /** @var CM_Model_Language $language */ foreach (new CM_Paging_Language_All() as $language) { if ($this->isBackingUp($language) && !$this->equals($language)) { $language->setBackup(null); } } CM_Db_Db::update('cm_user', array('languageId' => null), array('languageId' => $this->getId())); }
public function save($type, array $id, array $data) { CM_Db_Db::update($this->_getTableName($type), $data, $id); }
<?php if ('1.00' === CM_Db_Db::describeColumn('cm_splittestVariation_fixture', 'conversionWeight')->getDefaultValue()) { CM_Db_Db::exec('ALTER TABLE cm_splittestVariation_fixture MODIFY COLUMN conversionWeight decimal(10,2) NOT NULL DEFAULT 0'); CM_Db_Db::update('cm_splittestVariation_fixture', array('conversionWeight' => 0), array('conversionStamp' => null)); }
public function setBar($bar) { $bar = (string) $bar; CM_Db_Db::update('modelThasIsAnAssetMock', array('bar' => $bar), array('id' => $this->getId())); $this->_change(); }
<?php $nameList[] = 'Your browser is no longer supported'; $nameList[] = 'We recommend upgrading to the latest Internet Explorer, Google Chrome, Firefox, or Opera. Click here for <a href="{$url}">more information</a>'; $nameList[] = 'If you are using IE 9 or later, make sure you <a href="{$url}">turn off "Compatibility View"</a>'; foreach ($nameList as $name) { $id = CM_Db_Db::select('cm_languageKey', 'id', array('name' => $name))->fetchColumn(); if ($id) { CM_Db_Db::update('cm_languageKey', array('name' => $name . '.'), array('id' => $id)); CM_Db_Db::exec('UPDATE `cm_languageValue` SET `value`= CONCAT(`value`, ".") WHERE `languageKeyId` = ' . $id); } }
// 1) Duplicate entry for the city "Saint John's" // Setting the region code to "Newfoundland and Labrador" for one of them // to achieve consistency with the updated GeoIP data CM_Db_Db::update('cm_model_location_city', array('stateId' => 2524), array('id' => 22256)); // 2) Duplicate entries for the cities "Apo"/"Fpo" (U.S. Army post offices) // Adding region entries for the U.S. Armed Forces Americas & Pacific $idUS = CM_Db_Db::select('cm_model_location_country', 'id', array('abbreviation' => 'US'))->fetchColumn(); if (false === $idUS) { throw new CM_Exception_Invalid('No country with abbreviation `US` found'); } $idUS = (int) $idUS; $armedForcesRegionList = array('AA' => 'Armed Forces Americas', 'AE' => 'Armed Forces Europe, Middle East, & Canada', 'AP' => 'Armed Forces Pacific'); $idArmedForcesList = array(); foreach ($armedForcesRegionList as $regionCode => $regionName) { $idArmedForces = CM_Db_Db::select('cm_model_location_state', 'id', array('countryId' => $idUS, 'abbreviation' => $regionCode))->fetchColumn(); if (false === $idArmedForces) { $idArmedForces = CM_Db_Db::insert('cm_model_location_state', array('countryId' => $idUS, 'abbreviation' => $regionCode, 'name' => $regionName)); } else { CM_Db_Db::update('cm_model_location_state', array('name' => $regionName), array('countryId' => $idUS, 'abbreviation' => $regionCode)); } $idArmedForcesList[$regionCode] = (int) $idArmedForces; } // Moving the duplicate cities to the correct regions $armedForcesCityList = array('AA' => array(173158, 173159), 'AE' => array(173160, 173161), 'AP' => array(173944, 173945)); foreach ($armedForcesCityList as $regionCode => $cityIdList) { $regionId = $idArmedForcesList[$regionCode]; foreach ($cityIdList as $cityId) { CM_Db_Db::update('cm_model_location_city', array('stateId' => $regionId), array('id' => $cityId)); } }
public function monitorSynchronizedCommands() { $time = time(); $timeoutStamp = $time + self::TIMEOUT; $process = $this->_getProcess(); $hostId = $process->getHostId(); $result = CM_Db_Db::select('cm_cli_command_manager_process', array('commandName', 'processId'), array('hostId' => $hostId)); foreach ($result->fetchAll() as $row) { $commandName = $row['commandName']; $processId = (int) $row['processId']; if ($process->isRunning($processId)) { CM_Db_Db::update('cm_cli_command_manager_process', array('timeoutStamp' => $timeoutStamp), array('commandName' => $commandName)); } else { CM_Db_Db::delete('cm_cli_command_manager_process', array('commandName' => $commandName)); } } CM_Db_Db::delete('cm_cli_command_manager_process', '`timeoutStamp` < ' . $time); }
public function testUpdateRegionName_numericMaxMindCodeUS() { $this->_import([['United States', 'US']], [['US', 'CA', 'California']], [['223', 'US', '', '', '', '38', '-97'], ['2221', 'US', 'CA', '', '', '34.0522', '-118.243']], [], []); CM_Db_Db::update('cm_model_location_state', ['_maxmind' => 'US06']); $this->_verify([['id' => 1, 'abbreviation' => 'US', 'name' => 'United States']], [['id' => 1, 'countryId' => 1, 'name' => 'California', '_maxmind' => 'US06', 'abbreviation' => 'CA']], [], [], []); $this->_import([['United States', 'US']], [['US', 'CA', 'State of California']], [['223', 'US', '', '', '', '38', '-97'], ['2221', 'US', 'CA', '', '', '34.0522', '-118.243']], [['68866048', '68866303', '2221'], ['135422208', '135422463', '2221']], []); $this->_verify([['id' => 1, 'abbreviation' => 'US', 'name' => 'United States']], [['id' => 1, 'countryId' => 1, 'name' => 'State of California', '_maxmind' => 'US06', 'abbreviation' => 'CA']], [], [], [['id' => 1, 'level' => CM_Model_Location::LEVEL_STATE, 'ipStart' => 68866048, 'ipEnd' => 68866303], ['id' => 1, 'level' => CM_Model_Location::LEVEL_STATE, 'ipStart' => 135422208, 'ipEnd' => 135422463]]); }
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')); }
<?php if (CM_Db_Db::existsTable('cm_model_location_city_ip') && !CM_Db_Db::existsTable('cm_model_location_ip')) { CM_Db_Db::exec('RENAME TABLE `cm_model_location_city_ip` TO `cm_model_location_ip`'); } if (CM_Db_Db::existsTable('cm_model_location_ip')) { if (CM_Db_Db::existsIndex('cm_model_location_ip', 'cityId')) { CM_Db_Db::exec('DROP INDEX `cityId` ON `cm_model_location_ip`'); } if (CM_Db_Db::existsColumn('cm_model_location_ip', 'cityId') && !CM_Db_Db::existsColumn('cm_model_location_ip', 'id')) { CM_Db_Db::exec('ALTER TABLE `cm_model_location_ip` CHANGE COLUMN `cityId` `id` int(10) unsigned NOT NULL '); } if (!CM_Db_Db::existsColumn('cm_model_location_ip', 'level')) { CM_Db_Db::exec('ALTER TABLE `cm_model_location_ip` ADD COLUMN `level` int(10) unsigned NOT NULL AFTER `id`'); } if (CM_Db_Db::existsColumn('cm_model_location_ip', 'level')) { CM_Db_Db::update('cm_model_location_ip', array('level' => CM_Model_Location::LEVEL_CITY), array('level' => 0)); } if (CM_Db_Db::existsTable('cm_model_location_country_ip')) { $result = CM_Db_Db::select('cm_model_location_country_ip', array('countryId', 'ipStart', 'ipEnd')); foreach ($result->fetchAll() as $row) { CM_Db_Db::insert('cm_model_location_ip', array('id' => $row['countryId'], 'level' => CM_Model_Location::LEVEL_COUNTRY, 'ipStart' => $row['ipStart'], 'ipEnd' => $row['ipEnd'])); } CM_Db_Db::exec('DROP TABLE `cm_model_location_country_ip`'); } }
/** * @param int $thumbnailCount */ public function setThumbnailCount($thumbnailCount) { $thumbnailCount = (int) $thumbnailCount; CM_Db_Db::update('cm_streamChannel_video', array('thumbnailCount' => $thumbnailCount), array('id' => $this->getId())); $this->_change(); }
public function regenerateId() { $newId = self::_generateId(); if ($this->_isPersistent) { CM_Db_Db::update('cm_session', array('sessionId' => $newId), array('sessionId' => $this->getId())); $this->_change(); } $this->_id = $newId; }
<?php if (CM_Db_Db::existsIndex('cm_svm', 'trainingChanges')) { CM_Db_Db::exec('DROP INDEX `trainingChanges` on `cm_svm`'); } if (CM_Db_Db::existsColumn('cm_svm', 'trainingChanges')) { CM_Db_Db::exec(' ALTER TABLE `cm_svm` DROP COLUMN `trainingChanges`, ADD COLUMN `updateStamp` int(10) unsigned NOT NULL'); CM_Db_Db::update('cm_svm', array('updateStamp' => time())); }