Getting “An error occurred while updating object. lang ()” in PrestaShop

If you get the error message "An error occurred while updating object. lang ()" when updating a language in PrestaShop, this is caused when the system doesn’t have permissions to write in the .htaccess-file in your root directory.

If the file does not exist, just create an empty .htaccess-file and make sure it is writeable by the user running the webserver process, for example by issuing: 

chmod 666 .htaccess

Moving a PrestaShop 1.4 webshop

 When moving a PrestaShop version 1.4 webshop to a new domain name (from a development server to a live site for example) you must do the following: 

  1. Make sure all directories are writeable according to the PrestaShop installation instructions.
    Don’t forget that the files in config directory must be writeable as well as the entire cache directory structure. All files and directories in tools/smarty/compiletools/smarty/cache, tools/smarty_v2/cache and smarty_v2/compile must also be writeable.
    Internal server error 500 is a sign that these directories or files are not writeable.
  2. Update the file config/settings.php regarding PS base URI (if that will change) and the database settings.
  3. After importing the database on the new server use a tool like phpMyAdmin to access the database.
  4. Login to the Back Office of your shop on the new domain and go to Settings -> SEO & URLS and update the domain name for the shop (two fields). If this is not successful use the steps 5-7, otherwise go to step 8.
  5. Find a table named ps_configuration.
  6. Find the records PS_SHOP_DOMAIN and PS_SHOP_DOMAIN_SSL
  7. Update the values with your new domain name. You should enter just the domain name, no leading http:// or trailing path to subirectories (if your shop is located in a subdirectory, that should be entered in the PS base URI in step 1).
  8. If you use .htaccess and robots.txt files, go to Tools -> Generators and regenerate them.

 

Check if a file is open by another process in PHP (Linux/UNIX)

The PHP flock() function is good when the file locking method is used the same way by all programs that will lock the file.

However, you can’t check if any process in the system is actually using the file or not. If you for example are monitoring an incoming ftp folder, you don’t want to start processing a file until the file is completely tranferred (i.e. wait until the ftp daemon is no longer having the file open).

The following code illustrates how the command lsof can be used for the purpose: 

<?php
$filename = "locktest.txt";
$directory = ".";
while (1) {
        $result = exec("lsof +D $directory | grep -c -i $filename");
        if ($result == "0") {
                echo "$directory/$filename is NOT open ($result)\n";
        } else {
                echo "$directory/$filename IS OPEN ($result)\n";
        }
        sleep(1);
};
?>

 

Ktools PhotoStore batch image regenerate

Ktools PhotoStoreThe Ktools PhotoStore software (www.ktools.net) automatically generates thumbnails, sample and large images with watermarks of the images in the database. If you change the settings regarding the image sizes only newly added images will get the new sizes.

The following simple script regenerates / resizes the thumbnails, sample and large images from the original images. It runs in batch mode, i.e it will work on every image you have in your stock_photos folder. It will overwrite your current i_, s_ and m_-versions of your images without warning. The sizes is set in the script (it does not read the current settings in the manager).

#!/bin/sh
# ps_regenerate.sh for Ktools Photo Store - http://www.ktools.net
# Copyright 2010-12-27 HelTech Communication, Stefan Helander
# http://www.heltech.se
#
# This script may be downloaded from https://nerdia.net and used for free. It is not
# allowed to redistribute this script without written permission.
#
# Requires GraphicsMagick - gm
#
# Regenerates thumbnail, sample and large images for Ktools Photo Store.
# Copy this file to photostoreroot/stock_photos and execute it
# in that folder. If necessary adjust the sizes below.
# !!! WARNING !!! This script overwrites current m_, s_ and i_versons
# of your current images without question.
#
I_SIZE=”150″
S_SIZE=”500″
M_SIZE=”1200″
COMMAND=”gm convert”
FILES=`ls *.jpg | grep -v “^m_” | grep -v “^s_” | grep -v “^i_”`
for FILE in $FILES
do

# Make i_ image
$COMMAND -size $I_SIZE "$FILE" -resize $I_SIZE "i_$FILE"
# Make s_ image
$COMMAND -size $S_SIZE "$FILE" -resize $S_SIZE "s_$FILE"
# Make m_ image
$COMMAND -size $M_SIZE "$FILE" -resize $M_SIZE "m_$FILE"

done

PrestaShop module TECHNICAL ERROR

On a PrestaShop 1.3.2.3 installation I purchased the One Page Checkout 1.2.2 and installed it. After that I got the following error message when trying to add a product to the basket in the shop front end: TECHNICAL ERROR: unable to add the product.

Details:
Error thrown: [object XMLHttpRequest]
Text status: parserror

Solution: The reason is the web server is running in SAFE MODE and the user owning all the PrestaShop files is the FTP user I use to upload the shop. When installing the One Page Checkout module it will be owned by the user running the web server process (in my case www-data:www-data). In SAFE MODE a php script is not allowed to execute a script owned by another user. The solution is to set the owner of all the order-files in the PrestaShop directory to my FTP-user (including the files installed by the OPC module). In a shell this is simply done by the chmod command: cd prestashop-installation-dir chown -R my-user:my-group order* (Replace prestashop-installation-dir with the real path where PrestaShop is installed and my-user:my-group to the userid:grouid owning the rest of the files in the Prestashop installation.)

/tmp problem when installing plugins in WordPress

When you try to install a plugin in WordPress and get an error message like this:

Warning: file_exists() [function.file-exists]: open_basedir restriction in effect. File(/tmp//google-integration-toolkit.tmp) is not within the allowed path(s): (/var/www/XXX/) in/var/www/XXX/web/wp-includes/functions.php on line 2140

Warning: touch() [function.touch]: SAFE MODE Restriction in effect. The script whose uid is 12345 is not allowed to access /tmp owned by uid 0 in /var/www/XXX/web/wp-admin/includes/file.php on line 184

Download failed. Could not create Temporary file.

This is happening when the server is running with SAFE MODE because WordPress will not be able to access paths outside it’s web root. Find out the full path to your web root on the server (a hint is in the error message you just saw). Create a temporary directory within your website path and add the following line.

Edit wp-config.php and add:

define(‘WP_TEMP_DIR’, ‘/var/www/XXX/tmp’);

(Replace /var/www/XXX/tmp with the full path to your temporary directory.)

WordPress insert image/video/music problem caused by plugin

When writing a post in WordPress, and you press Upload/Insert buttons to insert images, video, music or other media you can run into a problem where a popup displaying “Are you sure you want to do this?” is showing instead of the normal insert screen. The problem is described here. As mentioned in the posts, it is caused by some plugin. This can be hard to guess as the plugin in question might have nothing to do with writing and posting articles.

I ran into this problem using the latest WordPress 3.0.1. The plugin that was causing trouble for me was WP-ContactForm. By disabling it, it was possible to insert images in the posts again.

If you experience this problem, try disabling all plugins. If inserting images now works, try enabling the plugins one by one to figure out which one is causing the trouble.

phplist problem with local UTF-8-characters in subject line

phplist is a popular software for sending newsletter to large lists of recievers. It has a large number of features which I will not go into depth here. For more information about what phplist can do –  visit the phplist homepage.

If you are experiencing problems when you are sending a newsletter containing local characters, like the Swedish Å, Ä and Ö in the subject line, the most probable reason is that administration web pages are rendered in a character set different from the one used in the newsletter.

The following solution is assuming that you are running phplist on a Linux host.

Read more

Pimping the laptop with a Solid State Drive

Intel Solid State diskSome week ago my laptop complained while trying to save a file that there was some error writing to the disk. I had two choices – wait until the harddisk breaks, preferably when I am overloaded with work and a deadline is coming up (that is a law of nature). Or I could buy a new disk now and replace it before disaster happens. I choose the not so adventurous way and decided to do something about it now.

I’ve been glancing at the dropping prices of Solid State Drives as they are faster than mechanical and probably lasts longer. My choice fell on the Intel X25-M 2,5″ 80 GB SSD SATA/300 MLC 34 NM from the swedish supplier called Dustin. I must mention the super quick delivery Dustin (in assistance by the swedish post) had. I ordered the device late tuesday night in their web shop. Wednesday morning around 10 i got the delivery note by mail. At 13.00 the very same the delivery guy rang my doorbell. That is impressive!

The installation was easy. Just unscrew the drive bay, uninstall the old harddisk and replace it with the SSD. Be sure not to touch the connectors of the SSD disk as it is sensetive to electric discharge. I partitioned the disk with dualboot running Ubuntu 10.04 LTS in one and Windows 7 in the other. Boot time is impressive as you can see in the videos. My laptop has a new life!

mysqldump to multiple files

It is a good idea to run mysqldump by cron to regurlarly make backups of your MySQL databases. An easy way to do this is by adding the –all-databases parameter.  This way you will have a backup of all your databases – in one file though. If the amount of data and the number of databases is small this might be ok.

After the first session of restoring just one database or one table from your one-file-backup you realize that it would be nice to have the dumps split up in some convenient way. Like dumping each database to one file, one for each database.

This little shell script does the trick for you. It is really simple and has no error handling what so ever. It is released under GNU GPLv2 license. If you modifiy it or add features (like error handling or so), please do send me a copy or post it as a comment here.


#!/bin/sh
# mysqldump-multi.sh
# Copyright HelTech Communication, Stefan Helander 2010
# stefan@heltech.se, http://www.heltech.se
#
# Licensed under GNU GPLv2
#
# Dumps all MySQL databases. Each database stored in a single file.
#
# settings

DUMPDIR=/root/mysql-backup/backups
MYSQL_HOST=localhost
MYSQL_USER=root
MYSQL_PASS=YOUR-PASSWORD-HERE
MYSQL=/usr/bin/mysql
MYSQLDUMP=/usr/bin/mysqldump

# dump each db

for DB in `echo 'show databases' | $MYSQL -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASS --batch -N`
do
$MYSQLDUMP -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASS --quote-names --create-options --force $DB > $DUMPDIR/$DB.sql
done