Skip to content
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

Naos 14.13.0 plat 9574 #8033

Merged
merged 2 commits into from
Jan 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions plugins/virus_scan/lib/batch/kVirusScanFlowManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
class kVirusScanFlowManager implements kBatchJobStatusEventConsumer, kObjectAddedEventConsumer
{

private static $flavorAssetIdsToScan = array();
private static $assetIdsToScan = array();


private function resumeEvents($flavorAsset, BatchJob $raisedJob = null)
{
$syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);

$c = FileSyncPeer::getCriteriaForFileSyncKey( $syncKey );
$fileSyncList = FileSyncPeer::doSelect( $c );

Expand All @@ -23,20 +23,20 @@ private function resumeEvents($flavorAsset, BatchJob $raisedJob = null)
}


private function saveIfShouldScan($flavorAsset)
private function saveIfShouldScan($asset)
{
if (!PermissionPeer::isAllowedPlugin(VirusScanPlugin::PLUGIN_NAME, $flavorAsset->getPartnerId()))
if (!PermissionPeer::isAllowedPlugin(VirusScanPlugin::PLUGIN_NAME, $asset->getPartnerId()))
return false;

if (isset(self::$flavorAssetIdsToScan[$flavorAsset->getId()]))
if (isset(self::$assetIdsToScan[$asset->getId()]))
{
return true;
}

$profile = VirusScanProfilePeer::getSuitableProfile($flavorAsset->getEntryId());
$profile = VirusScanProfilePeer::getSuitableProfile($asset->getEntryId());
if ($profile)
{
self::$flavorAssetIdsToScan[$flavorAsset->getId()] = $profile;
self::$assetIdsToScan[$asset->getId()] = $profile;
return true;
}

Expand Down Expand Up @@ -70,19 +70,19 @@ private function addedFileSync(FileSync $object)
}

/**
* @param flavorAsset $object
* @param asset $object
* @return bool true if should continue to the next consumer
*/
private function addedFlavorAsset(flavorAsset $object, BatchJob $raisedJob = null)
private function addedAsset(asset $object, BatchJob $raisedJob = null)
{
if($object instanceof flavorAsset && $object->getIsOriginal())
if(($object instanceof flavorAsset && $object->getIsOriginal()) || $object instanceof AttachmentAsset)
{
if ($this->saveIfShouldScan($object))
{
$profile = self::$flavorAssetIdsToScan[$object->getId()];
$profile = self::$assetIdsToScan[$object->getId()];

// suitable virus scan profile found - create scan job
$syncKey = $object->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
$syncKey = $object->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
kVirusScanJobsManager::addVirusScanJob($raisedJob, $object->getPartnerId(), $object->getEntryId(), $object->getId(), $syncKey, $profile->getEngineType(), $profile->getActionIfInfected());
return false; // pause other event consumers until virus scan job is finished
}
Expand All @@ -99,10 +99,8 @@ public function shouldConsumeAddedEvent(BaseObject $object)
// virus scan only works in api_v3 context because it uses dynamic enums
if (!class_exists('kCurrentContext') || !kCurrentContext::isApiV3Context())
return false;

if($object instanceof flavorAsset)
if($object instanceof asset)
return true;

if($object instanceof FileSync)
return true;

Expand All @@ -115,9 +113,9 @@ public function shouldConsumeAddedEvent(BaseObject $object)
public function objectAdded(BaseObject $object, BatchJob $raisedJob = null)
{
$response = true;
if($object instanceof flavorAsset)
if($object instanceof asset)
{
$response = $this->addedFlavorAsset($object, $raisedJob);
$response = $this->addedAsset($object, $raisedJob);
}

if($object instanceof FileSync)
Expand Down Expand Up @@ -295,4 +293,4 @@ protected static function getFlavorAssetStatusBeforeScanFailure(flavorAsset $fla
return $flavorAsset->getFromCustomData(VirusScanPlugin::getPluginName().'_'.self::CUSTOM_DATA_STATUS_BEFORE_SCAN_FAILURE);
}

}
}