Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A simple little script that takes the sample data SQL file for Magento and adds a prefix to it. Make sure to run it before you install the sample data. Also maked sure to specify the same prefix on installing Magento, so your sample data will actually show in the site :) Credit for this script goes to http://ffct.cc/magento-sample-data-prefix-sc…
<?php
// your prefix here
$prefix = 'mg4Hk_';
// magento sample data file
// make sure the path to the magento sample data folder is set correctly
$sample_data_path = '../magento-sample-data-1.6.1.0/';
$dumpFile = $sample_data_path . "magento_sample_data_for_1.6.1.0.sql";
// new sample data file
$outFile = $sample_data_path . "new-sample-data.sql";
// Search and replace!
$search = array("TABLES `", "TABLE `", "EXISTS `", "INTO `", "REFERENCES `");
$replace = array("TABLES `$prefix", "TABLE `$prefix", "EXISTS `$prefix", "INTO `$prefix", "REFERENCES `$prefix");
$file = file_get_contents($dumpFile);
if ($file !== FALSE) {
$file = str_ireplace($search, $replace, $file);
if (file_put_contents($outFile,$file) !== FALSE) {
echo "Successfully written new sample data dump to $outFile.\n";
} else {
echo "Error writing new sample data dump.\n";
}
} else {
echo "Error reading dump file.\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment