| 1 |
<?php
|
| 2 |
/* $Id: media_mover_api_admin.inc,v 1.10 2008/02/18 18:48:17 bdragon Exp $ */
|
| 3 |
|
| 4 |
/**
|
| 5 |
* checks a configuration to see if it harvests from another configuration
|
| 6 |
* @param $cid is the configuration id
|
| 7 |
* @return parent $cid or false
|
| 8 |
*/
|
| 9 |
function media_mover_api_config_parent_config($cid) {
|
| 10 |
$result = db_result(db_query('SELECT configuration FROM {media_mover_configurations} WHERE verb = "harvest" AND action = "1" AND module = "mm_node" AND cid = %d', $cid));
|
| 11 |
if ($result = unserialize($result)) {
|
| 12 |
return($result['mm_harvest_cid']);
|
| 13 |
}
|
| 14 |
return false;
|
| 15 |
}
|
| 16 |
|
| 17 |
/**
|
| 18 |
* calls all of the media mover modules which
|
| 19 |
* implement the 'admin' param
|
| 20 |
*/
|
| 21 |
function media_mover_admin_settings() {
|
| 22 |
foreach (module_implements('media_mover') as $m) {
|
| 23 |
$form[$m] = module_invoke($m, 'media_mover', 'admin');
|
| 24 |
}
|
| 25 |
return system_settings_form($form);
|
| 26 |
}
|
| 27 |
|
| 28 |
/**
|
| 29 |
* admin settings for the API module
|
| 30 |
*/
|
| 31 |
function media_mover_api_admin_form() {
|
| 32 |
global $user;
|
| 33 |
|
| 34 |
$form['admin'] = array(
|
| 35 |
'#type' => 'fieldset',
|
| 36 |
'#title' => t('Media Mover Options'),
|
| 37 |
'#collapsible' => true,
|
| 38 |
);
|
| 39 |
|
| 40 |
$form['admin']['mma_no_cron_run'] = array(
|
| 41 |
'#type' => 'checkbox',
|
| 42 |
'#title' => t('Do not run Media Mover on cron'),
|
| 43 |
'#default_value' => variable_get('mma_no_cron_run', false),
|
| 44 |
'#description' => t("By checking this, Media Mover will not run when cron.php is called. This is helpful when you don't want to have harvest operations running."),
|
| 45 |
);
|
| 46 |
|
| 47 |
// @@@ Make this more friendly.
|
| 48 |
$form['admin']['mma_default_uid'] = array(
|
| 49 |
'#type' => 'textfield',
|
| 50 |
'#title' => t('Default Drupal owner of created files'),
|
| 51 |
'#default_value' => variable_get('mma_default_uid', 0),
|
| 52 |
);
|
| 53 |
|
| 54 |
$form['admin']['mma_file_perm'] = array(
|
| 55 |
'#type' => 'checkbox',
|
| 56 |
'#title' => t('Set created file permissions'),
|
| 57 |
'#default_value' => variable_get('mma_file_perm', true),
|
| 58 |
);
|
| 59 |
|
| 60 |
$form['admin']['mma_file_mask'] = array(
|
| 61 |
'#type' => 'textfield',
|
| 62 |
'#title' => t('umask to use'),
|
| 63 |
'#default_value' => variable_get('mma_file_mask', 0644),
|
| 64 |
'#description' => t('Use this if you need to change the permssions on your file system for files created by Media Mover.'),
|
| 65 |
'#size' => 4,
|
| 66 |
);
|
| 67 |
|
| 68 |
$form['admin']['mma_node_edit_file_show'] = array(
|
| 69 |
'#type' => 'checkbox',
|
| 70 |
'#title' => t('Show files on node edit screen'),
|
| 71 |
'#default_value' => variable_get('mma_node_edit_file_show', false),
|
| 72 |
'#description' => t('When a user edits a node, they will see a list of any Media Mover files attached to the node.'),
|
| 73 |
);
|
| 74 |
|
| 75 |
$form['admin']['mma_node_file_delete'] = array(
|
| 76 |
'#type' => 'checkbox',
|
| 77 |
'#title' => t('Delete Media Mover files'),
|
| 78 |
'#default_value' => variable_get('mma_node_file_delete', true),
|
| 79 |
'#description' => t('When you delete a node that has Media Mover files associated with it, do you want those files deleted as well?'),
|
| 80 |
);
|
| 81 |
|
| 82 |
$form['admin']['time'] = array(
|
| 83 |
'#type' => 'fieldset',
|
| 84 |
'#title' => t('Job timeout alert'),
|
| 85 |
'#collapsible' => true,
|
| 86 |
'#collapsed' => variable_get('mma_cron_notify', false),
|
| 87 |
'#description' => t('Sometimes a MM job can get stuck and prevent MM from running in the future. Use this to notify an admin that the queue needs review.'),
|
| 88 |
);
|
| 89 |
|
| 90 |
$form['admin']['time']['mma_cron_notify'] = array(
|
| 91 |
'#type' => 'checkbox',
|
| 92 |
'#title' => t('Notify admin when a MM job has run to long'),
|
| 93 |
'#default_value' => variable_get('mma_cron_notify', false),
|
| 94 |
);
|
| 95 |
|
| 96 |
$form['admin']['time']['mma_cron_notify_email'] = array(
|
| 97 |
'#type' => 'textfield',
|
| 98 |
'#title' => t('Email address to notify'),
|
| 99 |
'#default_value' => variable_get('mma_cron_notify_email', $user->mail),
|
| 100 |
'#description' => t('Email address to notify that a MM job has taken more than the set time.'),
|
| 101 |
);
|
| 102 |
|
| 103 |
$form['admin']['time']['mma_cron_notify_time'] = array(
|
| 104 |
'#type' => 'textfield',
|
| 105 |
'#title' => t('MM alert time'),
|
| 106 |
'#default_value' => variable_get('mma_cron_notify_time', 10),
|
| 107 |
'#description' => t('Set the maximum time (in minutes) that a MM job can run before alerting an admin.'),
|
| 108 |
'#size' => 4,
|
| 109 |
);
|
| 110 |
|
| 111 |
return $form;
|
| 112 |
}
|
| 113 |
|
| 114 |
/**
|
| 115 |
* Overview page.
|
| 116 |
* Display information about media_mover modules
|
| 117 |
* and existing configurations.
|
| 118 |
*/
|
| 119 |
function media_mover_api_overview() {
|
| 120 |
drupal_add_css(drupal_get_path('module', 'media_mover_api') . '/media_mover_api.css');
|
| 121 |
$form = array();
|
| 122 |
$form['media_mover_modules'] = array(
|
| 123 |
'#type' => 'fieldset',
|
| 124 |
'#title' => t('Media Mover modules'),
|
| 125 |
);
|
| 126 |
|
| 127 |
$row = array();
|
| 128 |
$header = array(t('Loaded modules'), t('Action type(s)'), t('Module actions'));
|
| 129 |
foreach (module_implements('media_mover') as $m) {
|
| 130 |
$module_actions = array();
|
| 131 |
$module_verbs = array();
|
| 132 |
// get all mm module actions
|
| 133 |
$actions = module_invoke($m, 'media_mover', 'actions');
|
| 134 |
foreach (_mm_verbs() as $verb) {
|
| 135 |
if (isset($actions[$verb]) && is_array($actions[$verb])) {
|
| 136 |
foreach ($actions[$verb] as $action_verb => $action) {
|
| 137 |
$module_verbs[] = $verb;
|
| 138 |
$module_actions[] = $action;
|
| 139 |
}
|
| 140 |
}
|
| 141 |
}
|
| 142 |
$item = array();
|
| 143 |
$item[] = array('header' => TRUE, 'data' => module_invoke($m, 'media_mover', 'name'));
|
| 144 |
$item[] = implode(", ", $module_verbs);
|
| 145 |
$item[] = implode(", " , array_unique($module_actions));
|
| 146 |
$row[] = $item;
|
| 147 |
}
|
| 148 |
|
| 149 |
$form['media_mover_modules']['data'] = array(
|
| 150 |
'#type' => 'markup',
|
| 151 |
'#value' => theme('table', $header, $row),
|
| 152 |
);
|
| 153 |
|
| 154 |
$form['media_mover_configs'] = array(
|
| 155 |
'#type' => 'fieldset',
|
| 156 |
'#title' => t('Media Mover configurations'),
|
| 157 |
);
|
| 158 |
|
| 159 |
// build the new header.
|
| 160 |
$header = array(array('data' => t('Name'), 'colspan' => 2), t('Description'), t('Files'), t('Last run'), t('Status'), t('Run'), t('Edit'), t('Reset'), t('Delete'), );
|
| 161 |
|
| 162 |
$parents = array();
|
| 163 |
$children = array();
|
| 164 |
$rows = array();
|
| 165 |
|
| 166 |
// get the configurations
|
| 167 |
$results = pager_query('SELECT * FROM {media_mover_config_list} ORDER BY cid');
|
| 168 |
while ($result = db_fetch_array($results)) {
|
| 169 |
|
| 170 |
// handle the status of the current configuration
|
| 171 |
switch ($result['status']) {
|
| 172 |
case 'enabled':
|
| 173 |
case 'stopped':
|
| 174 |
$status = t('enabled') .' ('. l(t('disable'), 'admin/content/media_mover/'. $result['cid'] .'/status/disabled') .')';
|
| 175 |
break;
|
| 176 |
case 'running':
|
| 177 |
$status = t('running') .' ('. l(t('stop'), 'admin/content/media_mover/'. $result['cid'] .'/stop') .')';
|
| 178 |
break;
|
| 179 |
case 'disabled':
|
| 180 |
$status = t('disabled') .' ('. l(t('enable'), 'admin/content/media_mover/'. $result['cid'] .'/status/enabled') .')';
|
| 181 |
break;
|
| 182 |
}
|
| 183 |
|
| 184 |
// get the total number of files for this config
|
| 185 |
$count = db_result(db_query('SELECT COUNT(mmfid) FROM {media_mover_files} WHERE cid = %d', $result['cid']));
|
| 186 |
$count = l($count, 'admin/content/media_mover/'. $result['cid'] .'/files');
|
| 187 |
|
| 188 |
// initialize the row
|
| 189 |
$row = array();
|
| 190 |
|
| 191 |
// is this configuration harvesting from another MM config?
|
| 192 |
if ($parent_id = media_mover_api_config_parent_config($result['cid'])) {
|
| 193 |
$title = array('|--> ', $result['name']);
|
| 194 |
}
|
| 195 |
else {
|
| 196 |
$title = array(array('data' => $result['name'], 'colspan' => 2));
|
| 197 |
}
|
| 198 |
|
| 199 |
// merge the title into the row
|
| 200 |
$row = array_merge($title, array(
|
| 201 |
$result['description'],
|
| 202 |
$count,
|
| 203 |
$result['last_start_time'] ?
|
| 204 |
date('M j, Y g:ia', $result['last_start_time']) :
|
| 205 |
($result['start_time'] ?
|
| 206 |
date('M j, Y g:ia', $result['start_time']) : 'never'),
|
| 207 |
$status,
|
| 208 |
l(t('run'), 'admin/content/media_mover/'. $result['cid'] .'/run'),
|
| 209 |
l(t('edit'), 'admin/content/media_mover/'. $result['cid'] .'/edit'),
|
| 210 |
l(t('reset'), 'admin/content/media_mover/'. $result['cid'] .'/reset/full'),
|
| 211 |
l(t('delete'), 'admin/content/media_mover/'. $result['cid'] .'/delete'),
|
| 212 |
));
|
| 213 |
|
| 214 |
// if this is a child of another process, put it into the children array
|
| 215 |
if ($parent_id) {
|
| 216 |
$children[$parent_id][] = $row;
|
| 217 |
}
|
| 218 |
else {
|
| 219 |
$parents[$result['cid']] = $row;
|
| 220 |
}
|
| 221 |
}
|
| 222 |
|
| 223 |
// now we need to rebuild the rows, and insert the children under the right parents
|
| 224 |
foreach($parents as $pid => $parent) {
|
| 225 |
$rows[] = array('data' => $parent, 'class' => 'mmapi-parent');
|
| 226 |
if (!empty($children[$pid])){
|
| 227 |
foreach ($children[$pid] as $chid) {
|
| 228 |
$rows[] = $chid;
|
| 229 |
}
|
| 230 |
}
|
| 231 |
// insert an empty array
|
| 232 |
$rows[] = array('data' => array(), 'class' => 'mmapi-parent');
|
| 233 |
}
|
| 234 |
|
| 235 |
$form['media_mover_configs']['data'] = array(
|
| 236 |
'#type' => 'markup',
|
| 237 |
'#value' => theme('table', $header, $rows),
|
| 238 |
);
|
| 239 |
$form['media_mover_configs']['pager'] = array(
|
| 240 |
'#type' => 'markup',
|
| 241 |
'#value' => theme('pager'),
|
| 242 |
);
|
| 243 |
|
| 244 |
return $form;
|
| 245 |
}
|
| 246 |
|
| 247 |
/**
|
| 248 |
* Add / Edit configuration form.
|
| 249 |
*/
|
| 250 |
function media_mover_config_form(&$form_state, $config = NULL) {
|
| 251 |
// Make sure that autocomplete and collapse are loaded so that ahah loaded
|
| 252 |
// form pieces work.
|
| 253 |
drupal_add_js('misc/autocomplete.js');
|
| 254 |
drupal_add_js('misc/collapse.js');
|
| 255 |
|
| 256 |
if ($config) {
|
| 257 |
$form_state['storage']['config'] = $config;
|
| 258 |
}
|
| 259 |
|
| 260 |
if (isset($config->cid)) {
|
| 261 |
$form['cid'] = array(
|
| 262 |
'#type' => 'value',
|
| 263 |
'#value' => $config->cid,
|
| 264 |
);
|
| 265 |
}
|
| 266 |
$form['new_config']= array(
|
| 267 |
'#type' => 'fieldset',
|
| 268 |
'#title' => t('Configuration Info'),
|
| 269 |
);
|
| 270 |
$form['new_config']['mm_config_name']= array(
|
| 271 |
'#type' => 'textfield',
|
| 272 |
'#title' => t('Name your configuration'),
|
| 273 |
'#description' => t('Give a descriptive name to your configuration'),
|
| 274 |
'#default_value' => isset($config->name) ? $config->name : '',
|
| 275 |
);
|
| 276 |
$form['new_config']['mm_config_descript']= array(
|
| 277 |
'#type' => 'textarea',
|
| 278 |
'#title' => t('Describe configuration'),
|
| 279 |
'#description' => t('Enter a description for your configuration.'),
|
| 280 |
'#default_value' => isset($config->description) ? $config->description : '',
|
| 281 |
);
|
| 282 |
|
| 283 |
// add all mm module config forms
|
| 284 |
$form['actions'] = media_mover_api_build_config($form_state);
|
| 285 |
$form['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));
|
| 286 |
return $form;
|
| 287 |
}
|
| 288 |
|
| 289 |
/**
|
| 290 |
* AHAH callback for Add / Edit configuration form.
|
| 291 |
*/
|
| 292 |
function media_mover_api_config_js($verb = NULL) {
|
| 293 |
list($module, $action) = explode('--', $_POST[$verb]['options']);
|
| 294 |
$form_build_id = $_POST['form_build_id'];
|
| 295 |
|
| 296 |
$form_state = array('storage' => NULL, 'submitted' => FALSE);
|
| 297 |
$form = form_get_cache($form_build_id, $form_state);
|
| 298 |
|
| 299 |
$form_state['values'][$verb]['options'] = $_POST[$verb]['options'];
|
| 300 |
$config = $form_state['storage']['config'];
|
| 301 |
|
| 302 |
$config->$verb->module = $module;
|
| 303 |
$config->$verb->action = $action;
|
| 304 |
$config->$verb->configuration = NULL;
|
| 305 |
|
| 306 |
$form = drupal_rebuild_form('media_mover_config_form', $form_state, array($form_state, $config), $form_build_id);
|
| 307 |
|
| 308 |
$output = theme('status_messages') . drupal_render($form['actions'][$verb]['conf']);
|
| 309 |
|
| 310 |
print drupal_to_js(array('status' => TRUE, 'data' => $output));
|
| 311 |
exit;
|
| 312 |
}
|
| 313 |
|
| 314 |
/**
|
| 315 |
* Utility function for Add / Edit configuration form.
|
| 316 |
* Set up configuration data.
|
| 317 |
*/
|
| 318 |
function media_mover_api_build_config(&$form_state) {
|
| 319 |
$config = $form_state['storage']['config'];
|
| 320 |
|
| 321 |
$disabled = FALSE;
|
| 322 |
// Are we editing an existing config?
|
| 323 |
if (isset($config->cid)) {
|
| 324 |
// Some of our elements aren't allowed to change when editing.
|
| 325 |
$disabled = TRUE;
|
| 326 |
}
|
| 327 |
// build some descriptive text
|
| 328 |
$description['harvest'] = t('Harvesting is where files are selected from');
|
| 329 |
$description['process'] = t('Processing is how files are changed');
|
| 330 |
$description['storage'] = t('Storage is where files are stored in addition to Media Mover\'s internal storage');
|
| 331 |
$description['complete'] = t('Complete is something that happens to files at the end of a configuration');
|
| 332 |
|
| 333 |
|
| 334 |
// Put together the actions list.
|
| 335 |
$actions = array();
|
| 336 |
foreach (module_implements('media_mover') as $m) {
|
| 337 |
$temp = module_invoke($m, 'media_mover', 'actions');
|
| 338 |
$name = module_invoke($m, 'media_mover', 'name');
|
| 339 |
foreach ($temp as $k => $v) {
|
| 340 |
foreach ($v as $kk => $vv) {
|
| 341 |
$actions[$k][$m .'--'. $kk] = t('@media_mover_name: @media_mover_action', array('@media_mover_name' => $name, '@media_mover_action' => $vv));
|
| 342 |
}
|
| 343 |
}
|
| 344 |
}
|
| 345 |
|
| 346 |
$verbs = _mm_verbs();
|
| 347 |
foreach ($verbs as $verb) {
|
| 348 |
$form[$verb] = array(
|
| 349 |
'#type' => 'fieldset',
|
| 350 |
'#title' => t('%verb configuration', array('%verb' => $verb)),
|
| 351 |
//'#attributes' => array('class' => 'mm_config_fieldset'),
|
| 352 |
'#description' => $description[$verb],
|
| 353 |
// '#prefix' => '<div class="clear-block" id="mm_config_wrapper_'. $verb.'">',
|
| 354 |
// '#suffix' => '</div>',
|
| 355 |
);
|
| 356 |
|
| 357 |
$form[$verb]['options'] = array(
|
| 358 |
'#title' => t('Select which %verb module and action to use', array('%verb' => $verb)),
|
| 359 |
'#type' => 'select',
|
| 360 |
'#options' => $actions[$verb],
|
| 361 |
'#default_value' => (isset($config->$verb)) ? $config->$verb->module .'--'. $config->$verb->action : 'media_mover--1',
|
| 362 |
'#ahah' => array(
|
| 363 |
'path' => 'admin/content/media_mover/js/'. $verb,
|
| 364 |
'wrapper' => 'mm_config_wrapper_'. $verb,
|
| 365 |
// 'action' => 'change',
|
| 366 |
'method' => 'replace',
|
| 367 |
'effect' => 'fade',
|
| 368 |
),
|
| 369 |
'#parents' => array($verb, 'options'),
|
| 370 |
'#disabled' => $disabled,
|
| 371 |
);
|
| 372 |
/*
|
| 373 |
$form[$verb]['switch_'. $verb] = array(
|
| 374 |
'#type' => 'submit',
|
| 375 |
'#value' => t('Choose @verb action', array('@verb' => t($verb))),
|
| 376 |
//'#description' => t("If the amount of boxes above isn't enough, click here to add more choices."),
|
| 377 |
//'#weight' => 1,
|
| 378 |
'#submit' => array('mm_add_config_switch_config', $verb), // If no javascript action.
|
| 379 |
'#ahah' => array(
|
| 380 |
'path' => 'admin/content/media_mover/js',
|
| 381 |
'wrapper' => 'mm_config_wrapper_'. $verb,
|
| 382 |
'method' => 'replace',
|
| 383 |
'effect' => 'fade',
|
| 384 |
'progress' => array(
|
| 385 |
'type' => 'throbber',
|
| 386 |
'message' => t('Loading form'),
|
| 387 |
)
|
| 388 |
),
|
| 389 |
); */
|
| 390 |
$form[$verb]['conf'] = array(
|
| 391 |
'#prefix' => '<div class="clear-block" id="mm_config_wrapper_'. $verb .'">',
|
| 392 |
'#suffix' => '</div>',
|
| 393 |
'#parents' => array($verb),
|
| 394 |
);
|
| 395 |
|
| 396 |
$no_options_form = array(
|
| 397 |
'nooptions_'. $verb => array(
|
| 398 |
'#type' => 'fieldset',
|
| 399 |
'#title' => t('No options'),
|
| 400 |
'data' => array(
|
| 401 |
'#type' => 'markup',
|
| 402 |
'#value' => t('There are no configuration options for this.'),
|
| 403 |
),
|
| 404 |
),
|
| 405 |
);
|
| 406 |
if (isset($config->$verb)) {
|
| 407 |
$c = $config->$verb;
|
| 408 |
if (!$action_form = module_invoke($c->module, 'media_mover', 'config', $c->action, $c->configuration)) {
|
| 409 |
$action_form = $no_options_form;
|
| 410 |
}
|
| 411 |
}
|
| 412 |
else {
|
| 413 |
$action_form = $no_options_form;
|
| 414 |
}
|
| 415 |
$action_form['#tree'] = FALSE;
|
| 416 |
$form[$verb]['conf']['configuration'] = _media_mover_remap_action_form($action_form, $verb);
|
| 417 |
|
| 418 |
$form[$verb]['conf']['configuration']['#tree'] = TRUE;
|
| 419 |
$form[$verb]['conf']['configuration']['#parents'] = array($verb);
|
| 420 |
}
|
| 421 |
return $form;
|
| 422 |
}
|
| 423 |
|
| 424 |
/**
|
| 425 |
* Submit handler for the configuration add/edit form.
|
| 426 |
*/
|
| 427 |
function media_mover_config_form_submit($form, &$form_state) {
|
| 428 |
$values = $form_state['values'];
|
| 429 |
$verbs = _mm_verbs();
|
| 430 |
|
| 431 |
// Create the configuration.
|
| 432 |
$c = new stdClass();
|
| 433 |
$c->name = $values['mm_config_name'];
|
| 434 |
$c->description = $values['mm_config_descript'];
|
| 435 |
$c->status = 'enabled';
|
| 436 |
|
| 437 |
if (isset($values['cid'])) {
|
| 438 |
$c->cid = $values['cid'];
|
| 439 |
drupal_write_record('media_mover_config_list', $c, array('cid'));
|
| 440 |
}
|
| 441 |
else {
|
| 442 |
drupal_write_record('media_mover_config_list', $c);
|
| 443 |
}
|
| 444 |
$cid = $c->cid;
|
| 445 |
|
| 446 |
$conf = array();
|
| 447 |
foreach ($verbs as $verb) {
|
| 448 |
$conf[$verb] = array();
|
| 449 |
if (isset($values[$verb]['conf'])) {
|
| 450 |
$conf[$verb] = array();
|
| 451 |
$conf[$verb]['configuration'] = $values[$verb]['conf'];
|
| 452 |
}
|
| 453 |
list($conf[$verb]['module'], $conf[$verb]['action']) = explode('--', $values[$verb]['options']);
|
| 454 |
}
|
| 455 |
|
| 456 |
// Delete any old configuration rows that may be lying around.
|
| 457 |
db_query('DELETE FROM {media_mover_configurations} WHERE cid = %d', $cid);
|
| 458 |
|
| 459 |
// add each configuration's config to the db
|
| 460 |
foreach ($conf as $verb => $config) {
|
| 461 |
$c = new stdClass();
|
| 462 |
$c->cid = $cid;
|
| 463 |
$c->verb = $verb;
|
| 464 |
$c->module = $config['module'];
|
| 465 |
$c->action = $config['action'];
|
| 466 |
$c->configuration = isset($config['configuration']) ? $config['configuration'] : array();
|
| 467 |
drupal_write_record('media_mover_configurations', $c);
|
| 468 |
|
| 469 |
//db_query("INSERT INTO {media_mover_configurations} (cid, verb, module, action, configuration) VALUES (%d, '%s', '%s', '%s', '%s')", $cid, $verb, $module, $action, $configuration);
|
| 470 |
}
|
| 471 |
|
| 472 |
drupal_set_message(t('Media mover configuration %name created.', array('%name' => $values['mm_config_name'])));
|
| 473 |
|
| 474 |
// We're done with our storage.
|
| 475 |
unset($form_state['storage']);
|
| 476 |
$form_state['redirect'] = 'admin/content/media_mover';
|
| 477 |
}
|
| 478 |
|
| 479 |
/**
|
| 480 |
* Stop a running configuration.
|
| 481 |
* @param $config A configuration.
|
| 482 |
*/
|
| 483 |
function media_mover_api_config_stop_confirm(&$form_state, $config) {
|
| 484 |
$form['warning'] = array(
|
| 485 |
'#type' => 'markup',
|
| 486 |
'#value' => t('You are about to stop:<br /> %config_name <br /> %config_description <br /><br />'.
|
| 487 |
'This stops a running configuration. This is useful if the process got hung. '.
|
| 488 |
'Becareful that you can break a running process, so don\'t do this without good reason. <br /><br />',
|
| 489 |
array('%config_name' => $config->name, '%config_description' => $config->description) ),
|
| 490 |
);
|
| 491 |
$form['cid'] = array(
|
| 492 |
'#type' => 'value',
|
| 493 |
'#value' => $config->cid,
|
| 494 |
);
|
| 495 |
|
| 496 |
return confirm_form(
|
| 497 |
$form,
|
| 498 |
t('Are you sure you want to stop this configuration?'),
|
| 499 |
'admin/content/media_mover',
|
| 500 |
t('This action cannot be undone.'),
|
| 501 |
t('Reset'),
|
| 502 |
t('Cancel')
|
| 503 |
);
|
| 504 |
}
|
| 505 |
|
| 506 |
/**
|
| 507 |
* Submit handler for Stop a running configuration.
|
| 508 |
*/
|
| 509 |
function media_mover_api_config_stop_confirm_submit($form, &$form_state) {
|
| 510 |
db_query("UPDATE {media_mover_config_list} SET status = '%s', last_start_time = 0 WHERE cid = %d", 'stopped', $form_state['values']['cid']);
|
| 511 |
drupal_set_message('Stopped the configuration.');
|
| 512 |
$form_state['redirect'] = 'admin/content/media_mover';
|
| 513 |
}
|
| 514 |
|
| 515 |
/**
|
| 516 |
* Reset a configuration fully.
|
| 517 |
* @param $config A MM configuration.
|
| 518 |
*/
|
| 519 |
function media_mover_config_reset_full_confirm(&$form_state, $config) {
|
| 520 |
$form['warning'] = array(
|
| 521 |
'#type' => 'markup',
|
| 522 |
'#value' => t('You are about to reset:<br /> %config_name <br /> %config_description <br /><br />'.
|
| 523 |
'This removes Media Mover\'s references to files harvested, processed, and stored by this configuration as well as the files (unless you choose to not delete them). '.
|
| 524 |
'Doing this may result in duplicated copies of Media Mover files, depending on your configuration. <br /><br />'.
|
| 525 |
'Please only do this if you are debugging an installation or have very good reasons for wanting to do so.<br /><br /.',
|
| 526 |
array('%config_name' => $config->name, '%config_description' => $config->description) ),
|
| 527 |
);
|
| 528 |
$form['cid'] = array(
|
| 529 |
'#type' => 'value',
|
| 530 |
'#value' => $config->cid,
|
| 531 |
);
|
| 532 |
|
| 533 |
$form['confirm_delete'] = array(
|
| 534 |
'#type' => 'checkbox',
|
| 535 |
'#title' => t("Delete this configuration's files"),
|
| 536 |
'#description' => t('If this is checked, all files created by this configuration will also be removed'),
|
| 537 |
'#default_value' => TRUE,
|
| 538 |
);
|
| 539 |
|
| 540 |
return confirm_form(
|
| 541 |
$form,
|
| 542 |
t('Are you sure you want to reset this configuration and remove references to its files?'),
|
| 543 |
'admin/content/media_mover',
|
| 544 |
t('This action cannot be undone.'),
|
| 545 |
t('Reset'),
|
| 546 |
t('Cancel')
|
| 547 |
);
|
| 548 |
}
|
| 549 |
|
| 550 |
/**
|
| 551 |
* Submit handler for Reset a configuration fully.
|
| 552 |
* this only deletes the records of files
|
| 553 |
*/
|
| 554 |
function media_mover_config_reset_full_confirm_submit($form, &$form_state) {
|
| 555 |
|
| 556 |
if ($form_state['values']['confirm_delete']) {
|
| 557 |
// run the hook to delete files created by any MM module
|
| 558 |
media_mover_api_config_delete_files($form_state['values']['cid']);
|
| 559 |
drupal_set_message(t('Deleted files associated with this configuration'));
|
| 560 |
}
|
| 561 |
|
| 562 |
db_query("UPDATE {media_mover_config_list} SET status = '%s', last_start_time = 0, start_time = 0 WHERE cid = %d", 'stopped', $form_state['values']['cid']);
|
| 563 |
db_query('DELETE FROM {media_mover_files} WHERE cid = %d', $form_state['values']['cid']);
|
| 564 |
drupal_set_message(t("Reset the configuration. Removed all of Media Mover's file refrences for this configuration."));
|
| 565 |
$form_state['redirect'] = 'admin/content/media_mover';
|
| 566 |
}
|
| 567 |
|
| 568 |
/**
|
| 569 |
* Delete a configuration.
|
| 570 |
* @param $config A MM configuration.
|
| 571 |
*/
|
| 572 |
function media_mover_config_delete_confirm(&$form_state, $config) {
|
| 573 |
$form['warning'] = array(
|
| 574 |
'#type' => 'markup',
|
| 575 |
'#value' => t('You are about to delete:<br /> %config_name <br /> %config_description <br />', array('%config_name' => $config->name, '%config_description' => $config->description) )
|
| 576 |
. t('This will also delete references to files, and the files that Media Mover has created with this configuration.'),
|
| 577 |
);
|
| 578 |
$form['cid'] = array(
|
| 579 |
'#type' => 'value',
|
| 580 |
'#value' => $config->cid,
|
| 581 |
);
|
| 582 |
|
| 583 |
return confirm_form(
|
| 584 |
$form,
|
| 585 |
t('Are you sure you want to delete this configuration?'),
|
| 586 |
'admin/content/media_mover',
|
| 587 |
t('This action cannot be undone and will remove ALL files created by this configuration'),
|
| 588 |
t('Delete'),
|
| 589 |
t('Cancel')
|
| 590 |
);
|
| 591 |
}
|
| 592 |
|
| 593 |
/**
|
| 594 |
* Submit handler for Delete a configuration.
|
| 595 |
*/
|
| 596 |
function media_mover_config_delete_confirm_submit($form, &$form_state) {
|
| 597 |
// run the hook to delete files created by any MM module
|
| 598 |
media_mover_api_config_delete_files($form_state['values']['cid']);
|
| 599 |
// remove the configurations
|
| 600 |
db_query('DELETE FROM {media_mover_config_list} WHERE cid = %d', $form_state['values']['cid']);
|
| 601 |
// remove the definition of the config
|
| 602 |
db_query('DELETE FROM {media_mover_configurations} WHERE cid = %d', $form_state['values']['cid']);
|
| 603 |
drupal_set_message('Deleted the configuration.');
|
| 604 |
|
| 605 |
$form_state['redirect'] = 'admin/content/media_mover';
|
| 606 |
}
|
| 607 |
|
| 608 |
/**
|
| 609 |
* Form for deleting a file.
|
| 610 |
* @@@ Make the display_data here more relevant; we actually HAVE file info now...
|
| 611 |
*/
|
| 612 |
function media_mover_delete_file_form(&$form_state, $file) {
|
| 613 |
$form['display_data'] = array(
|
| 614 |
'#type' => 'markup',
|
| 615 |
'#value' => t('You are about to delete file id#: %fid', array('%fid' => $file->mmfid)),
|
| 616 |
);
|
| 617 |
|
| 618 |
$form['mmfid'] = array(
|
| 619 |
'#type' => 'value',
|
| 620 |
'#value' => $file->mmfid,
|
| 621 |
);
|
| 622 |
|
| 623 |
return confirm_form($form,
|
| 624 |
t('Are you sure you want to delete this file?'),
|
| 625 |
'admin/content/media_mover/files',
|
| 626 |
t('This action cannot be undone.'),
|
| 627 |
t('Delete'),
|
| 628 |
t('Cancel')
|
| 629 |
);
|
| 630 |
}
|
| 631 |
|
| 632 |
/**
|
| 633 |
* Submit handler for delete file form.
|
| 634 |
*/
|
| 635 |
function media_mover_delete_file_form_submit($form, &$form_state) {
|
| 636 |
db_query('DELETE FROM {media_mover_files} WHERE mmfid = %d', $form_state['values']['mmfid']);
|
| 637 |
drupal_set_message(t('Deleted the file.'));
|
| 638 |
$form_state['redirect'] = 'admin/content/media_mover/files';
|
| 639 |
}
|
| 640 |
|
| 641 |
/**
|
| 642 |
* Form for changing status.
|
| 643 |
*/
|
| 644 |
function media_mover_status_update_confirm(&$form_state, $config, $status) {
|
| 645 |
$form['cid'] = array(
|
| 646 |
'#type' => 'value',
|
| 647 |
'#value' => $config->cid,
|
| 648 |
);
|
| 649 |
$form['status'] = array(
|
| 650 |
'#type' => 'value',
|
| 651 |
'#value' => $status,
|
| 652 |
);
|
| 653 |
|
| 654 |
return confirm_form(
|
| 655 |
$form,
|
| 656 |
t('Are you sure you want to change the status of %config?', array('%config' => $config->name)),
|
| 657 |
'admin/content/media_mover',
|
| 658 |
t('Old state: %oldstate, New state: %newstate.', array('%oldstate' => t($config->status), '%newstate' => t($status))),
|
| 659 |
t('Change'),
|
| 660 |
t('Cancel')
|
| 661 |
);
|
| 662 |
}
|
| 663 |
|
| 664 |
/**
|
| 665 |
* Submit handler for status change form.
|
| 666 |
*/
|
| 667 |
function media_mover_status_update_confirm_submit($form, &$form_state) {
|
| 668 |
db_query("UPDATE {media_mover_config_list} SET status = '%s' WHERE cid = %d", $form_state['values']['status'], $form_state['values']['cid']);
|
| 669 |
$form_state['redirect'] = 'admin/content/media_mover';
|
| 670 |
}
|