Drupal如何更新注册表?
Drupal的注册表是指registry和registry_file两个数据表。前一个表保存所有可用的类和接口以及它们所对应的文件,后一个表保存每个文件的hash码。
1. 将所有需要更新的文件都汇总的$files数组:
// 需要更新的文件有两部分:一是系统includes目录下所有的.inc文件,二是模块描述文件中通过files属性声明的文件。
$files = array();
$modules = db_query("SELECT * FROM {system} WHERE type = 'module'")->fetchAll();
foreach ($modules as &$module) {
$module->info = unserialize($module->info);
$dir = dirname($module->filename);
$module->dir = $dir;
if ($module->status) {
foreach ($module->info['files'] as $file) {
$files["$dir/$file"] = array('module' => $module->name, 'weight' => $module->weight);
}
}
}
foreach (file_scan_directory('includes', '/\.inc$/') as $filename => $file) {
$files["$filename"] = array('module' => '', 'weight' => 0);
}
2. 更新$files数组的hash属性:
foreach (db_query("SELECT * FROM {registry_file}")->fetchAllAssoc('filename', PDO::FETCH_ASSOC)
as $filename => $file) {
// Add the hash for those files we have already parsed.
if (isset($files[$filename])) {
$files[$filename]['hash'] = $file['hash'];
}
else {
// Flush the registry of resources in files that are no longer on disc
// or are in files that no installed modules require to be parsed.
db_delete('registry')
->condition('filename', $filename)
->execute();
db_delete('registry_file')
->condition('filename', $filename)
->execute();
}
}
3. 更新registry和registry_file表:
$parsed_files = array(); // 重新计算每个文件的Hash码
foreach ($files as $filename => $file) {
if (file_exists($filename)) {
$hash = hash_file('sha256', $filename);
if (empty($file['hash']) || $file['hash'] != $hash) {
$file['hash'] = $hash;
$parsed_files[$filename] = $file;
}
}
} foreach ($parsed_files as $filename => $file) {
// 搜索文件中的类和接口
if (preg_match_all('/^\s*(?:abstract|final)?\s*(class|interface)\s+([a-zA-Z0-9_]+)/m',
file_get_contents($filename), $matches)) {
foreach ($matches[2] as $key => $name) {
// 将类和接口名称更新到registry表
db_merge('registry')
->key(array(
'name' => $name,
'type' => $matches[1][$key],
))
->fields(array(
'filename' => $filename,
'module' => $module,
'weight' => $weight,
))
->execute();
}
// Delete any resources for this file where the name is not in the list
// we just merged in.
db_delete('registry')
->condition('filename', $filename)
->condition('name', $matches[2], 'NOT IN')
->execute();
} // 更新registry_file表
db_merge('registry_file')
->key(array('filename' => $filename))
->fields(array(
'hash' => $file['hash'],
))
->execute();
}
所以,模块安装时,让Drupal自动更新注册表的关键是要在.info文件中注明files属性。例如,comment模块的.info文件就是这样写的:
name = Comment
description = Allows users to comment on and discuss published content.
package = Core
version = VERSION
core = 7.x
dependencies[] = text
files[] = comment.module
files[] = comment.test
configure = admin/content/comment
stylesheets[all][] = comment.css
Drupal如何更新注册表?的更多相关文章
- c++ 操作注册表
1. 注册表简介 注册表是为Windows NT和Windows95中所有32位硬件/驱动和32位应用程序设计的数据文件,用于存储系统和应用程序的设置信息.16位驱动在Winnt (Win ...
- C++注册表操作
数据结构 注册表由键(或称"项").子键(子项)和值项构成.一个键就是分支中的一个文件夹,而子键就是这个文件夹中的子文件夹,子键同样是一个键.一个值项则是一个键的当前定义,由名称. ...
- 注册表(regedit)
注册表(Registry,繁体中文版Windows称之为登录档)是Microsoft Windows中的一个重要的数据库,用于存储系统和应用程序的设置信息. 打开方式:1.开始>>运行.中 ...
- 注册表操作(VC_Win32)
注册表操作(VC_Win32) 数据类型 注册表的数据类型主要有以下四种:显示类型(在编辑器中) 数据类型 说明 REG_SZ 字符串 文本字符串REG_MULTI_SZ 多字符串 ...
- windows下注册表的操作
原博:https://blog.csdn.net/denghubu/article/details/5765921 1. 注册表简介 注册表是为Windows NT和Windows95中所 ...
- 病毒注册表常用目标Svchost和Explorer
Windows系统的Svchost.exe和Explorer.exe两种进程,作为Windows系统中两种重要的进程,下面我们就来看看他们的特点以及在各个操作系统中的应用. Explorer.exe ...
- C++写注册表
1. 注册表简介 注册表是为Windows NT和Windows95中所有32位硬件/驱动和32位应用程序设计的数据文件,用于存储系统和应用程序的设置信息.16位驱动在Winnt (Win ...
- 【转】Win7注册表的使用(更新中)
一.注册表的存储结构和数据类型 1.基本概念: Windows 7的注册表主要由“键”和“键值”构成,称HKEY为根键(RootKey),SubKey为子键. 键(Key):“位于左侧窗格如同文件夹图 ...
- C#综合揭秘——通过修改注册表建立Windows自定义协议
引言 本文主要介绍注册表的概念与其相关根项的功能,以及浏览器如何通过连接调用自定义协议并与客户端进行数据通信.文中讲及如何通过C#程序.手动修改.安装项目等不同方式对注册表进行修改.其中通过安装项目对 ...
随机推荐
- IDL---ENVI
ENVI;启动envi file=envi_pickfile();选择文件dialog,返回值就为file ENVI_OPEN_FIle,file,r_fid=fid;根据文件名打开file,并且返回 ...
- oracle记录解锁
oracle 怎样查一个表中的记录是否被锁住了 怎么查询一个数据库中有几个表引用了其中某个特定表的主键做为其外键的select t.table_name from user_constraints ...
- CentOS单用户模式下修改ROOT密码和grub加密
Linux 系统处于正常状态时,服务器主机开机(或重新启动)后,能够由系统引导器程序自动引导 Linux 系统启动到多用户模式,并提供正常的网络服务.如果系统管理员需要进行系统维护或系统出现启动异常时 ...
- Android 广播(内部类)
1.广播定义在一个单独的文件中 源码: public class MessageReceiver extends BroadcastReceiver{ @Override public void on ...
- lib-qqwry v1.0 发布 nodejs解析纯真IP库(qqwry.dat)
lib-qqwry是当初学习node时用来练手的一个模块,用来解析纯真IP库的 现在发一个v1.0版本弥补我当时稚嫩的代码. 意外收获是,整理代码后发现,相比v0.x版本 急速模式下的效率提升大概20 ...
- android 开发如何做内存优化
不少人认为JAVA程序,因为有垃圾回收机制,应该没有内存泄露.其实如果我 们一个程序中,已经不再使用某个对象,但是因为仍然有引用指向它,垃圾回收器就无法回收它,当然该对象占用的内存就无法被使用,这就造 ...
- Machine Learning for hackers读书笔记(九)MDS:可视化地研究参议员相似性
library('foreign') library('ggplot2') data.dir <- file.path('G:\\dataguru\\ML_for_Hackers\\ML_for ...
- R语言randomForest包实现随机森林——iris数据集和kyphosis数据集
library(randomForest)model.forest<-randomForest(Species~.,data=iris)pre.forest<-predict(model. ...
- Linux ARM kernel Makefile and Kconfig
kernel build:顶层Makefile:-->1. include build/main.mk -->2. include build/kernel.mk k ...
- PHP学习笔记03——函数
<!DOCTYPE unspecified PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www. ...