1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Admin forms for scheduling.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Schedule page with a view for the scheduled tasks.
|
10 |
|
|
*/
|
11 |
|
|
function rules_scheduler_schedule_page() {
|
12 |
|
|
// Display view for all scheduled tasks
|
13 |
|
|
if (module_exists('views')) {
|
14 |
|
|
// We cannot use views_embed_view() here as we need to set the path for the
|
15 |
|
|
// component filter form.
|
16 |
|
|
$view = views_get_view('rules_scheduler');
|
17 |
|
|
$view->override_path = RULES_SCHEDULER_PATH;
|
18 |
|
|
$task_list = $view->preview();
|
19 |
|
|
}
|
20 |
|
|
else {
|
21 |
|
|
$task_list = t('To display scheduled tasks you have to install the <a href="http://drupal.org/project/views">Views</a> module.');
|
22 |
|
|
}
|
23 |
|
|
$page['task_view'] = array(
|
24 |
|
|
'#markup' => $task_list,
|
25 |
|
|
);
|
26 |
|
|
$form = drupal_get_form('rules_scheduler_form');
|
27 |
|
|
$page['delete'] = array(
|
28 |
|
|
'#markup' => drupal_render($form),
|
29 |
|
|
);
|
30 |
|
|
return $page;
|
31 |
|
|
}
|
32 |
|
|
|
33 |
|
|
/**
|
34 |
|
|
* Form for deletion of tasks by component.
|
35 |
|
|
*/
|
36 |
|
|
function rules_scheduler_form($form, &$form_state) {
|
37 |
|
|
$result = db_select('rules_scheduler', 'r')
|
38 |
|
|
->fields('r', array('config'))
|
39 |
|
|
->distinct()
|
40 |
|
|
->execute();
|
41 |
|
|
$config_options = array_intersect_key(rules_get_components(TRUE), $result->fetchAllAssoc('config'));
|
42 |
|
|
|
43 |
|
|
// Fieldset for canceling by component name.
|
44 |
|
|
$form['delete_by_config'] = array(
|
45 |
|
|
'#type' => 'fieldset',
|
46 |
|
|
'#title' => t('Delete tasks by component name'),
|
47 |
|
|
'#disabled' => empty($config_options)
|
48 |
|
|
);
|
49 |
|
|
$form['delete_by_config']['config'] = array(
|
50 |
|
|
'#title' => t('Component'),
|
51 |
|
|
'#type' => 'select',
|
52 |
|
|
'#options' => $config_options,
|
53 |
|
|
'#description' => t('Select the component for which to delete all scheduled tasks.'),
|
54 |
|
|
'#required' => TRUE,
|
55 |
|
|
);
|
56 |
|
|
$form['delete_by_config']['submit'] = array(
|
57 |
|
|
'#type' => 'submit',
|
58 |
|
|
'#value' => t('Delete tasks'),
|
59 |
|
|
'#submit' => array('rules_scheduler_form_delete_by_config_submit'),
|
60 |
|
|
);
|
61 |
|
|
return $form;
|
62 |
|
|
}
|
63 |
|
|
|
64 |
|
|
/**
|
65 |
|
|
* Submit handler for deleting future scheduled tasks.
|
66 |
|
|
*/
|
67 |
|
|
function rules_scheduler_form_delete_by_config_submit($form, &$form_state) {
|
68 |
|
|
$config = rules_config_load($form_state['values']['config']);
|
69 |
|
|
rules_action('schedule_delete')->execute($config->name);
|
70 |
|
|
drupal_set_message(t('All scheduled tasks associated with %config have been deleted.', array('%config' => $config->label())));
|
71 |
|
|
$form_state['redirect'] = RULES_SCHEDULER_PATH;
|
72 |
|
|
}
|
73 |
|
|
|
74 |
|
|
/**
|
75 |
|
|
* Confirmation form for deleting single tasks.
|
76 |
|
|
*/
|
77 |
|
|
function rules_scheduler_delete_task($form, &$form_state, $task) {
|
78 |
|
|
$form_state['task'] = $task;
|
79 |
|
|
$config = rules_config_load($task['config']);
|
80 |
|
|
$path['path'] = isset($_GET['destination']) ? $_GET['destination'] : RULES_SCHEDULER_PATH;
|
81 |
|
|
|
82 |
|
|
$title = t('Are you sure you want to delete the scheduled task %id?', array('%id' => $task['tid']));
|
83 |
|
|
if (!empty($task['identifier'])) {
|
84 |
|
|
$msg = t('This task with the custom identifier %id executes component %label on %date. The action cannot be undone.', array(
|
85 |
|
|
'%label' => $config->label(),
|
86 |
|
|
'%id' => $task['identifier'],
|
87 |
|
|
'%date' => format_date($task['date']),
|
88 |
|
|
));
|
89 |
|
|
}
|
90 |
|
|
else {
|
91 |
|
|
$msg = t('This task executes component %label and will be executed on %date. The action cannot be undone.', array(
|
92 |
|
|
'%label' => $config->label(),
|
93 |
|
|
'%id' => $task['identifier'],
|
94 |
|
|
'%date' => format_date($task['date']),
|
95 |
|
|
));
|
96 |
|
|
}
|
97 |
|
|
return confirm_form($form, $title, $path, $msg, t('Delete'), t('Cancel'));
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
/**
|
101 |
|
|
* Submit handler for deleting single tasks.
|
102 |
|
|
*/
|
103 |
|
|
function rules_scheduler_delete_task_submit($form, &$form_state) {
|
104 |
|
|
rules_scheduler_task_delete($form_state['task']['tid']);
|
105 |
|
|
drupal_set_message(t('Task %tid has been deleted.', array('%tid' => $form_state['task']['tid'])));
|
106 |
|
|
$form_state['redirect'] = RULES_SCHEDULER_PATH;
|
107 |
|
|
}
|
108 |
|
|
|
109 |
|
|
/**
|
110 |
|
|
* Configuration form to manually schedule a rules component.
|
111 |
|
|
*/
|
112 |
|
|
function rules_scheduler_schedule_form($form, &$form_state, $rules_config, $base_path) {
|
113 |
|
|
// Only components can be scheduled.
|
114 |
|
|
if (!($rules_config instanceof RulesTriggerableInterface)) {
|
115 |
|
|
RulesPluginUI::$basePath = $base_path;
|
116 |
|
|
$form_state['component'] = $rules_config->name;
|
117 |
|
|
$action = rules_action('schedule', array('component' => $rules_config->name));
|
118 |
|
|
$action->form($form, $form_state);
|
119 |
|
|
// The component should be fixed, so hide the paramter for it.
|
120 |
|
|
$form['parameter']['component']['#access'] = FALSE;
|
121 |
|
|
$form['submit'] = array(
|
122 |
|
|
'#type' => 'submit',
|
123 |
|
|
'#value' => t('Schedule'),
|
124 |
|
|
);
|
125 |
|
|
$form['#validate'] = array('rules_ui_form_rules_config_validate');
|
126 |
|
|
return $form;
|
127 |
|
|
}
|
128 |
|
|
drupal_not_found();
|
129 |
|
|
exit;
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
/**
|
133 |
|
|
* Submit callback to execute the scheduling action.
|
134 |
|
|
*/
|
135 |
|
|
function rules_scheduler_schedule_form_submit($form, &$form_state) {
|
136 |
|
|
$action = $form_state['rules_element'];
|
137 |
|
|
$action->execute();
|
138 |
|
|
drupal_set_message(t('Component %label has been scheduled.', array('%label' => rules_config_load($form_state['component'])->label())));
|
139 |
|
|
$form_state['redirect'] = RULES_SCHEDULER_PATH;
|
140 |
|
|
} |