Skip to content

Commit

Permalink
tweak(OOI) improve select for update / broadcast hub behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmhh committed Aug 13, 2024
1 parent 18d08e2 commit 884a860
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
6 changes: 5 additions & 1 deletion tine20/OnlyOfficeIntegrator/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @subpackage Controller
* @license http://www.gnu.org/licenses/agpl.html AGPL Version 3
* @author Cornelius Weiß <c.weiss@metaways.de>
* @copyright Copyright (c) 2018-2023 Metaways Infosystems GmbH (http://www.metaways.de)
* @copyright Copyright (c) 2018-2024 Metaways Infosystems GmbH (http://www.metaways.de)
*
*/

Expand Down Expand Up @@ -485,12 +485,16 @@ protected function processStatus3(string $token): bool

protected function processStatus4($token)
{
$forUpdateRaii = Tinebase_Backend_Sql_SelectForUpdateHook::getRAII(
OnlyOfficeIntegrator_Controller_AccessToken::getInstance()->getBackend()
);
$raii = Tinebase_RAII::getTransactionManagerRAII();
$allTokens = OnlyOfficeIntegrator_Controller_AccessToken::getInstance()->search(
Tinebase_Model_Filter_FilterGroup::getFilterForModel(OnlyOfficeIntegrator_Model_AccessToken::class, [
['field' => OnlyOfficeIntegrator_Model_AccessToken::FLDS_TOKEN, 'operator' => 'equals', 'value' => $token],
['field' => OnlyOfficeIntegrator_Model_AccessToken::FLDS_INVALIDATED, 'operator' => 'equals', 'value' => Tinebase_Model_Filter_Bool::VALUE_NOTSET],
]));
unset($forUpdateRaii);

foreach ($allTokens as $tokenRecord) {
$tokenRecord->{OnlyOfficeIntegrator_Model_AccessToken::FLDS_INVALIDATED} = 1;
Expand Down
20 changes: 15 additions & 5 deletions tine20/OnlyOfficeIntegrator/Controller/AccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @subpackage Controller
* @license http://www.gnu.org/licenses/agpl.html AGPL Version 3
* @author Paul Mehrer <p.mehrer@metaways.de>
* @copyright Copyright (c) 2019-2023 Metaways Infosystems GmbH (http://www.metaways.de)
* @copyright Copyright (c) 2019-2024 Metaways Infosystems GmbH (http://www.metaways.de)
*
*/

Expand Down Expand Up @@ -290,22 +290,32 @@ protected function _inspectAfterCreate($_createdRecord, Tinebase_Record_Interfac
{
parent::_inspectAfterCreate($_createdRecord, $_record);

static $bhCache = [];
if ($_createdRecord->{OnlyOfficeIntegrator_Model_AccessToken::FLDS_NODE_REVISION} != OnlyOfficeIntegrator_Model_AccessToken::TEMP_FILE_REVISION &&
Tinebase_BroadcastHub::getInstance()->isActive()) {
$node = Tinebase_FileSystem::getInstance()->get($_createdRecord->{OnlyOfficeIntegrator_Model_AccessToken::FLDS_NODE_ID});
Tinebase_BroadcastHub::getInstance()->pushAfterCommit('update', get_class($node), $node->getId(), $node->getContainerId());
$nodeId = $_createdRecord->{OnlyOfficeIntegrator_Model_AccessToken::FLDS_NODE_ID};
if (!isset($bhCache[$nodeId])) {
$bhCache[$nodeId] = true;
$node = Tinebase_FileSystem::getInstance()->get($nodeId);
Tinebase_BroadcastHub::getInstance()->pushAfterCommit('update', get_class($node), $node->getId(), $node->getContainerId());
}
}
}

protected function _inspectAfterUpdate($updatedRecord, $record, $currentRecord)
{
parent::_inspectAfterUpdate($updatedRecord, $record, $currentRecord);

static $bhCache = [];
if ($updatedRecord->{OnlyOfficeIntegrator_Model_AccessToken::FLDS_NODE_REVISION} != OnlyOfficeIntegrator_Model_AccessToken::TEMP_FILE_REVISION &&
Tinebase_BroadcastHub::getInstance()->isActive()) {
try {
$node = Tinebase_FileSystem::getInstance()->get($updatedRecord->{OnlyOfficeIntegrator_Model_AccessToken::FLDS_NODE_ID});
Tinebase_BroadcastHub::getInstance()->pushAfterCommit('update', get_class($node), $node->getId(), $node->getContainerId());
$nodeId = $updatedRecord->{OnlyOfficeIntegrator_Model_AccessToken::FLDS_NODE_ID};
if (!isset($bhCache[$nodeId])) {
$bhCache[$nodeId] = true;
$node = Tinebase_FileSystem::getInstance()->get($nodeId);
Tinebase_BroadcastHub::getInstance()->pushAfterCommit('update', get_class($node), $node->getId(), $node->getContainerId());
}
// file might have been deleted -> ignore tenf
} catch (Tinebase_Exception_NotFound $tenf) {}
}
Expand Down

0 comments on commit 884a860

Please sign in to comment.