Skip to content

Commit 22d51b7

Browse files
committed
[TASK] improve UpgradeWizard: ChangeResponsivePartFieldTypeUpgradeWizard
Better output if old content of field isn't empty and valid json.
1 parent a71be5f commit 22d51b7

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

Classes/Upgrades/ChangeResponsivePartFieldTypeUpgradeWizard.php

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ public function setOutput(OutputInterface $output): void {
3131
* Return the speaking name of this wizard
3232
*/
3333
public function getTitle(): string {
34-
return 'EXT:hh_slider - Update DB:field tx_hhslider_responsive_part';
34+
return 'EXT:hh_slider - Update DB:field "tx_hhslider_responsive_part"';
3535
}
3636

3737
/**
3838
* Return the description for this wizard
3939
*/
4040
public function getDescription(): string {
41-
return 'Update DB:field tx_hhslider_responsive_part from text to json.';
41+
return 'Update DB:field "tx_hhslider_responsive_part" from text to json.';
4242
}
4343

4444
/**
@@ -48,6 +48,29 @@ public function getDescription(): string {
4848
*/
4949
public function executeUpdate(): bool {
5050
if($this->updateNecessary()) {
51+
$results = $this->getContentofFieldIfNotValidJson();
52+
53+
if(\count($results) > 0) {
54+
$message = "
55+
Maybe some DB table \"tt_content\" field \"tx_hhslider_responsive_part\" are not empty, has not valid json.
56+
They has to be empty or contains valid json! Please check this manualy.
57+
Affected elements:
58+
";
59+
60+
foreach ($results as $value) {
61+
$message .= 'UID: ' . $value['uid'] . ', ';
62+
$message .= 'PID: ' . $value['pid'] . ', ';
63+
$message .= 'hidden: ' . $value['hidden'] . ', ';
64+
$message .= 'deleted: ' . $value['deleted'] . ' <|> ';
65+
}
66+
67+
$message = rtrim($message, ' <|> ');
68+
69+
$this->output->writeln($message);
70+
71+
return false;
72+
}
73+
5174
$connection = GeneralUtility::makeInstance(ConnectionPool::class)
5275
->getConnectionForTable('tt_content');
5376

@@ -112,6 +135,29 @@ public function updateNecessary(): bool {
112135
return false;
113136
}
114137

138+
public function getContentofFieldIfNotValidJson(string $field = 'tx_hhslider_responsive_part'): array {
139+
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content');
140+
$queryBuilder->getRestrictions()->removeAll();
141+
$expressionBuilder = $queryBuilder->expr();
142+
143+
return $queryBuilder
144+
->select('uid', 'pid', 'hidden', 'deleted', $field)
145+
->from('tt_content')
146+
->where(
147+
$expressionBuilder->and(
148+
$expressionBuilder->isNotNull($field),
149+
$expressionBuilder->neq($field, $queryBuilder->createNamedParameter('')),
150+
$expressionBuilder->comparison(
151+
'JSON_VALID('.$field.')',
152+
'=',
153+
$queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
154+
)
155+
)
156+
)
157+
->executeQuery()
158+
->fetchAllAssociative();
159+
}
160+
115161
/**
116162
* Returns an array of class names of prerequisite classes
117163
*

ext_emconf.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
'title' => 'Hauer-Heinrich - Slider (tiny-slider)',
1515
'description' => 'Hauer-Heinrich - Image and Content Slider',
1616
'category' => 'fe',
17-
'version' => '0.7.0',
17+
'version' => '0.7.1',
1818
'state' => 'stable',
1919
'uploadfolder' => false,
2020
'clearcacheonload' => false,

0 commit comments

Comments
 (0)