public static findOne ( string $type, string $sql = NULL, array $bindings = [] ) : OODBBean | ||
$type | string | the type of bean you are looking for |
$sql | string | SQL query to find the desired bean, starting right after WHERE clause |
$bindings | array | array of values to be bound to parameters in query |
Результат | OODBBean |
/** * Test whether we can override the getModelForBean() method * of the BeanHelper and use a custom BeanHelper to attach a model * based on type. * * @return void */ public function testCustomBeanHelper() { $customBeanHelper = new \SoupBeanHelper(R::getToolbox()); $oldBeanHelper = R::getRedBean()->getBeanHelper(); asrt($oldBeanHelper instanceof SimpleFacadeBeanHelper, TRUE); R::getRedBean()->setBeanHelper($customBeanHelper); $meal = R::dispense('meal'); asrt($meal->box() instanceof \Model_Soup, TRUE); $cake = R::dispense('cake'); asrt(is_null($cake->box()), TRUE); $bean = R::dispense('coffee'); asrt($bean->box() instanceof \Model_Coffee, TRUE); $meal->setFlavour('tomato'); asrt($meal->getFlavour(), 'tomato'); $meal->rating = 5; R::store($meal); asrt($meal->getFlavour(), 'tomato'); $meal = $meal->unbox(); asrt($meal->getFlavour(), 'tomato'); $meal = R::findOne('meal'); asrt($meal->box() instanceof \Model_Soup, TRUE); asrt($meal->getFlavour(), ''); $meal->setFlavour('tomato'); asrt($meal->getFlavour(), 'tomato'); $meal = $meal->unbox(); asrt($meal->getFlavour(), 'tomato'); R::getRedBean()->setBeanHelper($oldBeanHelper); }
/** * Test whether we can set the 'auto clear' * option in OODB. * * @return void */ public function testAutoClearHistory() { testpack('Auto clear history'); $book = R::dispense('book'); $book->pages = 100; $book->title = 'book'; R::store($book); $book = R::findOne('book'); asrt($book->hasChanged('title'), FALSE); $book->title = 'yes'; R::store($book); asrt($book->hasChanged('title'), TRUE); OODB::autoClearHistoryAfterStore(TRUE); $book = R::findOne('book'); asrt($book->hasChanged('title'), FALSE); $book->title = 'yes2'; R::store($book); asrt($book->hasChanged('title'), FALSE); OODB::autoClearHistoryAfterStore(FALSE); $book = R::findOne('book'); asrt($book->hasChanged('title'), FALSE); $book->title = 'yes'; R::store($book); asrt($book->hasChanged('title'), TRUE); }
/** * Logs admin into the system * @param $login * @param $password * @return \SkullyAdmin\Models\Admin|null */ public function login($login, $password) { /** @var \RedBean_SimpleModel $adminBean */ $adminBean = R::findOne('admin', "status = ? and email = ?", array(Admin::STATUS_ACTIVE, $login)); if (!empty($adminBean)) { /** @var \SkullyAdmin\Models\Admin $admin */ $admin = $adminBean->box(); if ($admin->get('password_hash') == UtilitiesHelper::toHash($password, $admin->get('salt'), $this->app->config('globalSalt'))) { $adminSessions = R::find('adminsession', "admin_id = ?", array($admin->getID())); if (!empty($adminSessions)) { R::trashAll($adminSessions); } // when everything ok, regenerate session session_regenerate_id(true); // change session ID for the current session and invalidate old session ID $adminId = $admin->getID(); $sessionId = session_id(); $adminsession = $this->app->createModel('adminsession', array("admin_id" => $adminId, "session_id" => $sessionId)); $this->app->getSession()->set('adminId', $admin->getID()); R::store($adminsession); return $admin; } } return null; }
public function uploadImage() { $error = ''; $uploadedImages = array(); if (isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") { // Find instance $id = $this->getParam($this->instanceName . '_id'); if (!empty($id)) { /** @var \RedbeanPHP\SimpleModel $instanceBean */ $instanceBean = R::findOne($this->model(), 'id = ?', array($id)); /** @var \Skully\App\Models\Setting $instance */ $instance = $instanceBean->box(); } else { $instance = null; } try { $uploadedImages = $this->processUploadedImage($instance, $this->getParam('settingName')); } catch (\Exception $e) { $error = $e->getMessage(); } } if (!empty($error)) { echo json_encode(array('error' => $error)); } else { echo json_encode($uploadedImages); } }
public function testCreateAdmin() { $this->migrate(); $admin = $this->app->createModel('admin', array('name' => 'Admin', 'email' => '*****@*****.**', 'password' => 'lepass', 'password_confirmation' => 'lepass', 'status' => Admin::STATUS_ACTIVE)); R::store($admin); $bean = R::findOne('admin', 'name = ?', array('Admin')); $this->assertEquals($bean->name, $admin->get('name')); }
function equipe($slug) { global $twig, $base, $titre; $personne = R::findOne("personnes", "slug = ?", [$slug]); if (!$personne) { return not_found(); } return $twig->render("equipe.html", compact("base", "titre", "personne")); }
public function getAdmin() { /** @var \RedBean_SimpleModel $adminBean */ $adminBean = R::findOne('admin', "id = ?", array($this->getSession()->get('adminId'))); if (!empty($adminBean)) { return $adminBean->box(); } else { return null; } }
/** * Test to make sure stash cache works with recursively opening models * with FUSE. * * @return void */ public function testIssue259() { testpack('Testing Issue #259 - Stash Cache breaks model delegation in open().'); $mother = R::dispense('mother'); $mother->desc = 'I am mother'; R::store($mother); $child = R::dispense('child'); $child->mother = $mother; $child->desc = 'I am child'; $id = R::store($child); R::findOne('child', ' id = ?', array($id)); R::find('child', ' id = ? ', array($id)); R::load('child', $id); }
/** * Test Null bindings. */ public function testBindings() { R::nuke(); $book = R::dispense('book'); $book->content = NULL; //can we store a NULL? asrt(is_null($book->content), TRUE); R::store($book); //did we really store the NULL value ? $book = R::findOne('book', ' content IS NULL '); asrt($book instanceof OODBBean, TRUE); //still NULL, not empty STRING ? asrt(is_null($book->content), TRUE); $book->pages = 100; R::store($book); //did we save it once again as NULL? $book = R::findOne('book', ' content IS NULL '); asrt($book instanceof OODBBean, TRUE); asrt(is_null($book->content), TRUE); asrt(gettype($book->pages), 'string'); $otherBook = R::dispense('book'); $otherBook->pages = 99; //also if the column is VARCHAR-like? $otherBook->content = 'blah blah'; R::store($otherBook); $book = R::findOne('book', ' content IS NULL '); asrt($book instanceof OODBBean, TRUE); asrt(is_null($book->content), TRUE); asrt(intval($book->pages), 100); //can we query not NULL as well? $book = R::findOne('book', ' content IS NOT NULL '); asrt($book instanceof OODBBean, TRUE); asrt(is_null($book->content), FALSE); asrt(intval($book->pages), 99); asrt($book->content, 'blah blah'); //Can we bind NULL directly? $book->isGood = FALSE; //Is NULL the default? And... no confusion with boolean FALSE? R::store($book); $book = R::findOne('book', ' is_good IS NULL'); asrt($book instanceof OODBBean, TRUE); asrt(is_null($book->content), TRUE); asrt(intval($book->pages), 100); $book = R::findOne('book', ' is_good = ?', array(0)); asrt($book instanceof OODBBean, TRUE); asrt(is_null($book->content), FALSE); asrt(intval($book->pages), 99); }
/** * In the past it was not possible to export beans * like 'feed' (Model_Feed). * * @return void */ public function testExportIssue() { R::nuke(); $feed = R::dispense('feed'); $feed->post = array('first', 'second'); R::store($feed); $rows = R::getAll('SELECT * FROM feed'); asrt($rows[0]['post'], '["first","second"]'); $feed = $feed->fresh(); asrt(is_array($feed->post), TRUE); asrt($feed->post[0], 'first'); asrt($feed->post[1], 'second'); R::store($feed); $rows = R::getAll('SELECT * FROM feed'); asrt($rows[0]['post'], '["first","second"]'); $feed = R::load('feed', $feed->id); $feed->post[] = 'third'; R::store($feed); $rows = R::getAll('SELECT * FROM feed'); asrt($rows[0]['post'], '["first","second","third"]'); $feed = $feed->fresh(); asrt(is_array($feed->post), TRUE); asrt($feed->post[0], 'first'); asrt($feed->post[1], 'second'); asrt($feed->post[2], 'third'); //now the catch: can we use export? //PHP Fatal error: Call to a member function export() on a non-object $feeds = R::exportAll(R::find('feed')); asrt(is_array($feeds), TRUE); $feed = reset($feeds); asrt($feed['post'][0], 'first'); asrt($feed['post'][1], 'second'); asrt($feed['post'][2], 'third'); //can we also dup()? $feedOne = R::findOne('feed'); R::store(R::dup($feedOne)); asrt(R::count('feed'), 2); //can we delete? R::trash($feedOne); asrt(R::count('feed'), 1); $feedTwo = R::findOne('feed'); $feed = $feedTwo->export(); asrt($feed['post'][0], 'first'); asrt($feed['post'][1], 'second'); asrt($feed['post'][2], 'third'); }
/** * @return \Skully\App\Models\Session */ public function getSessionModel() { //read session with current session id // todo: empty($this->sessionModel) is required to keep connection to db as low as possible, // but somehow enabling this make session disappears on new page. // if(empty($this->sessionModel)){ //echo "try to find with session id: ". session_id() . "\n"; $sessionId = session_id(); $sessionBean = R::findOne('session', "session_id = ?", array($sessionId)); if (empty($sessionBean)) { //echo "create with session id: ". session_id()."\n"; $this->sessionModel = $this->app->createModel('session', array("session_id" => $sessionId)); R::store($this->sessionModel); //echo "after creation, session model is".get_class($this->sessionModel)."\n"; } else { $this->sessionModel = $sessionBean->box(); } // } // else { //echo "this sessionModel not empty, data is ".$this->sessionModel->get('data'); // } return $this->sessionModel; }
/** * Test basic operations in frozen mode. */ public function testBasicOperationsFrozen() { R::nuke(); $author = R::xdispense(AUTHOR); $author->name = 'Mr. Quill'; $book = R::xdispense(BOOK); $book->title = 'Good Stories'; $book2 = R::xdispense(BOOK); $book2->title = 'Good Stories 2'; $friend = R::xdispense(FRIEND); $friend->name = 'Muse'; $publisher = R::xdispense(PUBLISHER); $publisher->name = 'Good Books'; $author->{BOOKLIST} = array($book, $book2); $author->{FRIENDLIST}[] = $friend; $author->{PUBLISHER} = $publisher; $coAuthor = R::xdispense(AUTHOR); $coAuthor->name = 'Xavier'; $book2->{COAUTHOR} = $coAuthor; R::store($author); R::freeze(TRUE); asrt($author->name, 'Mr. Quill'); asrt(count($author->{BOOKLIST}), 2); $firstBook = reset($author->{BOOKLIST}); asrt($firstBook->title, 'Good Stories'); asrt(count($author->{FRIENDLIST}), 1); $firstFriend = reset($author->{FRIENDLIST}); $parent = $author->{PUBLISHER}; asrt($parent instanceof OODBBean, TRUE); $tables = R::inspect(); //have all tables been prefixed? foreach ($tables as $table) { asrt(strpos($table, 'tbl_'), 0); } //Can we make an export? $export = R::exportAll(R::findOne(AUTHOR), TRUE); $export = reset($export); asrt(isset($export[PUBLISHER]), TRUE); asrt(isset($export[BOOKLIST]), TRUE); asrt(isset($export[FRIENDLIST]), TRUE); asrt(isset($export['ownBook']), FALSE); asrt(isset($export['sharedFriend']), FALSE); asrt(isset($export['publisher']), FALSE); R::freeze(FALSE); }
$cost_sheet = R::dispense('costsheet'); $cost_sheet->month = $faker->month; $cost_sheet->visitor = R::findOne('visitor', 'id=?', [$faker->numberBetween($min = 1, $max = 540)]); $cost_sheet->status = R::findOne('status', 'id=?', [$faker->numberBetween($min = 1, $max = 5)]); $cost_sheet->justification_number = $faker->randomDigitNotNull; $cost_sheet->valid_amount = $faker->randomNumber($nbDigits = 3); $cost_sheet->modification_date = $faker->dateTime($max = 'now'); R::store($cost_sheet); } for ($i = 0; $i < 20; $i++) { $package_cost = R::dispense('packagecost'); $package_cost->libelle = $faker->realText($maxNbChars = 20, $indexSize = 2); $package_cost->amount = $faker->randomNumber($nbDigits = 3); R::store($package_cost); } for ($i = 0; $i < 1000; $i++) { $outpackage_line = R::dispense('outpackageline'); $outpackage_line->date = $faker->dateTime($max = 'now'); $outpackage_line->cost_sheet = R::findOne('costsheet', 'id=?', [$faker->numberBetween($min = 1, $max = 12960)]); $outpackage_line->amount = $faker->randomNumber($nbDigits = 3); $outpackage_line->libelle = $faker->realText($maxNbChars = 20, $indexSize = 2); R::store($outpackage_line); } for ($i = 0; $i < 129600; $i++) { $package_line = R::dispense('packageline'); $package_line->package_cost = R::findOne('packagecost', 'id=?', [$faker->numberBetween($min = 1, $max = 20)]); $package_line->cost_sheet = R::findOne('costsheet', 'id=?', [$faker->numberBetween($min = 1, $max = 12960)]); $package_line->month = $faker->month; $package_line->quantity = $faker->randomNumber($nbDigits = 3); R::store($package_line); }
/** * Test common Facade usage scenarios. * * @return void */ public function testCommonUsageFacade() { $toolbox = R::getToolBox(); $adapter = $toolbox->getDatabaseAdapter(); $writer = $toolbox->getWriter(); $redbean = $toolbox->getRedBean(); $pdo = $adapter->getDatabase(); $a = new AssociationManager($toolbox); asrt(R::getRedBean() instanceof OODB, TRUE); asrt(R::getToolBox() instanceof ToolBox, TRUE); asrt(R::getDatabaseAdapter() instanceof Adapter, TRUE); asrt(R::getWriter() instanceof QueryWriter, TRUE); $book = R::dispense("book"); asrt($book instanceof OODBBean, TRUE); $book->title = "a nice book"; $id = R::store($book); asrt($id > 0, TRUE); $book = R::load("book", (int) $id); asrt($book->title, "a nice book"); asrt(R::load('book', 999)->title, NULL); R::freeze(TRUE); try { R::load('bookies', 999); fail(); } catch (\Exception $e) { pass(); } R::freeze(FALSE); $author = R::dispense("author"); $author->name = "me"; R::store($author); $book9 = R::dispense("book"); $author9 = R::dispense("author"); $author9->name = "mr Nine"; $a9 = R::store($author9); $book9->author_id = $a9; $bk9 = R::store($book9); $book9 = R::load("book", $bk9); $author = R::load("author", $book9->author_id); asrt($author->name, "mr Nine"); R::trash($author); R::trash($book9); pass(); $book2 = R::dispense("book"); $book2->title = "second"; R::store($book2); $book3 = R::dispense("book"); $book3->title = "third"; R::store($book3); asrt(count(R::find("book")), 3); asrt(count(R::findAll("book")), 3); asrt(count(R::findAll("book", " LIMIT 2")), 2); asrt(count(R::find("book", " id=id ")), 3); asrt(count(R::find("book", " title LIKE ?", array("third"))), 1); asrt(count(R::find("book", " title LIKE ?", array("%d%"))), 2); // Find without where clause asrt(count(R::findAll('book', ' order by id')), 3); R::trash($book3); R::trash($book2); asrt(count(R::getAll("SELECT * FROM book ")), 1); asrt(count(R::getCol("SELECT title FROM book ")), 1); asrt((int) R::getCell("SELECT 123 "), 123); $book = R::dispense("book"); $book->title = "not so original title"; $author = R::dispense("author"); $author->name = "Bobby"; R::store($book); $aid = R::store($author); $author = R::findOne("author", " name = ? ", array("Bobby")); }
/** * Test Facade bind function method. * Test for MySQL WKT spatial format. */ public function testFunctionFilters() { R::nuke(); R::bindFunc('read', 'location.point', 'asText'); R::bindFunc('write', 'location.point', 'GeomFromText'); R::store(R::dispense('location')); R::freeze(true); try { R::find('location'); fail(); } catch (SQL $exception) { pass(); } R::freeze(false); try { R::find('location'); pass(); } catch (SQL $exception) { fail(); } $location = R::dispense('location'); $location->point = 'POINT(14 6)'; R::store($location); $columns = R::inspect('location'); asrt($columns['point'], 'point'); $location = $location->fresh(); asrt($location->point, 'POINT(14 6)'); R::nuke(); $location = R::dispense('location'); $location->point = 'LINESTRING(0 0,1 1,2 2)'; R::store($location); $columns = R::inspect('location'); asrt($columns['point'], 'linestring'); $location->bustcache = 2; R::store($location); $location = $location->fresh(); asrt($location->point, 'LINESTRING(0 0,1 1,2 2)'); R::nuke(); $location = R::dispense('location'); $location->point = 'POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7,5 5))'; R::store($location); $columns = R::inspect('location'); asrt($columns['point'], 'polygon'); $location->bustcache = 4; R::store($location); $location = $location->fresh(); asrt($location->point, 'POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7,5 5))'); R::bindFunc('read', 'location.point', NULL); $location->bustcache = 1; R::store($location); $location = $location->fresh(); asrt($location->point === 'POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7,5 5))', FALSE); $filters = AQueryWriter::getSQLFilters(); asrt(is_array($filters), TRUE); asrt(count($filters), 2); asrt(isset($filters[QueryWriter::C_SQLFILTER_READ]), TRUE); asrt(isset($filters[QueryWriter::C_SQLFILTER_WRITE]), TRUE); R::bindFunc('read', 'place.point', 'asText'); R::bindFunc('write', 'place.point', 'GeomFromText'); R::bindFunc('read', 'place.line', 'asText'); R::bindFunc('write', 'place.line', 'GeomFromText'); R::nuke(); $place = R::dispense('place'); $place->point = 'POINT(13.2 666.6)'; $place->line = 'LINESTRING(9.2 0,3 1.33)'; R::store($place); $columns = R::inspect('place'); asrt($columns['point'], 'point'); asrt($columns['line'], 'linestring'); $place = R::findOne('place'); asrt($place->point, 'POINT(13.2 666.6)'); asrt($place->line, 'LINESTRING(9.2 0,3 1.33)'); R::bindFunc('read', 'place.point', NULL); R::bindFunc('write', 'place.point', NULL); R::bindFunc('read', 'place.line', NULL); R::bindFunc('write', 'place.line', NULL); }
public function reorder() { // Reorder positions first to fix broken data R::exec("SET @ordering = 0;"); R::exec("UPDATE {$this->model()} SET\n\t\t position = (@ordering := @ordering + 1)\n\t\t ORDER BY {$this->dragField}, id ASC"); $toPosition = $this->params['toPosition']; $fromPosition = $this->params['fromPosition']; $direction = $this->params['direction']; $id = $this->params['id']; /** @var \RedBeanPHP\SimpleModel $instanceBean */ $instanceBean = R::findOne($this->model(), 'id = ?', array($id)); if (!empty($instanceBean)) { /** @var \Skully\App\Models\BaseModel $instance */ $instance = $instanceBean->box(); if ($direction == 'back') { // Adds all rows after this one's final position by 1 $sql = "UPDATE `{$this->model()}`\n \t\t\t SET `{$this->dragField}` = `{$this->dragField}` + 1\n \t\t\t WHERE `{$this->dragField}` >= '" . $toPosition . "'\n \t\t\t AND `{$this->dragField}` < '{$fromPosition}'"; } else { // Reduce all rows before this one's final position by 1 $sql = "UPDATE `{$this->model()}`\n \t\t\t SET `{$this->dragField}` = `{$this->dragField}` - 1\n \t\t\t WHERE `{$this->dragField}` > '" . $fromPosition . "'\n \t\t\t AND `{$this->dragField}` <= '{$toPosition}'"; } R::exec($sql); $instance->set($this->dragField, $toPosition); try { R::store($instance); } catch (\Exception $e) { $message = $e->getMessage(); if (!empty($message)) { $instance->addError($message); } $this->app->getLogger()->log("error happened when updating from CRUDController (model " . $this->model() . "): " . $message); $this->app->getLogger()->debugBacktrace(); $this->app->getLogger()->log("params are: " . print_r($this->getParams(), true)); } } }
/** * test N-M relations through intermediate beans * * @return void */ public function testNMRelationsIntermediate() { list($mrA, $mrB, $mrC) = R::dispense('person', 3); list($projA, $projB, $projC) = R::dispense('project', 3); $projA->title = 'A'; $projB->title = 'B'; $projC->title = 'C'; $participant = R::dispense('participant'); $projA->link('participant', array('role' => 'manager'))->person = $mrA; $projA->link($participant->setAttr('role', 'developer'))->person = $mrB; $projB->link(R::dispense('participant')->setAttr('role', 'developer'))->person = $mrB; $projB->link('participant', '{"role":"helpdesk"}')->person = $mrC; $projC->link('participant', '{"role":"sales"}')->person = $mrC; R::storeAll(array($projA, $projB, $projC)); $a = R::findOne('project', ' title = ? ', array('A')); $b = R::findOne('project', ' title = ? ', array('B')); $c = R::findOne('project', ' title = ? ', array('C')); asrt(count($a->ownParticipant), 2); asrt(count($b->ownParticipant), 2); asrt(count($c->ownParticipant), 1); $managers = $developers = 0; foreach ($a->ownParticipant as $p) { if ($p->role === 'manager') { $managers++; } if ($p->role === 'developer') { $developers++; } } $p = reset($a->ownParticipant); asrt($p->person->getMeta('type'), 'person'); asrt($p->person->id > 0, TRUE); asrt($managers, 1); asrt($developers, 1); asrt((int) R::count('participant'), 5); asrt((int) R::count('person'), 3); }
/** * Test query counter. * * @return void */ public function testQueryCount() { R::nuke(); R::store(R::dispense('bean')); R::resetQueryCount(); asrt(R::getQueryCount(), 0); R::findOne('bean'); asrt(R::getQueryCount(), 1); R::resetQueryCount(); asrt(R::getQueryCount(), 0); R::findOne('bean'); R::findOne('bean'); R::findOne('bean'); asrt(R::getQueryCount(), 0); R::store(R::dispense('bean2')); R::resetQueryCount(); R::findOne('bean'); R::findOne('bean2'); asrt(R::getQueryCount(), 2); R::resetQueryCount(); R::findOne('bean', ' id < 100'); R::findOne('bean', ' id < 101'); R::findOne('bean', ' id < 102'); R::findOne('bean', ' id < 103'); asrt(R::getQueryCount(), 4); R::findOne('bean', ' id < 100'); R::findOne('bean', ' id < 101'); R::findOne('bean', ' id < 102'); R::findOne('bean', ' id < 103'); asrt(R::getQueryCount(), 4); R::findOne('bean', ' id < 104'); asrt(R::getQueryCount(), 5); }
/** * Test BIG INT primary key support. * * @return void */ public function testBigIntSupport() { R::nuke(); $createPageTableSQL = ' CREATE TABLE `page` ( id BIGINT(20) UNSIGNED NOT NULL, book_id BIGINT(20) UNSIGNED NOT NULL, magazine_id BIGINT(20) UNSIGNED NOT NULL, title VARCHAR(255), PRIMARY KEY ( id ) ) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci AUTO_INCREMENT = 1223372036854775808'; $createBookTableSQL = ' CREATE TABLE `book` ( id BIGINT(20) UNSIGNED NOT NULL, title VARCHAR(255), PRIMARY KEY ( id ) ) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci AUTO_INCREMENT = 2223372036854775808'; $createPagePageTableSQL = ' CREATE TABLE `page_page` ( id BIGINT(20) UNSIGNED NOT NULL, page_id BIGINT(20) UNSIGNED NOT NULL, page2_id BIGINT(20) UNSIGNED NOT NULL, PRIMARY KEY ( id ) ) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci AUTO_INCREMENT = 3223372036854775808'; R::exec($createBookTableSQL); R::exec($createPageTableSQL); R::exec($createPagePageTableSQL); //insert some records $book1ID = '2223372036854775808'; $book2ID = '2223372036854775809'; $page1ID = '1223372036854775808'; $page2ID = '1223372036854775809'; $page3ID = '1223372036854775890'; $pagePage1ID = '3223372036854775808'; $insertBook1SQL = "\n\t\t\tINSERT INTO book (id, title) VALUES( '{$book1ID}', 'book 1' );\n\t\t"; $insertBook2SQL = "\n\t\t\tINSERT INTO book (id, title) VALUES( '{$book2ID}', 'book 2' );\n\t\t"; $insertPage1SQL = "\n\t\t\tINSERT INTO page (id, book_id, title, magazine_id) VALUES( '{$page1ID}', '{$book1ID}', 'page 1 of book 1', '{$book2ID}' );\n\t\t"; $insertPage2SQL = "\n\t\t\tINSERT INTO page (id, book_id, title) VALUES( '{$page2ID}', '{$book1ID}', 'page 2 of book 1' );\n\t\t"; $insertPage3SQL = "\n\t\t\tINSERT INTO page (id, book_id, title) VALUES( '{$page3ID}', '{$book2ID}', 'page 1 of book 2' );\n\t\t"; $insertPagePage1SQL = "\n\t\t\tINSERT INTO page_page (id, page_id, page2_id) VALUES( '{$pagePage1ID}', '{$page2ID}', '{$page3ID}' );\n\t\t"; R::exec($insertBook1SQL); R::exec($insertBook2SQL); R::exec($insertPage1SQL); R::exec($insertPage2SQL); R::exec($insertPage3SQL); R::exec($insertPagePage1SQL); //basic tour of basic functions.... $book1 = R::load('book', $book1ID); asrt($book1->id, $book1ID); asrt($book1->title, 'book 1'); $book2 = R::load('book', $book2ID); asrt($book2->id, $book2ID); asrt($book2->title, 'book 2'); asrt(count($book1->ownPage), 2); asrt(count($book1->fresh()->with('LIMIT 1')->ownPage), 1); asrt(count($book1->fresh()->withCondition(' title = ? ', array('page 2 of book 1'))->ownPage), 1); asrt(count($book2->ownPage), 1); asrt($book2->fresh()->countOwn('page'), 1); $page1 = R::load('page', $page1ID); asrt(count($page1->sharedPage), 0); asrt($page1->fetchAs('book')->magazine->id, $book2ID); $page2 = R::load('page', $page2ID); asrt(count($page2->sharedPage), 1); asrt($page2->fresh()->countShared('page'), 1); $page3 = R::findOne('page', ' title = ? ', array('page 1 of book 2')); asrt($page3->id, $page3ID); asrt($page3->book->id, $book2ID); }
public function forgetPasswordConfirm() { // $this->app->getLogger()->log('confirm new password after reset..'); // $this->app->getLogger()->log("referer : " . (empty($_SERVER["HTTP_REFERER"]) ? " empty referer " : $_SERVER["HTTP_REFERER"])); $params = $this->getParams(); /** @var \Redbean_SimpleModel $userBean */ $userBean = R::findOne('admin', "id = ? and activation_key = ?", array($params["id"], $params["activation_key"])); if (!empty($params['activation_key']) && !empty($userBean)) { /** @var \SkullyAdmin\Models\Admin $user */ $user = $userBean->box(); $user->activationKey = ''; $newPassword = $user->resetPassword(); try { // $this->app->getLogger()->log('store new password'); R::store($user); if ($this->SendNewPassword($user, $newPassword)) { $this->showMessage($this->app->getTranslator()->translate('emailNewPasswordSent'), 'message'); } else { $this->showMessage($this->app->getTranslator()->translate("unknownError"), 'error'); } } catch (\Exception $e) { // $this->app->getLogger()->log('error saving new password'); $this->showMessage($e->getMessage(), 'error'); } } else { $this->showMessage($this->app->getTranslator()->translate("userNotFoundOrInvalidActivationKey"), 'error'); } $this->render('login'); }
public function moveImage() { $id = $this->getParam('id'); $from = (int) $this->getParam('position'); $direction = $this->getParam('direction'); $settingName = $this->getParam('setting'); $fieldName = $this->getParam('field'); if ($direction == 'up') { $to = $from - 1; } else { $to = $from + 1; } $instanceBean = R::findOne($this->model(), 'id = ?', array($id)); $instance = $instanceBean->box(); $images = $instance->get($fieldName); if (!is_array($images)) { $images = UtilitiesHelper::decodeJson($images, true); } $imageFrom = $images[$from]; $images[$from] = $images[$to]; $images[$to] = $imageFrom; $instance->set($fieldName, json_encode($images)); R::store($instance); echo json_encode(array('settingName' => $settingName, 'from' => $from, 'to' => $to)); }
/** * Test Full fluid UUID support. * */ public function testFullSupport() { //Rewire objects to support UUIDs. $oldToolBox = R::getToolBox(); $oldAdapter = $oldToolBox->getDatabaseAdapter(); $uuidWriter = new \UUIDWriterPostgres($oldAdapter); $newRedBean = new OODB($uuidWriter); $newToolBox = new ToolBox($newRedBean, $oldAdapter, $uuidWriter); R::configureFacadeWithToolbox($newToolBox); list($mansion, $rooms, $ghosts, $key) = R::dispenseAll('mansion,room*3,ghost*4,key'); $mansion->name = 'Haunted Mansion'; $mansion->xownRoomList = $rooms; $rooms[0]->name = 'Green Room'; $rooms[1]->name = 'Red Room'; $rooms[2]->name = 'Blue Room'; $ghosts[0]->name = 'zero'; $ghosts[1]->name = 'one'; $ghosts[2]->name = 'two'; $ghosts[3]->name = 'three'; $rooms[0]->noLoad()->sharedGhostList = array($ghosts[0], $ghosts[1]); $rooms[1]->noLoad()->sharedGhostList = array($ghosts[0], $ghosts[2]); $rooms[2]->noLoad()->sharedGhostList = array($ghosts[1], $ghosts[3], $ghosts[2]); $rooms[2]->xownKey = array($key); //Can we store a bean hierachy with UUIDs? R::debug(1); $id = R::store($mansion); //exit; asrt(is_string($id), TRUE); asrt(strlen($id), 36); $haunted = R::load('mansion', $id); asrt($haunted->name, 'Haunted Mansion'); asrt(is_string($haunted->id), TRUE); asrt(strlen($haunted->id), 36); asrt(is_array($haunted->xownRoomList), TRUE); asrt(count($haunted->ownRoom), 3); $rooms = $haunted->xownRoomList; //Do some counting... $greenRoom = NULL; foreach ($rooms as $room) { if ($room->name === 'Green Room') { $greenRoom = $room; break; } } asrt(!is_null($greenRoom), TRUE); asrt(is_array($greenRoom->with(' ORDER BY id ')->sharedGhostList), TRUE); asrt(count($greenRoom->sharedGhostList), 2); $names = array(); foreach ($greenRoom->sharedGhost as $ghost) { $names[] = $ghost->name; } sort($names); $names = implode(',', $names); asrt($names, 'one,zero'); $rooms = $haunted->xownRoomList; $blueRoom = NULL; foreach ($rooms as $room) { if ($room->name === 'Blue Room') { $blueRoom = $room; break; } } asrt(!is_null($blueRoom), TRUE); asrt(is_array($blueRoom->sharedGhostList), TRUE); asrt(count($blueRoom->sharedGhostList), 3); $names = array(); foreach ($blueRoom->sharedGhost as $ghost) { $names[] = $ghost->name; } sort($names); $names = implode(',', $names); asrt($names, 'one,three,two'); $rooms = $haunted->xownRoomList; $redRoom = NULL; foreach ($rooms as $room) { if ($room->name === 'Red Room') { $redRoom = $room; break; } } $names = array(); foreach ($redRoom->sharedGhost as $ghost) { $names[] = $ghost->name; } sort($names); $names = implode(',', $names); asrt($names, 'two,zero'); asrt(!is_null($redRoom), TRUE); asrt(is_array($redRoom->sharedGhostList), TRUE); asrt(count($redRoom->sharedGhostList), 2); //Can we repaint a room? $redRoom->name = 'Yellow Room'; $id = R::store($redRoom); $yellowRoom = R::load('room', $id); asrt($yellowRoom->name, 'Yellow Room'); asrt(!is_null($yellowRoom), TRUE); asrt(is_array($yellowRoom->sharedGhostList), TRUE); asrt(count($yellowRoom->sharedGhostList), 2); //Can we throw one ghost out? array_pop($yellowRoom->sharedGhost); R::store($yellowRoom); $yellowRoom = $yellowRoom->fresh(); asrt($yellowRoom->name, 'Yellow Room'); asrt(!is_null($yellowRoom), TRUE); asrt(is_array($yellowRoom->sharedGhostList), TRUE); asrt(count($yellowRoom->sharedGhostList), 1); //can we remove one of the rooms? asrt(R::count('key'), 1); $list = $mansion->withCondition(' "name" = ? ', array('Blue Room'))->xownRoomList; $room = reset($list); unset($mansion->xownRoomList[$room->id]); R::store($mansion); asrt(R::count('room'), 2); //and what about its dependent beans? asrt(R::count('key'), 0); asrt(R::count('ghost_room'), 3); //and can we find ghosts? $ghosts = R::find('ghost'); asrt(count($ghosts), 4); $ghosts = R::findAll('ghost', 'ORDER BY id'); asrt(count($ghosts), 4); $ghosts = R::findAll('ghost', 'ORDER BY id LIMIT 2'); asrt(count($ghosts), 2); $ghostZero = R::findOne('ghost', ' "name" = ? ', array('zero')); asrt($ghostZero instanceof OODBBean, TRUE); //can we create link properties on existing tables? $blackRoom = R::dispense('room'); $blackRoom->name = 'Black Room'; $ghostZero->link('ghost_room', array('mood' => 'grumpy'))->room = $blackRoom; R::store($ghostZero); $ghostZero = $ghostZero->fresh(); $list = $ghostZero->sharedRoomList; asrt(count($list), 3); $ghostZero = $ghostZero->fresh(); $list = $ghostZero->withCondition(' ghost_room.mood = ? ', array('grumpy'))->sharedRoomList; asrt(count($list), 1); //can we load a batch? $ids = R::getCol('SELECT id FROM ghost'); $ghosts = R::batch('ghost', $ids); asrt(count($ghosts), 4); //can we do an aggregation? $ghosts = $greenRoom->aggr('ownGhostRoom', 'ghost', 'ghost'); asrt(count($ghosts), 2); //can we duplicate the mansion? asrt(R::count('mansion'), 1); asrt(R::count('room'), 3); asrt(R::count('ghost'), 4); $copy = R::dup($mansion); R::store($copy); asrt(R::count('mansion'), 2); asrt(R::count('room'), 5); //black room does not belong to mansion 1 asrt(R::count('ghost'), 4); //can we do some counting using the list? asrt($copy->countOwn('room'), 2); $rooms = $copy->withCondition(' "name" = ? ', array('Green Room'))->xownRoomList; $room = reset($rooms); asrt($room->countShared('ghost'), 2); //Finally restore old toolbox R::configureFacadeWithToolbox($oldToolBox); }
/** * updates infos abount an user * * @param string $username * @param array $data All information of the user */ public static function updateUser($username, $data) { if (self::is_user($username)) { $u = R::findOne('user', ' username = ? ', [$username]); foreach ($data as $index => $value) { if ($index == "password") { $value = self::hash($value); } $u->{$index} = $value; } R::store($u); } }
$user->snid = $snid[$idp]; $user->identifier = $user_profile->identifier; $user->email = $user_profile->email; $user->first_name = $user_profile->firstName; $user->last_name = $user_profile->lastName; $user->avatar_url = $user_profile->photoURL; $user->reg = R::isoDateTime(); if (R::store($user)) { \Hybrid_Auth::storage()->set('user', ['identifier' => $user_profile->identifier, 'snid' => $snid[$idp]]); $app->redirect($app->wroot . '/welcome/'); } } // Get error } catch (Exception $e) { echo $e->getMessage(); } }); // Logout $app->get('/logout/', function () use($app) { $app->hybridInstance; \Hybrid_Auth::storage()->set('user', null); Hybrid_Auth::logoutAllProviders(); $app->redirect($app->wroot . '/login/'); }); // Wellcome $app->get('/welcome/', $authenticate($app), function () use($app) { $u_ses = Hybrid_Auth::storage()->get('user'); $user = R::findOne('users', ' snid = ? AND identifier = ?', array($u_ses['snid'], $u_ses['identifier'])); $app->render('welcome.php', ['user' => $user->export()]); }); $app->run();
/** * * Same as above.. test keep cache. * * @return void */ public function testInstructNoDrop() { $str = 'SELECT * FROM ' . R::getWriter()->esc('bean', TRUE) . ' -- keep-cache'; $bean = R::dispense('bean'); $bean->title = 'abc'; $id = R::store($bean); $bean = R::load('bean', $id); $bean->title = 'xxx'; R::store($bean); R::exec($str); $bean = R::load('bean', $id); asrt($bean->title, 'abc'); R::nuke(); // Now INSTRUCT the cache to not drop the cache CASE 2 $str = 'SELECT * FROM ' . R::getWriter()->esc('bean', TRUE) . ' -- keep-cache'; $bean = R::dispense('bean'); $bean->title = 'abc'; $id = R::store($bean); $bean = R::load('bean', $id); $bean->title = 'xxx'; R::store($bean); R::findOne('bean', ' title = ? ', array('cache')); $bean = R::load('bean', $id); asrt($bean->title, 'xxx'); }
/** * Can we use colons in SQL? * * @return void */ public function testColonsInSQL() { R::nuke(); $book = R::dispense('book'); $book->title = 'About :'; R::store($book); pass(); $book = R::findOne('book', ' title LIKE :this ', array(':this' => 'About :')); asrt($book instanceof OODBBean, TRUE); //without the colon? $book = R::findOne('book', ' title LIKE :this ', array('this' => 'About :')); asrt($book instanceof OODBBean, TRUE); $book = R::findOne('book', ' title LIKE :this ', array(':this' => '%:%')); asrt($book instanceof OODBBean, TRUE); $book = R::findOne('book', ' title LIKE :this OR title LIKE :that', array('this' => '%:%', ':that' => 'That')); asrt($book instanceof OODBBean, TRUE); $records = R::getAll('SELECT * FROM book WHERE title LIKE :this', array(':this' => 'About :')); asrt(count($records), 1); $records = R::getAll('SELECT * FROM book WHERE title LIKE :this', array('this' => 'About :')); asrt(count($records), 1); $records = R::getAll('SELECT * FROM book WHERE title LIKE :this OR title LIKE :that', array(':this' => 'About :', ':that' => 'That')); asrt(count($records), 1); $records = R::getRow('SELECT * FROM book WHERE title LIKE :this', array(':this' => 'About :')); asrt(count($records), 2); $records = R::getRow('SELECT * FROM book WHERE title LIKE :this', array('this' => 'About :')); asrt(count($records), 2); $records = R::getRow('SELECT * FROM book WHERE title LIKE :this OR title LIKE :that', array(':this' => 'About :', ':that' => 'That')); asrt(count($records), 2); }
/** * Tests fix for issue #378. * Via property does not get cleared properly. * * @return void */ public function testIssue378() { R::nuke(); $mediaBean = R::dispense('media'); $fooPerson = R::dispense('person'); $mediaBean->sharedPersonList[] = $fooPerson; R::store($mediaBean); asrt(count($mediaBean->sharedPersonList), 1); $person = R::findOne('person'); $person->via('relation')->sharedMarriageList[] = R::dispense('marriage'); //this second one caused the via property to not get cleared $person->via('relation')->sharedMarriageList; asrt(count($person->sharedMediaList), 1); //also found this scenario, non-existing property $book = R::dispense('book'); $book->sharedPage[] = R::dispense('page'); R::store($book); $book = $book->fresh(); $book->via('garbage')->nothing; asrt(count($book->sharedPageList), 1); //yet another $book = R::dispense('magazine'); $book->ownAdList[] = R::dispense('ad'); $book->sharedPage[] = R::dispense('page'); R::store($book); $book = $book->fresh(); $book->via('garbage')->ownAdList; asrt(count($book->sharedPageList), 1); $book = R::dispense('folder'); $book->sharedPage[] = R::dispense('page'); R::store($book); $book = $book->fresh(); $book->via('garbage')->sharedItemList[] = R::dispense('item'); asrt(count($book->sharedPageList), 1); $book = R::dispense('folder2'); $book->sharedPage[] = R::dispense('page'); R::store($book); $book = $book->fresh(); $book->via('garbage')->sharedItemList[] = R::dispense('item'); $book->via('garbage')->sharedItemList[] = R::dispense('item'); asrt(count($book->sharedPageList), 1); $book = R::dispense('folder3'); $book->sharedPage[] = R::dispense('page'); R::store($book); $book = $book->fresh(); $book->via('garbage')->item = R::dispense('item'); asrt(count($book->sharedPageList), 1); $book = R::dispense('folder3'); $book->sharedPage[] = R::dispense('page'); R::store($book); $book = $book->fresh(); $book->via('garbage')->item = 'test'; asrt(count($book->sharedPageList), 1); //yet another $book = R::dispense('leaflet'); $book->title = 'leaflet'; $book->sharedPage[] = R::dispense('page'); R::store($book); $book = $book->fresh(); $book->via('garbage')->title; asrt(count($book->sharedPageList), 1); //yet another $book = R::dispense('paper'); $book->author = R::dispense('author'); $book->sharedPage[] = R::dispense('page'); R::store($book); $book = $book->fresh(); $book->via('garbage')->author; asrt(count($book->sharedPageList), 1); $book = R::dispense('paper2'); $book->sharedPage[] = R::dispense('page'); R::store($book); $book = $book->fresh(); $book->via('garbage')->author; asrt(count($book->sharedPageList), 1); //yet another one $book = R::dispense('archive'); $book->sharedItem[] = R::dispense('item'); $book->sharedPage[] = R::dispense('page'); R::store($book); $book = $book->fresh(); unset($book->via('garbage')->sharedItem); asrt(count($book->sharedPageList), 1); //theoretic cases $book = R::dispense('guide'); $book->sharedItem[] = R::dispense('item'); $book->sharedPage[] = R::dispense('page'); R::store($book); $book = $book->fresh(); $book->via('relation')->countShared('item'); $book->via('relation')->countShared('item'); asrt(count($book->sharedPageList), 1); $book = R::dispense('catalogue'); $book->sharedPage[] = R::dispense('page'); R::store($book); $book = $book->fresh(); $book->via('relation')->countShared('item'); $book->via('relation')->countShared('item'); asrt(count($book->sharedPageList), 1); $book = R::dispense('tabloid'); $book->ownItemList[] = R::dispense('item'); $book->sharedPage[] = R::dispense('page'); R::store($book); $book = $book->fresh(); $book->via('relation')->countOwn('item'); $book->via('relation')->countOwn('item'); asrt(count($book->sharedPageList), 1); $book = R::dispense('booklet'); $book->ownItemList[] = R::dispense('item'); $book->sharedPage[] = R::dispense('page'); R::store($book); $book = $book->fresh(); $book->via('relation')->countOwn('item'); $book->via('relation')->countOwn('item'); asrt(count($book->sharedPageList), 1); AQueryWriter::clearRenames(); }
public function testUploadFile() { $this->migrate(); $this->login(); // Preparation: Create an image entry. $image = $this->app->createModel('image', array('position' => 0)); R::store($image); $this->assertNotEmpty($image->getID()); // upload to aws s3 $filename = 'original.jpg'; $filepath = realpath(__DIR__ . '/' . $filename); $_SERVER['REQUEST_METHOD'] = "POST"; $params = array('image_id' => $image->getID(), 'data' => '{ "id": ' . $image->getID() . ', "type": "uploadOnce", "settingName": "multiple_many_types" }', 'settingName' => 'multiple_many_types', 'uploadOnce' => 1); $size = filesize($filepath); $_FILES = array('file-0' => array('name' => $filename, 'type' => 'image/jpeg', 'tmp_name' => $filepath, 'error' => 0, 'size' => $size)); ob_start(); $this->app->runControllerFromRawUrl('admin/cRUDImages/uploadImage', $params); $output = ob_get_clean(); echo "\nOutput of uploadImage:\n"; echo $output; $output_r = json_decode($output); print_r($output_r); $this->assertFalse(property_exists($output_r[0], 'error')); // See if file uploaded successfully. echo "\nFind image with id " . $image->getID(); $imageBean = R::findOne('image', 'id = ?', array($image->getID())); $this->assertNotEmpty($imageBean); echo "\n...Found!"; $data = json_decode($imageBean['multiple_many_types']); echo "\nUploaded images:\n"; print_r($data); $this->assertEquals(1, count($data)); // Uploaded data must contain 'images/Image/1/original-smartphone' $this->assertNotEquals(-1, strpos(SkullyAwsS3\Helpers\S3Helpers::key($this->app->config('publicDir'), $data[0]->smartphone), 'public/images/Image/' . $image->getID() . '/original-smartphone')); // Now see if file does exist in Amazon S3 repository. $amazonS3Config = $this->app->config('amazonS3'); $client = \Aws\S3\S3Client::factory($amazonS3Config['settings']); $result = $client->getObject(array('Bucket' => $amazonS3Config['bucket'], 'Key' => SkullyAwsS3\Helpers\S3Helpers::key($this->app->config('publicDir'), $data[0]->smartphone))); $this->assertNotEmpty($result['Body']); // $this->app->getLogger()->log("result get object : " . print_r($result, true)); // TEST ACL $resultAcl = $client->getObjectAcl(array('Bucket' => $amazonS3Config['bucket'], 'Key' => SkullyAwsS3\Helpers\S3Helpers::key($this->app->config('publicDir'), $data[0]->smartphone))); // $this->app->getLogger()->log("result get object ACL : " . print_r($resultAcl, true)); $this->assertNotEmpty($resultAcl["Grants"]); $dataAcl = array(); foreach (\Aws\S3\Model\Acp::fromArray($resultAcl->toArray()) as $grant) { $grantee = $grant->getGrantee(); $dataAcl[$grantee->getGroupUri()] = array($grantee->getType(), $grant->getPermission()); } $this->assertEquals(2, count($dataAcl)); $this->assertArrayHasKey('http://acs.amazonaws.com/groups/global/AllUsers', $dataAcl); $this->assertEquals(array('Group', 'READ'), $dataAcl['http://acs.amazonaws.com/groups/global/AllUsers']); // ---- end of test ACL ---- // Local file must have been deleted. $filepath = \Skully\App\Helpers\FileHelper::replaceSeparators($this->app->getTheme()->getBasePath() . $data[0]->smartphone); echo "\nChecking if file {$filepath} is deleted..."; $this->assertFalse(file_exists($filepath)); echo "\nYep"; // Delete Models try { R::trash($imageBean); } catch (\Exception $e) { echo 'failed to delete image bean. reason: ' . $e->getMessage(); } // // Cleanup by removing files in bucket. // $client->deleteObject(array( // 'Bucket' => $amazonS3Config['bucket'], // 'Key' => SkullyAwsS3\Helpers\S3Helpers::key($this->app->config('publicDir'), $data[0]->smartphone)) // ); // // $client->deleteObject(array( // 'Bucket' => $amazonS3Config['bucket'], // 'Key' => SkullyAwsS3\Helpers\S3Helpers::key($this->app->config('publicDir'), $data[0]->desktop)) // ); // Check existence of deleted files on s3 server $result = $client->doesObjectExist($amazonS3Config['bucket'], SkullyAwsS3\Helpers\S3Helpers::key($this->app->config('publicDir'), $data[0]->smartphone)); $this->assertFalse($result); $result = $client->doesObjectExist($amazonS3Config['bucket'], SkullyAwsS3\Helpers\S3Helpers::key($this->app->config('publicDir'), $data[0]->desktop)); $this->assertFalse($result); }
/** * Test BIG INT primary key support. * * @return void */ public function testBigIntSupport() { R::nuke(); $createPageTableSQL = ' CREATE TABLE page ( id BIGSERIAL PRIMARY KEY, book_id BIGSERIAL, magazine_id BIGSERIAL, title VARCHAR(255) )'; $createBookTableSQL = ' CREATE TABLE book ( id BIGSERIAL PRIMARY KEY, title VARCHAR(255) )'; $createPagePageTableSQL = ' CREATE TABLE page_page ( id BIGSERIAL PRIMARY KEY, page_id BIGSERIAL, page2_id BIGSERIAL ) '; R::exec($createBookTableSQL); R::exec($createPageTableSQL); R::exec($createPagePageTableSQL); //insert some records $book1ID = '2223372036854775808'; $book2ID = '2223372036854775809'; $page1ID = '1223372036854775808'; $page2ID = '1223372036854775809'; $page3ID = '1223372036854775890'; $pagePage1ID = '3223372036854775808'; R::exec("ALTER SEQUENCE book_id_seq RESTART WITH {$book1ID}"); R::exec("ALTER SEQUENCE page_id_seq RESTART WITH {$page1ID}"); R::exec("ALTER SEQUENCE page_page_id_seq RESTART WITH {$pagePage1ID}"); $insertBook1SQL = "\n\t\t\tINSERT INTO book (title) VALUES( 'book 1' );\n\t\t"; $insertBook2SQL = "\n\t\t\tINSERT INTO book (title) VALUES( 'book 2' );\n\t\t"; $insertPage1SQL = "\n\t\t\tINSERT INTO page (id, book_id, title, magazine_id) VALUES( '{$page1ID}', '{$book1ID}', 'page 1 of book 1', '{$book2ID}' );\n\t\t"; $insertPage2SQL = "\n\t\t\tINSERT INTO page (id, book_id, title) VALUES( '{$page2ID}', '{$book1ID}', 'page 2 of book 1' );\n\t\t"; $insertPage3SQL = "\n\t\t\tINSERT INTO page (id, book_id, title) VALUES( '{$page3ID}', '{$book2ID}', 'page 1 of book 2' );\n\t\t"; $insertPagePage1SQL = "\n\t\t\tINSERT INTO page_page (id, page_id, page2_id) VALUES( '{$pagePage1ID}', '{$page2ID}', '{$page3ID}' );\n\t\t"; R::exec($insertBook1SQL); R::exec($insertBook2SQL); R::exec($insertPage1SQL); R::exec($insertPage2SQL); R::exec($insertPage3SQL); R::exec($insertPagePage1SQL); //basic tour of basic functions.... $book1 = R::load('book', $book1ID); asrt($book1->id, $book1ID); asrt($book1->title, 'book 1'); $book2 = R::load('book', $book2ID); asrt($book2->id, $book2ID); asrt($book2->title, 'book 2'); asrt(count($book1->ownPage), 2); asrt(count($book1->fresh()->with('LIMIT 1')->ownPage), 1); asrt(count($book1->fresh()->withCondition(' title = ? ', array('page 2 of book 1'))->ownPage), 1); asrt(count($book2->ownPage), 1); asrt($book2->fresh()->countOwn('page'), 1); $page1 = R::load('page', $page1ID); asrt(count($page1->sharedPage), 0); asrt($page1->fetchAs('book')->magazine->id, $book2ID); $page2 = R::load('page', $page2ID); asrt(count($page2->sharedPage), 1); asrt($page2->fresh()->countShared('page'), 1); $page3 = R::findOne('page', ' title = ? ', array('page 1 of book 2')); asrt($page3->id, $page3ID); asrt($page3->book->id, $book2ID); }
/** * @return void */ public function logout() { if ($this->getCookieData() != false) { $userLog = Facade::findOne('rememberme', 'hash = :hash', [':hash' => $this->getCookieData()['token']]); Facade::trash($userLog); } $this->unsetCookie(); session_destroy(); }