Thursday, May 31, 2012

MySQL lock table and subqueries

MySQL complaints when a subqueries table / alias is not locked.
But Even if we lock the table by tablename, it will still complaint on the subquery table being not locked.


select n.node_id,
    (select count(*) from node where node_aboveid=n.node_nextleftnodeid) as leftnextcnt,
    (select count(*) from node where node_aboveid=n.node_nextrightnodeid) as rightnextcnt,
    n.node_nextleftnodeid, n.node_nextleftdepth from
    node n

To solve this issue,
Every sub select table must have a alias name, different from the main table name.

select n.node_id,
    (select count(*) from node nleft where node_aboveid=n.node_nextleftnodeid) as leftnextcnt,
    (select count(*) from node nright where node_aboveid=n.node_nextrightnodeid) as rightnextcnt,
    n.node_nextleftnodeid, n.node_nextleftdepth from
    node n

And makesure to lock tables node write, node n write, node nleft write, node nright write;

Tuesday, May 29, 2012

Magento deleting an order

It have been some argument about able to cancel or delete a processed or shipped or completed order.
But by end of the day, there are reasons that people want to delete the order.
Be it by mistake, or due to testing the order.

I finally found a extension which works with magento 1.6.2, but it does not cover properly for 1.6.2.

So i ended up altering the module block to support it.

But due to the nature of the reporting in magento, its not possible to delete the cached reports in the database using this extension.
It can only be deleted based on date, but becareful with this procedures.
The reporting tables for sales order are:

Please note that i do not responsible for any data lost in the extension. So do the original developer himself. Please remember to backup your database in system > tools > backup before applying this extension and deleting any order.

Thursday, May 17, 2012

infinite loop in bootstrap module

It seems that if you want to develop a bootstrap for module,
you will need to extends Zend_Application_Module_Bootstrap

But how to get Layout from bootstrap_bootstrap?

How to get view?

What if i get undefined getView of a undefined object?
Yes, this problem is because layout and view bootstrap is not loaded in Zend_Application_Bootstrap_Bootstrap.

Makesure to run these in the class which extends bootstrap_bootstrap:

Wednesday, May 16, 2012

tail cannot watch no space left

Ive been encountering this problem when i tried to tail a file using -f...
The problem is caused by inode watch limit. I suspect its due to the dropbox that ive installed.

To fix it, set fs.inotify.max_user_watches configuration to higher:
sudo sysctl -w fs.inotify.max_user_watches=16384

Tuesday, May 15, 2012

Zend DB Select join

Example of joining table using dbtable (EntStudio_Db_Table_Abstract)

$maintable = "x";

$query = $dbtable->select();
$query->from($dbtable, array("*")); //only specify column for main table

$query->join(array("u" => "table2"),  $maintable . "", array("username")); //only specify column for table2

to output to test:
echo $query;

to get results:

$resultSet = $dbtable->fetchAll($query);
$entries   = array();
foreach ($resultSet as $row) {
//... codes here

to get a single row:
$row = $dbtable->fetchRow($query);

Zend Notification

Zend built in notification are divided into session saved message, and current message.
$flashmsg = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger');

To get last added message in previous request (which is saved in the session):
$aMsg = $flashmsg->getMessages();

To clear the messages storage:
To get current added message (same request):

$aMsg = $flashmsg->getCurrentMessages();

To clear the current messages storage:

Please note that the current and the session message are separated, and need to be called respectively to retrieve all messages in the notification

zend view render vs layout render

To render another view file within the same controller,
$view / $this->render("filename.phtml");

to render a view file within layout:
$view / $this->layout()->render("filename"); //without .phtml

Monday, May 14, 2012

jquery(document).ready not running

Latest jQuery seems to halt all event execution when it comes to error.
If one of the javascript contains error, other event will not be triggering.
Its one of the gotcha that i stumbled upon since jQuery 1.6