Skip to content

Commit

Permalink
[TASK] Prevent sys_refindex entries for download stats
Browse files Browse the repository at this point in the history
If you do want sys_refindex entries for download stats you can reenable with a new extension configuration variable. When set this will also now create sys_refindex entries when creating the download entries, so a regular reference index update is no longer needed.

Resolves: #243
  • Loading branch information
Rudy Gnodde committed Nov 29, 2024
1 parent d659f72 commit 08c7411
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 18 deletions.
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

0 comments on commit 08c7411

Please sign in to comment.