19 require_once(BASE.
"wcmf/application/controller/class.LongTaskController.php");
51 parent::initialize($request, $response);
55 if ($request->getAction() ==
'continue')
58 if ($session->exist($this->WORK_PACKAGES_VARNAME))
59 $this->_workPackages = $session->get($this->WORK_PACKAGES_VARNAME);
68 $session->set($this->WORK_PACKAGES_VARNAME, $tmpArray);
74 if (!isset($workPackage[
'name']) || !isset($workPackage[
'size']) ||
75 !isset($workPackage[
'oids']) || !isset($workPackage[
'callback']))
79 $this->
addWorkPackage($workPackage[
'name'], $workPackage[
'size'], $workPackage[
'oids'], $workPackage[
'callback'], $workPackage[
'args']);
84 WCMFException::throwEx(
"Error initializing BatchController: ".get_class($this).
": No work package defined.", __FILE__, __LINE__);
103 WCMFException::throwEx(
"Wrong work package description '".$name.
"': Size must be at least 1.", __FILE__, __LINE__);
106 if (sizeOf($oids) == 0)
111 if (strlen($callback) == 0)
113 WCMFException::throwEx(
"Wrong work package description '".$name.
"': No callback given.", __FILE__, __LINE__);
118 $workPackages = $session->get($this->WORK_PACKAGES_VARNAME);
121 $total = sizeOf($oids);
122 while(sizeOf($oids) > 0)
125 for($i=0; $i<$size; $i++)
127 $nextItem = array_shift($oids);
128 if($nextItem !== null)
129 array_push($items, $nextItem);
134 $end = ($counter+sizeOf($items)-1);
135 $stepsText = $counter;
136 if ($start != $end) {
137 $stepsText .=
'-'.($counter+sizeOf($items)-1);
141 $statusText = $stepsText.
'/'.$total;
144 $curWorkPackage = array(
'name' => $name.
' '.$statusText,
146 'callback' => $callback,
148 array_push($workPackages, $curWorkPackage);
151 $session->set($this->WORK_PACKAGES_VARNAME, $workPackages);
152 $session->set($this->NUM_STEPS_VARNAME, sizeOf($workPackages));
154 $this->_workPackages = $workPackages;
168 WCMFException::throwEx(
"getWorkPackage() must be implemented by derived class: ".get_class($this), __FILE__, __LINE__);
176 return $session->get($this->NUM_STEPS_VARNAME);
183 return Message::get(
"Processing").
" ".$this->_workPackages[$step-1][
'name'].
" ...";
202 $curWorkPackageDef = $this->_workPackages[$this->
getStepNumber()-1];
203 if (strlen($curWorkPackageDef[
'callback']) == 0) {
208 if (!method_exists($this, $curWorkPackageDef[
'callback']))
209 WCMFException::throwEx(
"Method '".$curWorkPackageDef[
'callback'].
"' must be implemented by ".get_class($this), __FILE__, __LINE__);
211 call_user_method($curWorkPackageDef[
'callback'], $this, $curWorkPackageDef[
'oids'], $curWorkPackageDef[
'args']);
LongTaskController is a controller that may be used as base class for tasks, that require a long exec...
get($message, $parameters=null, $domain='', $lang='')
initialize(&$request, &$response)
throwEx($message, $file='', $line='')
addWorkPackage($name, $size, $oids, $callback, $args=null)
BatchController allows to define work packages that will be processed in a sequence. It simplifies the usage of LongTaskController functionality for splitting different bigger tasks into many smaller (similar) tasks where the whole number of tasks isn't known at designtime.