Sunday, January 29, 2012

modx page not found after upgrade to 2.1

There is some cache issue on modx, after an upgrade from modx 2.0.x
Clearing cache does not seems to fix the issue.
One way to fix it is to edit every resources which ever are effected...


Updates:
Another way is to do a script to run recursively on all resources, edit it by changing the alias, and save,
and then changing the alias back to the actual alias, and save it again.
Example:

function doFixResource($id, $iLevel=1) {


$oRes = $modx->getObject("modResource", $id);
$aContext = array($oRes->get("context_key"));
$iParentId = $oRes->get("parent");
if (!empty($iParentId)) {
doFixResource($iParentId, $iLevel+1);
}

echo "Fixing: " . $oRes->get("id") . "(lvl:" . $iLevel . ")," . $oRes->get("alias") . "::" . $oRes->get("pagetitle") . "(" . $oRes->get("context_key") . ")
\n";
$sAlias = $oRes->get("alias");
$oRes->set("alias", $sAlias . "-". rand(10000,9999));
$oRes->save(false);
//doFlushContext($aContext);
$oRes->set("alias", $sAlias);
$oRes->save(false);
doFlushContext($aContext);

}


then run flush script:

function doFlushContext($aContext) {
global $modx;

$modx->cacheManager->refresh(array(
'db' => array(),
'auto_publish' => array('contexts' => $aContext),
'context_settings' => array('contexts' => $aContext),
'resource' => array('contexts' => $aContext),
));

}

And finally, run clear cache from manager screen.

Tips: If you want performance, cached up all the id which you have run doFixResource by using static variable, and skip it, it may save you up to more than 80% of the time :)



Friday, January 27, 2012

modx 2.2 changes

$modx->getUser("contextname")
return anonymous user if no user is logged in to the context.
when getOne("Profile") is performed on anonymous user, will return null, so some error might be thrown.

modx->db->dbfunctions is now deprecated, so use the actual function from $modx itself.
for more information, refer here:
http://rtfm.modx.com/display/revolution20/Upgrading+MODx#UpgradingMODx-VersionSpecificChanges
http://rtfm.modx.com/display/revolution20/Summary+of+Legacy+Code+Removed+in+2.1

Example of a big change:

$modx->db->query is completely different from $modx->query

So you may use parseBinding to do your query.
Example:

$sSelectSQL = "select `parent`, `context_key` , id, `alias`, pagetitle, longtitle from modx_site_content where context_key=:contextand parent=:parent and `alias`=:alias and (published=0 or deleted=1)";

$aParam = array(":context" => "web",
":parent" => 1, ":alias" => "somealias");

$sResultSelectSQL = $modx->parseBindings($sSelectSQL, $aParam);
$stmt = $modx->query($sResultSelectSQL);

if (! $stmt) throw new Exception("SQL Failed: " . $sResultSQL);

//to fetch all
$aCount = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach($aCount as $oRow) {
  echo $oRow["id"];
}
//to fetch one
$oRow = $stmt->fetch($PDO::FETCH_ASSOC);
echo $oRow["id"];


And other class based method:

//to get an object row
$oRes = $modx->getObject("modResource", array("context_key" => "web", "parent" => 1, "alias" => "somealias"));

echo $oRes->get("id");

modx 2.2 modX::isFrontEnd() is undefined?

After doing an upgrade to modx2.2, editing any resources seems to throw this error.
Solution, go to package manager, upgrade tinymce plugin.
And we are all set to go! :)

modx 2.2 upgrade from 2.0 error 500

There were seems to some configuration changes from 2.0 to 2.2 on core/config/config.inc.php.
When i was upgrading, the test database seems to response with an error 500.
After inspecting core/cache/logs/error.log, it shows "no database selected"

So i went into editing core/config/config.inc.php and found the $dbase = "{dbase}"
Using setup with advanced configuration does not seems to do the trick.
The solution now is to edit core/config/config.inc.php and set $dbase = "`mydatabasename`"
and $database_dsn = 'mysql:host=localhost;dbname=mydatabasename;charset=utf8';

Take note on the different between the 2, one with `` delimiter, and one without.
Next, rerun setup for upgrade shall do the trick :)

magento enable cookie issue on chrome and ie

I came across this problem while trying to test my localhost machine for adding a product to cart.
it turn out to be some sort of cookie session issue on magento.

changing session length nor disabling cookie checking does not seems to work.
its suppose to only happen on localhost testing machine, might work well on actual domain.

Setting up vhost and pointing using hosts file shall do the trick...

magento 1.5

Magento 1.5 doesnt allow one to addjs or addskinjs with a custom sorting order...
its because the head.phtml file is doesn't support it in getCssJsHtml() and getIncludes();

One way to solve it is to inject script directly into head.phtml, but put it into your own template folder...
copy from app/design/frontend/base/default/template/page/html/head.phtml to
app/design/frontend/[yourtemplate]/default/template/page/html/

Another thing to take note is getUrl and getSkinURL gotcha...
Example:
$this->getSkinUrl("js/java.js"); // return skin/frontend/[base_or_yourtemplate]/default/js/java.js
but
$this->getUrl("js/java.js"); // return http://yourbasepath.com/js/java.js/


Work around will be using $this->getUrl(""). "js/java.js"

Tuesday, January 17, 2012

netonboard.com sucks?

Updates 2012 jan 18:
Finally, got their attention from facebook fanpage. Talked to their support, and got my email replied.
They should check their offline chat message if its provided on their website...


-----------------------------------------------------------------
Well, i tried to be professional in judging them.
If it wasn't because the client bought the hosting with them, i might not have to face their shit.


First, they change their hosting without our notice.
Previously things which works, now doesn't work, and they claim they never change anything,


In php point of programmer view, they disable error log.
Fine, as programmer, i will use ini_set to enable it to see what went wrong.
so my surprise, it came out error 500 instead.
so defnitely it has been disabled ini_set function... wth..


Next, if you php code doesnt close with ?>, it will also come out error 500, isn't this a norm in php to have unclosed tag? its to avoid unwanted endline charactor in the end to avoid being output out.


3rd, fine, lets fill in the support form for help..
After filling in the contact form, its been 1+ weeks and no response.
Okay, lets try call their support fella, went to voice mail...
Okay, lets try again, their "live chat",
waiting for operator, waiting for operator, waiting for operator, waiting for operator,  sorry operator not available..
Their website published they hosted CIMB, wth? do you think bank will host with them with this kind of SLA? LoL, what a joke..

Thursday, January 5, 2012

Facebook App session issue after user logout or close browser

It seems that Facebook PHP SDK does not properly check if user have logged out or close the browser.
When someone closes the browser or log out of facebook, the php sdk should detect the problem and automatically destroy the session, but it doesnt seems to be the case, even when we call $fb->destroySession();

One way to effectively check for problem is to use Facebook javascript sdk by subscribing to :

----------
FB.Event.subscribe('auth.logout', function(response) {
      if (response.status=="unknown") {
        //some weird session error
        document.location.href="login.php";
        return;
      }
      doTimerReload();
    });
----------
The code effectively detect the logout with "unknown" status and redirect the user to a login screen.
Example of a login.php code:

Please <a href="javascript:">click here</a><br /> <script>

function doFBLogin() {

FB.login(function(response) {

  if (response.authResponse) {

   FB.api('/me', function(response) {

   });

  } else {

   alert("Please authorize app by refreshing to continue...");

  }

  }, {scope: 'email,user_likes'}); //additional parameter

}

</script><br /> ----------


Wednesday, January 4, 2012

Setting up zimbra centos 6 64bits

#makesure to update first
yum update
#install java first
yum install java-1.6.0
yum install netc
yum install which


#change existing httpd port other port than 80
sudo vi /etc/httpd/conf/httpd.conf
#change line: Listen 80 to Listen 8080 (any other port)


#change existing sendmail port to other than port 25
sudo vi /etc/mail/sendmail.mc
#locate line:
DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl
#change to other port than 25 / smtp
DAEMON_OPTIONS(`Port=2525,Addr=127.0.0.1, Name=MTA')dnl

#locate line:
dnl DAEMON_OPTIONS(`port=smtp,Addr=::1, Name=MTA-v6, Family=inet6')dnl
#change to other port than 25 / smtp
dnl DAEMON_OPTIONS(`port=2525,Addr=::1, Name=MTA-v6, Family=inet6')dnl
#run this to apply changes
m4 sendmail.mc > /etc/sendmail.cf

#temporary disable sudo tty requirement
su
visudo
#locate line Default requiretty and disable it with a #
#Defaults requiretty

/etc/init.d/httpd restart
/etc/init.d/sendmail restart

#double check to ensure both http / 80 and smtp / 25 is not used any longer
netstat -lp

#Go to zimbra website and download the respective package for your platform...
#if something went wrong, check the log.
#to resetup, run:
/opt/zimbra/libexec/zmsetup.pl

#when done, reboot the system
sudo reboot

#next, run netstat -lp to check if system is running
#try telnet localhost 25, telnet localhost 110 and try web browsing
#to restart the service, try:
/etc/init.d/zimbra restart

sudo -u zimbra /opt/zimbra/bin/zmcontrol status
#shows:
# mailbox                 Stopped
#check the log
tail -n 100 /opt/zimbra/log/mailbox.log
#if it shows
...Unknown table engine 'InnoDB'
#it meants that your innodb engine is not initiated , and most likely is memory issue.
#try changing innodb_buffer_pool_size to a lower value (below about 40% of your memory or vps memory)
sudo vi /opt/zimbra/conf/my.inf
#locate line innodb_buffer_pool_size
innodb_buffer_pool_size=400M
#restart zimbra mail
sudo -u zimbra /opt/zimbra/bin/mysql.server restart
sudo -u zimbra /opt/zimbra/bin/zmmailboxdctl restart

#to begin:
https://www.mydomain.com:7071
admin@mydomain.com

http://wiki.zimbra.com/wiki/Administration_Console


#If you forgotten your password, run this on server:
/opt/zimbra/bin/zmprov sp admin@mydomain.com [password]

If you get error in the admin ui with:
Message: system failure: server yourdomain.com  zimbraRemoteManagementPrivateKeyPath (/opt/zimbra/.ssh/zimbra_identity) does not exist Error code: service.FAILURE Details:soap:Receive
Try this:
http://wiki.zimbra.com/index.php?title=Mail_Queue_Monitoring

If you are facing memory heap size problem with java, try following this link:
http://www.thatsmyview.net/2010/04/17/optimizing-performance-for-vps-and-low-ram/
and also set your default heap size in java by editing ~/.bash_profile
export _JAVA_OPTIONS=-Xmx100m


#If your mail have not been deliver, try check the que by running:
sudo mailq

#if you encounter some file(1) utils missing, install it by running:
sudo yum install file

#If you are running zimbra from a openvz vps, please ensure min 3Gb of burst memory. Or it wont run properly. The problem is due to missing swap in openvz. So it will need sufficient memory to run.


#references: