Compare two Category CSVS (Category_Code / Category_Name )
<table>
<tr>
<th colspan="2">Redirects! Same Category Name, Different Codes.</th>
</tr>
<tr>
<th>OLD SITE</th>
<th>NEW SITE</th>
</tr>
<?PHP
function readCSV($csvFile){
$file_handle = fopen($csvFile, 'r');
while (!feof($file_handle) ) {
$line_of_text[] = fgetcsv($file_handle, 0);
}
fclose($file_handle);
return $line_of_text;
}
// Set path to CSV file
// Dev = OLD site
// live = NEW site
$devCsv = 'dev.csv';
$liveCsv = 'live-site.csv';
$live = readCSV($liveCsv);
$dev = readCSV($devCsv);
/*
foreach ( $dev as $d ) {
foreach ( $live as $l ) {
if ( $d[1] == $l[1] && $d[0] != $l[0] ) {
if (strpos($d[0], ' ')) {
echo 'Redirect 301 "/c/' . $d[0] . '.html" http://www.photodon.com/c/' . $l[0] . '.html? <br />';
} else {
echo 'Redirect 301 /c/' . $d[0] . '.html http://www.photodon.com/c/' . $l[0] . '.html? <br />';
}
}
}
}*/
foreach ( $dev as $d ) {
foreach ( $live as $l ) {
if ( $d[1] == $l[1] && $d[0] != $l[0] ) {
echo '<tr>';
echo '<td>' . $d[0] . '</td>';
echo '<td>' . $l[0] . '</td>';
echo '</tr>';
}
}
}
?>
</table>
<table>
<tr><th>Missing from LIVE store. Redirect to homepage.</th></tr>
<?PHP
function readCSV($csvFile){
$file_handle = fopen($csvFile, 'r');
while (!feof($file_handle) ) {
$line_of_text[] = fgetcsv($file_handle, 0);
}
fclose($file_handle);
return $line_of_text;
}
// Set path to CSV file
$devCsv = 'dev.csv';
$liveCsv = 'live-site.csv';
$live = readCSV($liveCsv);
$dev = readCSV($devCsv);
$alreadyWritten = array();
// Is the [old] Category name the same as the [new] category AND the [old] Category code is NOT the same as the [new] category code?
foreach ( $dev as $d ) {
foreach ( $live as $l ) {
if ( $d[1] == $l[1] && $d[0] != $l[0] ) {
array_push ( $alreadyWritten, $d[0] );
}
}
}
$liveOnes = array();
// Push all [new] Category Codes into an array
foreach ( $live as $l ) {
array_push($liveOnes, $l[0]);
}
// If [old] category code is not already rewritten AND it's not transferred over to the [new] site
// We need Redirects for these
foreach ( $dev as $d ) {
if ( !in_array($d[0], $liveOnes) && !in_array($d[0], $alreadyWritten) ) {
echo '<tr><td>' . $d[0] . '</td></tr>';
}
}
?>
</table>