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);
 }
 /**
  * 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
0
文件: JuniaModule.php 项目: iuf/junia
 /**
  */
 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
0
 /**
  * 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
0
 /**
  * {@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
0
 /**
  * @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
0
 /**
  * {@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
0
文件: Mains.php 项目: AlvaCorp/POS-2
 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
0
 /**
  * {@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
0
 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
0
 /**
  * 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
0
 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
0
文件: Model.php 项目: nenepadi/diy
 /**
  * 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
0
 /**
  * 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
0
 /**
  * @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);
 }
示例#16
0
 /**
  * This is run before each unit test; it populates the database.
  */
 protected function setUp()
 {
     Propel::init(dirname(__FILE__) . '/../../../../Fixtures/bookstore/build/conf/bookstore-conf.php');
     parent::setUp();
     $this->con = Propel::getConnection(PagePeer::DATABASE_NAME);
     $this->con->beginTransaction();
     CmsDataPopulator::depopulate($this->con);
     CmsDataPopulator::populate($this->con);
 }
示例#17
0
 /**
  * Allowed try/catch. If we have no database setup, getConnection throws an Exception
  * ServiceProvider is called more then once and after setup of database we can enable debug
  *
  * @return bool
  */
 private function hasConnection()
 {
     try {
         Propel::getConnection();
         return true;
     } catch (\Exception $e) {
         return false;
     }
 }
 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();
 }
示例#19
0
 /**
  * Constructor.
  *
  * @param \Symfony\Component\Security\Acl\Model\PermissionGrantingStrategyInterface $permissionGrantingStrategy
  * @param ConnectionInterface                                                       $connection
  * @param \Symfony\Component\Security\Acl\Model\AclCacheInterface                   $cache
  */
 public function __construct(PermissionGrantingStrategyInterface $permissionGrantingStrategy, ConnectionInterface $connection = null, AclCacheInterface $cache = null)
 {
     // @codeCoverageIgnoreStart
     if (null === $connection) {
         $connection = Propel::getConnection(EntryTableMap::DATABASE_NAME, ServiceContainerInterface::CONNECTION_WRITE);
     }
     // @codeCoverageIgnoreEnd
     parent::__construct($permissionGrantingStrategy, $connection, $cache);
 }
 protected function setUp()
 {
     // Initialize translator
     new Translator(new Container());
     $this->exportHandler = new ProductPricesExport(new Container());
     $this->importHandler = new ProductPricesImport(new Container());
     $this->con = Propel::getConnection();
     $this->con->beginTransaction();
 }
 protected function setUp()
 {
     parent::setUp();
     Propel::init(__DIR__ . '/../../../../Fixtures/reverse/pgsql/build/conf/reverse-bookstore-conf.php');
     $this->con = Propel::getConnection('reverse-bookstore');
     $this->con->beginTransaction();
     if ('pgsql' !== $this->con->getAttribute(\PDO::ATTR_DRIVER_NAME)) {
         $this->markTestSkipped('This test is designed for PostgreSQL');
     }
 }
 protected function init(InputInterface $input)
 {
     $this->initRequest();
     $container = $this->getContainer();
     $this->translator = $container->get('thelia.translator');
     $this->parser = $container->get('thelia.parser');
     $this->con = Propel::getConnection(ProductTableMap::DATABASE_NAME);
     $this->initLocales($input);
     $this->initParser();
 }
示例#23
0
 /**
  * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
  * @param \Generated\Shared\Transfer\CheckoutResponseTransfer $checkoutResponse
  *
  * @return void
  */
 public function saveShipmentForOrder(QuoteTransfer $quoteTransfer, CheckoutResponseTransfer $checkoutResponse)
 {
     $this->assertShipmentRequirements($quoteTransfer);
     Propel::getConnection()->beginTransaction();
     $salesOrderEntity = $this->getSalesOrderByIdSalesOrder($checkoutResponse->getSaveOrder()->getIdSalesOrder());
     $this->addShippingDetailsToOrder($quoteTransfer, $salesOrderEntity);
     $this->addExpensesToOrder($quoteTransfer, $salesOrderEntity, $checkoutResponse);
     $salesOrderEntity->save();
     Propel::getConnection()->commit();
 }
示例#24
0
 protected function setUp()
 {
     parent::setUp();
     // Start a transaction to revert all the modification after the test
     $this->con = Propel::getConnection();
     $this->con->beginTransaction();
     // Drop the table to be sure we have a clean environment
     $this->con->exec("SET FOREIGN_KEY_CHECKS = 0;");
     $this->con->exec("DROP TABLE IF EXISTS `example_table`");
 }
示例#25
0
 /**
  * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
  *
  * @return void
  */
 public function saveOrder(QuoteTransfer $quoteTransfer)
 {
     Propel::getConnection()->beginTransaction();
     $paymentTransfer = $quoteTransfer->getPayonePayment();
     $paymentTransfer->setFkSalesOrder($orderTransfer->getIdSalesOrder());
     $payment = $this->savePayment($paymentTransfer);
     $paymentDetailTransfer = $paymentTransfer->getPaymentDetail();
     $this->savePaymentDetail($payment, $paymentDetailTransfer);
     Propel::getConnection()->commit();
 }
示例#26
0
 /**
  * Execute one simple database query to test connection.
  *
  * @return void
  */
 public function testDatabaseConnection()
 {
     $minion = $this->commonInitFramework();
     // must boot services to init propel connection
     $minion->boot();
     $con = Propel::getConnection();
     $date = $con->query("SELECT date('now') AS `date`")->fetch();
     $this->assertArrayHasKey(0, $date);
     $this->assertEquals(\date('Y-m-d'), $date[0]);
 }
示例#27
0
 protected function getConnection()
 {
     // use the first connection available
     $class = key($this->entities);
     if (!$class) {
         throw new \RuntimeException('No class found from entities. Did you add entities to the Populator ?');
     }
     $peer = $class::TABLE_MAP;
     return Propel::getConnection($peer::DATABASE_NAME, ServiceContainerInterface::CONNECTION_WRITE);
 }
 protected function setUp()
 {
     include __DIR__ . '/../../../Fixtures/reverse/mysql/build/conf/reverse-bookstore-conf.php';
     $this->con = Propel::getConnection('reverse-bookstore');
     $this->parser = new MysqlSchemaParser($this->con);
     $this->platform = new MysqlPlatform();
     $this->parser->setGeneratorConfig(new QuickGeneratorConfig());
     $this->parser->setPlatform($this->platform);
     parent::setUp();
 }
示例#29
0
 public function __construct()
 {
     $this->log_file = THELIA_LOG_DIR . DS . 'import-log.txt';
     // Set the current router ID, to use our parent's route methods on our routes
     $this->setCurrentRouter("router.ImportT1");
     $destination = "Thelia\\Log\\Destination\\TlogDestinationFile";
     Tlog::getInstance()->setLevel(Tlog::INFO)->setDestinations($destination)->setConfig($destination, TlogDestinationFile::VAR_PATH_FILE, $this->log_file)->setFiles('*')->setPrefix('[#LEVEL] #DATE #HOUR:');
     // Do not log requests
     Propel::getConnection(ProductTableMap::DATABASE_NAME)->useDebug(false);
 }
示例#30
0
 protected function init(InputInterface $input)
 {
     $container = $this->getContainer();
     $container->set("request", new Request());
     $container->get("request")->setSession(new Session(new MockArraySessionStorage()));
     $this->translator = $container->get('thelia.translator');
     $this->parser = $container->get('thelia.parser');
     $this->con = Propel::getConnection(ProductTableMap::DATABASE_NAME);
     $this->initLocales($input);
     $this->initParser();
 }