本文整理汇总了PHP中Propel\Runtime\Propel::getWriteConnection方法的典型用法代码示例。如果您正苦于以下问题:PHP Propel::getWriteConnection方法的具体用法?PHP Propel::getWriteConnection怎么用?PHP Propel::getWriteConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Propel\Runtime\Propel
的用法示例。
在下文中一共展示了Propel::getWriteConnection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateModules
public function updateModules()
{
$finder = new Finder();
$finder->name('module.xml')->in($this->baseModuleDir . '/*/Config');
$descriptorValidator = new ModuleDescriptorValidator();
foreach ($finder as $file) {
$content = $descriptorValidator->getDescriptor($file->getRealPath());
$reflected = new \ReflectionClass((string) $content->fullnamespace);
$code = basename(dirname($reflected->getFileName()));
$con = Propel::getWriteConnection(ModuleTableMap::DATABASE_NAME);
$con->beginTransaction();
try {
$module = ModuleQuery::create()->filterByCode($code)->findOne();
if (null === $module) {
$module = new Module();
$module->setCode($code)->setFullNamespace((string) $content->fullnamespace)->setType($this->getModuleType($reflected))->setActivate(0)->save($con);
}
$this->saveDescription($module, $content, $con);
$con->commit();
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
}
}
示例2: createOrUpdate
/**
* @param int $titleId customer title id (from customer_title table)
* @param string $firstname customer first name
* @param string $lastname customer last name
* @param string $address1 customer address
* @param string $address2 customer adress complement 1
* @param string $address3 customer adress complement 2
* @param string $phone customer phone number
* @param string $cellphone customer cellphone number
* @param string $zipcode customer zipcode
* @param string $city
* @param int $countryId customer country id (from Country table)
* @param string $email customer email, must be unique
* @param string $plainPassword customer plain password, hash is made calling setPassword method. Not mandatory parameter but an exception is thrown if customer is new without password
* @param string $lang
* @param int $reseller
* @param null $sponsor
* @param int $discount
* @param null $company
* @param null $ref
* @param bool $forceEmailUpdate true if the email address could be updated.
* @param int $stateId customer state id (from State table)
* @throws \Exception
* @throws \Propel\Runtime\Exception\PropelException
*/
public function createOrUpdate($titleId, $firstname, $lastname, $address1, $address2, $address3, $phone, $cellphone, $zipcode, $city, $countryId, $email = null, $plainPassword = null, $lang = null, $reseller = 0, $sponsor = null, $discount = 0, $company = null, $ref = null, $forceEmailUpdate = false, $stateId = null)
{
$this->setTitleId($titleId)->setFirstname($firstname)->setLastname($lastname)->setEmail($email, $forceEmailUpdate)->setPassword($plainPassword)->setReseller($reseller)->setSponsor($sponsor)->setDiscount($discount)->setRef($ref);
if (!is_null($lang)) {
$this->setLangId($lang);
}
$con = Propel::getWriteConnection(CustomerTableMap::DATABASE_NAME);
$con->beginTransaction();
try {
if ($this->isNew()) {
$address = new Address();
$address->setLabel(Translator::getInstance()->trans("Main address"))->setCompany($company)->setTitleId($titleId)->setFirstname($firstname)->setLastname($lastname)->setAddress1($address1)->setAddress2($address2)->setAddress3($address3)->setPhone($phone)->setCellphone($cellphone)->setZipcode($zipcode)->setCity($city)->setCountryId($countryId)->setStateId($stateId)->setIsDefault(1);
$this->addAddress($address);
if (ConfigQuery::isCustomerEmailConfirmationEnable()) {
$this->setConfirmationToken(bin2hex(random_bytes(32)));
}
} else {
$address = $this->getDefaultAddress();
$address->setCompany($company)->setTitleId($titleId)->setFirstname($firstname)->setLastname($lastname)->setAddress1($address1)->setAddress2($address2)->setAddress3($address3)->setPhone($phone)->setCellphone($cellphone)->setZipcode($zipcode)->setCity($city)->setCountryId($countryId)->setStateId($stateId)->save($con);
}
$this->save($con);
$con->commit();
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
}
示例3: setupAndGetPropelConnection
/**
* Set up propel connection
*
* @return \Propel\Runtime\Connection\ConnectionInterface
*/
protected function setupAndGetPropelConnection()
{
$config = Helper::getConfig();
Helper::setupPropel();
$con = Propel::getWriteConnection($config['database']['connectionName']);
return $con;
}
示例4: __construct
public function __construct()
{
$this->helper = new Helper();
$this->debug = Propel::getWriteConnection(\Map\JaCategoriasTableMap::DATABASE_NAME);
$this->debug->setLogMethods(array('exec', 'query', 'execute', 'beginTransaction', 'commit', 'rollBack', 'bindValue'));
$this->debug->useDebug(Config::$DEBUG_SQL);
}
示例5: execute
public function execute($params)
{
$id = $params['id'];
$movie = \Engine\MovieQuery::create()->findPK($id);
$movie->setTitle($params['title']);
$movie->setYear($params['year']);
$movie->setFormat($params['format']);
$actors = [];
//generate array of new actors
foreach ($params['actor_name'] as $key => $name) {
$actor = new \Engine\Actor();
$actor->setMovieId($id);
$actor->setName($name);
$actor->setSurname($params['actor_surname'][$key]);
$actors[] = $actor;
}
//propel accepts a collection to set related data
$collection = new \Propel\Runtime\Collection\ObjectCollection($actors);
$con = \Propel\Runtime\Propel::getWriteConnection(\Engine\Map\MovieTableMap::DATABASE_NAME);
$con->beginTransaction();
try {
//set collection of actors; this automatically deletes old related actors
$movie->setActors($collection);
$movie->save($con);
$con->commit();
} catch (Exception $e) {
$con->rollback();
throw $e;
}
return ['Message' => 'Movie has beed updated successfully.', 'Status' => 1];
}
示例6: createOrUpdate
/**
* Create or Update this Coupon
*
* @param string $code Coupon Code
* @param string $title Coupon title
* @param array $effects Ready to be serialized in JSON effect params
* @param string $type Coupon type
* @param bool $isRemovingPostage Is removing Postage
* @param string $shortDescription Coupon short description
* @param string $description Coupon description
* @param boolean $isEnabled Enable/Disable
* @param \DateTime $expirationDate Coupon expiration date
* @param boolean $isAvailableOnSpecialOffers Is available on special offers
* @param boolean $isCumulative Is cumulative
* @param int $maxUsage Coupon quantity
* @param string $defaultSerializedRule Serialized default rule added if none found
* @param string $locale Coupon Language code ISO (ex: fr_FR)
* @param array $freeShippingForCountries ID of Countries to which shipping is free
* @param array $freeShippingForMethods ID of Shipping modules for which shipping is free
* @param bool $perCustomerUsageCount True if usage coiunt is per customer
*
* @throws \Exception
*/
public function createOrUpdate($code, $title, array $effects, $type, $isRemovingPostage, $shortDescription, $description, $isEnabled, $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $maxUsage, $defaultSerializedRule, $locale, $freeShippingForCountries, $freeShippingForMethods, $perCustomerUsageCount)
{
$con = Propel::getWriteConnection(CouponTableMap::DATABASE_NAME);
$con->beginTransaction();
try {
$this->setCode($code)->setType($type)->setEffects($effects)->setIsRemovingPostage($isRemovingPostage)->setIsEnabled($isEnabled)->setExpirationDate($expirationDate)->setIsAvailableOnSpecialOffers($isAvailableOnSpecialOffers)->setIsCumulative($isCumulative)->setMaxUsage($maxUsage)->setPerCustomerUsageCount($perCustomerUsageCount)->setLocale($locale)->setTitle($title)->setShortDescription($shortDescription)->setDescription($description);
// If no rule given, set default rule
if (null === $this->getSerializedConditions()) {
$this->setSerializedConditions($defaultSerializedRule);
}
$this->save();
// Update countries and modules relation for free shipping
CouponCountryQuery::create()->filterByCouponId($this->id)->delete();
CouponModuleQuery::create()->filterByCouponId($this->id)->delete();
foreach ($freeShippingForCountries as $countryId) {
if ($countryId <= 0) {
continue;
}
$couponCountry = new CouponCountry();
$couponCountry->setCouponId($this->getId())->setCountryId($countryId)->save();
}
foreach ($freeShippingForMethods as $moduleId) {
if ($moduleId <= 0) {
continue;
}
$couponModule = new CouponModule();
$couponModule->setCouponId($this->getId())->setModuleId($moduleId)->save();
}
$con->commit();
} catch (\Exception $ex) {
$con->rollback();
throw $ex;
}
}
示例7: processLenderInvite
function processLenderInvite(Lender $invitee, InviteVisit $lenderInviteVisit)
{
$con = Propel::getWriteConnection(TransactionTableMap::DATABASE_NAME);
for ($retry = 0; $retry < 3; $retry++) {
$con->beginTransaction();
try {
$invite = $lenderInviteVisit->getInvite();
if ($invite) {
$res1 = $invite->setInvitee($invitee)->save();
} else {
$invite = new Invite();
$invite->setLender($lenderInviteVisit->getLender());
$invite->setEmail($invitee->getUser()->getEmail());
$invite->setInvitee($invitee);
$invite->setInvited(false);
$res1 = $invitee->save($con);
}
if (!$res1) {
throw new \Exception();
}
$this->transactionService->addLenderInviteTransaction($con, $invite);
} catch (\Exception $e) {
$con->rollback();
}
$con->commit();
//TODO , invite_notify(see below commented if statement)
// if ($lender['invite_notify']) {
$this->lenderMailer->sendLenderInviteCredit($invite);
// }
$this->mixpanelService->trackInviteAccept($invite);
return $invite;
}
return false;
}
示例8: delete
/**
* Delete a category entry
*
* @param \Thelia\Core\Event\Category\CategoryDeleteEvent $event
*/
public function delete(CategoryDeleteEvent $event)
{
if (null !== ($category = CategoryQuery::create()->findPk($event->getCategoryId()))) {
$con = Propel::getWriteConnection(CategoryTableMap::DATABASE_NAME);
$con->beginTransaction();
try {
// Get category's files to delete after category deletion
$fileList['images']['list'] = CategoryImageQuery::create()->findByCategoryId($event->getCategoryId());
$fileList['images']['type'] = TheliaEvents::IMAGE_DELETE;
$fileList['documentList']['list'] = CategoryDocumentQuery::create()->findByCategoryId($event->getCategoryId());
$fileList['documentList']['type'] = TheliaEvents::DOCUMENT_DELETE;
// Delete category
$category->setDispatcher($event->getDispatcher())->delete($con);
$event->setCategory($category);
// Dispatch delete category's files event
foreach ($fileList as $fileTypeList) {
foreach ($fileTypeList['list'] as $fileToDelete) {
$fileDeleteEvent = new FileDeleteEvent($fileToDelete);
$event->getDispatcher()->dispatch($fileTypeList['type'], $fileDeleteEvent);
}
}
$con->commit();
} catch (\Exception $e) {
$con->rollback();
throw $e;
}
}
}
示例9: delete
public function delete(FolderDeleteEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
if (null !== ($folder = FolderQuery::create()->findPk($event->getFolderId()))) {
$con = Propel::getWriteConnection(FolderTableMap::DATABASE_NAME);
$con->beginTransaction();
try {
$fileList = ['images' => [], 'documentList' => []];
// Get folder's files to delete after folder deletion
$fileList['images']['list'] = FolderImageQuery::create()->findByFolderId($event->getFolderId());
$fileList['images']['type'] = TheliaEvents::IMAGE_DELETE;
$fileList['documentList']['list'] = FolderDocumentQuery::create()->findByFolderId($event->getFolderId());
$fileList['documentList']['type'] = TheliaEvents::DOCUMENT_DELETE;
// Delete folder
$folder->setDispatcher($dispatcher)->delete($con);
$event->setFolder($folder);
// Dispatch delete folder's files event
foreach ($fileList as $fileTypeList) {
foreach ($fileTypeList['list'] as $fileToDelete) {
$fileDeleteEvent = new FileDeleteEvent($fileToDelete);
$dispatcher->dispatch($fileTypeList['type'], $fileDeleteEvent);
}
}
$con->commit();
} catch (\Exception $e) {
$con->rollback();
throw $e;
}
}
}
示例10: delete
public function delete(ModuleDeleteEvent $event)
{
if (null !== ($module = ModuleQuery::create()->findPk($event->getModuleId()))) {
$con = Propel::getWriteConnection(ModuleTableMap::DATABASE_NAME);
$con->beginTransaction();
try {
if (null === $module->getFullNamespace()) {
throw new \LogicException(Translator::getInstance()->trans('Cannot instanciante module "%name%": the namespace is null. Maybe the model is not loaded ?', array('%name%' => $module->getCode())));
}
try {
$instance = $module->createInstance();
$instance->setContainer($this->container);
$path = $module->getAbsoluteBaseDir();
$instance->destroy($con, $event->getDeleteData());
$fs = new Filesystem();
$fs->remove($path);
} catch (\ReflectionException $ex) {
// Happens probably because the module directory has been deleted.
// Log a warning, and delete the database entry.
Tlog::getInstance()->addWarning(Translator::getInstance()->trans('Failed to create instance of module "%name%" when trying to delete module. Module directory has probably been deleted', array('%name%' => $module->getCode())));
}
$module->delete($con);
$con->commit();
$event->setModule($module);
$this->cacheClear($event->getDispatcher());
} catch (\Exception $e) {
$con->rollBack();
throw $e;
}
}
}
示例11: execute
public function execute($params)
{
$movie = new \Engine\Movie();
$movie->setTitle($params['title']);
$movie->setYear($params['year']);
$movie->setFormat($params['format']);
$actors = [];
foreach ($params['actor_name'] as $key => $name) {
$actor = new \Engine\Actor();
$actor->setName($name);
$actor->setSurname($params['actor_surname'][$key]);
$actors[] = $actor;
}
$con = \Propel\Runtime\Propel::getWriteConnection(\Engine\Map\MovieTableMap::DATABASE_NAME);
$con->beginTransaction();
try {
$movie->save($con);
foreach ($actors as $actor) {
$actor->setMovieId($movie->getId());
$actor->save($con);
}
$con->commit();
} catch (Exception $e) {
$con->rollback();
throw $e;
}
return ['Message' => 'Movie has beed added successfully.', 'Status' => 1];
}
示例12: _failed
/**
* @param \Codeception\TestCase $test
* @param bool $fail
*
* @return void
*/
public function _failed(TestCase $test, $fail)
{
parent::_failed($test, $fail);
Propel::getWriteConnection('zed')->rollBack();
if (session_status() === PHP_SESSION_ACTIVE) {
session_destroy();
}
}
示例13: getVolunteerMentorCity
public function getVolunteerMentorCity()
{
$countryCode = \Session::get('BorrowerJoin.countryCode');
$country = CountryQuery::create()->filterByCountryCode($countryCode)->findOne();
$con = Propel::getWriteConnection(TransactionTableMap::DATABASE_NAME);
$sql = "SELECT DISTINCT city FROM borrower_profiles WHERE borrower_id IN " . "(SELECT borrower_id FROM volunteer_mentor WHERE country_id = :country_id AND status = :status\n AND mentee_count < :mentee_count)";
$stmt = $con->prepare($sql);
//TODO to make mentee_count = 50
$stmt->execute(array(':country_id' => $country->getId(), ':status' => '1', ':mentee_count' => '25'));
$cities = $stmt->fetchAll(\PDO::FETCH_COLUMN);
return array_combine($cities, $cities);
}
示例14: migrateShippingZones
protected function migrateShippingZones(MigrateCountryEvent $event)
{
$con = Propel::getWriteConnection(CountryAreaTableMap::DATABASE_NAME);
$con->beginTransaction();
try {
$updatedRows = CountryAreaQuery::create()->filterByCountryId($event->getCountry())->update(['CountryId' => $event->getNewCountry(), 'StateId' => $event->getNewState()]);
$con->commit();
return $updatedRows;
} catch (PropelException $e) {
$con->rollback();
throw $e;
}
}
示例15: runInTransaction
public static function runInTransaction($function)
{
$con = \Propel\Runtime\Propel::getWriteConnection(\Engine\Map\MovieTableMap::DATABASE_NAME);
$con->beginTransaction();
try {
$result = $function();
$con->commit();
return $result;
} catch (\Exception $e) {
$con->rollback();
throw $e;
}
}