function admin_apply_draft_changes_perform_batch_operation
Search API
| 7.x admin.module | admin_apply_draft_changes_perform_batch_operation(&$batch, $ops) |
File
- modules/
admin/ admin.module, line 1704 - The administrative configurations for FlightPath.
Code
function admin_apply_draft_changes_perform_batch_operation(&$batch, $ops) {
// if this is our first time through, let's init our values.
if (!isset($batch ["results"]["total"])) {
// Our first time through. Let's start up.
$batch ["results"]["total"] = count($ops);
$batch ["results"]["current"] = 0;
$batch ["results"]["finished"] = FALSE;
// First, set maintenance mode...
variable_set("maintenance_mode", TRUE);
}
$op_command = key($ops [$batch ['results']['current']]);
$op_val = $ops [$batch ['results']['current']][$op_command];
if ($op_command == 'truncate_prod_and_copy') {
$table_name = $op_val;
$draft_table_name = "draft_$table_name";
// First, truncate existing...
$query = "truncate table `$table_name`";
$res = db_query($query);
// Now, copy in draft changes...
$query = "INSERT INTO `$table_name`
SELECT * FROM `$draft_table_name` ";
$res = db_query($query);
} // truncate prod and copy
/////////////
/////////////
if ($op_command == 'perform_draft_instructions') {
$db = get_global_database_handler();
// Now, we need to go through the draft_instructions table,
// and perform each instruction one at a time.
$res = db_query("SELECT * FROM draft_instructions
ORDER BY `id` ");
while ($cur = db_fetch_array($res))
{
$instruction = trim($cur ["instruction"]);
$temp = explode(",", $instruction);
if (trim($temp [0]) == "update_course_id") {
$db->update_course_id(trim($temp [1]), trim($temp [2]), trim($temp [3]));
}
if (trim($temp [0]) == "update_course_requirement_from_name") {
$db->update_course_requirement_from_name(trim($temp [1]), trim($temp [2]), trim($temp [3]), trim($temp [4]));
}
// TODO: Maybe invoke another hook here, to let other modules act on the instruction?
} // while
// Once this is done, truncate the draft_instructions table.
$res = db_query("TRUNCATE TABLE draft_instructions");
} // perform_draft_instructions
/////////////////
/////////////////
if ($op_command == 'invoke_apply_draft_changes') {
// Invoke a hook to allow other modules to apply_draft_changes as well
invoke_hook("apply_draft_changes");
}
///////////////
///////////////
if ($op_command == 'rebuild_cache_course_inventory') {
// Rebuild our course cache file.
unset($_SESSION ['fp_cache_course_inventory_last_generated']);
if (file_exists(fp_get_files_path() . "/cache_data/courses_serialized.info")) {
$x = unlink(fp_get_files_path() . "/cache_data/courses_serialized.info");
if (!$x) {
fpm("Cannot delete cache_data/courses_serialized.info under custom/files. Permission error or file does not exist?");
watchdog("system", "Cannot delete cache_data/courses_serialized.info under custom/files. Permission error or file does not exist?", array(), WATCHDOG_ERROR);
}
}
variable_set('cache_course_inventory_last_generated', 0); // reset this so it will be regenerated.
// Builds new courses cache file on the hard drive.
system_reload_and_cache_course_inventory();
} // rebuild cache course inventory
$batch ['results']['current'];
// Have we finished?
if (++$batch ["results"]["current"] >= $batch ["results"]["total"]) {
$batch ["results"]["finished"] = TRUE;
// Send emails to notify programmers
$notify = variable_get("notify_apply_draft_changes_email_address", "");
if ($notify != "") {
mail($notify, "FlightPath Apply Draft Changes", "Someone has applied draft changes to FlightPath, which updated degree plans, groups, and courses.");
}
fp_add_message(t("Successfully updated the production database with draft changes. Your changes are now live and visible on production for all users."));
watchdog("admin", "Draft changes applied.");
// Remove maintenance mode...
variable_set("maintenance_mode", FALSE);
}
}
