protected function storeFull($json) { $categories = json_decode($json, true); // grab categories from the database $dbCategories = collect(DB::table('categories')->get(['cSlug']))->keyBy('cSlug')->toArray(); // grab an array of columns in the categories table $columns = DB::select('select COLUMN_NAME as `column` from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = \'fmtc_categories\''); // set the counters for reporting $insertCount = 0; $removeCount = 0; // walk through the categories from a merchant feed $jsonCategoryIds = []; foreach ($categories as $category) { // is the category missing from the database? if (!isset($dbCategories[$category['cSlug']])) { // insert it (this is faster than building an insert queue and bulk inserting) DB::table('categories')->insert($this->formatForInsertion($category, $columns)); $insertCount++; } // collect an array of ids to aid in the remove queue $jsonCategoryIds[] = $category['cSlug']; } // remove old categories showing up in the database but not in the new merchant feed. $removeQueue = array_diff(array_keys($dbCategories), $jsonCategoryIds); $removeCount = count($removeQueue); foreach ($removeQueue as $categoryId) { DB::table('categories')->where('cSlug', $categoryId)->delete(); } //---- debugging // debug($removeCount . ' removed'); // debug($insertCount . ' inserted'); //----- return true; }
public function test_sessions_sweep_when_hits_lottery() { $config = ['sessions.driver' => 'database']; $this->dispatch($config); $rec = $this->capsule->getConnection()->table('sessions')->get(); $this->assertSame(1, count($rec)); $config['sessions.lifetime'] = 0; $config['sessions.lottery'] = [1, 1]; // 100% hits $this->dispatch($config); $rec = $this->capsule->table('sessions')->get(); $this->assertEmpty($rec); }
private function validateUnique($item, $value, $parameter) { $results = DB::table($parameter)->where($item, '=', $value)->get(); if (sizeof($results) > 0) { $this->errors[] = $item . ' already exists on this system.'; } }
protected function seedData() { $faker = $this->getFaker(); for ($i = 0; $i < $this->count; $i++) { DB::table('tests')->insert(['title' => $faker->title, 'seq' => $i + 1, 'created_at' => $faker->dateTime(), 'updated_at' => $faker->dateTime()]); } }
/** * For raw array fetching. Must be static, otherwise PHP gets confused about where to find the table_id. */ public static function queryBuilder() { // Set query builder to fetch result sets as associative arrays (instead of creating stdClass objects) Capsule::connection()->setFetchMode(\PDO::FETCH_ASSOC); $table = Database::getSchemaTable(static::$_table_id)->name; return Capsule::table($table); }
public function acceptFriendRequest($token, $requestId) { $user = new User(); $meId = $user->getMeId($token); try { $requestData = Capsule::table('friendrequests')->select('userFrom', 'userTo')->where('id', $requestId)->first(); if ($requestData->userFrom == $meId) { $newFriendId = $requestData->userTo; } else { $newFriendId = $requestData->userFrom; } } catch (\Exception $e) { throw new \Exception('Wystąpił błąd przy pobieraniu przyjaciół'); } if ($user->isUserMyFriend($newFriendId, $token)) { throw new \Exception('Ten użytkownik jest już Twoim znajomym'); } try { Capsule::table('friendrequests')->where('id', $requestId)->where('userFrom', $meId)->orWhere('userTo', $meId)->where('accepted', 0)->update(array('accepted' => 1)); Capsule::table('friends')->insert(array('userA' => $meId, 'userB' => $newFriendId)); } catch (\Exception $e) { throw new \Exception('Wystąpił błąd przy pobieraniu przyjaciół'); } $newFriendData = $user->getUser($newFriendId, $token); return $newFriendData; }
public function testSerialize() { $eloquentDriver = new EloquentDriver(); $output = $eloquentDriver->serialize(Capsule::table('users')->find(1)); $expected = array('@type' => 'stdClass', 'id' => array('@scalar' => 'string', '@value' => '1'), 'account_manager_id' => array('@scalar' => 'string', '@value' => '1'), 'username' => array('@scalar' => 'string', '@value' => 'Nil'), 'password' => array('@scalar' => 'string', '@value' => 'password'), 'email' => array('@scalar' => 'string', '@value' => '*****@*****.**'), 'created_at' => array('@scalar' => 'string', '@value' => '2016-01-13 00:06:16'), 'updated_at' => array('@scalar' => 'string', '@value' => '2016-01-13 00:06:16'), 'deleted_at' => array('@scalar' => 'NULL', '@value' => null)); $this->assertEquals($expected, $output); }
protected function seedData() { $faker = $this->getFaker(); for ($i = 1; $i <= $this->count; $i++) { DB::table('tests')->insert(['title' => $faker->title, 'seq' => $i, 'created_at' => $i > 5 ? (new DateTime('2005-01-01'))->format('Y-m-d H:i:s') : (new DateTime('1998-01-01'))->format('Y-m-d H:i:s'), 'updated_at' => $faker->dateTime()]); } }
/** * Check to see some data in the database */ protected function seeInDatabase($table, $data) { $conditions = []; foreach ($data as $key => $value) { $conditions[] = [$key, $value]; } $this->assertTrue(DB::table($table)->where($conditions)->count() > 0); }
public function getBySearch($search) { $networks = DB::table('networks')->where(function ($query) use($search) { $search = '%' . $search . '%'; $query->where('cSlug', 'like', $search)->orWhere('aCountries', 'like', $search)->orWhere('cName', 'like', $search); })->get(); return $networks; }
protected function formatDealForReturn($deal) { // attach it's categories $deal->aCategories = DB::table('deals_categories')->where('deals_categories.nCouponID', $id)->join('categories', 'categories.cSlug', '=', 'deals_categories.cCategorySlug')->get(); // attach it's types $deal->aTypes = DB::table('deals_types')->where('deals_types.nCouponID', $id)->join('types', 'types.cSlug', '=', 'deals_types.cTypeSlug')->get(); return $deal; }
public function run() { DB::table('posts')->delete(); Post::unguard(); Post::create(['id' => 1, 'title' => 'First post', 'body' => 'This is the first post!']); Post::create(['id' => 2, 'title' => 'Second post', 'body' => 'This is the second post!']); Post::reguard(); }
public function getBySearch($search) { $merchants = DB::table('merchants')->where(function ($query) use($search) { $search = '%' . $search . '%'; $query->where('nMerchantID', 'like', $search)->orWhere('nMasterMerchantID', 'like', $search)->orWhere('cName', 'like', $search); })->get(); return $merchants; }
public function getBySearch($search) { $types = DB::table('types')->where(function ($query) use($search) { $search = '%' . $search . '%'; $query->where('cSlug', 'like', $search)->orWhere('cName', 'like', $search); })->get(); return $types; }
public static function gen() { $id = Capsule::table('uid')->insertGetId(array()); if (!$id) { throw new Exception("Could not generate UID!"); } return $id; }
public function testUnchainedQueryBuilder() { $this->databaseInitSimple(); $query = \Illuminate\Database\Capsule\Manager::table('captains'); $query->where('last_name', 'Kirk'); $result = (object) $query->first(); $this->assertEquals('James', $result->first_name); }
/** * {@inheritdoc} */ public function get($scope, $grantType = null, $clientId = null) { $result = Capsule::table('oauth_scopes')->where('id', $scope)->get(); if (count($result) === 0) { return; } return (new ScopeEntity($this->server))->hydrate(['id' => $result[0]['id'], 'description' => $result[0]['description']]); }
public function run() { DB::table('users')->delete(); User::unguard(); User::create(['id' => 1]); User::create(['id' => 2]); User::reguard(); }
public function updateRadius() { Capsule::transaction(function () { Capsule::table('radcheck')->where('username', $this->user)->delete(); Capsule::table('radreply')->where('username', $this->user)->delete(); Capsule::table('radcheck')->insert($this->check); Capsule::table('radreply')->insert($this->reply); }); }
/** * {@inehritDoc} * Overriden from parent to use Illuminate/database for querying. * @return array applied migration entries */ protected function getMigrationHistory() { $history = []; $rows = Manager::table('migration')->get(); foreach ($rows as $row) { $history[] = ['version' => $row->version, 'apply_time' => $row->apply_time]; } return $history; }
public function testPaginationWithLaravelAdapter() { $records = Capsule::table('sample'); $expected = Capsule::table('sample')->limit(20)->offset(60)->get(); $paginatorClass = new Paginator(); $paginator = $paginatorClass->page(4)->perPage(20)->make($records); $this->assertEquals(100, $paginator->total(), 'Failed asserting pagination total.'); $this->assertEquals($expected, $paginator->records(), 'Failed asserting pagination records.'); }
public function isFirstRun() { $users = Capsule::table('users')->count(); if ($users === 0) { return true; } else { return false; } }
public static function getByUser($userId, $page) { $result = Capsule::table(Comment::TABLE_NAME)->where('userId', '=', $userId)->orderBy('date', 'desc')->skip(10 * ($page - 1))->take(10)->get(); foreach ($result as $item) { $item->promo = Promo::query()->where('id', '=', $item->promoId)->first(['id', 'title', 'thumbnail']); unset($item->promoId); } return $result; }
/** @test */ public function it_implements_identity_interface_correctly() { $userId = Manager::table('users')->insertGetId(['username' => 'test', 'auth_key' => 'foobar']); $user = User::findIdentity($userId); $this->assertEquals($userId, $user->getId()); $this->assertEquals($user->getAuthKey(), 'foobar'); $this->assertTrue($user->validateAuthKey('foobar')); $this->assertFalse($user->validateAuthKey('foobaz')); }
public function getCustid($token) { $userid = $this->getUserid($token); $result = Capsule::table('users')->select('custid')->where('userid', $userid)->get(); if (count($result) === 1) { return $result[0]->custid; } else { return 0; } }
public function run() { DB::table('users')->delete(); User::unguard(); User::create(array('id' => 1, 'name' => 'User 1')); User::create(array('id' => 2, 'name' => 'User 2')); User::create(array('id' => 3, 'name' => 'User 3')); User::create(array('id' => 4, 'name' => 'User 4')); User::reguard(); }
private function isConversationBetweenUsers($userA, $userB) { $topicId = Capsule::table('messagestopics')->select('id')->whereIn('userFrom', array($userA, $userB))->whereIn('userTo', array($userA, $userB))->first(); if (!$topicId) { $topicId = false; } else { $topicId = $topicId->id; } return $topicId; }
public function getById($id) { $this->id = $id; $deocanry = DB::table("espereskerulet")->select("*")->where("id", "=", $this->id)->limit(1)->get(); if (!count($deocanry)) { throw new Exception("There is no deocanry with id = '{$id}'"); } $this->name = $deocanry[0]->nev . " espereskerület"; $this->shortname = $deocanry[0]->nev; }
/** * {@inheritdoc} */ public function getBySession(SessionEntity $session) { $result = Capsule::table('oauth_clients')->select(['oauth_clients.id', 'oauth_clients.name'])->join('oauth_sessions', 'oauth_clients.id', '=', 'oauth_sessions.client_id')->where('oauth_sessions.id', $session->getId())->get(); if (count($result) === 1) { $client = new ClientEntity($this->server); $client->hydrate(['id' => $result[0]['id'], 'name' => $result[0]['name']]); return $client; } return; }
public function getByChurchId($id) { $result = DB::table('templomok')->join('terkep_geocode as geo', 'geo.tid', '=', 'templomok.id', 'left')->join('varosok', 'varosok.nev', '=', 'templomok.varos', 'left')->select('templomok.*', 'geo.lat', 'geo.lng', 'geo.checked', 'geo.address2', 'varosok.irsz')->where('templomok.id', "=", $id)->limit(1)->get(); if (!count($result)) { throw new Exception("There is no church with tid = '{$id}' (location)."); } $acceptedColumns = array('orszag', 'megye', 'varos', 'cim', 'megkozelites', 'lat', 'lng', 'checked', 'address2', 'irsz'); foreach ($acceptedColumns as $column) { $this->{$column} = $result[0]->{$column}; } }