13 private $kotobaDesc =
"Custom phrase analysis agent";
15 public function __construct()
17 $this->Name =
"agent_kotoba";
18 $this->Title = _(
"Kotoba Analysis <img src=\"images/info_16.png\" data-toggle=\"tooltip\" title=\"".$this->kotobaDesc.
"\" class=\"info-bullet\"/>");
19 $this->AgentName =
"kotoba";
21 parent::__construct();
30 return CheckARS($uploadId, $this->AgentName,
"kotoba scanner",
"kotoba_ars");
33 function AgentAdd($jobId, $uploadId, &$errorMsg, $dependencies=[],
34 $arguments=
null, $request=
null, $unpackArgs=
null)
37 if ($request !=
null && !is_array($request)) {
38 $unpackArgs = intval($request->get(
'scm', 0)) == 1 ?
'-I' :
'';
40 $unpackArgs = intval(@$_POST[
'scm']) == 1 ?
'-I' :
'';
50 if ($jobQueueId != 0) {
55 if (!$this->hasActiveCustomPhrases()) {
56 $errorMsg = _(
"No active custom phrases found. Please add and activate custom phrases before running the kotoba bulk agent.");
61 $baseDependencies = array();
62 if (!empty($unpackArgs)) {
63 $baseDependencies[] =
"agent_mimetype";
65 $baseDependencies[] =
"agent_adj2nest";
69 $licenseScannerAgents = array(
"agent_monk",
"agent_nomos",
"agent_ojo",
"agent_scancode");
70 foreach ($licenseScannerAgents as $agentName) {
72 if ($this->isAgentScheduledForUpload($uploadId, $agentName)) {
73 $baseDependencies[] = $agentName;
79 if (!empty($unpackArgs)) {
80 $kotobaJqId = $this->
doAgentAdd($jobId, $uploadId, $errorMsg,
81 $baseDependencies, $uploadId, $args, $request);
83 $kotobaJqId = $this->
doAgentAdd($jobId, $uploadId, $errorMsg,
84 $baseDependencies, $uploadId,
null, $request);
88 if ($kotobaJqId > 0) {
91 if ($deciderJobPlugin !==
null) {
92 $deciderJobDependencies = array(array(
'name' =>
'agent_kotoba',
'args' => $uploadId));
93 $deciderJobErrorMsg =
'';
94 $deciderJobJqId = $deciderJobPlugin->AgentAdd($jobId, $uploadId, $deciderJobErrorMsg, $deciderJobDependencies,
null, $request);
96 if (!empty($deciderJobErrorMsg)) {
97 $errorMsg .=
" DeciderJob scheduling: " . $deciderJobErrorMsg;
101 if ($deciderJobJqId > 0) {
102 return $deciderJobJqId;
114 private function hasActiveCustomPhrases()
118 $dbManager = $container->get(
'db.manager');
120 $sql =
"SELECT COUNT(*) as count FROM custom_phrase WHERE is_active = true";
121 $result = $dbManager->getSingleRow($sql);
123 return ($result[
'count'] > 0);
134 foreach ($dependencies as $dependency) {
135 if ($dependency == $agentName) {
138 if (is_array($dependency) && $agentName == $dependency[
'name']) {
151 private function isAgentScheduledForUpload($uploadId, $pluginName)
155 $dbManager = $container->get(
'db.manager');
159 if ($plugin ===
null) {
162 $agentName = $plugin->AgentName;
166 $sql =
"SELECT jq_pk FROM jobqueue, job WHERE job_pk=jq_job_fk " .
167 "AND jq_type=$1 AND job_upload_fk = $2 " .
168 "AND jq_endtime IS NULL";
169 $result = $dbManager->getSingleRow($sql, array($agentName, $uploadId));
171 return !empty($result);
doAgentAdd($jobId, $uploadId, &$errorMsg, $dependencies, $jqargs="", $jq_cmd_args=null, $request=null)
isAgentIncluded($dependencies, $agentName)
AgentAdd($jobId, $uploadId, &$errorMsg, $dependencies=[], $arguments=null, $request=null, $unpackArgs=null)
AgentHasResults($uploadId=0)
CheckARS($upload_pk, $AgentName, $AgentDesc, $AgentARSTableName)
Check the ARS table to see if an agent has successfully scanned an upload.
IsAlreadyScheduled($job_pk, $AgentName, $upload_pk)
Check if an agent is already scheduled in a job.
plugin_find($pluginName)
Given the official name of a plugin, return the $Plugins object.