13 use Symfony\Component\HttpFoundation\Request;
17 const NAME =
"agent_add";
19 public function __construct()
21 parent::__construct(self::NAME, array(
22 self::TITLE => _(
"Schedule an Analysis"),
23 self::MENU_LIST =>
"Jobs::Schedule Agents",
32 protected function handle(Request $request)
34 $folderId = intval($request->get(
'folder'));
35 if (empty($folderId)) {
38 $uploadId = intval($request->get(
'upload'));
39 $agents = $request->get(
'agents') ?:
'';
42 if (! empty($uploadId) && ! empty($agents) && is_array($agents)) {
43 $rc = $this->
agentsAdd($uploadId, $agents, $request);
44 if (is_numeric($rc)) {
46 $scheduler_msg = empty($status) ? _(
"Is the scheduler running? ") :
'';
48 $text = _(
"Your jobs have been added to job queue.");
49 $linkText = _(
"View Jobs");
50 $msg =
"$scheduler_msg" .
"$text <a href=\"$url\">$linkText</a>";
51 $vars[
'message'] = $msg;
53 $text = _(
"Scheduling of Agent(s) failed: ");
54 $vars[
'message'] = $text.$rc;
60 $vars[
'folderId'] = $folderId;
64 $vars[
'uploadId'] = $uploadId;
66 $parmAgentList = MenuHook::getAgentPluginNames(
"ParmAgents");
69 foreach ($parmAgentList as $parmAgent) {
71 $out .=
"<br/><b>".$agent->AgentName.
":</b><br/>";
72 $out .= $agent->renderContent($vars);
73 $parmAgentFoots .= $agent->renderFoot($vars);
77 $vars[
'outFoot'] =
'<script language="javascript"> '.$parmAgentFoots.
'</script>';
79 return $this->
render(
'agent_adder.html.twig', $this->mergeWithDefault($vars));
88 private function agentsAdd($uploadId, $agentsToStart, Request $request)
90 $mimetypeIgnore = intval($request->get(
'scm') == 1) ?
'-I' :
'';
91 if (! is_array($agentsToStart)) {
92 return "bad parameters";
95 return "agent-add.php AgentsAdd(): No upload_pk specified";
99 $upload = $GLOBALS[
'container']->get(
'dao.upload')->getUpload($uploadId);
100 if ($upload===
null) {
101 return _(
"Upload") .
" " . $uploadId .
" " . _(
"not found");
104 $parmAgentList = MenuHook::getAgentPluginNames(
"ParmAgents");
105 $plainAgentList = MenuHook::getAgentPluginNames(
"Agents");
106 $agentList = array_merge($plainAgentList, $parmAgentList);
107 foreach ($agentList as $agentName) {
108 if (in_array($agentName, $agentsToStart)) {
113 $jobId = JobAddJob(Auth::getUserId(), Auth::getGroupId(), $upload->getFilename(), $uploadId);
115 foreach ($parmAgentList as $parmAgent) {
117 $agent->scheduleAgent($jobId, $uploadId, $errorMsg, $request);
120 foreach ($agents as &$agent) {
121 if (!empty($mimetypeIgnore)) {
122 $rv = $agent->AgentAdd($jobId, $uploadId, $errorMsg,
123 array(
"agent_mimetype"), $mimetypeIgnore, $request);
125 $rv = $agent->AgentAdd($jobId, $uploadId, $errorMsg, array(),
null,
144 return $this->
agentsAdd($uploadId, $agentsToStart, $request);
agentsAdd($uploadId, $agentsToStart, Request $request)
Add an upload to multiple agents.
scheduleAgents($uploadId, $agentsToStart, Request $request)
Add an upload to multiple agents (wrapper for agentsAdd()).
Contains the constants and helpers for authentication of user.
render($templateName, $vars=null, $headers=null)
ActiveHTTPscript($RequestName, $IncludeScriptTags=1)
Given a function name, create the JavaScript needed for doing the request.
FolderListOption($ParentFolder, $Depth, $IncludeTop=1, $SelectId=-1, $linkParent=false, $OldParent=0)
Create the folder tree, using OPTION tags.
FolderGetTop()
DEPRECATED! Find the top-of-tree folder_pk for the current user.
FolderListUploads_perm($ParentFolder, $perm)
Returns an array of uploads in a folder.
Traceback_uri()
Get the URI without query to this location.
plugin_find($pluginName)
Given the official name of a plugin, return the $Plugins object.
GetRunnableJobList()
Get runnable job list, the process is below:
#define PERM_WRITE
Read-Write permission.