28 const NAME =
"agent_add";
30 public function __construct()
32 parent::__construct(self::NAME, array(
33 self::TITLE => _(
"Schedule an Analysis"),
34 self::MENU_LIST =>
"Jobs::Schedule Agents",
43 protected function handle(Request $request)
45 $folderId = intval($request->get(
'folder'));
46 if (empty($folderId)) {
49 $uploadId = intval($request->get(
'upload'));
50 $agents = $request->get(
'agents') ?:
'';
53 if (! empty($uploadId) && ! empty($agents) && is_array($agents)) {
54 $rc = $this->
agentsAdd($uploadId, $agents, $request);
55 if (is_numeric($rc)) {
57 $scheduler_msg = empty($status) ? _(
"Is the scheduler running? ") :
'';
59 $text = _(
"Your jobs have been added to job queue.");
60 $linkText = _(
"View Jobs");
61 $msg =
"$scheduler_msg" .
"$text <a href=\"$url\">$linkText</a>";
62 $vars[
'message'] = $msg;
64 $text = _(
"Scheduling of Agent(s) failed: ");
65 $vars[
'message'] = $text.$rc;
71 $vars[
'folderId'] = $folderId;
75 $vars[
'uploadId'] = $uploadId;
77 $parmAgentList = MenuHook::getAgentPluginNames(
"ParmAgents");
80 foreach ($parmAgentList as $parmAgent) {
82 $out .=
"<br/><b>".$agent->AgentName.
":</b><br/>";
83 $out .= $agent->renderContent($vars);
84 $parmAgentFoots .= $agent->renderFoot($vars);
88 $vars[
'outFoot'] =
'<script language="javascript"> '.$parmAgentFoots.
'</script>';
90 return $this->
render(
'agent_adder.html.twig', $this->mergeWithDefault($vars));
99 private function agentsAdd($uploadId, $agentsToStart, Request $request)
101 $mimetypeIgnore = intval($request->get(
'scm') == 1) ?
'-I' :
'';
102 if (! is_array($agentsToStart)) {
103 return "bad parameters";
106 return "agent-add.php AgentsAdd(): No upload_pk specified";
110 $upload = $GLOBALS[
'container']->get(
'dao.upload')->getUpload($uploadId);
111 if ($upload===null) {
112 return _(
"Upload") .
" " . $uploadId .
" " . _(
"not found");
115 $parmAgentList = MenuHook::getAgentPluginNames(
"ParmAgents");
116 $plainAgentList = MenuHook::getAgentPluginNames(
"Agents");
117 $agentList = array_merge($plainAgentList, $parmAgentList);
118 foreach ($agentList as $agentName) {
119 if (in_array($agentName, $agentsToStart)) {
124 $jobId = JobAddJob(Auth::getUserId(), Auth::getGroupId(), $upload->getFilename(), $uploadId);
126 foreach ($parmAgentList as $parmAgent) {
128 $agent->scheduleAgent($jobId, $uploadId, $errorMsg, $request);
131 foreach ($agents as &$agent) {
132 if (!empty($mimetypeIgnore)) {
133 $rv = $agent->AgentAdd($jobId, $uploadId, $errorMsg, array(
"agent_mimetype"), $mimetypeIgnore);
135 $rv = $agent->AgentAdd($jobId, $uploadId, $errorMsg, array());
153 return $this->
agentsAdd($uploadId, $agentsToStart, $request);
GetRunnableJobList()
Get runnable job list, the process is below:
agentsAdd($uploadId, $agentsToStart, Request $request)
Add an upload to multiple agents.
Traceback_uri()
Get the URI without query to this location.
FolderListOption($ParentFolder, $Depth, $IncludeTop=1, $SelectId=-1, $linkParent=false, $OldParent=0)
Create the folder tree, using OPTION tags.
FolderListUploads_perm($ParentFolder, $perm)
Returns an array of uploads in a folder.
render($templateName, $vars=null, $headers=null)
ActiveHTTPscript($RequestName, $IncludeScriptTags=1)
Given a function name, create the JavaScript needed for doing the request.
FolderGetTop()
DEPRECATED! Find the top-of-tree folder_pk for the current user.
plugin_find($pluginName)
Given the official name of a plugin, return the $Plugins object.
scheduleAgents($uploadId, $agentsToStart, Request $request)
Add an upload to multiple agents (wrapper for agentsAdd()).
#define PERM_WRITE
Read-Write permission.