public function testDelete() { $language = CM_Model_Language::create('Foo', 'foo', true); $language->setTranslation('foo', 'bar'); $this->assertSame(array('foo' => array('value' => 'bar', 'variables' => array())), $language->getTranslations()->getAssociativeArray()); $languageKey = CM_Model_LanguageKey::findByName('foo'); $languageKey->delete(); $this->assertSame(array(), $language->getTranslations()->getAssociativeArray()); $this->assertSame(0, CM_Db_Db::count('cm_model_languagekey', array('name' => 'foo'))); $this->assertSame(0, CM_Db_Db::count('cm_languageValue', array('languageKeyId' => $languageKey->getId(), 'languageId' => $language->getId()))); }
public function testQueue() { $user = $this->getMock('CM_Model_User', array('getEmail', 'getSite'), array(CMTest_TH::createUser()->getId())); $user->expects($this->any())->method('getEmail')->will($this->returnValue('*****@*****.**')); $user->expects($this->any())->method('getSite')->will($this->returnValue(CM_Site_Abstract::factory())); $msg = new CM_Mail($user, null); $msg->setSubject('testSubject'); $msg->setHtml('<b>hallo</b>'); $msg->addReplyTo('*****@*****.**'); $msg->addCc('*****@*****.**', 'foobar'); $msg->addBcc('*****@*****.**'); $msg->sendDelayed(); $this->assertRow('cm_mail', array('subject' => 'testSubject', 'text' => 'hallo', 'html' => '<b>hallo</b>', 'to' => serialize($msg->getTo()), 'replyTo' => serialize($msg->getReplyTo()), 'cc' => serialize($msg->getCc()), 'bcc' => serialize($msg->getBcc()))); $this->assertEquals(1, CM_Db_Db::count('cm_mail', 'id')); CM_Mail::processQueue(1); $this->assertEquals(0, CM_Db_Db::count('cm_mail', 'id')); }
/** * @return int */ public function getFixtureCount() { return CM_Db_Db::count('cm_splitfeature_fixture', array('splitfeatureId' => $this->getId())); }
/** * @param string $name * @return bool */ public static function exists($name) { $name = (string) $name; return (bool) CM_Db_Db::count('cm_model_languagekey', array('name' => $name)); }
public function testCount() { $this->assertSame(0, CM_Db_Db::count('test')); CM_Db_Db::insert('test', array('bar' => 'bar1', 'sequence' => 1)); $this->assertSame(1, CM_Db_Db::count('test')); }
public function testCreateCountry() { $country = CM_Model_Location::createCountry('Example Country', 'EC'); $this->assertSame(CM_Model_Location::LEVEL_COUNTRY, $country->getLevel()); $this->assertSame(1, CM_Db_Db::count('cm_model_location_country', array('abbreviation' => 'EC'))); $this->assertSame('Example Country', $country->getName()); $this->assertSame('EC', $country->getAbbreviation()); }
/** * @return int */ public static function getQueueSize() { return CM_Db_Db::count('cm_mail'); }
public function testCollapse() { $values[] = array(1, null, 1, 1, null, 1, 1); $values[] = array(1, null, 1, 1, null, 1, 2); $values[] = array(1, null, 1, 1, null, 2, 1); $values[] = array(1, null, 1, 1, null, 3, 1); $values[] = array(1, null, 1, 1, null, 4, 10); $values[] = array(1, null, 1, 1, 1, 4, 10); $values[] = array(1, null, 2, 1, null, 4, 100); $values[] = array(1, null, 1, 2, null, 4, 100); $values[] = array(1, null, 1, 1, null, 5, 100); CM_Db_Db::insert('cm_action', array('actorId', 'ip', 'verb', 'type', 'actionLimitType', 'createStamp', 'count'), $values); CM_Action_Abstract::collapse(1, 4); $this->assertEquals(6, CM_Db_Db::count('cm_action')); $this->assertRow('cm_action', array('verb' => 1, 'type' => 1, 'createStamp' => 2, 'count' => 5)); }
/** * @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(); }
/** * @param string $table * @param string $column * @param int $position * @param array $whereRow Associative array field=>value * @param array|null $where Associative array field=>value * @throws CM_Exception_Invalid */ public static function updateSequence($table, $column, $position, array $whereRow, array $where = null) { $table = (string) $table; $column = (string) $column; $position = (int) $position; if (null === $where) { $where = array(); } if ($position <= 0 || $position > CM_Db_Db::count($table, $where)) { throw new CM_Exception_Invalid('Sequence out of bounds.'); } $whereMerged = array_merge($whereRow, $where); $positionOld = CM_Db_Db::select($table, $column, $whereMerged)->fetchColumn(); if (false === $positionOld) { throw new CM_Exception_Invalid('Could not retrieve original sequence number.'); } $positionOld = (int) $positionOld; if ($position > $positionOld) { $upperBound = $position; $lowerBound = $positionOld; $direction = -1; } else { $upperBound = $positionOld; $lowerBound = $position; $direction = 1; } $client = self::getClient(); $query = new CM_Db_Query_UpdateSequence($client, $table, $column, $direction, $where, $lowerBound, $upperBound); $query->execute(); self::update($table, array($column => $position), $whereMerged); }
/** * @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 int $id * @return null|static */ public static function findById($id) { if (!CM_Db_Db::count('cm_streamChannelArchive_video', array('id' => $id))) { return null; } return new static($id); }