Radicore Forum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » RADICORE development » Workflow » How to redirect to another url in batch ?
How to redirect to another url in batch ? [message #4214] Wed, 04 June 2014 22:58 Go to next message
rainfallwu is currently offline  rainfallwu
Messages: 8
Registered: May 2014
Junior Member
Hi Tony:

We use Radicore on such situation: A batch run on radicore listenning for something happen , when it happened ,the workflow start.
The problem is, when the workflow start, we can't find a way radicore can redirect to another pages(which is the 2nd task in the workflow) from batch,thus the workflow can not be processed.
Can you tell me how to redirect from batch also carrying the session along?

Thanks!
Re: How to redirect to another url in batch ? [message #4217 is a reply to message #4214] Thu, 05 June 2014 04:11 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
Can you give me a copy of your workflow definition? By that I mean the contents of the wf_workflow, wf_place, wf_arc and wf_transition tables.

Re: How to redirect to another url in batch ? [message #4218 is a reply to message #4217] Thu, 05 June 2014 05:00 Go to previous messageGo to next message
rainfallwu is currently offline  rainfallwu
Messages: 8
Registered: May 2014
Junior Member
We use the sequence workflow just like add person->add address->update address. But we want to run the step of add person using batch. Now we find that after finishing the add person ,the add address.php can't run.
Re: How to redirect to another url in batch ? [message #4221 is a reply to message #4218] Thu, 05 June 2014 05:52 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
Can you send me the script which does the 'add person' in batch? I will have to run it on my local PC to see what it does.

Re: How to redirect to another url in batch ? [message #4222 is a reply to message #4221] Thu, 05 June 2014 05:57 Go to previous messageGo to next message
rainfallwu is currently offline  rainfallwu
Messages: 8
Registered: May 2014
Junior Member
We modified some code, thanks!
<?php
//*****************************************************************************
// Allow a new occurrence to be added to the PERSON table.
//*****************************************************************************

//DebugBreak();

$stdout = '../logs/test_x_person.html';
$csvout = '../logs/test_x_person.csv';

ini_set('include_path', '.');
require 'std.batch.inc';

batchInit(__FILE__);


$table_id = 'test_x_person';					// table name
$screen   = 'test_person.detail.screen.inc'; // file identifying screen structure


require_once 'include.general.inc';

// identify mode for xsl file
$mode = 'insert';

// add by wushan 0603
//$uri="http://192.168.131.68/radicore/xample/person_add.php?";

// load session variables
initSession();



if (isset($_POST['quit'])) {
    // cancel this screen, return to previous screen
    scriptPrevious(null, null, 'quit');
} // if

// define action buttons
$act_buttons['submitBtn']  = 'submit';  // do not use name 'submit' as this conflicts with javascript 'submit()' function.
$act_buttons['submitstay'] = 'submitstay';
$act_buttons['copy']       = 'copy';
$act_buttons['quit']       = 'cancel';


// create a class instance for the main database table
require_once "classes/$table_id.class.inc";

if (isset($script_vars['dbobject'])) {
    // use data from previous instance for this script
    $dbobject = unserialize($script_vars['dbobject']);
    if (!empty($return_from)) {
        // see if any action is required when being restarted
        $dbobject->restart($return_from, $return_action, $return_string);
    } // if
    // get data from previous instance
    $fieldarray = $dbobject->getFieldArray();
} else {
    // create new instance for initial activation of this script
    $dbobject = new $table_id;
    // indicate that this object was started from a page controller
    $dbobject->initiated_from_controller = true;
    $dbobject->setRowsPerPage(1);  // scroll through one item at a time
    // get initial data for a new record
    $where = $dbobject->initialise($where, $selection);
    if (empty($dbobject->errors)) {
        $fieldarray = $dbobject->getInitialData($where);
    } // if
    if ($dbobject->errors) {
        scriptPrevious($dbobject->getErrors(), $dbobject->getMessages());
    } // if
} // if

$i =28;
//while(1)
//{
$i = $i +1 ;
$fieldarray=array("person_id"=>$i ,"nat_ins_no"=>$i ,"pers_type_id"=>$i ,"node_id"=>"2","star_sign"=>"Can");
$_POST=$fieldarray;
    $fieldarray = $dbobject->updateFieldArray($fieldarray, $_POST);
    if ($dbobject->errors) {
        $errors = $dbobject->getErrors();
    } // if
 $dbobject->startTransaction();
	$fieldarray = $dbobject->insertRecord($fieldarray);  // add this data to the database
	$messages   = array_merge($messages, $dbobject->getMessages());
	if ($dbobject->errors) {
		$errors = $dbobject->getErrors();
	} // if
	if (empty($errors)) {
		$errors = $dbobject->commit();
		if (empty($errors)) {
			$messages[] = getLanguageText('sys0080'); // 'Record inserted OK'
			if (isset($_POST['submitstay'])) {
				// re-initialise data for a new record
				$fieldarray = $dbobject->getInitialData($where);
				// get any extra data and merge with $fieldarray
				$fieldarray = $dbobject->getExtraData($fieldarray, $where);
				if (isset($_SESSION['script_sequence'])) {
					$script_vars['dbobject'] = serialize($dbobject);
					// do other tasks before returning to this one
					scriptNext($task_id);
				} // if
			} else {
				// update was OK - return to previous screen
				$selection = array2where($fieldarray, $dbobject->getPkeyNamesAdjusted());
				$prev_script = getPreviousScript();
				$prev_task   = getPreviousTask($prev_script);
				$_SESSION['pages'][$prev_script][$prev_task]['selection'] = $selection;
				$messages = array_merge($messages, $dbobject->getMessages());
				scriptPrevious(null, $messages, 'insert', $dbobject->getInstruction(), $selection);
			} // if
		} // if
	} else {
		$dbobject->rollback();
	} // if
	//sleep(10);
//}

if ($_SERVER['REQUEST_METHOD'] == 'GET') {
    // check if we are returning from a child form where something has been selected
    if (!empty($return_from) AND isset($selection) ) {
        // merge previous saved variables with selection from popup form
        $fieldarray = $dbobject->popupReturn($fieldarray, basename($return_from), $selection);
        if ($dbobject->errors) {
            $errors = $dbobject->getErrors();
        } // if
    } // if
    // get any extra data and merge with $fieldarray
    $fieldarray = $dbobject->getExtraData($fieldarray);
} // if

if (isset($_SESSION['data'][$table_id])) {
    // saved data exists, so allow a PASTE button
    $prepend = array('paste' => 'paste');
    $act_buttons = array_merge($prepend, $act_buttons);
} // if

$messages = array_merge($messages, $dbobject->getMessages());

// save these variables for later in the same session
$script_vars['where']    = $where;
$script_vars['dbobject'] = serialize($dbobject);
$script_vars = updateScriptVars ($script_vars);

$dbobject->fieldarray = $fieldarray;  // replace data lost during serialization

if ($_SERVER['REQUEST_METHOD'] == 'POST' AND empty($errors) AND !$button) {
    // repeat current task with GET instead of POST
    scriptNext($GLOBALS['task_id'], $where);
} // if

if (!empty($errors)) {
    // all errors are associated with this table
	$errors2[$dbobject->getClassName()] = $errors;
	$errors = $errors2;
} // if

//$url = person_addr_add.php
//Header("HTTP/1.1 303 See Other");
// header('HTTP/1.0 401 Authorized');
//Header("Location: $url");
//Header("Location: http://192.168.131.68/radicore/xample/person_addr_add.php?session_name=".session_name());
//http://localhost/radicore/xample/person_add.php?session_name=menu3





//require 'std.add1.inc';                 // activate page controller

batchEnd();
?>


Re: How to redirect to another url in batch ? [message #4224 is a reply to message #4222] Thu, 05 June 2014 11:05 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
Your script is totally wrong as you have copied the code from an ADD1 pattern which is designed to accept input from an HTML form. A batch job can only accept input from a disk file which can contain any number of records. I have tried the following script in my test environment and it works perfectly:

This script is called 'takeon_person(batch).php' with a task_id of 'takeon_person(batch)':
<?php
//*****************************************************************************
// this uploads data from a CSV file to the XAMPLE database
//*****************************************************************************

$stdout = '../logs/person_csv.html';

ini_set('include_path', '.');
require 'std.batch.inc';

batchInit(__FILE__);

$task_id = basename($task_id, '.php');  // replaces 'batch'
$role_id = 'DEMO';                      // replaces 'batch'

$filename = 'files/upload/person.csv';

$dbobject = RDCsingleton::getInstance('x_person');

// do not fail if record already exists when inserting
$dbobject->no_duplicate_error = TRUE;

require('std.csv.class.inc');
$CSVobj = new csv_class($dbobject);

// read first line to obtain delimiter (comma, tab or pipe)
$CSVobj->open_read($filename);
check_errors($CSVobj);

$count = 0;
while ($data = $CSVobj->read_file()) {
	// give this array to the database object
	$dbobject->startTransaction();
    $data = $dbobject->insertRecord($data);
    check_errors($dbobject);
    $dbobject->commit();
    $count ++;
    $key = 'person_id= ' .$data['person_id'];
    if ($dbobject->numrows == 0) {
    	$output = "<p>$count : $key already exists</p>\r\n";
    } else {
        $output = "<p>$count : $key created</p>\r\n";
    } // if
    if (!$result = fwrite($stdouth, $output)) {
        trigger_error("Cannot write to file $stdout", E_USER_ERROR);
    } // if
    $output = '';
} // while
check_errors($CSVobj);

$output = "<p>$count records processed.<p>";
if (!$result = fwrite($stdouth, $output)) {
    trigger_error("Cannot write to file $stdout", E_USER_ERROR);
} // if

fclose($handle);

batchEnd();

?>


The person.csv file has the following format:

"person_id","first_name","last_name","nat_ins_no","pers_type_id ","node_id","star_sign"
"test_01","test_01","test_01","test_01","MAD","2", "CAN"



Re: How to redirect to another url in batch ? [message #4225 is a reply to message #4224] Thu, 05 June 2014 21:37 Go to previous messageGo to next message
rainfallwu is currently offline  rainfallwu
Messages: 8
Registered: May 2014
Junior Member
Thanks. According to the workflow, after finishing this 'add_person' task, the task of person_addr_add should run. But this task don't run. the code of person_addr_add.php below:
------------------------------------------------------------ ------------------------------------------------------------ ---------------------------
<?php


$stdout = '../logs/x_person_addr.html';
$csvout = '../logs/x_person_addr.csv';
ini_set('include_path', '.');
require 'std.batch.inc';

batchInit(__FILE__);
$table_id = 'x_person_addr'; // table name
$task_id = basename($task_id, '.php'); // replaces 'batch'
$role_id = 'DEMO'; // replaces 'batch'

$filename = 'E:\xampp\htdocs\files\upload\addr.csv';

$dbobject = RDCsingleton::getInstance('x_person_addr');

// do not fail if record already exists when inserting
$dbobject->no_duplicate_error = TRUE;

require('std.csv.class.inc');
$CSVobj = new csv_class($dbobject);

// read first line to obtain delimiter (comma, tab or pipe)
$CSVobj->open_read($filename);
check_errors($CSVobj);

$count = 0;
while ($data = $CSVobj->read_file()) {
// give this array to the database object
$dbobject->startTransaction();
print('************************');
print_r($data);
print('************************');
$data = $dbobject->insertRecord($data);
check_errors($dbobject);
$dbobject->commit();
$count ++;

if (!$result = fwrite($stdouth, $output)) {
trigger_error("Cannot write to file $stdout", E_USER_ERROR);
} // if
$output = '';
} // while
check_errors($CSVobj);



$output = "<p>$count records processed.<p>";
if (!$result = fwrite($stdouth, $output)) {
trigger_error("Cannot write to file $stdout", E_USER_ERROR);
} // if

fclose($handle);

batchEnd();

?>


the addr.csv file is:
person_id,address_no,addr_line_1,town,postcode
test_100,tst100addr,hahaStreet,London,EH1 4AS

the person.csv file is:
person_id,nat_ins_no,pers_type_id,node_id,star_sign
test_100,tes100,test10,2,CAN


[Updated on: Thu, 05 June 2014 21:47]

Report message to a moderator

Re: How to redirect to another url in batch ? [message #4234 is a reply to message #4225] Fri, 06 June 2014 04:27 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
Did you set the transition_trigger for the 'Add Person Address' task to 'auto'? If you didn't it will just sit in the queue which is displayed on the Home Page and wait for someone to click on the link.

Re: How to redirect to another url in batch ? [message #4237 is a reply to message #4234] Fri, 06 June 2014 05:27 Go to previous messageGo to next message
rainfallwu is currently offline  rainfallwu
Messages: 8
Registered: May 2014
Junior Member
yes, it is set to 'auto'.

is the 'add address' script has some error? it can't run automatically
  • Attachment: 1.png
    (Size: 5.75KB, Downloaded 1473 times)
Re: How to redirect to another url in batch ? [message #4239 is a reply to message #4237] Fri, 06 June 2014 05:49 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
I have a suspicion that your 'Add Address' task is trying to run a version of the ADD2 pattern in batch, which is totally wrong. That is why I provided you with a different script for the 'Add Person' task.

It appears that you are trying to run a complete workflow as a set of batch programs which is *NOT* what it was designed to do. If you wish to load person details from a CSV file then you can accomplish this in a single script. If all the input cannot fit into a single CSV file then you can process data from multiple files one after the other in the same script.


Re: How to redirect to another url in batch ? [message #4248 is a reply to message #4239] Sun, 08 June 2014 20:49 Go to previous messageGo to next message
rainfallwu is currently offline  rainfallwu
Messages: 8
Registered: May 2014
Junior Member
Yep.We want to use Radicore as an engine to run a set of batch programs to finish workflow.

if 'Add person' and 'add address' are both batch file, and the transition is set to 'Auto', can 'add address' script be run automatically after 'add person' script? Or do I need to make some modification to achieve this?

Re: How to redirect to another url in batch ? [message #4249 is a reply to message #4248] Mon, 09 June 2014 04:05 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
I repeat, the workflow system was not designed to run a series of tasks in batch mode. A workflow is supposed to have one or more manual tasks which prompt a user for action. Batch jobs which load data from CSV files do not wait for user action as they expect to read from a disk file. If you want to load person details and person address details from a batch file then I suggest you combine those into a single batch job. I would also suggest that you combine the person and person address details into a single file to avoid the problem where the job looks for a second file which isn't there.

Re: How to redirect to another url in batch ? [message #4437 is a reply to message #4249] Sun, 10 August 2014 22:31 Go to previous message
rainfallwu is currently offline  rainfallwu
Messages: 8
Registered: May 2014
Junior Member
settled ,thanks!
Previous Topic: Having problem starting a case
Next Topic: Work item assignments
Goto Forum:
  


Current Time: Tue Dec 03 11:38:55 EST 2024

Total time taken to generate the page: 0.01354 seconds