@@ -42,8 +42,19 @@ public function fromFileCommand($file)
42
42
$ this ->outputLine ('Emptied database table " ' . $ config ['table ' ] . '" ' );
43
43
}
44
44
foreach ($ config ['entries ' ] as $ entry ) {
45
- $ conn ->insert ($ config ['table ' ], $ entry );
46
- $ this ->outputLine ('Added ' . json_encode ($ entry ) . ' to database table ' . $ config ['table ' ]);
45
+ if ($ mode === 'update ' && isset ($ entry ['uid ' ])) {
46
+ $ identifiers = ['uid ' => $ entry ['uid ' ]];
47
+ if ($ conn ->count ('uid ' , $ config ['table ' ], $ identifiers )) {
48
+ $ conn ->update ($ config ['table ' ], $ entry , $ identifiers );
49
+ $ this ->outputLine ('Updated (mode=update, entry has uid): ' . json_encode ($ entry ) . ' to database table ' . $ config ['table ' ]);
50
+ } else {
51
+ $ conn ->insert ($ config ['table ' ], $ entry );
52
+ $ this ->outputLine ('Added (mode=update, entry does not have uid): ' . json_encode ($ entry ) . ' to database table ' . $ config ['table ' ]);
53
+ }
54
+ } else {
55
+ $ conn ->insert ($ config ['table ' ], $ entry );
56
+ $ this ->outputLine ('Added ' . json_encode ($ entry ) . ' to database table ' . $ config ['table ' ]);
57
+ }
47
58
}
48
59
} else {
49
60
if (!($ GLOBALS ['TYPO3_DB ' ] instanceof DatabaseConnection)) {
@@ -57,8 +68,19 @@ public function fromFileCommand($file)
57
68
$ this ->outputLine ('Emptied database table " ' . $ config ['table ' ] . '" ' );
58
69
}
59
70
foreach ($ config ['entries ' ] as $ entry ) {
60
- $ conn ->exec_INSERTquery ($ config ['table ' ], $ entry );
61
- $ this ->outputLine ('Added ' . json_encode ($ entry ) . ' to database table ' . $ config ['table ' ]);
71
+ if ($ mode === 'update ' && isset ($ entry ['uid ' ])) {
72
+ $ condition = sprintf ('uid = %d ' , $ entry ['uid ' ]);
73
+ if ($ conn ->exec_SELECTcountRows ('uid ' , $ config ['table ' ], $ condition )) {
74
+ $ conn ->exec_UPDATEquery ($ config ['table ' ], $ condition , $ entry );
75
+ $ this ->outputLine ('Updated (mode=update, entry has uid): ' . json_encode ($ entry ) . ' to database table ' . $ config ['table ' ]);
76
+ } else {
77
+ $ conn ->exec_INSERTquery ($ config ['table ' ], $ entry );
78
+ $ this ->outputLine ('Added (mode=update, entry does not have uid): ' . json_encode ($ entry ) . ' to database table ' . $ config ['table ' ]);
79
+ }
80
+ } else {
81
+ $ conn ->exec_INSERTquery ($ config ['table ' ], $ entry );
82
+ $ this ->outputLine ('Added ' . json_encode ($ entry ) . ' to database table ' . $ config ['table ' ]);
83
+ }
62
84
}
63
85
}
64
86
}
0 commit comments