作者:kirkbauer
项目:kirkx
/**
* Send message
*
* @return boolean
*/
public function send()
{
if (\XLite\Core\Config::getInstance()->XC->WebmasterKit->logMail) {
\XLite\Logger::getInstance()->logCustom('mail-messages', 'From: ' . $this->mail->From . PHP_EOL . 'To: ' . $this->get('to') . PHP_EOL . 'Subject: ' . $this->mail->Subject . PHP_EOL . $this->mail->Body . PHP_EOL . PHP_EOL);
}
return parent::send();
}
作者:kirkbauer
项目:kirkx
/**
* Constructor
* Creates directory for locks if needed
*/
public function __construct()
{
if (!\Includes\Utils\FileManager::isExists(rtrim(static::LOCK_DIR, LC_DS))) {
\Includes\Utils\FileManager::mkdirRecursive(rtrim(static::LOCK_DIR, LC_DS));
}
if (!\Includes\Utils\FileManager::isReadable(static::LOCK_DIR) || !\Includes\Utils\FileManager::isWriteable(static::LOCK_DIR)) {
\XLite\Logger::getInstance()->log('Cannot create lock for keys', LOG_DEBUG);
}
parent::__construct();
}
作者:kirkbauer
项目:kirkx
/**
* Perform actual mapping
*
* @return mixed
*/
protected function performMap()
{
$response = json_decode($this->inputData->body);
$result = null;
if (isset($response->error)) {
\XLite\Logger::logCustom("PitneyBowes", 'ConfirmOrder: ' . $response->error . ' - ' . $response->message, false);
} else {
$result = $response;
}
return $result;
}
作者:kirkbauer
项目:kirkx
/**
* Start Doctrine entity manager
*
* @return void
*/
public function startEntityManager()
{
parent::startEntityManager();
if (!defined('LC_CACHE_BUILDING')) {
if (\XLite\Module\XC\WebmasterKit\Core\Profiler::getInstance()->enabled) {
static::$em->getConnection()->getConfiguration()->setSQLLogger(\XLite\Module\XC\WebmasterKit\Core\Profiler::getInstance());
} elseif (\XLite\Core\Config::getInstance()->XC->WebmasterKit->logSQL) {
static::$em->getConnection()->getConfiguration()->setSQLLogger(\XLite\Logger::getInstance());
}
}
}
作者:kirkbauer
项目:kirkx
/**
* Return current module object
*
* @return \XLite\Model\Module
* @throws \Exception
*/
public function getModule()
{
if (!isset($this->module)) {
$this->module = \XLite\Core\Database::getRepo('\\XLite\\Model\\Module')->find($this->getModuleID());
if (!$this->module) {
\XLite\Core\TopMessage::addError('Add-on does not exist.');
\XLite\Logger::getInstance()->log('Add-on does not exist (ID: ' . $this->getModuleID() . ')', LOG_ERR);
$this->redirect($this->buildURL('addons_list_installed'));
}
}
return $this->module;
}
作者:kewaunite
项目:xcar
/**
* Process callback
*
* @return void
*/
protected function doActionCallback()
{
$transaction = $this->detectTransaction();
if ($transaction) {
$this->transaction = $transaction;
$transaction->getPaymentMethod()->getProcessor()->processCallback($transaction);
$cart = $transaction->getOrder();
if ($cart instanceof \XLite\Model\Cart) {
$cart->tryClose();
}
$transaction->getOrder()->setPaymentStatusByTransaction($transaction);
$transaction->getOrder()->update();
\XLite\Core\Database::getEM()->flush();
} else {
\XLite\Logger::getInstance()->log('Request callback with undefined payment transaction' . PHP_EOL . 'Data: ' . var_export(\XLite\Core\Request::getInstance()->getData(), true), LOG_ERR);
}
$this->set('silent', true);
}
作者:kings
项目:cor
/**
* Get request data
*
* @return mixed
*/
public function getRequestData()
{
$data = null;
$validator = $this->getValidator();
try {
$validator->validate(\XLite\Core\Request::getInstance()->getData());
$data = $validator->sanitize(\XLite\Core\Request::getInstance()->getData());
} catch (\XLite\Core\Validator\Exception $exception) {
$message = static::t($exception->getMessage(), $exception->getLabelArguments());
if ($exception->isInternal()) {
\XLite\Logger::getInstance()->log($message, LOG_ERR);
} else {
\XLite\Core\Event::invalidElement($exception->getPath(), $message);
}
$this->validationMessage = ($exception->getPublicName() ? static::t($exception->getPublicName()) . ': ' : '') . $message;
}
return $data;
}
作者:kings
项目:cor
/**
* Process item
*
* @param mixed $item Item
*
* @return boolean
*/
protected function processItem($item)
{
$result = false;
$path = tempnam(LC_DIR_TMP, 'migrate_file');
file_put_contents($path, $item->getBody());
if (\Includes\Utils\FileManager::isExists($path)) {
$localPath = $item->isURL() ? null : $item->getStoragePath();
$result = $item->loadFromLocalFile($path, $item->getFileName() ?: basename($item->getPath()));
if ($result && $localPath && \Includes\Utils\FileManager::isExists($localPath)) {
\Includes\Utils\FileManager::deleteFile($localPath);
}
\Includes\Utils\FileManager::deleteFile($path);
}
if (!$result) {
if (!isset($this->record['s3_error_count'])) {
$this->record['s3_error_count'] = 0;
}
$this->record['s3_error_count']++;
\XLite\Logger::getInstance()->log('Couldn\'t move image ' . $item->getPath() . ' (local file system to Amazon S3)', LOG_ERR);
}
return true;
}
作者:kings
项目:cor
/**
* Process item
*
* @param mixed $item Item
*
* @return boolean
*/
protected function processItem($item)
{
$result = false;
$path = tempnam(LC_DIR_TMP, 'migrate_file');
file_put_contents($path, $item->getBody());
if (file_exists($path)) {
$item->setS3Forbid(true);
$localPath = $item->getStoragePath();
$result = $item->loadFromLocalFile($path, $item->getFileName() ?: basename($item->getPath()));
if ($localPath) {
\XLite\Module\CDev\AmazonS3Images\Core\S3::getInstance()->delete($localPath);
}
unlink($path);
}
if (!$result) {
if (!isset($this->record['s3_error_count'])) {
$this->record['s3_error_count'] = 0;
}
$this->record['s3_error_count']++;
\XLite\Logger::getInstance()->log('Couldn\'t move image ' . $item->getPath() . ' (Amazon S3 to local file system)', LOG_ERR);
}
return true;
}
作者:kirkbauer
项目:kirkx
/**
* Uninstall module
*
* @param \XLite\Model\Module $module Module object
* @param array &$messages Messages list
*
* @return boolean
*/
public function uninstallModule(\XLite\Model\Module $module, &$messages)
{
$result = false;
// Get module pack
$pack = new \XLite\Core\Pack\Module($module);
$dirs = $pack->getDirs();
$nonWritableDirs = array();
// Check module directories permissions
foreach ($dirs as $dir) {
if (\Includes\Utils\FileManager::isExists($dir) && !\Includes\Utils\FileManager::isDirWriteable($dir)) {
$nonWritableDirs[] = \Includes\Utils\FileManager::getRelativePath($dir, LC_DIR_ROOT);
}
}
$params = array('name' => sprintf('%s v%s (%s)', $module->getModuleName(), $module->getVersion(), $module->getAuthorName()));
if (empty($nonWritableDirs)) {
$yamlData = array();
$yamlFiles = \Includes\Utils\ModulesManager::getModuleYAMLFiles($module->getAuthor(), $module->getName());
foreach ($yamlFiles as $yamlFile) {
$yamlData[] = \Includes\Utils\FileManager::read($yamlFile);
}
if (!$module->checkModuleMainClass()) {
$classFile = LC_DIR_CLASSES . \Includes\Utils\Converter::getClassFile($module->getMainClass());
if (\Includes\Utils\FileManager::isFileReadable($classFile)) {
require_once $classFile;
}
}
// Call uninstall event method
$r = $module->callModuleMethod('callUninstallEvent', 111);
if (111 == $r) {
\XLite\Logger::getInstance()->log($module->getActualName() . ': Method callUninstallEvent() was not called');
}
// Remove from FS
foreach ($dirs as $dir) {
\Includes\Utils\FileManager::unlinkRecursive($dir);
}
\Includes\Utils\ModulesManager::disableModule($module->getActualName());
\Includes\Utils\ModulesManager::removeModuleFromDisabledStructure($module->getActualName());
// Remove module from DB
try {
// Refresh module entity as it was changed by disableModule() method above
$module = $this->find($module->getModuleID());
$this->delete($module);
} catch (\Exception $e) {
$messages[] = $e->getMessage();
}
if ($module->getModuleID()) {
$messages[] = \XLite\Core\Translation::getInstance()->translate('A DB error occured while uninstalling the module X', $params);
} else {
if (!empty($yamlData)) {
foreach ($yamlData as $yaml) {
\XLite\Core\Database::getInstance()->unloadFixturesFromYaml($yaml);
}
}
$messages[] = \XLite\Core\Translation::getInstance()->translate('The module X has been uninstalled successfully', $params);
$result = true;
}
} else {
$messages[] = \XLite\Core\Translation::getInstance()->translate('Unable to delete module X files: some dirs have no writable permissions: Y', $params + array('dirs' => implode(', ', $nonWritableDirs)));
}
return $result;
}
作者:kirkbauer
项目:kirkx
/**
* Attempts to display widget using its template
*
* @param string $template Template file name OPTIONAL
*
* @return void
*/
public function display($template = null)
{
// todo: use meaning name
$flag = null !== $template;
if ($flag || $this->checkVisibility()) {
if (!$this->isCloned && !$flag) {
$this->initView();
}
$cacheAvailable = $this->isCacheAllowed($template);
$content = $cacheAvailable ? $this->getCachedContent() : null;
if (null !== $content) {
print $content;
} else {
if ($cacheAvailable) {
ob_start();
}
// Body of the old includeCompiledFile() method
list($this->currentSkin, $this->currentLocale, $normalized) = $this->getTemplateFile($template);
if (null === $normalized) {
\XLite\Logger::getInstance()->log(sprintf('Empty compiled template. View class: %s, view main template: %s', get_class($this), $this->getTemplate()), \LOG_DEBUG);
} else {
$compiled = \XLite\Singletons::$handler->flexy->prepare($normalized);
// Collect the specific data to send it to the finalizeTemplateDisplay method
$profilerData = $this->prepareTemplateDisplay($normalized);
static::$viewsTail[] = $normalized;
include $compiled;
array_pop(static::$viewsTail);
$this->finalizeTemplateDisplay($template, $profilerData);
}
if ($cacheAvailable) {
$this->setCachedContent(ob_get_contents());
ob_end_flush();
}
}
}
}
作者:kirkbauer
项目:kirkx
/**
* Call controller action
*
* @return void
*/
protected function callAction()
{
$action = $this->getAction();
$method = 'doAction' . \Includes\Utils\Converter::convertToPascalCase($action);
if (method_exists($this, $method)) {
// Call method doAction<action-name-in-camel-case>
$this->{$method}();
} else {
\XLite\Logger::getInstance()->log('Handler for the action "' . $action . '" is not defined for the "' . get_class($this) . '" class');
}
$this->actionPostprocess($action);
}
作者:kings
项目:cor
/**
* Process callback
*
* @return void
*/
protected function doActionCallback()
{
$txn = null;
$txnIdName = 'txnId';
if (isset(\XLite\Core\Request::getInstance()->txn_id_name)) {
/**
* some of gateways can't accept return url on run-time and
* use the one set in merchant account, so we can't pass
* 'order_id' in run-time, instead pass the order id parameter name
*/
$txnIdName = \XLite\Core\Request::getInstance()->txn_id_name;
}
if (isset(\XLite\Core\Request::getInstance()->{$txnIdName})) {
$txn = \XLite\Core\Database::getRepo('XLite\\Model\\Payment\\Transaction')->find(\XLite\Core\Request::getInstance()->{$txnIdName});
}
if (!$txn) {
$methods = \XLite\Core\Database::getRepo('XLite\\Model\\Payment\\Method')->findAllActive();
foreach ($methods as $method) {
if (method_exists($method->getProcessor(), 'getCallbackOwnerTransaction')) {
$txn = $method->getProcessor()->getCallbackOwnerTransaction();
if ($txn) {
break;
}
}
}
}
if ($txn) {
$txn->getPaymentMethod()->getProcessor()->processCallback($txn);
$cart = $txn->getOrder();
if (!$cart->isOpen()) {
// TODO: move it to \XLite\Controller\ACustomer
if ($cart->isPayed()) {
$status = $txn->isCaptured() ? \XLite\Model\Order::STATUS_PROCESSED : \XLite\Model\Order::STATUS_AUTHORIZED;
} else {
if ($txn->isRefunded()) {
$status = \XLite\Model\Order::STATUS_DECLINED;
} elseif ($txn->isFailed()) {
$status = \XLite\Model\Order::STATUS_FAILED;
} else {
$status = \XLite\Model\Order::STATUS_QUEUED;
}
}
$cart->setStatus($status);
}
} else {
\XLite\Logger::getInstance()->log('Request callback with undefined payment transaction' . PHP_EOL . 'Data: ' . var_export(\XLite\Core\Request::getInstance()->getData(), true), LOG_ERR);
}
\XLite\Core\Database::getEM()->flush();
$this->set('silent', true);
}
作者:kewaunite
项目:xcar
/**
* Add log message
*
* @param boolean $status Status
* @param array $request Request data
* @param array $response Response data
*
* @return void
*/
protected function logResponse($status, $request, $response)
{
if (\XLite\Core\Config::getInstance()->XC->AuctionInc->debugMode) {
\XLite\Logger::logCustom('AuctionInc', array('status' => $status, 'request' => $request, 'response' => $response));
}
}
作者:kewaunite
项目:xcar
/**
* Add record to the module log file
*
* @param string $message Text message OPTIONAL
* @param mixed $data Data (can be any type) OPTIONAL
*
* @return void
*/
public static function addLog($message = null, $data = null)
{
if ($message && $data) {
$msg = array('message' => $message, 'data' => $data);
} else {
$msg = $message ?: ($data ?: null);
}
if (!is_string($msg)) {
$msg = var_export($msg, true);
}
\XLite\Logger::logCustom(self::getModuleName(), $msg);
}
作者:kewaunite
项目:xcar
/**
* Import data
*
* @param array $data Row set Data
*
* @return boolean
*/
protected function importData(array $data)
{
$model = $this->detectModel($data);
if ($model) {
$this->setMetaData('updateCount', (int) $this->getMetaData('updateCount') + 1);
} else {
$this->setMetaData('addCount', (int) $this->getMetaData('addCount') + 1);
}
if (!$model) {
$model = $this->createModel($data);
\XLite\Core\Database::getEM()->persist($model);
}
$result = $this->updateModel($model, $data);
if ($result) {
try {
\XLite\Core\Database::getEM()->flush();
} catch (\Exception $e) {
\XLite\Logger::getInstance()->registerException($e);
$result = false;
}
}
return $result;
}
作者:kings
项目:cor
/**
* Log import notice
*
* @param string $message Message
* @param integer $position Row position OPTIONAL
* @param string $column Column name OPTIONAL
* @param string $value Cell value OPTIONAL
* @param \XLite\Model\Product $product Product OPTIONAL
*
* @return void
*/
protected function logImportWarning($message, $position = null, $column = null, $value = null, \XLite\Model\Product $product = null)
{
$message = trim($message);
$this->importCell['warning_count']++;
if (isset($position)) {
$message .= PHP_EOL . 'Row number: ' . ($position + 2);
}
if (isset($column)) {
$message .= PHP_EOL . 'Column: ' . $column;
}
if (isset($value)) {
$message .= PHP_EOL . 'Cell value: ' . var_export($value, true);
}
if (isset($product)) {
if ($product->getProductId()) {
$message .= PHP_EOL . 'Product id: ' . $product->getProductId();
} elseif ($product->getSku()) {
$message .= PHP_EOL . 'Product SKU: ' . $product->getSku();
}
}
\XLite\Logger::getInstance()->logCustom('import', $message);
}
作者:kewaunite
项目:xcar
/**
* Orders collect garbage
*
* @return void
*/
public function collectGarbage()
{
// Remove old temporary orders
$list = $this->findAllExpiredTemporaryOrders();
if (count($list)) {
foreach ($list as $order) {
\XLite\Core\Database::getEM()->remove($order);
}
\XLite\Core\Database::getEM()->flush();
// Log operation only in debug mode
\XLite\Logger::getInstance()->log(\XLite\Core\Translation::getInstance()->translate('X expired shopping cart(s) have been successfully removed', array('count' => count($list))));
}
}
作者:kewaunite
项目:xcar
/**
* Write error to log
*
* @param string $error Error message
* @param mixed $logData Log data
*
* @return void
*/
public static function writeLogError($error, $logData = null)
{
if (!is_null($logData)) {
if (is_scalar($logData)) {
$logData = strval($logData);
} else {
$logData = var_export($logData, true);
}
$logData = $error . PHP_EOL . $logData;
} else {
$logData = $error;
}
\XLite\Logger::getInstance()->logCustom(self::LOG_FILE_ERROR, $logData, true);
}
作者:kewaunite
项目:xcar
/**
* "Upload" handler for category images.
*
* @return void
*/
protected function doActionSelectUploadLanguageFile()
{
$result = null;
$error = null;
$message = null;
$key = 'uploaded_file';
$cell = isset($_FILES[$key]) ? $_FILES[$key] : null;
if ($cell) {
$size = null;
switch ($cell['error']) {
case UPLOAD_ERR_OK:
$path = \Includes\Utils\FileManager::getUniquePath(LC_DIR_TMP, $cell['name']);
if (move_uploaded_file($cell['tmp_name'], $path)) {
$result = $path;
}
break;
case UPLOAD_ERR_INI_SIZE:
$size = ini_get('upload_max_filesize');
case UPLOAD_ERR_FORM_SIZE:
$size = $size ?: \XLite\Core\Request::getInstance()->MAX_FILE_SIZE;
$error = 'File size exceeds the maximum size (' . $size . ')';
$size = \XLite\Core\Converter::convertShortSizeToHumanReadable($size);
$message = \XLite\Core\Translation::lbl('File size exceeds the maximum size', array('size' => $size));
break;
case UPLOAD_ERR_PARTIAL:
$error = 'The uploaded file was only partially uploaded';
case UPLOAD_ERR_NO_FILE:
$error = $error ?: 'No file was uploaded';
case UPLOAD_ERR_NO_TMP_DIR:
$error = $error ?: 'Missing a temporary folder';
case UPLOAD_ERR_CANT_WRITE:
$error = $error ?: 'Failed to write file to disk';
case UPLOAD_ERR_EXTENSION:
$message = \XLite\Core\Translation::lbl('The file was not loaded because of a failure on the server.');
$error = $error ?: 'File upload stopped by extension';
break;
default:
}
}
if ($result && $message) {
\XLite\Logger::getInstance()->log('Upload file error: ' . $error ?: $message, LOG_ERR);
}
$this->doActionSelectLanguageFile($result, $message);
}