Clean temporary files left by editors

打开文件进行编辑或其他操作后,有时会留下一些临时文件。按理只有非正常中止会留下临时文件,但有时即使正常退出仍在硬盘上留下一堆垃圾,可能某些编辑器有 bug。 不过,清理临时文件也不费力,找准文件名特征可以一次性删除它们。 find /var/www -name “.goutputstream-*” -exec rm -rf {} \; 据说 .goutputstream-* 是 GNOME 拷贝粘帖文件时的临时文件。 find /var/www -name “.tmp*~” -exec rm -rf {} \; .tmp*~ 是 Text Editor 编辑时的临时文件。 保持良好的习惯,不要用 root 身份去执行此类操作,执行前也要再三检查查找起始位置是否正确。

Why not use over-sized images in Magento?

为什么不要在 Magento 下使用过高像素的图片?其实这个命题跟 Magento 没有多大关系——任何网站都不要使用超过实际需要尺寸的图片。 只是 Magento 强大的图片处理机制容易让人产生惰性:如今买个相机动辄 10m pixels,拍完照一上传,只要 php.ini 允许足够大的值,Magento 也认可,但是,如果你真的这么做了,至少有这几点不良后果: Can not send large images to Google Base (now called Google Merchant Centre). 虽然 Magento 能在自己的网站上缩放图片,但显然没有为 Google Base 考虑到。若为了让 Magento 缩放图片兼容去修改 GoogleBase module,在我看来有点头痛医脚的感觉。 Cost longer time to generate images in cache. 如果整个网站最大图片也只要 600x600px,那么何必为每次清空 image cache 后等上几秒钟来一张 10 兆像素的照片缩小成 600x600px? Waste bandwidth to… Continue reading Why not use over-sized images in Magento?

A tool to synchronise Magento database between servers

我时不时需要在测试服务器上加载生产服务器的实时数据,以前都是把数据下载到本地的测试服务器后,手工键入一些命令完成数据加载,每次都要花费几分钟时间。为了避免一再“浪费”这几分钟,我今天一次性投入了几小时完成了一个 php 脚本。虽然这是为 magento 的数据迁移而写的脚本,但我写完一看,用在其他地方也是可以的。 为了安全起见,该脚本是用 php 命令行运行的,所有输出针对 terminal 美化,不是 browser。保存源码为 data_mover.php,同一目录下要有 mysqldump 得到的经 gzip 的 sql 文件,文件名以 FILENAME_PREFIX 开头,以 .sql.gz 结尾。启动时只需键入 /path/to/php -f data_mover.php 即可。 初始化 PDO 对象时,按理只需要 host=localhost,不需要 unix_socket=MYSQL_SOCKET。但奇怪的是,如果通过 apache 调用本程序(虽然不是本程序的初衷,但我希望它在浏览器下也能运行),仅指定 host=localhost 作 PDO __construct() 参数,会产生一个莫名其妙的错误: SQLSTATE[HY000] [2002] Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2) 似乎是 PDO bug。可以通过 host=127.0.0.1 或者追加… Continue reading A tool to synchronise Magento database between servers

Magento Googlecheckout module ignore free shipping shopping cart price rule

We charge a fixed shipping rate for subtotal under a certain amount, and offer free shipping to orders over this threshold. To achieve that, initially I created a shopping cart price rule in Magento promotions, and specified free shipping conditions and actions. Then I enabled Flatrate as a shipping method. This shipping method working in… Continue reading Magento Googlecheckout module ignore free shipping shopping cart price rule

How to override abstract class in Magento?

If you are googling “override abstract class in magento” to find my blog, probably you already tried Mage::getModel(‘module/model_abstract’) as it worked for instantiatable classes. The scenario when requires override an abstract class is overriding isActive() method in Mage_Shipping_Model_Carrier_Abstract. If Mage_Shipping_Model_Carrier_Abstract can be overridden, all carrier methods’ isActive logic can be changed without changing each instantiatable… Continue reading How to override abstract class in Magento?

Magento meta keywords field name inconsistent

I don’t know whether Magento did this on purpose. Both of category page and product page have a meta keywords attribute. Because meta keywords attribute of category or product belongs to EAV system, it has two entries in eav_attribute table, one for catalog_category (entity_type_id = 3) and one for catalog_product (entity_type_id = 4). However, if… Continue reading Magento meta keywords field name inconsistent

Magento code snippet

Magento provide a beautiful GUI, which let you setup or change nearly everything. However, occasionally you prefer do it with php code. Here are a collection of codes for various functionalities. I will keep editing this post to add new methods. Read if a product attribute is “Use Default Value” in a Store View: Assume… Continue reading Magento code snippet

Magento extension: Root Category As Homepage

It is my first time publish an Magento extension – Qian_Rcah. By default, Magento prevent root category from being shown at frontend, not to say use it as homepage. I do not see significant security leaks if showing root category. There are some benefits using root category as homepage: Layered navigation starts with a complete… Continue reading Magento extension: Root Category As Homepage

How can Magento generate sitemap.xml belongs to root?

今天看到 magento 目录下的 sitemap.xml 的属主和属组分别是 root:root,属性是644,而这一台的 webserver 是以 apache:apache 身份运行的,所以我觉得很奇怪: apache 怎么能建立一个 root:root 的文件? 如果这个文件不是 apache 建的,apache 怎么有权去更新它(最近更新就在今天)? 想了好一会明白过来,sitemap.xml 是 cron job 建的,crontab 这么写 */10 * * * * /usr/bin/php -f /path/to/magento/cron.php 那么 sitemap.xml 归 root:root 所有就不奇怪了。 我想这样写会好些: */10 * * * * sudo -u apache -g apache /usr/bin/php -f /path/to/magento/cron.php 2010年6月29日更新:上行命令不对,设想在 cron job 里以… Continue reading How can Magento generate sitemap.xml belongs to root?

CNVD-2010-00979

互联网是一个很容易以讹传讹的地方,这大概是人们不满意 google 的地方,要搞个知识搜索取而代之。 最近金山毒霸和360杀毒口水之争,我无意关心了一把。看到被多家网站(包括人民网)转发的金山网盾再陷新的诚信危机“漏洞门”,其中提到 5月24日,中国国家信息安全漏洞库证实金山网盾存在一个高危的内核本地提权漏洞(国家漏洞库编号:CNVD-2010-00979),并公布了该漏洞利用相关细节。同一天,国外权威漏洞机构Secunia研究并收录了金山网盾这一漏洞,同时对该漏洞进行了自己的解释和归类(SA ID:SA39916)。国内外两大权威安全机构同时证实金山网盾存在高危漏洞,把此前一直高调否认软件有漏洞的金山公司置于非常尴尬的境地。 我好奇了一下,上 cnvd 和 secunia 去查了一下,CNVD-2010-00979 和 SA ID:SA39916 讲的是多个供应商”rpc.pcnfsd”整数溢出漏洞,跟金山网盾无关,真不知道这个刹有其事的报导从何而来。 虽然CNVD-2010-00979 跟金山网盾无关,但我有感觉无风不起浪,因为这是在 cnvd 上搜索金山网盾的结果: 但实际查看被缓存的页面却什么也没有: 或许 cnvd 只把详细信息公开给了 google spider;或许这其中有太多的内幕是我们常人无法知道的……