PageRenderTime 50ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/magento/app/code/core/Mage/Core/Model/Observer.php

https://bitbucket.org/jit_bec/shopifine
PHP | 108 lines | 56 code | 10 blank | 42 comment | 11 complexity | 8b8671a386f1a5b270284fa83d10e057 MD5 | raw file
Possible License(s): LGPL-3.0
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Core
  23. * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Core Observer model
  28. *
  29. * @category Mage
  30. * @package Mage_Core
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Core_Model_Observer
  34. {
  35. /**
  36. * Check if synchronize process is finished and generate notification message
  37. *
  38. * @param Varien_Event_Observer $observer
  39. * @return Mage_Core_Model_Observer
  40. */
  41. public function addSynchronizeNotification(Varien_Event_Observer $observer)
  42. {
  43. $adminSession = Mage::getSingleton('admin/session');
  44. if (!$adminSession->hasSyncProcessStopWatch()) {
  45. $flag = Mage::getSingleton('core/file_storage')->getSyncFlag();
  46. $state = $flag->getState();
  47. if ($state == Mage_Core_Model_File_Storage_Flag::STATE_RUNNING) {
  48. $syncProcessStopWatch = true;
  49. } else {
  50. $syncProcessStopWatch = false;
  51. }
  52. $adminSession->setSyncProcessStopWatch($syncProcessStopWatch);
  53. }
  54. $adminSession->setSyncProcessStopWatch(false);
  55. if (!$adminSession->getSyncProcessStopWatch()) {
  56. if (!isset($flag)) {
  57. $flag = Mage::getSingleton('core/file_storage')->getSyncFlag();
  58. }
  59. $state = $flag->getState();
  60. if ($state == Mage_Core_Model_File_Storage_Flag::STATE_FINISHED) {
  61. $flagData = $flag->getFlagData();
  62. if (isset($flagData['has_errors']) && $flagData['has_errors']) {
  63. $severity = Mage_AdminNotification_Model_Inbox::SEVERITY_MAJOR;
  64. $title = Mage::helper('adminhtml')->__('An error has occured while syncronizing media storages.');
  65. $description = Mage::helper('adminhtml')->__('One or more media files failed to be synchronized during the media storages syncronization process. Refer to the log file for details.');
  66. } else {
  67. $severity = Mage_AdminNotification_Model_Inbox::SEVERITY_NOTICE;
  68. $title = Mage::helper('adminhtml')->__('Media storages synchronization has completed!');
  69. $description = Mage::helper('adminhtml')->__('Synchronization of media storages has been successfully completed.');
  70. }
  71. $date = date('Y-m-d H:i:s');
  72. Mage::getModel('adminnotification/inbox')->parse(array(
  73. array(
  74. 'severity' => $severity,
  75. 'date_added' => $date,
  76. 'title' => $title,
  77. 'description' => $description,
  78. 'url' => '',
  79. 'internal' => true
  80. )
  81. ));
  82. $flag->setState(Mage_Core_Model_File_Storage_Flag::STATE_NOTIFIED)->save();
  83. }
  84. $adminSession->setSyncProcessStopWatch(false);
  85. }
  86. return $this;
  87. }
  88. /**
  89. * Cron job method to clean old cache resources
  90. *
  91. * @param Mage_Cron_Model_Schedule $schedule
  92. */
  93. public function cleanCache(Mage_Cron_Model_Schedule $schedule)
  94. {
  95. Mage::app()->getCache()->clean(Zend_Cache::CLEANING_MODE_OLD);
  96. Mage::dispatchEvent('core_clean_cache');
  97. }
  98. }