Created
February 26, 2018 10:27
-
-
Save mklooss/b57e1a3fa950f637b23e27cfe3513ab5 to your computer and use it in GitHub Desktop.
An Extension f**ked up the Database Shema
This file contains 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 | |
$store_id = 4; | |
/* | |
Becarefull this Script will remove all other data only Store ID 0 and $store_id will be keep! | |
An Extension made changes direct in the Database but, GLOBAL Attributes has been unable to edit, yay! | |
Our sample store was an Sinlge Store System, so we could copy all Data from Store View to Base. | |
*/ | |
require_once 'app/Mage.php'; | |
Mage::app('admin'); | |
$resource = Mage::getSingleton('core/resource'); | |
$conn = $resource->getConnection('core_write'); | |
$store_ids = array( | |
0, | |
$store_id | |
); | |
$tables = array( | |
'catalog_product_entity_datetime', | |
'catalog_product_entity_int', | |
'catalog_product_entity_text', | |
'catalog_product_entity_varchar' | |
); | |
foreach ($tables as $_table) | |
{ | |
$_table = $resource->getTableName($_table); | |
$conn->query('DELETE FROM '.$_table.' WHERE store_id NOT IN('.implode(',', $store_ids).');'); | |
$conn->query('DELETE FROM '.$_table.' WHERE store_id = '.$store_id.' AND value IS NULL;'); | |
$sql = 'SELECT * FROM '.$_table.' WHERE store_id = '.$store_id; | |
foreach ($conn->fetchAll($sql) as $_row) | |
{ | |
$_data = $_row; | |
if (isset($_data['value_id'])) | |
{ | |
unset($_data['value_id']); | |
} | |
$_data['store_id'] = 0; | |
$conn->insertOnDuplicate($_table, $_data, array('value')); | |
$conn->delete($_table, 'value_id = '.$_row['value_id']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment