Created
October 3, 2011 20:25
-
-
Save anonymous/1260142 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Customerreviewimport.php | |
* CommerceExtensions @ InterSEC Solutions LLC. | |
* | |
* NOTICE OF LICENSE | |
* | |
* This source file is subject to the EULA | |
* that is bundled with this package in the file LICENSE.txt. | |
* It is also available through the world-wide-web at this URL: | |
* http://www.commerceextensions.com/LICENSE-M1.txt | |
* | |
* @category Review | |
* @package Customerreviewimport | |
* @copyright Copyright (c) 2003-2010 CommerceExtensions @ InterSEC Solutions LLC. (http://www.commerceextensions.com) | |
* @license http://www.commerceextensions.com/LICENSE-M1.txt | |
*/ | |
class Mage_Catalog_Model_Convert_Adapter_Cmspagesimport extends Mage_Eav_Model_Convert_Adapter_Entity | |
{ | |
protected $_stores; | |
protected $_rowCount; | |
/** | |
* Init stores | |
*/ | |
protected function _initStores () | |
{ | |
if (is_null($this->_stores)) { | |
$this->_stores = Mage::app()->getStores(true, true); | |
foreach ($this->_stores as $code => $store) { | |
$this->_storesIdCode[$store->getId()] = $code; | |
} | |
} | |
} | |
/** | |
* Retrieve store object by code | |
* | |
* @param string $store | |
* @return Mage_Core_Model_Store | |
*/ | |
public function getStoreByCode($store) | |
{ | |
$this->_initStores(); | |
/** | |
* In single store mode all data should be saved as default | |
*/ | |
if (Mage::app()->isSingleStoreMode()) { | |
return Mage::app()->getStore(Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID); | |
} | |
if (isset($this->_stores[$store])) { | |
return $this->_stores[$store]; | |
} | |
return false; | |
} | |
public function parse() | |
{ | |
$batchModel = Mage::getSingleton('dataflow/batch'); | |
$_rowCount = 50; | |
/* @var $batchModel Mage_Dataflow_Model_Batch */ | |
$batchImportModel = $batchModel->getBatchImportModel(); | |
$importIds = $batchImportModel->getIdCollection(); | |
foreach ($importIds as $importId) { | |
//print '<pre>'.memory_get_usage().'</pre>'; | |
$batchImportModel->load($importId); | |
$importData = $batchImportModel->getBatchData(); | |
$this->saveRow($importData); | |
} | |
} | |
/** | |
* Save Customer Review (import) | |
* | |
* @param array $importData | |
* @throws Mage_Core_Exception | |
* @return bool | |
*/ | |
public function saveRow(array $importData) | |
{ | |
$resource = Mage::getSingleton('core/resource'); | |
$prefix = Mage::getConfig()->getNode('global/resources/db/table_prefix'); | |
$write = $resource->getConnection('core_write'); | |
$read = $resource->getConnection('core_read'); | |
//CONVERT DATE TIME TO MYSQL DATE TIME | |
if(isset($importData['created_at']) && $importData['created_at'] !="") { | |
$CreatedDateTime = strtotime($importData['created_at']); | |
} else { | |
$CreatedDateTime = strtotime(date("m/d/Y, g:i a")); | |
} | |
if(isset($importData['status']) && $importData['status'] !="") { | |
if($importData['status'] == "Enabled") { | |
$isactive = "1"; | |
} else { | |
$isactive = "0"; | |
} | |
} | |
if(isset($importData['layout_update_xml']) && $importData['layout_update_xml'] !="") { | |
$layout_update_xml = "'".$importData['layout_update_xml']."'"; | |
} else { | |
$layout_update_xml = "NULL"; | |
} | |
if(isset($importData['custom_theme']) && $importData['custom_theme'] !="") { | |
$custom_theme = "'".$importData['custom_theme']."'"; | |
} else { | |
$custom_theme = "NULL"; | |
} | |
if(isset($importData['custom_root_template']) && $importData['custom_root_template'] !="") { | |
$custom_root_template = trim($importData['custom_root_template']); | |
} else { | |
$custom_root_template = ""; | |
} | |
if(isset($importData['custom_layout_update_xml']) && $importData['custom_layout_update_xml'] !="") { | |
$custom_layout_update_xml = "'".$importData['custom_layout_update_xml']."'"; | |
} else { | |
$custom_layout_update_xml = "NULL"; | |
} | |
if(isset($importData['custom_theme_from']) && $importData['custom_theme_from'] !="") { | |
$custom_theme_from = "'".$importData['custom_theme_from']."'"; | |
} else { | |
$custom_theme_from = "NULL"; | |
} | |
if(isset($importData['custom_theme_to']) && $importData['custom_theme_to'] !="") { | |
$custom_theme_to = "'".$importData['custom_theme_to']."'"; | |
} else { | |
$custom_theme_to = "NULL"; | |
} | |
if(isset($importData['page_title']) && $importData['page_title'] !="") { | |
$page_title = addslashes($importData['page_title']); | |
} else { | |
$page_title = "NULL"; | |
} | |
if($page_title == "NULL") return; | |
if(isset($importData['content']) && $importData['content'] !="") { | |
$content = addslashes($importData['content']); | |
} else { | |
$content = "NULL"; | |
} | |
if($content == "NULL") return; | |
$key = $importData['url_key']; | |
$page_exists = $write->fetchOne("Select count(*) From `".$prefix."cms_page` Where identifier = '".$key."'"); | |
if($page_exists > 0) return; | |
// INSERTS MAIN CMS PAGE DATA | |
$write->query("Insert into `".$prefix."cms_page` (title,root_template,meta_keywords,meta_description,identifier,content_heading,content,creation_time,update_time,is_active,sort_order,layout_update_xml,custom_theme,custom_root_template,custom_layout_update_xml,custom_theme_from,custom_theme_to) VALUES ('".$page_title."','".$importData['layout']."','".addslashes($importData['meta_keyword'])."','".addslashes($importData['meta_description'])."','".$importData['url_key']."','".addslashes ($importData['content_heading'])."','".addslashes($content)."','".date("Y-m-d H:i:s", $CreatedDateTime)."','".date("Y-m-d H:i:s", $CreatedDateTime)."','".$isactive."','0',".$layout_update_xml.",".$custom_theme.",'".$custom_root_template."',".$custom_layout_update_xml.",".$custom_theme_from.",".$custom_theme_to.")"); | |
$lastInsertId = $write->fetchOne('SELECT last_insert_id()'); | |
// INSERTS CMS PAGE STORE DATA | |
$delimiteddata = explode(',',$importData['storeview']); | |
foreach ($delimiteddata as $individualstoreName) { | |
$store = $this->getStoreByCode($individualstoreName); | |
/* | |
$allstores = Mage::app()->getStores(true, true); | |
foreach ($allstores as $code => $store) { | |
$storesIdCode[] = $code; | |
echo "CODE ID: " . $code; | |
} | |
*/ | |
$write->query("Insert into `".$prefix."cms_page_store` (page_id,store_id) VALUES ('".$lastInsertId."','".$store->getId()."')"); | |
} | |
//Try to add it to content hireachy | |
if($lastInsertId > 0 && isset($importData['parents']) && $importData['parents'] !="") { | |
$delimiteddata = explode(',',$importData['parents']); // 49,52 | |
//Articles = 48; | |
//BreakingNews = 49; | |
//Newsletter = 52; | |
foreach ($delimiteddata as $parent_id) { | |
$xpath = $parent_id."/".$lastInsertId; // "49/100" | |
$url = $this->GetUrlKey($parent_id, $importData['url_key']); //"articles/vitamin-k-important-for-bone-health" | |
if(isset($url) && $url !="") { | |
$exists = $write->fetchOne("Select count(*) From `".$prefix."enterprise_cms_hierarchy_node` Where request_url = '".$url."'"); | |
if($exists == 0) | |
{ | |
// Insert Into 'enterprise_cms_hierarchy_node' (parent_node_id, page_id, level, request_url, xpath) Values ('49', '100', '2', 'articles/this-is-a-test', '49/100') | |
$write->query("Insert into `".$prefix."enterprise_cms_hierarchy_node` (parent_node_id, page_id, level, sort_order, request_url, xpath) VALUES ('".$parent_id."', '".$lastInsertId."', '2', '".$_rowCount."', '".$url."', '".$xpath."')"); | |
$nodeId = $write->fetchOne('SELECT last_insert_id()'); | |
$sql = "Insert Into `".$prefix."enterprise_cms_hierarchy_metadata` (node_id,meta_first_last,meta_next_previous,meta_chapter,meta_section,meta_cs_enabled,pager_visibility,pager_frame,pager_jump,menu_visibility,menu_excluded,menu_layout,menu_brief,menu_levels_down,menu_ordered,menu_list_type )"; | |
$sql .= " Values ('".$nodeId."', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '')"; | |
$write->query($sql); | |
$_rowCount++; | |
} | |
} | |
} | |
} | |
return true; | |
} | |
public function GetUrlKey($parent, $url){ | |
if($parent == "49"){ | |
return "breaking_news_page2/".$url; | |
}elseif($parent == "52"){ | |
return "articles/".$url; //"articles/blah-blah | |
}elseif($parent == "48"){ | |
return "newsletter/".$url; | |
}elseif($parent == "995"){ | |
return "protocols_list/".$url; | |
}elseif($parent == "998"){ | |
return "tech_sheets/".$url; | |
}else{ | |
return ""; | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment