本文整理汇总了PHP中ActiveRecord::clearPool方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecord::clearPool方法的具体用法?PHP ActiveRecord::clearPool怎么用?PHP ActiveRecord::clearPool使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ActiveRecord
的用法示例。
在下文中一共展示了ActiveRecord::clearPool方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: reloadOrder
private function reloadOrder(CustomerOrder $order)
{
ActiveRecord::clearPool();
$order = CustomerOrder::getInstanceById($order->getID(), true);
$order->loadAll();
return $order;
}
示例2: testTransactionCurrencyConverting
function testTransactionCurrencyConverting()
{
$eur = Currency::getNewInstance('EUR');
$eur->rate->set('3.4528');
$eur->save();
$this->products[0]->setPrice($this->usd, '9.99');
$this->order->addProduct($this->products[0], 1);
$this->order->save();
$this->order->changeCurrency($this->usd);
//$this->order->finalize();
ActiveRecord::clearPool();
$order = CustomerOrder::getInstanceByID($this->order->getID(), true);
$order->loadAll();
$details = new LiveCartTransaction($order, $eur);
ActiveRecord::clearPool();
$order = CustomerOrder::getInstanceByID($this->order->getID(), true);
$order->loadAll();
$this->assertEquals($details->amount->get(), '2.89');
$result = new TransactionResult();
$result->amount->set($details->amount->get());
$result->currency->set($details->currency->get());
$transaction = Transaction::getNewInstance($order, $result);
$transaction->type->set(Transaction::TYPE_SALE);
$this->assertEquals($transaction->amount->get(), '9.99');
$this->assertEquals($transaction->realAmount->get(), '2.89');
$transaction->save();
$this->assertFalse((bool) $order->isFinalized->get());
$order->finalize();
$this->assertTrue((bool) $order->isFinalized->get());
$this->assertEquals($order->getPaidAmount(), '9.99');
$this->assertEquals($order->totalAmount->get(), '9.99');
$this->assertTrue((bool) $order->isPaid->get());
}
示例3: process
public function process()
{
AddRatingFieldToSchema::process();
$main = Product::getInstanceByID($this->request->get('id'), true);
if ($main->parent->get()) {
$main->parent->get()->load();
$var = $main->toArray();
$var['custom'] = $main->custom->get();
$this->request->set('variation', $var);
$this->request->set('activeVariationID', $this->request->get('id'));
$main = $main->parent->get();
$this->request->set('id', $main->getID());
$productArray = $main->toArray();
$handle = empty($productArray['URL']) ? $productArray['name_lang'] : $productArray['URL'];
$this->request->set('producthandle', $handle);
}
ActiveRecord::clearPool();
$variations = $main->getRelatedRecordSet('Product', select());
$handle = $main->URL->get() ? $main->URL->get() : $main->getValueByLang('name', 'en');
foreach ($variations as $variation) {
$variation->setValueByLang('name', 'en', $main->getValueByLang('name', 'en') . ' ' . $variation->sku->get());
$variation->URL->set($handle . ' ' . $variation->sku->get());
$variation->parent->set(null);
}
$variations->toArray();
}
示例4: testUpdate
function testUpdate()
{
$page = StaticPage::getNewInstance();
$page->setValueByLang('title', 'en', 'test title');
$page->save();
$page->setValueByLang('title', 'en', 'changed');
$page->save();
ActiveRecord::clearPool();
$instance = StaticPage::getInstanceById($page->getID());
$this->assertEqual($page->getValueByLang('title', 'en'), 'changed');
// test deleting a page
$this->assertTrue(file_exists($page->getFileName()));
$page->delete();
$this->assertFalse(file_exists($page->getFileName()));
}
示例5: testDeleteCategory
public function testDeleteCategory()
{
ActiveRecord::clearPool();
$startingPositions = array();
$nodes = $this->root->getChildNodes(false, true);
$nodes->add($this->root);
$this->root->reload();
foreach ($nodes as $category) {
$startingPositions[$category->getID()] = array('lft' => $category->getFieldValue(ActiveTreeNode::LEFT_NODE_FIELD_NAME), 'rgt' => $category->getFieldValue(ActiveTreeNode::RIGHT_NODE_FIELD_NAME), 'parent' => $category == $this->root ? '0' : $category->getFieldValue(ActiveTreeNode::PARENT_NODE_FIELD_NAME)->getID());
}
// new node
$newCategory = Category::getNewInstance($this->root);
$newCategory->setValueByLang("name", 'en', 'NEWNODE');
$newCategory->save();
// nested nodes
$nestedNodes = array();
$lastNode = $newCategory;
foreach (array() as $i) {
$nestedNodes[$i] = Category::getNewInstance($lastNode);
$nestedNodes[$i]->setValueByLang("name", 'en', 'TEST ' . rand(1, 1000));
$nestedNodes[$i]->save();
$lastNode = $nestedNodes[$i];
}
$newCategory->reload();
// Delete child node
$newCategory->delete();
$this->assertFalse($newCategory->isExistingRecord());
$this->assertFalse($newCategory->isLoaded());
// Check to see if everything is back to starting values
$activeTreeNodes = ActiveRecord::retrieveFromPool(get_class($newCategory));
foreach ($activeTreeNodes as $category) {
try {
$category->reload();
} catch (ARNotFoundException $e) {
continue;
}
if (!$category->getID()) {
continue;
}
$this->assertEqual($category->getFieldValue(ActiveTreeNode::LEFT_NODE_FIELD_NAME), $startingPositions[$category->getID()]['lft']);
$this->assertEqual($category->getFieldValue(ActiveTreeNode::RIGHT_NODE_FIELD_NAME), $startingPositions[$category->getID()]['rgt']);
if (!$category->isRoot()) {
$this->assertEqual($category->getFieldValue(ActiveTreeNode::PARENT_NODE_FIELD_NAME)->getID(), $startingPositions[$category->getID()]['parent']);
}
}
}
示例6: flush
protected function &fetch($pos)
{
if (!($pos >= $this->from && $pos < $this->to)) {
$this->from = $pos;
$this->to = $pos + $this->getChunkSize();
ActiveRecord::clearPool();
$this->filter->setLimit($this->getChunkSize(), $this->from);
$this->loadData();
$this->postProcessData();
}
if ($this->flush) {
//echo '|' . round(memory_get_usage() / (1024*1024), 1) . "\n";
flush();
ob_flush();
}
$offset = $pos - $this->from;
return $this->data[$offset];
}
示例7: processSet
protected function processSet(ARSet $set)
{
foreach ($set as $record) {
$this->processRecord($record);
//echo round(memory_get_usage() / (1024*1024), 1) . "MB \n";
if ('delete' == $this->getAction()) {
$this->deleteRecord($record);
} else {
$this->saveRecord($record);
}
$record->__destruct();
unset($record);
if (connection_aborted()) {
$this->cancel();
}
}
$set->__destruct();
unset($set);
ActiveRecord::clearPool();
}
示例8: testSerializeSpeed
public function testSerializeSpeed()
{
for ($k = 1; $k <= 10; $k++) {
$record = ActiveRecord::getNewInstance('SerializedModel');
$record->setID($k);
$record->name->set('some name ' . $k);
$record->save();
}
ActiveRecord::clearPool();
// fetch from database
$fetchTime = microtime(true);
$set = ActiveRecord::getRecordSet('SerializedModel', new ARSelectFilter());
$fetchTime = microtime(true) - $fetchTime;
$serialized = serialize($set);
ActiveRecord::clearPool();
// unserialize
$serTime = microtime(true);
$set = unserialize($serialized);
$serTime = microtime(true) - $serTime;
$this->assertTrue($serTime < $fetchTime);
}
示例9: testSerializingValuesWithQuotes
function testSerializingValuesWithQuotes()
{
// two quotes
$testValue = 'This is a value with "quotes" :)';
$root = Category::getInstanceByID(1);
$new = Category::getNewInstance($root);
$new->setValueByLang('name', 'en', $testValue);
$new->save();
ActiveRecord::clearPool();
$restored = Category::getInstanceByID($new->getID(), Category::LOAD_DATA);
$array = $restored->toArray();
$this->assertEqual($testValue, $restored->getValueByLang('name', 'en'));
// one quote
$testValue = 'NX9420 C2D T7400 17" WSXGA+ WVA BRIGHT VIEW 1024MB 120GB DVD+/-RW DL ATI MOBILITY RADEON X1600 256MB WLAN BT TPM XPPKeyb En';
$restored->setValueByLang('name', 'en', $testValue);
$restored->save();
ActiveRecord::clearPool();
$restored->totalProductCount->set(333);
$another = Category::getInstanceByID($restored->getID(), Category::LOAD_DATA);
$this->assertEqual($testValue, $another->getValueByLang('name', 'en'));
}
示例10: clear
protected function clear($instance)
{
if (method_exists($instance, '__destruct')) {
$instance->__destruct();
}
if (method_exists($instance, 'destruct')) {
$instance->destruct(true);
}
ActiveRecord::clearPool();
}
示例11: import
public function import()
{
$options = unserialize(base64_decode($this->request->get('options')));
$response = new JSONResponse(null);
if (file_exists($this->getCancelFile())) {
unlink($this->getCancelFile());
}
if (!$this->request->get('continue')) {
$this->clearCacheProgress();
}
$import = $this->getImportInstance();
set_time_limit(0);
ignore_user_abort(true);
$profile = new CsvImportProfile($import->getClassName());
// map CSV fields to LiveCart fields
$params = $this->request->get('params');
foreach ($this->request->get('column') as $key => $value) {
if ($value) {
$fieldParams = !empty($params[$key]) ? $params[$key] : array();
$profile->setField($key, $value, array_filter($fieldParams));
}
}
$profile->setParam('isHead', $this->request->get('firstHeader'));
if ($this->request->get('saveProfile')) {
$path = $this->getProfileDirectory($import) . $this->request->get('profileName') . '.ini';
$profile->setFileName($path);
$profile->save();
}
// get import root category
if ($import->isRootCategory()) {
$profile->setParam('category', $this->request->get('category'));
}
$import->beforeImport($profile);
$csv = new CsvFile($this->request->get('file'), $this->request->get('delimiter'));
$total = $csv->getRecordCount();
if ($this->request->get('firstHeader')) {
$total -= 1;
}
if ($this->request->get('firstHeader')) {
$import->skipHeader($csv);
$import->skipHeader($csv);
}
$progress = 0;
$processed = 0;
if ($this->request->get('continue')) {
$import->setImportPosition($csv, $this->getCacheProgress() + 1);
$progress = $this->getCacheProgress();
} else {
if (!empty($options['transaction'])) {
ActiveRecord::beginTransaction();
}
}
if (empty($options['transaction'])) {
$this->request->set('continue', true);
}
$import->setOptions($options);
if ($uid = $this->request->get('uid')) {
$import->setUID($uid);
}
do {
$progress += $import->importFileChunk($csv, $profile, 1);
// continue timed-out import
if ($this->request->get('continue')) {
$this->setCacheProgress($progress);
}
ActiveRecord::clearPool();
if ($progress % self::PROGRESS_FLUSH_INTERVAL == 0 || $total == $progress) {
$response->flush($this->getResponse(array('progress' => $progress, 'total' => $total, 'uid' => $import->getUID(), 'lastName' => $import->getLastImportedRecordName())));
//echo '|' . round(memory_get_usage() / (1024*1024), 1) . '|' . count($categories) . "\n";
}
// test non-transactional mode
//if (!$this->request->get('continue')) exit;
if (connection_aborted()) {
if ($this->request->get('continue')) {
exit;
} else {
$this->cancel();
}
}
} while (!$import->isCompleted($csv));
if (!empty($options['missing']) && 'keep' != $options['missing']) {
$filter = $import->getMissingRecordFilter($profile);
if ('disable' == $options['missing']) {
$import->disableRecords($filter);
} else {
if ('delete' == $options['missing']) {
$import->deleteRecords($filter);
}
}
}
$import->afterImport();
if (!$this->request->get('continue')) {
//ActiveRecord::rollback();
ActiveRecord::commit();
}
$response->flush($this->getResponse(array('progress' => 0, 'total' => $total)));
//echo '|' . round(memory_get_usage() / (1024*1024), 1);
exit;
}
示例12: apiActionGetOrdersBySelectFilter
private function apiActionGetOrdersBySelectFilter($ARSelectFilter, $allowEmptyResponse = false)
{
set_time_limit(0);
$ARSelectFilter->setOrder(new ARExpressionHandle('CustomerOrder.ID'), 'DESC');
$customerOrders = ActiveRecordModel::getRecordSet('CustomerOrder', $ARSelectFilter, array('User'));
if ($allowEmptyResponse == false && count($customerOrders) == 0) {
throw new Exception('Order not found');
}
$response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>');
foreach ($customerOrders as $order) {
$order->loadAll();
$transactions = $order->getTransactions();
$this->fillResponseItem($response->addChild('order'), $order->toArray());
unset($order);
ActiveRecord::clearPool();
}
return new SimpleXMLResponse($response);
}
示例13: importInstance
//.........这里部分代码省略.........
$group = isset($params['group']) ? $params['group'] : '';
$price = $product->getPricingHandler()->getPriceByCurrencyCode($currency);
$product->getPricingHandler()->setPrice($price);
if ($group || $quantityLevel) {
if ($value > 0) {
$quantity = $quantityLevel ? $record[$fields['ProductPrice'][$quantityLevel]] : 1;
$group = $group ? UserGroup::getInstanceByID($group) : null;
$price->setPriceRule($quantity, $group, $value);
}
} else {
$price->price->set($value);
}
} else {
if ('ProductPrice.listPrice' == $column) {
$value = (double) preg_replace('/[^\\.0-9]/', '', str_replace(',', '.', $value));
$currency = $params['currency'];
$price = $product->getPricingHandler()->getPriceByCurrencyCode($currency);
$price->listPrice->set($value);
$product->getPricingHandler()->setPrice($price);
} else {
if ('ProductVariation' == $className) {
if ($parent = $product->parent->get()) {
$this->importProductVariationValue($product, $field, $value);
} else {
$this->importVariationType($product, $field, $value);
}
}
}
}
}
}
}
$product->loadRequestData($impReq);
$product->save();
$this->importAttributes($product, $record, $fields, 'specField');
$this->setLastImportedRecordName($product->getValueByLang('name'));
if (isset($fields['ProductImage']['mainurl'])) {
if (!($image = $product->defaultImage->get())) {
$image = ProductImage::getNewInstance($product);
}
$image->setOwner($product);
// this is needed when ProductApi imports default ProductImage.
$this->importImage($image, $record[$fields['ProductImage']['mainurl']]);
unset($image);
}
if (isset($fields['ProductAdditionalImage'])) {
foreach ($fields['ProductAdditionalImage'] as $index) {
$this->importImage(ProductImage::getNewInstance($product), $record[$index]);
}
}
if (isset($fields['ProductImage']['Images'])) {
$images = explode('; ', $record[$fields['ProductImage']['Images']]);
if ($images) {
$product->deleteRelatedRecordSet('ProductImage');
foreach ($images as $path) {
$image = ProductImage::getNewInstance($product);
$this->importImage($image, $path);
unset($image);
}
}
}
if (isset($fields['ProductOption']['options'])) {
$options = explode('; ', $record[$fields['ProductOption']['options']]);
if ($options) {
$product->deleteRelatedRecordSet('ProductOption');
foreach ($options as $option) {
$parts = explode(':', $option, 2);
if (count($parts) < 2) {
continue;
}
$optionInstance = ProductOption::getNewInstance($product);
$optionInstance->setValueByLang('name', null, trim($parts[0]));
$optionInstance->type->set(ProductOption::TYPE_SELECT);
$optionInstance->isDisplayed->set(true);
$optionInstance->save();
foreach (explode(',', $parts[1]) as $choice) {
$choiceInstance = ProductOptionChoice::getNewInstance($optionInstance);
$choiceInstance->setValueByLang('name', null, trim($choice));
$choiceInstance->save();
}
}
}
}
// create variation by name
if ((isset($fields['Product']['parentID']) || isset($fields['Parent']['parentSKU'])) && !isset($fields['ProductVariation']) && $product->parent->get()) {
$this->importProductVariationValue($product, 1, $product->getValueByLang('name', 'en'));
}
// additional categories
if (is_array($extraCategories)) {
$this->importAdditionalCategories($profile, $product, $extraCategories);
}
if ($this->callback) {
call_user_func($this->callback, $product);
}
$product->__destruct();
$product->destruct(true);
ActiveRecord::clearPool();
return true;
}
}
示例14: completed
/**
* @role login
*/
public function completed()
{
if ($this->request->isValueSet('id')) {
return new ActionRedirectResponse('checkout', 'completeExternal', array('id' => $this->request->get('id')));
}
ActiveRecord::clearPool();
ActiveRecord::clearArrayData();
$order = CustomerOrder::getInstanceByID((int) $this->session->get('completedOrderID'), CustomerOrder::LOAD_DATA);
$order->getTaxAmount();
$order->loadAll();
$order->getTaxAmount();
ActiveRecord::clearArrayData();
$arr = $order->toArray();
$response = new ActionResponse();
$response->set('order', $arr);
$response->set('url', $this->router->createUrl(array('controller' => 'user', 'action' => 'viewOrder', 'id' => $this->session->get('completedOrderID')), true));
if (!$order->isPaid->get()) {
$transactions = $order->getTransactions()->toArray();
$response->set('transactions', $transactions);
} else {
$response->set('files', ProductFile::getOrderFiles(select(eq('CustomerOrder.ID', $order->getID()))));
}
return $response;
}
示例15: getUpdateResponse
protected function getUpdateResponse()
{
/////// @todo - should be a better way for recalculating taxes...
ActiveRecord::clearPool();
$this->config->resetRuntime('DELIVERY_TAX_CLASS');
$this->order = CustomerOrder::getInstanceById($this->order->getID(), true);
///////
$this->order->loadAll();
$this->restoreShippingMethodSelection();
ActiveRecordModel::clearArrayData();
if ($paymentMethod = $this->session->get('OrderPaymentMethod_' . $this->order->getID())) {
$this->order->setPaymentMethod($paymentMethod);
$this->order->getTotal(true);
}
$this->setAnonAddresses();
// @todo: sometimes the shipping address disappears (for registered users that might already have the shipping address entered before)
if (!$this->order->shippingAddress->get() && $this->isShippingRequired($this->order) && $this->user->defaultShippingAddress->get()) {
$this->user->defaultShippingAddress->get()->load();
$this->order->shippingAddress->set($this->user->defaultShippingAddress->get()->userAddress->get());
$this->order->shippingAddress->get()->load();
}
$response = new CompositeJSONResponse();
$response->addAction('overview', 'onePageCheckout', 'overview');
$response->addAction('cart', 'onePageCheckout', 'cart');
if ($this->request->getActionName() != 'setPaymentMethod') {
$response->addAction('payment', 'onePageCheckout', 'payment');
}
$response->set('order', $this->getOrderValues($this->order));
foreach (func_get_args() as $arg) {
$response->addAction($arg, 'onePageCheckout', $arg);
}
$this->session->unsetValue('noJS');
$response = $this->postProcessResponse($response);
return $response;
}