protected function removeOldFile($fieldId, $versionNo, array $context)
{
$gateway = $this->getGateway($context);
$fileReference = $gateway->getFileReferenceData($fieldId, $versionNo);
if ($fileReference === null) {
// No previous file
return;
}
$gateway->removeFileReference($fieldId, $versionNo);
$fileCounts = $gateway->countFileReferences(array($fileReference['id']));
if ($fileCounts[$fileReference['id']] === 0) {
$binaryFile = $this->IOService->loadBinaryFile($fileReference['id']);
$this->IOService->deleteBinaryFile($binaryFile);
}
}