Tag Archives: cvs

Importing My Magento Theme into CVS (Concurrent Versions System)


I’m pretty much just adapting/ copying an old internal wiki entry out here. I’ve used CVS for years and years, but only once in a great while do I add whole new directories of source code. More typically, I’m simply adding a module or 2, so “cvs add” does the trick. So here it goes, so future me and current you have a quick and dirty reference going forward.

Importing Directories into CVS

If the directory in which your source code resides has never been in CVS at all, you’ll need to import it. Here I’m importing my new Magento theme into my repository.

cd /magento/app/design/frontend/MXWestInterface/MXWestTheme
cvs import -m "Imported sources" magento/app/design/frontend/MXWestInterface/MXWestTheme MAGENTO_1_3_2_1 MXWEST_1

Notice that I don’t have a leading / in my import command.

I don’t have any use (yet? ever?) for vendorTag (MAGENTO_1_3_2_1) or releaseTag (MXWEST_1) in my context, but CVS requires them – they must be present. For details about what they mean, click here for the CVS documentation.

Checking your Source Back Out

To work with the newly imported files, you’ll need to checkout the files you just imported. If you want a working copy in the same directory from which you just imported, you’ll need to (re)move the existing files first. I strongly recommend a backup!

cd /magento/app/design/frontend/MXWestInterface
tar cvf ~/myBackup.tar ./MXWestTheme # back me up to a tar bundle
rm -rf ./MXWestTheme # remove existing files
cvs co -d ./MXWestTheme magento/app/design/frontend/MXWestInterface/MXWestTheme # checkout a working copy

The -d specifies the destination directory. Otherwise you’ll end up with a lot of sub sub sub directories!

Convert csv to xls (excel) in php

Luckily for me, Ingatius Teo has done all of the heavy lifting, I just had to add a little code around it. Here’s the excel.php class: http://www.phpclasses.org/browse/package/1919.html

When faced with legacy systems, it’s nearly inevitable you’ll come across csv files. In fact, when you’re moving data from anywhere to anywhere, you’re likely to run into csv files.

The challenge I faced here was providing a list of new incoming customers on a daily basis, so that their data could be reviewed in a simpler manner – a spreadsheet to check that fields such as customer classification and email address were being filled in appropriately.

The code shown here is really simple. You include the excel.php class; by including that file you register a stream wrapper for protocol xlsfile – that’s the last thing the excel.php does.

After that, it’s all you. In this working example below, I am running the php program from a command line. Argument 1 is the input file, a tab separated csv file, and argument 2 is the xls file to be written. The code expects the first row to be column headings.

First, we read the first row to set the column headers. Then we reach each line and form an associative array that will be an element of the Big Array ($xlsArray) that contains the data that will become the xls file.

Finally, we write the Big Array, and *poof* we’re done!

/* Get the excel.php class here: http://www.phpclasses.org/browse/package/1919.html */
if( empty($inputFile) || empty($xlsFile) ) {
    die("Usage: ". basename($argv[0]) . " in.csv out.xls\n" );
$fh = fopen( $inputFile, "r" );
if( !is_resource($fh) ) {
    die("Error opening $inputFile\n" );
/* Assuming that first line is column headings */
if( ($columns = fgetcsv($fh, 1024, "\t")) == false ) {
    print( "Error, couldn't get header row\n" );
$numColumns = count($columns);
/* Now read each of the rows, and construct a
    big Array that holds the data to be Excel-ified: */
$xlsArray = array();
$xlsArray[] = $columns;
while( ($rows = fgetcsv($fh, 1024, "\t")) != FALSE ) {
    $rowArray = array();
    for( $i=0; $i<$numColumns;$i++ ) {
        $key = $columns[$i];
        $val = $rows[$i];
        $rowArray["$key"] = $val;
    $xlsArray[] = $rowArray;
/* Now let the excel class work its magic. excel.php
    has registered a stream wrapper for "xlsfile:/"
    and that's what triggers its 'magic': */
$xlsFile = "xlsfile://".$xlsFile;
$fOut = fopen( $xlsFile, "wb" );
if( !is_resource($fOut) ) {
    die( "Error opening $xlsFile\n" );
fwrite($fOut, serialize($xlsArray));