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_XmlConnect
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: /**
28: * XmlConnect module observer
29: *
30: * @category Mage
31: * @package Mage_Xmlconnect
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_XmlConnect_Model_Observer
35: {
36: /**
37: * List of config field names which changing affects mobile applications behaviour
38: *
39: * @var array
40: */
41: protected $_appDependOnConfigFieldPathes = array(
42: Mage_XmlConnect_Model_Application::XML_PATH_PAYPAL_BUSINESS_ACCOUNT,
43: 'sendfriend/email/max_recipients',
44: 'sendfriend/email/allow_guest',
45: 'general/locale/code',
46: 'currency/options/default',
47: Mage_XmlConnect_Model_Application::XML_PATH_SECURE_BASE_LINK_URL,
48: Mage_XmlConnect_Model_Application::XML_PATH_GENERAL_RESTRICTION_IS_ACTIVE,
49: Mage_XmlConnect_Model_Application::XML_PATH_GENERAL_RESTRICTION_MODE,
50: Mage_XmlConnect_Model_Application::XML_PATH_DEFAULT_CACHE_LIFETIME
51: );
52:
53: /**
54: * Stop website stub or private sales restriction
55: *
56: * @param Varien_Event_Observer $observer
57: */
58: public function restrictWebsite($observer)
59: {
60: if (Mage::app()->getRequest()->getModuleName() == 'xmlconnect') {
61: $observer->getEvent()->getResult()->setShouldProceed(false);
62: }
63: }
64:
65: /**
66: * Update all applications "updated at" parameter with current date on save some configurations
67: *
68: * @param Varien_Event_Observer $observer
69: */
70: public function changeUpdatedAtParamOnConfigSave($observer)
71: {
72: $configData = $observer->getEvent()->getConfigData();
73: if ($configData && (int)$configData->isValueChanged()
74: && in_array($configData->getPath(), $this->_appDependOnConfigFieldPathes)
75: ) {
76: Mage::getModel('xmlconnect/application')->updateAllAppsUpdatedAtParameter();
77: }
78: }
79:
80: /**
81: * Send a message if Start Date (Queue Date) is empty
82: *
83: * @param Varien_Event_Observer $observer
84: * @return bool
85: */
86: public function sendMessageImmediately($observer)
87: {
88: $message = $observer->getEvent()->getData('queueMessage');
89: if ($message instanceof Mage_XmlConnect_Model_Queue && (strtolower($message->getExecTime()) == 'null'
90: || !$message->getExecTime())
91: ) {
92: $message->setExecTime(Mage::getSingleton('core/date')->gmtDate());
93: Mage::helper('xmlconnect')->sendBroadcastMessage($message);
94: return true;
95: }
96:
97: return false;
98: }
99:
100: /**
101: * Send scheduled messages
102: *
103: * @return null
104: */
105: public function scheduledSend()
106: {
107: $countOfQueue = Mage::getStoreConfig(Mage_XmlConnect_Model_Queue::XML_PATH_CRON_MESSAGES_COUNT);
108:
109: $collection = Mage::getModel('xmlconnect/queue')->getCollection()->addOnlyForSendingFilter()
110: ->setPageSize($countOfQueue)->setCurPage(1)->load();
111:
112: foreach ($collection as $message) {
113: if ($message->getId()) {
114: Mage::helper('xmlconnect')->sendBroadcastMessage($message);
115: }
116: }
117: }
118: }
119: