'Islandora Workflow Client',
'description' => 'Manage Islandora Workflows',
'page callback' => 'islandora_workflow_client_manage',
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM
);
return $items;
}
function islandora_workflow_client_search_submit($form,&$form_state)
{
$url ='admin/settings/workflow_client/'.$form['process_name']['#value'];
if (trim($form['process_id']['#value']) !== '') {
$url.='/'.$form['process_id']['#value'];
} else {
$url .= '/-/';
}
if (trim($form['collection_pid']['#value']) !== '') {
$url.='/'.$form['collection_pid']['#value'];
} else {
$url .= '/-/';
}
drupal_goto($url);
}
function islandora_workflow_client_search(&$form_state,$terms=null,$process_id=null,$collection=null)
{
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
$form = array();
$form['process_name'] = array(
'#type' => 'textfield',
'#required'=> TRUE,
'#title' => t('Search by Process Name'),
'#default_value' => ($terms!=null?$terms:''),
'#description' => t('Returns a list of objects that match the process name(s) entered. Separate multiple names by spaces.'),
);
$form['process_id'] = array(
'#type' => 'textfield',
'#title' => t('Search by Process ID'),
'#default_value' => ($process_id!=null?$process_id:''),
'#description' => t('Returns only objects that match the also match the process id entered. '),
);
$form['collection_pid'] = array(
'#type' => 'textfield',
'#title' => t('Search by Collection PID'),
'#default_value' => ($collection!=null?$collection:''),
'#description' => t('Returns only objects that match the also match the collection pid(s) entered. Separate multiple PIDs by spaces.'),
);
$form['submit'] = array('#type' => 'submit', '#value' => t('Search'));
return $form;
}
function islandora_workflow_client_manage($terms = null, $process_id= null, $collection = null, $queue= null, $queueProcess = null)
{
if ($collection == 'none' || $collection == '-') {
$collection = null;
}
if ($process_id == 'none' || $process_id == '-') {
$process_id = null;
}
$output = '';
if (trim($terms) != '')
{
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'islandora_workflow_client', 'workflow');
if (module_load_include('php', 'islandora_solr_search', 'Solr/Service') === FALSE)
{
drupal_set_message(t('Error: Islandora_solr_search module is required to search by process.'));
} else
{
$host = variable_get('islandora_solr_search_block_host','localhost');
$port = variable_get('islandora_solr_search_block_port','8080');
$appName = variable_get('islandora_solr_search_block_app_name','solr');
$solr = new Apache_Solr_Service($host, $port, '/'.$appName.'/');
try
{
if ($solr->ping())
{
$q = preg_split('/\s+/',$terms);
foreach ($q as $key=>$bit)
{
$q[$key]='workflow_process_t:'.htmlentities($bit);
}
$query = join(' OR ',$q);
if (trim($collection) != '')
{
$q= preg_split('/\s/',$collection);
foreach ($q as $key=>$bit)
{
$q[$key]='related_item_identifier_t:'.htmlentities(preg_replace('/\:/','/',$bit));
}
$query .= ' AND ('. join(' OR ',$q).')';
}
$results = $solr->search($query,0,100);
$pids=array();
$processes = array();
if ($results->response->numFound ==0 )
{
drupal_set_message(t('No processes found.'));
} else
{
foreach($results->response->docs as $doc)
{
$id = preg_replace('/\//',':',$doc->id);
$collection_pid = preg_replace('/\//',':',$doc->related_item_identifier_t);
$pids[]=$id;
if (!is_array($doc->workflow_process_t))
{
if (!is_array($processes[$doc->workflow_process_t]))
$processes[$doc->workflow_process_t]=array($id);
else
$processes[$doc->workflow_process_t][]=$id;
} else
{
foreach ($doc->workflow_process_t as $process)
{
if (!is_array($processes[$process]))
$processes[$process]=array($id);
else
$processes[$process][]=$id;
}
}
}
}
$workflows=array();
foreach ($pids as $pid)
{
$workflows[$pid]=Workflow::loadFromObject($pid);
}
if (count($processes) > 0)
{
$errors=array();
$headers = array('Process Name', '# Waiting to Run', '# Completed', '# Errors', 'Action');
$rows=array();
foreach ($processes as $name=>$pids)
{
$errCount = 0;
$waitCount =0;
$completeCount = 0;
$display = false;
foreach ($pids as $pid)
{
if ( isset($workflows[$pid]) && $workflows[$pid] !== false )
{
$display = true;
$procs = $workflows[$pid]->getProcesses();
$updated = FALSE;
foreach ($procs as $id=>$n)
{
if ($process_id == null || $id == $process_id)
{
if ($name == $n)
{
$proc=$workflows[$pid]->getProcess($id);
if (($queue == 'queue'|| ($queue =='errorQueue' && $proc['state'] == 'error')) && $queueProcess == $n)
{
$workflows[$pid]->setState($id,'waiting');
$updated=TRUE;
}
switch ($proc['state'])
{
case 'completed':
$completeCount++;
break;
case 'waiting':
$waitCount++;
break;
case 'error':
$errCount++;
$errors[]=$proc;
break;
}
}
}
if ($updated)
{
$workflows[$pid]->saveToFedora();
}
}
}
}
if ($display) {
$rows[]= array($name, $waitCount,$completeCount,$errCount,
l('Add All to Queue','admin/settings/workflow_client/'.$terms.'/'.(trim($process_id)==''?'none':$process_id).'/'.(trim($collection)==''?'none':$collection).'/queue/'.$name).'
'.
l('Add Errors to Queue','admin/settings/workflow_client/'.$terms.'/'.(trim($process_id)==''?'none':$process_id).'/'.(trim($collection)==''?'none':$collection).'/errorQueue/'.$name));
}
}
if ($queue == 'queue' || $queue == 'errorQueue')
{
drupal_goto('admin/settings/workflow_client/'.$terms.(trim($collection)==''?'/'.$collection:''));
}
$output.='
'.$dump.'',array(),WATCHDOG_NOTICE); } }