/** * Removes items from the collection based on the given criteria. * * @param string $collection Name of the collection from which to remove items. * @param CriteriaExpression $criteria [optional] Lookup criteria. */ public function remove($collection, CriteriaExpression $criteria = null) { $this->connect(); $timer = new Timer(); $criteria = $this->criteriaParser->parse($criteria); try { $info = $this->database->{$collection}->deleteMany($criteria); } catch (MongoException $e) { $this->log('remove', $collection, $criteria, [], 'error'); throw new StoreQueryErrorException('MongoDB: ' . $e->getMessage(), $e->getCode(), $e); } // log this query $this->log('remove', $collection, $criteria, ['time' => $timer->stop(), 'affected' => is_array($info) ? $info['n'] : 'unknown']); }
/** * @expectedException \BadMethodCallException */ public function testDoubleStop() { $timer = new Timer(); $timer->stop(); $timer->stop(); }
/** * Removes items from the collection based on the given criteria. * * @param string $collection Name of the collection from which to remove items. * @param CriteriaExpression $criteria [optional] Lookup criteria. */ public function remove($collection, CriteriaExpression $criteria = null) { $this->connect(); $timer = new Timer(); $queryBuilder = $this->connection->createQueryBuilder()->delete($collection); $this->criteriaParser->parse($queryBuilder, $criteria); $sql = $queryBuilder->getSQL(); $sqlParams = $queryBuilder->getParameters(); // execute the query try { $queryBuilder->execute(); } catch (\Exception $e) { $this->log($sql, $sqlParams, [], 'error'); throw new StoreQueryErrorException('DoctrineDBAL: ' . $e->getMessage(), $e->getCode(), $e); } // log this query $this->log($sql, $sqlParams, ['time' => $timer->stop()]); }
/** * Removes items from the collection based on the given criteria. * * @param string $collection Name of the collection from which to remove items. * @param CriteriaExpression $criteria [optional] Lookup criteria. */ public function remove($collection, CriteriaExpression $criteria = null) { $timer = new Timer(); $this->ensureCollection($collection); // remove the matching items $affected = 0; foreach ($this->collections[$collection] as $i => $item) { if ($this->matcher->matches($item, $criteria)) { unset($this->collections[$collection][$i]); $affected++; } } // log this query $this->log('remove', $collection, $criteria ? $criteria->getRaw() : [], ['time' => $timer->stop(), 'affected' => $affected]); }
/** * Runs the application in context of the given mode and using the given runner function. * * The last argument is a callback that will be invoked by this method and it should contain * execution logic specific to the given mode. * * Returns whatever the runner returns (which should be a result of running the application). * * @param AbstractApplication $application Application to be ran. * @param int $mode Mode in which the application should be ran. * One of the `Framework::MODE_*` constants. * @param callable $runner Closure that is responsible for actually running * the application in appropriate mode. * @return mixed */ protected function doRunApplication(AbstractApplication $application, $mode, $runner) { $timer = new Timer(); $container = $application->getContainer(); // container can now know in what mode its running $container->setParameter('mode', $mode); // run modules and the app foreach ($application->getModules() as $module) { $module->run(); } $application->run(); // run using the passed runner $result = call_user_func($runner); // log benchmark data $time = $timer->stop(); $memory = $timer->getMemoryUsage(); $container->get('splot.logger')->debug('Application run phase in mode "{mode}" finished in {time} ms and used {memory} memory.', array('mode' => self::modeName($mode), 'env' => $container->getParameter('env'), 'debug' => $container->getParameter('debug'), 'time' => $time, 'memory' => StringUtils::bytesToString($memory), '@stat' => 'splot.run.' . self::modeName($mode), '@time' => $time, '@memory' => $memory)); return $result; }