function system_confirm_db_updates_form_submit

6.x system.module system_confirm_db_updates_form_submit($form, $form_state)
4.x system.module system_confirm_db_updates_form_submit($form, $form_state)
5.x system.module system_confirm_db_updates_form_submit($form, $form_state)

Perform the actual hook_update calls here, send the user to a completed page.

_state

Parameters

unknown_type $form:

File

modules/system/system.module, line 467

Code

function system_confirm_db_updates_form_submit($form, $form_state) {


  // We need to find modules whose schema in their .info file
  // is different than what's in the database.

  $module_dirs = array();
  $module_dirs [] = array("start" => "modules", "type" => t("Core"));
  $module_dirs [] = array("start" => "custom/modules", "type" => t("Custom"));

  foreach ($module_dirs as $module_dir) {
    $start_dir = $module_dir ["start"];

    if ($dh = opendir($start_dir)) {
      while ($file = readdir($dh)) {
        if ($file == "." || $file == "..") {
          continue;
        }

        if (is_dir($start_dir . "/" . $file)) {

          // Okay, now look inside and see if there is a .info file.
          if (file_exists("$start_dir/$file/$file.info")) {
            $module = $file;
            $info_contents = file_get_contents("$start_dir/$file/$file.info");

            //fpm($info_contents);  
            // From the info_contents variable, split up and place into an array.
            $info_details_array = array();
            $lines = explode("\n", $info_contents);
            foreach ($lines as $line) {
              if (trim($line) == "") {
                continue;
              }
              $temp = explode("=", trim($line));
              $info_details_array [trim($temp [0])] = trim(substr($line, strlen($temp [0]) + 1));
            }


            $path = "$start_dir/$file";

            $res = db_query("SELECT * FROM modules WHERE path = '?' ", $path);
            $cur = db_fetch_array($res);
            $info_details_array ["enabled"] = $cur ["enabled"];

            // Does this module need to run db updates?
            if ($cur ["enabled"] == "1" && $cur ["schema"] != $info_details_array ["schema"] && $info_details_array ["schema"] != "") {
              // YES, we need to run this module's hook_update function, if it exists.

              // So, let's try to do that.              

              // If the module has a .install file, begin by including it.
              if (include_module_install($module, $path)) {

                // Include the original module file first.
                include_module($module, TRUE, $path);

                // Now, we can call hook_update, if it exists.
                if (function_exists($module . '_update')) {
                  call_user_func_array($module . '_update', array($cur ["schema"], $info_details_array ["schema"]));
                }

              }

              // Okay, update the modules table for this module, and set schema to correct version.
              $res = db_query("UPDATE modules 
                                SET `schema` = '?'
                                WHERE path = '?' LIMIT 1 ", $info_details_array ["schema"], $path);


              fp_add_message(t("The module %module has run its DB updates.", array("%module" => $module)));



            }

          }
        }
      }
    }
  }

  // Clear our cache
  fp_clear_cache();

  fp_goto("admin/completed-db-updates");
}