Drupal 如何理解';运行时';你的要求是什么?
我在上面的路径中看到了一些代码部分。我不理解这里“运行时”的含义。答案是在网站运行的那一刻吗?或者每一个迷你们来处理下面的代码Drupal 如何理解';运行时';你的要求是什么?,drupal,drupal-8,Drupal,Drupal 8,我在上面的路径中看到了一些代码部分。我不理解这里“运行时”的含义。答案是在网站运行的那一刻吗?或者每一个迷你们来处理下面的代码 /docroot/modules/contrib/ultimate_cron/ultimate_cron.install /** *实现hook_需求()。 */ 功能最终需求(阶段){ $requirements=array(); 交换机($相位){ 案例“运行时”: $requirements['cron_jobs']['title']='Ultimate cro
/docroot/modules/contrib/ultimate_cron/ultimate_cron.install
/**
*实现hook_需求()。
*/
功能最终需求(阶段){
$requirements=array();
交换机($相位){
案例“运行时”:
$requirements['cron_jobs']['title']='Ultimate cron';
$requirements['cron_jobs']['severity']=需求正常;
//检查是否有工作落后。
$jobs\u behind=0;
$jobs=CronJob::loadMultiple();
foreach($jobs作为$job){
如果($job->isBehindSchedule()){
$jobs_落后于++;
}
}
如果($jobs\u落后){
$requirements['cron_jobs']['severity']=REQUIREMENT_警告;
$requirements['cron\u jobs']['value']=\Drupal::translation()->formatPlural(
$jobs_落后,
“@count作业落后于计划”,
“@count作业落后于计划”
);
$requirements['cron_jobs']['description']=[
“#markup'=>t('某些作业落后于计划。请检查是否正常运行。”[
':system.cron\u url'=>url::fromRoute('system.cron',['key'=>\Drupal::state()->get('system.cron\u key'))->toString()
])
];
}
否则{
$requirements['cron_jobs']['value']=t('cron运行正常');
}
}
返回所需的美元;
}
直接取自。阅读他们的更多信息
功能要求
检查安装要求并进行状态报告。这个钩子有三个密切相关的用途,由$phase参数决定:
- 检查安装要求($phase=='install')
- 检查更新要求($phase=='update')
- 状态报告($phase=='runtime')
/admin/reports/Status
)时,将执行“运行时代码”($phase==“运行时”
)
参考资料:
我的意思是什么时候执行运行时代码,而不是参数解释。这就是为什么我引用了文档页面OK,非常感谢。你同意Kien Nguyen的apinion吗?也就是说,如果我不访问状态报告页面,代码将不会执行?据我所知,是的
/**
* Implements hook_requirements().
*/
function ultimate_cron_requirements($phase) {
$requirements = array();
switch ($phase) {
case 'runtime':
$requirements['cron_jobs']['title'] = 'Ultimate Cron';
$requirements['cron_jobs']['severity'] = REQUIREMENT_OK;
// Check if any jobs are behind.
$jobs_behind = 0;
$jobs = CronJob::loadMultiple();
foreach ($jobs as $job) {
if ($job->isBehindSchedule()) {
$jobs_behind++;
}
}
if ($jobs_behind) {
$requirements['cron_jobs']['severity'] = REQUIREMENT_WARNING;
$requirements['cron_jobs']['value'] = \Drupal::translation()->formatPlural(
$jobs_behind,
'@count job is behind schedule',
'@count jobs are behind schedule'
);
$requirements['cron_jobs']['description'] = [
'#markup' => t('Some jobs are behind their schedule. Please check if <a href=":system_cron_url">Cron</a> is running properly.', [
':system_cron_url' => Url::fromRoute('system.cron', ['key' => \Drupal::state()->get('system.cron_key')])->toString()
])
];
}
else {
$requirements['cron_jobs']['value'] = t('Cron is running properly.');
}
}
return $requirements;
}