PageRenderTime 35ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/www/shop/engine/Shopware/Controllers/Backend/Log.php

https://bitbucket.org/weberlars/sot-shopware
PHP | 170 lines | 91 code | 20 blank | 59 comment | 5 complexity | 4ff4f99a48b34f66b7491317aee13b04 MD5 | raw file
Possible License(s): AGPL-3.0, MIT, BSD-3-Clause, LGPL-2.1, LGPL-3.0
  1. <?php
  2. /**
  3. * Shopware 4.0
  4. * Copyright Š 2012 shopware AG
  5. *
  6. * According to our dual licensing model, this program can be used either
  7. * under the terms of the GNU Affero General Public License, version 3,
  8. * or under a proprietary license.
  9. *
  10. * The texts of the GNU Affero General Public License with an additional
  11. * permission and of our proprietary license can be found at and
  12. * in the LICENSE file you have received along with this program.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * "Shopware" is a registered trademark of shopware AG.
  20. * The licensing of the program under the AGPLv3 does not imply a
  21. * trademark license. Therefore any rights, title and interest in
  22. * our trademarks remain entirely with us.
  23. *
  24. * @category Shopware
  25. * @package Shopware_Controllers
  26. * @subpackage Premium
  27. * @copyright Copyright (c) 2012, shopware AG (http://www.shopware.de)
  28. * @version $Id$
  29. * @author Patrick Stahl
  30. * @author $Author$
  31. */
  32. /**
  33. * Shopware Log Controller
  34. *
  35. * This controller handles all actions made by the user or the server in the log module or the backend.
  36. * It reads all logs, creates new ones or deletes them.
  37. */
  38. class Shopware_Controllers_Backend_Log extends Shopware_Controllers_Backend_ExtJs
  39. {
  40. /**
  41. * Sets the ACL-rights for the log-module
  42. */
  43. public function initAcl()
  44. {
  45. $this->addAclPermission("getLogs", "read", "You're not allowed to see the logs.");
  46. $this->addAclPermission("deleteLogs", "delete", "You're not allowed to delete the logs.");
  47. }
  48. /**
  49. * Disable template engine for all actions
  50. *
  51. * @return void
  52. */
  53. public function preDispatch()
  54. {
  55. if (!in_array($this->Request()->getActionName(), array('index', 'load'))) {
  56. $this->Front()->Plugins()->Json()->setRenderer(true);
  57. }
  58. }
  59. /**
  60. * This function is called, when the user opens the log-module.
  61. * It reads the logs from s_core_log
  62. * Additionally it sets a filterValue
  63. */
  64. public function getLogsAction(){
  65. $start = $this->Request()->get('start');
  66. $limit = $this->Request()->get('limit');
  67. //order data
  68. $order = (array)$this->Request()->getParam('sort', array());
  69. //Get the value itself
  70. if($this->Request()->get('filter')){
  71. $filter = $this->Request()->get('filter');
  72. $filter = $filter[count($filter) - 1];
  73. $filterValue = $filter['value'];
  74. }
  75. $builder = Shopware()->Models()->createQueryBuilder();
  76. $builder->select(
  77. 'log.id as id',
  78. 'log.type as type',
  79. 'log.key as key',
  80. 'log.text as text',
  81. 'log.date as date',
  82. 'log.user as user',
  83. 'log.ipAddress as ip_address',
  84. 'log.userAgent as user_agent',
  85. 'log.value4 as value4'
  86. )->from('Shopware\Models\Log\Log','log');
  87. if($filterValue){
  88. $builder->where('log.user = ?1')->setParameter(1, $filterValue);
  89. }
  90. $builder->addOrderBy($order);
  91. $builder->setFirstResult($start)->setMaxResults($limit);
  92. $result = $builder->getQuery()->getArrayResult();
  93. $total = Shopware()->Models()->getQueryCount($builder->getQuery());
  94. $this->View()->assign(array('success'=>true, 'data'=>$result, 'total'=>$total));
  95. }
  96. /**
  97. * This function is called when the user wants to delete a log.
  98. * It only handles the deletion.
  99. */
  100. public function deleteLogsAction(){
  101. try{
  102. $params = $this->Request()->getParams();
  103. unset($params['module']);
  104. unset($params['controller']);
  105. unset($params['action']);
  106. unset($params['_dc']);
  107. if($params[0]){
  108. $data = array();
  109. foreach($params as $values){
  110. $logModel = Shopware()->Models()->find('\Shopware\Models\Log\Log', $values['id']);
  111. Shopware()->Models()->remove($logModel);
  112. Shopware()->Models()->flush();
  113. $data[] = Shopware()->Models()->toArray($logModel);
  114. }
  115. }else{
  116. $logModel = Shopware()->Models()->find('\Shopware\Models\Log\Log', $params['id']);
  117. Shopware()->Models()->remove($logModel);
  118. Shopware()->Models()->flush();
  119. }
  120. $this->View()->assign(array('success'=>true, 'data'=>$params));
  121. }catch(Exception $e){
  122. $this->View()->assign(array('success'=>false, 'errorMsg'=>$e->getMessage()));
  123. }
  124. }
  125. /**
  126. * This method is called when a new log is made automatically.
  127. * It sets the different values and saves the log into s_core_log
  128. */
  129. public function createLogAction(){
  130. try{
  131. $params = $this->Request()->getParams();
  132. $params['key'] = utf8_encode(html_entity_decode($params['key']));
  133. $logModel = new Shopware\Models\Log\Log;
  134. $userAgent = $_SERVER['HTTP_USER_AGENT'];
  135. if(empty($userAgent)){
  136. $userAgent = 'Unknown';
  137. }
  138. $logModel->fromArray($params);
  139. $logModel->setDate(new \DateTime("now"));
  140. $logModel->setIpAddress(getenv("REMOTE_ADDR"));
  141. $logModel->setUserAgent($userAgent);
  142. Shopware()->Models()->persist($logModel);
  143. Shopware()->Models()->flush();
  144. $data = Shopware()->Models()->toArray($logModel);
  145. $this->View()->assign(array('success'=>true, 'data'=>$data));
  146. }catch(Exception $e){
  147. $this->View()->assign(array('success'=>false, 'errorMsg'=>$e->getMessage()));
  148. }
  149. }
  150. }