1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27:
28: 29: 30: 31: 32: 33: 34:
35: class Mage_Core_Model_Observer
36: {
37: 38: 39: 40: 41: 42:
43: public function addSynchronizeNotification(Varien_Event_Observer $observer)
44: {
45: $adminSession = Mage::getSingleton('admin/session');
46: if (!$adminSession->hasSyncProcessStopWatch()) {
47: $flag = Mage::getSingleton('core/file_storage')->getSyncFlag();
48: $state = $flag->getState();
49: if ($state == Mage_Core_Model_File_Storage_Flag::STATE_RUNNING) {
50: $syncProcessStopWatch = true;
51: } else {
52: $syncProcessStopWatch = false;
53: }
54:
55: $adminSession->setSyncProcessStopWatch($syncProcessStopWatch);
56: }
57: $adminSession->setSyncProcessStopWatch(false);
58:
59: if (!$adminSession->getSyncProcessStopWatch()) {
60: if (!isset($flag)) {
61: $flag = Mage::getSingleton('core/file_storage')->getSyncFlag();
62: }
63:
64: $state = $flag->getState();
65: if ($state == Mage_Core_Model_File_Storage_Flag::STATE_FINISHED) {
66: $flagData = $flag->getFlagData();
67: if (isset($flagData['has_errors']) && $flagData['has_errors']) {
68: $severity = Mage_AdminNotification_Model_Inbox::SEVERITY_MAJOR;
69: $title = Mage::helper('adminhtml')->__('An error has occured while syncronizing media storages.');
70: $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.');
71: } else {
72: $severity = Mage_AdminNotification_Model_Inbox::SEVERITY_NOTICE;
73: $title = Mage::helper('adminhtml')->__('Media storages synchronization has completed!');
74: $description = Mage::helper('adminhtml')->__('Synchronization of media storages has been successfully completed.');
75: }
76:
77: $date = date('Y-m-d H:i:s');
78: Mage::getModel('adminnotification/inbox')->parse(array(
79: array(
80: 'severity' => $severity,
81: 'date_added' => $date,
82: 'title' => $title,
83: 'description' => $description,
84: 'url' => '',
85: 'internal' => true
86: )
87: ));
88:
89: $flag->setState(Mage_Core_Model_File_Storage_Flag::STATE_NOTIFIED)->save();
90: }
91:
92: $adminSession->setSyncProcessStopWatch(false);
93: }
94:
95: return $this;
96: }
97:
98: 99: 100: 101: 102:
103: public function cleanCache(Mage_Cron_Model_Schedule $schedule)
104: {
105: Mage::app()->getCache()->clean(Zend_Cache::CLEANING_MODE_OLD);
106: Mage::dispatchEvent('core_clean_cache');
107: }
108: }
109: