You are here

function workbench_scheduler_save_schedule in Workbench Scheduler 7

Same name and namespace in other branches
  1. 7.2 workbench_scheduler.module \workbench_scheduler_save_schedule()

Inserts/updates a schedule.

Parameters

string $name: The machine name of the schedule.

array $schedule_data: An array of other schedule data.

Return value

bool boolean TRUE/FALSE if the insert/update was a success

2 calls to workbench_scheduler_save_schedule()
workbench_scheduler_admin_edit_schedule_submit in ./workbench_scheduler.admin.inc
Submit function for adding/editing a schedule.
workbench_scheduler_features_rebuild in ./workbench_scheduler.features.inc
Implements COMPONENT_features_rebuild().

File

./workbench_scheduler.module, line 1027
Content scheduling for Workbench.

Code

function workbench_scheduler_save_schedule($name, $schedule_data) {

  // Need to have the label, start_state and end_state.
  if (isset($schedule_data['label']) && isset($schedule_data['start_state']) && isset($schedule_data['end_state'])) {

    // Run a merge query to insert or update the row.
    $merge = db_merge('workbench_scheduler_schedules')
      ->key(array(
      'name' => $name,
    ))
      ->fields(array(
      'label' => trim($schedule_data['label']),
      'start_state' => trim($schedule_data['start_state']),
      'end_state' => trim($schedule_data['end_state']),
    ))
      ->execute();
    if ($merge) {

      // Core schedule data was updated, need to update types?
      if (isset($schedule_data['types'])) {

        // Delete the old types set.
        db_delete('workbench_scheduler_types')
          ->condition('name', $name)
          ->execute();

        // Build insert query for new types.
        $insert_query = db_insert('workbench_scheduler_types')
          ->fields(array(
          'name',
          'type',
        ));
        foreach ($schedule_data['types'] as $content_type) {
          $insert_query
            ->values(array(
            'name' => $name,
            'type' => $content_type,
          ));
        }
        $insert_query
          ->execute();
      }

      // Reset the statics.
      drupal_static_reset('workbench_scheduler_load_schedules');
      drupal_static_reset('workbench_scheduler_load_type_schedules');
      return $merge;
    }
  }

  // Return boolean FALSE if missing fields or failed query.
  return FALSE;
}