Ejemplo n.º 1
0
 /**
  * Process all pending tasks
  */
 public function work()
 {
     while (count($task = $this->_queue->receive()) > 0) {
         try {
             $taskData = $task->toArray();
             $this->getWorker()->execute($taskData[0]);
         } catch (Exception $e) {
             $this->_logger->logException($e);
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Log wrapper
  *
  * @param string $message
  * @param int $level
  * @param string $file
  * @param bool $forceLog
  * @return void
  */
 public function log($message, $level = null, $file = '', $forceLog = false)
 {
     if (empty($file)) {
         $file = self::MENU_DEBUG_FILE;
     }
     parent::log($message, $level, $file, $forceLog);
 }
Ejemplo n.º 3
0
 public function testLogComplex()
 {
     $this->expectOutputRegex('/Array\\s\\(\\s+\\[0\\] => 1\\s\\).+stdClass Object/s');
     $this->_model->addStreamLog(Mage_Core_Model_Logger::LOGGER_SYSTEM, 'php://output');
     $this->_model->log(array(1));
     $this->_model->log(new StdClass());
 }
Ejemplo n.º 4
0
 /**
  * Log information about exception to exception log.
  *
  * @param Exception $exception
  * @return string $reportId
  */
 protected function _logException(Exception $exception)
 {
     $exceptionClass = get_class($exception);
     $reportId = uniqid("webapi-");
     $exceptionForLog = new $exceptionClass("Report ID: {$reportId}; Message: {$exception->getMessage()}", $exception->getCode());
     $this->_logger->logException($exceptionForLog);
     return $reportId;
 }
Ejemplo n.º 5
0
 /**
  * Initialize and execute changelog clear action with metadata provided.
  *
  * @param Enterprise_Mview_Model_Metadata $metadata
  */
 protected function _runCleanupAction(Enterprise_Mview_Model_Metadata $metadata)
 {
     $this->_getClient()->init($metadata->getTableName());
     try {
         $this->_getClient()->execute('enterprise_mview/action_changelog_clear');
     } catch (Exception $e) {
         $this->_logger->logException($e);
     }
 }
Ejemplo n.º 6
0
 /**
  * Test maskException method with turned on developer mode.
  */
 public function testMaskNonWebapiException()
 {
     /** Assert exception was logged. */
     $this->_loggerMock->expects($this->once())->method('logException');
     $maskedException = $this->_errorProcessor->maskException(new LogicException());
     /** Assert masked exception type is Mage_Webapi_Exception. */
     $this->assertInstanceOf('Mage_Webapi_Exception', $maskedException, 'Masked exception type is not Webapi.');
     /** Asser masked exception code is 500. */
     $this->assertEquals(Mage_Webapi_Exception::HTTP_INTERNAL_ERROR, $maskedException->getCode(), 'Masked exception code is wrong.');
     /** Assert masked exception message. */
     $this->assertEquals('Internal Error. Details are available in Magento log file. Report ID: "%s"', $maskedException->getMessage(), 'Masked exception message is wrong.');
 }
Ejemplo n.º 7
0
 /**
  * Delete a message from the queue
  *
  * @param Zend_Queue_Message $message
  * @return bool
  */
 public function deleteMessage(Zend_Queue_Message $message)
 {
     try {
         $msg = $this->_queueTaskModel->load($message->handle, 'handle');
         if (!is_null($msg->getId())) {
             $msg->delete();
             return true;
         }
     } catch (Exception $e) {
         $this->_logger->logException($e);
     }
     return false;
 }
Ejemplo n.º 8
0
 /**
  * Save file to storage
  *
  * @param string $filePath
  * @param string $content
  * @param bool $overwrite
  * @return bool
  */
 public function saveFile($filePath, $content, $overwrite = false)
 {
     if (strpos($filePath, $this->getMediaBaseDirectory()) !== 0) {
         $filePath = $this->getMediaBaseDirectory() . DS . $filePath;
     }
     try {
         if (!$this->_filesystem->isFile($filePath) || $overwrite && $this->_filesystem->delete($filePath)) {
             $this->_filesystem->write($filePath, $content);
             return true;
         }
     } catch (Magento_Filesystem_Exception $e) {
         $this->_logger->log($e->getMessage());
         Mage::throwException($this->_helper->__('Unable to save file: %s', $filePath));
     }
     return false;
 }
Ejemplo n.º 9
0
 /**
  * Remove menu item by id
  *
  * @param string $itemId
  * @return bool
  */
 public function remove($itemId)
 {
     $result = false;
     foreach ($this as $key => $item) {
         /** @var $item Mage_Backend_Model_Menu_Item */
         if ($item->getId() == $itemId) {
             unset($this[$key]);
             $result = true;
             $this->_logger->logDebug(sprintf('Remove on item with id %s was processed', $item->getId()), self::LOGGER_KEY);
             break;
         }
         if ($item->hasChildren() && ($result = $item->getChildren()->remove($itemId))) {
             break;
         }
     }
     return $result;
 }
Ejemplo n.º 10
0
 /**
  * Get command object
  * @param array $data command params
  * @return Mage_Backend_Model_Menu_Builder_CommandAbstract
  */
 protected function _getCommand($data)
 {
     switch ($data['type']) {
         case 'update':
             $command = $this->_factory->create('Mage_Backend_Model_Menu_Builder_Command_Update', array('data' => $data));
             $this->_logger->logDebug(sprintf('Update on item with id %s was processed', $command->getId()), Mage_Backend_Model_Menu::LOGGER_KEY);
             break;
         case 'remove':
             $command = $this->_factory->create('Mage_Backend_Model_Menu_Builder_Command_Remove', array('data' => $data));
             $this->_logger->logDebug(sprintf('Remove on item with id %s was processed', $command->getId()), Mage_Backend_Model_Menu::LOGGER_KEY);
             break;
         default:
             $command = $this->_factory->create('Mage_Backend_Model_Menu_Builder_Command_Add', array('data' => $data));
             break;
     }
     return $command;
 }
Ejemplo n.º 11
0
 /**
  * Execute specified task
  *
  * @param array $task
  * @return bool
  */
 public function execute($task)
 {
     $taskDetails = Zend_Json::decode($task['data']);
     if (isset($taskDetails['task_name'])) {
         try {
             $this->_config->loadEventObservers('workers');
             $this->_app->addEventArea('workers');
             $this->getReporter()->reportTaskProcessing($task['task_id']);
             $this->_dispatchEvent($taskDetails['task_name'], $taskDetails['params']);
             $this->getReporter()->reportTaskCompleted($task['task_id']);
         } catch (Exception $e) {
             $this->getReporter()->reportTaskFailed($task['task_id']);
             $this->_logger->logException($e);
         }
     }
     return true;
 }
Ejemplo n.º 12
0
 /**
  * Build menu model from config
  *
  * @return Mage_Backend_Model_Menu
  * @throws InvalidArgumentException|BadMethodCallException|OutOfRangeException|Exception
  */
 public function getMenu()
 {
     $store = $this->_factory->get('Mage_Core_Model_App')->getStore();
     $this->_logger->addStoreLog(Mage_Backend_Model_Menu::LOGGER_KEY, $store);
     try {
         $this->_initMenu();
         return $this->_menu;
     } catch (InvalidArgumentException $e) {
         $this->_logger->logException($e);
         throw $e;
     } catch (BadMethodCallException $e) {
         $this->_logger->logException($e);
         throw $e;
     } catch (OutOfRangeException $e) {
         $this->_logger->logException($e);
         throw $e;
     } catch (Exception $e) {
         throw $e;
     }
 }
Ejemplo n.º 13
0
 public function testSerialize()
 {
     $this->assertNotEmpty($this->_model->serialize());
     $this->_logger->expects($this->once())->method('log');
     $this->_model->add($this->_items['item1']);
 }