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: class Mage_Adminhtml_Block_System_Convert_Profile_Run extends Mage_Adminhtml_Block_Abstract
35: {
36: 37: 38: 39:
40: protected $_batchModelPrepared = false;
41: 42: 43: 44:
45: protected $_batchModel = null;
46: 47: 48: 49:
50: protected function _prepareBatchModel()
51: {
52: if ($this->_batchModelPrepared) {
53: return $this;
54: }
55: $this->setShowFinished(true);
56: $batchModel = Mage::getSingleton('dataflow/batch');
57: $this->_batchModel = $batchModel;
58: if ($batchModel->getId()) {
59: if ($batchModel->getAdapter()) {
60: $this->setBatchModelHasAdapter(true);
61: $numberOfRecords = $this->getProfile()->getData('gui_data/import/number_of_records');
62: if (!$numberOfRecords) {
63: $batchParams = $batchModel->getParams();
64: $numberOfRecords = isset($batchParams['number_of_records']) ? $batchParams['number_of_records'] : 1;
65: }
66: $this->setNumberOfRecords($numberOfRecords);
67: $this->setShowFinished(false);
68: $batchImportModel = $batchModel->getBatchImportModel();
69: $importIds = $batchImportModel->getIdCollection();
70: $this->setBatchItemsCount(count($importIds));
71: $this->setBatchConfig(
72: array(
73: 'styles' => array(
74: 'error' => array(
75: 'icon' => Mage::getDesign()->getSkinUrl('images/error_msg_icon.gif'),
76: 'bg' => '#FDD'
77: ),
78: 'message' => array(
79: 'icon' => Mage::getDesign()->getSkinUrl('images/fam_bullet_success.gif'),
80: 'bg' => '#DDF'
81: ),
82: 'loader' => Mage::getDesign()->getSkinUrl('images/ajax-loader.gif')
83: ),
84: 'template' => '<li style="#{style}" id="#{id}">'
85: . '<img id="#{id}_img" src="#{image}" class="v-middle" style="margin-right:5px"/>'
86: . '<span id="#{id}_status" class="text">#{text}</span>'
87: . '</li>',
88: 'text' => $this->__('Processed <strong>%s%% %s/%d</strong> records', '#{percent}', '#{updated}', $this->getBatchItemsCount()),
89: 'successText' => $this->__('Imported <strong>%s</strong> records', '#{updated}')
90: )
91: );
92: $jsonIds = array_chunk($importIds, $numberOfRecords);
93: $importData = array();
94: foreach ($jsonIds as $part => $ids) {
95: $importData[] = array(
96: 'batch_id' => $batchModel->getId(),
97: 'rows[]' => $ids
98: );
99: }
100: $this->setImportData($importData);
101: } else {
102: $this->setBatchModelHasAdapter(false);
103: $batchModel->delete();
104: }
105: }
106: $this->_batchModelPrepared = true;
107: return $this;
108: }
109: 110: 111: 112:
113: protected function _getBatchModel()
114: {
115: return $this->_batchModel;
116: }
117: 118: 119: 120:
121: public function getBatchConfigJson()
122: {
123: return Mage::helper('core')->jsonEncode(
124: $this->getBatchConfig()
125: );
126: }
127: 128: 129: 130: 131:
132: public function jsonEncode($source)
133: {
134: return Mage::helper('core')->jsonEncode($source);
135: }
136: 137: 138: 139:
140: public function getProfile()
141: {
142: return Mage::registry('current_convert_profile');
143: }
144: 145: 146: 147:
148: public function getFormKey()
149: {
150: return Mage::getSingleton('core/session')->getFormKey();
151: }
152: 153: 154: 155:
156: public function getBatchModel()
157: {
158: return $this->_prepareBatchModel()
159: ->_getBatchModel();
160: }
161: 162: 163: 164:
165: public function getExceptions()
166: {
167: if (!is_null(parent::getExceptions()))
168: return parent::getExceptions();
169: $exceptions = array();
170: $this->getProfile()->run();
171: foreach ($this->getProfile()->getExceptions() as $e) {
172: switch ($e->getLevel()) {
173: case Varien_Convert_Exception::FATAL:
174: $img = 'error_msg_icon.gif';
175: $liStyle = 'background-color:#FBB; ';
176: break;
177: case Varien_Convert_Exception::ERROR:
178: $img = 'error_msg_icon.gif';
179: $liStyle = 'background-color:#FDD; ';
180: break;
181: case Varien_Convert_Exception::WARNING:
182: $img = 'fam_bullet_error.gif';
183: $liStyle = 'background-color:#FFD; ';
184: break;
185: case Varien_Convert_Exception::NOTICE:
186: $img = 'fam_bullet_success.gif';
187: $liStyle = 'background-color:#DDF; ';
188: break;
189: }
190: $exceptions[] = array(
191: "style" => $liStyle,
192: "src" => Mage::getDesign()->getSkinUrl('images/'.$img),
193: "message" => $e->getMessage(),
194: "position" => $e->getPosition()
195: );
196: }
197: parent::setExceptions($exceptions);
198: return $exceptions;
199: }
200: }
201: