7 system.module system_update_files_database(&$files, $type)

Updates the records in the system table based on the files array.


$files: An array of files.

$type: The type of the files.

2 calls to system_update_files_database()
system_rebuild_module_data in modules/system/system.module
Rebuild, save, and return data about all currently available modules.
system_rebuild_theme_data in modules/system/system.module
Rebuild, save, and return data about all currently available themes.


modules/system/system.module, line 2243
Configuration system that lets administrators modify the workings of the site.


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;

      // 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)) {
          ->condition('filename', $old_filename)

      // Indicate 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, but only if the plugin
    // has never been installed.
      ->condition('schema_version', -1)

  // 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)) {
    else {
        'filename' => $file->uri,
        '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;

  // If any module or theme was moved to a new location, we need to reset the
  // system_list() cache or we will continue to load the old copy, look for
  // schema updates in the wrong place, etc.


This function should not auto delete modules from the system table if it can not find them. This causes major issue if you happen to move module or a symlink gets broken. There is no way to restore the enabled modules unless you have db backup.