$schedule['name']), 'error'); } } } } /** * Get all the available backup schedules. */ function backup_migrate_get_schedules() { static $schedules = NULL; // Get the list of schedules and cache them locally. if ($schedules === NULL) { $schedules = array(); $all_schedules = module_invoke_all('backup_migrate_schedules'); // Reindex since module_invoke_all stomps on numerical indices (thanks to array_merge). foreach ($all_schedules as $schedule) { $schedules[$schedule['schedule_id']] = $schedule; } } return $schedules; } /** * Get the schedule info for the schedule with the given ID, or NULL if none exists. */ function backup_migrate_get_schedule($schedule_id) { $schedules = backup_migrate_get_schedules(); return @$schedules[$schedule_id]; } /** * Implementation of hook_backup_migrate_schedules(). * * Get the backup schedules stored in the db. */ function backup_migrate_backup_migrate_schedules() { // Get the saved scheduless $result = db_query('SELECT * FROM {backup_migrate_schedules}'); while ($schedule = db_fetch_array($result)) { $schedule['db'] = TRUE; $out[$schedule['schedule_id']] = $schedule; } return $out; } /** * Update an existing schedule or create a new one. */ function backup_migrate_schedule_save_schedule(&$schedule) { // Calculate the period in seconds $periods = _backup_migrate_frequency_periods(); $period = $periods[$schedule['period']['type']]; $schedule['period'] = $schedule['period']['number'] * $period['seconds']; if ($schedule['schedule_id']) { db_query("UPDATE {backup_migrate_schedules} SET name = '%s', destination_id = '%s', profile_id = %d, keep = %d, period = %d, enabled = %d WHERE schedule_id = %d", $schedule['name'], $schedule['destination_id'], $schedule['profile_id'], $schedule['keep'], $schedule['period'], $schedule['enabled'], $schedule['schedule_id'] ); } else { $schedule['schedule_id'] = db_next_id('{backup_migrate_schedules}_schedule_id'); db_query("INSERT INTO {backup_migrate_schedules} (schedule_id, name, destination_id, profile_id, keep, period, enabled) VALUES (%d, '%s', '%s', %d, %d, %d, %d)", $schedule['schedule_id'], $schedule['name'], $schedule['destination_id'], $schedule['profile_id'], $schedule['keep'], $schedule['period'], $schedule['enabled'] ); } } /** * Delete a saved schedule from the database. */ function backup_migrate_schedule_delete_schedule($schedule_id) { $schedule = backup_migrate_get_schedule($schedule_id); if ($schedule && $schedule['db']) { db_query("DELETE FROM {backup_migrate_schedules} WHERE schedule_id = %d", $schedule_id); _backup_migrate_message('Schedule deleted: %schedule', array('%schedule' => $schedule['name'])); } } /* UI Menu Callbacks */ /** * List the the available schedules in the UI. */ function backup_migrate_ui_schedule_display_schedules() { require_once './'. drupal_get_path('module', 'backup_migrate') .'/includes/destinations.inc'; require_once './'. drupal_get_path('module', 'backup_migrate') .'/includes/profiles.inc'; $out = array(); foreach (backup_migrate_get_schedules() as $schedule) { $destination = backup_migrate_get_destination($schedule['destination_id']); $profile = backup_migrate_get_profile($schedule['profile_id']); $row = array( check_plain($schedule['name']), $destination ? l($destination['name'], 'admin/content/backup_migrate/destination/files/'. $destination['destination_id']) : t("Missing"), $profile ? $profile['name'] : t("Missing"), _backup_migrate_schedule_format_frequency($schedule['period']), $schedule['keep'] ? $schedule['keep'] : t('All'), $schedule['enabled'] ? t('Enabled') : t('Disabled'), $schedule['last_run'] ? format_date($schedule['last_run'], 'small') : t('Never'), implode(" | ", _backup_migrate_schedule_get_links($schedule['schedule_id'])), ); if (!$schedule['enabled']) { foreach ($row as $key => $field) { $row[$key] = array('data' => $field, 'class' => 'schedule-list-disabled'); } } $out[] = $row; } $headers = array( t('Name'), t('Destination'), t('Profile'), t('Frequency'), t('Keep'), t('Enabled'), t('Last run'), t('Operations'), ); drupal_add_css(drupal_get_path('module', 'backup_migrate') .'/backup_migrate.css'); if ($out) { $out = theme("table", $headers, $out); } else { $out = t('There are no schedules to display.'); } return $out .' '. l(t("Create new schedule..."), 'admin/content/backup_migrate/schedule/add'); } /** * Get a form to create a new schedule. */ function backup_migrate_ui_schedule_create() { $schedule = array('name' => t("Untitled Schedule"), 'enabled' => 1, 'keep' => 0, 'period' => 60 * 60 * 24); $output = drupal_get_form('backup_migrate_ui_schedule_configure_form', $schedule); return $output; } /** * Get a form to configure the schedule. */ function backup_migrate_ui_schedule_configure($schedule_id) { if ($schedule = backup_migrate_get_schedule($schedule_id)) { return drupal_get_form('backup_migrate_ui_schedule_configure_form', $schedule); } return NULL; } /** * Get a form to configure the schedule. */ function backup_migrate_ui_schedule_configure_form($schedule) { if ($schedule) { require_once './'. drupal_get_path('module', 'backup_migrate') .'/includes/destinations.inc'; require_once './'. drupal_get_path('module', 'backup_migrate') .'/includes/profiles.inc'; $form = array(); $form['schedule_id'] = array( "#type" => "value", "#default_value" => $schedule['schedule_id'], ); $form['enabled'] = array( "#type" => "checkbox", "#title" => t("Enabled"), "#field_suffix" => t("Hour(s)"), "#default_value" => $schedule['enabled'], ); $form['name'] = array( "#type" => "textfield", "#title" => t("Schedule Name"), "#default_value" => $schedule['name'], ); $form['profile_id'] = array( "#type" => "select", "#title" => t("Settings Profile"), "#options" => _backup_migrate_get_profile_form_item_options(), "#default_value" => $schedule['profile_id'], ); $form['profile_id']['#description'] .= ' '. l(t("Create new profile..."), "admin/content/backup_migrate/profile/add"); if (!$form['profile_id']['#options']) { $form['profile_id']['#options'] = array('0' => t('-- None Available --')); } $period_options = array(); foreach (_backup_migrate_frequency_periods() as $type => $period) { $period_options[$type] = $period['title']; } $default_period = _backup_migrate_schedule_get_frequency_period($schedule['period']); $default_period_num = $schedule['period'] / $default_period['seconds']; $form['period'] = array( "#type" => "item", "#title" => t("Backup every"), "#prefix" => '