31 use Symfony\Component\HttpFoundation\RedirectResponse;
32 use Symfony\Component\HttpFoundation\Response;
34 define(
"TITLE_CLEARINGVIEW", _(
"Change concluded License "));
49 private $highlightDao;
51 private $highlightProcessor;
53 private $highlightRenderer;
55 private $clearingDecisionEventProcessor;
57 private $clearingDecisionFilter;
59 private $invalidParm =
false;
61 private $decisionTypes;
63 private $searchChunkSize = 1048576;
65 private $searchBlockSize = 81920;
69 $this->Name =
"view-license";
70 $this->Title = TITLE_CLEARINGVIEW;
72 $this->Dependency = array(
"view");
75 parent::__construct();
78 $this->licenseDao = $container->get(
'dao.license');
79 $this->uploadDao = $container->get(
'dao.upload');
80 $this->clearingDao = $container->get(
'dao.clearing');
81 $this->agentsDao = $container->get(
'dao.agent');
82 $this->logger = $container->get(
"logger");
83 $this->highlightDao = $container->get(
"dao.highlight");
84 $this->highlightRenderer = $container->get(
"view.highlight_renderer");
85 $this->highlightProcessor = $container->get(
"view.highlight_processor");
87 $this->decisionTypes = $container->get(
'decision.types');
89 $this->clearingDecisionEventProcessor = $container->get(
90 'businessrules.clearing_decision_processor');
91 $this->clearingDecisionFilter = $container->get(
92 'businessrules.clearing_decision_filter');
107 $unmaskAgents = $selectedAgentId;
108 if (empty($selectedAgentId)) {
109 $scanJobProxy =
new ScanJobProxy($this->agentsDao,$uploadId);
110 $scanJobProxy->createAgentStatus(array_keys(AgentRef::AGENT_LIST));
111 $unmaskAgents = $scanJobProxy->getLatestSuccessfulAgentIds();
113 $highlightEntries = $this->highlightDao->getHighlightEntries($itemTreeBounds,
114 $licenseId, $unmaskAgents, $highlightId, $clearingId);
115 $groupId = Auth::getGroupId();
116 if (($selectedAgentId > 0) || ($clearingId > 0)) {
117 $this->highlightProcessor->addReferenceTexts($highlightEntries, $groupId);
119 $this->highlightProcessor->flattenHighlights($highlightEntries, array(
"K",
"K "));
121 return $highlightEntries;
124 public function execute()
127 if ($openOutput instanceof RedirectResponse) {
128 $response = $openOutput;
138 if ($this->
State != PLUGIN_STATE_READY) {
142 if (empty($uploadId)) {
147 if (empty($uploadTreeId)) {
148 $parent = $this->uploadDao->getUploadParent($uploadId);
149 if (!isset($parent)) {
150 $this->invalidParm =
true;
154 $item = $this->uploadDao->getNextItem($uploadId, $parent);
155 if ($item === UploadDao::NOT_FOUND) {
156 $this->invalidParm =
true;
159 $uploadTreeId = $item->getId();
160 return new RedirectResponse(
Traceback_uri() .
'?mod=' . $this->Name
164 $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId);
165 $uploadEntry = $this->uploadDao->getUploadEntry($uploadTreeId, $uploadTreeTableName);
166 if (
Isdir($uploadEntry[
'ufile_mode']) ||
Iscontainer($uploadEntry[
'ufile_mode'])) {
167 $parent = $this->uploadDao->getUploadParent($uploadId);
168 if (!isset($parent)) {
169 $this->invalidParm =
true;
173 $item = $this->uploadDao->getNextItem($uploadId, $parent);
174 if ($item === UploadDao::NOT_FOUND) {
175 $this->invalidParm =
true;
178 $uploadTreeId = $item->getId();
179 return new RedirectResponse(
Traceback_uri() .
'?mod=' . $this->Name
183 return parent::OutputOpen();
192 if ($this->invalidParm) {
193 $this->vars[
'content'] =
'This upload contains no files!<br><a href="'
194 .
Traceback_uri() .
'?mod=browse">Go back to browse view</a>';
195 return $this->
render(
"include/base.html.twig");
199 if (empty($uploadId)) {
200 return new Response(
"", Response::HTTP_BAD_REQUEST);
203 if (empty($uploadTreeId)) {
204 return new Response(
"", Response::HTTP_BAD_REQUEST);
207 $userId = Auth::getUserId();
208 $groupId = Auth::getGroupId();
212 if (!empty($lastItem)) {
213 $currentUploadtreeId = $lastItem;
214 if ($lastItem == $uploadTreeId) {
215 $currentUploadtreeId = $uploadTreeId;
217 $this->
updateLastItem($userId, $groupId, $lastItem, $currentUploadtreeId);
220 $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId);
221 $itemTreeBounds = $this->uploadDao->getItemTreeBounds($uploadTreeId, $uploadTreeTableName);
223 $this->vars[
'micromenu'] =
Dir2Browse(
'license', $uploadTreeId, NULL,
224 $showBox = 0,
"View", -1,
'',
'', $uploadTreeTableName);
228 $view = &$Plugins[plugin_find_id(
"view")];
236 $this->vars[
'searchQuery'] = $searchQuery;
237 $this->vars[
'searchMatches'] = [];
240 if ($clearingId !==
null) {
242 }
else if ($highlightId !==
null) {
247 $this->vars[
'baseuri'] = $baseUri;
248 $this->vars[
'uri'] = $baseUri .
"?mod=" . $this->Name .
Traceback_parm_keep(array(
'upload',
'folder'));
249 $this->vars[
'bulkHistoryHighlightUri'] = $this->vars[
'uri'];
250 $this->vars[
'kotobaHistoryHighlightUri'] = $this->vars[
'uri'];
251 $this->vars[
'optionName'] =
"skipFile";
252 $this->vars[
'formName'] =
"uiClearingForm";
253 $this->vars[
'ajaxAction'] =
"setNextPrev";
255 $selectedAgentId, $highlightId, $clearingId, $uploadId);
256 if (empty($searchQuery)) {
259 $searchQuery = $request->query->get(
'search',
'');
262 if (!empty($searchQuery)) {
263 $searchQuery =
trim($searchQuery);
264 if (strlen($searchQuery) < 3) {
265 $this->vars[
'searchMatches'] = [];
270 if ($filePath && file_exists($filePath)) {
271 $this->vars[
'searchMatches'] = $this->
getSearchMatches($filePath, $searchQuery, $this->searchBlockSize);
273 $this->vars[
'searchMatches'] = [];
278 $isSingleFile = !$itemTreeBounds->containsFiles();
279 $hasWritePermission = $this->uploadDao->isEditable($uploadId, $groupId);
281 $clearingDecisions =
null;
282 if ($isSingleFile || $hasWritePermission) {
283 $clearingDecisions = $this->clearingDao->getFileClearings($itemTreeBounds, $groupId,
false);
286 if ($isSingleFile && $hasWritePermission) {
287 $this->vars[
'bulkUri'] =
Traceback_uri() .
"?mod=popup-license";
288 $licenseArray = $this->licenseDao->getLicenseArray($groupId);
289 list($addedResults, $removedResults) = $this->clearingDecisionEventProcessor->getCurrentClearings($itemTreeBounds, $groupId, LicenseMap::CONCLUSION);
290 if (count($addedResults)+count($removedResults)>0) {
291 array_unshift($licenseArray, array(
'id'=>0,
'fullname'=>
'',
'shortname'=>
'------'));
294 foreach ($removedResults as $result) {
295 array_unshift($licenseArray, array(
'id'=>$result->getLicenseId() ,
'fullname'=>$result->getLicenseFullName() ,
'shortname'=>$result->getLicenseShortName()));
298 foreach ($addedResults as $result) {
299 array_unshift($licenseArray, array(
'id'=>$result->getLicenseId() ,
'fullname'=>$result->getLicenseFullName() ,
'shortname'=>$result->getLicenseShortName()));
301 $this->vars[
'licenseArray'] = $licenseArray;
302 } elseif ($isSingleFile) {
303 $this->vars[
'auditDenied'] =
true;
306 $selectedClearingType =
false;
307 $selectedClearingScope =
false;
308 if (!empty($clearingDecisions)) {
309 $selectedClearingType = $clearingDecisions[0]->getType();
310 $selectedClearingScope = $clearingDecisions[0]->getScope();
312 $bulkHistory = $this->clearingDao->getBulkHistory($itemTreeBounds, $groupId);
313 $hasKotobaFindings = $this->clearingDao->hasKotobaFindings($itemTreeBounds, $groupId);
314 $kotobaHistory = array();
315 if ($hasKotobaFindings) {
316 $kotobaHistory = $this->clearingDao->getKotobaHistory($itemTreeBounds, $groupId);
320 list($pageMenu, $textView) = $view->getView(NULL, $ModBack, 0,
"", $highlights,
false,
true);
322 $this->vars[
'uploadId'] = $uploadId;
323 $this->vars[
'itemId'] = $uploadTreeId;
324 $this->vars[
'pageMenu'] = $pageMenu;
325 $this->vars[
'textView'] = $textView;
326 $this->vars[
'legendData'] = $this->highlightRenderer->getLegendData($selectedAgentId || $clearingId);
327 $this->vars[
'clearingTypes'] = $this->decisionTypes->getMap();
328 $this->vars[
'selectedClearingType'] = $selectedClearingType;
329 $this->vars[
'selectedClearingScope'] = $selectedClearingScope;
330 $this->vars[
'tmpClearingType'] = $this->clearingDao->isDecisionCheck($uploadTreeId, $groupId, DecisionTypes::WIP);
331 $this->vars[
'bulkHistory'] = $bulkHistory;
332 $this->vars[
'hasKotobaFindings'] = $hasKotobaFindings;
333 $this->vars[
'kotobaHistory'] = $kotobaHistory;
334 $this->vars[
'isAdmin'] = Auth::isAdmin();
337 array(UploadTreeProxy::OPT_SKIP_THESE =>
"noLicense",
338 UploadTreeProxy::OPT_GROUP_ID => $groupId),
339 $uploadTreeTableName,
340 'no_license_uploadtree' . $uploadId);
341 $filesOfInterest = $noLicenseUploadTreeView->count();
344 array(UploadTreeProxy::OPT_SKIP_THESE =>
"alreadyCleared",
345 UploadTreeProxy::OPT_GROUP_ID => $groupId),
346 $uploadTreeTableName,
347 'already_cleared_uploadtree' . $uploadId);
348 $filesToBeCleared = $nonClearedUploadTreeView->count();
350 $filesAlreadyCleared = $filesOfInterest - $filesToBeCleared;
351 $this->vars[
'message'] = _(
"Cleared").
": $filesAlreadyCleared/$filesOfInterest";
352 if ($filesOfInterest == 0) {
355 $percentage = ($filesAlreadyCleared / $filesOfInterest) * 100;
356 $percentage = ($percentage > 11) ? $percentage : 11;
358 $this->vars[
'progressBar'] =
"width:".$percentage.
"%";
360 return $this->
render(
"ui-clearing-view.html.twig");
368 $menuText=
"Licenses";
371 $tooltipText = _(
"Set the concluded licenses for this upload");
372 $this->microMenu->insert(array(MicroMenu::VIEW, MicroMenu::VIEW_META), $menuText, $menuPosition, $this->Name, $uri, $tooltipText );
375 menu_insert(
"Browse-Pfile::$menuText", 0, $this->Name, $tooltipText);
387 public function updateLastItem($userId, $groupId, $lastItem, $currentUploadtreeId)
391 $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($lastItem);
392 $itemBounds = $this->uploadDao->getItemTreeBounds($lastItem, $uploadTreeTableName);
394 $isDecisionWip = $this->clearingDao->isDecisionCheck($currentUploadtreeId, $groupId, DecisionTypes::WIP);
395 $hasChangedClearingType = $this->clearingDao->isDecisionCheck($currentUploadtreeId, $groupId,
'');
396 if ($isDecisionWip) {
397 $this->clearingDecisionEventProcessor->makeDecisionFromLastEvents($itemBounds, $userId, $groupId, $type, $global);
398 }
else if (empty($hasChangedClearingType[
'scope'])
399 || ($hasChangedClearingType[
'decision_type'] != $type)
401 $this->clearingDecisionEventProcessor->makeDecisionFromLastEvents($itemBounds, $userId, $groupId, $type, $global);
406 $this->clearingDecisionEventProcessor->makeDecisionFromLastEvents($itemBounds, $userId, $groupId, $type, $global);
418 $handle = fopen($filePath,
"rb");
424 $searchLen = strlen($searchQuery);
428 $pattern =
'/' . preg_quote($searchQuery,
'/') .
'/i';
430 while (!feof($handle)) {
431 $chunk = fread($handle, $this->searchChunkSize);
432 $haystack = $overlapBuffer . $chunk;
434 if (preg_match_all($pattern, $haystack, $matches, PREG_OFFSET_CAPTURE)) {
435 foreach ($matches[0] as $match) {
436 $posInHaystack = $match[1];
437 $absolutePos = $currentFilePos - strlen($overlapBuffer) + $posInHaystack;
439 if (empty($searchMatches) || end($searchMatches)[
'position'] !== $absolutePos) {
441 'position' => $absolutePos,
442 'page' => (int)floor($absolutePos / $blockSize)
448 $overlapBuffer = ($searchLen > 1) ? substr($haystack, -($searchLen - 1)) :
'';
449 $currentFilePos += strlen($chunk);
453 return $searchMatches;
getSelectedHighlighting(ItemTreeBounds $itemTreeBounds, $licenseId, $selectedAgentId, $highlightId, $clearingId, $uploadId)
RegisterMenus()
While menus can be added to any time at or after the PostInitialize phase, this is the standard locat...
OutputOpen()
This function is called when user output is requested. This function is responsible for assigning hea...
getSearchMatches($filePath, $searchQuery, $blockSize=81920)
updateLastItem($userId, $groupId, $lastItem, $currentUploadtreeId)
__construct()
base constructor. Most plugins will just use this
This is the Plugin class. All plugins should:
Output()
This function is called when user output is requested. This function is responsible for content....
render($templateName, $vars=null)
Contains the constants and helpers for authentication of user.
Various utility functions to filter ClearingDecision.
Utility functions to process ClearingDecision.
Wrapper class for license map.
Dir2Browse($Mod, $UploadtreePk, $LinkLast=NULL, $ShowBox=1, $ShowMicro=NULL, $Enumerate=-1, $PreText='', $PostText='', $uploadtree_tablename="uploadtree")
Get an html linked string of a file browse path.
Traceback_uri()
Get the URI without query to this location.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Traceback_parm_keep($List)
Create a new URI, keeping only these items.
RepPathItem($Item, $Repo="files")
Given an uploadtree_pk, retrieve the pfile path.
char * trim(char *ptext)
Trimming whitespace.
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.