About how to clone a Prestashop instance

Lately, I’ve been helping my neighbor with his Prestashop website. I’ve learned a few tricks, like editing the overall appearance of the site, making and restoring backups in a limited environment, but my best invention has been cloning the Prestashop instance to have a test version where I can try things out without fear of breaking anything. Here’s the code for anyone who might find it useful, licensed under GPL 3.

You can see the code here, too: https://gist.github.com/axelei/dafd305213ed1b2655545f06edfbc905

# Programa para clonar prestashop
# Copyright Krusher 2015 - Licenciado bajo GPL3

paramfile="httpdocs/app/config/parameters.php"
extractDatabaseName="s/.*'database_name' => '\(.*\)'.*/\1/p"
extractDatabaseUser="s/.*'database_user' => '\(.*\)'.*/\1/p"
extractDatabasePassword="s/.*'database_password' => '\(.*\)'.*/\1/p"

if [ "$#" -lt 4 ]; then
  echo "Error: Se requieren 3 argumentos."
  echo "Uso: $0 dir_web_original dir_web_destino url_original url_destino"
  exit 1
fi

echo Traspasando de $1 a $2 \(urls: $3 -- $4 \)

databaseName=$(sed -n "$extractDatabaseName" $1/app/config/parameters.php)
databaseUser=$(sed -n "$extractDatabaseUser" $1/app/config/parameters.php)
databasePassword=$(sed -n "$extractDatabasePassword" $1/app/config/parameters.php)

echo Datos de la base de datos de origen: $databaseName / $databaseUser / $databasePassword

targetName=$(sed -n "$extractDatabaseName" $2/app/config/parameters.php)
targetUser=$(sed -n "$extractDatabaseUser" $2/app/config/parameters.php)
targetPassword=$(sed -n "$extractDatabasePassword" $2/app/config/parameters.php)

echo Datos de la base de datos de destino: $targetName / $targetUser / $targetPassword

if [[ -z "$databaseName" ]] || [[ -z "$databaseUser" ]] || [[ -z "$databasePassword" ]] || [[ -z "$targetName" ]] || [[ -z "$targetUser" ]] || [[ -z "$targetPassword" ]]; then
  echo "Error: Algunas de las variables no han sido extraídas, comprueba los errores y los directorios."
  exit 1
fi

echo URL de la instancia origen: $3
echo URL de la instancia destino: $4

read -p "Pulsa enter para continuar o CTRL+C para cancelar"
echo  "Procediendo con el traspaso."

echo Extrayendo base de datos
rm -f temp.sql
mysqldump -u $databaseUser $databaseName -p$databasePassword > temp.sql
echo Borrando base de datos objetivo
mysql -u $targetUser $targetName -p$targetPassword -e "drop database $targetName; create database $targetName"
echo Insertando la base de datos origen en la objetivo
mysql -u $targetUser -D $targetName -p$targetPassword < temp.sql
rm -f temp.sql

echo borra ficheros contenido antiguo
rm -Rf $2/*
echo copia ficheros
cp -r $1/* $2/

echo Configurando base de datos objetivo con los datos originales

sed -i "s/'database_name' => '\(.*\)'/'database_name' => '$targetName'/g" $2/app/config/parameters.php
sed -i "s/'database_user' => '\(.*\)'/'database_user' => '$targetUser'/g" $2/app/config/parameters.php
sed -i "s/'database_password' => '\(.*\)'/'database_password' => '$targetPassword'/g" $2/app/config/parameters.php

echo Configurando la nueva URL en la instancia destino

mysql -u $targetUser $targetName -p$targetPassword -e "update prstshp_configuration set value = '$4' where NAME IN ('PS_SHOP_DOMAIN', 'PS_SHOP_DOMAIN_SSL')"
mysql -u $targetUser $targetName -p$targetPassword -e "UPDATE prstshp_shop_url SET domain = '$4', domain_ssl = '$4' WHERE id_shop_url = 1;"
sed -i s/\\^$3\$/^$4$/g $2/.htaccess

echo Terminado.

The implementation could undoubtedly be improved—using a more suitable language or more advanced tools—but this is the solution I came up with given the constraints of an environment lacking many essential utilities and commands. If you found it helpful, feel free to share your experience in the comments.

The golden age of sound cards

Not all computers were created equal. Some were made for education, others for gaming, and IBM PC was designed for business. In 1981, the 5150 was introduced, the first model of what would become the ubiquitous architecture that we have all used. Its sound capabilities were mostly harmless.

However, over time, these computers swept everything aside. During their peak, Macintosh computers were a minority, and both the Amiga and Atari ST faded away. How did they fare in terms of sound to compete with them? It was the era of sound cards for PCs and compatibles.

Continue reading “The golden age of sound cards”

The most important computers in history

We often come across articles about famous computers and lists that include some very beautiful ones, those that sold well, or simply ones that the author likes a lot. Today, I want to present a list of those I consider most important from a technical innovation standpoint, the ones that truly advanced the industry with new features that set them apart from the rest.

It’s also true that a commercial success can lead to significant advancements, dragging others along, or simply have the merit of bringing them to the masses. Let’s take a look.

Continue reading “The most important computers in history”

Graphics cards of the IBM era

Not all computers were created equal. Some were born to educate, others for playing and in the case of the IBM PC it was for business. This has been already discussed in my famous article about golden age of sound cards. This time we will focus in the graphical aspect of the ancient and ubiquitous computer of the Big Blue. CGA, EGA, VGA… does it ring a bell to you?

Unlike contemporary home computers, PC architecture didn’t use an integrated graphics chipset, it would use expansion cards to undertake graphical tasks. This –along with its philosophy of a more-or-less open architecture– would result in many solutions coming into existence along its lifetime. I’ve devoured quite a lot of old computer magazine pages and thus my impressions.

Continue reading “Graphics cards of the IBM era”

Sound chips that shaped video games

Sound is present since videogames are such. From little beeps to the complex, positional digital audio system nowadays. Sound effects and music in the digital entertainment have come a long way, and so the necessary hardware has.

Among the electronic circuits that have made possible the sound aspect of the digital world there are really notable ones. Because the melodies they have been written for, the impact in the gaming (or general) culture, its capacities or simply because the leap they meant. As the dumb lists enthusiast I am, here is a list of some which, in my judgement, are the most interesting and deserve to be remembered.

Continue reading “Sound chips that shaped video games”

Taking Sim City 2000 into pieces

SimCity 2000 (Maxis, 1993) is one of my superfavourite games, ever. I’ve been playing it for 20 years and it’s partially responsible of my terrible grades at high school. I have always liked modifying games, but so far I haven’t been serious about decoding the data files of this city simulator. And I have found some quite interesting things!

There were ports in a great number of platforms, from the Macintosh (the original) to GameBoy Advance, but my favourite is MS-DOS, and it’s what this article is about. There are two interesting files: the executable (SC2000.EXE) and the data file (SC2000.DAT). Unfortunately, Windows version didn’t came out in Spanish (my mother language), and Network Edition version works awfully bad (and it is available only in English). Continue reading “Taking Sim City 2000 into pieces”

JSF converter for SelectOneMenu

The main JSF feature (or, at least, the one I like the most) is the ease to link controller bean attributes to xhtml view. However there’s an inherent important limitation: in the HTTP standard keys and values always will be strings, because they are sent that way. Of course you could serialize an object to base64, but a barbaric thing like that should be avoided in almost any circumstance.

Then how can we link a HTTP control to an object? For that, JSF provides converters. Well, it will allow you to program them, of course. Neither PrimeFaces, my library of choice, includes these converters. Thus, I’ve programmed a simple one for SelectOneMenu, the dropdown menus in the like of a combobox. I’ll leave it here for my own reference, and for anyone that could use it.

Continue reading “JSF converter for SelectOneMenu”

State of the Art: mémoires

At this stage is needless to say that Amiga is one of the most loved architectures by its fans, or that its multimedia capabilities made its demoscene one of the most important. One of the most long-remembered productions is, of course, State of the Art, by the group Spaceballs, from 1992.

Technology behind this demo is not groundbreaking. It is true that the use of rotoscope made it very interesting, but for the rest it could go unnoticed. It was however very bold regarding one thing: it was one of the first demos that used mainstream techno themes. For first time you could show it to a person not from demoscene circles (those nerds with their computers!) and exclaim: “That’s dope, dude!”

Continue reading “State of the Art: mémoires”