PHP5: Quick on exceptions

Very quick (&dirty):

1
2
3
4
5
6
7
8
try{
	doStuff();
}
catch (Exception $e){
	echo 'Error on line '. $e->getLine().' in '. $e->getFile() . $e->getMessage();
	//Or if you are working inside an object, you could use.
	echo 'Error on line '.$this->getLine().' in '.$this->getFile() . $e->getMessage();
}

Now to catch a specific kind of exception (in this case CustomException), and say woups, but to re-throw all other Exceptions.

1
2
3
4
5
6
7
8
9
10
11
try{
	doStuffThatCanGiveCustomException();
}
catch (Exception $e){
	//echo get_class($e) . "<br/>";
	if (get_class($e) == "CustomException" && $e->getMessage() === "My custom exception message."){
		echo "woups";
	}
	else
		throw $e;
}

To throw a custom exception:

 throw new Exception('My exception message');

For more informaion about this please check out the php manual

ubuntu: what version is installed?

The quick way is to run “lsb_release -a”

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 9.10
Release:        9.10
Codename:       karmic

Or just read the info from /etc/lsb-release

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=9.10
DISTRIB_CODENAME=karmic
DISTRIB_DESCRIPTION="Ubuntu 9.10"

It is also possible to check the file “/etc/issue”

$ cat /etc/issue
Ubuntu 9.10 \n \l

From X check out System->about.

Magento – using etc/system.xml to controll a modules visibility in the admin interface

In the admin interface it is possible to alter setting on a “default”, “website” or “store” level.
Whether or not the module is visible [and configurable] in these is controlled by the modules config file (most commonly saved as “etc/system.xml”)

There are some lines that looks like:

<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>

The variables are fairly self explanatory; 0 is don’t show, 1 is show [I have also seen 2 but I haven’t figured that one out yet]

Magento admin, make it possible to enter DIBS login information on a per store basis

If you are using the DIBS module from MagentoConnect it is possible to set up DIBS accounts as default configuration (all sites & stores) and website (and all stores under that).

If you would like to be able to set up one DIBS account per store, then you should edit the app/code/local/Mage/Dibs/etc/system.xml
Find the lines that look like

                        <active translate="label">
                            <label>Enabled</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                            <sort_order>1</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>

and alter them to

                        <active translate="label">
                            <label>Enabled</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                            <sort_order>1</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>

This should be done in several locations (this is controlled for each option in the plugin so make sure you edit it for all the options you wish to alter on a store level).

Send mail to several to-addresses

To send email to several recipients use

name <name@example.com>, name2 <name2@example.com>

the part inside the brackes (< & >) is the adress, the part before the < is the name shown as the recipient. The separation char for several addresses is “,”

Magento: Sending the info in the contact form to several email addresses

By default Magento only has one filed to input the recipient of the contact form (in admin).
If you would like to get this sent to several email addresses then a small hack is required as Magento adds some encding to address in this field.

Use

mail@example1.com>, name <mail@example2.com

to send to two recipients. name is the name shown as the address in the second mail.

Send contact form to two mail addressesv

To send to 3 addresses use

mail@example1.com>, name <mail@example2.com>,name2<mail@example3.com

To sent to 4 or more, just add more as in the 3 addresses example

Forcing a fsck at next reboot

Sometimes you wish to make fsck run at the next time (after the computer is powered up/rebooted).
This can be achieved by

Passing F to shutdown

By passing the option “F” to shutdown it will force a file system check at the next boot up.

shutdown -rF now

By creating a /forcefsck file

If the file “/forcefsck” exists then a fsck is forced at boot up.

touch /forcefsck

Turning off auto fsck at boot time

A Linux machine will auto check the file system if the last shutdown was unclean (the system was powered off before the file system was unmounted) or if it has passed to much time since the last check.

This can be turned off in a few ways, here are some.

[never check] From /etc/fstab

If the sixth option is not 0 (or missing) then fsck will do automatic checking, so change the sixth option to a 0.
As root edit the /etc/fstab (use your favorite text editor or vi).

/dev/sda1		/home/files			ext3	defaults	0 0

[never check] By passing arguments via GRUB

It is possible to pass the option fastboot to the kernel at boot time, this will also prevent fsck from running at boot time.
Edit /boot/grub/menu.lst (use your favorite text editor or vi) [might also be called /etc/grub.conf]
So an example of this would look like

title           Debian GNU/Linux, kernel 2.6.26-1-686
root            (hd0,0)
kernel          /vmlinuz-2.6.26-1-686 root=/dev/mapper/root-root--volume ro fastboot
initrd          /initrd.img-2.6.26-1-686

[only skip once] By passing options to shutdown

If you only wish to bypass the automatic testing of the file system once, but keep the automatic settings saved you can use the shutdown command with the option “f”.
For instance to reboot without checking

shutdown -rf now