Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save veganista/2653289 to your computer and use it in GitHub Desktop.
Save veganista/2653289 to your computer and use it in GitHub Desktop.
A quick hack to destroy all sample data in an OpenCart catalog.
<?php
$options = getopt('p:');
$prefix = empty($options['p'])
? realpath('.')
: realpath($options['p']);
if (empty($prefix)) {
die("Bad prefix. Try again.\n");
}
require $prefix . '/admin/config.php';
require $prefix . '/system/database/' . DB_DRIVER . '.php';
require $prefix . '/system/library/db.php';
$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
$tables = array(
'address',
'affiliate',
'affiliate_transaction',
'attribute',
'attribute_description',
'attribute_group',
'attribute_group_description',
'category',
'category_description',
'category_to_store',
'coupon',
'coupon_history',
'coupon_product',
'customer',
'customer_ip',
'customer_ip_blacklist',
'customer_reward',
'download',
'download_description',
'manufacturer',
'manufacturer_to_store',
'option',
'option_description',
'option_value',
'option_value_description',
'order',
'order_fraud',
'order_history',
'order_option',
'order_product',
'order_total',
'order_voucher',
'product',
'product_attribute',
'product_description',
'product_discount',
'product_image',
'product_option',
'product_description',
'product_option_value',
'product_related',
'product_reward',
'product_special',
'product_tag',
'product_to_category',
'product_to_download',
'product_to_layout',
'product_to_store',
'return',
'return_history',
'review',
'store',
'voucher',
'voucher_history'
);
foreach ($tables as $table) {
$sql = sprintf('TRUNCATE TABLE %s%s', DB_PREFIX, $table);
printf('%s %s ', $sql, str_repeat('.', 73 - strlen($sql)));
$db->query($sql);
echo "Done!\n";
}
//no clear the cache
$files = glob(DIR_CACHE . 'cache.*.*');
if ($files) {
foreach ($files as $file) {
if (file_exists($file)) {
unlink($file);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment