summaryrefslogtreecommitdiff
path: root/modules/system/system.module
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-06-06 16:05:28 +0000
committerDries Buytaert <dries@buytaert.net>2009-06-06 16:05:28 +0000
commit1f9077ee9263a64eb62cfdb75d7a5233cb86e83c (patch)
tree951ff40932870affff95e58ae3a2af27b86f1879 /modules/system/system.module
parent36e3d552cfe211cba22d1fc8cf0a7f4b13627179 (diff)
downloadbrdo-1f9077ee9263a64eb62cfdb75d7a5233cb86e83c.tar.gz
brdo-1f9077ee9263a64eb62cfdb75d7a5233cb86e83c.tar.bz2
- Patch #147000 by Berdir: unify and rewrite module_rebuild_cache() and system_theme_data().
Diffstat (limited to 'modules/system/system.module')
-rw-r--r--modules/system/system.module225
1 files changed, 166 insertions, 59 deletions
diff --git a/modules/system/system.module b/modules/system/system.module
index 767981c82..4635a3d3f 100644
--- a/modules/system/system.module
+++ b/modules/system/system.module
@@ -1159,9 +1159,8 @@ function system_get_files_database(&$files, $type) {
foreach ($result as $file) {
if (isset($files[$file->name]) && is_object($files[$file->name])) {
$file->filepath = $file->filename;
- $file->old_filepath = $file->filepath;
foreach ($file as $key => $value) {
- if (!isset($files[$file->name]) || !isset($files[$file->name]->$key)) {
+ if (!isset($files[$file->name]->key)) {
$files[$file->name]->$key = $value;
}
}
@@ -1170,75 +1169,139 @@ function system_get_files_database(&$files, $type) {
}
/**
- * Prepare defaults for themes.
- *
- * @return
- * An array of default themes settings.
+ * Updates the records in the system table based on the files array.
+ *
+ * @param $files
+ * An array of files.
+ * @param $type
+ * The type of the files.
*/
-function system_theme_default() {
- return array(
- 'regions' => array(
- 'left' => 'Left sidebar',
- 'right' => 'Right sidebar',
- 'content' => 'Content',
- 'header' => 'Header',
- 'footer' => 'Footer',
- 'highlight' => 'Highlighted content',
- 'help' => 'Help',
- ),
- 'description' => '',
- 'features' => array(
- 'comment_user_picture',
- 'comment_user_verification',
- 'favicon',
- 'logo',
- 'name',
- 'node_user_picture',
- 'search',
- 'slogan',
- 'main_menu',
- 'secondary_menu',
- ),
- 'screenshot' => 'screenshot.png',
- 'php' => DRUPAL_MINIMUM_PHP,
- );
+function system_update_files_database(&$files, $type) {
+ $result = db_query("SELECT * FROM {system} WHERE type = :type", array(':type' => $type));
+
+ // Add all files that need to be deleted to a DatabaseCondition.
+ $delete = db_or();
+ foreach ($result as $file) {
+ if (isset($files[$file->name]) && is_object($files[$file->name])) {
+ // Keep the old filename from the database in case the file has moved.
+ $old_filename = $file->filename;
+
+ $updated_fields = array();
+
+ // Handle info specially, compare the serialized value.
+ $serialized_info = serialize($files[$file->name]->info);
+ if ($serialized_info != $file->info) {
+ $updated_fields['info'] = $serialized_info;
+ }
+ unset($file->info);
+
+ // Scan remaining fields to find only the updated values.
+ foreach ($file as $key => $value) {
+ if (isset($files[$file->name]->$key) && $files[$file->name]->$key != $value) {
+ $updated_fields[$key] = $files[$file->name]->$key;
+ }
+ }
+
+ // Update the record.
+ if (count($updated_fields)) {
+ db_update('system')
+ ->fields($updated_fields)
+ ->condition('filename', $old_filename)
+ ->execute();
+ }
+
+ // Indiciate that the file exists already.
+ $files[$file->name]->exists = TRUE;
+ }
+ else {
+ // File is not found in file system, so delete record from the system table.
+ $delete->condition('filename', $file->filename);
+ }
+ }
+
+ if (count($delete) > 0) {
+ // Delete all missing files from the system table
+ db_delete('system')
+ ->condition($delete)
+ ->execute();
+ }
+
+ // All remaining files are not in the system table, so we need to add them.
+ $query = db_insert('system')->fields(array('filename', 'name', 'type', 'owner', 'info'));
+ foreach($files as &$file) {
+ if (isset($file->exists)) {
+ unset($file->exists);
+ }
+ else {
+ $query->values(array(
+ 'filename' => $file->filepath,
+ 'name' => $file->name,
+ 'type' => $type,
+ 'owner' => isset($file->owner) ? $file->owner : '',
+ 'info' => serialize($file->info),
+ ));
+ $file->type = $type;
+ $file->status = 0;
+ $file->schema_version = -1;
+ }
+ }
+ $query->execute();
}
/**
- * Collect data about all currently available themes.
+ * Helper function to scan and collect module .info data.
*
* @return
- * Array of all available themes and their data.
+ * An associative array of module information.
*/
-function system_theme_data() {
- // Scan the installation theme .info files and their engines.
- $themes = _system_theme_data();
+function _system_get_module_data() {
+ // Find modules
+ $modules = drupal_system_listing('/\.module$/', 'modules', 'name', 0);
- // Extract current files from database.
- system_get_files_database($themes, 'theme');
+ // Set defaults for module info.
+ $defaults = array(
+ 'dependencies' => array(),
+ 'dependents' => array(),
+ 'description' => '',
+ 'version' => NULL,
+ 'php' => DRUPAL_MINIMUM_PHP,
+ );
- db_delete('system')
- ->condition('type', 'theme')
- ->execute();
+ // Read info files for each module.
+ foreach ($modules as $key => $module) {
+ // Look for the info file.
+ $module->info = drupal_parse_info_file(dirname($module->filepath) . '/' . $module->name . '.info');
- $query = db_insert('system')->fields(array('name', 'owner', 'info', 'type', 'filename', 'status'));
- foreach ($themes as $theme) {
- if (!isset($theme->owner)) {
- $theme->owner = '';
+ // Skip modules that don't provide info.
+ if (empty($module->info)) {
+ unset($modules[$key]);
+ continue;
}
- $query->values(array(
- 'name' => $theme->name,
- 'owner' => $theme->owner,
- 'info' => serialize($theme->info),
- 'type' => 'theme',
- 'filename' => $theme->filename,
- 'status' => isset($theme->status) ? $theme->status : 0,
- ));
+ // Merge in defaults and save.
+ $modules[$key]->info = $module->info + $defaults;
+
+ // Invoke hook_system_info_alter() to give installed modules a chance to
+ // modify the data in the .info files if necessary.
+ drupal_alter('system_info', $modules[$key]->info, $modules[$key]);
}
- $query->execute();
- return $themes;
+ return $modules;
+}
+
+/**
+ * Collect data about all currently available modules.
+ *
+ * @return
+ * Array of all available modules and their data.
+ */
+function system_get_module_data() {
+ $modules = _system_get_module_data();
+ ksort($modules);
+ system_get_files_database($modules, 'module');
+ system_update_files_database($modules, 'module');
+ $modules = _module_build_dependencies($modules);
+ return $modules;
}
/**
@@ -1247,7 +1310,7 @@ function system_theme_data() {
* @return
* An associative array of themes information.
*/
-function _system_theme_data() {
+function _system_get_theme_data() {
static $themes_info = array();
if (empty($themes_info)) {
@@ -1256,7 +1319,37 @@ function _system_theme_data() {
// Find theme engines
$engines = drupal_system_listing('/\.engine$/', 'themes/engines');
- $defaults = system_theme_default();
+ // Set defaults for theme info.
+ $defaults = array(
+ 'regions' => array(
+ 'left' => 'Left sidebar',
+ 'right' => 'Right sidebar',
+ 'content' => 'Content',
+ 'header' => 'Header',
+ 'footer' => 'Footer',
+ 'highlight' => 'Highlighted content',
+ 'help' => 'Help',
+ ),
+ 'description' => '',
+ 'features' => array(
+ 'comment_user_picture',
+ 'favicon',
+ 'mission',
+ 'logo',
+ 'name',
+ 'node_user_picture',
+ 'search',
+ 'slogan',
+ 'main_menu',
+ 'secondary_menu',
+ ),
+ 'stylesheets' => array(
+ 'all' => array('style.css')
+ ),
+ 'scripts' => array('script.js'),
+ 'screenshot' => 'screenshot.png',
+ 'php' => DRUPAL_MINIMUM_PHP,
+ );
$sub_themes = array();
// Read info files for each theme
@@ -1340,6 +1433,20 @@ function _system_theme_data() {
}
/**
+ * Collect data about all currently available themes.
+ *
+ * @return
+ * Array of all available themes and their data.
+ */
+function system_get_theme_data() {
+ $themes = _system_get_theme_data();
+ ksort($themes);
+ system_get_files_database($themes, 'theme');
+ system_update_files_database($themes, 'theme');
+ return $themes;
+}
+
+/**
* Recursive function to find the top level base theme. Themes can inherit
* templates and function implementations from earlier themes.
*