Skip to content

Instantly share code, notes, and snippets.

@joostvanveen
Last active December 19, 2015 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save joostvanveen/5984679 to your computer and use it in GitHub Desktop.
Save joostvanveen/5984679 to your computer and use it in GitHub Desktop.
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