本文整理汇总了PHP中XLite\Core\Database::getEM方法的典型用法代码示例。如果您正苦于以下问题:PHP Database::getEM方法的具体用法?PHP Database::getEM怎么用?PHP Database::getEM使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XLite\Core\Database
的用法示例。
在下文中一共展示了Database::getEM方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doActionUpdate
/**
* Update payment method
*
* @return void
*/
protected function doActionUpdate()
{
$settings = \XLite\Core\Request::getInstance()->settings;
$method = $this->getPaymentMethod();
if (!$method) {
\XLite\Core\TopMessage::addError('An attempt to update settings of unknown payment method');
} else {
if (is_array($settings)) {
foreach ($settings as $name => $value) {
$method->setSetting($name, trim($value));
}
}
$properties = \XLite\Core\Request::getInstance()->properties;
if (is_array($properties) && !empty($properties)) {
$method->map($properties);
}
\XLite\Core\Database::getRepo('\\XLite\\Model\\Payment\\Method')->update($method);
// If "just added" method is configured and can be enabled then we enable it
if (\XLite\Core\Request::getInstance()->just_added && $method->isConfigured() && $method->canEnable()) {
$method->setEnabled(true);
\XLite\Core\Database::getEM()->flush();
}
if ($method->isConfigured()) {
\XLite\Core\TopMessage::addInfo('The settings of payment method successfully updated');
$this->setReturnURL($this->buildURL('payment_settings'));
} else {
\XLite\Core\TopMessage::addWarning('Payment method has not been configured properly');
}
}
}
示例2: executeHookHandler
/**
* Execute certain hook handle
*
* @return void
*/
public function executeHookHandler()
{
if (\XLite\Upgrade\Cell::getInstance()->isUpgraded()) {
$entries = \XLite\Upgrade\Cell::getInstance()->getEntries();
if ($entries) {
\Includes\Utils\Operator::showMessage('', true, false);
/** @var \XLite\Upgrade\Entry\AEntry $entry */
foreach ($entries as $entry) {
if (!$entry->isPostUpgradeActionsCalled()) {
$message = '...Invoke actions for ' . $entry->getActualName();
\Includes\Decorator\Utils\CacheManager::logMessage(PHP_EOL);
\Includes\Decorator\Utils\CacheManager::logMessage($message);
$isInvoked = \XLite\Upgrade\Cell::getInstance()->runHelper($entry, 'post_rebuild');
if ($isInvoked && \XLite\Upgrade\Cell::getInstance()->getHookRedirect()) {
break;
}
if (!\XLite\Upgrade\Cell::getInstance()->hasUnfinishedUpgradeHooks('post_rebuild', $entry)) {
// All post-rebuild hooks completed, run the rest actions...
\XLite\Upgrade\Cell::getInstance()->runCommonHelper($entry, 'add_labels');
\XLite\Upgrade\Cell::getInstance()->callInstallEvent($entry);
$entry->setPostUpgradeActionsCalled();
}
if (\Includes\Decorator\Utils\CacheManager::isTimeExceeds(static::STEP_TTL)) {
break;
}
}
}
}
}
\Includes\Decorator\Utils\CacheManager::logMessage(PHP_EOL);
\XLite\Core\Database::getEM()->flush();
\XLite\Core\Database::getEM()->clear();
}
示例3: doActionRun
/**
* Run task
*
* @return void
*/
protected function doActionRun()
{
$event = \XLite\Core\Request::getInstance()->event;
$result = false;
$errors = array();
$task = \XLite\Core\Database::getRepo('XLite\\Model\\EventTask')->findOneBy(array('name' => $event));
if ($task) {
if (\XLite\Core\EventListener::getInstance()->handle($task->getName(), $task->getArguments())) {
\XLite\Core\Database::getEM()->remove($task);
$result = true;
}
$errors = \XLite\Core\EventListener::getInstance()->getErrors();
} else {
\XLite\Core\Database::getRepo('XLite\\Model\\TmpVar')->removeEventState($event);
}
\XLite\Core\Database::getEM()->flush();
$state = \XLite\Core\Database::getRepo('XLite\\Model\\TmpVar')->getEventState($event);
$this->setPureAction(true);
if ($result && $state) {
\XLite\Core\Event::eventTaskRun(array('percent' => \XLite\Core\Database::getRepo('XLite\\Model\\TmpVar')->getEventStatePercent($event), 'error' => !empty($errors)));
} else {
$result = false;
}
if ($errors) {
foreach ($errors as $message) {
\XLite\Core\TopMessage::addError($message);
}
$result = false;
}
$this->valid = $result;
}
示例4: getTestOrder
/**
* @param bool $new_order
* @return XLite\Model\Order
*/
protected function getTestOrder($new_order = false)
{
$order = parent::getTestOrder($new_order);
$order->setPaymentMethod($this->getTestMethod());
\XLite\Core\Database::getEM()->flush();
return $order;
}
示例5: testCreate
/**
* testCreate
*
* @return void
* @access public
* @see ____func_see____
* @since 1.0.0
*/
public function testCreate()
{
$c = new \XLite\Model\Country();
foreach ($this->entityData as $field => $testValue) {
$setterMethod = 'set' . \XLite\Core\Converter::getInstance()->convertToCamelCase($field);
$getterMethod = 'get' . \XLite\Core\Converter::getInstance()->convertToCamelCase($field);
$c->{$setterMethod}($testValue);
$value = $c->{$getterMethod}();
$this->assertEquals($testValue, $value, 'Creation checking (' . $field . ')');
}
$s = new \XLite\Model\State();
$s->setState('test state');
$s->setCode('ttt');
$c->addStates($s);
$em = \XLite\Core\Database::getEM();
$em->persist($c);
$em->flush();
$em->clear();
$c = \XLite\Core\Database::getEM()->merge($c);
foreach ($this->entityData as $field => $testValue) {
$getterMethod = 'get' . \XLite\Core\Converter::getInstance()->convertToCamelCase($field);
$this->assertEquals($testValue, $c->{$getterMethod}(), 'Creation checking (' . $field . ') #2');
}
$this->assertEquals($s->getStateId(), $c->getStates()->get(0)->getStateId(), 'check state');
$em->remove($c);
$em->flush();
}
示例6: doActionUpdate
/**
* Update membership list
*
* @return void
*/
protected function doActionUpdate()
{
$data = \XLite\Core\Request::getInstance()->update_memberships;
if (!is_array($data)) {
// TODO - add top message
} else {
$code = $this->getCurrentLanguage();
$flag = false;
foreach ($data as $id => $row) {
$m = \XLite\Core\Database::getRepo('\\XLite\\Model\\Membership')->find($id);
if ($m) {
$duplicate = \XLite\Core\Database::getRepo('\\XLite\\Model\\Membership')->createQueryBuilder()->andWhere('translations.name = :name', 'm.membership_id != :id')->setParameter('name', $row['name'])->setParameter('id', $id)->setMaxResults(1)->getSingleResult();
if (!is_null($duplicate)) {
\XLite\Core\TopMessage::addWarning('"' . $row['name'] . '" ' . ' membership name is already in use. ' . 'Please specify another name for this membership level');
} else {
\XLite\Core\Database::getRepo('\\XLite\\Model\\Membership')->update($m, $row);
}
$flag = true;
} else {
\XLite\Core\TopMessage::addError('Could not find membership ID#' . $id . ' record in the database');
}
}
if ($flag) {
\XLite\Core\Database::getEM()->flush();
}
}
}
示例7: updateDrupalRoles
/**
* Update user's Drupal roles
*
* @param array $newDrupalRoles Array of Drupal role IDs
*
* @return void
*/
public function updateDrupalRoles($newDrupalRoles)
{
$processedRoles = array();
$drupalRoles = $this->getDrupalRoles();
if ($drupalRoles) {
// Remove roles that is not in new roles array
foreach ($this->getDrupalRoles() as $key => $drupalRole) {
if (!in_array($drupalRole->getDrupalRoleId(), $newDrupalRoles)) {
$this->drupalRoles->remove($key);
\XLite\Core\Database::getEM()->remove($drupalRole);
} else {
$processedRoles[] = $drupalRole->getDrupalRoleId();
}
}
}
// Get roles to add
$rolesToAdd = array_diff($newDrupalRoles, $processedRoles);
// Create new roles
foreach ($rolesToAdd as $roleId) {
$newDrupalRole = new \XLite\Module\CDev\DrupalConnector\Model\DrupalRole();
$newDrupalRole->setProfile($this);
$newDrupalRole->setDrupalRoleId($roleId);
$this->addDrupalRoles($newDrupalRole);
}
}
示例8: doActionRegisterKey
/**
* Action of license key registration
*
* @return void
*/
protected function doActionRegisterKey()
{
$key = \XLite\Core\Request::getInstance()->key;
$addonsInfo = \XLite\Core\Marketplace::getInstance()->checkAddonKey($key);
if ($addonsInfo && $addonsInfo[$key]) {
$addonsInfo = $addonsInfo[$key];
$repo = \XLite\Core\Database::getRepo('\\XLite\\Model\\ModuleKey');
foreach ($addonsInfo as $info) {
$module = \XLite\Core\Database::getRepo('\\XLite\\Model\\Module')->findOneBy(array('author' => $info['author'], 'name' => $info['name']));
if ($module) {
$entity = $repo->findKey($info['author'], $info['name']);
if ($entity) {
$entity->setKeyValue($key);
$repo->update($entity);
} else {
$entity = $repo->insert($info + array('keyValue' => $key));
}
\XLite\Core\Database::getEM()->flush();
// Clear cache for proper installation
\XLite\Core\Marketplace::getInstance()->clearActionCache(\XLite\Core\Marketplace::ACTION_GET_ADDONS_LIST);
$this->showInfo(__FUNCTION__, 'License key has been successfully verified for "{{name}}" module by "{{author}}" author', array('name' => $module->getModuleName(), 'author' => $module->getAuthorName()));
} else {
$this->showError(__FUNCTION__, 'Key is validated, but the module [' . implode(',', $info) . '] was not found');
}
}
} else {
$error = \XLite\Core\Marketplace::getInstance()->getError();
if ($error) {
$this->showError(__FUNCTION__, 'Response from marketplace: ' . $error);
} else {
$this->showError(__FUNCTION__, 'Response from marketplace is not received');
}
}
$this->setReturnURL($this->buildURL('addons_list_marketplace'));
}
示例9: testGetTotalRate
public function testGetTotalRate()
{
$tax = \XLite\Core\Database::getRepo('XLite\\Module\\CDev\\VAT\\Model\\Tax')->getTax();
foreach ($tax->getRates() as $rate) {
\XLite\Core\Database::getEM()->remove($rate);
}
$tax->getRates()->clear();
$tax->setEnabled(true);
$rate = new \XLite\Module\CDev\VAT\Model\Tax\Rate();
$rate->setValue(10);
$rate->setPosition(1);
\XLite\Core\Database::getEM()->persist($rate);
$tax->addRates($rate);
$rate->setTax($tax);
$rate = new \XLite\Module\CDev\VAT\Model\Tax\Rate();
$rate->setValue(20);
$rate->setPosition(0);
\XLite\Core\Database::getEM()->persist($rate);
$tax->addRates($rate);
$rate->setTax($tax);
$memberships = \XLite\Core\Database::getRepo('XLite\\Model\\Membership')->findAll();
$membership = array_shift($memberships);
$rate->setMembership($membership);
$tax->setVATMembership($membership);
\XLite\Core\Database::getEM()->flush();
$method = new \XLite\Model\Shipping\Method();
$method->setEnabled(true);
$rate = new \XLite\Model\Shipping\Rate();
$rate->setBaseRate(10);
$rate->setMarkupRate(10);
$rate->setMethod($method);
$this->assertEquals(16.67, \XLite::getInstance()->getCurrency()->formatValue($rate->getTotalRate()), 'check cost');
}
示例10: executeHookHandler
/**
* Execute certain hook handler
*
* @return void
*/
public function executeHookHandler()
{
\XLite\Core\Translation::getInstance()->reset();
\XLite\Core\Database::getEM()->flush();
\XLite\Core\Translation::getInstance()->resetDriver();
\XLite\Core\Translation::getInstance()->translateByString('label');
\XLite\Core\Database::getRepo('XLite\\Model\\TmpVar')->setVar(\XLite::CACHE_TIMESTAMP, intval(microtime(true)));
}
示例11: syncAmount
/**
* Sync amount in stock with remaining pin codes
*
* @return void
*/
public function syncAmount()
{
$remaining = $this->getProduct()->getRemainingPinCodesCount();
if (parent::getAmount() !== $remaining) {
$this->setAmount($remaining);
\XLite\Core\Database::getEM()->persist($this);
}
}
示例12: createTax
/**
* Create tax
*
* @return \XLite\Module\CDev\SalesTax\Model\Tax
*/
protected function createTax()
{
$tax = new \XLite\Module\CDev\SalesTax\Model\Tax();
$tax->setName('Sales tax');
$tax->setEnabled(true);
\XLite\Core\Database::getEM()->persist($tax);
return $tax;
}
示例13: doActionSetOrderNote
/**
* Set order note
*
* @return void
*/
public function doActionSetOrderNote()
{
if (isset(\XLite\Core\Request::getInstance()->notes)) {
$this->getCart()->setNotes(\XLite\Core\Request::getInstance()->notes);
}
\XLite\Core\Database::getEM()->flush();
exit;
}
示例14: getTestOrder
protected function getTestOrder($new_order = false)
{
$order = parent::getTestOrder($new_order);
$order->setDetail('t1', '123');
$order->setDetail('t2', '456', 'test');
\XLite\Core\Database::getEM()->flush();
return $order;
}
示例15: fire
/**
* Fire event
*
* @param string $name Event name
* @param array $arguments Arguments OPTIONAL
*
* @return boolean
*/
public function fire($name, array $arguments = array())
{
$entity = new \XLite\Model\EventTask();
$entity->setName($name);
$entity->setArguments($arguments);
\XLite\Core\Database::getEM()->persist($entity);
\XLite\Core\Database::getEM()->flush();
}