function admin_duplicate_year_form_submit
Search API
| 7.x admin.module | admin_duplicate_year_form_submit($form, &$form_state) |
| 6.x admin.module | admin_duplicate_year_form_submit($form, &$form_state) |
| 5.x admin.module | admin_duplicate_year_form_submit($form, &$form_state) |
This function will set up a batch operation so we can duplicate an entire year with less chance of time or memory running out.
_state
Parameters
array $form:
File
- modules/
admin/ admin.module, line 675 - The administrative configurations for FlightPath.
Code
function admin_duplicate_year_form_submit($form, &$form_state) {
$values = $form_state ["values"];
$new_year = $values ["destination_year"];
$old_year = $values ["source_year"];
// We are going to keep track of all the operations we need to do in this $ops array.
$ops = array();
$ops []['delete_new_year'] = TRUE;
// We need to break up how many courses we copy at a time, so let's query to get a count.
$count = db_result(db_query("SELECT COUNT(*) as mycount FROM draft_courses WHERE catalog_year = ? ", array($old_year)));
for ($t = 0; $t < $count; $t = $t + 150) { // 150 is how many to do on each pass.
$ops []['copy_courses'] = $t;
}
// We need to break up the groups the same way we did the courses...
$count = db_result(db_query("SELECT count(*) FROM draft_groups WHERE catalog_year = ? ", array($old_year)));
for ($t = 0; $t < $count; $t = $t + 3) { // 3 is how many to do on each pass, because groups are much more detailed.
$ops []['copy_groups'] = $t;
}
$ops []['copy_degree_tracks'] = TRUE;
// We also want to break up the degrees for the same reasons as the others.
// We need to break up the groups the same way we did the courses...
$count = db_result(db_query("SELECT count(*) FROM draft_degrees WHERE catalog_year = ? ", array($old_year)));
for ($t = 0; $t < $count; $t = $t + 15) { // 15 is how many to do on each pass.
$ops []['copy_degrees'] = $t;
}
$ops []['hook_admin_duplicate_year'] = TRUE;
// Okay, set up the batch....
$batch = array(
"operation" => array("admin_duplicate_year_perform_batch_operation", array($ops, $old_year, $new_year)),
"title" => t("Duplicate catalog year"),
"success_message" => t("Duplication from $old_year to $new_year completed successfully."),
"progress_message" => "Working on @current of @total operations. This may take some time, do not close this window/tab.",
"display_percent" => TRUE,
);
// Set the batch...
batch_set($batch);
}
