本文整理汇总了PHP中Dao::beginTransaction方法的典型用法代码示例。如果您正苦于以下问题:PHP Dao::beginTransaction方法的具体用法?PHP Dao::beginTransaction怎么用?PHP Dao::beginTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dao
的用法示例。
在下文中一共展示了Dao::beginTransaction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public static function run()
{
try {
Dao::beginTransaction();
$start = self::_logMsg("== START: processing Product Ageing ==", __CLASS__, __FUNCTION__);
self::_emptyProductAgeingLog();
$productCount = 0;
$products = self::_getProducts();
if (self::DEBUG === true) {
self::_logMsg('ProductCount: ' . count($products), __CLASS__, __FUNCTION__);
}
foreach ($products as $product) {
$productCount++;
if (self::DEBUG === true) {
self::_logMsg('ProductId: ' . $product->getId(), __CLASS__, __FUNCTION__);
}
$lastPurchase = self::_getLastPurchase($product);
if ($lastPurchase instanceof ProductQtyLog) {
self::_recordProductAgeingLog($lastPurchase);
}
}
$end = new UDate();
self::_logMsg("== FINISHED: process product ageing, (productCount: " . $productCount . ", ProductAgeingLogCount: " . ProductAgeingLog::countByCriteria('active = 1') . ")", __CLASS__, __FUNCTION__);
Dao::commitTransaction();
} catch (Exception $e) {
Dao::rollbackTransaction();
echo "\n" . $e->getMessage() . "\n" . $e->getTraceAsString();
}
}
示例2: saveItem
/**
* (non-PHPdoc)
* @see DetailsPageAbstract::saveItem()
*/
public function saveItem($sender, $param)
{
$results = $errors = array();
try {
Dao::beginTransaction();
$task = null;
if (isset($param->CallbackParameter->id) && !($task = Task::get(trim($param->CallbackParameter->id))) instanceof Task) {
throw new Exception('Invalid Task passed in!');
}
if (!isset($param->CallbackParameter->instructions) || ($instructions = trim($param->CallbackParameter->instructions)) === '') {
throw new Exception('Instructions are required!');
}
if (!isset($param->CallbackParameter->customerId) || !($customer = Customer::get(trim($param->CallbackParameter->customerId))) instanceof Customer) {
throw new Exception('Invalid Customer Passed in!');
}
$tech = isset($param->CallbackParameter->techId) ? UserAccount::get(trim($param->CallbackParameter->techId)) : null;
$order = isset($param->CallbackParameter->orderId) ? Order::get(trim($param->CallbackParameter->orderId)) : null;
$dueDate = new UDate(trim($param->CallbackParameter->dueDate));
$status = isset($param->CallbackParameter->statusId) ? TaskStatus::get(trim($param->CallbackParameter->statusId)) : null;
if (!$task instanceof Task) {
$task = Task::create($customer, $dueDate, $instructions, $tech, $order);
} else {
$task->setCustomer($customer)->setDueDate($dueDate)->setInstructions($instructions)->setTechnician($tech)->setFromEntityId($order instanceof Order ? $order->getId() : '')->setFromEntityName($order instanceof Order ? get_class($order) : '')->setStatus($status)->save();
}
// $results['url'] = '/task/' . $task->getId() . '.html?' . $_SERVER['QUERY_STRING'];
$results['item'] = $task->getJson();
Dao::commitTransaction();
} catch (Exception $ex) {
Dao::rollbackTransaction();
$errors[] = $ex->getMessage();
}
$param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
}
示例3: sendEmail
/**
* Sending the email out
*
* @param unknown $sender
* @param unknown $param
*
* @throws Exception
*/
public function sendEmail($sender, $param)
{
$results = $errors = array();
try {
Dao::beginTransaction();
if (!isset($param->CallbackParameter->orderId) || !($order = Order::get($param->CallbackParameter->orderId)) instanceof Order) {
throw new Exception('System Error: invalid order provided!');
}
if (!isset($param->CallbackParameter->emailAddress) || ($emailAddress = trim($param->CallbackParameter->emailAddress)) === '') {
throw new Exception('System Error: invalid emaill address provided!');
}
$emailBody = '';
if (isset($param->CallbackParameter->emailBody) && ($emailBody = trim($param->CallbackParameter->emailBody)) !== '') {
$emailBody = str_replace("\n", "<br />", $emailBody);
}
$pdfFile = EntityToPDF::getPDF($order);
$asset = Asset::registerAsset($order->getOrderNo() . '.pdf', file_get_contents($pdfFile), Asset::TYPE_TMP);
$type = $order->getType();
EmailSender::addEmail('sales@budgetpc.com.au', $emailAddress, 'BudgetPC ' . $type . ':' . $order->getOrderNo(), (trim($emailBody) === '' ? '' : $emailBody . "<br /><br />") . 'Please find attached ' . $type . ' (' . $order->getOrderNo() . '.pdf) from Budget PC Pty Ltd.', array($asset));
$order->addComment('An email sent to "' . $emailAddress . '" with the attachment: ' . $asset->getAssetId(), Comments::TYPE_SYSTEM);
$results['item'] = $order->getJson();
Dao::commitTransaction();
} catch (Exception $ex) {
Dao::rollbackTransaction();
$errors[] = $ex->getMessage();
}
$param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
}
示例4: saveOrder
/**
* saveOrder
*
* @param unknown $sender
* @param unknown $param
*
* @throws Exception
*
*/
public function saveOrder($sender, $param)
{
$results = $errors = array();
$daoStart = false;
try {
Dao::beginTransaction();
$daoStart = true;
$supplier = Supplier::get(trim($param->CallbackParameter->supplier->id));
if (!$supplier instanceof Supplier) {
throw new Exception('Invalid Supplier passed in!');
}
$supplierContactName = trim($param->CallbackParameter->supplier->contactName);
$supplierContactNo = trim($param->CallbackParameter->supplier->contactNo);
$supplierEmail = trim($param->CallbackParameter->supplier->email);
if (!empty($supplierContactName) && $supplierContactName !== $supplier->getContactName()) {
$supplier->setContactName($supplierContactName);
}
if (!empty($supplierContactNo) && $supplierContactNo !== $supplier->getContactNo()) {
$supplier->setContactNo($supplierContactNo);
}
if (!empty($supplierEmail) && $supplierEmail !== $supplier->getEmail()) {
$supplier->setEmail($supplierEmail);
}
$supplier->save();
$purchaseOrder = PurchaseOrder::create($supplier, trim($param->CallbackParameter->supplierRefNum), $supplierContactName, $supplierContactNo, StringUtilsAbstract::getValueFromCurrency(trim($param->CallbackParameter->shippingCost)), StringUtilsAbstract::getValueFromCurrency(trim($param->CallbackParameter->handlingCost)))->setTotalAmount(StringUtilsAbstract::getValueFromCurrency(trim($param->CallbackParameter->totalPaymentDue)))->setEta(trim($param->CallbackParameter->eta))->setStatus(PurchaseOrder::STATUS_NEW)->save()->addComment(trim($param->CallbackParameter->comments), Comments::TYPE_PURCHASING);
foreach ($param->CallbackParameter->items as $item) {
if (!($product = Product::get(trim($item->productId))) instanceof Product) {
throw new Exception('Invalid Product passed in!');
}
$purchaseOrder->addItem($product, StringUtilsAbstract::getValueFromCurrency(trim($item->unitPrice)), 0 - abs(intval(trim($item->qtyOrdered))));
}
if ($param->CallbackParameter->submitToSupplier === true) {
$purchaseOrder->setStatus(PurchaseOrder::STATUS_ORDERED);
}
// For credit PO
if (isset($param->CallbackParameter->type) && trim($param->CallbackParameter->type) === 'CREDIT') {
$purchaseOrder->setIsCredit(true);
if (isset($param->CallbackParameter->po) && ($fromPO = PurchaseOrder::get(trim($param->CallbackParameter->po->id))) instanceof PurchaseOrder) {
$purchaseOrder->setFromPO($fromPO);
}
}
$purchaseOrder->save();
$daoStart = false;
Dao::commitTransaction();
$results['item'] = $purchaseOrder->getJson();
if (isset($param->CallbackParameter->confirmEmail) && trim($confirmEmail = trim($param->CallbackParameter->confirmEmail)) !== '') {
$pdfFile = EntityToPDF::getPDF($purchaseOrder);
$asset = Asset::registerAsset($purchaseOrder->getPurchaseOrderNo() . '.pdf', file_get_contents($pdfFile), Asset::TYPE_TMP);
EmailSender::addEmail('purchasing@budgetpc.com.au', $confirmEmail, 'BudgetPC Purchase Order:' . $purchaseOrder->getPurchaseOrderNo(), 'Please Find the attached PurchaseOrder(' . $purchaseOrder->getPurchaseOrderNo() . ') from BudgetPC.', array($asset));
EmailSender::addEmail('purchasing@budgetpc.com.au', 'purchasing@budgetpc.com.au', 'BudgetPC Purchase Order:' . $purchaseOrder->getPurchaseOrderNo(), 'Please Find the attached PurchaseOrder(' . $purchaseOrder->getPurchaseOrderNo() . ') from BudgetPC.', array($asset));
$purchaseOrder->addComment('An email sent to "' . $confirmEmail . '" with the attachment: ' . $asset->getAssetId(), Comments::TYPE_SYSTEM);
}
} catch (Exception $ex) {
if ($daoStart === true) {
Dao::rollbackTransaction();
}
$errors[] = $ex->getMessage();
}
$param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
}
示例5: saveItem
/**
* (non-PHPdoc)
* @see DetailsPageAbstract::saveItem()
*/
public function saveItem($sender, $param)
{
$results = $errors = array();
try {
Dao::beginTransaction();
if (!isset($param->CallbackParameter->id)) {
throw new Exception('Invalid supplier ID passed in!');
}
$supplier = ($id = trim($param->CallbackParameter->id)) === '' ? new Supplier() : Supplier::get($id);
if (!$supplier instanceof Supplier) {
throw new Exception('Invalid supplier passed in!');
}
$contactName = trim($param->CallbackParameter->address->contactName);
$contactNo = trim($param->CallbackParameter->address->contactNo);
$street = trim($param->CallbackParameter->address->street);
$city = trim($param->CallbackParameter->address->city);
$region = trim($param->CallbackParameter->address->region);
$postCode = trim($param->CallbackParameter->address->postCode);
$country = trim($param->CallbackParameter->address->country);
$address = $supplier->getAddress();
$supplier->setName(trim($param->CallbackParameter->name))->setDescription(trim($param->CallbackParameter->description))->setContactNo(trim($param->CallbackParameter->contactNo))->setEmail(trim($param->CallbackParameter->email))->setAddress(Address::create($street, $city, $region, $country, $postCode, $contactName, $contactNo, $address))->save();
$results['url'] = '/supplier/' . $supplier->getId() . '.html' . (isset($_REQUEST['blanklayout']) ? '?blanklayout=' . $_REQUEST['blanklayout'] : '');
$results['item'] = $supplier->getJson();
Dao::commitTransaction();
} catch (Exception $ex) {
Dao::rollbackTransaction();
$errors[] = $ex->getMessage() . $ex->getTraceAsString();
}
$param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
}
示例6: addComments
/**
*
* @param unknown $sender
* @param unknown $params
*/
public function addComments($sender, $params)
{
$results = $errors = array();
try {
Dao::beginTransaction();
if (!isset($params->CallbackParameter->entityName) || ($entityName = trim($params->CallbackParameter->entityName)) === '') {
throw new Exception('System Error: EntityName is not provided!');
}
if (!isset($params->CallbackParameter->entityId) || ($entityId = trim($params->CallbackParameter->entityId)) === '') {
throw new Exception('System Error: entityId is not provided!');
}
if (!($entity = $entityName::get($entityId)) instanceof $entityName) {
throw new Exception('System Error: no such a entity exisits!');
}
if (!isset($params->CallbackParameter->comments) || ($comments = trim($params->CallbackParameter->comments)) === '') {
throw new Exception('System Error: invalid comments passed in!');
}
$comment = Comments::addComments($entity, $comments, Comments::TYPE_NORMAL);
$results['item'] = $comment->getJson();
Dao::commitTransaction();
} catch (Exception $ex) {
Dao::rollbackTransaction();
$errors[] = $ex->getMessage();
}
$params->ResponseData = StringUtilsAbstract::getJson($results, $errors);
}
示例7: updateSetting
public function updateSetting($sender, $param)
{
$result = $errors = array();
try {
$result = $products = array();
$systemSetting = SystemSettings::getByType(SystemSettings::TYPE_SYSTEM_BUILD_PRODUCTS_ID);
foreach ($param->CallbackParameter as $type => $ids) {
$result[$type] = array();
$products[$type] = array();
foreach ($ids as $index => $id) {
$id = intval(trim($id));
if (($product = Product::get($id)) instanceof Product) {
$result[$type][] = $id;
$products[$type][] = $product->getJson();
}
}
}
Dao::beginTransaction();
$systemSetting->setValue(json_encode($result))->save();
Dao::commitTransaction();
} catch (Exception $ex) {
// Dao::rollbackTransaction();
$errors[] = $ex->getMessage();
}
$param->ResponseData = StringUtilsAbstract::getJson($products, $errors);
}
示例8: genReport
public function genReport($sender, $param)
{
$results = $errors = array();
try {
Dao::beginTransaction();
if (isset($param->CallbackParameter->type) && ($type = trim($param->CallbackParameter->type)) === '') {
throw new Exception('SYSTEM ERROR: invalid type passed in.');
}
$asset = null;
switch (strtolower($type)) {
case 'sales_daily':
SalesExport_Xero::setStartNEndDate(new UDate(trim($param->CallbackParameter->date_from)), new UDate(trim($param->CallbackParameter->date_to)));
$asset = SalesExport_Xero::run(false, false);
break;
case 'creditnotes_daily':
CreditNoteExport_Xero::setStartNEndDate(new UDate(trim($param->CallbackParameter->date_from)), new UDate(trim($param->CallbackParameter->date_to)));
$asset = CreditNoteExport_Xero::run(false, false);
break;
case 'supplier_bill_daily':
BillExport_Xero::setStartNEndDate(new UDate(trim($param->CallbackParameter->date_from)), new UDate(trim($param->CallbackParameter->date_to)));
$asset = BillExport_Xero::run(false, false);
break;
case 'manual_journal':
ManualJournalExport_Xero::setStartNEndDate(new UDate(trim($param->CallbackParameter->date_from)), new UDate(trim($param->CallbackParameter->date_to)));
$asset = ManualJournalExport_Xero::run(false, false);
break;
case 'payments_daily':
PaymentExport_Xero::setStartNEndDate(new UDate(trim($param->CallbackParameter->date_from)), new UDate(trim($param->CallbackParameter->date_to)));
$asset = PaymentExport_Xero::run(false, false);
break;
case 'inventory_list':
ItemExport_Xero::setStartNEndDate(new UDate(trim($param->CallbackParameter->date_from)), new UDate(trim($param->CallbackParameter->date_to)));
$asset = ItemExport_Xero::run(false, true);
break;
case 'magento_price':
ItemExport_Magento::setStartNEndDate(new UDate(trim($param->CallbackParameter->date_from)), new UDate(trim($param->CallbackParameter->date_to)));
$asset = ItemExport_Magento::run(false, false);
break;
case 'accounting_code':
AccoutingCodeExport::setStartNEndDate(new UDate(trim($param->CallbackParameter->date_from)), new UDate(trim($param->CallbackParameter->date_to)));
$asset = AccoutingCodeExport::run(false, false);
break;
case 'open_inv':
OpenInvoiceExport::setStartNEndDate(new UDate(trim($param->CallbackParameter->date_from)), new UDate(trim($param->CallbackParameter->date_to)));
$asset = OpenInvoiceExport::run(false, false);
break;
default:
throw new Exception('SYSTEM ERROR: invalid type passed in: ' . $type);
}
if ($asset instanceof Asset) {
$results['item'] = $asset->getJson();
}
Dao::commitTransaction();
} catch (Exception $ex) {
Dao::rollbackTransaction();
$error[] = $ex->getMessage();
}
$param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
}
示例9: updateProduct
function updateProduct($pro, $fileName, $line)
{
$clientScript = CatelogConnector::getConnector(B2BConnector::CONNECTOR_TYPE_CATELOG, getWSDL(), 'B2BUser', 'B2BUser');
try {
$transStarted = false;
try {
Dao::beginTransaction();
} catch (Exception $e) {
$transStarted = true;
}
$sku = trim($pro['sku']);
$product = Product::getBySku($pro['sku']);
$mageId = trim($pro['product_id']);
$name = trim($pro['name']);
$short_description = trim($pro['short_description']);
$description = trim($pro['description']);
$weight = trim($pro['weight']);
$statusId = trim($pro['status']);
$price = trim($pro['price']);
$specialPrice = trim($pro['special_price']);
$specialPrice_From = trim($pro['special_from_date']) === '' ? trim($pro['special_from_date']) : null;
$specialPrice_To = trim($pro['special_to_date']) === '' ? trim($pro['special_to_date']) : null;
$supplierName = trim($pro['supplier']);
$attributeSet = ProductAttributeSet::get(trim($pro['attributeSetId']));
if (!$product instanceof Product) {
$product = Product::create($sku, $name);
}
$asset = ($assetId = trim($product->getFullDescAssetId())) === '' || !($asset = Asset::getAsset($assetId)) instanceof Asset ? Asset::registerAsset('full_desc_' . $sku, $description, Asset::TYPE_PRODUCT_DEC) : $asset;
$product->setName($name)->setMageId($mageId)->setAttributeSet($attributeSet)->setShortDescription($short_description)->setFullDescAssetId(trim($asset->getAssetId()))->setIsFromB2B(true)->setStatus(ProductStatus::get($statusId))->setSellOnWeb(true)->setManufacturer($clientScript->getManufacturerName(trim($pro['manufacturer'])))->save()->clearAllPrice()->addPrice(ProductPriceType::get(ProductPriceType::ID_RRP), $price)->addInfo(ProductInfoType::ID_WEIGHT, $weight);
if ($specialPrice !== '') {
$product->addPrice(ProductPriceType::get(ProductPriceType::ID_CASUAL_SPECIAL), $specialPrice, $specialPrice_From, $specialPrice_To);
}
if ($supplierName !== '') {
$product->addSupplier(Supplier::create($supplierName, $supplierName, true));
}
if (isset($pro['categories']) && count($pro['categories']) > 0) {
$product->clearAllCategory();
foreach ($pro['categories'] as $cateMageId) {
if (!($category = ProductCategory::getByMageId($cateMageId)) instanceof ProductCategory) {
continue;
}
$product->addCategory($category);
}
}
if ($transStarted === false) {
Dao::commitTransaction();
}
//TODO remove the file
removeLineFromFile($fileName, $line);
echo $product->getId() . " => done! \n";
} catch (Exception $ex) {
if ($transStarted === false) {
Dao::rollbackTransaction();
}
throw $ex;
}
}
示例10: saveUser
public function saveUser($sender, $params)
{
$results = $errors = array();
try {
Dao::beginTransaction();
if (!isset($params->CallbackParameter->firstName) || ($firstName = trim($params->CallbackParameter->firstName)) === '') {
throw new Exception('System Error: firstName is mandatory!');
}
if (!isset($params->CallbackParameter->lastName) || ($lastName = trim($params->CallbackParameter->lastName)) === '') {
throw new Exception('System Error: lastName is mandatory!');
}
if (!isset($params->CallbackParameter->userName) || ($userName = trim($params->CallbackParameter->userName)) === '') {
throw new Exception('System Error: userName is mandatory!');
}
if (!isset($params->CallbackParameter->roleid) || !($role = Role::get($params->CallbackParameter->roleid)) instanceof Role) {
throw new Exception('System Error: role is mandatory!');
}
$newpassword = trim($params->CallbackParameter->newpassword);
if (!isset($params->CallbackParameter->userid) || !($userAccount = UserAccount::get($params->CallbackParameter->userid)) instanceof UserAccount) {
$userAccount = new UserAccount();
$person = new Person();
if ($newpassword === '') {
throw new Exception('System Error: new password is mandatory!');
}
$newpassword = sha1($newpassword);
} else {
$person = $userAccount->getPerson();
if ($newpassword === '') {
$newpassword = $userAccount->getPassword();
} else {
$newpassword = sha1($newpassword);
}
}
//double check whether the username has been used
$users = UserAccount::getAllByCriteria('username=? and id!=?', array($userName, $userAccount->getId()), false, 1, 1);
if (count($users) > 0) {
throw new Exception('Username(=' . $userName . ') has been used by another user, please choose another one!');
}
$person->setFirstName($firstName)->setLastName($lastName)->save();
$userAccount->setUserName($userName)->setPassword($newpassword)->setPerson($person)->save();
$results = $userAccount->clearRoles()->addRole($role)->getJson();
Dao::commitTransaction();
} catch (Exception $ex) {
Dao::rollbackTransaction();
$errors[] = $ex->getMessage();
}
$params->ResponseData = StringUtilsAbstract::getJson($results, $errors);
}
示例11: run
/**
* runner
* @param string $debug
*/
public static function run($debug = false)
{
try {
self::$_debug = $debug;
Dao::beginTransaction();
Core::setUser(UserAccount::get(UserAccount::ID_SYSTEM_ACCOUNT));
$start = self::_debug("Start to run " . __CLASS__ . ' =================== ');
$assetIds = self::_findAllOverdueAssets();
$assetIds = array_merge($assetIds, self::_findAllZombieAssets());
self::_deleteAssets($assetIds);
self::_debug("Finished to run " . __CLASS__ . ' =================== ', self::NEW_LINE, "", $start);
Dao::commitTransaction();
} catch (Exception $ex) {
Dao::rollbackTransaction();
self::_debug("***** ERROR: " . $ex->getMessage());
self::_debug($ex->getTraceAsString());
}
}
示例12: createProduct
/**
* create product
*
* @param string $sku The sku of product
* @param string $name The name of product
* @param array $categoryPaths The category paths of product (e.g. $categories = array(array('cate2', 'cate3'), array('cate4', 'cate5', 'cate6'));
* @param string $mageProductId //TODO
* @param string $isFromB2B
* @param string $shortDescr
* @param string $fullDescr
* @param string $brandName
*
* @throws Exception
* @return string
* @soapmethod
*/
public function createProduct($sku, $name, $categoryPaths = array(), $mageProductId = '', $isFromB2B = false, $shortDescr = '', $fullDescr = '', $brandName = '')
{
$response = $this->_getResponse(UDate::now());
try {
Dao::beginTransaction();
Core::setUser(UserAccount::get(UserAccount::ID_SYSTEM_ACCOUNT));
//TODO
if (Product::getBySku(trim($sku)) instanceof Product) {
throw new Exception('sku "' . $sku . '" already exists');
}
$categories = array();
if (is_array($categoryPaths)) {
foreach ($categoryPaths as $categoryPath) {
$parentCategory = null;
foreach ($categoryPath as $categoryName) {
if (count($i = ProductCategory::getAllByCriteria('name = ?', array(trim($categoryName)), true, 1, 1)) > 0) {
$categories[$i[0]->getId()] = $category = $i[0];
} else {
$category = ProductCategory::create(trim($categoryName), trim($categoryName), $parentCategory);
$categories[$category->getId()] = $category;
}
$parentCategory = $category;
}
}
}
// create product
$product = Product::create(trim($sku), trim($name));
// TODO
foreach ($categories as $category) {
$product->addCategory($category);
}
$response['status'] = self::RESULT_CODE_SUCC;
$this->addCData('product', json_encode($product->getJson()), $response);
Dao::commitTransaction();
} catch (Exception $e) {
Dao::rollbackTransaction();
$response['status'] = self::RESULT_CODE_FAIL;
$this->addCData('error', $e->getMessage(), $response);
}
return trim($response->asXML());
}
示例13: addMemo
/**
* Creating a new Memo
*
* @param unknown $sender
* @param unknown $params
*
* @throws Exception
*/
public function addMemo($sender, $param)
{
$results = $errors = array();
try {
Dao::beginTransaction();
if (!isset($param->CallbackParameter->entity) || !isset($param->CallbackParameter->entityId) || ($entityName = trim($param->CallbackParameter->entity)) === '' || !($entity = $entityName::get(trim($param->CallbackParameter->entityId))) instanceof $entityName) {
throw new Exception('System Error: no entity provided for the Memo');
}
if (!isset($param->CallbackParameter->data) || !isset($param->CallbackParameter->data->comments) || ($comments = trim($param->CallbackParameter->data->comments)) === '') {
throw new Exception('You can NOT create a Memo with a blank message.');
}
$newComments = null;
$entity->addComment($comments, Comments::TYPE_MEMO, '', $newComments);
$results['item'] = $newComments->getJson();
Dao::commitTransaction();
} catch (Exception $ex) {
Dao::rollbackTransaction();
$errors[] = $ex->getMessage();
}
$param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
}
示例14: run
public static function run()
{
$start = self::_logMsg("== START: processing Messages ==", __CLASS__, __FUNCTION__);
$messages = self::_getAndMarkMessages();
self::_logMsg("GOT " . count($messages) . ' Message(s): ', __CLASS__, __FUNCTION__);
foreach ($messages as $message) {
self::_logMsg(" Looping message(ID=" . $message->getId() . ': ', __CLASS__, __FUNCTION__);
try {
Dao::beginTransaction();
EmailSender::sendEmail($message->getFrom(), $message->getTo(), $message->getSubject(), $message->getBody(), $message->getAttachmentAssetIdArray());
$message->setStatus(Message::STATUS_SENT)->save();
Dao::commitTransaction();
self::_logMsg(" SUCCESS sending message(ID=" . $message->getId() . ').', __CLASS__, __FUNCTION__);
} catch (Exception $ex) {
Dao::rollbackTransaction();
$message->setStatus(Message::STATUS_FAILED)->save();
self::_logMsg(" ERROR sending message(ID=" . $message->getId() . ': ' . $ex->getMessage(), __CLASS__, __FUNCTION__);
self::_logMsg(" ERROR sending message(ID=" . $message->getId() . ': ' . $ex->getTraceAsString(), __CLASS__, __FUNCTION__);
}
}
$end = new UDate();
self::_logMsg("== FINISHED: " . count($messages) . " Message(s) == ", __CLASS__, __FUNCTION__);
}
示例15: saveQuantities
/**
* saveOrder
*
* @param unknown $sender
* @param unknown $param
*
* @throws Exception
*
*/
public function saveQuantities($sender, $param)
{
$results = $errors = array();
try {
Dao::beginTransaction();
$items = array();
var_dump($param->CallbackParameter->products);
$products = array();
foreach ($param->CallbackParameter->products as $item) {
if (!($product = Product::get(trim($item->productId))) instanceof Product) {
throw new Exception('Invalid Product passed in!');
}
if (($stockOnPO = trim($item->stockOnPO)) !== $product->getstockOnPO()) {
$product->setStockOnPO($stockOnPO);
}
if (($stockOnHand = trim($item->stockOnHand)) !== $product->getStockOnHand()) {
$product->setStockOnHand($stockOnHand);
}
if (($stockOnOrder = trim($item->stockOnOrder)) !== $product->getStockOnOrder()) {
$product->setStockOnOrder($stockOnOrder);
}
if (($stockInRMA = trim($item->stockInRMA)) !== $product->getStockInRMA()) {
$product->setStockInRMA($stockInRMA);
}
if (($stockInParts = trim($item->stockInParts)) !== $product->getStockInParts()) {
$product->setStockInParts($stockInParts);
}
if (($totalInPartsValue = trim($item->totalInPartsValue)) !== $product->getTotalInPartsValue()) {
$product->setTotalInPartsValue($totalInPartsValue);
}
if (($totalOnHandValue = trim($item->totalOnHandValue)) !== $product->getTotalOnHandValue()) {
$product->setTotalOnHandValue($totalOnHandValue);
}
$product->snapshotQty(null, ProductQtyLog::TYPE_STOCK_ADJ, 'Manual Adjusted by ' . Core::getUser()->getPerson()->getFullName())->save();
$products[] = $product->getJson();
}
$results['items'] = $products;
Dao::commitTransaction();
} catch (Exception $ex) {
Dao::rollbackTransaction();
$errors[] = $ex->getMessage();
}
$param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
}