You are here

function workbench_scheduler_delete_schedules in Workbench Scheduler 7

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

Delete schedule(s) add associated data from the database.

Parameters

mixed $names: Machine name(s) of schedule(s) to be deleted.

Return value

bool True or false is successful.

1 call to workbench_scheduler_delete_schedules()
workbench_scheduler_admin_delete_schedule_submit in ./workbench_scheduler.admin.inc
Submit function for deleting a schedule.

File

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

Code

function workbench_scheduler_delete_schedules($names) {

  // If was not passed an array of machine names.
  if (!is_array($names)) {

    // Make machine name an array with one element.
    $names = array(
      $names,
    );
  }

  // Get all sid's for the schedules going to be delete.
  $sids_query = db_select('workbench_scheduler_schedules', 'wss')
    ->fields('wss', array(
    'sid',
  ))
    ->condition('wss.name', $names, 'IN')
    ->execute();
  $sids = array();
  if ($sids_query
    ->rowCount()) {
    foreach ($sids_query as $sid) {
      $sids[] = $sid->sid;
    }
  }

  // Schedules nodes to delete?
  if (count($sids) > 0) {

    // Delete all nodes for these schedules.
    db_delete('workbench_scheduler_nodes')
      ->condition('sid', $sids, 'IN')
      ->execute();
  }

  // Delete all types associated to these schedules.
  db_delete('workbench_scheduler_types')
    ->condition('name', $names, 'IN')
    ->execute();

  // Delete the schedules themselves.
  db_delete('workbench_scheduler_schedules')
    ->condition('name', $names, 'IN')
    ->execute();

  // Check to see if machine name still exists as validation.
  if (_workbench_schedule_check_machine_name_exists($names)) {

    // Failed to delete, return false.
    return FALSE;
  }
  else {

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