/** * Insert data (Step 2) * * @param Pimgento_Core_Model_Task $task * * @return bool * @throws Exception */ public function insertData($task) { $file = $task->getFile(); $lines = $this->getRequest()->insertDataFromFile($this->getCode(), $file); if (!$lines) { $task->error(Mage::helper('pimgento_variant')->__('No data to insert, verify the file is not empty or CSV configuration is correct')); } $task->setMessage(Mage::helper('pimgento_variant')->__('%s lines found', $lines)); return true; }
/** * Init default Group (Step 5) * * @param Pimgento_Core_Model_Task $task * * @return bool */ public function initDefaultGroup($task) { $resource = $this->getResource(); $adapter = $this->getAdapter(); $family = $adapter->select()->from($this->getTable(), array('entity_id')); $query = $adapter->query($family); $count = 0; while ($row = $query->fetch()) { $exist = $adapter->fetchOne($adapter->select()->from($resource->getTable('eav/attribute_group'), array($this->_zde(1)))->where('attribute_set_id = ?', $row['entity_id'])->limit(1)); if (!$exist) { $set = Mage::getModel('eav/entity_attribute_set')->load($row['entity_id']); if ($set->hasData()) { $set->initFromSkeleton(4)->save(); $count++; } } } $task->setMessage(Mage::helper('pimgento_attribute')->__('%s family(ies) initialized', $count)); return true; }
/** * Download Images (Step 6) * * @param Pimgento_Core_Model_Task $task * * @return bool */ public function downloadImages($task) { $adapter = $this->getAdapter(); $ftp = null; try { $connexion = Mage::getStoreConfig('pimdata/asset/connexion'); if ($connexion == 'ftp') { /* @var $ftp Varien_Io_Ftp */ $ftp = new Varien_Io_Ftp(); $config = array('host' => Mage::getStoreConfig('pimdata/asset/host'), 'user' => Mage::getStoreConfig('pimdata/asset/user'), 'password' => Mage::getStoreConfig('pimdata/asset/password')); if (Mage::getStoreConfig('pimdata/asset/directory')) { $config['path'] = Mage::getStoreConfig('pimdata/asset/directory'); } if (Mage::getStoreConfig('pimdata/asset/passive')) { $config['passive'] = true; } $ftp->open($config); } else { if ($connexion == 'sftp') { /* @var $ftp Varien_Io_Sftp */ $ftp = new Varien_Io_Sftp(); $config = array('host' => Mage::getStoreConfig('pimdata/asset/host'), 'username' => Mage::getStoreConfig('pimdata/asset/user'), 'password' => Mage::getStoreConfig('pimdata/asset/password')); $ftp->open($config); if (Mage::getStoreConfig('pimdata/asset/directory')) { $ftp->cd(Mage::getStoreConfig('pimdata/asset/directory')); } } else { $task->error(Mage::helper('pimgento_asset')->__('Connexion type %s is not authorised', $connexion)); } } if ($ftp) { $select = $adapter->select()->from($adapter->getTableName('pimgento_asset'), array('file', 'image')); $query = $adapter->query($select); $directory = Mage::helper('pimgento_asset')->getBaseMediaPath(); while ($row = $query->fetch()) { $dir = dirname($directory . $row['image']); if (!is_dir($dir)) { mkdir($dir, 0777, true); } $ftp->read($row['file'], $directory . $row['image']); } $ftp->close(); } } catch (Exception $e) { $task->error(Mage::helper('pimgento_asset')->__($e->getMessage())); } return true; }
/** * Reindex (Step 18) * * @param Pimgento_Core_Model_Task $task * * @return bool */ public function reindex($task) { if (!$this->getConfig('reindex')) { $task->setMessage(Mage::helper('pimgento_product')->__('Reindex is disabled')); return false; } /* @var $indexer Mage_Index_Model_Indexer */ $indexer = Mage::getSingleton('index/indexer'); Mage::dispatchEvent('shell_reindex_init_process'); if ($this->isEnterprise()) { $processes = array('catalog_product_flat', 'cataloginventory_stock', 'catalog_product_price', 'catalog_url_product', 'url_redirect', 'catalog_category_product', 'catalogsearch_fulltext', 'catalog_product_attribute'); } else { $processes = array('catalog_product_attribute', 'catalog_product_flat', 'catalog_product_price', 'catalog_url', 'catalog_category_product', 'catalogsearch_fulltext', 'cataloginventory_stock'); } foreach ($processes as $code) { $process = $indexer->getProcessByCode($code); if ($process) { $process->reindexEverything(); Mage::dispatchEvent($code . '_shell_reindex_after'); } } Mage::dispatchEvent('shell_reindex_finalize_process'); return true; }
/** * Check required columns * * @param array $columns * @param Pimgento_Core_Model_Task $task * * @return bool */ protected function columnsRequired($columns, $task) { foreach ($columns as $column) { if (!$this->columnExists($column)) { $task->setMessage(Mage::helper('pimgento_product')->__('Column %s not found, step ignored', $column)); return false; } } return true; }
/** * Reindex (Step 8) * * @param Pimgento_Core_Model_Task $task * * @return bool */ public function reindex($task) { if (!$this->getConfig('reindex')) { $task->setMessage(Mage::helper('pimgento_position')->__('Reindex is disabled')); return false; } /* @var $indexer Mage_Index_Model_Indexer */ $indexer = Mage::getSingleton('index/indexer'); Mage::dispatchEvent('shell_reindex_init_process'); $processes = array('catalog_category_product'); foreach ($processes as $code) { $process = $indexer->getProcessByCode($code); if ($process) { $process->reindexEverything(); Mage::dispatchEvent($code . '_shell_reindex_after'); } } Mage::dispatchEvent('shell_reindex_finalize_process'); return true; }
/** * Flush catalog image cache (Step 8) * * @param Pimgento_Core_Model_Task $task * * @return bool */ public function cleanImage($task) { if (!Mage::getStoreConfig('pimdata/image/cache')) { $task->setMessage(Mage::helper('pimgento_image')->__('Cache flushing is disabled')); return false; } Mage::getModel('catalog/product_image')->clearCache(); Mage::dispatchEvent('clean_catalog_images_cache_after'); return true; }