Skip to content

Commit aa59568

Browse files
committed
[CLEANUP] Unify code style
1 parent 0534bf7 commit aa59568

19 files changed

+211
-308
lines changed

Diff for: Classes/Command/LinkMigrationCommandController.php

+19-54
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
*
2727
* @package TYPO3\CMS\Extbase\Command
2828
*/
29-
class LinkMigrationCommandController extends CommandController {
29+
class LinkMigrationCommandController extends CommandController
30+
{
3031
/**
3132
* Default list of fields where to search for record references to migrate
3233
*/
@@ -90,20 +91,14 @@ public function migrateCommand($fields = '')
9091
$this->setFields($fields);
9192
// Loop on all tables and fields
9293
foreach ($this->tablesAndFields as $table => $listOfFields) {
93-
$this->gatherRecordsToMigrate(
94-
$table,
95-
$listOfFields
96-
);
94+
$this->gatherRecordsToMigrate($table, $listOfFields);
9795
}
9896
// Ask the user for configuration key for each table
9997
$this->getConfigurationKeys();
10098
// Replace in fields and save modified data
10199
$this->migrateRecords();
102-
}
103-
catch (\InvalidArgumentException $e) {
104-
$this->outputLine(
105-
$e->getMessage() . ' (' . $e->getCode() . ')'
106-
);
100+
} catch (\InvalidArgumentException $e) {
101+
$this->outputLine($e->getMessage() . ' (' . $e->getCode() . ')');
107102
$this->quit(1);
108103
}
109104
}
@@ -122,11 +117,8 @@ protected function setFields($fields)
122117
list($table, $field) = explode('.', $aField);
123118
if (empty($table) || empty($field)) {
124119
throw new \InvalidArgumentException(
125-
sprintf(
126-
'Invalid argument "%s". Use "table.field" syntax',
127-
$aField
128-
),
129-
1457434202
120+
sprintf('Invalid argument "%s". Use "table.field" syntax', $aField),
121+
1457434202
130122
);
131123
} else {
132124
if (!array_key_exists($table, $this->tablesAndFields)) {
@@ -150,22 +142,15 @@ protected function setFields($fields)
150142
protected function gatherRecordsToMigrate($table, $listOfFields)
151143
{
152144
try {
153-
$records = $this->genericRepository->findByRecordLink(
154-
$table,
155-
$listOfFields
156-
);
145+
$records = $this->genericRepository->findByRecordLink($table, $listOfFields);
157146
foreach ($records as $record) {
158147
$id = (int)$record['uid'];
159148
foreach ($listOfFields as $field) {
160149
$matches = array();
161150
// Find all element that have a syntax like "record:string:string(:string)"
162151
// The last string is optional. If it exists, it is already a 4-part record reference,
163152
// i.e. a reference using the new syntax and which does not need to be migrated.
164-
preg_match_all(
165-
'/record:(\w+):(\w+)(:\w+)?/',
166-
$record[$field],
167-
$matches
168-
);
153+
preg_match_all('/record:(\w+):(\w+)(:\w+)?/', $record[$field], $matches);
169154
foreach ($matches as $index => $match) {
170155
// Consider only matches that have 3 parts (i.e. 4th part is empty)
171156
// NOTE: although not captured, the first part is "record:"
@@ -186,23 +171,16 @@ protected function gatherRecordsToMigrate($table, $listOfFields)
186171
if (!array_key_exists($field, $this->recordsForMigration[$table][$id])) {
187172
$this->recordsForMigration[$table][$id][$field] = array(
188173
'content' => $record[$field],
189-
'matches' => array()
174+
'matches' => array(),
190175
);
191176
}
192177
$this->recordsForMigration[$table][$id][$field]['matches'][] = $matches[0][$index];
193178
}
194179
}
195180
}
196181
}
197-
}
198-
catch (FailedQueryException $e) {
199-
$this->outputLine(
200-
sprintf(
201-
'Table "%s" skipped. An error occurred: %s',
202-
$table,
203-
$e->getMessage()
204-
)
205-
);
182+
} catch (FailedQueryException $e) {
183+
$this->outputLine(sprintf('Table "%s" skipped. An error occurred: %s', $table, $e->getMessage()));
206184
}
207185
}
208186

@@ -211,19 +189,16 @@ protected function gatherRecordsToMigrate($table, $listOfFields)
211189
*
212190
* @return void
213191
*/
214-
protected function getConfigurationKeys() {
192+
protected function getConfigurationKeys()
193+
{
215194
foreach ($this->tablesForMigration as $table => &$dummy) {
216195
$key = null;
217196
do {
218197
try {
219198
$key = $this->console->ask(
220-
sprintf(
221-
'Please enter the configuration key to use for table "%s": ',
222-
$table
223-
)
199+
sprintf('Please enter the configuration key to use for table "%s": ', $table)
224200
);
225-
}
226-
catch (\Exception $e) {
201+
} catch (\Exception $e) {
227202
// Do nothing, just let it try again
228203
}
229204
} while ($key === null);
@@ -246,27 +221,17 @@ protected function migrateRecords()
246221
foreach ($fieldInformation['matches'] as $link) {
247222
$linkParts = explode(':', $link);
248223
$newLink = 'record:' . $this->tablesForMigration[$linkParts[1]] . ':' . $linkParts[1] . ':' . $linkParts[2];
249-
$updatedField = str_replace(
250-
$link,
251-
$newLink,
252-
$updatedField
253-
);
224+
$updatedField = str_replace($link, $newLink, $updatedField);
254225
}
255226
if (!array_key_exists($id, $recordsForTable)) {
256227
$recordsForTable[$id] = array();
257228
}
258229
$recordsForTable[$id][$field] = $updatedField;
259230
}
260231
}
261-
$result = $this->genericRepository->massUpdate(
262-
$table,
263-
$recordsForTable
264-
);
232+
$result = $this->genericRepository->massUpdate($table, $recordsForTable);
265233
if (!$result) {
266-
$this->outputLine(
267-
'Some database updates failed for table "%s"',
268-
$table
269-
);
234+
$this->outputLine('Some database updates failed for table "%s"', $table);
270235
}
271236
}
272237
}

Diff for: Classes/Domain/Model/RecordLink.php

+5-7
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
*
2222
* @package Cobweb\Linkhandler\Domain\Model
2323
*/
24-
class RecordLink {
24+
class RecordLink
25+
{
2526
/**
2627
* @var string Name of the linkhandler configuration
2728
*/
@@ -112,10 +113,7 @@ public function getRecordReference()
112113
public function setRecordReference($recordReference)
113114
{
114115
if (empty($recordReference)) {
115-
throw new \InvalidArgumentException(
116-
'Record reference cannot be empty',
117-
1457367830
118-
);
116+
throw new \InvalidArgumentException('Record reference cannot be empty', 1457367830);
119117
}
120118
$referenceParts = explode(':', $recordReference);
121119
if (count($referenceParts) === 4) {
@@ -125,8 +123,8 @@ public function setRecordReference($recordReference)
125123
$this->id = (int)$referenceParts[3];
126124
} else {
127125
throw new \InvalidArgumentException(
128-
'Expected record reference structure is "record:key:table:id"',
129-
1457367830
126+
'Expected record reference structure is "record:key:table:id"',
127+
1457367830
130128
);
131129
}
132130
}

Diff for: Classes/Domain/Repository/GenericRepository.php

+12-20
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
*
2424
* @package Cobweb\Linkhandler\Domain\Repository
2525
*/
26-
class GenericRepository {
26+
class GenericRepository
27+
{
2728
/**
2829
* Fetches a list of records from given table that contain links to records.
2930
*
@@ -44,26 +45,21 @@ public function findByRecordLink($table, $listOfFields)
4445
$where = implode(' OR ', $conditions) . BackendUtility::deleteClause($table);
4546
try {
4647
$fields = implode(', ', $listOfFields);
47-
$result = $this->getDatabaseConnection()->exec_SELECTgetRows(
48-
'uid, ' . $fields,
49-
$table,
50-
$where
51-
);
48+
$result = $this->getDatabaseConnection()->exec_SELECTgetRows('uid, ' . $fields, $table, $where);
5249
if ($result === null) {
5350
throw new FailedQueryException(
54-
sprintf(
55-
'A SQL error occurred querying table "%s" with fields "%s": %s',
56-
$table,
57-
$fields,
58-
$this->getDatabaseConnection()->sql_error()
59-
),
60-
1457441163
51+
sprintf(
52+
'A SQL error occurred querying table "%s" with fields "%s": %s',
53+
$table,
54+
$fields,
55+
$this->getDatabaseConnection()->sql_error()
56+
),
57+
1457441163
6158
);
6259
} else {
6360
$records = $result;
6461
}
65-
}
66-
catch (\InvalidArgumentException $e) {
62+
} catch (\InvalidArgumentException $e) {
6763
// Nothing to do here
6864
}
6965
return $records;
@@ -81,11 +77,7 @@ public function massUpdate($table, $records)
8177
$globalResult = true;
8278
// @todo: this could be improved to provide better reporting on errors (and maybe use transactions to roll everything back)
8379
foreach ($records as $id => $fields) {
84-
$result = $this->getDatabaseConnection()->exec_UPDATEquery(
85-
$table,
86-
'uid = ' . (int)$id,
87-
$fields
88-
);
80+
$result = $this->getDatabaseConnection()->exec_UPDATEquery($table, 'uid = ' . (int)$id, $fields);
8981
$globalResult &= $result;
9082
}
9183
return $globalResult;

Diff for: Classes/Linkvalidator/LinkhandlerLinkType.php

+10-16
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
use Cobweb\Linkhandler\Domain\Model\RecordLink;
18+
use TYPO3\CMS\Core\Utility\GeneralUtility;
1819
use TYPO3\CMS\Linkvalidator\Linktype\AbstractLinktype;
1920
use TYPO3\CMS\Backend\Utility\BackendUtility;
2021

@@ -94,18 +95,14 @@ public function checkLink($url, $softRefEntry, $linkAnalyzer)
9495
$this->initializeRequiredClasses();
9596

9697
try {
97-
$this->recordLink = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
98-
RecordLink::class,
99-
$url
100-
);
101-
}
102-
catch (\Exception $e) {
98+
$this->recordLink = GeneralUtility::makeInstance(RecordLink::class, $url);
99+
} catch (\Exception $e) {
103100
// Set error type to invalid (record reference) and return early
104101
$this->setErrorParams(
105-
array(
106-
'errorType' => self::ERROR_TYPE_INVALID,
107-
'url' => $url
108-
)
102+
array(
103+
'errorType' => self::ERROR_TYPE_INVALID,
104+
'url' => $url,
105+
)
109106
);
110107
return false;
111108
}
@@ -129,7 +126,8 @@ public function checkLink($url, $softRefEntry, $linkAnalyzer)
129126
$errorType = self::ERROR_TYPE_MISSING;
130127
} else {
131128
// If the record was found, but its "delete" flag is set, it is a deleted record
132-
$deleteFlag = (!empty($GLOBALS['TCA'][$this->recordLink->getTable()]['ctrl']['delete'])) ? $GLOBALS['TCA'][$this->recordLink->getTable()]['ctrl']['delete'] : '';
129+
$deleteFlag = (!empty($GLOBALS['TCA'][$this->recordLink->getTable()]['ctrl']['delete']))
130+
? $GLOBALS['TCA'][$this->recordLink->getTable()]['ctrl']['delete'] : '';
133131
if ($deleteFlag !== '') {
134132
$deleted = (bool)$rawRecord[$deleteFlag];
135133
if ($deleted) {
@@ -224,11 +222,7 @@ protected function getRecordRow($applyEnableFields = false)
224222
$whereStatement .= BackendUtility::BEenableFields($this->recordLink->getTable());
225223
}
226224

227-
$row = $this->databaseConnection->exec_SELECTgetSingleRow(
228-
'*',
229-
$this->recordLink->getTable(),
230-
$whereStatement
231-
);
225+
$row = $this->databaseConnection->exec_SELECTgetSingleRow('*', $this->recordLink->getTable(), $whereStatement);
232226

233227
// Since exec_SELECTgetSingleRow can return NULL or FALSE we
234228
// make sure we always return NULL if no row was found.

Diff for: Classes/ProcessLinkParametersInterface.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
*
2121
* @package Cobweb\Linkhandler
2222
*/
23-
interface ProcessLinkParametersInterface {
23+
interface ProcessLinkParametersInterface
24+
{
2425
/**
2526
* @param \Cobweb\Linkhandler\TypolinkHandler $linkHandler Back-reference to the calling object
2627
* @return void

0 commit comments

Comments
 (0)