2012-01-27 59 views
1

我正在编写一个安装配置文件,并且如果用户的max_execution_time和memory_limit值较低,我们会通知用户。据我了解Drupal有检查可能要求myprofile.install文件,所以我放在那里以下几点:在安装配置文件中添加自定义需求。 Drupal 7

 function myprofile_requirements($phase) { 
      $requirements = array(); 
      // Min required PHP execution time 
      $min_time = 60; 
      // Min required memory limit, Mb 
      $min_memory = 128; 
      // Get current value of "max_execution_time" 
      $time = ini_get('max_execution_time'); 
      // Get current value of "max_execution_time" 
      $memory = ini_get('memory_limit'); 
      // Get "raw" numeric value 
      preg_match("|\d+|", $memory, $value); 
      $severity_time = ($time < $min_time) ? REQUIREMENT_WARNING : REQUIREMENT_OK; 
      $severity_memory = ($value[0] < $min_memory) ? REQUIREMENT_WARNING : REQUIREMENT_OK; 
      $t = get_t(); 
      if ($phase == 'install') { 
      $requirements['max_execution_time'] = array(
       'title' => $t('PHP max execution time'), 
       'value' => $t('Please increase the parameter "max_execution_time" in your PHP settings . Recommended value is at least @min sec. and more (now you have @current sec.', 
     array('@min' => $min_time, '@current' => $time)), 
       'severity' => $severity_time, 
    ); 
      $requirements['memory_limit'] = array(
       'title' => $t('PHP memory limit'), 
       'value' => $t('Please increase the parameter "memory_limit" in your PHP settings . Recommended value is at least @minM and more (now you have @current', 
     array('@min' => $min_memory, '@current' => $memory)), 
       'severity' => $severity_memory, 
    ); 
    } 
    return $requirements; 
} 

它不工作 - Drupal的简单忽略上面的代码。怎么了?

回答

1

它看起来像hook_requirements()不会被调用的安装配置文件,它调用在这几个阶段:

  • 安装:正在安装的模块。
  • 更新:模块已启用并运行update.php。
  • 运行时:正在检查运行时要求并在状态报告页面上显示。

请注意,上面的install表示正在安装的模块,而不是整个安装配置文件。

+0

“请注意,上面的安装是指正在安装的模块,而不是整个安装配置文件。”但安装配置文件是一个模块。 – ymakux 2012-01-27 22:11:30