Tag Archive: Drupal

I have developed based on Drupal stack for more than 4 years. In my opinion:

  • The learning curve of Drupal is higher than other stacks, since It’s flexibility. 
  • Server environment in China is very poor. Drupal can works well at least installed in VPS.
  • The requirement is very simple in China, you can just install something like DZ forum or DEDE cms to accomplish the goal. Since the feature requirement is not comes from business requirement, they just want a simple web page to display there company profile etc.
  • Lots of teams want to build there own framework. (I disagree with this idea, it is wasting resource and time.)
  • The traffic of the website in China almost 100x larger than EU or US, but the value of the traffic is very low. So you need do more performance optimization for the Drupal site in China.
  • Most developers in China works on a Windows PC. So no drush, varnish, memcache, cron, etc.
  • Lots of developers installed Drupal and thought that Drupal is a blog :)

长期维护生产环境的数据库,恐怕很多人会犯这样的错误:

update tableA set field1value = VVVV (where …);

忘记了加括号中的约束条件,等反应过来,Shell 中显示已经更新了几万条数据。

如何挽救这样的失误呢?

  1. 每天进行数据备份,我们的方案是每天 dump 整库,保存在 S3 中,服务器上只保存昨天的数据
  2. 假如有前一天的备份数据,可以选择性恢复除了今天以外的数据。Shell 中命令行失误往往被损坏的数据都涉及一张表的一个字段或者几个字段。
  3. Drupal 中可以利用其支持多库的特性,新建一个旧数据的库,从旧数据库中读取数据,覆盖到新库上。以下是恢复数据的脚本例子

假如不是 Drupal 系统,也可以直接用 PHP 连接2个数据库,进行类似操作。

Drupal Views PHP Code Validator

Views is one of the best module of Drupal. It provide a way to map the data in the mysql database to the web interface. You can do that even without writing any SQL query, just some clicks. I do not want to cover all the aspet of Views, but only to show how to restrict the Veiws result based on Arguments.

Arguments are parts of URL, may be a node id in /node/xxxx, or user id in /user/xxxx. Views provide some build-in arguments: See Views arguments. You can restrict the views by Node type, User ID, Term ID, etc. But these build-in features can not meet all of our requirement.

So we can use PHP Code Validator.

For example, I want to show the view only in the node where a CCK field eqs 1. And only show in the content type blog.

$nid = $argument;
$node = node_load($nid);
return ($node->type == ‘blog’ && $node->field_Myfield_type[0]['value'] == 1);

Put the php code block in the views argument, then you will find the result.