public function testFormatALotOfResults() { $nbBooks = 50; $con = Propel::getConnection(BookPeer::DATABASE_NAME); Propel::disableInstancePooling(); $book = new Book(); for ($i = 0; $i < $nbBooks; $i++) { $book->clear(); $book->setTitle('BookTest' . $i); $book->save($con); } $stmt = $con->query('SELECT * FROM book'); $formatter = new PropelOnDemandFormatter(); $formatter->init(new ModelCriteria('bookstore', 'Book')); $books = $formatter->format($stmt); $this->assertTrue($books instanceof PropelOnDemandCollection, 'PropelOnDemandFormatter::format() returns a PropelOnDemandCollection'); $this->assertEquals($nbBooks, count($books), 'PropelOnDemandFormatter::format() returns a collection that counts as many rows as the results in the query'); $i = 0; foreach ($books as $book) { $this->assertTrue($book instanceof Book, 'PropelOnDemandFormatter::format() returns a collection of Model objects'); $this->assertEquals('BookTest' . $i, $book->getTitle(), 'PropelOnDemandFormatter::format() returns the model objects matching the query'); $i++; } Propel::enableInstancePooling(); }
/** * @param AbstractFormatter $formatter * @param DataFetcherInterface $dataFetcher */ public function __construct(AbstractFormatter $formatter, DataFetcherInterface $dataFetcher) { $this->currentKey = -1; $this->formatter = $formatter; $this->dataFetcher = $dataFetcher; $this->enableInstancePoolingOnFinish = Propel::disableInstancePooling(); }
protected function setUp() { parent::setUp(); BookstoreDataPopulator::populate($this->con); Propel::disableInstancePooling(); $this->books = PropelQuery::from('\\Propel\\Tests\\Bookstore\\Book')->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)->find(); }
public function boot() { parent::boot(); $this->configure(); if (function_exists('ppm_log')) { //In an environment like PPM with several workers Propel's not distributed cache will //lead to inconsistent states across all workers, so we need to disable it here completely. //Jarves already caches using a distributed cache where all workers are notified when //a change changes, so we don't really need Propel's cache here. Propel::disableInstancePooling(); } if (!$this->booted) { /** @var ContainerInterface $container */ $container = $this->container; /** @var $jarves Jarves */ $jarves = $container->get('jarves'); /** @var JarvesConfig $jarvesConfig */ $jarvesConfig = $container->get('jarves.config'); $twig = $container->get('twig'); $twig->addGlobal('jarves_content_render', $container->get('jarves.content.render')); $twig->addGlobal('pageStack', $container->get('jarves.page_stack')); if ($jarvesConfig->getSystemConfig()->getLogs(true)->isActive()) { /** @var $logger \Symfony\Bridge\Monolog\Logger */ $logger = $container->get('logger'); $logger->pushHandler($container->get('jarves.logger.handler')); } } $this->booted = true; }
function initialize() { $loader = (require_once __DIR__ . '/../propel_20/vendor/autoload.php'); include realpath(dirname(__FILE__) . '/build/conf/config.php'); $loader->add('', __DIR__ . '/build/classes'); \Propel\Runtime\Propel::disableInstancePooling(); $this->con = \Propel\Runtime\Propel::getConnection('bookstore'); $this->initTables(); }
public function testInstancePoolingReenabled() { Propel::enableInstancePooling(); $books = PropelQuery::from('\\Propel\\Tests\\Bookstore\\Book')->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)->find($this->con); foreach ($books as $book) { } $this->assertTrue(Propel::isInstancePoolingEnabled()); Propel::disableInstancePooling(); $books = PropelQuery::from('\\Propel\\Tests\\Bookstore\\Book')->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)->find($this->con); foreach ($books as $book) { } $this->assertFalse(Propel::isInstancePoolingEnabled()); Propel::enableInstancePooling(); }
/** * Populate the database using all the Entity classes previously added. * * @param PropelPDO $con A Propel connection object * * @return array A list of the inserted PKs */ public function execute($con = null) { if (null === $con) { $con = $this->getConnection(); } $isInstancePoolingEnabled = Propel::isInstancePoolingEnabled(); Propel::disableInstancePooling(); $insertedEntities = array(); $con->beginTransaction(); foreach ($this->quantities as $class => $number) { for ($i = 0; $i < $number; $i++) { $insertedEntities[$class][] = $this->entities[$class]->execute($con, $insertedEntities); } } $con->commit(); if ($isInstancePoolingEnabled) { Propel::enableInstancePooling(); } return $insertedEntities; }
public function initialization() { Propel::disableInstancePooling(); Propel::getConnection('default'); }
public function testFindPkSimpleWithAbstractSingleTableInheritanceReturnCorrectClass() { Propel::disableInstancePooling(); $manager = new DistributionManager(); $manager->setName('manager1'); $manager->save(); $distributionStore = new DistributionStore(); $distributionStore->setName('my store 1'); $distributionStore->setDistributionManager($manager); $distributionStore->save(); $distributionVirtualStore = new DistributionVirtualStore(); $distributionVirtualStore->setName('my VirtualStore 1'); $distributionVirtualStore->setDistributionManager($manager); $distributionVirtualStore->save(); $this->assertInstanceOf('Propel\\Tests\\Bookstore\\DistributionStore', DistributionQuery::create()->findPk($distributionStore->getId()), 'findPk() return right object : DistributionStore'); $this->assertInstanceOf('Propel\\Tests\\Bookstore\\DistributionVirtualStore', DistributionQuery::create()->findPk($distributionVirtualStore->getId()), 'findPk() return right object : DistributionVirtualStore'); Propel::enableInstancePooling(); }
/** * @param PropelFormatter $formatter * @param PDOStatement $stmt */ public function __construct(PropelFormatter $formatter, PDOStatement $stmt) { $this->formatter = $formatter; $this->stmt = $stmt; $this->enableInstancePoolingOnFinish = Propel::disableInstancePooling(); }
public function testFindOneWithoutUsingInstancePool() { BookstoreDataPopulator::populate(); Propel::disableInstancePooling(); $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book'); $c->orderBy('Propel\\Tests\\Bookstore\\Book.Title'); $c->join('Propel\\Tests\\Bookstore\\Book.Author'); $c->with('Author'); $c->join('Propel\\Tests\\Bookstore\\Book.Publisher'); $c->with('Publisher'); $this->assertCorrectHydration1($c, 'without instance pool'); Propel::enableInstancePooling(); }
public function onMessage(ConnectionInterface $from, $msg) { $event = $from->event = 'anonymous'; $data = []; // if message did not exist then deny access if (!isset($msg) || $msg == '') { throw new Exception('Wrong turn buddy'); } // if event or data did not exist then deny access $msg = json_decode($msg); if (!$msg || !isset($msg->event) || !isset($msg->data)) { throw new Exception('Wrong turn buddy'); } // store baby store em to variables $event = $from->event = $msg->event; $params = $msg->data; // if user not loged in yet then deny access if ($from->Session->get('pos/state') != 1) { throw new Exception('Akses ditolak. Anda belum login.'); } // initiating propel orm require_once 'propel-config.php'; Propel::disableInstancePooling(); $con = Propel::getConnection('pos'); // if user don't have role assigned then deny access $role = RoleQuery::create()->findOneById($from->Session->get('pos/current_user')->role_id); if (!$role) { throw new Exception('Akses ditolak. Anda belum punya Jabatan.'); } // uh... decoding event to get requested module and method $decode = explode('/', $event); // if decoded array length is not 2 then deny access if (count($decode) != 2) { throw new Exception('Wrong turn buddy'); } // store baby store em to variables... again $module = $decode[0]; $method = $decode[1]; // list of all module that can be requested $registeredModule = array('chart', 'combo', 'credit', 'customer', 'debit', 'notification', 'option', 'populate', 'product', 'purchase', 'report', 'role', 'sales', 'secondParty', 'stock', 'supplier', 'unit', 'user'); // if requested module is not registered then deny access if (!in_array($module, $registeredModule)) { throw new Exception('Wrong turn buddy'); } // you know it.. begin transaction $con->beginTransaction(); // this is where magic begins.. // route to requested module $data = $this->{$module}($method, $params, $from, $con); // commit transaction $con->commit(); // store to results variable before spitting it out back to client $results['event'] = $event; $results['data'] = $data; // errmmmmm $from->send(json_encode($results)); // followup action if ($event == 'purchase/create' || $event == 'purchase/destroy' || $event == 'purchase/update') { // get update of last 30 Days transaction's data $data = $this->chart('last30DaysTransaction', new \stdClass(), $from, $con); $last30DaysTransaction['event'] = 'chart/last30DaysTransaction'; $last30DaysTransaction['data'] = $data; // iterate through all connected client foreach ($this->clients as $client) { // get notification update of each client $data = $this->notification('read', new \stdClass(), $client, $con); $results['event'] = 'notification/read'; $results['data'] = $data; // push notification to each client $client->send(json_encode($results)); // push last 30 Days transaction's data to each client $client->send(json_encode($last30DaysTransaction)); } } elseif ($event == 'sales/create' || $event == 'sales/destroy' || $event == 'sales/update') { // get update of last 30 Days transaction's data $data = $this->chart('last30DaysTransaction', new \stdClass(), $from, $con); $last30DaysTransaction['event'] = 'chart/last30DaysTransaction'; $last30DaysTransaction['data'] = $data; // iterate through all connected client foreach ($this->clients as $client) { // push last 30 Days transaction's data to each client $client->send(json_encode($last30DaysTransaction)); } } // finish return; }
public function testHydrateOverwritePreviousValues() { $schema = <<<EOF <database name="generated_object_complex_type_test_with_constructor" namespace="MyNameSpace"> <table name="complex_column_type_entity_with_constructor"> <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" /> <column name="tags" type="ARRAY" /> </table> </database> EOF; QuickBuilder::buildSchema($schema); Propel::disableInstancePooling(); // need to be disabled to test the hydrate() method $obj = new ComplexColumnTypeEntityWithConstructor(); $this->assertEquals(array('foo', 'bar'), $obj->getTags()); $obj->setTags(array('baz')); $this->assertEquals(array('baz'), $obj->getTags()); $obj->save(); $obj = ComplexColumnTypeEntityWithConstructorQuery::create()->findOne(); $this->assertEquals(array('baz'), $obj->getTags()); Propel::enableInstancePooling(); }
public function disablePooling() { \Propel\Runtime\Propel::disableInstancePooling(); }
public function testDoSelectJoinOneToOne() { $con = Propel::getServiceContainer()->getReadConnection(BookstoreEmployeeAccountPeer::DATABASE_NAME); $count = $con->getQueryCount(); Propel::disableInstancePooling(); $c = new Criteria(); $accs = BookstoreEmployeeAccountPeer::doSelectJoinBookstoreEmployee($c, $con); Propel::enableInstancePooling(); $this->assertEquals(1, $con->getQueryCount() - $count, 'doSelectJoin() makes only one query in a one-to-one relationship'); }
/** * @expectedException \Propel\Runtime\Exception\RuntimeException * @expectedExceptionMessage Propel\Runtime\Collection\ObjectCollection::populateRelation needs instance pooling to be enabled prior to populating the collection */ public function testPopulateRelationWhenInstancePoolingIsDisabled() { $coll = new ObjectCollection(); Propel::disableInstancePooling(); $coll->populateRelation('Book'); }
/** * Bug found in Thelia 2.0.2 */ public function testUpdateDefaultAddress() { /** * Disable propel cache in order to get a new instance of the * active record in $updatedAddress */ Propel::disableInstancePooling(); /** * Get a customer and it's default address */ $customer = CustomerQuery::create()->findOne(); $defaultAddress = $customer->getDefaultAddress(); $addressId = $defaultAddress->getId(); /** * Try to update the address, and set the isDefault argument, * that should keep this address as the default one. */ $addressEvent = new AddressCreateOrUpdateEvent("", 1, "Thelia modif", "Thelia modif", "cour des étoiles", "rue des miracles", "", "63000", "clermont-ferrand", 64, "0102030405", "", "", 1); $addressEvent->setAddress($defaultAddress); $addressEvent->setDispatcher($this->getMock("Symfony\\Component\\EventDispatcher\\EventDispatcherInterface")); /** * Do the update */ $actionAddress = new Address(); $actionAddress->update($addressEvent); $updatedAddress = AddressQuery::create()->findPk($addressId); /** * This address should still be the default address */ $this->assertEquals(1, $updatedAddress->getIsDefault()); /** * Renable it after */ Propel::enableInstancePooling(); }
/** * @param AbstractFormatter $formatter * @param StatementInterface $stmt */ public function __construct(AbstractFormatter $formatter, StatementInterface $stmt) { $this->formatter = $formatter; $this->stmt = $stmt; $this->enableInstancePoolingOnFinish = Propel::disableInstancePooling(); }
/** * To illustrate that instance pooling makes no difference */ public function testPoisonedCacheWithJoinInstancePoolingDisabled() { Propel::disableInstancePooling(); $this->testPoisonedCacheWhenDoSelectJoinAuthor(); }
public function testFormatALotOfResults() { $nbBooks = 50; $con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME); Propel::disableInstancePooling(); $book = new Book(); for ($i = 0; $i < $nbBooks; $i++) { $book->clear(); $book->setTitle('BookTest' . $i); $book->setISBN('FA404-' . $i); $book->save($con); } $stmt = $con->query('SELECT id, title, isbn, price, publisher_id, author_id FROM book ORDER BY book.ID ASC'); $formatter = new OnDemandFormatter(); $formatter->init(new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book')); $books = $formatter->format($stmt); $this->assertTrue($books instanceof OnDemandCollection, 'OnDemandFormatter::format() returns a PropelOnDemandCollection'); $this->assertEquals($nbBooks, count($books), 'OnDemandFormatter::format() returns a collection that counts as many rows as the results in the query'); $i = 0; foreach ($books as $book) { $this->assertTrue($book instanceof Book, 'OnDemandFormatter::format() returns a collection of Model objects'); $this->assertEquals('BookTest' . $i, $book->getTitle(), 'OnDemandFormatter::format() returns the model objects matching the query'); $i++; } Propel::enableInstancePooling(); }