本文整理汇总了PHP中AO::throwException方法的典型用法代码示例。如果您正苦于以下问题:PHP AO::throwException方法的具体用法?PHP AO::throwException怎么用?PHP AO::throwException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AO
的用法示例。
在下文中一共展示了AO::throwException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _beforeSave
public function _beforeSave(Mage_Core_Model_Abstract $object)
{
$format = AO::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
if ($date = $object->getDateFrom()) {
$date = AO::app()->getLocale()->date($date, $format, null, false);
$object->setDateFrom($date->toString(Varien_Date::DATETIME_INTERNAL_FORMAT));
} else {
$object->setDateFrom(null);
}
if ($date = $object->getDateTo()) {
$date = AO::app()->getLocale()->date($date, $format, null, false);
$object->setDateTo($date->toString(Varien_Date::DATETIME_INTERNAL_FORMAT));
} else {
$object->setDateTo(null);
}
if (!is_null($object->getDateFrom()) && !is_null($object->getDateTo()) && strtotime($object->getDateFrom()) > strtotime($object->getDateTo())) {
AO::throwException(AO::helper('core')->__('Start date can\'t be greater than end date'));
}
$check = $this->_checkIntersection($object->getStoreId(), $object->getDateFrom(), $object->getDateTo(), $object->getId());
if ($check) {
AO::throwException(AO::helper('core')->__('Your design change for the specified store intersects with another one, please specify another date range'));
}
if (is_null($object->getDateFrom())) {
$object->setDateFrom(new Zend_Db_Expr('null'));
}
if (is_null($object->getDateTo())) {
$object->setDateTo(new Zend_Db_Expr('null'));
}
parent::_beforeSave($object);
}
示例2: _beforeDelete
protected function _beforeDelete(Mage_Core_Model_Abstract $group)
{
if ($group->usesAsDefault()) {
AO::throwException(AO::helper('customer')->__('Group "%s" can not be deleted', $group->getCode()));
}
return parent::_beforeDelete($group);
}
示例3: prepareForCart
/**
* Prepare option value for cart
*
* @throws Mage_Core_Exception
* @return mixed Prepared option value
*/
public function prepareForCart()
{
if ($this->getIsValid()) {
return is_array($this->getUserValue()) ? implode(',', $this->getUserValue()) : $this->getUserValue();
}
AO::throwException(AO::helper('catalog')->__('Option validation failed to add product to cart'));
}
示例4: login
/**
* Try to login user in admin
*
* @param string $username
* @param string $password
* @param Mage_Core_Controller_Request_Http $request
* @return Mage_Admin_Model_User|null
*/
public function login($username, $password, $request = null)
{
if (empty($username) || empty($password)) {
return;
}
try {
/* @var $user Mage_Admin_Model_User */
$user = AO::getModel('admin/user');
$user->login($username, $password);
if ($user->getId()) {
if (AO::getSingleton('adminhtml/url')->useSecretKey()) {
AO::getSingleton('adminhtml/url')->renewSecretUrls();
}
$session = AO::getSingleton('admin/session');
$session->setIsFirstVisit(true);
$session->setUser($user);
$session->setAcl(AO::getResourceModel('admin/acl')->loadAcl());
if ($requestUri = $this->_getRequestUri($request)) {
header('Location: ' . $requestUri);
exit;
}
} else {
AO::throwException(AO::helper('adminhtml')->__('Invalid Username or Password.'));
}
} catch (Mage_Core_Exception $e) {
if ($request && !$request->getParam('messageSent')) {
AO::getSingleton('adminhtml/session')->addError($e->getMessage());
$request->setParam('messageSent', true);
}
}
return $user;
}
示例5: checkDatabase
/**
* Check database connection
*
* $data = array(
* [db_host]
* [db_name]
* [db_user]
* [db_pass]
* )
*
* @param array $data
*/
public function checkDatabase($data)
{
$config = array('host' => $data['db_host'], 'username' => $data['db_user'], 'password' => $data['db_pass'], 'dbname' => $data['db_name']);
try {
$connection = AO::getSingleton('core/resource')->createConnection('install', $this->_getConnenctionType(), $config);
$variables = $connection->fetchPairs("SHOW VARIABLES");
$version = isset($variables['version']) ? $variables['version'] : 'undefined';
$match = array();
if (preg_match("#^([0-9\\.]+)#", $version, $match)) {
$version = $match[0];
}
$requiredVersion = (string) AO::getSingleton('install/config')->getNode('check/mysql/version');
// check MySQL Server version
if (version_compare($version, $requiredVersion) == -1) {
AO::throwException(AO::helper('install')->__('Database server version does not match system requirements (required: %s, actual: %s)', $requiredVersion, $version));
}
// check InnoDB support
if (!isset($variables['have_innodb']) || $variables['have_innodb'] != 'YES') {
AO::throwException(AO::helper('install')->__('Database server does not support InnoDB storage engine'));
}
} catch (Exception $e) {
$this->_getInstaller()->getDataModel()->addError($e->getMessage());
AO::throwException(AO::helper('install')->__('Database connection error'));
}
}
示例6: _beforeSave
protected function _beforeSave()
{
parent::_beforeSave();
$actionsXML = $this->getData('actions_xml');
if (strlen($actionsXML) < 0 && @simplexml_load_string('<data>' . $actionsXML . '</data>', null, LIBXML_NOERROR) === false) {
AO::throwException(AO::helper("dataflow")->__("Actions XML is not valid."));
}
if (is_array($this->getGuiData())) {
$data = $this->getData();
$guiData = $this->getGuiData();
if (isset($guiData['file']['type']) && $guiData['file']['type'] == 'file') {
if (strlen($guiData['file']['path']) == 0 || strlen($guiData['file']['path']) == 1 && in_array($guiData['file']['path'], array('\\', '/', '.', '!', '@', '#', '$', '%', '&', '*', '~', '^'))) {
$guiData['file']['path'] = self::DEFAULT_EXPORT_PATH;
}
if (strlen($guiData['file']['filename']) == 0) {
$guiData['file']['filename'] = self::DEFAULT_EXPORT_FILENAME . $data['entity_type'] . '.' . ($guiData['parse']['type'] == 'csv' ? $guiData['parse']['type'] : 'xml');
}
$this->setGuiData($guiData);
}
// echo '<pre>';
// print_r($this->getGuiData());
$this->_parseGuiData();
$this->setGuiData(serialize($this->getGuiData()));
}
if ($this->_getResource()->isProfileExists($this->getName(), $this->getId())) {
AO::throwException(AO::helper("dataflow")->__("Profile with such name already exists."));
}
}
示例7: saveAction
public function saveAction()
{
$userId = AO::getSingleton('admin/session')->getUser()->getId();
$pwd = null;
$user = AO::getModel("admin/user")->setId($userId)->setUsername($this->getRequest()->getParam('username', false))->setFirstname($this->getRequest()->getParam('firstname', false))->setLastname($this->getRequest()->getParam('lastname', false))->setEmail(strtolower($this->getRequest()->getParam('email', false)));
if ($this->getRequest()->getParam('password', false)) {
$user->setPassword($this->getRequest()->getParam('password', false));
}
try {
try {
if ($user->userExists()) {
AO::throwException(AO::helper('adminhtml')->__('User with the same User Name or Email aleady exists'));
}
$user->save();
AO::getSingleton('adminhtml/session')->addSuccess(AO::helper('adminhtml')->__('Account successfully saved'));
} catch (Mage_Core_Exception $e) {
throw $e;
} catch (Exception $e) {
throw new Exception(AO::helper('adminhtml')->__('Error while saving account. Please try again later'));
}
} catch (Exception $e) {
AO::getSingleton('adminhtml/session')->addError($e->getMessage());
}
$this->getResponse()->setRedirect($this->getUrl("*/*/"));
}
示例8: validateUserValue
/**
* Validate user input for option
*
* @throws Mage_Core_Exception
* @param array $values All product option values, i.e. array (option_id => mixed, option_id => mixed...)
* @return Mage_Catalog_Model_Product_Option_Type_Default
*/
public function validateUserValue($values)
{
parent::validateUserValue($values);
$option = $this->getOption();
$value = $this->getUserValue();
$dateValid = true;
if ($this->_dateExists()) {
if ($this->useCalendar()) {
$dateValid = isset($value['date']) && preg_match('/^[0-9]{1,4}.+[0-9]{1,4}.+[0-9]{1,4}$/', $value['date']);
} else {
$dateValid = isset($value['day']) && isset($value['month']) && isset($value['year']) && $value['day'] > 0 && $value['month'] > 0 && $value['year'] > 0;
}
}
$timeValid = true;
if ($this->_timeExists()) {
$timeValid = isset($value['hour']) && isset($value['minute']) && is_numeric($value['hour']) && is_numeric($value['minute']);
}
$isValid = $dateValid && $timeValid;
if ($isValid) {
$this->setUserValue(array('date' => isset($value['date']) ? $value['date'] : '', 'year' => isset($value['year']) ? intval($value['year']) : 0, 'month' => isset($value['month']) ? intval($value['month']) : 0, 'day' => isset($value['day']) ? intval($value['day']) : 0, 'hour' => isset($value['hour']) ? intval($value['hour']) : 0, 'minute' => isset($value['minute']) ? intval($value['minute']) : 0, 'day_part' => isset($value['day_part']) ? $value['day_part'] : '', 'date_internal' => isset($value['date_internal']) ? $value['date_internal'] : ''));
} elseif (!$isValid && $option->getIsRequire() && !$this->getProduct()->getSkipCheckRequiredOption()) {
$this->setIsValid(false);
if (!$dateValid) {
AO::throwException(AO::helper('catalog')->__('Please specify date required option(s)'));
} elseif (!$timeValid) {
AO::throwException(AO::helper('catalog')->__('Please specify time required option(s)'));
} else {
AO::throwException(AO::helper('catalog')->__('Please specify the product required option(s)'));
}
} else {
$this->setUserValue(null);
return $this;
}
return $this;
}
示例9: _beforeSave
/**
* Perform actions before object save
*
* @param Mage_Core_Model_Abstract $object
* @return Mage_Core_Model_Mysql4_Website
*/
protected function _beforeSave(Mage_Core_Model_Abstract $object)
{
if (!preg_match('/^[a-z]+[a-z0-9_]*$/', $object->getCode())) {
AO::throwException(AO::helper('core')->__('Website code should contain only letters (a-z), numbers (0-9) or underscore(_), first character should be a letter'));
}
return parent::_beforeSave($object);
}
示例10: addSubscribersToQueue
/**
* Add subscribers to queue
*
* @param Mage_Newsletter_Model_Queue $queue
* @param array $subscriberIds
*/
public function addSubscribersToQueue(Mage_Newsletter_Model_Queue $queue, array $subscriberIds)
{
if (count($subscriberIds) == 0) {
AO::throwException(AO::helper('newsletter')->__('No subscribers selected'));
}
if (!$queue->getId() && $queue->getQueueStatus() != Mage_Newsletter_Model_Queue::STATUS_NEVER) {
AO::throwException(AO::helper('newsletter')->__('Invalid queue selected'));
}
$select = $this->_getWriteAdapter()->select();
$select->from($this->getTable('queue_link'), 'subscriber_id')->where('queue_id = ?', $queue->getId())->where('subscriber_id in (?)', $subscriberIds);
$usedIds = $this->_getWriteAdapter()->fetchCol($select);
$this->_getWriteAdapter()->beginTransaction();
try {
foreach ($subscriberIds as $subscriberId) {
if (in_array($subscriberId, $usedIds)) {
continue;
}
$data = array();
$data['queue_id'] = $queue->getId();
$data['subscriber_id'] = $subscriberId;
$this->_getWriteAdapter()->insert($this->getTable('queue_link'), $data);
}
$this->_getWriteAdapter()->commit();
} catch (Exception $e) {
$this->_getWriteAdapter()->rollBack();
}
}
示例11: fetchRatesAction
public function fetchRatesAction()
{
try {
$service = $this->getRequest()->getParam('rate_services');
$this->_getSession()->setCurrencyRateService($service);
if (!$service) {
throw new Exception(AO::helper('adminhtml')->__('Invalid Import Service Specified'));
}
try {
$importModel = AO::getModel(AO::getConfig()->getNode('global/currency/import/services/' . $service . '/model')->asArray());
} catch (Exception $e) {
AO::throwException(AO::helper('adminhtml')->__('Unable to initialize import model'));
}
$rates = $importModel->fetchRates();
$errors = $importModel->getMessages();
if (sizeof($errors) > 0) {
foreach ($errors as $error) {
AO::getSingleton('adminhtml/session')->addWarning($error);
}
AO::getSingleton('adminhtml/session')->addWarning(AO::helper('adminhtml')->__('All possible rates were fetched, click on "Save" to apply'));
} else {
AO::getSingleton('adminhtml/session')->addSuccess(AO::helper('adminhtml')->__('All rates were fetched, click on "Save" to apply'));
}
AO::getSingleton('adminhtml/session')->setRates($rates);
} catch (Exception $e) {
AO::getSingleton('adminhtml/session')->addError($e->getMessage());
}
$this->_redirect('*/*/');
}
示例12: scheduledUpdateCurrencyRates
public function scheduledUpdateCurrencyRates($schedule)
{
$importWarnings = array();
if (!AO::getStoreConfig(self::IMPORT_ENABLE) || !AO::getStoreConfig(self::CRON_STRING_PATH)) {
return;
}
$service = AO::getStoreConfig(self::IMPORT_SERVICE);
if (!$service) {
$importWarnings[] = AO::helper('directory')->__('FATAL ERROR:') . ' ' . AO::helper('directory')->__('Invalid Import Service Specified');
}
try {
$importModel = AO::getModel(AO::getConfig()->getNode('global/currency/import/services/' . $service . '/model')->asArray());
} catch (Exception $e) {
$importWarnings[] = AO::helper('directory')->__('FATAL ERROR:') . ' ' . AO::throwException(AO::helper('directory')->__('Unable to initialize import model'));
}
$rates = $importModel->fetchRates();
$errors = $importModel->getMessages();
if (sizeof($errors) > 0) {
foreach ($errors as $error) {
$importWarnings[] = AO::helper('directory')->__('WARNING:') . ' ' . $error;
}
}
if (sizeof($importWarnings) == 0) {
AO::getModel('directory/currency')->saveRates($rates);
} else {
$translate = AO::getSingleton('core/translate');
/* @var $translate Mage_Core_Model_Translate */
$translate->setTranslateInline(false);
/* @var $mailTemplate Mage_Core_Model_Email_Template */
$mailTemplate = AO::getModel('core/email_template');
$mailTemplate->setDesignConfig(array('area' => 'frontend'))->sendTransactional(AO::getStoreConfig(self::XML_PATH_ERROR_TEMPLATE), AO::getStoreConfig(self::XML_PATH_ERROR_IDENTITY), AO::getStoreConfig(self::XML_PATH_ERROR_RECIPIENT), null, array('warnings' => join("\n", $importWarnings)));
$translate->setTranslateInline(true);
}
}
示例13: _afterSave
/**
* Check base currency is available in installed currencies
*
* @return Mage_Adminhtml_Model_System_Config_Backend_Currency_Base
*/
protected function _afterSave()
{
if (!in_array($this->getValue(), $this->_getInstalledCurrencies())) {
AO::throwException(AO::helper('adminhtml')->__('Selected base currency is not available in installed currencies'));
}
return $this;
}
示例14: checkout
public function checkout()
{
$quote = $this->getQuote();
if (!$quote instanceof Mage_Sales_Model_Quote) {
AO::throwException('Invalid quote');
}
$xml = <<<EOT
<checkout-shopping-cart xmlns="http://checkout.google.com/schema/2">
<shopping-cart>
{$this->_getItemsXml()}
{$this->_getMerchantPrivateDataXml()}
{$this->_getCartExpirationXml()}
</shopping-cart>
<checkout-flow-support>
{$this->_getMerchantCheckoutFlowSupportXml()}
</checkout-flow-support>
<order-processing-support>
{$this->_getRequestInitialAuthDetailsXml()}
</order-processing-support>
</checkout-shopping-cart>
EOT;
#echo "<xmp>".$xml."</xmp>";
$result = $this->_call($xml);
$this->setRedirectUrl($result->{'redirect-url'});
return $this;
}
示例15: getRetreiver
/**
* Returns data retreiver model by specified product type
*
* @param string $type
* @return Mage_CatalogIndex_Model_Data_Abstract
*/
public function getRetreiver($type)
{
if (isset($this->_retreivers[$type])) {
return AO::getSingleton($this->_retreivers[$type]);
} else {
AO::throwException("Data retreiver for '{$type}' is not defined");
}
}