public static function getRowsCount($table, $condition = array()) { Trace::addMessage(__CLASS__, sprintf('getRowsCount. Table:"%s", $condition:%s', $table, print_r($condition, true))); $result = parent::getRowsCount($table, $condition); Trace::addMessage(__CLASS__, 'Rows counting finished'); return $result; }
/** * Возвращает все элементы указанного типа * @return */ protected function selectItem() { $orderBy = ''; if (!empty($this->typeInfo['order'])) { $orderBy = trim($this->typeInfo['order']); } return DBSimple::select($this->typeInfo['table'], null, $orderBy); }
public static function factoryById($id) { $found = DBSimple::get(self::TableName, array('id' => intval($id))); if (empty($found)) { throw new \NotFoundException('Job not found'); } return self::factory($found); }
public function testReSave() { $this->factoryColumn(self::Login); $this->column->setValue(['facebook' => self::UID]); $this->column->onUpdate(new \Extasy\ORM\QueryBuilder('select')); // $this->assertEquals(1, DBSimple::getRowsCount(SocialNetworks::UIDTable)); }
public function testGrant() { ACL::create('test/test2'); ACL::grant('test/test2', 'e1'); $this->assertEquals(1, DBSimple::getRowsCount(ACL_GRANT_TABLE)); $found = DBSimple::get(ACL_GRANT_TABLE, array('actionId' => 2)); $this->assertEquals('e1', $found['entity']); }
/** * @return Job[] */ public function getActual() { $jobData = DBSimple::get(self::TableName, array('status' => Job::NewStatus, 'actionDate <= NOW() '), 'order by `id` asc'); if (!empty($jobData)) { return Job::factory($jobData); } return null; }
public static function getByName($name) { $found = DBSimple::get(self::TableName, array('name' => $name)); if (empty($found)) { throw new \NotFoundException('Unknown social network name - ' . $name); } $result = new Network($found); return $result; }
public static function getLast() { $found = DBSimple::get(\EmailLogModel::getTableName(), '', 'order by id desc'); if (empty($found)) { throw new \NotFoundException('Last log message not found. Log table empty'); } $log = new \EmailLogModel($found); return $log; }
public static function getByName($name) { $found = DBSimple::get(Log::tableName, array('name' => $name)); if (empty($found)) { throw new \NotFoundException('Log record not found'); } $result = new Log($found); return $result; }
public function testAuditRecordCreated() { $fixture = DBSimple::getRowsCount(Record::tableName); // $api = new RestartServer(); $api->exec(); // $this->assertEquals($fixture + 1, DBSimple::getRowsCount(Record::tableName)); }
public static function dbFixture($tableName, $data) { $sql = sprintf(' TRUNCATE `%s` ', $tableName); \Faid\DB::post($sql); // foreach ($data as $row) { \Faid\DBSimple::insert($tableName, $row); } }
/** * * @return multitype:extasyTestModel */ public static function selectAll() { $list = DBSimple::select(self::getTableName(), '', '`id` asc'); $result = array(); foreach ($list as $key => $row) { $result[] = new extasyTestModel($row); } return $result; }
public function testNewTasksNotRestarted() { $job = new TestAction(); $job->insert(); // $api = new Restart(['id' => $job->id->getValue(), 'actionDate' => '']); $api->exec(); // $this->assertEquals(1, DBSimple::getRowsCount(TestAction::TableName)); }
protected function action() { $orderCond = sprintf('id desc limit 0,%d', $this->limit); $data = DBSimple::select(Job::TableName, [], $orderCond); foreach ($data as $key => $row) { $job = Job::factory($row); $data[$key] = $job->getPreviewParseData(); } return $data; }
public function testDeleteAndCheckEntityDeletion() { ACL::create('test/test2/test3'); ACL::grant('test/test2/test3', 'o1'); ACL::grant('test', 'o2'); ACL::remove('test/test2'); $this->assertEquals(1, DBSimple::getRowsCount(ACL_GRANT_TABLE)); // Проверяем, что удалились именно нужные данные $this->assertEquals(true, ACL::isGranted('test', 'o2')); }
/** * Возвращает информацию о скрипте на основании его файла и пути для редактирования в админке */ public static function getScriptByAdminInfo($szPath, $szAdminUrl = '') { $szPath = \Faid\DB::escape($szPath); $szAdminUrl = \Faid\DB::escape($szAdminUrl); $condition = array(sprintf('STRCMP(`script`,"%s") = 0', $szPath)); if (!empty($szAdminUrl)) { $condition[] = sprintf('STRCMP(`script_admin_url`,"%s") = 0', $szAdminUrl); } return DBSimple::get(SITEMAP_TABLE, $condition); }
public function testFactoryMethod() { $job = new TestAction(); $job->insert(); // $row = DBSimple::get(TestAction::TableName, array('id' => $job->id->getValue())); $newJob = Job::factory($row); // $this->AssertEquals(get_class($job), get_class($newJob)); }
public function testGarbageCollection() { $job = new TestAction(); $job->status = Job::FinishedStatus; $job->actionDate = date('Y-m-d H:i:s', strtotime('-1 day')); $job->insert(); $this->assertEquals(1, DBSimple::getRowsCount(Job::TableName)); $runner = new Runner(); $runner->resolveJobs(); $this->assertEquals(0, DBSimple::getRowsCount(Job::TableName)); }
/** * Возвращает все существующие схемы */ public static function selectAll() { $table = CCONFIG_SCHEMA_TABLE; $data = DBSimple::select($table, '', '`title`'); $result = array(); foreach ($data as $row) { // Создаем объект на основе схемы $result[] = new CConfigSchema($row); } return $result; }
protected function loadLastFail() { $lastId = !empty($this->successId) ? $this->successId : 0; $condition = array('user_id' => $this->user->id->getValue(), 'status' => LoginAttempt::FailStatus, sprintf('`id` > "%d"', DB::escape($lastId)), sprintf('`date` < NOW() ')); $this->failCount = DBSimple::getRowsCount(LoginAttempt::TableName, $condition); $last = DBSimple::get(LoginAttempt::TableName, $condition, 'order by `id` desc'); if (!empty($last)) { $model = new LoginAttempt($last); $this->failLastIp = $model->host->getValue(); $this->failLastDate = $model->date->getValue(); } }
protected function createTable() { $sql = <<<SQL create table `test_document` ( \t`id` int not null auto_increment, \t`name` varchar(255 ) not null default '', \tprimary key (`id`) ); SQL; DB::post($sql); DBSimple::insert(Model::TableName, array('name' => 'sitemap document')); }
/** * */ public function testRemoveEntity() { ACL::create('test'); ACL::create('test2'); ACL::create('test3'); ACL::grant('test', 'obj1'); ACL::grant('test2', 'obj2'); ACL::grant('test3', 'obj1'); ACL::removeEntity('obj1'); $this->assertEquals(1, DBSimple::getRowsCount(ACL_GRANT_TABLE)); $this->assertEquals(true, ACL::isGranted('test2', 'obj2')); }
protected function getGroupSelectbox() { $rights = DBSimple::select(ACL_TABLE, 'parentId = 0', '`fullPath` asc'); foreach ($rights as $key => $row) { $rights[$key] = ['id' => $row['fullPath'], 'name' => $row['fullPath']]; } array_unshift($rights, ['id' => 0, 'name' => 'Не выбрано']); $control = new \CSelect(); $control->name = 'group'; $control->values = $rights; return $control->generate(); }
public function testRecordNotAddedInEnableLoggingDisabled() { $initial = DBSimple::getRowsCount(Record::tableName); // $log = Log::getByName('Log1'); $log->setupLogging(false); // $result = Record::add('Log1', '1', '2'); $this->assertTrue(empty($result)); // $result = DBSimple::getRowsCount(Record::tableName); $this->AssertEquals($initial, $result); }
public static function quickRegister($user, $authPassed, $method = 'default') { if (!empty($_SERVER['REMOTE_ADDR'])) { $ip = $_SERVER['REMOTE_ADDR']; if ('::1' == $ip) { $ip = '127.0.0.1'; } } else { $ip = '127.0.0.1'; } $userId = !empty($user) ? $user->id->getValue() : 0; \Faid\DBSimple::insert(self::TableName, array('host' => ip2long($ip), 'date' => date('Y-m-d H:i:s'), 'user_id' => $userId, 'status' => !empty($authPassed) ? self::SuccessStatus : self::FailStatus, 'method' => $method)); \CMSLog::addMessage(__CLASS__, sprintf('Login attemp into user with id="%d", operation status - %s', $userId, !empty($authPassed) ? 'success' : 'fail')); }
public static function export($parentId = 0) { $parentId = IntegerHelper::toNatural($parentId); $result = array(); $data = DBSimple::select(ACL_TABLE, "parentId = '{$parentId}'", '`name` ASC'); foreach ($data as $row) { $children = self::export($row['id']); $add = array('id' => $row['id'], 'name' => $row['name'], 'title' => $row['title'], 'fullPath' => $row['fullPath']); if (!empty($children)) { $add['children'] = $children; } $result[] = $add; } return $result; }
protected static function storeExtraRecords() { \CMSLog::addMessage(__CLASS__, 'Cleaning log table'); $found = DBSimple::select(Record::tableName, array(), sprintf('id desc limit %d,1', self::$maximumLogLength)); if (empty($found)) { return; } $data = DBSimple::select(Record::tableName, '1', sprintf('id asc limit 0,%d', self::$maximumLogLength)); if (!empty($data)) { $lastId = $data[sizeof($data) - 1]['id']; $fileName = sprintf('%s%s%s.log', SYS_ROOT, self::OutputDir, date('Y-m-d H:i:s')); file_put_contents($fileName, json_encode($data)); DBSimple::delete(Record::tableName, array(sprintf('id <= %d', $lastId))); \CMSLog::addMessage(__CLASS__, 'Extra messages exported in local folder: ' . $fileName); } }
protected function getViewedCount() { return DBSimple::getRowsCount(Record::tableName, array('viewed' => '1')); }
protected static function insertIntoBD($szName, $szUrlKey, $szDocument, $nDocumentId, $aParent) { $szName = strip_tags($szName); $szName = \Faid\DB::escape($szName); $szUrlKey = \Faid\DB::escape($szUrlKey); $szDocument = \Faid\DB::escape($szDocument); $nDocumentId = intval($nDocumentId); $condition = array('parent' => $aParent['id']); DBSimple::update('sitemap', '`order` = `order` + 1', $condition); $visible = SystemRegisterHelper::getValue('/System/Sitemap/visible'); $sql = 'INSERT INTO `%s` SET `name`="%s",`url_key`="%s",`document_name`="%s",`document_id`="%d",`parent`="%d",`order`="%d",date_created=NOW(),date_updated=NOW(),revision_count=0, `sitemap_xml_priority` = "0.1", `sitemap_xml_change`="weekly",`visible`="%d"'; $sql = sprintf($sql, SITEMAP_TABLE, $szName, $szUrlKey, $szDocument, $nDocumentId, $aParent['id'], 0, $visible); DB::post($sql); return DB::$connection->insert_id; }
<?php use Faid\DBSimple; use Extasy\Schedule\Job; DBSimple::delete(Job::TableName, array('class' => '\\Extasy\\Users\\Tasks\\CleanLoginAttempts')); $model = new \Extasy\Users\login\LoginAttempt(); $model->createDatabaseTable(true);