-
Notifications
You must be signed in to change notification settings - Fork 481
fix(markDirectoryAsDecisionTypeRec): Properly handle clearing state when removing irrelevant decisions #3015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Squash multiple commits, Follow commit guidelines.
src/lib/php/Dao/ClearingDao.php
Outdated
$sql = $uploadTreeProxy->asCTE() . ' SELECT uploadtree_pk FROM UploadTreeView;'; | ||
$itemRows = $this->dbManager->getRows($sql, $params, __METHOD__ . ".getItemsForReset"); | ||
$uploadTreeTableName = $itemTreeBounds->getUploadTreeTableName(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DRY.
You can shift this logic outside conditional statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/lib/php/Dao/ClearingDao.php
Outdated
$options = array( | ||
UploadTreeProxy::OPT_SKIP_THESE => 'noLicense', | ||
UploadTreeProxy::OPT_ITEM_FILTER => ' AND (lft BETWEEN $1 AND $2)', | ||
UploadTreeProxy::OPT_GROUP_ID => '$' . $a | ||
); | ||
$uploadTreeProxy = new UploadTreeProxy($itemTreeBounds->getUploadId(), $options, $itemTreeBounds->getUploadTreeTableName()); | ||
if (!$removeDecision) { | ||
$sql = $uploadTreeProxy->asCTE() . | ||
' SELECT uploadtree_pk FROM UploadTreeView;'; | ||
$itemRows = $this->dbManager->getRows($sql, $params, | ||
__METHOD__ . ".getRevelantItems"); | ||
$sql = $uploadTreeProxy->asCTE() . ' SELECT uploadtree_pk FROM UploadTreeView;'; | ||
$itemRows = $this->dbManager->getRows($sql, $params, __METHOD__ . ".getRevelantItems"); | ||
$uploadTreeTableName = $itemTreeBounds->getUploadTreeTableName(); | ||
/** @var ClearingDecisionProcessor $clearingDecisionEventProcessor */ | ||
$clearingDecisionEventProcessor = $GLOBALS['container']->get( | ||
'businessrules.clearing_decision_processor'); | ||
$clearingDecisionEventProcessor = $GLOBALS['container']->get('businessrules.clearing_decision_processor'); | ||
foreach ($itemRows as $itemRow) { | ||
$itemBounds = $this->uploadDao->getItemTreeBounds( | ||
$itemRow['uploadtree_pk'], $uploadTreeTableName); | ||
$clearingDecisionEventProcessor->makeDecisionFromLastEvents( | ||
$itemBounds, $userId, $groupId, $decisionMark, DecisionScopes::ITEM); | ||
$itemBounds = $this->uploadDao->getItemTreeBounds($itemRow['uploadtree_pk'], $uploadTreeTableName); | ||
$clearingDecisionEventProcessor->makeDecisionFromLastEvents($itemBounds, $userId, $groupId, $decisionMark, DecisionScopes::ITEM); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Irrelevant beautification. Makes hard to review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing that out — I forgot to revert the automatic formatting done by the PHP Sniffer & Beautifier extension in between the actual changes. I’ll clean that up and push the corrected diff.
src/lib/php/Dao/ClearingDao.php
Outdated
$this->dbManager->getSingleRow($delCdEventSql, array($clearingDecisions), __METHOD__ . ".deleteCdEvent"); | ||
|
||
/** @var ClearingDecisionProcessor $clearingDecisionEventProcessor */ | ||
$clearingDecisionEventProcessor = $GLOBALS['container']->get('businessrules.clearing_decision_processor'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where are we using this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
used earlier , but removed now
src/lib/php/Dao/ClearingDao.php
Outdated
$clearingDecisionRows = $this->dbManager->getRows($sql, $params, | ||
__METHOD__ . ".getRelevantDecisions"); | ||
$clearingDecisions = array_map(function($x) { | ||
$clearingDecisionRows = $this->dbManager->getRows($sql, $params, __METHOD__ . ".getRelevantDecisions"); | ||
$clearingDecisions = array_map(function ($x) { | ||
return $x['clearing_decision_pk']; | ||
}, $clearingDecisionRows); | ||
$clearingDecisions = "{" . join(",", $clearingDecisions) . "}"; | ||
|
||
$delEventSql = "DELETE FROM clearing_event WHERE clearing_event_pk IN (" . | ||
"SELECT clearing_event_fk FROM clearing_decision_event " . | ||
"WHERE clearing_decision_fk = ANY($1::int[]));"; | ||
$this->dbManager->getSingleRow($delEventSql, array($clearingDecisions), | ||
__METHOD__ . ".deleteEvent"); | ||
$this->dbManager->getSingleRow($delEventSql, array($clearingDecisions), __METHOD__ . ".deleteEvent"); | ||
|
||
$delCdEventSql = "DELETE FROM clearing_decision_event WHERE " . | ||
"clearing_decision_fk = ANY($1::int[]);"; | ||
$this->dbManager->getSingleRow($delCdEventSql, array($clearingDecisions), | ||
__METHOD__ . ".deleteCdEvent"); | ||
$this->dbManager->getSingleRow($delCdEventSql, array($clearingDecisions), __METHOD__ . ".deleteCdEvent"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too much beautification for my eyes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/lib/php/Dao/ClearingDao.php
Outdated
$clearingDecisionProcessor = $GLOBALS['container']->get('businessrules.clearing_decision_processor'); | ||
|
||
$noDecisionType = $clearingDecisionProcessor::NO_LICENSE_KNOWN_DECISION_TYPE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be taken out directly from the class: ClearingDecisionProcessor
Something like: ClearingDecisionProcessor::NO_LICENSE_KNOWN_DECISION_TYPE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/lib/php/Dao/ClearingDao.php
Outdated
|
||
$sql = "INSERT INTO clearing_decision | ||
(uploadtree_fk, pfile_fk, user_fk, group_fk, decision_type, scope, date_added) | ||
SELECT $1, pfile_fk, $2, $3, $4, " . DecisionScopes::ITEM . ", now() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DecisionScopes::ITEM
can also be made a variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
created a variable for it
src/lib/php/Dao/ClearingDao.php
Outdated
$clearingDecisionProcessor = $GLOBALS['container']->get('businessrules.clearing_decision_processor'); | ||
|
||
$noDecisionType = $clearingDecisionProcessor::NO_LICENSE_KNOWN_DECISION_TYPE; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before inserting clearing decision, Check if the record already exist. To prevent duplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually here we need to ensure a fresh "no license known" decision with the current timestamp exists after removing an irrelevant flag. Simply checking for existing records would block the insertion.
The approach i implemented - deleting old "no license known" decisions and always inserting a new one - ensures proper status resetting with an up-to-date timestamp and preventing duplication as well
13aec3b
to
67a1f9a
Compare
…ing irrelevant decisions changes preventing duplication Signed-off-by: Vaibhav <sahusv4527@gmail.com> changes Signed-off-by: Vaibhav <sahusv4527@gmail.com>
67a1f9a
to
460344e
Compare
Hey @Kaushl2208, |
Description
Fixes #2215
Problem
When a file with an identified license is marked as irrelevant and then the irrelevant decision is removed, the following issues occur:
This happens because when removing a decision type, the system doesn't properly reset the file's status to its original "no decision" state.
Solution
Modified the
markDirectoryAsDecisionTypeRec
method in theClearingDao
class to properly handle the removal of decision types. When a decision type is removed, the method now:Changes
markDirectoryAsDecisionTypeRec
method to insert a null decision ("no license known") for each affected item after removing irrelevant decisionsinsertNullDecision
that correctly resets the clearing status by inserting a decision with the "no license known" decision type by using the existingClearingDecisionProcessor
instance to access theNO_LICENSE_KNOWN_DECISION_TYPE
constantProof of Work
Before changes
bef1.mov
After changes
aft1.mov
How to test