本文整理汇总了PHP中Propel\Runtime\Propel::getConnection方法的典型用法代码示例。如果您正苦于以下问题:PHP Propel::getConnection方法的具体用法?PHP Propel::getConnection怎么用?PHP Propel::getConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Propel\Runtime\Propel
的用法示例。
在下文中一共展示了Propel::getConnection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateOrCreateLinkAction
public function updateOrCreateLinkAction($id)
{
// Check current user authorization
if (null !== ($response = $this->checkAuth(AdminResources::MODULE, DealerTeam::getModuleCode(), AccessManager::CREATE))) {
return $response;
}
$retour = [];
$code = 200;
$con = Propel::getConnection();
$con->beginTransaction();
try {
$data = ['id' => $id];
$tempOption = $this->getRequest()->request->get("option_id");
$dafyDealer = [];
foreach ($tempOption as $option) {
$data["dealer_option_id"] = $option;
$temp = $this->getService()->createFromArray($data);
if ($temp) {
$dafyDealer[] = $temp->toArray();
}
}
$con->commit();
$retour["data"] = $dafyDealer;
} catch (\Exception $e) {
$con->rollBack();
// Any other error
Tlog::getInstance()->addError($e->getMessage());
$code = $e->getCode();
if ($code == 0) {
$code = 500;
}
$retour["message"] = $e->getMessage();
}
return JsonResponse::create($retour, $code);
}
示例2: createOrUpdateLegacyProductAttributeValue
/**
* Create or update the configuration for a legacy product attribute value.
*
* @param int $productId Product id.
* @param int $attributeAvId Attribute value id.
* @param int $currencyId Currency id.
* @param float|null $priceDelta Price difference added (or removed) by the attribute value.
*
* @throws PropelException
*/
protected function createOrUpdateLegacyProductAttributeValue($productId, $attributeAvId, $currencyId, $priceDelta = null)
{
if ($priceDelta === null) {
return;
}
$legacyProductAttributeValue = LegacyProductAttributeValueQuery::create()->findPk([$productId, $attributeAvId]);
if ($legacyProductAttributeValue === null) {
$legacyProductAttributeValue = (new LegacyProductAttributeValue())->setProductId($productId)->setAttributeAvId($attributeAvId);
}
$legacyProductAttributeValuePriceDelta = LegacyProductAttributeValuePriceQuery::create()->findPk([$productId, $attributeAvId, $currencyId]);
if ($legacyProductAttributeValuePriceDelta === null) {
$legacyProductAttributeValuePriceDelta = (new LegacyProductAttributeValuePrice())->setProductId($productId)->setAttributeAvId($attributeAvId)->setCurrencyId($currencyId);
}
if ($priceDelta !== null) {
$legacyProductAttributeValuePriceDelta->setDelta($priceDelta);
}
Propel::getConnection()->beginTransaction();
try {
$legacyProductAttributeValue->save();
$legacyProductAttributeValuePriceDelta->save();
} catch (PropelException $e) {
Propel::getConnection()->rollBack();
throw $e;
}
Propel::getConnection()->commit();
}
示例3: install
/**
*/
public function install()
{
// install sql
$files = ['sql/keeko.sql', 'data/static-data.sql', 'data/dummy-data.sql'];
try {
$repo = $this->getServiceContainer()->getResourceRepository();
$con = Propel::getConnection();
foreach ($files as $file) {
if ($repo->contains('/iuf/junia/database/' . $file)) {
$sql = $repo->get('/iuf/junia/database/' . $file)->getBody();
$stmt = $con->prepare($sql);
$stmt->execute();
}
}
} catch (\Exception $e) {
echo $e->getMessage();
}
// install static data
// $comp = new Competition();
// $comp->setLabel('Individual Freestyle');
// $comp->save();
// $comp = new Competition();
// $comp->setLabel('Pairs Freestyle');
// $comp->save();
// $comp = new Competition();
// $comp->setLabel('Small Group Freestyle');
// $comp->save();
// $comp = new Competition();
// $comp->setLabel('Large Group Freestyle');
// $comp->save();
}
示例4: CreateOverwriteByExternalTypeIdAndExternalId
/**
* Create a task with transaction into the data gateway
*
* @param Request $request Request that will contain attributes of the new entity to be created
*
* @throws EmptyArray When an empty array is found
*
* @return void
*/
public function CreateOverwriteByExternalTypeIdAndExternalId(Request $request)
{
$con = Propel::getConnection();
$con->beginTransaction();
$this->retrieve(new Request(['externalTypeId' => $request->getData()['externalTypeId'], 'externalId' => $request->getData()['externalId']]));
if (count($this->getEntitiesFromResponse()) > 0) {
$con->rollBack();
return;
}
/** @var \Tasker\Mapper\Task\Entity $mapper */
$mapper = DbMapperFactory::make('task|entity');
$mapper->setArrays($request->getData());
/** @var \Tasker\DataGateway\Db\Entity\Task $task */
$dbTaskCollection = $mapper->getMappedSecondEntities();
if (!isset($dbTaskCollection[0])) {
$con->rollBack();
throw new EmptyArray('Array must be populated with one db entity', __FILE__, __LINE__);
}
/** @var ActiveRecordInterface $dbTask */
$dbTask = $dbTaskCollection[0];
$dbTask->save();
$con->commit();
$mapper->setArrays($dbTask->toArray());
$this->setEntitiesFromResponse($mapper->getMappedFirstEntities());
}
示例5: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if (!$input->getOption('force')) {
$output->writeln('<error>You have to use the "--force" option to drop the database.</error>');
return;
}
if ('prod' === $this->getApplication()->getKernel()->getEnvironment()) {
$this->writeSection($output, 'WARNING: you are about to drop a database in production !', 'bg=red;fg=white');
if (false === $this->askConfirmation($input, $output, 'Are you sure ? (y/n) ', false)) {
$output->writeln('Aborted, nice decision !');
return -2;
}
}
$connectionName = $input->getOption('connection') ?: $this->getDefaultConnection();
$config = $this->getConnectionData($connectionName);
$connection = Propel::getConnection($connectionName);
$dbName = $this->parseDbName($config['dsn']);
if (null === $dbName) {
return $output->writeln('<error>No database name found.</error>');
} else {
$query = 'DROP DATABASE ' . $dbName . ';';
}
$statement = $connection->prepare($query);
$statement->execute();
$output->writeln(sprintf('<info>Database <comment>%s</comment> has been dropped.</info>', $dbName));
}
示例6: deleteCard
/**
* @param Click $card
*/
public function deleteCard($card)
{
$delete = "\n DELETE FROM logintime t1\n JOIN\n (\n SELECT MAX(datetime)\n AS max_dt\n FROM logintime\n WHERE user_id = 1\n ) t2\nWHERE t1.datetime = t2.max_dt\n AND card = {$card->get}\n ";
$con = Propel::getConnection();
$stmt = $con->prepare($delete);
return $stmt->execute();
}
示例7: register
/**
* {@inheritDoc}
*/
public function register(Container $container)
{
// Append custom settings with missing params from default settings
$container['settings']['database'] = self::mergeWithDefaultSettings($container['settings']['database']);
$settings = $container['settings']['database'];
$logLevel = $settings['logger']['level'] ?? null;
$logPath = $settings['logger']['path'] ?? null;
$className = $settings['classname'] ?? null;
if (!$className) {
$className = 'Propel\\Runtime\\Connection\\ConnectionWrapper';
if ($logLevel == Logger::DEBUG) {
$className = 'Propel\\Runtime\\Connection\\ProfilerConnectionWrapper';
}
}
$manager = new ConnectionManagerSingle();
$manager->setConfiguration(['classname' => $className, 'dsn' => $settings['dsn'], 'user' => $settings['user'], 'password' => $settings['password'], 'settings' => $settings['settings']]);
$manager->setName($settings['connection']);
/** @var StandardServiceContainer $serviceContainer */
$serviceContainer = Propel::getServiceContainer();
$serviceContainer->checkVersion($settings['version']);
$serviceContainer->setAdapterClass($settings['connection'], $settings['adapter']);
$serviceContainer->setConnectionManager($settings['connection'], $manager);
$serviceContainer->setDefaultDatasource($settings['connection']);
if ($logPath && $logLevel) {
$logger = new Logger('defaultLogger');
$logger->pushHandler(new StreamHandler($logPath, $logLevel));
$serviceContainer->setLogger('defaultLogger', $logger);
if ($logLevel == Logger::DEBUG) {
/** @var ConnectionWrapper $con */
$con = Propel::getConnection();
$con->useDebug(true);
}
}
}
示例8: changeAppPhoto
function changeAppPhoto($params)
{
require 'session.php';
$con = Propel::getConnection('pos');
$con->beginTransaction();
$operationTime = time();
$unique = session_id() . time();
$file = $_FILES['photo'];
$folder = $session->get('pos/folder') . '/resources/images/';
$ext = pathinfo($file['name'], PATHINFO_EXTENSION);
$newfile = $unique . '.' . $ext;
$newfile_full_path = $folder . $newfile;
try {
if ($file['name'] == '') {
throw new Exception('Missing file');
}
if ($file['error'] > 0) {
throw new Exception($file['error']);
}
move_uploaded_file($file['tmp_name'], $newfile_full_path);
$appPhoto = OptionQuery::create()->filterByName(['app_photo'])->findOne($con);
$appPhoto->setValue($newfile)->save($con);
$results['success'] = true;
$results['photo'] = $newfile;
$con->commit();
} catch (Exception $e) {
$con->rollBack();
$results['success'] = false;
$results['errmsg'] = $e->getMessage();
}
return $results;
}
示例9: load
/**
* {@inheritdoc}
*/
public function load($files = array(), $connectionName)
{
$nbFiles = 0;
$this->deletedClasses = array();
$this->loadMapBuilders($connectionName);
$this->con = Propel::getConnection($connectionName);
try {
$this->con->beginTransaction();
$datas = array();
foreach ($files as $file) {
$content = $this->transformDataToArray($file);
if (count($content) > 0) {
$datas = array_merge_recursive($datas, $content);
$nbFiles++;
}
}
$this->deleteCurrentData($datas);
$this->loadDataFromArray($datas);
$this->con->commit();
} catch (\Exception $e) {
$this->con->rollBack();
throw $e;
}
return $nbFiles;
}
示例10: createOrUpdate
protected function createOrUpdate(PopInCampaignEvent $event, PopInCampaign $model)
{
$con = Propel::getConnection(PopInCampaignTableMap::DATABASE_NAME);
$con->beginTransaction();
try {
if (null !== ($id = $event->getId())) {
$model->setId($id);
}
if (null !== ($start = $event->getStart())) {
$model->setStart($start);
}
if (null !== ($end = $event->getEnd())) {
$model->setEnd($end);
}
if (null !== ($contentSourceType = $event->getContentSourceType())) {
$model->setContentSourceType($contentSourceType);
}
if (null !== ($contentSourceId = $event->getContentSourceId())) {
$model->setContentSourceId($contentSourceId);
}
$model->save($con);
$con->commit();
} catch (\Exception $e) {
$con->rollback();
throw $e;
}
$event->setPopInCampaign($model);
}
示例11: setUp
/**
* This is run before each unit test; it populates the database.
*/
protected function setUp()
{
Propel::init(__DIR__ . '/../../../../Fixtures/bookstore/build/conf/bookstore-conf.php');
parent::setUp();
$this->con = Propel::getConnection(BookPeer::DATABASE_NAME);
$this->con->beginTransaction();
}
示例12: testSimpleCountSql
public function testSimpleCountSql()
{
$con = \Propel\Runtime\Propel::getConnection();
$con->useDebug(true);
$exec = QuerycacheTable1Query::create()->count($con);
$expectedSql = $this->getSql("SELECT COUNT(*) FROM querycache_table1");
$renderedSql = \Propel\Runtime\Propel::getConnection()->getLastExecutedQuery();
$this->assertEquals($expectedSql, $renderedSql);
}
示例13: __construct
/**
* Model constructor.
*/
public function __construct()
{
if (USE_ORM === true) {
$this->dbase = Propel::getConnection();
} else {
$this->_dbConfig = unserialize(DATABASE);
$this->dbase = new Database($this->_dbConfig);
}
}
示例14: getCardClicksDataWithinSeconds
/**
* Get Card Clicks count within Seconds.
*
* @param int $seconds
* @return array
*/
public function getCardClicksDataWithinSeconds($seconds = 45)
{
$query = "\n SELECT game_id,card,count(card) as clicks\n FROM `bingo_click`\n WHERE time_create > (NOW() - INTERVAL {$seconds} SECOND)\n GROUP BY card\n ORDER BY clicks DESC\n ";
$con = Propel::getConnection();
$stmt = $con->prepare($query);
$stmt->execute();
$clickResult = $stmt->fetchAll(\PDO::FETCH_ASSOC);
return $clickResult;
}
示例15: saveOrder
/**
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
* @param \Generated\Shared\Transfer\CheckoutResponseTransfer $checkoutResponseTransfer
*
* @return void
*/
public function saveOrder(QuoteTransfer $quoteTransfer, CheckoutResponseTransfer $checkoutResponseTransfer)
{
$this->assertOrderRequirements($quoteTransfer);
Propel::getConnection()->beginTransaction();
$salesOrderEntity = $this->saveOrderEntity($quoteTransfer);
$this->saveOrderItems($quoteTransfer, $salesOrderEntity);
Propel::getConnection()->commit();
$this->hydrateCheckoutResponseTransfer($checkoutResponseTransfer, $quoteTransfer, $salesOrderEntity);
}