-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 16058f1
Showing
14 changed files
with
694 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace StudioMitte\SolrContextmenu\ContextMenu; | ||
|
||
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
class AccessCheck | ||
{ | ||
public static function tableIsValid(string $tableName): bool | ||
{ | ||
try { | ||
$settings = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('solr_contextmenu'); | ||
$tables = GeneralUtility::trimExplode(',', $settings['tables'] ?? '', true); | ||
return in_array($tableName, $tables, true); | ||
} catch (\Exception $e) { | ||
// do nothing | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace StudioMitte\SolrContextmenu\ContextMenu; | ||
|
||
use TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider; | ||
|
||
class SolrContextMenuItemProvider extends AbstractProvider | ||
{ | ||
|
||
/** | ||
* This array contains configuration for items you want to add | ||
* @var array | ||
*/ | ||
protected $itemsConfiguration = [ | ||
'hello' => [ | ||
'type' => 'item', | ||
'label' => 'LLL:EXT:solr_contextmenu/Resources/Private/Language/locallang.xlf:contextmenu.remove', | ||
'iconIdentifier' => 'actions-edit-delete', | ||
'callbackAction' => 'removeFromSolr' | ||
] | ||
]; | ||
|
||
public function addItems(array $items): array | ||
{ | ||
$this->initDisabledItems(); | ||
|
||
//passes array of items to the next item provider | ||
$items += $this->prepareItems($this->itemsConfiguration); | ||
return $items; | ||
} | ||
|
||
public function getPriority(): int | ||
{ | ||
return 19; | ||
} | ||
|
||
public function canHandle(): bool | ||
{ | ||
return AccessCheck::tableIsValid($this->table); | ||
} | ||
|
||
protected function getAdditionalAttributes(string $itemName): array | ||
{ | ||
return [ | ||
'data-callback-module' => 'TYPO3/CMS/SolrContextmenu/ContextMenuActions', | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace StudioMitte\SolrContextmenu\Controller; | ||
|
||
use ApacheSolrForTypo3\Solr\ConnectionManager; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use StudioMitte\SolrContextmenu\ContextMenu\AccessCheck; | ||
use TYPO3\CMS\Backend\Utility\BackendUtility; | ||
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; | ||
use TYPO3\CMS\Core\Http\JsonResponse; | ||
use TYPO3\CMS\Core\Localization\LanguageService; | ||
use TYPO3\CMS\Core\Type\Bitmask\Permission; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Extbase\Utility\DebuggerUtility; | ||
|
||
class SolrRemoveRecordController | ||
{ | ||
|
||
public function mainAction(ServerRequestInterface $request): ResponseInterface | ||
{ | ||
$parsedBody = $request->getParsedBody(); | ||
$queryParams = $request->getQueryParams(); | ||
$recordUid = (int)($parsedBody['uid'] ?? $queryParams['uid'] ?? 0); | ||
$table = $parsedBody['table'] ?? $queryParams['table'] ?? ''; | ||
$language = null; | ||
|
||
if (!AccessCheck::tableIsValid($table)) { | ||
return new JsonResponse([ | ||
'success' => true, | ||
'title' => 'table invalid', | ||
'message' => '' | ||
]); | ||
} | ||
|
||
$pageId = null; | ||
|
||
$connectionManager = GeneralUtility::makeInstance(ConnectionManager::class); | ||
$fullRecord = BackendUtility::getRecord($table, $recordUid); | ||
|
||
|
||
if (!$fullRecord) { | ||
return new JsonResponse([ | ||
'success' => true, | ||
'title' => 'record not found', | ||
'message' => '' | ||
]); | ||
} | ||
|
||
|
||
if ($table !== 'pages') { | ||
$pageId = $fullRecord['pid']; | ||
$pageRow = BackendUtility::getRecord('pages', $pageId); | ||
|
||
if ($GLOBALS['TCA'][$table]['ctrl']['languageField'] ?? false) { | ||
$language = $fullRecord[$GLOBALS['TCA'][$table]['ctrl']['languageField']] ?? 0; | ||
} else { | ||
$language = 0; | ||
} | ||
} else { | ||
$pageId = $recordUid; | ||
$pageRow = $fullRecord; | ||
$language = $fullRecord['sys_language_uid'] ?? 0; | ||
} | ||
|
||
if (!$this->checkAccess($table, $fullRecord, $pageRow)) { | ||
return new JsonResponse([ | ||
'success' => false, | ||
'title' => 'Could not be cleared', | ||
'message' => '' | ||
]); | ||
} | ||
|
||
if ($pageId) { | ||
$connection = $connectionManager->getConnectionByPageId($pageId, $language); | ||
$connection->getWriteService()->deleteByQuery(sprintf('type:%s AND uid:%s', $table, $recordUid)); | ||
} | ||
|
||
return new JsonResponse([ | ||
'success' => true, | ||
'title' => 'Cleared from solr', | ||
'message' => '' | ||
]); | ||
} | ||
|
||
protected function checkAccess(string $table, array $record, array $page): bool | ||
{ | ||
$user = $this->getBackendUserAuthentication(); | ||
if ($user->isAdmin()) { | ||
return true; | ||
} | ||
if (!$user->recordEditAccessInternals($table, $record)) { | ||
return false; | ||
} | ||
if (!$user->check('tables_modify', $table)) { | ||
return false; | ||
} | ||
|
||
if (class_exists(Permission::class)) { | ||
$pagePermissions = new Permission($user->calcPerms($page)); | ||
if (!$pagePermissions->isGranted(Permission::CONTENT_EDIT)) { | ||
return false; | ||
} | ||
} else { | ||
$pagePermissions = $user->calcPerms($page); | ||
if (!(($pagePermissions & Permission::CONTENT_EDIT) == Permission::CONTENT_EDIT)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
protected function getBackendUserAuthentication(): BackendUserAuthentication | ||
{ | ||
return $GLOBALS['BE_USER']; | ||
} | ||
|
||
protected function getLanguageService(): LanguageService | ||
{ | ||
return $GLOBALS['LANG']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
return [ | ||
'web_list_solrrecordclear' => [ | ||
'path' => '/web/list/solrrecordclear', | ||
'target' => \StudioMitte\SolrContextmenu\Controller\SolrRemoveRecordController::class . '::mainAction' | ||
], | ||
]; |
Oops, something went wrong.