--- /var/www/media_mover/media_mover_api.module 2008-09-21 20:53:42.000000000 -0400 +++ media_mover_api.module 2008-09-22 03:23:11.000000000 -0400 @@ -47,8 +47,8 @@ define('MMA_FILE_STATUS_COMPLETE_COMPLET /** * Implementation of hook_help(). */ -function media_mover_api_help($section) { - switch ($section) { +function media_mover_api_help($path, $arg) { + switch ($path) { case 'admin/modules#description' : return t('Media Mover module is a helper module to manipulate media files on your site.'); } @@ -58,15 +58,14 @@ function media_mover_api_help($section) /** * Implementation of hook_menu(). */ -function media_mover_api_menu($may_cache) { +function media_mover_api_menu() { global $user; // main page - $items[] = array( - 'path' => 'admin/media_mover', - 'title' => t('Media Mover'), - 'callback' => 'media_mover_api_page', - 'access' => user_access('administer media_mover'), + $items['admin/media_mover'] = array( + 'title' => 'Media Mover', + 'page callback' => 'media_mover_api_page', + 'access arguments' => array('administer media_mover'), 'type' => MENU_NORMAL_ITEM, ); @@ -74,81 +73,73 @@ function media_mover_api_menu($may_cache // MAIN TABS for admin/media_mover // main page - $items[] = array( - 'path' => 'admin/media_mover/default', - 'title' => t('Overview'), - 'callback' => 'media_mover_api_page', - 'access' => user_access('administer media_mover'), + $items['admin/media_mover/default'] = array( + 'title' => 'Overview', + 'page callback' => 'media_mover_api_page', + 'access arguments' => array('administer media_mover'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, ); // settings as a tab - $items[] = array( - 'path' => 'admin/media_mover/settings', - 'title' => t('Settings'), - 'callback' => 'drupal_get_form', - 'callback arguments' => array('media_mover_api_admin_settings'), - 'access' => user_access('administer media_mover'), + $items['admin/media_mover/settings'] = array( + 'title' => 'Settings', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('media_mover_api_admin_settings'), + 'access arguments' => array('administer media_mover'), 'type' => MENU_LOCAL_TASK, ); // settings in the normal place - $items[] = array( - 'path' => 'admin/settings/media_mover', - 'title' => t('Media Mover admin settings'), - 'description' => t('Configure default settings for Media Mover modules.'), - 'callback' => 'drupal_get_form', - 'callback arguments' => array('media_mover_api_admin_settings'), - 'access' => user_access('administer media_mover'), + $items['admin/settings/media_mover'] = array( + 'title' => 'Media Mover admin settings', + 'description' => 'Configure default settings for Media Mover modules.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('media_mover_api_admin_settings'), + 'access arguments' => array('administer media_mover'), ); // add a new configuration - $items[] = array( - 'path' => 'admin/media_mover/config/add', - 'title' => t('Add Config'), - 'callback' => 'drupal_get_form', - 'access' => user_access('administer media_mover'), - 'callback arguments' => array('media_mover_api_add_config_form', arg(4)), + $items['admin/media_mover/config/add'] = array( + 'title' => 'Add Config', + 'page callback' => 'drupal_get_form', + 'access arguments' => array('administer media_mover'), + 'page arguments' => array('media_mover_api_add_config_form', arg(4)), 'type' => MENU_LOCAL_TASK, ); // show all files - $items[] = array( - 'path' => 'admin/media_mover/files', - 'title' => t('All Files'), - 'callback' => 'media_mover_api_files_list', - 'callback arguments' => array(arg(3)), - 'access' => user_access('administer media_mover'), + $items['admin/media_mover/files'] = array( + 'title' => 'All Files', + 'page callback' => 'media_mover_api_files_list', + 'page arguments' => array(arg(3)), + 'access arguments' => array('administer media_mover'), 'type' => MENU_LOCAL_TASK, 'weight' => -9, ); // files status - $items[] = array( - 'path' => 'admin/media_mover/files/status', - 'title' => t('File Status'), - 'callback' => 'media_mover_api_files_status', - 'access' => user_access('administer media_mover'), + $items['admin/media_mover/files/status'] = array( + 'title' => 'File Status', + 'page callback' => 'media_mover_api_files_status', + 'access arguments' => array('administer media_mover'), 'type' => MENU_LOCAL_TASK, ); // import a configuration - $items[] = array( - 'path' => 'admin/media_mover/import', - 'title' => t('Import'), - 'callback' => 'media_mover_api_import_config', - 'access' => user_access('administer media_mover'), + $items['admin/media_mover/import'] = array( + 'title' => 'Import', + 'page callback' => 'media_mover_api_import_config', + 'access arguments' => array('administer media_mover'), 'type' => MENU_LOCAL_TASK, 'weight' => 10, ); // export a configuration - $items[] = array( - 'path' => 'admin/media_mover/export', - 'title' => t('Export'), - 'callback' => 'media_mover_api_export', - 'access' => user_access('administer media_mover'), + $items['admin/media_mover/export'] = array( + 'title' => 'Export', + 'page callback' => 'media_mover_api_export', + 'access arguments' => array('administer media_mover'), 'type' => MENU_LOCAL_TASK, 'weight' => 10, ); @@ -156,99 +147,100 @@ function media_mover_api_menu($may_cache // ------------------------------------------------------- // Individual Configuration functions + // add a new configuration + $items['admin/media_mover/config/%media_mover_api_menu_get_configuration/edit'] = array( + 'title' => 'Add Config', + 'page callback' => 'drupal_get_form', + 'access arguments' => array('administer media_mover'), + 'page arguments' => array('media_mover_api_config_edit_form', arg(3)), + 'type' => MENU_LOCAL_TASK, + ); + + // only add these to the menu if we're on a config page if (arg(2) == 'config' && is_numeric(arg(3))) { // landing page for an individual configuration - $items[] = array( - 'path' => 'admin/media_mover/config/'. arg(3), - 'title' => t('View'), - 'callback' => 'media_mover_api_configuration', - 'access' => user_access('administer media_mover'), - 'callback arguments' => array(arg(3)), + $items['admin/media_mover/config/'. '%'] = array( + 'title' => 'View', + 'page callback' => 'media_mover_api_configuration', + 'access arguments' => array('administer media_mover'), + 'page arguments' => array(arg(3)), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -9, ); // landing page for an individual configuration - $items[] = array( - 'path' => 'admin/media_mover/config/'. arg(3) .'/view', - 'title' => t('Details'), - 'callback' => 'media_mover_api_configuration', - 'access' => user_access('administer media_mover'), - 'callback arguments' => array(arg(3)), + $items['admin/media_mover/config/'. '%' .'/view'] = array( + 'title' => 'Details', + 'page callback' => 'media_mover_api_configuration', + 'access arguments' => array('administer media_mover'), + 'page arguments' => array(arg(3)), 'type' => MENU_LOCAL_TASK, 'weight' => -10, ); // edit tab for a configuration - $items[] = array( - 'path' => 'admin/media_mover/config/'. arg(3) .'/edit', - 'title' => t('Edit'), + $items['admin/media_mover/config/'. '%' .'/edit'] = array( + 'title' => 'Edit', 'callback' => 'drupal_get_form', - 'access' => user_access('administer media_mover'), - 'callback arguments' => array('media_mover_api_config_edit_form', arg(3)), + 'access arguments' => array('administer media_mover'), + 'page arguments' => array('media_mover_api_config_edit_form', arg(3)), 'type' => MENU_LOCAL_TASK, ); // file tab for a configuration - $items[] = array( - 'path' => 'admin/media_mover/config/'. arg(3) .'/files', - 'title' => t('Files'), - 'callback' => 'media_mover_api_files_list', - 'access' => user_access('administer media_mover'), - 'callback arguments' => array(arg(3)), + $items['admin/media_mover/config/'. '%' .'/files'] = array( + 'title' => 'Files', + 'page callback' => 'media_mover_api_files_list', + 'access arguments' => array('administer media_mover'), + 'page arguments' => array(arg(3)), 'type' => MENU_LOCAL_TASK, ); // clear non finished files for a config - $items[] = array( - 'path' => 'admin/media_mover/config/'. arg(3) .'/files/clear', - 'title' => t('Files'), - 'callback' => 'media_mover_api_config_files_clear', - 'access' => user_access('administer media_mover'), - 'callback arguments' => array(arg(3)), + $items['admin/media_mover/config/'. '%' .'/files/clear'] = array( + 'title' => 'Files', + 'page callback' => 'media_mover_api_config_files_clear', + 'access arguments' => array('administer media_mover'), + 'page arguments' => array(arg(3)), 'type' => MENU_LOCAL_TASK, ); // run tab for a configuration - $items[] = array( - 'path' => 'admin/media_mover/config/'. arg(3) .'/run', - 'title' => t('Run'), - 'callback' => 'media_mover_api_run_configuration', - 'access' => user_access('administer media_mover'), - 'callback arguments' => array(arg(3)), + $items['admin/media_mover/config/'. '%' .'/run'] = array( + 'title' => 'Run', + 'page callback' => 'media_mover_api_run_configuration', + 'access arguments' => array('administer media_mover'), + 'page arguments' => array(arg(3)), 'type' => MENU_LOCAL_TASK, ); } // stop an existing configuration - $items[] = array( - 'path' => 'admin/media_mover/config/'. arg(3) .'/stop', - 'title' => t('Confirm Configuration Stop'), - 'callback' => 'drupal_get_form', - 'access' => user_access('administer media_mover'), + $items['admin/media_mover/config/'. '%' .'/stop'] = array( + 'title' => 'Confirm Configuration Stop', + 'page callback' => 'drupal_get_form', + 'access arguments' => array('administer media_mover'), 'type' => MENU_CALLBACK, - 'callback arguments' => array('media_mover_api_config_stop_confirm', arg(3)), + 'page arguments' => array('media_mover_api_config_stop_confirm', arg(3)), ); // delete an existing configuration - $items[] = array( - 'path' => 'admin/media_mover/config/'. arg(3) .'/delete', - 'title' => t('Confirm Configuration Deletion'), - 'callback' => 'drupal_get_form', - 'access' => user_access('administer media_mover'), - 'callback arguments' => array('media_mover_api_config_delete_confirm', arg(3)), + $items['admin/media_mover/config/'. '%' .'/delete'] = array( + 'title' => 'Confirm Configuration Deletion', + 'page callback' => 'drupal_get_form', + 'access arguments' => array('administer media_mover'), + 'page arguments' => array('media_mover_api_config_delete_confirm', arg(3)), 'type' => MENU_CALLBACK, ); // Empty an existing configuration of files - $items[] = array( - 'path' => 'admin/media_mover/config/'. arg(3) .'/empty', - 'title' => t('Confirm Configuration Deletion'), - 'callback' => 'drupal_get_form', - 'access' => user_access('administer media_mover'), - 'callback arguments' => array('media_mover_api_config_empty_confirm', arg(3)), + $items['admin/media_mover/config/'. '%' .'/empty'] = array( + 'title' => 'Confirm Configuration Deletion', + 'page callback' => 'drupal_get_form', + 'access arguments' => array('administer media_mover'), + 'page arguments' => array('media_mover_api_config_empty_confirm', arg(3)), 'type' => MENU_CALLBACK, ); @@ -256,48 +248,44 @@ function media_mover_api_menu($may_cache // Configuration tasks // change a configuration status - $items[] = array( - 'path' => 'admin/media_mover/config/'. arg(3). '/status/'. arg(5), - 'title' => t('Update configuration status'), - 'callback' => 'drupal_get_form', - 'access' => user_access('administer media_mover'), + $items['admin/media_mover/config/'. arg(3). '/status/'. '%'] = array( + 'title' => 'Update configuration status', + 'page callback' => 'drupal_get_form', + 'access arguments' => array('administer media_mover'), 'type' => MENU_CALLBACK, - 'callback arguments' => array('media_mover_api_config_status_change_confirm', arg(3), arg(5) ), + 'page arguments' => array('media_mover_api_config_status_change_confirm', arg(3), arg(5) ), ); // ------------------------------------------------------- // File tasks // edit a file - $items[] = array( - 'path' => 'admin/media_mover/file/edit', - 'title' => t('Edit File'), - 'callback' => 'drupal_get_form', - 'access' => user_access('administer media_mover'), + $items['admin/media_mover/file/edit'] = array( + 'title' => 'Edit File', + 'page callback' => 'drupal_get_form', + 'access arguments' => array('administer media_mover'), 'type' => MENU_CALLBACK, - 'callback arguments' => array('media_mover_api_edit_file_form', arg(4)), + 'page arguments' => array('media_mover_api_edit_file_form', arg(4)), ); // delete a file - $items[] = array( - 'path' => 'admin/media_mover/file/delete', - 'title' => t('Delete File'), - 'callback' => 'drupal_get_form', - 'access' => user_access('administer media_mover'), + $items['admin/media_mover/file/delete'] = array( + 'title' => 'Delete File', + 'page callback' => 'drupal_get_form', + 'access arguments' => array('administer media_mover'), 'type' => MENU_CALLBACK, - 'callback arguments' => array('media_mover_api_file_delete_confirm_form', arg(4)), + 'page arguments' => array('media_mover_api_file_delete_confirm_form', arg(4)), ); // ------------------------------------------------------- // File tasks - $items[] = array( - 'path' => 'media_mover/rerun/'. arg(2) .'/node', - 'title' => t('Rerun process'), - 'callback' => 'drupal_get_form', - 'access' => user_access('administer media_mover'), + $items['media_mover/rerun/'. '%' .'/node'] = array( + 'title' => 'Rerun process', + 'page callback' => 'drupal_get_form', + 'access arguments' => array('administer media_mover'), 'type' => MENU_CALLBACK, - 'callback arguments' => array('media_mover_api_rerun_node_form', arg(2), arg(4)), + 'page arguments' => array('media_mover_api_rerun_node_form', arg(2), arg(4)), ); return $items; @@ -324,10 +312,10 @@ function media_mover_api_cron() { foreach ($configurations as $config) { // check to see if we should run on cron for this configuration if (isset($config->config->mma_cron_run) ? $config->config->mma_cron_run : variable_get('mma_cron_run', true)) { - // now we check and see there is a hard override of this cron - if (! constant("MEDIA_MOVER_CRON_OFF_". $config->cid)) { + // now we check and see there is a hard override of this cron + if (! constant("MEDIA_MOVER_CRON_OFF_". $config->cid)) { media_mover_api_run_config($config, null, null, true); - } + } } } } @@ -378,7 +366,7 @@ function media_mover_api_nodeapi(&$node, * @param string $form_id * @param array $form drupal form array */ -function media_mover_api_form_alter($form_id, &$form) { +function media_mover_api_form_alter(&$form, $form_state, $form_id) { // check and see if this is a node delete form if ($form_id == 'node_delete_confirm') { // load the node @@ -515,20 +503,20 @@ function media_mover_api_get_status($sta * @return array or string */ function media_mover_api_item_status($status = null) { - static $states; - if (! $states) { + static $states; + if (! $states) { $states = array( MMA_FILE_ERROR => t('Error'), - MMA_FILE_STATUS_HARVESTED => t('Harvested'), - MMA_FILE_STATUS_IN_PROCESS => t('Processing'), - MMA_FILE_STATUS_PROCESS_COMPLETE => t('Processed'), - MMA_FILE_STATUS_IN_STORAGE => t('Storing'), - MMA_FILE_STATUS_STORAGE_COMPLETE => t('Stored'), - MMA_FILE_STATUS_IN_COMPLETE => t('Finishing'), - MMA_FILE_STATUS_COMPLETE_COMPLETE => t('Finished'), - ); - } - if ($status) {return $states[$status];} + MMA_FILE_STATUS_HARVESTED => t('Harvested'), + MMA_FILE_STATUS_IN_PROCESS => t('Processing'), + MMA_FILE_STATUS_PROCESS_COMPLETE => t('Processed'), + MMA_FILE_STATUS_IN_STORAGE => t('Storing'), + MMA_FILE_STATUS_STORAGE_COMPLETE => t('Stored'), + MMA_FILE_STATUS_IN_COMPLETE => t('Finishing'), + MMA_FILE_STATUS_COMPLETE_COMPLETE => t('Finished'), + ); + } + if ($status) {return $states[$status];} return $states; } @@ -544,27 +532,27 @@ function media_mover_api_item_status($st * @return string */ function media_mover_api_verb_base_status($verb, $id = null) { - static $status; - if (! $status) { - $status = array( - // note that the harvest is a special case as the file - // would not exist previous to the harvest - 'harvest' => 0, - 'process' => MMA_FILE_STATUS_HARVESTED, - 'storage' => MMA_FILE_STATUS_PROCESS_COMPLETE, - 'complete' => MMA_FILE_STATUS_STORAGE_COMPLETE - ); - } + static $status; + if (! $status) { + $status = array( + // note that the harvest is a special case as the file + // would not exist previous to the harvest + 'harvest' => 0, + 'process' => MMA_FILE_STATUS_HARVESTED, + 'storage' => MMA_FILE_STATUS_PROCESS_COMPLETE, + 'complete' => MMA_FILE_STATUS_STORAGE_COMPLETE + ); + } - // do we need to hand back verbs or ids? + // do we need to hand back verbs or ids? if ($id) { - // return the $verb for the ID - $return = array_flip($status); - } + // return the $verb for the ID + $return = array_flip($status); + } else { - $return = $status; + $return = $status; } - return $return[$verb]; + return $return[$verb]; } @@ -634,13 +622,13 @@ function media_mover_api_run_configurati */ function media_mover_api_run_config($config, $debug = true, $nid = null, $cron = false) { $output = t('Running') .' '. l($config->name, 'admin/media_mover/config/'. $config->cid) ."
"; - /** + /** * first, lock config, harvest files, store files, unlock config * get all files ready for processing, process one file at a time * lock each file to prevent overrunning */ - // check to make sure that we have all directories + // check to make sure that we have all directories media_mover_api_check_config_dirs($config); // start the loop where we run all the verbs @@ -648,13 +636,13 @@ function media_mover_api_run_config($con // we make a special case for harvesting // @ TODO refactor harvest to work the same way that all the other steps do. if ($verb == 'harvest') { - $output = media_mover_api_run_config_harvest($config, $verb, $nid); + $output = media_mover_api_run_config_harvest($config, $verb, $nid); } else { // ----------------------------------------------------- // run all the other configuration actions - // pass back the stuatus of the previous step to get the previous files - $output .= media_mover_api_run_config_verb($config, $verb, media_mover_api_verb_base_status($verb), $cron); + // pass back the stuatus of the previous step to get the previous files + $output .= media_mover_api_run_config_verb($config, $verb, media_mover_api_verb_base_status($verb), $cron); } } // end verb loop @@ -719,10 +707,10 @@ function media_mover_api_run_config_verb $output = t('Configuration process: %verb is acting on !count files', array('%verb' => $verb, '!count' => count($files))) .'
'; // loop through all of the found files for this status foreach ($files as $file) { - // only run this if cron isn't requeseting this OR cpu check doesn't report a high condition - if (! $cron || ( $cron && ! media_mover_api_cpu_check() )) { + // only run this if cron isn't requeseting this OR cpu check doesn't report a high condition + if (! $cron || ( $cron && ! media_mover_api_cpu_check() )) { media_mover_api_run_config_verb_file($file, $config, $verb); - } + } } return $output; } @@ -925,17 +913,16 @@ function media_mover_api_harvest_lock($c // figure out how long ago the job started $time = intval( (time() - $config['start_time']) / 60); - $message = t('Media Mover detected a MM job (!name) that has been running for !time minutes. You may want to consider decreasing your cron.php frequency or increase your PHP timeout.', - array('!name' => $config['name'], '!time' => $time) - ); + $message = 'Media Mover detected a MM job (!name) that has been running for !time minutes. You may want to consider decreasing your cron.php frequency or increase your PHP timeout.'; + $params = array('!name' => $config['name'], '!time' => $time); // set watchdog - watchdog('media_mover', $message, 'WATCHDOG_NOTICE' ); + watchdog('media_mover', $message, $params, 'WATCHDOG_WARNING' ); // should we alert an admin? if (variable_get('mma_cron_notify', false) && ($time >= variable_get('mma_cron_notify_time', 10))) { $subject = t('[!sitename] Media Mover Job Stuck', array('!sitename' => variable_get('site_name', false))); - drupal_mail('media_mover_api_job_running', variable_get('mma_cron_notify_email', null), $subject, $message); + drupal_mail('media_mover_api_job_running', variable_get('mma_cron_notify_email', null), $subject, t($message, $params)); } } return $output; @@ -1016,7 +1003,7 @@ function media_mover_api_stuck_job_check // are there stuck any to report? if (count($rows)) { $message = theme('media_mover_api_stuck_job', $rows); - watchdog('media_mover', $message, 'WATCHDOG_NOTICE' ); + watchdog('media_mover', $message, array(), 'WATCHDOG_NOTICE' ); // load the configuration to see if we have settings we have to abide by $configuration = media_mover_api_get_configuration($result['cid']); @@ -1048,17 +1035,17 @@ function media_mover_api_stuck_job_check */ function media_mover_api_event_trigger($type, $event, $verb, $data) { switch ($type) { - case 'config': - switch($event) { - case 'run': - if (module_exists('mm_workflow_ng')) { - // fire the harvest method; - workflow_ng_invoke_event('media_mover_'. $verb .'_file', $data); + case 'config': + switch($event) { + case 'run': + if (module_exists('mm_workflow_ng')) { + // fire the harvest method; + workflow_ng_invoke_event('media_mover_'. $verb .'_file', $data); } break; - } - break; - } + } + break; + } } @@ -1107,9 +1094,11 @@ function media_mover_cpu_load_check() { * @param int $status usually "enabled" * @return cid value */ -function media_mover_api_config_name_add($name, $description, $settings, $status) { - $cid = db_next_id("{media_mover_config_list}_cid"); - db_query("INSERT INTO {media_mover_config_list} (cid, name, description, settings, status) VALUES (%d, '%s', '%s', %d, '%s')", $cid, $name, $description, serialize($settings), $status ); +function media_mover_api_config_add($name, $description, $settings, $status) { + db_query("INSERT INTO {media_mover_config_list} (name, description, settings, status) VALUES ('%s', '%s', %d, '%s')", + $name, $description, serialize($settings), $status + ); + $cid = db_last_insert_id('media_mover_config_list', 'cid'); return $cid; } @@ -1134,18 +1123,13 @@ function media_mover_api_configuration_p * @return $mmfid for this files ID */ function media_mover_api_file_db_add($file, $config, $verb, $status) { - // get next mmfid - $mmfid = db_next_id("{media_mover_files}_mmfid"); - // add to db - db_query("INSERT INTO {media_mover_files} - (mmfid, nid, fid, cid, harvest_file, status, date, data) - VALUES (%d, %d, %d, %d, '%s', %d, %d, '%s')", - $mmfid, $file['nid'], $file['fid'], $config->cid, - $file['harvest_file'], $status, time(), serialize($file) + db_query("INSERT INTO {media_mover_files} (nid, fid, cid, harvest_file, status, date, data) VALUES (%d, %d, %d, '%s', %d, %d, '%s')", + $file['nid'], $file['fid'], $config->cid, $file['harvest_file'], $status, time(), serialize($file) ); - return $mmfid; + // return the mmfid + return db_last_insert_id("media_mover_files", 'mmfid'); } @@ -1197,16 +1181,15 @@ function media_mover_api_node_files_fetc // create cache name $cache_name = 'media_mover_files_node_'. $nid; // get data from cache - $data = cache_get($cache_name, 'cache_media_mover'); - $data = unserialize($data->data); + // we can haz cache? - if (! $data) { + if (! $data = cache_get($cache_name, 'cache_media_mover')) { $data = array(); $items = db_query('SELECT mmfid, cid FROM {media_mover_files} WHERE nid= %d ORDER BY cid', $nid); while ($item = db_fetch_array($items)) { $data[$item['cid']][] = media_mover_api_file_fetch($item['mmfid']); } - cache_set($cache_name, 'cache_media_mover', serialize($data), CACHE_TEMPORARY); + cache_set($cache_name, 'cache_media_mover', $data, CACHE_TEMPORARY); } return $data; } @@ -1221,11 +1204,11 @@ function media_mover_api_node_files_fetc * @return string */ function media_mover_api_config_current_file($file, $type = 'previous') { - switch ($type) { - case 'previous': - return $file[media_mover_api_verb_base_status($file['status'] - 2, true) .'_file']; - break; - } + switch ($type) { + case 'previous': + return $file[media_mover_api_verb_base_status($file['status'] - 2, true) .'_file']; + break; + } } @@ -1320,7 +1303,7 @@ function media_mover_api_config_delete_f * @return array of configuration objects */ function media_mover_api_get_configurations() { - $configurations = array(); + $configurations = array(); // get all active configuration names $results = db_query("SELECT * FROM {media_mover_config_list} mmcl WHERE mmcl.status != 'disabled'"); while ($config_name = db_fetch_array($results)) { @@ -1331,6 +1314,15 @@ function media_mover_api_get_configurati /** + * wrapper function for menu arguments + * @param int $cid + * @return object + */ +function media_mover_api_menu_get_configuration_load($cid) { + return media_mover_api_get_configuration($cid); +} + +/** * takes a CID and returns the full configuration object * uses a local cache to store config data to prevent multiple hits the DB * @param int $cid is a configuration id @@ -1344,7 +1336,10 @@ function media_mover_api_get_configurati // add this configuration to the static cache $configurations[$cid] = media_mover_api_build_configuration($result); } - // return the config + // return false if necessary + + if (! $configurations[$cid]) { return false;} + // return the config return $configurations[$cid]; } @@ -1458,7 +1453,7 @@ function media_mover_api_admin_form() { $form['admin']['cpu'] = array( '#title' => t('CPU settings'), '#type' => 'fieldset', - '#collapsed' => true, + '#collapsed' => true, ); $form['admin']['cpu']['cpu_limit'] = array( @@ -1497,7 +1492,6 @@ function media_mover_api_admin_form() { * @return string html */ function media_mover_api_page() { - // add the css file drupal_add_css(drupal_get_path('module', 'media_mover_api') . '/media_mover_api.css'); @@ -1695,14 +1689,14 @@ function media_mover_api_configuration($ * @param string $id is a cache id for the import functions * @return array drupal form array */ -function media_mover_api_add_config_form($id) { +function media_mover_api_add_config_form($id) { // do we have an incoming cache id that we should load // an imported configuration from? if ($id) { $configuration = cache_get('media_mover_config_'. $id); if ($configuration->data) { - $configuration = unserialize($configuration->data); - drupal_set_message(t('You are now configuring the configuration you just imported. Please make any changes and save the configuration.')); + $configuration = unserialize($configuration->data); + drupal_set_message(t('You are now configuring the configuration you just imported. Please make any changes and save the configuration.')); } } @@ -1732,7 +1726,7 @@ function media_mover_api_add_config_form * @return string prefix name */ function media_mover_api_form_prefix($configuration) { - return $configuration['verb'] .'--'. $configuration['module'] .'--'. $configuration['action'] .'--'; + return $configuration['verb'] .'--'. $configuration['module'] .'--'. $configuration['action'] .'--'; } @@ -1744,7 +1738,7 @@ function media_mover_api_form_prefix($co * @return array drupal form array */ function media_mover_api_configuration_base_form($configuration = null) { - $form['config'] = array( + $form['config'] = array( '#type' => 'fieldset', '#title' => t('Configuration Info'), ); @@ -1900,7 +1894,7 @@ function media_mover_api_config_advanced * @return array drupal form array */ function media_mover_api_build_add_config($configuration) { - + // add the javascript to show and hide configuration for modules drupal_add_js(drupal_get_path('module', 'media_mover_api') .'/media_mover_api.js'); @@ -1927,19 +1921,19 @@ function media_mover_api_build_add_confi if ($actions[$verb]) { foreach ($actions[$verb] as $action_id => $action) { - // if we don't have a config, build one - if (! $configuration->{$verb}->configuration) { - $config = array( - 'verb' => $verb, - 'module' => $module, - 'action' => $action_id, - ); - } - // we have a config, use it - else { - $config = $configuration->{$verb}->configuration; - } - + // if we don't have a config, build one + if (! $configuration->{$verb}->configuration) { + $config = array( + 'verb' => $verb, + 'module' => $module, + 'action' => $action_id, + ); + } + // we have a config, use it + else { + $config = $configuration->{$verb}->configuration; + } + // get the config form from the modules if (! $action_form = module_invoke($module, 'media_mover', 'config', $action_id, $config)) { // this action has no config, make a default @@ -2046,8 +2040,8 @@ function media_mover_api_rename_form_key * @param array $form_values * is the array of form data */ -function media_mover_api_add_config_form_validate($form_id, $form_values) { - media_mover_api_config_form_validate($form_values, true); +function media_mover_api_add_config_form_validate($form, &$form_state) { + media_mover_api_config_form_validate($form_state, true); } @@ -2060,16 +2054,16 @@ function media_mover_api_add_config_form * is the array of form data * */ -function media_mover_api_add_config_form_submit($form_id, $form_values) { +function media_mover_api_add_config_form_submit($form, &$form_state) { // Get all of the general configuration data out of this form - $settings = media_mover_api_configuration_get_settings($form_values); + $settings = media_mover_api_configuration_get_settings($form_state['values']); // create the config and get a cid for building the configuration - $cid = media_mover_api_config_name_add($form_values['mm_config_name'], $form_values['mm_config_descript'], $settings , 'enabled'); + $cid = media_mover_api_config_add($form_state['values']['mm_config_name'], $form_state['values']['mm_config_descript'], $settings , 'enabled'); // fish out the data for each item foreach (media_mover_api_verbs() as $verb) { - $configuration[$verb] = media_mover_api_collect_form_data($verb, $form_values); + $configuration[$verb] = media_mover_api_collect_form_data($verb, $form_state['values']); } // add each configuration's config to the db @@ -2077,9 +2071,9 @@ function media_mover_api_add_config_form media_mover_api_configuration_process_add($cid, $verb, $config['module'], $config['action'], $config['configuration'], 1 ); } - drupal_set_message(t('Media mover configuration %name created.', array('%name' => $form_values['name']))); + drupal_set_message(t('Media mover configuration %name created.', array('%name' => $form_state['values']['name']))); - return 'admin/media_mover'; + $form_state['redirect'] = 'admin/media_mover/config/'. $cid .'/view'; } @@ -2121,12 +2115,12 @@ function media_mover_api_collect_form_da * @return object */ function media_mover_api_configuration_get_settings($form_values) { - foreach ($form_values as $name => $value) { - if (strstr($name, 'mma_')) { - $settings->{$name} = $value; - } - } - return $settings; + foreach ($form_values as $name => $value) { + if (strstr($name, 'mma_')) { + $settings->{$name} = $value; + } + } + return $settings; } @@ -2136,17 +2130,16 @@ function media_mover_api_configuration_g * only the specific configurations for the origional configuration * can be change which prevents some potentially bad things from happening * - * @param int $cid is a configuration id + * @param array $form,= + * @param array $configuration is a configuration id * @return array drupal form */ -function media_mover_api_config_edit_form($cid) { - // get the full configuration object - $configuration = media_mover_api_get_configuration($cid); - +function media_mover_api_config_edit_form($form, $configuration) { + // check if this configuration is currently running, if it is, return user to config screen if ($configuration->status == 'running') { drupal_set_message(t('This configuration is currently running. You need to wait to modify it until it is complete.'), 'error'); - drupal_goto('admin/media_mover/config/'. $cid); + drupal_goto('admin/media_mover/config/'. $configuration->cid .'/view'); } // get the standard elements for the configuration @@ -2169,7 +2162,7 @@ function media_mover_api_config_edit_for $form['config']['cid']= array( '#type' => 'hidden', - '#value' => $cid, + '#value' => $configuration->cid , ); // we need to build out the existing data @@ -2180,8 +2173,6 @@ function media_mover_api_config_edit_for ); } - // get the full configuration - $configuration = media_mover_api_get_configuration($cid); // build each form element for this configuration foreach(media_mover_api_verbs() as $weight => $verb) { // get the form for this configuration role @@ -2258,7 +2249,7 @@ function media_mover_api_config_edit_for * @param array $form_values */ function media_mover_api_config_edit_form_validate($form_edit, $form_values) { - media_mover_api_config_form_validate($form_values, false); + media_mover_api_config_form_validate($form_values, false); } @@ -2287,7 +2278,7 @@ function media_mover_api_config_edit_for $verbs = media_mover_api_verbs(); foreach ($verbs as $verb) { foreach ($form_values as $key => $value) { - // $key is in format $verb--$module--$action_id--$element + // $key is in format $verb--$module--$action_id--$element $items = explode('--', $key); if ($items[0] == $verb) { $update[$verb] = array( @@ -2340,13 +2331,13 @@ function media_mover_api_config_form_val if ($all_errors) { // now loop through and build out the form elements foreach ($all_errors as $verb => $errors) { - if ($errors) { - foreach ($errors as $error) { - // build the id in form {$verb}--{$module}--{$action}--{$element} - $id = $verb .'--'. $error['module'] .'--'. $error['action'] .'--'. $error['element']; - form_set_error($id, $error['message']); - } - } + if ($errors) { + foreach ($errors as $error) { + // build the id in form {$verb}--{$module}--{$action}--{$element} + $id = $verb .'--'. $error['module'] .'--'. $error['action'] .'--'. $error['element']; + form_set_error($id, $error['message']); + } + } } } } @@ -2597,9 +2588,9 @@ function media_mover_api_export($cid = n * @return int */ function media_mover_api_configuration_files_count($cid, $in_process = false) { - if ($in_process) { - $status = ' AND status != -1 AND status != '. MMA_FILE_STATUS_COMPLETE_COMPLETE; - } + if ($in_process) { + $status = ' AND status != -1 AND status != '. MMA_FILE_STATUS_COMPLETE_COMPLETE; + } $count = db_result(db_query('SELECT COUNT(mmfid) FROM {media_mover_files} WHERE cid = %d '. $status, $cid)); return $count; } @@ -2784,7 +2775,7 @@ function media_mover_api_file_fetch_get_ * @return array drupal form array */ function media_mover_api_edit_file_form($mmfid) { - // set the title + // set the title drupal_set_title(t('Media Mover Edit File %id', array('%id'=> $mmfid))); // load the item $item = media_mover_api_file_get($mmfid); @@ -2795,12 +2786,12 @@ function media_mover_api_edit_file_form( 'error' ); } - + // get the configuration $configuration = media_mover_api_get_configuration($item['cid']); // get each of the actions for this configuration foreach (media_mover_api_verbs() as $verb) { - $rows[] = array( + $rows[] = array( t('Verb: %name', array('%name' => $verb)), t('Action: %name', array('%name' => media_mover_api_action_name($configuration->{$verb}->module, $verb, $configuration->{$verb}->action)) ), ); @@ -2876,15 +2867,15 @@ function media_mover_api_edit_file_form( function media_mover_api_edit_file_form_submit($form_id, $form_values) { switch ($form_values['op']) { case t('Save'): - db_query("UPDATE {media_mover_files} SET nid = %d, status = %d, url = '%s' WHERE mmfid = %d", $form_values['nid'], $form_values['status'], $form_values['url'], $form_values['mmfid']); + db_query("UPDATE {media_mover_files} SET nid = %d, status = %d, url = '%s' WHERE mmfid = %d", $form_values['nid'], $form_values['status'], $form_values['url'], $form_values['mmfid']); drupal_set_message(t('Media mover file ID: !id was updated.', array('!id' => $form_values['mmfid']))); return "admin/media_mover/files"; - break; + break; case t('Delete'): // redirect to the delete confirm drupal_goto('admin/media_mover/file/delete/'. $form_values['mmfid']); - break; - } + break; + } } @@ -3196,7 +3187,7 @@ function media_mover_api_xspf_playlist_u case 'return': // get files for the running configuration - if ($mmfiles = $node->media_mover[$config]) { + if ($mmfiles = $node->media_mover[$config]) { $items = array(); foreach($mmfiles as $mmfile) { $filepath = $mmfile['complete_file'];