Skip to content

Commit

Permalink
[REFACTOR] Use constants for Repository Table Names (tomasnorre#745)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasnorre committed May 22, 2021
1 parent cb124e1 commit a225dd9
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 117 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Added Troubleshooting information about Crawler Module

### Changed
* Switch to Constants for Repository TableNames
* Following classes are marked as internal
* Backend/BackendModule.php
* Backend/Helper/ResultHandler.php
Expand Down
8 changes: 4 additions & 4 deletions Classes/Api/CrawlerApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ public function getLatestCrawlTimestampForPage($uid, $future_crawldates_only = f
{
$uid = intval($uid);

$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->tableName);
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(QueueRepository::TABLE_NAME);
$query = $queryBuilder
->from($this->tableName)
->from(QueueRepository::TABLE_NAME)
->selectLiteral('max(scheduled) as latest')
->where(
$queryBuilder->expr()->eq('page_id', $queryBuilder->createNamedParameter($uid))
Expand Down Expand Up @@ -228,9 +228,9 @@ public function getCrawlHistoryForPage(int $uid, int $limit = 0)
$uid = intval($uid);
$limit = intval($limit);

$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->tableName);
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(QueueRepository::TABLE_NAME);
$statement = $queryBuilder
->from($this->tableName)
->from(QueueRepository::TABLE_NAME)
->select('scheduled', 'exec_time', 'set_id')
->where(
$queryBuilder->expr()->eq('page_id', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT))
Expand Down
2 changes: 1 addition & 1 deletion Classes/Backend/BackendModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function __construct()
{
$objectManger = GeneralUtility::makeInstance(ObjectManager::class);
$this->processManager = $objectManger->get(ProcessService::class);
$this->queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_crawler_queue');
$this->queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(QueueRepository::TABLE_NAME);
$this->queueRepository = $objectManger->get(QueueRepository::class);
$this->initializeView();
$this->extensionSettings = GeneralUtility::makeInstance(ExtensionConfigurationProvider::class)->getExtensionConfiguration();
Expand Down
4 changes: 2 additions & 2 deletions Classes/Backend/RequestForm/LogRequestForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function __construct(StandaloneView $view, InfoModuleController $infoModu
$this->view = $view;
$this->infoModuleController = $infoModuleController;
$this->jsonCompatibilityConverter = new JsonCompatibilityConverter();
$this->queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_crawler_queue');
$this->queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(QueueRepository::TABLE_NAME);
$this->csvWriter = new CrawlerCsvWriter();
$this->extensionSettings = $extensionSettings;
$this->queueRepository = $objectManager->get(QueueRepository::class);
Expand Down Expand Up @@ -140,7 +140,7 @@ private function showLogAction(int $setId, string $quiPath): string
if ($queueId) {
// Get entry record:
$q_entry = $this->queryBuilder
->from('tx_crawler_queue')
->from(QueueRepository::TABLE_NAME)
->select('*')
->where(
$this->queryBuilder->expr()->eq('qid', $this->queryBuilder->createNamedParameter($queueId))
Expand Down
3 changes: 2 additions & 1 deletion Classes/ContextMenu/ItemProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* The TYPO3 project - inspiring people to share!
*/

use AOE\Crawler\Domain\Repository\ConfigurationRepository;
use TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down Expand Up @@ -46,7 +47,7 @@ class ItemProvider extends AbstractProvider
*/
public function canHandle(): bool
{
return $this->table === 'tx_crawler_configuration';
return $this->table === ConfigurationRepository::TABLE_NAME;
}

/**
Expand Down
43 changes: 23 additions & 20 deletions Classes/Controller/CrawlerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ class CrawlerController implements LoggerAwareInterface

/**
* @var string
* @deprecated Since v9.2.5 - This will be remove in v10
*/
protected $tableName = 'tx_crawler_queue';

Expand Down Expand Up @@ -697,10 +698,10 @@ public function getConfigurationsForBranch(int $rootid, int $depth): array
$pids[] = $node['row']['uid'];
}

$queryBuilder = $this->getQueryBuilder('tx_crawler_configuration');
$queryBuilder = $this->getQueryBuilder(ConfigurationRepository::TABLE_NAME);
$statement = $queryBuilder
->select('name')
->from('tx_crawler_configuration')
->from(ConfigurationRepository::TABLE_NAME)
->where(
$queryBuilder->expr()->in('pid', $queryBuilder->createNamedParameter($pids, Connection::PARAM_INT_ARRAY))
)
Expand Down Expand Up @@ -1036,9 +1037,9 @@ public function addQueueEntry_callBack($setId, $params, $callBack, $page_id = 0,
}
$params['_CALLBACKOBJ'] = $callBack;

GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('tx_crawler_queue')
GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable(QueueRepository::TABLE_NAME)
->insert(
'tx_crawler_queue',
QueueRepository::TABLE_NAME,
[
'page_id' => (int) $page_id,
'parameters' => json_encode($params),
Expand Down Expand Up @@ -1125,12 +1126,12 @@ public function addUrl(
}

if (empty($rows)) {
$connectionForCrawlerQueue = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('tx_crawler_queue');
$connectionForCrawlerQueue = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable(QueueRepository::TABLE_NAME);
$connectionForCrawlerQueue->insert(
'tx_crawler_queue',
QueueRepository::TABLE_NAME,
$fieldArray
);
$uid = $connectionForCrawlerQueue->lastInsertId('tx_crawler_queue', 'qid');
$uid = $connectionForCrawlerQueue->lastInsertId(QueueRepository::TABLE_NAME, 'qid');
$rows[] = $uid;
$urlAdded = true;

Expand Down Expand Up @@ -1179,13 +1180,13 @@ public function getCurrentTime()
*/
public function readUrl($queueId, $force = false)
{
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->tableName);
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(QueueRepository::TABLE_NAME);
$ret = 0;
$this->logger->debug('crawler-readurl start ' . microtime(true));

$queryBuilder
->select('*')
->from('tx_crawler_queue')
->from(QueueRepository::TABLE_NAME)
->where(
$queryBuilder->expr()->eq('qid', $queryBuilder->createNamedParameter($queueId, PDO::PARAM_INT))
);
Expand Down Expand Up @@ -1214,9 +1215,9 @@ public function readUrl($queueId, $force = false)
$field_array['process_id_completed'] = $this->processID;
}

GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('tx_crawler_queue')
GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable(QueueRepository::TABLE_NAME)
->update(
'tx_crawler_queue',
QueueRepository::TABLE_NAME,
$field_array,
['qid' => (int) $queueId]
);
Expand Down Expand Up @@ -1256,9 +1257,9 @@ public function readUrl($queueId, $force = false)
[$queueId, &$field_array]
);

GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('tx_crawler_queue')
GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable(QueueRepository::TABLE_NAME)
->update(
'tx_crawler_queue',
QueueRepository::TABLE_NAME,
$field_array,
['qid' => (int) $queueId]
);
Expand All @@ -1278,12 +1279,12 @@ public function readUrlFromArray($field_array)
{
// Set exec_time to lock record:
$field_array['exec_time'] = $this->getCurrentTime();
$connectionForCrawlerQueue = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($this->tableName);
$connectionForCrawlerQueue = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable(QueueRepository::TABLE_NAME);
$connectionForCrawlerQueue->insert(
$this->tableName,
QueueRepository::TABLE_NAME,
$field_array
);
$queueId = $field_array['qid'] = $connectionForCrawlerQueue->lastInsertId($this->tableName, 'qid');
$queueId = $field_array['qid'] = $connectionForCrawlerQueue->lastInsertId(QueueRepository::TABLE_NAME, 'qid');
$result = $this->queueExecutor->executeQueueItem($field_array, $this);

// Set result in log which also denotes the end of the processing of this entry.
Expand All @@ -1296,7 +1297,7 @@ public function readUrlFromArray($field_array)
);

$connectionForCrawlerQueue->update(
$this->tableName,
QueueRepository::TABLE_NAME,
$field_array,
['qid' => $queueId]
);
Expand Down Expand Up @@ -1723,8 +1724,9 @@ public function CLI_releaseProcesses($releaseIds)

// mark all processes as deleted which have no "waiting" queue-entires and which are not active

// ReleaseQueueEntries
$queryBuilder
->update($this->tableName, 'q')
->update(QueueRepository::TABLE_NAME, 'q')
->where(
'q.process_id IN(SELECT p.process_id FROM tx_crawler_process as p WHERE p.active = 0)'
)
Expand All @@ -1735,8 +1737,9 @@ public function CLI_releaseProcesses($releaseIds)
// FIXME: Not entirely sure that this is equivalent to the previous version
$queryBuilder->resetQueryPart('set');

// ReleaseProcessEntries
$queryBuilder
->update('tx_crawler_process')
->update(ProcessRepository::TABLE_NAME)
->where(
$queryBuilder->expr()->eq('active', 0),
'process_id IN(SELECT q.process_id FROM tx_crawler_queue as q WHERE q.exec_time = 0)'
Expand Down Expand Up @@ -1862,7 +1865,7 @@ protected function getDuplicateRowsIfExist($tstamp, $fieldArray)
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->tableName);
$queryBuilder
->select('qid')
->from('tx_crawler_queue');
->from(QueueRepository::TABLE_NAME);
//if this entry is scheduled with "now"
if ($tstamp <= $currentTime) {
if ($this->extensionSettings['enableTimeslot']) {
Expand Down
9 changes: 6 additions & 3 deletions Classes/Domain/Repository/ConfigurationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@
*/
class ConfigurationRepository extends Repository
{
public const TABLE_NAME = 'tx_crawler_configuration';

/**
* @var string
* @deprecated Since v9.2.5 - This will be remove in v10
*/
protected $tableName = 'tx_crawler_configuration';

Expand All @@ -44,7 +47,7 @@ public function getCrawlerConfigurationRecords(): array
$queryBuilder = $this->createQueryBuilder();
$statement = $queryBuilder
->select('*')
->from($this->tableName)
->from(self::TABLE_NAME)
->execute();

while ($row = $statement->fetch()) {
Expand Down Expand Up @@ -73,7 +76,7 @@ public function getCrawlerConfigurationRecordsFromRootLine(int $pageId): array
->add(GeneralUtility::makeInstance(HiddenRestriction::class));
$configurationRecordsForCurrentPage = $queryBuilder
->select('*')
->from($this->tableName)
->from(self::TABLE_NAME)
->where(
$queryBuilder->expr()->in('pid', $queryBuilder->createNamedParameter($pageIdsInRootLine, Connection::PARAM_INT_ARRAY))
)
Expand All @@ -84,6 +87,6 @@ public function getCrawlerConfigurationRecordsFromRootLine(int $pageId): array

protected function createQueryBuilder(): QueryBuilder
{
return GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->tableName);
return GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(self::TABLE_NAME);
}
}

0 comments on commit a225dd9

Please sign in to comment.