public function test_model_cache_new() { $publisher = new Publisher(array("name" => "HarperCollins")); $publisher->save(); $method = $this->set_method_public('Publisher', 'cache_key'); $cache_key = $method->invokeArgs($publisher, array()); $publisherDirectlyFromCache = Cache::$adapter->read($cache_key); $this->assertTrue(is_object($publisherDirectlyFromCache)); $this->assertEquals($publisher->name, $publisherDirectlyFromCache->name); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Publisher(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Publisher'])) { $model->attributes = $_POST['Publisher']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
private function action($form) { $session = session_currentSession(); $p = new Publisher(); $p->user = $session->id; $p->label = $form->name; $p->short_label = $form->shortname; $p->key = $this->generateKey(); $p->secret = $this->generateSecret(); $p->domain = $form->domain; // ISO-8601 2005-08-14T16:13:03+0000; $time = time() + $value; $p->created = date('c', $time); $p->save(); header('location:/account/settings'); }
/** * Edit a publisher. */ public function actionEdit($id = 0) { if ($id > 0) { $model = Publisher::model()->findByPk($id); } else { $model = new Publisher(); } if (isset($_POST['Publisher'])) { $model->attributes = $_POST['Publisher']; if ($model->validate() && $model->save()) { Yii::app()->user->setFlash('successmsg', 'The changes have been saved.'); $this->redirect('/publisher/index'); } else { Yii::app()->user->setFlash('errormsg', 'Error saving the publisher page.'); $this->render('edit', array('model' => $model, 'id' => $id)); } } else { $this->render('edit', array('model' => $model, 'id' => $id)); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Publisher(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Publisher'])) { $model->attributes = $_POST['Publisher']; if ($model->validate()) { if ($model->save()) { Yii::app()->clientScript->scriptMap['jquery.js'] = false; echo CJSON::encode(array('status' => 'success', 'div' => "<div class=alert alert-info fade in>Successfully added ! </div>")); Yii::app()->end(); } } } if (Yii::app()->request->isAjaxRequest) { $cs = Yii::app()->clientScript; $cs->scriptMap = array('jquery.js' => false, 'bootstrap.js' => false, 'jquery.min.js' => false, 'bootstrap.notify.js' => false, 'bootstrap.bootbox.min.js' => false); echo CJSON::encode(array('status' => 'render', 'div' => $this->renderPartial('_form', array('model' => $model), true, false))); Yii::app()->end(); } else { $this->render('create', array('model' => $model)); } }
$scholastic->setName("Scholastic"); // do not save, will do later to test cascade print "Added publisher \"Scholastic\" [not saved yet].\n"; $morrow = new Publisher(); $morrow->setName("William Morrow"); $morrow->save(); $morrow_id = $morrow->getId(); print "Added publisher \"William Morrow\" [id = {$morrow_id}].\n"; $penguin = new Publisher(); $penguin->setName("Penguin"); $penguin->save(); $penguin_id = $penguin->getId(); print "Added publisher \"Penguin\" [id = {$penguin_id}].\n"; $vintage = new Publisher(); $vintage->setName("Vintage"); $vintage->save(); $vintage_id = $vintage->getId(); print "Added publisher \"Vintage\" [id = {$vintage_id}].\n"; } catch (Exception $e) { die("Error adding publisher: " . $e->__toString()); } // Add author records // ------------------ try { print "\nAdding some new authors to the list\n"; print "--------------------------------------\n\n"; $rowling = new Author(); $rowling->setFirstName("J.K."); $rowling->setLastName("Rowling"); // no save() print "Added author \"J.K. Rowling\" [not saved yet].\n";
public function testSpeed() { // Add publisher records // --------------------- $scholastic = new Publisher(); $scholastic->setName("Scholastic"); // do not save, will do later to test cascade $morrow = new Publisher(); $morrow->setName("William Morrow"); $morrow->save(); $morrow_id = $morrow->getId(); $penguin = new Publisher(); $penguin->setName("Penguin"); $penguin->save(); $penguin_id = $penguin->getId(); $vintage = new Publisher(); $vintage->setName("Vintage"); $vintage->save(); $vintage_id = $vintage->getId(); // Add author records // ------------------ $rowling = new Author(); $rowling->setFirstName("J.K."); $rowling->setLastName("Rowling"); // no save() $stephenson = new Author(); $stephenson->setFirstName("Neal"); $stephenson->setLastName("Stephenson"); $stephenson->save(); $stephenson_id = $stephenson->getId(); $byron = new Author(); $byron->setFirstName("George"); $byron->setLastName("Byron"); $byron->save(); $byron_id = $byron->getId(); $grass = new Author(); $grass->setFirstName("Gunter"); $grass->setLastName("Grass"); $grass->save(); $grass_id = $grass->getId(); // Add book records // ---------------- $phoenix = new Book(); $phoenix->setTitle("Harry Potter and the Order of the Phoenix"); $phoenix->setISBN("043935806X"); // cascading save (Harry Potter) $phoenix->setAuthor($rowling); $phoenix->setPublisher($scholastic); $phoenix->save(); $phoenix_id = $phoenix->getId(); $qs = new Book(); $qs->setISBN("0380977427"); $qs->setTitle("Quicksilver"); $qs->setAuthor($stephenson); $qs->setPublisher($morrow); $qs->save(); $qs_id = $qs->getId(); $dj = new Book(); $dj->setISBN("0140422161"); $dj->setTitle("Don Juan"); $dj->setAuthor($byron); $dj->setPublisher($penguin); $dj->save(); $dj_id = $qs->getId(); $td = new Book(); $td->setISBN("067972575X"); $td->setTitle("The Tin Drum"); $td->setAuthor($grass); $td->setPublisher($vintage); $td->save(); $td_id = $td->getId(); // Add review records // ------------------ $r1 = new Review(); $r1->setBook($phoenix); $r1->setReviewedBy("Washington Post"); $r1->setRecommended(true); $r1->setReviewDate(time()); $r1->save(); $r1_id = $r1->getId(); $r2 = new Review(); $r2->setBook($phoenix); $r2->setReviewedBy("New York Times"); $r2->setRecommended(false); $r2->setReviewDate(time()); $r2->save(); $r2_id = $r2->getId(); // Perform a "complex" search // -------------------------- $crit = new Criteria(); $crit->add(BookPeer::TITLE, 'Harry%', Criteria::LIKE); $results = BookPeer::doSelect($crit); $crit2 = new Criteria(); $crit2->add(BookPeer::ISBN, array("0380977427", "0140422161"), Criteria::IN); $results = BookPeer::doSelect($crit2); // Perform a "limit" search // ------------------------ $crit = new Criteria(); $crit->setLimit(2); $crit->setOffset(1); $crit->addAscendingOrderByColumn(BookPeer::TITLE); $results = BookPeer::doSelect($crit); // Perform a lookup & update! // -------------------------- $qs_lookup = BookPeer::retrieveByPk($qs_id); $new_title = "Quicksilver (" . crc32(uniqid(rand())) . ")"; $qs_lookup->setTitle($new_title); $qs_lookup->save(); $qs_lookup2 = BookPeer::retrieveByPk($qs_id); // Test some basic DATE / TIME stuff // --------------------------------- // that's the control timestamp. $control = strtotime('2004-02-29 00:00:00'); // should be two in the db $r = ReviewPeer::doSelectOne(new Criteria()); $r_id = $r->getId(); $r->setReviewDate($control); $r->save(); $r2 = ReviewPeer::retrieveByPk($r_id); // Testing the DATE/TIME columns // ----------------------------- // that's the control timestamp. $control = strtotime('2004-02-29 00:00:00'); // should be two in the db $r = ReviewPeer::doSelectOne(new Criteria()); $r_id = $r->getId(); $r->setReviewDate($control); $r->save(); $r2 = ReviewPeer::retrieveByPk($r_id); // Testing the column validators // ----------------------------- $bk1 = new Book(); $bk1->setTitle("12345"); // min length is 10 $ret = $bk1->validate(); // Unique validator $bk2 = new Book(); $bk2->setTitle("Don Juan"); $ret = $bk2->validate(); // Now trying some more complex validation. $auth1 = new Author(); $auth1->setFirstName("Hans"); // last name required; will fail $bk1->setAuthor($auth1); $rev1 = new Review(); $rev1->setReviewDate("08/09/2001"); // will fail: reviewed_by column required $bk1->addReview($rev1); $ret2 = $bk1->validate(); $bk2 = new Book(); $bk2->setTitle("12345678901"); // passes $auth2 = new Author(); $auth2->setLastName("Blah"); //passes $auth2->setEmail("*****@*****.**"); //passes $auth2->setAge(50); //passes $bk2->setAuthor($auth2); $rev2 = new Review(); $rev2->setReviewedBy("Me!"); // passes $rev2->setStatus("new"); // passes $bk2->addReview($rev2); $ret3 = $bk2->validate(); // Testing doCount() functionality // ------------------------------- $c = new Criteria(); $count = BookPeer::doCount($c); // Testing many-to-many relationships // ---------------------------------- // init book club list 1 with 2 books $blc1 = new BookClubList(); $blc1->setGroupLeader("Crazyleggs"); $blc1->setTheme("Happiness"); $brel1 = new BookListRel(); $brel1->setBook($phoenix); $brel2 = new BookListRel(); $brel2->setBook($dj); $blc1->addBookListRel($brel1); $blc1->addBookListRel($brel2); $blc1->save(); // init book club list 2 with 1 book $blc2 = new BookClubList(); $blc2->setGroupLeader("John Foo"); $blc2->setTheme("Default"); $brel3 = new BookListRel(); $brel3->setBook($phoenix); $blc2->addBookListRel($brel3); $blc2->save(); // re-fetch books and lists from db to be sure that nothing is cached $crit = new Criteria(); $crit->add(BookPeer::ID, $phoenix->getId()); $phoenix = BookPeer::doSelectOne($crit); $crit = new Criteria(); $crit->add(BookClubListPeer::ID, $blc1->getId()); $blc1 = BookClubListPeer::doSelectOne($crit); $crit = new Criteria(); $crit->add(BookClubListPeer::ID, $blc2->getId()); $blc2 = BookClubListPeer::doSelectOne($crit); $relCount = $phoenix->countBookListRels(); $relCount = $blc1->countBookListRels(); $relCount = $blc2->countBookListRels(); // Removing books that were just created // ------------------------------------- $hp = BookPeer::retrieveByPk($phoenix_id); $c = new Criteria(); $c->add(BookPeer::ID, $hp->getId()); // The only way for cascading to work currently // is to specify the author_id and publisher_id (i.e. the fkeys // have to be in the criteria). $c->add(AuthorPeer::ID, $hp->getId()); $c->add(PublisherPeer::ID, $hp->getId()); $c->setSingleRecord(true); BookPeer::doDelete($c); // Attempting to delete books by complex criteria $c = new Criteria(); $cn = $c->getNewCriterion(BookPeer::ISBN, "043935806X"); $cn->addOr($c->getNewCriterion(BookPeer::ISBN, "0380977427")); $cn->addOr($c->getNewCriterion(BookPeer::ISBN, "0140422161")); $c->add($cn); BookPeer::doDelete($c); $td->delete(); AuthorPeer::doDelete($stephenson_id); AuthorPeer::doDelete($byron_id); $grass->delete(); PublisherPeer::doDelete($morrow_id); PublisherPeer::doDelete($penguin_id); $vintage->delete(); // These have to be deleted manually also since we have onDelete // set to SETNULL in the foreign keys in book. Is this correct? $rowling->delete(); $scholastic->delete(); $blc1->delete(); $blc2->delete(); }
public static function populate($con = null) { if ($con === null) { $con = Propel::getConnection(BookPeer::DATABASE_NAME); } $con->beginTransaction(); // Add publisher records // --------------------- $scholastic = new Publisher(); $scholastic->setName("Scholastic"); // do not save, will do later to test cascade $morrow = new Publisher(); $morrow->setName("William Morrow"); $morrow->save($con); $morrow_id = $morrow->getId(); $penguin = new Publisher(); $penguin->setName("Penguin"); $penguin->save(); $penguin_id = $penguin->getId(); $vintage = new Publisher(); $vintage->setName("Vintage"); $vintage->save($con); $vintage_id = $vintage->getId(); $rowling = new Author(); $rowling->setFirstName("J.K."); $rowling->setLastName("Rowling"); // no save() $stephenson = new Author(); $stephenson->setFirstName("Neal"); $stephenson->setLastName("Stephenson"); $stephenson->save($con); $stephenson_id = $stephenson->getId(); $byron = new Author(); $byron->setFirstName("George"); $byron->setLastName("Byron"); $byron->save($con); $byron_id = $byron->getId(); $grass = new Author(); $grass->setFirstName("Gunter"); $grass->setLastName("Grass"); $grass->save($con); $grass_id = $grass->getId(); $phoenix = new Book(); $phoenix->setTitle("Harry Potter and the Order of the Phoenix"); $phoenix->setISBN("043935806X"); $phoenix->setAuthor($rowling); $phoenix->setPublisher($scholastic); $phoenix->setPrice(10.99); $phoenix->save($con); $phoenix_id = $phoenix->getId(); $qs = new Book(); $qs->setISBN("0380977427"); $qs->setTitle("Quicksilver"); $qs->setPrice(11.99); $qs->setAuthor($stephenson); $qs->setPublisher($morrow); $qs->save($con); $qs_id = $qs->getId(); $dj = new Book(); $dj->setISBN("0140422161"); $dj->setTitle("Don Juan"); $dj->setPrice(12.99); $dj->setAuthor($byron); $dj->setPublisher($penguin); $dj->save($con); $dj_id = $dj->getId(); $td = new Book(); $td->setISBN("067972575X"); $td->setTitle("The Tin Drum"); $td->setPrice(13.99); $td->setAuthor($grass); $td->setPublisher($vintage); $td->save($con); $td_id = $td->getId(); $r1 = new Review(); $r1->setBook($phoenix); $r1->setReviewedBy("Washington Post"); $r1->setRecommended(true); $r1->setReviewDate(time()); $r1->save($con); $r1_id = $r1->getId(); $r2 = new Review(); $r2->setBook($phoenix); $r2->setReviewedBy("New York Times"); $r2->setRecommended(false); $r2->setReviewDate(time()); $r2->save($con); $r2_id = $r2->getId(); $blob_path = _LOB_SAMPLE_FILE_PATH . '/tin_drum.gif'; $clob_path = _LOB_SAMPLE_FILE_PATH . '/tin_drum.txt'; $m1 = new Media(); $m1->setBook($td); $m1->setCoverImage(file_get_contents($blob_path)); // CLOB is broken in PDO OCI, see http://pecl.php.net/bugs/bug.php?id=7943 if (get_class(Propel::getDB()) != "DBOracle") { $m1->setExcerpt(file_get_contents($clob_path)); } $m1->save($con); // Add book list records // --------------------- // (this is for many-to-many tests) $blc1 = new BookClubList(); $blc1->setGroupLeader("Crazyleggs"); $blc1->setTheme("Happiness"); $brel1 = new BookListRel(); $brel1->setBook($phoenix); $brel2 = new BookListRel(); $brel2->setBook($dj); $blc1->addBookListRel($brel1); $blc1->addBookListRel($brel2); $blc1->save(); $bemp1 = new BookstoreEmployee(); $bemp1->setName("John"); $bemp1->setJobTitle("Manager"); $bemp2 = new BookstoreEmployee(); $bemp2->setName("Pieter"); $bemp2->setJobTitle("Clerk"); $bemp2->setSupervisor($bemp1); $bemp2->save($con); $bemp3 = new BookstoreCashier(); $bemp3->setName("Tim"); $bemp3->setJobTitle("Cashier"); $bemp3->save($con); $role = new AcctAccessRole(); $role->setName("Admin"); $bempacct = new BookstoreEmployeeAccount(); $bempacct->setBookstoreEmployee($bemp1); $bempacct->setAcctAccessRole($role); $bempacct->setLogin("john"); $bempacct->setPassword("johnp4ss"); $bempacct->save($con); // Add bookstores $store = new Bookstore(); $store->setStoreName("Amazon"); $store->setPopulationServed(5000000000); // world population $store->setTotalBooks(300); $store->save($con); $store = new Bookstore(); $store->setStoreName("Local Store"); $store->setPopulationServed(20); $store->setTotalBooks(500000); $store->save($con); $summary = new BookSummary(); $summary->setSummarizedBook($phoenix); $summary->setSummary("Harry Potter does some amazing magic!"); $summary->save(); $con->commit(); }
public function testFindOneWithLeftJoinWithOneToManyAndNullObjectsAndWithAdditionalJoins() { BookPeer::clearInstancePool(); AuthorPeer::clearInstancePool(); BookOpinionPeer::clearInstancePool(); BookReaderPeer::clearInstancePool(); $freud = new Author(); $freud->setFirstName("Sigmund"); $freud->setLastName("Freud"); $freud->save($this->con); $publisher = new Publisher(); $publisher->setName('Psycho Books'); $publisher->save(); $book = new Book(); $book->setAuthor($freud); $book->setTitle('Weirdness'); $book->setIsbn('abc123456'); $book->setPrice('14.99'); $book->setPublisher($publisher); $book->save(); $query = BookQuery::create()->filterByTitle('Weirdness')->innerJoinAuthor()->useBookOpinionQuery(null, Criteria::LEFT_JOIN)->leftJoinBookReader()->endUse()->with('Author')->with('BookOpinion')->with('BookReader'); $books = $query->findOne($this->con); $this->assertEquals(0, count($books->getBookOpinions())); }
public function install_submit() { $username = Input::get('username'); $password = Input::get('password'); $admin_username = Input::get('admin_username'); $admin_password = Input::get('admin_password'); $sitename = Input::get('sitename'); $database_name = Input::get('database_name'); $picture = Input::file('picture'); $timezone = Input::get('timezone'); $database_host = Input::get('database_host'); $validator = Validator::make(array('password' => $password, 'username' => $username, 'database_name' => $database_name, 'admin_username' => $admin_username, 'admin_password' => $admin_password, 'sitename' => $sitename, 'picture' => $picture, 'timezone' => $timezone, 'database_host' => $database_host), array('password' => '', 'username' => 'required', 'sitename' => 'required', 'database_name' => 'required', 'admin_password' => 'required', 'admin_username' => 'required', 'timezone' => 'required', 'picture' => 'mimes:png,jpg', 'database_host' => 'required')); if ($validator->fails()) { $error_messages = $validator->messages()->all(); return Redirect::back()->with('flash_errors', $error_messages); } else { $file_name = time(); $file_name .= rand(); if (Input::hasFile('picture')) { $ext = Input::file('picture')->getClientOriginalExtension(); Input::file('picture')->move(public_path() . "/uploads", $file_name . "." . $ext); $local_url = $file_name . "." . $ext; $s3_url = URL::to('/') . '/uploads/' . $local_url; } Setting::set('sitename', $sitename); Setting::set('footer', "Powered by Appoets"); Setting::set('username', $username); Setting::set('password', $password); Setting::set('database_name', $database_name); Setting::set('timezone', $timezone); Setting::set('logo', $s3_url); Setting::set('database_host', $database_host); import_db($username, $password, 'localhost', $database_name); $admin = new User(); $admin->email = $admin_username; $admin->is_activated = 1; $admin->password = Hash::make($admin_password); $admin->author_name = "Admin"; $admin->role_id = 2; $admin->save(); // Default publisher $publisher = new Publisher(); $publisher->name = Input::get('sitename'); if (Input::hasFile('picture')) { $publisher->image = Setting::get('logo'); } $publisher->save(); // Default category $category = new Category(); $category->name = "Uncategory"; if (Input::hasFile('picture')) { $category->pics = Setting::get('logo'); } $category->save(); return Redirect::to('/'); } }
if ($publisherID == NULL || $publisherName != $holdPublisher) { //get the publisher object $publisherTestObj = new Publisher(); $publisherObj = new Publisher(); $publisherObj = $publisherTestObj->getByName($publisherName); if (is_object($publisherObj)) { $publisherID = $publisherObj->publisherID; } } //If it does not already exist, insert it and get the new ID if ($publisherID == '' && $publisherName) { $publisher = new Publisher(); $publisher->publisherID = ''; $publisher->name = $publisherName; try { $publisher->save(); } catch (Exception $e) { echo $e->getMessage(); } $publisherID = $publisher->primaryKey; } ################################################################# // PUBLISHER / PLATFORM // Query to see if the Publisher / Platform already exists, if so, get the ID ################################################################# //check it against the previous row - no need to do another lookup if we've already figured out the publisherplatformID if (!isset($publisherPlatformID) || $publisherName != $holdPublisher || $platformName != $holdPlatform) { //get the publisher platform object $publisherPlatformTestObj = new PublisherPlatform(); $publisherPlatformObj = $publisherPlatformTestObj->getPublisherPlatform($publisherID, $platformID); if (is_object($publisherPlatformObj)) {
public function addPublisher() { $act = 'add'; if (Input::has('submit')) { $rules = array('publishername' => 'required', 'phone' => 'required', 'email' => 'required|email', 'address' => 'required'); $validator = Validator::make(Input::all(), $rules); if ($validator->passes()) { $pb = new Publisher(); $pb->publishername = Input::get('publishername'); $pb->phone = Input::get('phone'); $pb->email = Input::get('email'); $pb->address = Input::get('address'); $pb->save(); return Redirect::to('admin/rkmpublisher')->with('sukses', 'rekam data berhasil!'); } else { return Redirect::to('admin/rkmpublisher')->withInput()->withErrors($validator); } } else { return View::make('admin.publisher', compact('act')); } //return Redirect::to('admin/publisher')->with('error','illegal operation!!!'); }
public function addPublisherProcess() { $name = Input::get('name'); $cat_img = Input::file('cat_img'); $validator = Validator::make(array('name' => $name, 'cat_img' => $cat_img), array('name' => 'required', 'cat_img' => 'required|mimes:jpeg,bmp,gif,png')); if ($validator->fails()) { $error_messages = $validator->messages()->all(); return Redirect::back()->with('flash_errors', $error_messages); } else { $publisher = new Publisher(); $publisher->name = Input::get('name'); $file_name = seo_url(Input::get('name')) . '-' . time(); $ext = Input::file('cat_img')->getClientOriginalExtension(); Input::file('cat_img')->move(public_path() . "/uploads", $file_name . "." . $ext); $local_url = $file_name . "." . $ext; $s3_url = URL::to('/') . '/uploads/' . $local_url; $publisher->image = $s3_url; $publisher->save(); if ($publisher) { return Redirect::back()->with('flash_success', tr('publisher_add')); } else { return Redirect::back()->with('flash_error', tr('went_wrong')); } } }
public function savePublisher($publisher_name) { $publisher_id = null; $exists = Publisher::model()->exists('id=:publisher_id', array(':publisher_id' => (int) $publisher_name)); if (!$exists) { $publisher = new Publisher(); $publisher->name = $publisher_name; $publisher->save(); $publisher_id = $publisher->id; } return $publisher_id; }
/** * */ public function testObjectInstances_Fkeys() { // Establish a relationship between one employee and account // and then change the employee_id and ensure that the account // is not pulling the old employee. $pub1 = new Publisher(); $pub1->setName('Publisher 1'); $pub1->save(); $pub2 = new Publisher(); $pub2->setName('Publisher 2'); $pub2->save(); $book = new Book(); $book->setTitle("Book Title"); $book->setISBN("1234"); $book->setPublisher($pub1); $book->save(); $this->assertSame($pub1, $book->getPublisher()); // now change values behind the scenes $con = Propel::getConnection(BookstoreEmployeeAccountPeer::DATABASE_NAME); $con->exec("UPDATE " . BookPeer::TABLE_NAME . " SET " . " publisher_id = " . $pub2->getId() . " WHERE id = " . $book->getId()); $book2 = BookPeer::retrieveByPK($book->getId()); $this->assertSame($book, $book2, "Expected same book object instance"); $this->assertEquals($pub1->getId(), $book->getPublisherId(), "Expected book to have OLD publisher id before reload()"); $book->reload(); $this->assertEquals($pub2->getId(), $book->getPublisherId(), "Expected book to have new publisher id"); $this->assertSame($pub2, $book->getPublisher(), "Expected book to have new publisher object associated."); // Now let's set it back, just to be double sure ... $con->exec("UPDATE " . BookPeer::TABLE_NAME . " SET " . " publisher_id = " . $pub1->getId() . " WHERE id = " . $book->getId()); $book->reload(); $this->assertEquals($pub1->getId(), $book->getPublisherId(), "Expected book to have old publisher id (again)."); $this->assertSame($pub1, $book->getPublisher(), "Expected book to have old publisher object associated (again)."); }
public function executeUpdate() { $i18n = new sfI18N(); $i18n->initialize($this->getContext()); $i18n->setCulture($this->getUser()->getCulture()); $action_i18n = $i18n->globalMessageFormat->format('save as new'); $action_edit_i18n = $i18n->globalMessageFormat->format('edit'); $action_type = $this->getRequestParameter('action_type'); if ($action_type == $action_i18n || !$this->getRequestParameter('id', 0)) { $catalog = new Catalog(); } else { $catalog = CatalogPeer::retrieveByPk($this->getRequestParameter('id')); $this->forward404Unless($catalog); } $catalog->setId($this->getRequestParameter('id')); $catalog->setCatLanguageId($this->getRequestParameter('cat_language_id')); $catalog->setCatCategoryId($this->getRequestParameter('cat_category_id')); $catalog->setCatSubjectId($this->getRequestParameter('cat_subject_id')); $catalog->setTitle($this->getRequestParameter('title')); $catalog->setSubtitle($this->getRequestParameter('subtitle')); $catalog->setPublishedYear($this->getRequestParameter('published_year')); $catalog->setPublishedLocation($this->getRequestParameter('published_location')); $catalog->setIsbn($this->getRequestParameter('isbn')); $catalog->setStudentNo($this->getRequestParameter('student_no')); $catalog->setStudentName($this->getRequestParameter('student_name')); $catalog->setStudentMajor($this->getRequestParameter('student_major')); $catalog->setStudentTutor($this->getRequestParameter('student_tutor')); $catalog->setVersion($this->getRequestParameter('version')); $catalog->setEdition($this->getRequestParameter('edition')); $catalog->setPrintNo($this->getRequestParameter('print_no')); $catalog->setPart($this->getRequestParameter('part')); $catalog->setVolume($this->getRequestParameter('volume')); $catalog->setMonth($this->getRequestParameter('month')); $catalog->setYear($this->getRequestParameter('year')); $catalog->setNo($this->getRequestParameter('no')); $catalog->setBonus($this->getRequestParameter('bonus')); $catalog->setPages($this->getRequestParameter('pages')); $catalog->setHeight($this->getRequestParameter('height')); $catalog->setSynopsis($this->getRequestParameter('synopsis')); $catalog->setAbstracts($this->getRequestParameter('abstracts')); $catalog->setSearchKeywords($this->getRequestParameter('search_keywords')); //publisher if ($action_type == $action_i18n || !$this->getRequestParameter('publisher_id')) { $publisher = new Publisher(); $publisher->setId($this->getRequestParameter('publisher_id')); $publisher->setName($this->getRequestParameter('publisher_name')); $publisher->save(); $catalog->setPublisher($publisher); $catalog->save(); } elseif ($action_type !== $action_i18n || !$this->getRequestParameter('publisher_id')) { $publisher = new Publisher(); $publisher->setId($this->getRequestParameter('publisher_id')); $publisher->setName($this->getRequestParameter('publisher_name')); $publisher->save(); $catalog->setPublisher($publisher); $catalog->save(); } elseif ($this->getRequestParameter('publisher_id')) { $catalog->setPublisherId($this->getRequestParameter('publisher_id')); $catalog->save(); } //writer #if ($this->getRequestParameter('cat_category_id') != 3 && $this->getRequestParameter('cat_category_id') != 2) { if ($this->hasRequestParameter('writers_id') && $this->getRequestParameter('writers_id') != null && $this->getRequestParameter('writers_id') != '') { $name = $this->getRequestParameter('writers_name'); $c = new Criteria(); $c->add(WriterPeer::NAME, "%{$name}%", Criteria::LIKE); $rows = WriterPeer::doSelect($c); if ($rows != null) { $catalog->updateWriters($this->getRequestParameter('writers_name')); $catalog->save(); } else { $writer = new Writer(); $writer->setId($this->getRequestParameter('writers_id')); $writer->setName($this->getRequestParameter('writers_name')); $writer->save(); $cw = new CatalogWriter(); $cw->setCatalog($catalog); $cw->setWriter($writer); $cw->save(); } } elseif ($action_type !== $action_i18n || !$this->getRequestParameter('writer_id')) { $writer = new Writer(); $writer->setName($this->getRequestParameter('writers_name')); $writer->save(); $cw = new CatalogWriter(); $cw->setCatalog($catalog); $cw->setWriter($writer); $cw->save(); } else { $writer = new Writer(); $writer->setName($this->getRequestParameter('writers_name')); $writer->save(); $cw = new CatalogWriter(); $cw->setCatalog($catalog); $cw->setWriter($writer); $cw->save(); } #} $writer_name = $catalog->getFirstWriterName(); $writer_name = preg_replace('/\\W+/', '', $writer_name); $writer_name = strtoupper(substr($writer_name, 0, 3)); $title = substr(strtoupper(str_replace(' ', '', $catalog->getTitle())), 0, 3); $subject_code = $catalog->getCatSubject()->getCode(); /** $c = new Criteria(); $c->add(CatalogPeer::TITLE, "$title%", Criteria::LIKE); $c->add(CatalogPeer::ID, $catalog->getId(), Criteria::NOT_EQUAL); $c->addDescendingOrderByColumn(CatalogPeer::TITLE); $cat = CatalogPeer::doSelectOne($c); if ($cat != null) { $last_index = split('-', $cat->getCode()); $last_index = $last_index[1]; if ($last_index != null) ++$last_index; else $last_index = 1; $title = "$title-$last_index"; } **/ if ($this->hasRequestParameter('code') && $this->getRequestParameter('code') != null && $this->getRequestParameter('code') != '') { $catalog->setCode($this->getRequestParameter('code')); } else { $catalog->setCode("{$subject_code}-{$writer_name}-{$title}"); } $catalog->save(); if ($this->hasRequestParameter('copies') && $this->getRequestParameter('copies') > 0) { $catalog->addCopies($this); } $cover_dir = sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . 'photos' . DIRECTORY_SEPARATOR; if ($this->hasRequestParameter('coverFile') && $this->getRequestParameter('coverFile') != '' && $this->getRequestParameter('coverFile') != null) { // get cover content $cover_file = $cover_dir . 'tmp' . DIRECTORY_SEPARATOR . $this->getRequestParameter('coverFile'); $content = file_get_contents($cover_file); $im = imagecreatefromstring($content); list($w, $h) = getimagesize($cover_file); // generate cover $cover = imagecreatetruecolor(150, 200); imagecopyresized($cover, $im, 0, 0, 0, 0, 150, 200, $w, $h); // generate thumbnail $thumb = imagecreatetruecolor(100, 150); imagecopyresized($thumb, $im, 0, 0, 0, 0, 100, 150, $w, $h); // get cover record $c = new Criteria(); $c->add(CatalogCopiedPeer::CATALOG_ID, $catalog->getId()); $catalog_cover = CatalogCopiedPeer::doSelectOne($c); if ($catalog_cover == null) { $catalog_cover = new CatalogCopied(); $catalog_cover->setCatalog($catalog); } // save cover imagepng($cover, $cover_file); $catalog_cover->setCover(base64_encode(file_get_contents($cover_file))); imagepng($thumb, $cover_file); $catalog_cover->setThumbnail(base64_encode(file_get_contents($cover_file))); $catalog_cover->save(); unlink($cover_dir . 'tmp' . DIRECTORY_SEPARATOR . $this->getRequestParameter('coverFile')); } if ($this->hasRequestParameter('file') && $this->getRequestParameter('file') != '' && $this->getRequestParameter('file') != null) { $fileName = $this->getRequestParameter('file'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($this->hasRequestParameter('file_1') && $this->getRequestParameter('file_1') != '' && $this->getRequestParameter('file_1') != null) { $fileName = $this->getRequestParameter('file_1'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($this->hasRequestParameter('file_2') && $this->getRequestParameter('file_2') != '' && $this->getRequestParameter('file_2') != null) { $fileName = $this->getRequestParameter('file_2'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($this->hasRequestParameter('file_3') && $this->getRequestParameter('file_3') != '' && $this->getRequestParameter('file_3') != null) { $fileName = $this->getRequestParameter('file_3'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($this->hasRequestParameter('file_4') && $this->getRequestParameter('file_4') != '' && $this->getRequestParameter('file_4') != null) { $fileName = $this->getRequestParameter('file_4'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($this->hasRequestParameter('file_5') && $this->getRequestParameter('file_5') != '' && $this->getRequestParameter('file_5') != null) { $fileName = $this->getRequestParameter('file_5'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($this->hasRequestParameter('file_6') && $this->getRequestParameter('file_6') != '' && $this->getRequestParameter('file_6') != null) { $fileName = $this->getRequestParameter('file_6'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($this->hasRequestParameter('file_7') && $this->getRequestParameter('file_7') != '' && $this->getRequestParameter('file_7') != null) { $fileName = $this->getRequestParameter('file_7'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($this->hasRequestParameter('file_8') && $this->getRequestParameter('file_8') != '' && $this->getRequestParameter('file_8') != null) { $fileName = $this->getRequestParameter('file_8'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($this->hasRequestParameter('file_9') && $this->getRequestParameter('file_9') != '' && $this->getRequestParameter('file_9') != null) { $fileName = $this->getRequestParameter('file_9'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($this->hasRequestParameter('file_10') && $this->getRequestParameter('file_10') != '' && $this->getRequestParameter('file_10') != null) { $fileName = $this->getRequestParameter('file_10'); $catalog_file = new CatalogFile(); $catalog_file->setCatalog($catalog); $catalog_file->setFile($fileName); $catalog_file->save(); } if ($this->hasRequestParameter('filter_code') && $this->getRequestParameter('filter_code') != '' && $this->getRequestParameter('filter_code') != null) { return $this->redirect('catalog/list?filters[code]=' . $this->getRequestParameter('filter_code')); } elseif ($this->hasRequestParameter('filter_title') && $this->getRequestParameter('filter_title') != '' && $this->getRequestParameter('filter_title') != null) { return $this->redirect('catalog/list?filters[title]=' . $this->getRequestParameter('filter_title')); } elseif ($this->hasRequestParameter('filter_category') && $this->getRequestParameter('filter_category') != '' && $this->getRequestParameter('filter_category') != null) { return $this->redirect('catalog/list?filters[cat_category_id]=' . $this->getRequestParameter('filter_category')); } elseif ($this->hasRequestParameter('filter_writer') && $this->getRequestParameter('filter_writer') != '' && $this->getRequestParameter('filter_writer') != null) { return $this->redirect('catalog/list?filters[writer]=' . $this->getRequestParameter('filter_writer')); } elseif ($this->hasRequestParameter('filter_publisher') && $this->getRequestParameter('filter_publisher') != '' && $this->getRequestParameter('filter_publisher') != null) { return $this->redirect('catalog/list?filters[publisher]=' . $this->getRequestParameter('filter_publisher')); } elseif ($this->hasRequestParameter('filter_copies') && $this->getRequestParameter('filter_copies') != '' && $this->getRequestParameter('filter_copies') != null) { return $this->redirect('catalog/list?filters[copies]=' . $this->getRequestParameter('filter_copies')); } else { return $this->redirect('catalog/list'); } }
public function testScenarioUsingQuery() { // Add publisher records // --------------------- try { $scholastic = new Publisher(); $scholastic->setName("Scholastic"); // do not save, will do later to test cascade $morrow = new Publisher(); $morrow->setName("William Morrow"); $morrow->save(); $morrow_id = $morrow->getId(); $penguin = new Publisher(); $penguin->setName("Penguin"); $penguin->save(); $penguin_id = $penguin->getId(); $vintage = new Publisher(); $vintage->setName("Vintage"); $vintage->save(); $vintage_id = $vintage->getId(); $this->assertTrue(true, 'Save Publisher records'); } catch (Exception $e) { $this->fail('Save publisher records'); } // Add author records // ------------------ try { $rowling = new Author(); $rowling->setFirstName("J.K."); $rowling->setLastName("Rowling"); // do not save, will do later to test cascade $stephenson = new Author(); $stephenson->setFirstName("Neal"); $stephenson->setLastName("Stephenson"); $stephenson->save(); $stephenson_id = $stephenson->getId(); $byron = new Author(); $byron->setFirstName("George"); $byron->setLastName("Byron"); $byron->save(); $byron_id = $byron->getId(); $grass = new Author(); $grass->setFirstName("Gunter"); $grass->setLastName("Grass"); $grass->save(); $grass_id = $grass->getId(); $this->assertTrue(true, 'Save Author records'); } catch (Exception $e) { $this->fail('Save Author records'); } // Add book records // ---------------- try { $phoenix = new Book(); $phoenix->setTitle("Harry Potter and the Order of the Phoenix"); $phoenix->setISBN("043935806X"); $phoenix->setAuthor($rowling); $phoenix->setPublisher($scholastic); $phoenix->save(); $phoenix_id = $phoenix->getId(); $this->assertFalse($rowling->isNew(), 'saving book also saves related author'); $this->assertFalse($scholastic->isNew(), 'saving book also saves related publisher'); $qs = new Book(); $qs->setISBN("0380977427"); $qs->setTitle("Quicksilver"); $qs->setAuthor($stephenson); $qs->setPublisher($morrow); $qs->save(); $qs_id = $qs->getId(); $dj = new Book(); $dj->setISBN("0140422161"); $dj->setTitle("Don Juan"); $dj->setAuthor($byron); $dj->setPublisher($penguin); $dj->save(); $dj_id = $qs->getId(); $td = new Book(); $td->setISBN("067972575X"); $td->setTitle("The Tin Drum"); $td->setAuthor($grass); $td->setPublisher($vintage); $td->save(); $td_id = $td->getId(); $this->assertTrue(true, 'Save Book records'); } catch (Exception $e) { $this->fail('Save Author records'); } // Add review records // ------------------ try { $r1 = new Review(); $r1->setBook($phoenix); $r1->setReviewedBy("Washington Post"); $r1->setRecommended(true); $r1->setReviewDate(time()); $r1->save(); $r1_id = $r1->getId(); $r2 = new Review(); $r2->setBook($phoenix); $r2->setReviewedBy("New York Times"); $r2->setRecommended(false); $r2->setReviewDate(time()); $r2->save(); $r2_id = $r2->getId(); $this->assertTrue(true, 'Save Review records'); } catch (Exception $e) { $this->fail('Save Review records'); } // Perform a "complex" search // -------------------------- $results = BookQuery::create()->filterByTitle('Harry%')->find(); $this->assertEquals(1, count($results)); $results = BookQuery::create()->where('Book.ISBN IN ?', array("0380977427", "0140422161"))->find(); $this->assertEquals(2, count($results)); // Perform a "limit" search // ------------------------ $results = BookQuery::create()->limit(2)->offset(1)->orderByTitle()->find(); $this->assertEquals(2, count($results)); // we ordered on book title, so we expect to get $this->assertEquals("Harry Potter and the Order of the Phoenix", $results[0]->getTitle()); $this->assertEquals("Quicksilver", $results[1]->getTitle()); // Perform a lookup & update! // -------------------------- // Updating just-created book title // First finding book by PK (=$qs_id) .... $qs_lookup = BookQuery::create()->findPk($qs_id); $this->assertNotNull($qs_lookup, 'just-created book can be found by pk'); $new_title = "Quicksilver (" . crc32(uniqid(rand())) . ")"; // Attempting to update found object $qs_lookup->setTitle($new_title); $qs_lookup->save(); // Making sure object was correctly updated: "; $qs_lookup2 = BookQuery::create()->findPk($qs_id); $this->assertEquals($new_title, $qs_lookup2->getTitle()); // Test some basic DATE / TIME stuff // --------------------------------- // that's the control timestamp. $control = strtotime('2004-02-29 00:00:00'); // should be two in the db $r = ReviewQuery::create()->findOne(); $r_id = $r->getId(); $r->setReviewDate($control); $r->save(); $r2 = ReviewQuery::create()->findPk($r_id); $this->assertEquals(new Datetime('2004-02-29 00:00:00'), $r2->getReviewDate(null), 'ability to fetch DateTime'); $this->assertEquals($control, $r2->getReviewDate('U'), 'ability to fetch native unix timestamp'); $this->assertEquals('2-29-2004', $r2->getReviewDate('n-j-Y'), 'ability to use date() formatter'); // Handle BLOB/CLOB Columns // ------------------------ $blob_path = dirname(__FILE__) . '/../../etc/lob/tin_drum.gif'; $blob2_path = dirname(__FILE__) . '/../../etc/lob/propel.gif'; $clob_path = dirname(__FILE__) . '/../../etc/lob/tin_drum.txt'; $m1 = new Media(); $m1->setBook($phoenix); $m1->setCoverImage(file_get_contents($blob_path)); $m1->setExcerpt(file_get_contents($clob_path)); $m1->save(); $m1_id = $m1->getId(); $m1_lookup = MediaQuery::create()->findPk($m1_id); $this->assertNotNull($m1_lookup, 'Can find just-created media item'); $this->assertEquals(md5(file_get_contents($blob_path)), md5(stream_get_contents($m1_lookup->getCoverImage())), 'BLOB was correctly updated'); $this->assertEquals(file_get_contents($clob_path), (string) $m1_lookup->getExcerpt(), 'CLOB was correctly updated'); // now update the BLOB column and save it & check the results $m1_lookup->setCoverImage(file_get_contents($blob2_path)); $m1_lookup->save(); $m2_lookup = MediaQuery::create()->findPk($m1_id); $this->assertNotNull($m2_lookup, 'Can find just-created media item'); $this->assertEquals(md5(file_get_contents($blob2_path)), md5(stream_get_contents($m2_lookup->getCoverImage())), 'BLOB was correctly overwritten'); // Test Validators // --------------- require_once 'tools/helpers/bookstore/validator/ISBNValidator.php'; $bk1 = new Book(); $bk1->setTitle("12345"); // min length is 10 $ret = $bk1->validate(); $this->assertFalse($ret, 'validation failed'); $failures = $bk1->getValidationFailures(); $this->assertEquals(1, count($failures), '1 validation message was returned'); $el = array_shift($failures); $this->assertContains("must be more than", $el->getMessage(), 'Expected validation message was returned'); $bk2 = new Book(); $bk2->setTitle("Don Juan"); $ret = $bk2->validate(); $this->assertFalse($ret, 'validation failed'); $failures = $bk2->getValidationFailures(); $this->assertEquals(1, count($failures), '1 validation message was returned'); $el = array_shift($failures); $this->assertContains("Book title already in database.", $el->getMessage(), 'Expected validation message was returned'); //Now trying some more complex validation. $auth1 = new Author(); $auth1->setFirstName("Hans"); // last name required; will fail $bk1->setAuthor($auth1); $rev1 = new Review(); $rev1->setReviewDate("08/09/2001"); // will fail: reviewed_by column required $bk1->addReview($rev1); $ret2 = $bk1->validate(); $this->assertFalse($ret2, 'validation failed'); $failures2 = $bk1->getValidationFailures(); $this->assertEquals(3, count($failures2), '3 validation messages were returned'); $expectedKeys = array(AuthorPeer::LAST_NAME, BookPeer::TITLE, ReviewPeer::REVIEWED_BY); $this->assertEquals($expectedKeys, array_keys($failures2), 'correct columns failed'); $bk2 = new Book(); $bk2->setTitle("12345678901"); // passes $auth2 = new Author(); $auth2->setLastName("Blah"); //passes $auth2->setEmail("*****@*****.**"); //passes $auth2->setAge(50); //passes $bk2->setAuthor($auth2); $rev2 = new Review(); $rev2->setReviewedBy("Me!"); // passes $rev2->setStatus("new"); // passes $bk2->addReview($rev2); $ret3 = $bk2->validate(); $this->assertTrue($ret3, 'complex validation can pass'); // Testing doCount() functionality // ------------------------------- // old way $c = new Criteria(); $records = BookPeer::doSelect($c); $count = BookPeer::doCount($c); $this->assertEquals($count, count($records), 'correct number of results'); // new way $count = BookQuery::create()->count(); $this->assertEquals($count, count($records), 'correct number of results'); // Test many-to-many relationships // --------------- // init book club list 1 with 2 books $blc1 = new BookClubList(); $blc1->setGroupLeader("Crazyleggs"); $blc1->setTheme("Happiness"); $brel1 = new BookListRel(); $brel1->setBook($phoenix); $brel2 = new BookListRel(); $brel2->setBook($dj); $blc1->addBookListRel($brel1); $blc1->addBookListRel($brel2); $blc1->save(); $this->assertNotNull($blc1->getId(), 'BookClubList 1 was saved'); // init book club list 2 with 1 book $blc2 = new BookClubList(); $blc2->setGroupLeader("John Foo"); $blc2->setTheme("Default"); $brel3 = new BookListRel(); $brel3->setBook($phoenix); $blc2->addBookListRel($brel3); $blc2->save(); $this->assertNotNull($blc2->getId(), 'BookClubList 2 was saved'); // re-fetch books and lists from db to be sure that nothing is cached $crit = new Criteria(); $crit->add(BookPeer::ID, $phoenix->getId()); $phoenix = BookPeer::doSelectOne($crit); $this->assertNotNull($phoenix, "book 'phoenix' has been re-fetched from db"); $crit = new Criteria(); $crit->add(BookClubListPeer::ID, $blc1->getId()); $blc1 = BookClubListPeer::doSelectOne($crit); $this->assertNotNull($blc1, 'BookClubList 1 has been re-fetched from db'); $crit = new Criteria(); $crit->add(BookClubListPeer::ID, $blc2->getId()); $blc2 = BookClubListPeer::doSelectOne($crit); $this->assertNotNull($blc2, 'BookClubList 2 has been re-fetched from db'); $relCount = $phoenix->countBookListRels(); $this->assertEquals(2, $relCount, "book 'phoenix' has 2 BookListRels"); $relCount = $blc1->countBookListRels(); $this->assertEquals(2, $relCount, 'BookClubList 1 has 2 BookListRels'); $relCount = $blc2->countBookListRels(); $this->assertEquals(1, $relCount, 'BookClubList 2 has 1 BookListRel'); // Cleanup (tests DELETE) // ---------------------- // Removing books that were just created // First finding book by PK (=$phoenix_id) .... $hp = BookQuery::create()->findPk($phoenix_id); $this->assertNotNull($hp, 'Could find just-created book'); // Attempting to delete [multi-table] by found pk $c = new Criteria(); $c->add(BookPeer::ID, $hp->getId()); // The only way for cascading to work currently // is to specify the author_id and publisher_id (i.e. the fkeys // have to be in the criteria). $c->add(AuthorPeer::ID, $hp->getAuthor()->getId()); $c->add(PublisherPeer::ID, $hp->getPublisher()->getId()); $c->setSingleRecord(true); BookPeer::doDelete($c); // Checking to make sure correct records were removed. $this->assertEquals(3, AuthorPeer::doCount(new Criteria()), 'Correct records were removed from author table'); $this->assertEquals(3, PublisherPeer::doCount(new Criteria()), 'Correct records were removed from publisher table'); $this->assertEquals(3, BookPeer::doCount(new Criteria()), 'Correct records were removed from book table'); // Attempting to delete books by complex criteria BookQuery::create()->filterByISBN("043935806X")->orWhere('Book.ISBN = ?', "0380977427")->orWhere('Book.ISBN = ?', "0140422161")->delete(); // Attempting to delete book [id = $td_id] $td->delete(); // Attempting to delete authors AuthorQuery::create()->filterById($stephenson_id)->delete(); AuthorQuery::create()->filterById($byron_id)->delete(); $grass->delete(); // Attempting to delete publishers PublisherQuery::create()->filterById($morrow_id)->delete(); PublisherQuery::create()->filterById($penguin_id)->delete(); $vintage->delete(); // These have to be deleted manually also since we have onDelete // set to SETNULL in the foreign keys in book. Is this correct? $rowling->delete(); $scholastic->delete(); $blc1->delete(); $blc2->delete(); $this->assertEquals(array(), AuthorPeer::doSelect(new Criteria()), 'no records in [author] table'); $this->assertEquals(array(), PublisherPeer::doSelect(new Criteria()), 'no records in [publisher] table'); $this->assertEquals(array(), BookPeer::doSelect(new Criteria()), 'no records in [book] table'); $this->assertEquals(array(), ReviewPeer::doSelect(new Criteria()), 'no records in [review] table'); $this->assertEquals(array(), MediaPeer::doSelect(new Criteria()), 'no records in [media] table'); $this->assertEquals(array(), BookClubListPeer::doSelect(new Criteria()), 'no records in [book_club_list] table'); $this->assertEquals(array(), BookListRelPeer::doSelect(new Criteria()), 'no records in [book_x_list] table'); }
protected function parse() { $data = array(); $details = $this->getResponseObject()->query('//*[@id="gameDetailsSection"]/div/ul[@class="fields"]')->item(0); if ($details) { $items = $this->nodeToXPath($details)->query('//li'); if ($items->length > 0) { foreach ($items as $bundle_item) { $val = $this->cleanData($bundle_item->nodeValue); //pre($val); //continue; if (stristr($val, 'release')) { $date = $this->parseValue($val, '/^.+:\\040?(.+)$/'); $data['release_date'] = date('Y-m-d H:i:s', strtotime($date)); } elseif (stristr($val, 'developer')) { $data['developer'] = $this->parseValue($val, '/^.+:\\040?(.+)$/'); } elseif (stristr($val, 'publisher')) { $data['publisher'] = $this->parseValue($val, '/^.+:\\040?(.+)$/'); } elseif (stristr($val, 'genre')) { $genres = $this->parseValue($val, '/^.+:\\040?(.+)$/'); if ($genres) { $data['genres'] = explode(',', $genres); } } elseif (stristr($val, 'size')) { $val = $this->parseValue($val, '/^.+:\\040?(.+)$/'); $data['size'] = $this->parseSize($val); } } } $data['description'] = $this->parseDescription(); $data['price'] = $this->parsePrice(); //$data['facebook_iframe_url'] = $this->parseFacebookIframeUrl(); //pre($data,1); if (isset($data['developer'])) { $dobject = DeveloperModel::findOneByTitle($data['developer']); if (!$dobject) { $dobject = new Developer(); $dobject->fromArray(array('title' => $data['developer'])); $developer_id = $dobject->save(); } else { $developer_id = $dobject->id; } $data['developer_id'] = $developer_id; } if (isset($data['publisher'])) { $dobject = PublisherModel::findOneByTitle($data['publisher']); if (!$dobject) { $dobject = new Publisher(); $dobject->fromArray(array('title' => $data['publisher'])); $publisher_id = $dobject->save(); } else { $publisher_id = $dobject->id; } $data['publisher_id'] = $publisher_id; } $data = $this->cleanData($data); pre($data, 1); $data['processed'] = 1; $this->content_object->fromArray($data); $this->content_object->save(); if (isset($data['genres'])) { // remove old genres associations $res = ContentToGenreModel::deleteByContentId($this->content_object->id); if ($res) { foreach ($data['genres'] as $genre) { $gobject = GenreModel::findOneByTitle($genre); if (!$gobject) { $gobject = new Genre(); $gobject->fromArray(array('title' => $genre)); $genre_id = $gobject->save(); } else { $genre_id = $gobject->id; } $ctg = new ContentToGenre(); $ctg->fromArray(array('content_id' => $this->content_object->id, 'genre_id' => $genre_id)); $ctg->save(); } } } } }