Skip to content
Open
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions Classes/Configuration/ExtensionConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ExtensionConfiguration
private static bool $forceDownload = false;
private static string $forceDownloadForExt = '';
private static bool $trackDownloads = false;
private static bool $linkDownloads = false;
private static bool $resumableDownload = true;

private static function init(): void
Expand All @@ -53,6 +54,7 @@ private static function init(): void
self::$forceDownload = (bool)$extensionConfig['force_download'];
self::$forceDownloadForExt = $extensionConfig['force_download_for_ext'];
self::$trackDownloads = (bool)$extensionConfig['track_downloads'];
self::$linkDownloads = isset($extensionConfig['link_downloads']) && $extensionConfig['link_downloads'];
self::$resumableDownload = isset($extensionConfig['resumable_download']) && $extensionConfig['resumable_download'];
}
}
Expand Down Expand Up @@ -90,6 +92,17 @@ public static function trackDownloads(): bool
return self::$trackDownloads;
}

/**
* Link downloads in TCA
*
* @return bool
*/
public static function linkDownloads(): bool
{
self::init();
return self::$linkDownloads;
}

public static function resumableDownload(): bool
{
self::init();
Expand Down
21 changes: 14 additions & 7 deletions Classes/EventListener/ModifyFileDumpEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use TYPO3\CMS\Core\Context\Exception\AspectPropertyNotFoundException;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\ReferenceIndex;
use TYPO3\CMS\Core\LinkHandling\Exception\UnknownLinkHandlerException;
use TYPO3\CMS\Core\LinkHandling\LinkService;
use TYPO3\CMS\Core\Resource\Event\ModifyFileDumpEvent;
Expand Down Expand Up @@ -146,13 +147,19 @@ private function checkFileAccess(ResourceInterface $file)
'file' => (int)$this->originalFile->getUid(),
];

GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionForTable('tx_falsecuredownload_download')
->insert(
'tx_falsecuredownload_download',
$columns,
[Connection::PARAM_INT, Connection::PARAM_INT, Connection::PARAM_INT, Connection::PARAM_INT]
);
$downloadConnection = GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionForTable('tx_falsecuredownload_download');
$downloadConnection->insert(
'tx_falsecuredownload_download',
$columns,
[Connection::PARAM_INT, Connection::PARAM_INT, Connection::PARAM_INT, Connection::PARAM_INT]
);

if (ExtensionConfiguration::linkDownloads()) {
$downloadUid = $downloadConnection->lastInsertId();
$referenceIndex = GeneralUtility::makeInstance(ReferenceIndex::class);
$referenceIndex->updateRefIndexTable('tx_falsecuredownload_download', $downloadUid);
}
}

// Dump the precise requested file for File and ProcessedFile, but dump the referenced file for FileReference
Expand Down
31 changes: 20 additions & 11 deletions Configuration/TCA/tx_falsecuredownload_download.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,34 @@
'exclude' => false,
'label' => 'LLL:EXT:fal_securedownload/Resources/Private/Language/locallang_db.xlf:file',
'config' => [
'type' => 'group',
'size' => 1,
'maxitems' => 1,
'minitems' => 1,
'allowed' => 'sys_file',
'type' => 'passthrough',
],
],
'feuser' => [
'exclude' => false,
'label' => 'LLL:EXT:fal_securedownload/Resources/Private/Language/locallang_db.xlf:fe_user',
'config' => [
'type' => 'group',
'size' => 1,
'maxitems' => 1,
'minitems' => 1,
'allowed' => 'fe_users',
'type' => 'passthrough',
],
],
]
],
];

if (\BeechIt\FalSecuredownload\Configuration\ExtensionConfiguration::linkDownloads()) {
$tca['columns']['file']['config'] = [
'type' => 'group',
'size' => 1,
'maxitems' => 1,
'minitems' => 1,
'allowed' => 'sys_file',
];
$tca['columns']['feuser']['config'] = [
'type' => 'group',
'size' => 1,
'maxitems' => 1,
'minitems' => 1,
'allowed' => 'fe_users',
];
}

return $tca;
3 changes: 3 additions & 0 deletions Resources/Private/Language/locallang_be.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
<trans-unit id="extmng.track_downloads">
<source>Count downloads per user and create statistics</source>
</trans-unit>
<trans-unit id="extmng.link_downloads">
<source>Link downloads to files and users in TCA (This will create reference index records for each download)</source>
</trans-unit>
<trans-unit id="extmng.resumable_download">
<source>Enable resumable downloads</source>
</trans-unit>
Expand Down
3 changes: 3 additions & 0 deletions ext_conf_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ resumable_download = 1

# cat=basic/enable/6; type=boolean; label=LLL:EXT:fal_securedownload/Resources/Private/Language/locallang_be.xlf:extmng.track_downloads
track_downloads = 0

# cat=basic/enable/7; type=boolean; label=LLL:EXT:fal_securedownload/Resources/Private/Language/locallang_be.xlf:extmng.link_downloads
link_downloads = 0