About jontas

I like to make things that people find useful.

Magento: Admin login redrecting to old url after a url change (even though the database was updated)

If you have the problem that you have moved a magento database (and perhaps files to) from one server to another, you have update
web/unsecure/base_url & web/secure/base_url in the database to point at the new address, but the admin panel login is still redirecting to the old address, then the solution is fairly simple.

Make the var folder writable to the web server and clear out the var/session and var/cache folders.

MySQL creating a database and user from the console

Here is how to quickly create a database and add a user to a mysql database (the mysql console).
(Yes some values need to be changed)

  • mysql> use mysql;
  • mysql> CREATE DATABASE dbname;
  • mysql> INSERT INTO user (Host,User,Password) VALUES (‘localhost’, ‘username’, PASSWORD(‘password’));
  • mysql> GRANT ALL ON dbname.* TO ‘username’;
  • mysql> FLUSH PRIVILEGES;
  • mysql> exit

Update: This approch will not work when using MySQL server under Windows.

ubuntu: Upgrade release version

  1. Check out “/etc/update-manager/release-upgrades” to make check out what sort of releases you wish to use (lts/normal/or never upgrade)
    # default behavior for the release upgrader
    #
     
    [DEFAULT]
    # default prompting behavior, valid options:
    #  never  - never prompt for a new distribution version
    #  normal - prompt if a new version of the distribution is available
    #  lts    - prompt only if a LTS version of the distribution is available
    Prompt=normal
  2. Make sure the (current) dist is up to date. Problems are not guaranteed if you don’t – but they are likely
    • apt-get update
    • apt-get upgrade
  3. Make sure the upgrade tool is installed (and up to date) “apt-get install update-manager-core”
  4. do-release-upgrade
  5. Follow the instructions

Magento: Enabling Template/Block Hints in the Admin Panel

If you would like to turn on Template hits and block names in the admin panel this can be quickly done via the database.

INSERT INTO core_config_data (scope, scope_id, path, VALUE)
VALUES ('default', 0, 'dev/debug/template_hints', 1),
('default', 0, 'dev/debug/template_hints_blocks', 1);

Note, don’t forget to add your prefix if you are using one.

To turn this off once you are done, either delete these rows from the database, or set the values to 0. (If you set them to 0 you can later reactivate this by just swapping it back to 1, but the insert statement won’t work any more.

Magento deleting test orders (clearing orderhistory)

Just ran into the case that I needed to clear the order history of a magento installation (basically we had made fake orders when we were testing and wanted the statistics to be correct when we started for real).

Executing the following in the database solved this issue (warning if you are using a database prefix, don’t forget to update this script before executing)

SET FOREIGN_KEY_CHECKS=0;
 
-- reset orders 
TRUNCATE `sales_order`;
TRUNCATE `sales_order_datetime`;
TRUNCATE `sales_order_decimal`;
TRUNCATE `sales_order_entity`;
TRUNCATE `sales_order_entity_datetime`;
TRUNCATE `sales_order_entity_decimal`;
TRUNCATE `sales_order_entity_int`;
TRUNCATE `sales_order_entity_text`;
TRUNCATE `sales_order_entity_varchar`;
TRUNCATE `sales_order_int`;
TRUNCATE `sales_order_text`;
TRUNCATE `sales_order_varchar`;
TRUNCATE `sales_flat_quote`;
TRUNCATE `sales_flat_quote_address`;
TRUNCATE `sales_flat_quote_address_item`;
TRUNCATE `sales_flat_quote_item`;
TRUNCATE `sales_flat_quote_item_option`;
TRUNCATE `sales_flat_order_item`;
TRUNCATE `sendfriend_log`;
TRUNCATE `tag`;
TRUNCATE `tag_relation`;
TRUNCATE `tag_summary`;
TRUNCATE `wishlist`;
TRUNCATE `log_quote`;
TRUNCATE `report_event`;
TRUNCATE `sales_order_tax`;
TRUNCATE `sales_flat_quote_shipping_rate`;
TRUNCATE `sales_flat_quote_payment`;
 
ALTER TABLE `sales_order` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_datetime` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_decimal` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_int` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_text` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_varchar` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item_option` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_item` AUTO_INCREMENT=1;
ALTER TABLE `sendfriend_log` AUTO_INCREMENT=1;
ALTER TABLE `tag` AUTO_INCREMENT=1;
ALTER TABLE `tag_relation` AUTO_INCREMENT=1;
ALTER TABLE `tag_summary` AUTO_INCREMENT=1;
ALTER TABLE `wishlist` AUTO_INCREMENT=1;
ALTER TABLE `log_quote` AUTO_INCREMENT=1;
ALTER TABLE `report_event` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_tax` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_shipping_rate` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_payment` AUTO_INCREMENT=1;
 
-- reset customers
TRUNCATE `customer_address_entity`;
TRUNCATE `customer_address_entity_datetime`;
TRUNCATE `customer_address_entity_decimal`;
TRUNCATE `customer_address_entity_int`;
TRUNCATE `customer_address_entity_text`;
TRUNCATE `customer_address_entity_varchar`;
TRUNCATE `customer_entity`;
TRUNCATE `customer_entity_datetime`;
TRUNCATE `customer_entity_decimal`;
TRUNCATE `customer_entity_int`;
TRUNCATE `customer_entity_text`;
TRUNCATE `customer_entity_varchar`;
TRUNCATE `log_customer`;
TRUNCATE `log_visitor`;
TRUNCATE `log_visitor_info`;
 
ALTER TABLE `customer_address_entity` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `log_customer` AUTO_INCREMENT=1;
ALTER TABLE `log_visitor` AUTO_INCREMENT=1;
ALTER TABLE `log_visitor_info` AUTO_INCREMENT=1;
 
-- Reset all ID counters
TRUNCATE `eav_entity_store`;
ALTER TABLE  `eav_entity_store` AUTO_INCREMENT=1;
 
 
-- Clear logs
TRUNCATE `log_url_info`;
TRUNCATE `log_url`;
 
ALTER TABLE `log_url_info` AUTO_INCREMENT=1;
ALTER TABLE `log_url` AUTO_INCREMENT=1;
 
SET FOREIGN_KEY_CHECKS=1;

This is mostly based on a very nice post by the guys at inchoo

And it should go without saying, make a backup before trying this out.
(was tested on 1.3.2.4)

exim4 deleting a mail from the qeue

To delete one message from the exim queue

exim -Mrm message-id

To find the ids of all qued mails

mailq

If you wish to delete all the messages to a specific email recipient.

exiqgrep -i -r '<mail@example.com>' | xargs exim -Mrm

Of if you wish to delete all messages that were sent from a specific email address.

exiqgrep -i -f '<mail@example.com>' | xargs exim -Mrm

Turning off password saving (on a form)

If you have a form that you do not wish to use autocompletion for (either you want to disable password auto completion “for real”, or perhaps you have a form where the saved credentials are filled in where they shouldn’t be) then a quick tip to achieve this is to set ‘ autocomplete=”off” ‘ on the form.

<form id="loginForm" action="login.php" method="post" autocomplete="off">