@@ -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 *
0 commit comments