| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Module which rerun unfinished actions on media mover files
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Implementation of hook_help().
|
| 11 |
*/
|
| 12 |
function mm_retry_help($section) {
|
| 13 |
switch ($section) {
|
| 14 |
case 'admin/help#mm_retry':
|
| 15 |
$output = '<p>'. t('The Retry Media Mover Module runs active media mover\'s configurations with files which are not completed.'). '</p>';
|
| 16 |
$output .= '<p>'. t('Module doesn\'t have any avaliable settings and run inside cron.') .'</p>';
|
| 17 |
return $output;
|
| 18 |
}
|
| 19 |
}
|
| 20 |
|
| 21 |
/**
|
| 22 |
* Implementation of hook_cron
|
| 23 |
* Runs all active configurations
|
| 24 |
*/
|
| 25 |
function mm_retry_cron() {
|
| 26 |
$configurations = _mm_get_active_configurations();
|
| 27 |
foreach ($configurations as $config) {
|
| 28 |
print mm_retry_run_config($config);
|
| 29 |
}
|
| 30 |
}
|
| 31 |
|
| 32 |
/**
|
| 33 |
* Runs media mover configuration but instead of harvesting uses media mover
|
| 34 |
* files which are not completed
|
| 35 |
*
|
| 36 |
* @param $config
|
| 37 |
* Media mover configuration array
|
| 38 |
* @param $debug
|
| 39 |
* If true function will return debug text
|
| 40 |
* @return
|
| 41 |
* If $debug = true then return debug text
|
| 42 |
*/
|
| 43 |
function mm_retry_run_config($config, $debug = true) {
|
| 44 |
// check to see if this config is running
|
| 45 |
if (!_mm_configuration_is_running($config->cid)) {
|
| 46 |
$output = t('Re-running') .' '. l($config->name, 'admin/media_mover/config/'. $config->cid) ."<br />";
|
| 47 |
|
| 48 |
// check directories
|
| 49 |
media_mover_api_check_config_dirs($config);
|
| 50 |
|
| 51 |
// Getting files
|
| 52 |
$output .= t('Getting files.... ') .'<br />';
|
| 53 |
|
| 54 |
$files = db_query("SELECT mmfid FROM {media_mover_files} WHERE (complete_module = '' OR storage_module = '' OR process_module = '') AND cid = %d AND status = 1", $config->cid);
|
| 55 |
while ($file = db_fetch_array($files)) {
|
| 56 |
$mmfid = $file['mmfid'];
|
| 57 |
|
| 58 |
// get file data
|
| 59 |
$harvested_file = _mm_file_db_fetch($mmfid);
|
| 60 |
|
| 61 |
// PROCESS
|
| 62 |
if ($harvested_file['process_module']=='') {
|
| 63 |
$output .= t('Processing file #@mmfid', array('@mmfid' => $harvested_file['mmfid'])) .'<br />';
|
| 64 |
$harvested_file = module_invoke($config->process->module, 'media_mover', 'process', $config->process->action, $config->process->configuration, $harvested_file, $config);
|
| 65 |
_mm_file_db_update($harvested_file);
|
| 66 |
|
| 67 |
// check and see if we should continue
|
| 68 |
if ($harvested_file['status'] === 0 ) {
|
| 69 |
$output .= t('Error in processing file #@mmfid', array('@mmfid' => $harvested_file['mmfid'])) .'<br />';
|
| 70 |
continue;
|
| 71 |
}
|
| 72 |
}
|
| 73 |
|
| 74 |
// STORAGE
|
| 75 |
if ($harvested_file['storage_module']=='') {
|
| 76 |
$output .= t('Storing file #@mmfid', array('@mmfid' => $harvested_file['mmfid'])) .'<br />';
|
| 77 |
$harvested_file = module_invoke($config->storage->module, 'media_mover', 'storage', $config->storage->action, $config->storage->configuration, $harvested_file, $config);
|
| 78 |
_mm_file_db_update($harvested_file);
|
| 79 |
}
|
| 80 |
|
| 81 |
// COMPLETE
|
| 82 |
if ($harvested_file['complete_module']=='') {
|
| 83 |
$output .= t('Completion of file #@mmfid', array('@mmfid' => $harvested_file['mmfid'])) .'<br />';
|
| 84 |
$harvested_file = module_invoke($config->complete->module, 'media_mover', 'complete', $config->complete->action, $config->complete->configuration, $harvested_file, $config);
|
| 85 |
_mm_file_db_update($harvested_file);
|
| 86 |
}
|
| 87 |
}
|
| 88 |
// ends the configuration run
|
| 89 |
_mm_configuration_stop_run($config->cid);
|
| 90 |
}
|
| 91 |
|
| 92 |
// if in debug mode return $output
|
| 93 |
if ($debug) {
|
| 94 |
return $output;
|
| 95 |
}
|
| 96 |
|
| 97 |
}
|