mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 18:03:17 +00:00
add info to api/quarantine
This commit is contained in:
@@ -688,8 +688,18 @@ class V1Controller extends Controller
|
||||
|
||||
$checks = array_map(function (LazaretCheck $checker) use ($manager, $translator) {
|
||||
$checkerFQCN = $checker->getCheckClassname();
|
||||
|
||||
return $manager->getCheckerFromFQCN($checkerFQCN)->getMessage($translator);
|
||||
}, iterator_to_array($file->getChecks()));
|
||||
}, $file->getChecksWhithNameKey());
|
||||
|
||||
$recordsMatch = array_map(function ($recordsTab){
|
||||
$record = $recordsTab['record'];
|
||||
$matched['record_id'] = $record->getRecordId();
|
||||
$matched['collection'] = $record->getCollectionName();
|
||||
$matched['checks'] = $recordsTab['reasons'];
|
||||
|
||||
return $matched;
|
||||
}, array_values($file->getRecordsToSubstitute($this->app, true)));
|
||||
|
||||
$usr_id = $user = null;
|
||||
if ($file->getSession()->getUser()) {
|
||||
@@ -707,12 +717,13 @@ class V1Controller extends Controller
|
||||
'id' => $file->getId(),
|
||||
'quarantine_session' => $session,
|
||||
'base_id' => $file->getBaseId(),
|
||||
'record_id' => $file->getRecordIdsByCheckers($this->app)?:[],
|
||||
'original_name' => $file->getOriginalName(),
|
||||
'collection' => $file->getCollection($this->app)->get_label($this->app['locale']),
|
||||
'sha256' => $file->getSha256(),
|
||||
'uuid' => $file->getUuid(),
|
||||
'forced' => $file->getForced(),
|
||||
'checks' => $file->getForced() ? [] : $checks,
|
||||
'records_match' => $recordsMatch?:[],
|
||||
'created_on' => $file->getCreated()->format(DATE_ATOM),
|
||||
'updated_on' => $file->getUpdated()->format(DATE_ATOM),
|
||||
];
|
||||
|
@@ -386,6 +386,17 @@ class LazaretFile
|
||||
$this->checks->removeElement($checks);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LazaretCheck $checks
|
||||
* @return string
|
||||
*/
|
||||
public function getCheckerName(LazaretCheck $checks)
|
||||
{
|
||||
$checkNameTab = explode('\\', $checks->getCheckClassname());
|
||||
|
||||
return $checkNameTab[4];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get checks
|
||||
*
|
||||
@@ -396,6 +407,19 @@ class LazaretFile
|
||||
return $this->checks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array $checkers
|
||||
*/
|
||||
public function getChecksWhithNameKey()
|
||||
{
|
||||
$checkers = [];
|
||||
foreach($this->checks as $check){
|
||||
$checkers[$this->getCheckerName($check)] = $check;
|
||||
}
|
||||
|
||||
return $checkers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set session
|
||||
*
|
||||
@@ -439,7 +463,7 @@ class LazaretFile
|
||||
'reasons' => []
|
||||
];
|
||||
}
|
||||
$merged[$record->getRecordId()]['reasons'][] = $check->getReason($app['translator']);
|
||||
$merged[$record->getRecordId()]['reasons'][$this->getCheckerName($check)] = $check->getReason($app['translator']);
|
||||
}
|
||||
else {
|
||||
$merged[$record->getRecordId()] = $record;
|
||||
@@ -450,28 +474,4 @@ class LazaretFile
|
||||
return $merged;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of record_id
|
||||
*
|
||||
* @param Application $app
|
||||
* @return array
|
||||
*/
|
||||
public function getRecordIdsByCheckers(Application $app)
|
||||
{
|
||||
$recordIds = [];
|
||||
/** @var LazaretCheck $check */
|
||||
foreach($this->getChecks() as $check) {
|
||||
/** @var record_adapter $record */
|
||||
$conflicts = $check->listConflicts($app);
|
||||
|
||||
foreach ($conflicts as $record) {
|
||||
if(!in_array($record->getRecordId(), $recordIds)){
|
||||
$recordIds[] = $record->getRecordId();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $recordIds;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user